* mm-util.el (mm-enrich-utf-8-by-mule-ucs): Don't edit
[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 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 2, or (at your option)
14 ;; 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; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-map)
33   (defvar w3m-minor-mode-map))
34
35 (require 'gnus)
36 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
37 (eval-and-compile
38   (let ((recursive-load-depth-limit 100))
39     (require 'gnus-sum)))
40 (require 'gnus-spec)
41 (require 'gnus-int)
42 (require 'gnus-win)
43 (require 'mm-bodies)
44 (require 'mail-parse)
45 (require 'mm-decode)
46 (require 'mm-view)
47 (require 'wid-edit)
48 (require 'mm-uu)
49 (require 'message)
50
51 (autoload 'gnus-msg-mail "gnus-msg" nil t)
52 (autoload 'gnus-button-mailto "gnus-msg")
53 (autoload 'gnus-button-reply "gnus-msg" nil t)
54 (autoload 'parse-time-string "parse-time" nil nil)
55 (autoload 'ansi-color-apply-on-region "ansi-color")
56 (autoload 'mm-url-insert-file-contents-external "mm-url")
57 (autoload 'mm-extern-cache-contents "mm-extern")
58
59 (defgroup gnus-article nil
60   "Article display."
61   :link '(custom-manual "(gnus)Article Buffer")
62   :group 'gnus)
63
64 (defgroup gnus-article-treat nil
65   "Treating article parts."
66   :link '(custom-manual "(gnus)Article Hiding")
67   :group 'gnus-article)
68
69 (defgroup gnus-article-hiding nil
70   "Hiding article parts."
71   :link '(custom-manual "(gnus)Article Hiding")
72   :group 'gnus-article)
73
74 (defgroup gnus-article-highlight nil
75   "Article highlighting."
76   :link '(custom-manual "(gnus)Article Highlighting")
77   :group 'gnus-article
78   :group 'gnus-visual)
79
80 (defgroup gnus-article-signature nil
81   "Article signatures."
82   :link '(custom-manual "(gnus)Article Signature")
83   :group 'gnus-article)
84
85 (defgroup gnus-article-headers nil
86   "Article headers."
87   :link '(custom-manual "(gnus)Hiding Headers")
88   :group 'gnus-article)
89
90 (defgroup gnus-article-washing nil
91   "Special commands on articles."
92   :link '(custom-manual "(gnus)Article Washing")
93   :group 'gnus-article)
94
95 (defgroup gnus-article-emphasis nil
96   "Fontisizing articles."
97   :link '(custom-manual "(gnus)Article Fontisizing")
98   :group 'gnus-article)
99
100 (defgroup gnus-article-saving nil
101   "Saving articles."
102   :link '(custom-manual "(gnus)Saving Articles")
103   :group 'gnus-article)
104
105 (defgroup gnus-article-mime nil
106   "Worshiping the MIME wonder."
107   :link '(custom-manual "(gnus)Using MIME")
108   :group 'gnus-article)
109
110 (defgroup gnus-article-buttons nil
111   "Pushable buttons in the article buffer."
112   :link '(custom-manual "(gnus)Article Buttons")
113   :group 'gnus-article)
114
115 (defgroup gnus-article-various nil
116   "Other article options."
117   :link '(custom-manual "(gnus)Misc Article")
118   :group 'gnus-article)
119
120 (defcustom gnus-ignored-headers
121   (mapcar
122    (lambda (header)
123      (concat "^" header ":"))
124    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
125      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
126      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
127      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
128      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
129      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
130      "X-Attribution" "X-Originating-IP" "Delivered-To"
131      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
132      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
133      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
134      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
135      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
136      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
137      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
138      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
139      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
140      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
141      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
142      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
143      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
144      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
145      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
146      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
147      "List-[A-Za-z]+" "X-Listprocessor-Version"
148      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
149      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
150      "X-Received" "Content-length" "X-precedence"
151      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
152      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
153      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
154      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
155      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
156      "X-Content-length" "X-Posting-Agent" "Original-Received"
157      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
158      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
159      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
160      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
161      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
162      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
163      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
164      "Envelope-Sender" "Envelope-Recipients"))
165   "*All headers that start with this regexp will be hidden.
166 This variable can also be a list of regexps of headers to be ignored.
167 If `gnus-visible-headers' is non-nil, this variable will be ignored."
168   :type '(choice :custom-show nil
169                  regexp
170                  (repeat regexp))
171   :group 'gnus-article-hiding)
172
173 (defcustom gnus-visible-headers
174   "^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:"
175   "*All headers that do not match this regexp will be hidden.
176 This variable can also be a list of regexp of headers to remain visible.
177 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
178   :type '(repeat :value-to-internal (lambda (widget value)
179                                       (custom-split-regexp-maybe value))
180                  :match (lambda (widget value)
181                           (or (stringp value)
182                               (widget-editable-list-match widget value)))
183                  regexp)
184   :group 'gnus-article-hiding)
185
186 (defcustom gnus-sorted-header-list
187   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189   "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193   :type '(repeat regexp)
194   :group 'gnus-article-hiding)
195
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197   "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
199
200   'empty       Headers with no content.
201   'newsgroups  Newsgroup identical to Gnus group.
202   'to-address  To identical to To-address.
203   'to-list     To identical to To-list.
204   'cc-list     CC identical to To-list.
205   'followup-to Followup-to identical to Newsgroups.
206   'reply-to    Reply-to identical to From.
207   'date        Date less than four days old.
208   'long-to     To and/or Cc longer than 1024 characters.
209   'many-to     Multiple To and/or Cc."
210   :type '(set (const :tag "Headers with no content." empty)
211               (const :tag "Newsgroups identical to Gnus group." newsgroups)
212               (const :tag "To identical to To-address." to-address)
213               (const :tag "To identical to To-list." to-list)
214               (const :tag "CC identical to To-list." cc-list)
215               (const :tag "Followup-to identical to Newsgroups." followup-to)
216               (const :tag "Reply-to identical to From." reply-to)
217               (const :tag "Date less than four days old." date)
218               (const :tag "To and/or Cc longer than 1024 characters." long-to)
219               (const :tag "Multiple To and/or Cc headers." many-to))
220   :group 'gnus-article-hiding)
221
222 (defcustom gnus-article-skip-boring nil
223   "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text.  Boring text is controlled by
227 `gnus-article-boring-faces'."
228   :version "22.1"
229   :type 'boolean
230   :group 'gnus-article-hiding)
231
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233   "Regexp matching signature separator.
234 This can also be a list of regexps.  In that case, it will be checked
235 from head to tail looking for a separator.  Searches will be done from
236 the end of the buffer."
237   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238                  (regexp)
239                  (repeat :tag "List of regexp" regexp))
240   :group 'gnus-article-signature)
241
242 (defcustom gnus-signature-limit nil
243   "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number.  If it is a floating point number, no signature may be
246 longer (in lines) than that number.  If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer.  If it is a string, it will be used as a
249 regexp.  If it matches, the text in question is not a signature.
250
251 This can also be a list of the above values."
252   :type '(choice (const nil)
253                  (integer :value 200)
254                  (number :value 4.0)
255                  (function :value fun)
256                  (regexp :value ".*"))
257   :group 'gnus-article-signature)
258
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260   "Property list to use for hiding text."
261   :type 'sexp
262   :group 'gnus-article-hiding)
263
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267   (if (featurep 'xemacs)
268       (if (or (gnus-image-type-available-p 'xface)
269               (gnus-image-type-available-p 'pbm))
270           'gnus-display-x-face-in-from
271         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272     (if (gnus-image-type-available-p 'pbm)
273         'gnus-display-x-face-in-from
274       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
275 display -"))
276   "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously.  The compressed face will be piped to this command."
279   :type `(choice string
280                  (function-item gnus-display-x-face-in-from)
281                  function)
282   :version "21.1"
283   :group 'gnus-picon
284   :group 'gnus-article-washing)
285
286 (defcustom gnus-article-x-face-too-ugly nil
287   "Regexp matching posters whose face shouldn't be shown automatically."
288   :type '(choice regexp (const nil))
289   :group 'gnus-article-washing)
290
291 (defcustom gnus-article-banner-alist nil
292   "Banner alist for stripping.
293 For example,
294      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295   :version "21.1"
296   :type '(repeat (cons symbol regexp))
297   :group 'gnus-article-washing)
298
299 (gnus-define-group-parameter
300  banner
301  :variable-document
302  "Alist of regexps (to match group names) and banner."
303  :variable-group gnus-article-washing
304  :parameter-type
305  '(choice :tag "Banner"
306           :value nil
307           (const :tag "Remove signature" signature)
308           (symbol :tag "Item in `gnus-article-banner-alist'" none)
309           regexp
310           (const :tag "None" nil))
311  :parameter-document
312  "If non-nil, specify how to remove `banners' from articles.
313
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'.  Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
319
320 (defcustom gnus-article-address-banner-alist nil
321   "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements.  For example:
327
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
329 "
330   :type '(repeat
331           (cons
332            (regexp :tag "Address")
333            (choice :tag "Banner" :value nil
334                    (const :tag "Remove signature" signature)
335                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
336                    regexp
337                    (const :tag "None" nil))))
338   :version "22.1"
339   :group 'gnus-article-washing)
340
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342   `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345      ,@body))
346
347 (defun gnus-emphasis-custom-value-to-external (value)
348   (gnus-emphasis-custom-with-format
349    (if (consp (car value))
350        (list (format format (car (car value)) (cdr (car value)))
351              2
352              (if (nth 1 value) 2 3)
353              (nth 2 value))
354      value)))
355
356 (defun gnus-emphasis-custom-value-to-internal (value)
357   (gnus-emphasis-custom-with-format
358    (let ((regexp (concat "\\`"
359                          (format (regexp-quote format)
360                                  "\\([^()]+\\)" "\\([^()]+\\)")
361                          "\\'"))
362          pattern)
363      (if (string-match regexp (setq pattern (car value)))
364          (list (cons (match-string 1 pattern) (match-string 2 pattern))
365                (= (nth 2 value) 2)
366                (nth 3 value))
367        value))))
368
369 (defcustom gnus-emphasis-alist
370   (let ((types
371          '(("\\*" "\\*" bold nil 2)
372            ("_" "_" underline)
373            ("/" "/" italic)
374            ("_/" "/_" underline-italic)
375            ("_\\*" "\\*_" underline-bold)
376            ("\\*/" "/\\*" bold-italic)
377            ("_\\*/" "/\\*_" underline-bold-italic))))
378     (nconc
379      (gnus-emphasis-custom-with-format
380       (mapcar (lambda (spec)
381                 (list (format format (car spec) (cadr spec))
382                       (or (nth 3 spec) 2)
383                       (or (nth 4 spec) 3)
384                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385               types))
386      '(;; I've never seen anyone use this strikethru convention whereas I've
387        ;; several times seen it triggered by normal text.  --Stef
388        ;; Miles suggests that this form is sometimes used but for italics,
389        ;; so maybe we should map it to `italic'.
390        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391        ;; 2 3 gnus-emphasis-strikethru)
392        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393         2 3 gnus-emphasis-underline))))
394   "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
396
397   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
398
399 The first element is a regular expression to be matched.  The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word.  The third is a number that says what
402 regexp grouping should be displayed and highlighted.  The fourth
403 is the face used for highlighting."
404   :type
405   '(repeat
406     (menu-choice
407      :format "%[Customizing Style%]\n%v"
408      :indent 2
409      (group :tag "Default"
410             :value ("" 0 0 default)
411             :value-create
412             (lambda (widget)
413               (let ((value (widget-get
414                             (cadr (widget-get (widget-get widget :parent)
415                                               :args))
416                             :value)))
417                 (if (not (eq (nth 2 value) 'default))
418                     (widget-put
419                      widget
420                      :value
421                      (gnus-emphasis-custom-value-to-external value))))
422               (widget-group-value-create widget))
423             regexp
424             (integer :format "Match group: %v")
425             (integer :format "Emphasize group: %v")
426             face)
427      (group :tag "Simple"
428             :value (("_" . "_") nil default)
429             (cons :format "%v"
430                   (regexp :format "Start regexp: %v")
431                   (regexp :format "End regexp: %v"))
432             (boolean :format "Show start and end patterns: %[%v%]\n"
433                      :on " On " :off " Off ")
434             face)))
435   :get (lambda (symbol)
436          (mapcar 'gnus-emphasis-custom-value-to-internal
437                  (default-value symbol)))
438   :set (lambda (symbol value)
439          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440                                      value)))
441   :group 'gnus-article-emphasis)
442
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444   "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448   :version "21.1"
449   :group 'gnus-article-emphasis
450   :type 'regexp)
451
452 (defface gnus-emphasis-bold '((t (:bold t)))
453   "Face used for displaying strong emphasized text (*word*)."
454   :group 'gnus-article-emphasis)
455
456 (defface gnus-emphasis-italic '((t (:italic t)))
457   "Face used for displaying italic emphasized text (/word/)."
458   :group 'gnus-article-emphasis)
459
460 (defface gnus-emphasis-underline '((t (:underline t)))
461   "Face used for displaying underlined emphasized text (_word_)."
462   :group 'gnus-article-emphasis)
463
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465   "Face used for displaying underlined bold emphasized text (_*word*_)."
466   :group 'gnus-article-emphasis)
467
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469   "Face used for displaying underlined italic emphasized text (_/word/_)."
470   :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473   "Face used for displaying bold italic emphasized text (/*word*/)."
474   :group 'gnus-article-emphasis)
475
476 (defface gnus-emphasis-underline-bold-italic
477   '((t (:bold t :italic t :underline t)))
478   "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480   :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483                                       '((t (:strikethru t)))
484                                     '((t (:strike-through t))))
485   "Face used for displaying strike-through text (-word-)."
486   :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-highlight-words
489   '((t (:background "black" :foreground "yellow")))
490   "Face used for displaying highlighted words."
491   :group 'gnus-article-emphasis)
492
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494   "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
496
497 The variable can also be function, which should return a complete Date
498 header.  The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500   :type '(choice string function)
501   :link '(custom-manual "(gnus)Article Date")
502   :group 'gnus-article-washing)
503
504 (defcustom gnus-save-all-headers t
505   "*If non-nil, don't remove any headers before saving."
506   :group 'gnus-article-saving
507   :type 'boolean)
508
509 (defcustom gnus-prompt-before-saving 'always
510   "*This variable says how much prompting is to be done when saving articles.
511 If it is nil, no prompting will be done, and the articles will be
512 saved to the default files.  If this variable is `always', each and
513 every article that is saved will be preceded by a prompt, even when
514 saving large batches of articles.  If this variable is neither nil not
515 `always', there the user will be prompted once for a file name for
516 each invocation of the saving commands."
517   :group 'gnus-article-saving
518   :type '(choice (item always)
519                  (item :tag "never" nil)
520                  (sexp :tag "once" :format "%t\n" :value t)))
521
522 (defcustom gnus-saved-headers gnus-visible-headers
523   "Headers to keep if `gnus-save-all-headers' is nil.
524 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
525 If that variable is nil, however, all headers that match this regexp
526 will be kept while the rest will be deleted before saving."
527   :group 'gnus-article-saving
528   :type 'regexp)
529
530 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
531   "A function to save articles in your favourite format.
532 The function will be called by way of the `gnus-summary-save-article'
533 command, and friends such as `gnus-summary-save-article-rmail'.
534
535 Gnus provides the following functions:
536
537 * gnus-summary-save-in-rmail (Rmail format)
538 * gnus-summary-save-in-mail (Unix mail format)
539 * gnus-summary-save-in-folder (MH folder)
540 * gnus-summary-save-in-file (article format)
541 * gnus-summary-save-body-in-file (article body)
542 * gnus-summary-save-in-vm (use VM's folder format)
543 * gnus-summary-write-to-file (article format -- overwrite)
544 * gnus-summary-write-body-to-file (article body -- overwrite)."
545   :group 'gnus-article-saving
546   :type '(radio (function-item gnus-summary-save-in-rmail)
547                 (function-item gnus-summary-save-in-mail)
548                 (function-item gnus-summary-save-in-folder)
549                 (function-item gnus-summary-save-in-file)
550                 (function-item gnus-summary-save-body-in-file)
551                 (function-item gnus-summary-save-in-vm)
552                 (function-item gnus-summary-write-to-file)
553                 (function-item gnus-summary-write-body-to-file)
554                 (function)))
555
556 (defcustom gnus-article-save-coding-system
557   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
558       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
559       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
560       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
561   "Coding system used to save decoded articles to a file.
562
563 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
564 which can safely encode any characters in text.  This is used by the
565 commands including:
566
567 * gnus-summary-save-article-file
568 * gnus-summary-save-article-body-file
569 * gnus-summary-write-article-file
570 * gnus-summary-write-article-body-file
571
572 and the functions to which you may set `gnus-default-article-saver':
573
574 * gnus-summary-save-in-file
575 * gnus-summary-save-body-in-file
576 * gnus-summary-write-to-file
577 * gnus-summary-write-body-to-file
578
579 Those commands and functions save just text displayed in the article
580 buffer to a file if the value of this variable is non-nil.  Note that
581 buttonized MIME parts will be lost in a saved file in that case.
582 Otherwise, raw articles will be saved."
583   :group 'gnus-article-saving
584   :type `(choice
585           :format "%{%t%}:\n %[Value Menu%] %v"
586           (const :tag "Save raw articles" nil)
587           ,@(delq nil
588                   (mapcar
589                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
590                    '((const :tag "UTF-8" utf-8)
591                      (const :tag "iso-2022-7bit" iso-2022-7bit)
592                      (const :tag "Emacs internal" emacs-mule)
593                      (const :tag "escape-quoted" escape-quoted))))
594           (symbol :tag "Coding system")))
595
596 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
597   "A function generating a file name to save articles in Rmail format.
598 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
599   :group 'gnus-article-saving
600   :type 'function)
601
602 (defcustom gnus-mail-save-name 'gnus-plain-save-name
603   "A function generating a file name to save articles in Unix mail format.
604 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
605   :group 'gnus-article-saving
606   :type 'function)
607
608 (defcustom gnus-folder-save-name 'gnus-folder-save-name
609   "A function generating a file name to save articles in MH folder.
610 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
611   :group 'gnus-article-saving
612   :type 'function)
613
614 (defcustom gnus-file-save-name 'gnus-numeric-save-name
615   "A function generating a file name to save articles in article format.
616 The function is called with NEWSGROUP, HEADERS, and optional
617 LAST-FILE."
618   :group 'gnus-article-saving
619   :type 'function)
620
621 (defcustom gnus-split-methods
622   '((gnus-article-archive-name)
623     (gnus-article-nndoc-name))
624   "*Variable used to suggest where articles are to be saved.
625 For instance, if you would like to save articles related to Gnus in
626 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
627 you could set this variable to something like:
628
629  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
630    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
631
632 This variable is an alist where the key is the match and the
633 value is a list of possible files to save in if the match is
634 non-nil.
635
636 If the match is a string, it is used as a regexp match on the
637 article.  If the match is a symbol, that symbol will be funcalled
638 from the buffer of the article to be saved with the newsgroup as
639 the parameter.  If it is a list, it will be evaled in the same
640 buffer.
641
642 If this form or function returns a string, this string will be
643 used as a possible file name; and if it returns a non-nil list,
644 that list will be used as possible file names."
645   :group 'gnus-article-saving
646   :type '(repeat (choice (list :value (fun) function)
647                          (cons :value ("" "") regexp (repeat string))
648                          (sexp :value nil))))
649
650 (defcustom gnus-page-delimiter "^\^L"
651   "*Regexp describing what to use as article page delimiters.
652 The default value is \"^\^L\", which is a form linefeed at the
653 beginning of a line."
654   :type 'regexp
655   :group 'gnus-article-various)
656
657 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
658   "*The format specification for the article mode line.
659 See `gnus-summary-mode-line-format' for a closer description.
660
661 The following additional specs are available:
662
663 %w  The article washing status.
664 %m  The number of MIME parts in the article."
665   :type 'string
666   :group 'gnus-article-various)
667
668 (defcustom gnus-article-mode-hook nil
669   "*A hook for Gnus article mode."
670   :type 'hook
671   :group 'gnus-article-various)
672
673 (when (featurep 'xemacs)
674   ;; Extracted from gnus-xmas-define in order to preserve user settings
675   (when (fboundp 'turn-off-scroll-in-place)
676     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
677   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
678   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
679
680 (defcustom gnus-article-menu-hook nil
681   "*Hook run after the creation of the article mode menu."
682   :type 'hook
683   :group 'gnus-article-various)
684
685 (defcustom gnus-article-prepare-hook nil
686   "*A hook called after an article has been prepared in the article buffer."
687   :type 'hook
688   :group 'gnus-article-various)
689
690 (defcustom gnus-copy-article-ignored-headers nil
691   "List of headers to be removed when copying an article.
692 Each element is a regular expression."
693   :version "23.0" ;; No Gnus
694   :type '(repeat regexp)
695   :group 'gnus-article-various)
696
697 (make-obsolete-variable 'gnus-article-hide-pgp-hook
698                         "This variable is obsolete in Gnus 5.10.")
699
700 (defface gnus-button
701   '((t (:weight bold)))
702   "Face used for highlighting a button in the article buffer."
703   :group 'gnus-article-buttons)
704
705 (defcustom gnus-article-button-face 'gnus-button
706   "Face used for highlighting buttons in the article buffer.
707
708 An article button is a piece of text that you can activate by pressing
709 `RET' or `mouse-2' above it."
710   :type 'face
711   :group 'gnus-article-buttons)
712
713 (defcustom gnus-article-mouse-face 'highlight
714   "Face used for mouse highlighting in the article buffer.
715
716 Article buttons will be displayed in this face when the cursor is
717 above them."
718   :type 'face
719   :group 'gnus-article-buttons)
720
721 (defcustom gnus-signature-face 'gnus-signature
722   "Face used for highlighting a signature in the article buffer.
723 Obsolete; use the face `gnus-signature' for customizations instead."
724   :type 'face
725   :group 'gnus-article-highlight
726   :group 'gnus-article-signature)
727
728 (defface gnus-signature
729   '((t
730      (:italic t)))
731   "Face used for highlighting a signature in the article buffer."
732   :group 'gnus-article-highlight
733   :group 'gnus-article-signature)
734 ;; backward-compatibility alias
735 (put 'gnus-signature-face 'face-alias 'gnus-signature)
736
737 (defface gnus-header-from
738   '((((class color)
739       (background dark))
740      (:foreground "spring green"))
741     (((class color)
742       (background light))
743      (:foreground "red3"))
744     (t
745      (:italic t)))
746   "Face used for displaying from headers."
747   :group 'gnus-article-headers
748   :group 'gnus-article-highlight)
749 ;; backward-compatibility alias
750 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
751
752 (defface gnus-header-subject
753   '((((class color)
754       (background dark))
755      (:foreground "SeaGreen3"))
756     (((class color)
757       (background light))
758      (:foreground "red4"))
759     (t
760      (:bold t :italic t)))
761   "Face used for displaying subject headers."
762   :group 'gnus-article-headers
763   :group 'gnus-article-highlight)
764 ;; backward-compatibility alias
765 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
766
767 (defface gnus-header-newsgroups
768   '((((class color)
769       (background dark))
770      (:foreground "yellow" :italic t))
771     (((class color)
772       (background light))
773      (:foreground "MidnightBlue" :italic t))
774     (t
775      (:italic t)))
776   "Face used for displaying newsgroups headers.
777 In the default setup this face is only used for crossposted
778 articles."
779   :group 'gnus-article-headers
780   :group 'gnus-article-highlight)
781 ;; backward-compatibility alias
782 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
783
784 (defface gnus-header-name
785   '((((class color)
786       (background dark))
787      (:foreground "SeaGreen"))
788     (((class color)
789       (background light))
790      (:foreground "maroon"))
791     (t
792      (:bold t)))
793   "Face used for displaying header names."
794   :group 'gnus-article-headers
795   :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
798
799 (defface gnus-header-content
800   '((((class color)
801       (background dark))
802      (:foreground "forest green" :italic t))
803     (((class color)
804       (background light))
805      (:foreground "indianred4" :italic t))
806     (t
807      (:italic t)))  "Face used for displaying header content."
808   :group 'gnus-article-headers
809   :group 'gnus-article-highlight)
810 ;; backward-compatibility alias
811 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
812
813 (defcustom gnus-header-face-alist
814   '(("From" nil gnus-header-from)
815     ("Subject" nil gnus-header-subject)
816     ("Newsgroups:.*," nil gnus-header-newsgroups)
817     ("" gnus-header-name gnus-header-content))
818   "*Controls highlighting of article headers.
819
820 An alist of the form (HEADER NAME CONTENT).
821
822 HEADER is a regular expression which should match the name of a
823 header and NAME and CONTENT are either face names or nil.
824
825 The name of each header field will be displayed using the face
826 specified by the first element in the list where HEADER matches
827 the header name and NAME is non-nil.  Similarly, the content will
828 be displayed by the first non-nil matching CONTENT face."
829   :group 'gnus-article-headers
830   :group 'gnus-article-highlight
831   :type '(repeat (list (regexp :tag "Header")
832                        (choice :tag "Name"
833                                (item :tag "skip" nil)
834                                (face :value default))
835                        (choice :tag "Content"
836                                (item :tag "skip" nil)
837                                (face :value default)))))
838
839 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
840                                           '((xface . (:face gnus-x-face)))
841                                         '((pbm . (:face gnus-x-face))
842                                           (png . nil)))
843   "Alist of image types and properties applied to Face and X-Face images.
844 Here are examples:
845
846 ;; Specify the altitude of Face images in the From header.
847 \(setq gnus-face-properties-alist
848       '((pbm . (:face gnus-x-face :ascent 80))
849         (png . (:ascent 80))))
850
851 ;; Show Face images as pressed buttons.
852 \(setq gnus-face-properties-alist
853       '((pbm . (:face gnus-x-face :relief -2))
854         (png . (:relief -2))))
855
856 See the manual for the valid properties for various image types.
857 Currently, `pbm' is used for X-Face images and `png' is used for Face
858 images in Emacs.  Only the `:face' property is effective on the `xface'
859 image type in XEmacs if it is built with the libcompface library."
860   :version "23.0" ;; No Gnus
861   :group 'gnus-article-headers
862   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
863
864 (defcustom gnus-article-decode-hook
865   '(article-decode-charset article-decode-encoded-words
866                            article-decode-group-name article-decode-idna-rhs)
867   "*Hook run to decode charsets in articles."
868   :group 'gnus-article-headers
869   :type 'hook)
870
871 (defcustom gnus-display-mime-function 'gnus-display-mime
872   "Function to display MIME articles."
873   :group 'gnus-article-mime
874   :type 'function)
875
876 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
877   "Function used to decode headers.")
878
879 (defvar gnus-article-dumbquotes-map
880   '(("\200" "EUR")
881     ("\202" ",")
882     ("\203" "f")
883     ("\204" ",,")
884     ("\205" "...")
885     ("\213" "<")
886     ("\214" "OE")
887     ("\221" "`")
888     ("\222" "'")
889     ("\223" "``")
890     ("\224" "\"")
891     ("\225" "*")
892     ("\226" "-")
893     ("\227" "--")
894     ("\230" "~")
895     ("\231" "(TM)")
896     ("\233" ">")
897     ("\234" "oe")
898     ("\264" "'"))
899   "Table for MS-to-Latin1 translation.")
900
901 (defcustom gnus-ignored-mime-types nil
902   "List of MIME types that should be ignored by Gnus."
903   :version "21.1"
904   :group 'gnus-article-mime
905   :type '(repeat regexp))
906
907 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
908   "List of MIME types that should not be given buttons when rendered inline.
909 See also `gnus-buttonized-mime-types' which may override this variable.
910 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
911   :version "21.1"
912   :group 'gnus-article-mime
913   :type '(repeat regexp))
914
915 (defcustom gnus-buttonized-mime-types nil
916   "List of MIME types that should be given buttons when rendered inline.
917 If set, this variable overrides `gnus-unbuttonized-mime-types'.
918 To see e.g. security buttons you could set this to
919 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
920 this list to display radio buttons that allow you to choose one of two
921 media types those mails include.  See also `mm-discouraged-alternatives'.
922 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
923   :version "22.1"
924   :group 'gnus-article-mime
925   :type '(repeat regexp))
926
927 (defcustom gnus-inhibit-mime-unbuttonizing nil
928   "If non-nil, all MIME parts get buttons.
929 When nil (the default value), then some MIME parts do not get buttons,
930 as described by the variables `gnus-buttonized-mime-types' and
931 `gnus-unbuttonized-mime-types'."
932   :version "22.1"
933   :group 'gnus-article-mime
934   :type 'boolean)
935
936 (defcustom gnus-body-boundary-delimiter "_"
937   "String used to delimit header and body.
938 This variable is used by `gnus-article-treat-body-boundary' which can
939 be controlled by `gnus-treat-body-boundary'."
940   :version "22.1"
941   :group 'gnus-article-various
942   :type '(choice (item :tag "None" :value nil)
943                  string))
944
945 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
946                                   "/usr/share/picons")
947   "Defines the location of the faces database.
948 For information on obtaining this database of pretty pictures, please
949 see http://www.cs.indiana.edu/picons/ftp/index.html"
950   :version "22.1"
951   :type '(repeat directory)
952   :link '(url-link :tag "download"
953                    "http://www.cs.indiana.edu/picons/ftp/index.html")
954   :link '(custom-manual "(gnus)Picons")
955   :group 'gnus-picon)
956
957 (defun gnus-picons-installed-p ()
958   "Say whether picons are installed on your machine."
959   (let ((installed nil))
960     (dolist (database gnus-picon-databases)
961       (when (file-exists-p database)
962         (setq installed t)))
963     installed))
964
965 (defcustom gnus-article-mime-part-function nil
966   "Function called with a MIME handle as the argument.
967 This is meant for people who want to do something automatic based
968 on parts -- for instance, adding Vcard info to a database."
969   :group 'gnus-article-mime
970   :type '(choice (const nil)
971                  function))
972
973 (defcustom gnus-mime-multipart-functions nil
974   "An alist of MIME types to functions to display them."
975   :version "21.1"
976   :group 'gnus-article-mime
977   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
978
979 (defcustom gnus-article-date-lapsed-new-header nil
980   "Whether the X-Sent and Date headers can coexist.
981 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
982 either replace the old \"Date:\" header (if this variable is nil), or
983 be added below it (otherwise)."
984   :version "21.1"
985   :group 'gnus-article-headers
986   :type 'boolean)
987
988 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
989   "Function called with a MIME handle as the argument.
990 This is meant for people who want to view first matched part.
991 For `undisplayed-alternative' (default), the first undisplayed
992 part or alternative part is used.  For `undisplayed', the first
993 undisplayed part is used.  For a function, the first part which
994 the function return t is used.  For nil, the first part is
995 used."
996   :version "21.1"
997   :group 'gnus-article-mime
998   :type '(choice
999           (item :tag "first" :value nil)
1000           (item :tag "undisplayed" :value undisplayed)
1001           (item :tag "undisplayed or alternative"
1002                 :value undisplayed-alternative)
1003           (function)))
1004
1005 (defcustom gnus-mime-action-alist
1006   '(("save to file" . gnus-mime-save-part)
1007     ("save and strip" . gnus-mime-save-part-and-strip)
1008     ("replace with file" . gnus-mime-replace-part)
1009     ("delete part" . gnus-mime-delete-part)
1010     ("display as text" . gnus-mime-inline-part)
1011     ("view the part" . gnus-mime-view-part)
1012     ("pipe to command" . gnus-mime-pipe-part)
1013     ("toggle display" . gnus-article-press-button)
1014     ("toggle display" . gnus-article-view-part-as-charset)
1015     ("view as type" . gnus-mime-view-part-as-type)
1016     ("view internally" . gnus-mime-view-part-internally)
1017     ("view externally" . gnus-mime-view-part-externally))
1018   "An alist of actions that run on the MIME attachment."
1019   :group 'gnus-article-mime
1020   :type '(repeat (cons (string :tag "name")
1021                        (function))))
1022
1023 (defcustom gnus-auto-select-part 1
1024   "Advance to next MIME part when deleting or stripping parts.
1025
1026 When 0, point will be placed on the same part as before.  When
1027 positive (negative), move point forward (backwards) this many
1028 parts.  When nil, redisplay article."
1029   :version "23.0" ;; No Gnus
1030   :group 'gnus-article-mime
1031   :type '(choice (const nil :tag "Redisplay article.")
1032                  (const 1 :tag "Next part.")
1033                  (const 0 :tag "Current part.")
1034                  integer))
1035
1036 ;;;
1037 ;;; The treatment variables
1038 ;;;
1039
1040 (defvar gnus-part-display-hook nil
1041   "Hook called on parts that are to receive treatment.")
1042
1043 (defvar gnus-article-treat-custom
1044   '(choice (const :tag "Off" nil)
1045            (const :tag "On" t)
1046            (const :tag "Header" head)
1047            (const :tag "First" first)
1048            (const :tag "Last" last)
1049            (integer :tag "Less")
1050            (repeat :tag "Groups" regexp)
1051            (sexp :tag "Predicate")))
1052
1053 (defvar gnus-article-treat-head-custom
1054   '(choice (const :tag "Off" nil)
1055            (const :tag "Header" head)))
1056
1057 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1058                                    "text/x-patch")
1059   "Parts to treat.")
1060
1061 (defvar gnus-inhibit-treatment nil
1062   "Whether to inhibit treatment.")
1063
1064 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1065   "Highlight the signature.
1066 Valid values are nil, t, `head', `first', `last', an integer or a
1067 predicate.  See Info node `(gnus)Customizing Articles'."
1068   :group 'gnus-article-treat
1069   :link '(custom-manual "(gnus)Customizing Articles")
1070   :type gnus-article-treat-custom)
1071 (put 'gnus-treat-highlight-signature 'highlight t)
1072
1073 (defcustom gnus-treat-buttonize 100000
1074   "Add buttons.
1075 Valid values are nil, t, `head', `first', `last', an integer or a
1076 predicate.  See Info node `(gnus)Customizing Articles'."
1077   :group 'gnus-article-treat
1078   :link '(custom-manual "(gnus)Customizing Articles")
1079   :type gnus-article-treat-custom)
1080 (put 'gnus-treat-buttonize 'highlight t)
1081
1082 (defcustom gnus-treat-buttonize-head 'head
1083   "Add buttons to the head.
1084 Valid values are nil, t, `head', `first', `last', an integer or a
1085 predicate.  See Info node `(gnus)Customizing Articles'."
1086   :group 'gnus-article-treat
1087   :link '(custom-manual "(gnus)Customizing Articles")
1088   :type gnus-article-treat-head-custom)
1089 (put 'gnus-treat-buttonize-head 'highlight t)
1090
1091 (defcustom gnus-treat-emphasize
1092   (and (or window-system
1093            (featurep 'xemacs))
1094        50000)
1095   "Emphasize text.
1096 Valid values are nil, t, `head', `first', `last', an integer or a
1097 predicate.  See Info node `(gnus)Customizing Articles'."
1098   :group 'gnus-article-treat
1099   :link '(custom-manual "(gnus)Customizing Articles")
1100   :type gnus-article-treat-custom)
1101 (put 'gnus-treat-emphasize 'highlight t)
1102
1103 (defcustom gnus-treat-strip-cr nil
1104   "Remove carriage returns.
1105 Valid values are nil, t, `head', `first', `last', an integer or a
1106 predicate.  See Info node `(gnus)Customizing Articles'."
1107   :version "22.1"
1108   :group 'gnus-article-treat
1109   :link '(custom-manual "(gnus)Customizing Articles")
1110   :type gnus-article-treat-custom)
1111
1112 (defcustom gnus-treat-unsplit-urls nil
1113   "Remove newlines from within URLs.
1114 Valid values are nil, t, `head', `first', `last', an integer or a
1115 predicate.  See Info node `(gnus)Customizing Articles'."
1116   :version "22.1"
1117   :group 'gnus-article-treat
1118   :link '(custom-manual "(gnus)Customizing Articles")
1119   :type gnus-article-treat-custom)
1120
1121 (defcustom gnus-treat-leading-whitespace nil
1122   "Remove leading whitespace in headers.
1123 Valid values are nil, t, `head', `first', `last', an integer or a
1124 predicate.  See Info node `(gnus)Customizing Articles'."
1125   :version "22.1"
1126   :group 'gnus-article-treat
1127   :link '(custom-manual "(gnus)Customizing Articles")
1128   :type gnus-article-treat-custom)
1129
1130 (defcustom gnus-treat-hide-headers 'head
1131   "Hide headers.
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-head-custom)
1137
1138 (defcustom gnus-treat-hide-boring-headers nil
1139   "Hide boring headers.
1140 Valid values are nil, t, `head', `first', `last', an integer or a
1141 predicate.  See Info node `(gnus)Customizing Articles'."
1142   :group 'gnus-article-treat
1143   :link '(custom-manual "(gnus)Customizing Articles")
1144   :type gnus-article-treat-head-custom)
1145
1146 (defcustom gnus-treat-hide-signature nil
1147   "Hide the signature.
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate.  See Info node `(gnus)Customizing Articles'."
1150   :group 'gnus-article-treat
1151   :link '(custom-manual "(gnus)Customizing Articles")
1152   :type gnus-article-treat-custom)
1153
1154 (defcustom gnus-treat-fill-article nil
1155   "Fill the article.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate.  See Info node `(gnus)Customizing Articles'."
1158   :group 'gnus-article-treat
1159   :link '(custom-manual "(gnus)Customizing Articles")
1160   :type gnus-article-treat-custom)
1161
1162 (defcustom gnus-treat-hide-citation nil
1163   "Hide cited text.
1164 Valid values are nil, t, `head', `first', `last', an integer or a
1165 predicate.  See Info node `(gnus)Customizing Articles'."
1166   :group 'gnus-article-treat
1167   :link '(custom-manual "(gnus)Customizing Articles")
1168   :type gnus-article-treat-custom)
1169
1170 (defcustom gnus-treat-hide-citation-maybe nil
1171   "Hide cited text.
1172 Valid values are nil, t, `head', `first', `last', an integer or a
1173 predicate.  See Info node `(gnus)Customizing Articles'."
1174   :group 'gnus-article-treat
1175   :link '(custom-manual "(gnus)Customizing Articles")
1176   :type gnus-article-treat-custom)
1177
1178 (defcustom gnus-treat-strip-list-identifiers 'head
1179   "Strip list identifiers from `gnus-list-identifiers`.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate.  See Info node `(gnus)Customizing Articles'."
1182   :version "21.1"
1183   :group 'gnus-article-treat
1184   :link '(custom-manual "(gnus)Customizing Articles")
1185   :type gnus-article-treat-custom)
1186
1187 (make-obsolete-variable 'gnus-treat-strip-pgp
1188                         "This option is obsolete in Gnus 5.10.")
1189
1190 (defcustom gnus-treat-strip-pem nil
1191   "Strip PEM signatures.
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-strip-banner t
1199   "Strip banners from articles.
1200 The banner to be stripped is specified in the `banner' group parameter.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate.  See Info node `(gnus)Customizing Articles'."
1203   :group 'gnus-article-treat
1204   :link '(custom-manual "(gnus)Customizing Articles")
1205   :type gnus-article-treat-custom)
1206
1207 (defcustom gnus-treat-highlight-headers 'head
1208   "Highlight the headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate.  See Info node `(gnus)Customizing Articles'."
1211   :group 'gnus-article-treat
1212   :link '(custom-manual "(gnus)Customizing Articles")
1213   :type gnus-article-treat-head-custom)
1214 (put 'gnus-treat-highlight-headers 'highlight t)
1215
1216 (defcustom gnus-treat-highlight-citation t
1217   "Highlight cited text.
1218 Valid values are nil, t, `head', `first', `last', an integer or a
1219 predicate.  See Info node `(gnus)Customizing Articles'."
1220   :group 'gnus-article-treat
1221   :link '(custom-manual "(gnus)Customizing Articles")
1222   :type gnus-article-treat-custom)
1223 (put 'gnus-treat-highlight-citation 'highlight t)
1224
1225 (defcustom gnus-treat-date-ut nil
1226   "Display the Date in UT (GMT).
1227 Valid values are nil, t, `head', `first', `last', an integer or a
1228 predicate.  See Info node `(gnus)Customizing Articles'."
1229   :group 'gnus-article-treat
1230   :link '(custom-manual "(gnus)Customizing Articles")
1231   :type gnus-article-treat-head-custom)
1232
1233 (defcustom gnus-treat-date-local nil
1234   "Display the Date in the local timezone.
1235 Valid values are nil, t, `head', `first', `last', an integer or a
1236 predicate.  See Info node `(gnus)Customizing Articles'."
1237   :group 'gnus-article-treat
1238   :link '(custom-manual "(gnus)Customizing Articles")
1239   :type gnus-article-treat-head-custom)
1240
1241 (defcustom gnus-treat-date-english nil
1242   "Display the Date in a format that can be read aloud in English.
1243 Valid values are nil, t, `head', `first', `last', an integer or a
1244 predicate.  See Info node `(gnus)Customizing Articles'."
1245   :version "22.1"
1246   :group 'gnus-article-treat
1247   :link '(custom-manual "(gnus)Customizing Articles")
1248   :type gnus-article-treat-head-custom)
1249
1250 (defcustom gnus-treat-date-lapsed nil
1251   "Display the Date header in a way that says how much time has elapsed.
1252 Valid values are nil, t, `head', `first', `last', an integer or a
1253 predicate.  See Info node `(gnus)Customizing Articles'."
1254   :group 'gnus-article-treat
1255   :link '(custom-manual "(gnus)Customizing Articles")
1256   :type gnus-article-treat-head-custom)
1257
1258 (defcustom gnus-treat-date-original nil
1259   "Display the date in the original timezone.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate.  See Info node `(gnus)Customizing Articles'."
1262   :group 'gnus-article-treat
1263   :link '(custom-manual "(gnus)Customizing Articles")
1264   :type gnus-article-treat-head-custom)
1265
1266 (defcustom gnus-treat-date-iso8601 nil
1267   "Display the date in the ISO8601 format.
1268 Valid values are nil, t, `head', `first', `last', an integer or a
1269 predicate.  See Info node `(gnus)Customizing Articles'."
1270   :version "21.1"
1271   :group 'gnus-article-treat
1272   :link '(custom-manual "(gnus)Customizing Articles")
1273   :type gnus-article-treat-head-custom)
1274
1275 (defcustom gnus-treat-date-user-defined nil
1276   "Display the date in a user-defined format.
1277 The format is defined by the `gnus-article-time-format' variable.
1278 Valid values are nil, t, `head', `first', `last', an integer or a
1279 predicate.  See Info node `(gnus)Customizing Articles'."
1280   :group 'gnus-article-treat
1281   :link '(custom-manual "(gnus)Customizing Articles")
1282   :type gnus-article-treat-head-custom)
1283
1284 (defcustom gnus-treat-strip-headers-in-body t
1285   "Strip the X-No-Archive header line from the beginning of the body.
1286 Valid values are nil, t, `head', `first', `last', an integer or a
1287 predicate.  See Info node `(gnus)Customizing Articles'."
1288   :version "21.1"
1289   :group 'gnus-article-treat
1290   :link '(custom-manual "(gnus)Customizing Articles")
1291   :type gnus-article-treat-custom)
1292
1293 (defcustom gnus-treat-strip-trailing-blank-lines nil
1294   "Strip trailing blank lines.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate.  See Info node `(gnus)Customizing Articles'.
1297
1298 When set to t, it also strips trailing blanks in all MIME parts.
1299 Consider to use `last' instead."
1300   :group 'gnus-article-treat
1301   :link '(custom-manual "(gnus)Customizing Articles")
1302   :type gnus-article-treat-custom)
1303
1304 (defcustom gnus-treat-strip-leading-blank-lines nil
1305   "Strip leading blank lines.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate.  See Info node `(gnus)Customizing Articles'.
1308
1309 When set to t, it also strips trailing blanks in all MIME parts."
1310   :group 'gnus-article-treat
1311   :link '(custom-manual "(gnus)Customizing Articles")
1312   :type gnus-article-treat-custom)
1313
1314 (defcustom gnus-treat-strip-multiple-blank-lines nil
1315   "Strip multiple blank lines.
1316 Valid values are nil, t, `head', `first', `last', an integer or a
1317 predicate.  See Info node `(gnus)Customizing Articles'."
1318   :group 'gnus-article-treat
1319   :link '(custom-manual "(gnus)Customizing Articles")
1320   :type gnus-article-treat-custom)
1321
1322 (defcustom gnus-treat-unfold-headers 'head
1323   "Unfold folded header lines.
1324 Valid values are nil, t, `head', `first', `last', an integer or a
1325 predicate.  See Info node `(gnus)Customizing Articles'."
1326   :version "22.1"
1327   :group 'gnus-article-treat
1328   :link '(custom-manual "(gnus)Customizing Articles")
1329   :type gnus-article-treat-custom)
1330
1331 (defcustom gnus-treat-fold-headers nil
1332   "Fold headers.
1333 Valid values are nil, t, `head', `first', `last', an integer or a
1334 predicate.  See Info node `(gnus)Customizing Articles'."
1335   :version "22.1"
1336   :group 'gnus-article-treat
1337   :link '(custom-manual "(gnus)Customizing Articles")
1338   :type gnus-article-treat-custom)
1339
1340 (defcustom gnus-treat-fold-newsgroups 'head
1341   "Fold the Newsgroups and Followup-To headers.
1342 Valid values are nil, t, `head', `first', `last', an integer or a
1343 predicate.  See Info node `(gnus)Customizing Articles'."
1344   :version "22.1"
1345   :group 'gnus-article-treat
1346   :link '(custom-manual "(gnus)Customizing Articles")
1347   :type gnus-article-treat-custom)
1348
1349 (defcustom gnus-treat-overstrike t
1350   "Treat overstrike highlighting.
1351 Valid values are nil, t, `head', `first', `last', an integer or a
1352 predicate.  See Info node `(gnus)Customizing Articles'."
1353   :group 'gnus-article-treat
1354   :link '(custom-manual "(gnus)Customizing Articles")
1355   :type gnus-article-treat-custom)
1356 (put 'gnus-treat-overstrike 'highlight t)
1357
1358 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1359   "Treat ANSI SGR control sequences.
1360 Valid values are nil, t, `head', `first', `last', an integer or a
1361 predicate.  See Info node `(gnus)Customizing Articles'."
1362   :group 'gnus-article-treat
1363   :link '(custom-manual "(gnus)Customizing Articles")
1364   :type gnus-article-treat-custom)
1365
1366 (make-obsolete-variable 'gnus-treat-display-xface
1367                         'gnus-treat-display-x-face)
1368
1369 (defcustom gnus-treat-display-x-face
1370   (and (not noninteractive)
1371        (or (and (fboundp 'image-type-available-p)
1372                 (image-type-available-p 'xbm)
1373                 (string-match "^0x" (shell-command-to-string "uncompface"))
1374                 (executable-find "icontopbm"))
1375            (and (featurep 'xemacs)
1376                 (featurep 'xface)))
1377        'head)
1378   "Display X-Face headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate.  See Info node `(gnus)Customizing Articles' and Info
1381 node `(gnus)X-Face' for details."
1382   :group 'gnus-article-treat
1383   :version "21.1"
1384   :link '(custom-manual "(gnus)Customizing Articles")
1385   :link '(custom-manual "(gnus)X-Face")
1386   :type gnus-article-treat-head-custom
1387   :set (lambda (symbol value)
1388          (set-default
1389           symbol
1390           (cond ((or (boundp symbol) (get symbol 'saved-value))
1391                  value)
1392                 ((boundp 'gnus-treat-display-xface)
1393                  (message "\
1394 ** gnus-treat-display-xface is an obsolete variable;\
1395  use gnus-treat-display-x-face instead")
1396                  (default-value 'gnus-treat-display-xface))
1397                 ((get 'gnus-treat-display-xface 'saved-value)
1398                  (message "\
1399 ** gnus-treat-display-xface is an obsolete variable;\
1400  use gnus-treat-display-x-face instead")
1401                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1402                 (t
1403                  value)))))
1404 (put 'gnus-treat-display-x-face 'highlight t)
1405
1406 (defcustom gnus-treat-display-face
1407   (and (not noninteractive)
1408        (or (and (fboundp 'image-type-available-p)
1409                 (image-type-available-p 'png))
1410            (and (featurep 'xemacs)
1411                 (featurep 'png)))
1412        'head)
1413   "Display Face headers.
1414 Valid values are nil, t, `head', `first', `last', an integer or a
1415 predicate.  See Info node `(gnus)Customizing Articles' and Info
1416 node `(gnus)X-Face' for details."
1417   :group 'gnus-article-treat
1418   :version "22.1"
1419   :link '(custom-manual "(gnus)Customizing Articles")
1420   :link '(custom-manual "(gnus)X-Face")
1421   :type gnus-article-treat-head-custom)
1422 (put 'gnus-treat-display-face 'highlight t)
1423
1424 (defcustom gnus-treat-display-smileys
1425   (if (or (and (featurep 'xemacs)
1426                (featurep 'xpm))
1427           (and (fboundp 'image-type-available-p)
1428                (image-type-available-p 'pbm)))
1429       t nil)
1430   "Display smileys.
1431 Valid values are nil, t, `head', `first', `last', an integer or a
1432 predicate.  See Info node `(gnus)Customizing Articles' and Info
1433 node `(gnus)Smileys' for details."
1434   :group 'gnus-article-treat
1435   :version "21.1"
1436   :link '(custom-manual "(gnus)Customizing Articles")
1437   :link '(custom-manual "(gnus)Smileys")
1438   :type gnus-article-treat-custom)
1439 (put 'gnus-treat-display-smileys 'highlight t)
1440
1441 (defcustom gnus-treat-from-picon
1442   (if (and (gnus-image-type-available-p 'xpm)
1443            (gnus-picons-installed-p))
1444       'head nil)
1445   "Display picons in the From header.
1446 Valid values are nil, t, `head', `first', `last', an integer or a
1447 predicate.  See Info node `(gnus)Customizing Articles' and Info
1448 node `(gnus)Picons' for details."
1449   :version "22.1"
1450   :group 'gnus-article-treat
1451   :group 'gnus-picon
1452   :link '(custom-manual "(gnus)Customizing Articles")
1453   :link '(custom-manual "(gnus)Picons")
1454   :type gnus-article-treat-head-custom)
1455 (put 'gnus-treat-from-picon 'highlight t)
1456
1457 (defcustom gnus-treat-mail-picon
1458   (if (and (gnus-image-type-available-p 'xpm)
1459            (gnus-picons-installed-p))
1460       'head nil)
1461   "Display picons in To and Cc 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)Picons' for details."
1465   :version "22.1"
1466   :group 'gnus-article-treat
1467   :group 'gnus-picon
1468   :link '(custom-manual "(gnus)Customizing Articles")
1469   :link '(custom-manual "(gnus)Picons")
1470   :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-mail-picon 'highlight t)
1472
1473 (defcustom gnus-treat-newsgroups-picon
1474   (if (and (gnus-image-type-available-p 'xpm)
1475            (gnus-picons-installed-p))
1476       'head nil)
1477   "Display picons in the Newsgroups and Followup-To headers.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate.  See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Picons' for details."
1481   :version "22.1"
1482   :group 'gnus-article-treat
1483   :group 'gnus-picon
1484   :link '(custom-manual "(gnus)Customizing Articles")
1485   :link '(custom-manual "(gnus)Picons")
1486   :type gnus-article-treat-head-custom)
1487 (put 'gnus-treat-newsgroups-picon 'highlight t)
1488
1489 (defcustom gnus-treat-body-boundary
1490   (if (and (eq window-system 'x)
1491            (or gnus-treat-newsgroups-picon
1492                gnus-treat-mail-picon
1493                gnus-treat-from-picon))
1494       'head nil)
1495   "Draw a boundary at the end of the headers.
1496 Valid values are nil and `head'.
1497 See Info node `(gnus)Customizing Articles' for details."
1498   :version "22.1"
1499   :group 'gnus-article-treat
1500   :link '(custom-manual "(gnus)Customizing Articles")
1501   :type gnus-article-treat-head-custom)
1502
1503 (defcustom gnus-treat-capitalize-sentences nil
1504   "Capitalize sentence-starting words.
1505 Valid values are nil, t, `head', `first', `last', an integer or a
1506 predicate.  See Info node `(gnus)Customizing Articles'."
1507   :version "21.1"
1508   :group 'gnus-article-treat
1509   :link '(custom-manual "(gnus)Customizing Articles")
1510   :type gnus-article-treat-custom)
1511
1512 (defcustom gnus-treat-wash-html nil
1513   "Format as HTML.
1514 Valid values are nil, t, `head', `first', `last', an integer or a
1515 predicate.  See Info node `(gnus)Customizing Articles'."
1516   :version "22.1"
1517   :group 'gnus-article-treat
1518   :link '(custom-manual "(gnus)Customizing Articles")
1519   :type gnus-article-treat-custom)
1520
1521 (defcustom gnus-treat-fill-long-lines nil
1522   "Fill long lines.
1523 Valid values are nil, t, `head', `first', `last', an integer or a
1524 predicate.  See Info node `(gnus)Customizing Articles'."
1525   :group 'gnus-article-treat
1526   :link '(custom-manual "(gnus)Customizing Articles")
1527   :type gnus-article-treat-custom)
1528
1529 (defcustom gnus-treat-play-sounds nil
1530   "Play sounds.
1531 Valid values are nil, t, `head', `first', `last', an integer or a
1532 predicate.  See Info node `(gnus)Customizing Articles'."
1533   :version "21.1"
1534   :group 'gnus-article-treat
1535   :link '(custom-manual "(gnus)Customizing Articles")
1536   :type gnus-article-treat-custom)
1537
1538 (defcustom gnus-treat-translate nil
1539   "Translate articles from one language to another.
1540 Valid values are nil, t, `head', `first', `last', an integer or a
1541 predicate.  See Info node `(gnus)Customizing Articles'."
1542   :version "21.1"
1543   :group 'gnus-article-treat
1544   :link '(custom-manual "(gnus)Customizing Articles")
1545   :type gnus-article-treat-custom)
1546
1547 (defcustom gnus-treat-x-pgp-sig nil
1548   "Verify X-PGP-Sig.
1549 To automatically treat X-PGP-Sig, set it to head.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate.  See Info node `(gnus)Customizing Articles'."
1552   :version "22.1"
1553   :group 'gnus-article-treat
1554   :group 'mime-security
1555   :link '(custom-manual "(gnus)Customizing Articles")
1556   :type gnus-article-treat-custom)
1557
1558 (defvar gnus-article-encrypt-protocol-alist
1559   '(("PGP" . mml2015-self-encrypt)))
1560
1561 ;; Set to nil if more than one protocol added to
1562 ;; gnus-article-encrypt-protocol-alist.
1563 (defcustom gnus-article-encrypt-protocol "PGP"
1564   "The protocol used for encrypt articles.
1565 It is a string, such as \"PGP\". If nil, ask user."
1566   :version "22.1"
1567   :type 'string
1568   :group 'mime-security)
1569
1570 (defvar gnus-article-wash-function nil
1571   "Function used for converting HTML into text.")
1572
1573 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1574                               (mm-coding-system-p 'utf-8)
1575                               (executable-find idna-program))
1576   "Whether IDNA decoding of headers is used when viewing messages.
1577 This requires GNU Libidn, and by default only enabled if it is found."
1578   :version "22.1"
1579   :group 'gnus-article-headers
1580   :type 'boolean)
1581
1582 (defcustom gnus-article-over-scroll nil
1583   "If non-nil, allow scrolling the article buffer even when there no more text."
1584   :version "22.1"
1585   :group 'gnus-article
1586   :type 'boolean)
1587
1588 ;;; Internal variables
1589
1590 (defvar gnus-english-month-names
1591   '("January" "February" "March" "April" "May" "June" "July" "August"
1592     "September" "October" "November" "December"))
1593
1594 (defvar gnus-button-regexp nil)
1595 (defvar gnus-button-marker-list nil)
1596 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1597
1598 (defvar gnus-button-last nil)
1599 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1600
1601 (defvar article-goto-body-goes-to-point-min-p nil)
1602 (defvar gnus-article-wash-types nil)
1603 (defvar gnus-article-emphasis-alist nil)
1604 (defvar gnus-article-image-alist nil)
1605
1606 (defvar gnus-article-mime-handle-alist-1 nil)
1607 (defvar gnus-treatment-function-alist
1608   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1609     (gnus-treat-strip-banner gnus-article-strip-banner)
1610     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1611     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1612     (gnus-treat-buttonize gnus-article-add-buttons)
1613     (gnus-treat-fill-article gnus-article-fill-cited-article)
1614     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1615     (gnus-treat-strip-cr gnus-article-remove-cr)
1616     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1617     (gnus-treat-date-ut gnus-article-date-ut)
1618     (gnus-treat-date-local gnus-article-date-local)
1619     (gnus-treat-date-english gnus-article-date-english)
1620     (gnus-treat-date-original gnus-article-date-original)
1621     (gnus-treat-date-user-defined gnus-article-date-user)
1622     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1623     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1624     (gnus-treat-display-x-face gnus-article-display-x-face)
1625     (gnus-treat-display-face gnus-article-display-face)
1626     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1627     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1628     (gnus-treat-hide-signature gnus-article-hide-signature)
1629     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1630     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1631     (gnus-treat-strip-pem gnus-article-hide-pem)
1632     (gnus-treat-from-picon gnus-treat-from-picon)
1633     (gnus-treat-mail-picon gnus-treat-mail-picon)
1634     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1635     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1636     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637     (gnus-treat-strip-trailing-blank-lines
1638      gnus-article-remove-trailing-blank-lines)
1639     (gnus-treat-strip-leading-blank-lines
1640      gnus-article-strip-leading-blank-lines)
1641     (gnus-treat-strip-multiple-blank-lines
1642      gnus-article-strip-multiple-blank-lines)
1643     (gnus-treat-overstrike gnus-article-treat-overstrike)
1644     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1645     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1646     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1647     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1648     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1649     (gnus-treat-display-smileys gnus-treat-smiley)
1650     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1651     (gnus-treat-wash-html gnus-article-wash-html)
1652     (gnus-treat-emphasize gnus-article-emphasize)
1653     (gnus-treat-hide-citation gnus-article-hide-citation)
1654     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1655     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1656     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1657     (gnus-treat-play-sounds gnus-earcon-display)))
1658
1659 (defvar gnus-article-mime-handle-alist nil)
1660 (defvar article-lapsed-timer nil)
1661 (defvar gnus-article-current-summary nil)
1662
1663 (defvar gnus-article-mode-syntax-table
1664   (let ((table (copy-syntax-table text-mode-syntax-table)))
1665     ;; This causes the citation match run O(2^n).
1666     ;; (modify-syntax-entry ?- "w" table)
1667     (modify-syntax-entry ?> ")<" table)
1668     (modify-syntax-entry ?< "(>" table)
1669     ;; make M-. in article buffers work for `foo' strings
1670     (modify-syntax-entry ?' " " table)
1671     (modify-syntax-entry ?` " " table)
1672     table)
1673   "Syntax table used in article mode buffers.
1674 Initialized from `text-mode-syntax-table.")
1675
1676 (defvar gnus-save-article-buffer nil)
1677
1678 (defvar gnus-article-mode-line-format-alist
1679   (nconc '((?w (gnus-article-wash-status) ?s)
1680            (?m (gnus-article-mime-part-status) ?s))
1681          gnus-summary-mode-line-format-alist))
1682
1683 (defvar gnus-number-of-articles-to-be-saved nil)
1684
1685 (defvar gnus-inhibit-hiding nil)
1686
1687 (defvar gnus-article-edit-mode nil)
1688
1689 ;;; Macros for dealing with the article buffer.
1690
1691 (defmacro gnus-with-article-headers (&rest forms)
1692   `(save-excursion
1693      (set-buffer gnus-article-buffer)
1694      (save-restriction
1695        (let ((inhibit-read-only t)
1696              (inhibit-point-motion-hooks t)
1697              (case-fold-search t))
1698          (article-narrow-to-head)
1699          ,@forms))))
1700
1701 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1702 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1703
1704 (defmacro gnus-with-article-buffer (&rest forms)
1705   `(save-excursion
1706      (set-buffer gnus-article-buffer)
1707      (let ((inhibit-read-only t))
1708        ,@forms)))
1709
1710 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1711 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1712
1713 (defun gnus-article-goto-header (header)
1714   "Go to HEADER, which is a regular expression."
1715   (re-search-forward (concat "^\\(" header "\\):") nil t))
1716
1717 (defsubst gnus-article-hide-text (b e props)
1718   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1719   (gnus-add-text-properties-when 'article-type nil b e props)
1720   (when (memq 'intangible props)
1721     (put-text-property
1722      (max (1- b) (point-min))
1723      b 'intangible (cddr (memq 'intangible props)))))
1724
1725 (defsubst gnus-article-unhide-text (b e)
1726   "Remove hidden text properties from region between B and E."
1727   (remove-text-properties b e gnus-hidden-properties)
1728   (when (memq 'intangible gnus-hidden-properties)
1729     (put-text-property (max (1- b) (point-min))
1730                        b 'intangible nil)))
1731
1732 (defun gnus-article-hide-text-type (b e type)
1733   "Hide text of TYPE between B and E."
1734   (gnus-add-wash-type type)
1735   (gnus-article-hide-text
1736    b e (cons 'article-type (cons type gnus-hidden-properties))))
1737
1738 (defun gnus-article-unhide-text-type (b e type)
1739   "Unhide text of TYPE between B and E."
1740   (gnus-delete-wash-type type)
1741   (remove-text-properties
1742    b e (cons 'article-type (cons type gnus-hidden-properties)))
1743   (when (memq 'intangible gnus-hidden-properties)
1744     (put-text-property (max (1- b) (point-min))
1745                        b 'intangible nil)))
1746
1747 (defun gnus-article-hide-text-of-type (type)
1748   "Hide text of TYPE in the current buffer."
1749   (save-excursion
1750     (let ((b (point-min))
1751           (e (point-max)))
1752       (while (setq b (text-property-any b e 'article-type type))
1753         (add-text-properties b (incf b) gnus-hidden-properties)))))
1754
1755 (defun gnus-article-delete-text-of-type (type)
1756   "Delete text of TYPE in the current buffer."
1757   (save-excursion
1758     (let ((b (point-min)))
1759       (if (eq type 'multipart)
1760           ;; Remove MIME buttons associated with multipart/alternative parts.
1761           (progn
1762             (goto-char b)
1763             (while (if (get-text-property (point) 'gnus-part)
1764                        (setq b (point))
1765                      (when (setq b (next-single-property-change (point)
1766                                                                 'gnus-part))
1767                        (goto-char b)
1768                        t))
1769               (end-of-line)
1770               (skip-chars-forward "\n")
1771               (when (eq (get-text-property b 'article-type) 'multipart)
1772                 (delete-region b (point)))))
1773         (while (setq b (text-property-any b (point-max) 'article-type type))
1774           (delete-region
1775            b (or (text-property-not-all b (point-max) 'article-type type)
1776                  (point-max))))))))
1777
1778 (defun gnus-article-delete-invisible-text ()
1779   "Delete all invisible text in the current buffer."
1780   (save-excursion
1781     (let ((b (point-min)))
1782       (while (setq b (text-property-any b (point-max) 'invisible t))
1783         (delete-region
1784          b (or (text-property-not-all b (point-max) 'invisible t)
1785                (point-max)))))))
1786
1787 (defun gnus-article-text-type-exists-p (type)
1788   "Say whether any text of type TYPE exists in the buffer."
1789   (text-property-any (point-min) (point-max) 'article-type type))
1790
1791 (defsubst gnus-article-header-rank ()
1792   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1793   (let ((list gnus-sorted-header-list)
1794         (i 1))
1795     (while list
1796       (if (looking-at (car list))
1797           (setq list nil)
1798         (setq list (cdr list))
1799         (incf i)))
1800       i))
1801
1802 (defun article-hide-headers (&optional arg delete)
1803   "Hide unwanted headers and possibly sort them as well."
1804   (interactive)
1805   ;; This function might be inhibited.
1806   (unless gnus-inhibit-hiding
1807     (let ((inhibit-read-only nil)
1808           (case-fold-search t)
1809           (max (1+ (length gnus-sorted-header-list)))
1810           (inhibit-point-motion-hooks t)
1811           (cur (current-buffer))
1812           ignored visible beg)
1813       (save-excursion
1814         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1815         ;; group parameters, so we should go to the summary buffer.
1816         (when (prog1
1817                   (condition-case nil
1818                       (progn (set-buffer gnus-summary-buffer) t)
1819                     (error nil))
1820                 (setq ignored (when (not gnus-visible-headers)
1821                                 (cond ((stringp gnus-ignored-headers)
1822                                        gnus-ignored-headers)
1823                                       ((listp gnus-ignored-headers)
1824                                        (mapconcat 'identity
1825                                                   gnus-ignored-headers
1826                                                   "\\|"))))
1827                       visible (cond ((stringp gnus-visible-headers)
1828                                      gnus-visible-headers)
1829                                     ((and gnus-visible-headers
1830                                           (listp gnus-visible-headers))
1831                                      (mapconcat 'identity
1832                                                 gnus-visible-headers
1833                                                 "\\|")))))
1834           (set-buffer cur))
1835         (save-restriction
1836           ;; First we narrow to just the headers.
1837           (article-narrow-to-head)
1838           ;; Hide any "From " lines at the beginning of (mail) articles.
1839           (while (looking-at "From ")
1840             (forward-line 1))
1841           (unless (bobp)
1842             (delete-region (point-min) (point)))
1843           ;; Then treat the rest of the header lines.
1844           ;; Then we use the two regular expressions
1845           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1846           ;; select which header lines is to remain visible in the
1847           ;; article buffer.
1848           (while (re-search-forward "^[^ \t:]*:" nil t)
1849             (beginning-of-line)
1850             ;; Mark the rank of the header.
1851             (put-text-property
1852              (point) (1+ (point)) 'message-rank
1853              (if (or (and visible (looking-at visible))
1854                      (and ignored
1855                           (not (looking-at ignored))))
1856                  (gnus-article-header-rank)
1857                (+ 2 max)))
1858             (forward-line 1))
1859           (message-sort-headers-1)
1860           (when (setq beg (text-property-any
1861                            (point-min) (point-max) 'message-rank (+ 2 max)))
1862             ;; We delete the unwanted headers.
1863             (gnus-add-wash-type 'headers)
1864             (add-text-properties (point-min) (+ 5 (point-min))
1865                                  '(article-type headers dummy-invisible t))
1866             (delete-region beg (point-max))))))))
1867
1868 (defun article-hide-boring-headers (&optional arg)
1869   "Toggle hiding of headers that aren't very interesting.
1870 If given a negative prefix, always show; if given a positive prefix,
1871 always hide."
1872   (interactive (gnus-article-hidden-arg))
1873   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1874              (not gnus-show-all-headers))
1875     (save-excursion
1876       (save-restriction
1877         (let ((inhibit-read-only t)
1878               (inhibit-point-motion-hooks t))
1879           (article-narrow-to-head)
1880           (dolist (elem gnus-boring-article-headers)
1881             (goto-char (point-min))
1882             (cond
1883              ;; Hide empty headers.
1884              ((eq elem 'empty)
1885               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1886                 (forward-line -1)
1887                 (gnus-article-hide-text-type
1888                  (point-at-bol)
1889                  (progn
1890                    (end-of-line)
1891                    (if (re-search-forward "^[^ \t]" nil t)
1892                        (match-beginning 0)
1893                      (point-max)))
1894                  'boring-headers)))
1895              ;; Hide boring Newsgroups header.
1896              ((eq elem 'newsgroups)
1897               (when (gnus-string-equal
1898                      (gnus-fetch-field "newsgroups")
1899                      (gnus-group-real-name
1900                       (if (boundp 'gnus-newsgroup-name)
1901                           gnus-newsgroup-name
1902                         "")))
1903                 (gnus-article-hide-header "newsgroups")))
1904              ((eq elem 'to-address)
1905               (let ((to (message-fetch-field "to"))
1906                     (to-address
1907                      (gnus-parameter-to-address
1908                       (if (boundp 'gnus-newsgroup-name)
1909                           gnus-newsgroup-name ""))))
1910                 (when (and to to-address
1911                            (ignore-errors
1912                              (gnus-string-equal
1913                               ;; only one address in To
1914                               (nth 1 (mail-extract-address-components to))
1915                               to-address)))
1916                   (gnus-article-hide-header "to"))))
1917              ((eq elem 'to-list)
1918               (let ((to (message-fetch-field "to"))
1919                     (to-list
1920                      (gnus-parameter-to-list
1921                       (if (boundp 'gnus-newsgroup-name)
1922                           gnus-newsgroup-name ""))))
1923                 (when (and to to-list
1924                            (ignore-errors
1925                              (gnus-string-equal
1926                               ;; only one address in To
1927                               (nth 1 (mail-extract-address-components to))
1928                               to-list)))
1929                   (gnus-article-hide-header "to"))))
1930              ((eq elem 'cc-list)
1931               (let ((cc (message-fetch-field "cc"))
1932                     (to-list
1933                      (gnus-parameter-to-list
1934                       (if (boundp 'gnus-newsgroup-name)
1935                           gnus-newsgroup-name ""))))
1936                 (when (and cc to-list
1937                            (ignore-errors
1938                              (gnus-string-equal
1939                               ;; only one address in CC
1940                               (nth 1 (mail-extract-address-components cc))
1941                               to-list)))
1942                   (gnus-article-hide-header "cc"))))
1943              ((eq elem 'followup-to)
1944               (when (gnus-string-equal
1945                      (message-fetch-field "followup-to")
1946                      (message-fetch-field "newsgroups"))
1947                 (gnus-article-hide-header "followup-to")))
1948              ((eq elem 'reply-to)
1949               (if (gnus-group-find-parameter
1950                    gnus-newsgroup-name 'broken-reply-to)
1951                   (gnus-article-hide-header "reply-to")
1952                 (let ((from (message-fetch-field "from"))
1953                       (reply-to (message-fetch-field "reply-to")))
1954                   (when
1955                       (and
1956                        from reply-to
1957                        (ignore-errors
1958                          (equal
1959                           (sort (mapcar
1960                                  (lambda (x) (downcase (cadr x)))
1961                                  (mail-extract-address-components from t))
1962                                 'string<)
1963                           (sort (mapcar
1964                                  (lambda (x) (downcase (cadr x)))
1965                                  (mail-extract-address-components reply-to t))
1966                                 'string<))))
1967                     (gnus-article-hide-header "reply-to")))))
1968              ((eq elem 'date)
1969               (let ((date (message-fetch-field "date")))
1970                 (when (and date
1971                            (< (days-between (current-time-string) date)
1972                               4))
1973                   (gnus-article-hide-header "date"))))
1974              ((eq elem 'long-to)
1975               (let ((to (message-fetch-field "to"))
1976                     (cc (message-fetch-field "cc")))
1977                 (when (> (length to) 1024)
1978                   (gnus-article-hide-header "to"))
1979                 (when (> (length cc) 1024)
1980                   (gnus-article-hide-header "cc"))))
1981              ((eq elem 'many-to)
1982               (let ((to-count 0)
1983                     (cc-count 0))
1984                 (goto-char (point-min))
1985                 (while (re-search-forward "^to:" nil t)
1986                   (setq to-count (1+ to-count)))
1987                 (when (> to-count 1)
1988                   (while (> to-count 0)
1989                     (goto-char (point-min))
1990                     (save-restriction
1991                       (re-search-forward "^to:" nil nil to-count)
1992                       (forward-line -1)
1993                       (narrow-to-region (point) (point-max))
1994                       (gnus-article-hide-header "to"))
1995                     (setq to-count (1- to-count))))
1996                 (goto-char (point-min))
1997                 (while (re-search-forward "^cc:" nil t)
1998                   (setq cc-count (1+ cc-count)))
1999                 (when (> cc-count 1)
2000                   (while (> cc-count 0)
2001                     (goto-char (point-min))
2002                     (save-restriction
2003                       (re-search-forward "^cc:" nil nil cc-count)
2004                       (forward-line -1)
2005                       (narrow-to-region (point) (point-max))
2006                       (gnus-article-hide-header "cc"))
2007                     (setq cc-count (1- cc-count)))))))))))))
2008
2009 (defun gnus-article-hide-header (header)
2010   (save-excursion
2011     (goto-char (point-min))
2012     (when (re-search-forward (concat "^" header ":") nil t)
2013       (gnus-article-hide-text-type
2014        (point-at-bol)
2015        (progn
2016          (end-of-line)
2017          (if (re-search-forward "^[^ \t]" nil t)
2018              (match-beginning 0)
2019            (point-max)))
2020        'boring-headers))))
2021
2022 (defvar gnus-article-normalized-header-length 40
2023   "Length of normalized headers.")
2024
2025 (defun article-normalize-headers ()
2026   "Make all header lines 40 characters long."
2027   (interactive)
2028   (let ((inhibit-read-only t)
2029         column)
2030     (save-excursion
2031       (save-restriction
2032         (article-narrow-to-head)
2033         (while (not (eobp))
2034           (cond
2035            ((< (setq column (- (point-at-eol) (point)))
2036                gnus-article-normalized-header-length)
2037             (end-of-line)
2038             (insert (make-string
2039                      (- gnus-article-normalized-header-length column)
2040                      ? )))
2041            ((> column gnus-article-normalized-header-length)
2042             (gnus-put-text-property
2043              (progn
2044                (forward-char gnus-article-normalized-header-length)
2045                (point))
2046              (point-at-eol)
2047              'invisible t))
2048            (t
2049             ;; Do nothing.
2050             ))
2051           (forward-line 1))))))
2052
2053 (defun article-treat-dumbquotes ()
2054   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2055 Note that this function guesses whether a character is a sm*rtq**t* or
2056 not, so it should only be used interactively.
2057
2058 Sm*rtq**t*s are M****s***'s unilateral extension to the
2059 iso-8859-1 character map in an attempt to provide more quoting
2060 characters.  If you see something like \\222 or \\264 where
2061 you're expecting some kind of apostrophe or quotation mark, then
2062 try this wash."
2063   (interactive)
2064   (article-translate-strings gnus-article-dumbquotes-map))
2065
2066 (defun article-translate-characters (from to)
2067   "Translate all characters in the body of the article according to FROM and TO.
2068 FROM is a string of characters to translate from; to is a string of
2069 characters to translate to."
2070   (save-excursion
2071     (when (article-goto-body)
2072       (let ((inhibit-read-only t)
2073             (x (make-string 225 ?x))
2074             (i -1))
2075         (while (< (incf i) (length x))
2076           (aset x i i))
2077         (setq i 0)
2078         (while (< i (length from))
2079           (aset x (aref from i) (aref to i))
2080           (incf i))
2081         (translate-region (point) (point-max) x)))))
2082
2083 (defun article-translate-strings (map)
2084   "Translate all string in the body of the article according to MAP.
2085 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2086   (save-excursion
2087     (when (article-goto-body)
2088       (let ((inhibit-read-only t))
2089         (dolist (elem map)
2090           (save-excursion
2091             (while (search-forward (car elem) nil t)
2092               (replace-match (cadr elem)))))))))
2093
2094 (defun article-treat-overstrike ()
2095   "Translate overstrikes into bold text."
2096   (interactive)
2097   (save-excursion
2098     (when (article-goto-body)
2099       (let ((inhibit-read-only t))
2100         (while (search-forward "\b" nil t)
2101           (let ((next (char-after))
2102                 (previous (char-after (- (point) 2))))
2103             ;; We do the boldification/underlining by hiding the
2104             ;; overstrikes and putting the proper text property
2105             ;; on the letters.
2106             (cond
2107              ((eq next previous)
2108               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2109               (put-text-property (point) (1+ (point)) 'face 'bold))
2110              ((eq next ?_)
2111               (gnus-article-hide-text-type
2112                (1- (point)) (1+ (point)) 'overstrike)
2113               (put-text-property
2114                (- (point) 2) (1- (point)) 'face 'underline))
2115              ((eq previous ?_)
2116               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2117               (put-text-property
2118                (point) (1+ (point)) 'face 'underline)))))))))
2119
2120 (defun article-treat-ansi-sequences ()
2121   "Translate ANSI SGR control sequences into overlays or extents."
2122   (interactive)
2123   (save-excursion
2124     (when (article-goto-body)
2125       (let ((inhibit-read-only t))
2126         (ansi-color-apply-on-region (point) (point-max))))))
2127
2128 (defun gnus-article-treat-unfold-headers ()
2129   "Unfold folded message headers.
2130 Only the headers that fit into the current window width will be
2131 unfolded."
2132   (interactive)
2133   (gnus-with-article-headers
2134     (let (length)
2135       (while (not (eobp))
2136         (save-restriction
2137           (mail-header-narrow-to-field)
2138           (let ((header (buffer-string)))
2139             (with-temp-buffer
2140               (insert header)
2141               (goto-char (point-min))
2142               (while (re-search-forward "\n[\t ]" nil t)
2143                 (replace-match " " t t)))
2144             (setq length (- (point-max) (point-min) 1)))
2145           (when (< length (window-width))
2146             (while (re-search-forward "\n[\t ]" nil t)
2147               (replace-match " " t t)))
2148           (goto-char (point-max)))))))
2149
2150 (defun gnus-article-treat-fold-headers ()
2151   "Fold message headers."
2152   (interactive)
2153   (gnus-with-article-headers
2154     (while (not (eobp))
2155       (save-restriction
2156         (mail-header-narrow-to-field)
2157         (mail-header-fold-field)
2158         (goto-char (point-max))))))
2159
2160 (defun gnus-treat-smiley ()
2161   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2162   (interactive)
2163   (gnus-with-article-buffer
2164     (if (memq 'smiley gnus-article-wash-types)
2165         (gnus-delete-images 'smiley)
2166       (article-goto-body)
2167       (let ((images (smiley-region (point) (point-max))))
2168         (when images
2169           (gnus-add-wash-type 'smiley)
2170           (dolist (image images)
2171             (gnus-add-image 'smiley image)))))))
2172
2173 (defun gnus-article-remove-images ()
2174   "Remove all images from the article buffer."
2175   (interactive)
2176   (gnus-with-article-buffer
2177     (dolist (elem gnus-article-image-alist)
2178       (gnus-delete-images (car elem)))))
2179
2180 (defun gnus-article-treat-fold-newsgroups ()
2181   "Unfold folded message headers.
2182 Only the headers that fit into the current window width will be
2183 unfolded."
2184   (interactive)
2185   (gnus-with-article-headers
2186     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2187       (save-restriction
2188         (mail-header-narrow-to-field)
2189         (while (re-search-forward ", *" nil t)
2190           (replace-match ", " t t))
2191         (mail-header-fold-field)
2192         (goto-char (point-max))))))
2193
2194 (defun gnus-article-treat-body-boundary ()
2195   "Place a boundary line at the end of the headers."
2196   (interactive)
2197   (when (and gnus-body-boundary-delimiter
2198              (> (length gnus-body-boundary-delimiter) 0))
2199     (gnus-with-article-headers
2200       (goto-char (point-max))
2201       (let ((start (point)))
2202         (insert "X-Boundary: ")
2203         (gnus-add-text-properties start (point) '(invisible t intangible t))
2204         (insert (let (str)
2205                   (while (>= (1- (window-width)) (length str))
2206                     (setq str (concat str gnus-body-boundary-delimiter)))
2207                   (substring str 0 (1- (window-width))))
2208                 "\n")
2209         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2210
2211 (defun article-fill-long-lines ()
2212   "Fill lines that are wider than the window width."
2213   (interactive)
2214   (save-excursion
2215     (let ((inhibit-read-only t)
2216           (width (window-width (get-buffer-window (current-buffer)))))
2217       (save-restriction
2218         (article-goto-body)
2219         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2220           (while (not (eobp))
2221             (end-of-line)
2222             (when (>= (current-column) (min fill-column width))
2223               (narrow-to-region (min (1+ (point)) (point-max))
2224                                 (point-at-bol))
2225               (let ((goback (point-marker)))
2226                 (fill-paragraph nil)
2227                 (goto-char (marker-position goback)))
2228               (widen))
2229             (forward-line 1)))))))
2230
2231 (defun article-capitalize-sentences ()
2232   "Capitalize the first word in each sentence."
2233   (interactive)
2234   (save-excursion
2235     (let ((inhibit-read-only t)
2236           (paragraph-start "^[\n\^L]"))
2237       (article-goto-body)
2238       (while (not (eobp))
2239         (capitalize-word 1)
2240         (forward-sentence)))))
2241
2242 (defun article-remove-cr ()
2243   "Remove trailing CRs and then translate remaining CRs into LFs."
2244   (interactive)
2245   (save-excursion
2246     (let ((inhibit-read-only t))
2247       (goto-char (point-min))
2248       (while (re-search-forward "\r+$" nil t)
2249         (replace-match "" t t))
2250       (goto-char (point-min))
2251       (while (search-forward "\r" nil t)
2252         (replace-match "\n" t t)))))
2253
2254 (defun article-remove-trailing-blank-lines ()
2255   "Remove all trailing blank lines from the article."
2256   (interactive)
2257   (save-excursion
2258     (let ((inhibit-read-only t))
2259       (goto-char (point-max))
2260       (delete-region
2261        (point)
2262        (progn
2263          (while (and (not (bobp))
2264                      (looking-at "^[ \t]*$")
2265                      (not (gnus-annotation-in-region-p
2266                            (point) (point-at-eol))))
2267            (forward-line -1))
2268          (forward-line 1)
2269          (point))))))
2270
2271 (eval-when-compile
2272   (defvar gnus-face-properties-alist))
2273
2274 (defun article-display-face ()
2275   "Display any Face headers in the header."
2276   (interactive)
2277   (let ((wash-face-p buffer-read-only))
2278     (gnus-with-article-headers
2279       ;; When displaying parts, this function can be called several times on
2280       ;; the same article, without any intended toggle semantic (as typing `W
2281       ;; D d' would have). So face deletion must occur only when we come from
2282       ;; an interactive command, that is when the *Article* buffer is
2283       ;; read-only.
2284       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2285           (gnus-delete-images 'face)
2286         (let (face faces from)
2287           (save-current-buffer
2288             (when (and wash-face-p
2289                        (gnus-buffer-live-p gnus-original-article-buffer)
2290                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2291               (set-buffer gnus-original-article-buffer))
2292             (save-restriction
2293               (mail-narrow-to-head)
2294               (while (gnus-article-goto-header "Face")
2295                 (push (mail-header-field-value) faces))))
2296           (when faces
2297             (goto-char (point-min))
2298             (let ((from (gnus-article-goto-header "from"))
2299                   png image)
2300               (unless from
2301                 (insert "From:")
2302                 (setq from (point))
2303                 (insert "[no `from' set]\n"))
2304               (while faces
2305                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2306                   (setq image
2307                         (apply 'gnus-create-image png 'png t
2308                                (cdr (assq 'png gnus-face-properties-alist))))
2309                   (goto-char from)
2310                   (gnus-add-wash-type 'face)
2311                   (gnus-add-image 'face image)
2312                   (gnus-put-image image nil 'face))))))))))
2313
2314 (defun article-display-x-face (&optional force)
2315   "Look for an X-Face header and display it if present."
2316   (interactive (list 'force))
2317   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2318     (gnus-with-article-headers
2319       ;; Delete the old process, if any.
2320       (when (process-status "article-x-face")
2321         (delete-process "article-x-face"))
2322       ;; See the comment in `article-display-face'.
2323       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2324           ;; We have already displayed X-Faces, so we remove them
2325           ;; instead.
2326           (gnus-delete-images 'xface)
2327         ;; Display X-Faces.
2328         (let (x-faces from face)
2329           (save-current-buffer
2330             (when (and wash-face-p
2331                        (gnus-buffer-live-p gnus-original-article-buffer)
2332                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2333               ;; If type `W f', use gnus-original-article-buffer,
2334               ;; otherwise use the current buffer because displaying
2335               ;; RFC822 parts calls this function too.
2336               (set-buffer gnus-original-article-buffer))
2337             (save-restriction
2338               (mail-narrow-to-head)
2339               (while (gnus-article-goto-header "X-Face")
2340                 (push (mail-header-field-value) x-faces))
2341               (setq from (message-fetch-field "from"))))
2342           ;; Sending multiple EOFs to xv doesn't work, so we only do a
2343           ;; single external face.
2344           (when (stringp gnus-article-x-face-command)
2345             (setq x-faces (list (car x-faces))))
2346           (when (and x-faces
2347                      gnus-article-x-face-command
2348                      (or force
2349                          ;; Check whether this face is censored.
2350                          (not gnus-article-x-face-too-ugly)
2351                          (and from
2352                               (not (string-match gnus-article-x-face-too-ugly
2353                                                  from)))))
2354             (while (setq face (pop x-faces))
2355               ;; We display the face.
2356               (cond ((stringp gnus-article-x-face-command)
2357                      ;; The command is a string, so we interpret the command
2358                      ;; as a, well, command, and fork it off.
2359                      (let ((process-connection-type nil))
2360                        (gnus-set-process-query-on-exit-flag
2361                         (start-process
2362                          "article-x-face" nil shell-file-name
2363                          shell-command-switch gnus-article-x-face-command)
2364                         nil)
2365                        (with-temp-buffer
2366                          (insert face)
2367                          (process-send-region "article-x-face"
2368                                               (point-min) (point-max)))
2369                        (process-send-eof "article-x-face")))
2370                     ((functionp gnus-article-x-face-command)
2371                      ;; The command is a lisp function, so we call it.
2372                      (funcall gnus-article-x-face-command face))
2373                     (t
2374                      (error "%s is not a function"
2375                             gnus-article-x-face-command))))))))))
2376
2377 (defun article-decode-mime-words ()
2378   "Decode all MIME-encoded words in the article."
2379   (interactive)
2380   (gnus-with-article-buffer
2381     (let ((inhibit-point-motion-hooks t)
2382           (mail-parse-charset gnus-newsgroup-charset)
2383           (mail-parse-ignored-charsets
2384            (with-current-buffer gnus-summary-buffer
2385              gnus-newsgroup-ignored-charsets)))
2386       (mail-decode-encoded-word-region (point-min) (point-max)))))
2387
2388 (defun article-decode-charset (&optional prompt)
2389   "Decode charset-encoded text in the article.
2390 If PROMPT (the prefix), prompt for a coding system to use."
2391   (interactive "P")
2392   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2393         (inhibit-read-only t)
2394         (mail-parse-charset gnus-newsgroup-charset)
2395         (mail-parse-ignored-charsets
2396          (save-excursion (condition-case nil
2397                              (set-buffer gnus-summary-buffer)
2398                            (error))
2399                          gnus-newsgroup-ignored-charsets))
2400         ct cte ctl charset format)
2401     (save-excursion
2402       (save-restriction
2403         (article-narrow-to-head)
2404         (setq ct (message-fetch-field "Content-Type" t)
2405               cte (message-fetch-field "Content-Transfer-Encoding" t)
2406               ctl (and ct (mail-header-parse-content-type ct))
2407               charset (cond
2408                        (prompt
2409                         (mm-read-coding-system "Charset to decode: "))
2410                        (ctl
2411                         (mail-content-type-get ctl 'charset)))
2412               format (and ctl (mail-content-type-get ctl 'format)))
2413         (when cte
2414           (setq cte (mail-header-strip cte)))
2415         (if (and ctl (not (string-match "/" (car ctl))))
2416             (setq ctl nil))
2417         (goto-char (point-max)))
2418       (forward-line 1)
2419       (save-restriction
2420         (narrow-to-region (point) (point-max))
2421         (when (and (eq mail-parse-charset 'gnus-decoded)
2422                    (eq (mm-body-7-or-8) '8bit))
2423           ;; The text code could have been decoded.
2424           (setq charset mail-parse-charset))
2425         (when (and (or (not ctl)
2426                        (equal (car ctl) "text/plain"))
2427                    (not format)) ;; article with format will decode later.
2428           (mm-decode-body
2429            charset (and cte (intern (downcase
2430                                      (gnus-strip-whitespace cte))))
2431            (car ctl)))))))
2432
2433 (defun article-decode-encoded-words ()
2434   "Remove encoded-word encoding from headers."
2435   (let ((inhibit-point-motion-hooks t)
2436         (mail-parse-charset gnus-newsgroup-charset)
2437         (mail-parse-ignored-charsets
2438          (save-excursion (condition-case nil
2439                              (set-buffer gnus-summary-buffer)
2440                            (error))
2441                          gnus-newsgroup-ignored-charsets))
2442         (inhibit-read-only t))
2443     (save-restriction
2444       (article-narrow-to-head)
2445       (funcall gnus-decode-header-function (point-min) (point-max)))))
2446
2447 (defun article-decode-group-name ()
2448   "Decode group names in `Newsgroups:'."
2449   (let ((inhibit-point-motion-hooks t)
2450         (inhibit-read-only t)
2451         (method (gnus-find-method-for-group gnus-newsgroup-name)))
2452     (when (and (or gnus-group-name-charset-method-alist
2453                    gnus-group-name-charset-group-alist)
2454                (gnus-buffer-live-p gnus-original-article-buffer))
2455       (save-restriction
2456         (article-narrow-to-head)
2457         (with-current-buffer gnus-original-article-buffer
2458           (goto-char (point-min)))
2459         (while (re-search-forward
2460                 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2461           (replace-match (save-match-data
2462                            (gnus-decode-newsgroups
2463                             ;; XXX how to use data in article buffer?
2464                             (with-current-buffer gnus-original-article-buffer
2465                               (re-search-forward
2466                                "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2467                                nil t)
2468                               (match-string 1))
2469                             gnus-newsgroup-name method))
2470                          t t nil 1))
2471         (goto-char (point-min))
2472         (with-current-buffer gnus-original-article-buffer
2473           (goto-char (point-min)))
2474         (while (re-search-forward
2475                 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2476           (replace-match (save-match-data
2477                            (gnus-decode-newsgroups
2478                             ;; XXX how to use data in article buffer?
2479                             (with-current-buffer gnus-original-article-buffer
2480                               (re-search-forward
2481                                "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2482                                nil t)
2483                               (match-string 1))
2484                             gnus-newsgroup-name method))
2485                          t t nil 1))))))
2486
2487 (autoload 'idna-to-unicode "idna")
2488
2489 (defun article-decode-idna-rhs ()
2490   "Decode IDNA strings in RHS in various headers in current buffer.
2491 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2492 Mail-Reply-To: and Mail-Followup-To:."
2493   (when gnus-use-idna
2494     (save-restriction
2495       (let ((inhibit-point-motion-hooks t)
2496             (inhibit-read-only t))
2497         (article-narrow-to-head)
2498         (goto-char (point-min))
2499         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2500           (let (ace unicode)
2501             (when (save-match-data
2502                     (and (setq ace (match-string 1))
2503                          (save-excursion
2504                            (and (re-search-backward "^[^ \t]" nil t)
2505                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2506                          (setq unicode (idna-to-unicode ace))))
2507               (unless (string= ace unicode)
2508                 (replace-match unicode nil nil nil 1)))))))))
2509
2510 (defun article-de-quoted-unreadable (&optional force read-charset)
2511   "Translate a quoted-printable-encoded article.
2512 If FORCE, decode the article whether it is marked as quoted-printable
2513 or not.
2514 If READ-CHARSET, ask for a coding system."
2515   (interactive (list 'force current-prefix-arg))
2516   (save-excursion
2517     (let ((inhibit-read-only t) type charset)
2518       (if (gnus-buffer-live-p gnus-original-article-buffer)
2519           (with-current-buffer gnus-original-article-buffer
2520             (setq type
2521                   (gnus-fetch-field "content-transfer-encoding"))
2522             (let* ((ct (gnus-fetch-field "content-type"))
2523                    (ctl (and ct (mail-header-parse-content-type ct))))
2524               (setq charset (and ctl
2525                                  (mail-content-type-get ctl 'charset)))
2526               (if (stringp charset)
2527                   (setq charset (intern (downcase charset)))))))
2528       (if read-charset
2529           (setq charset (mm-read-coding-system "Charset: " charset)))
2530       (unless charset
2531         (setq charset gnus-newsgroup-charset))
2532       (when (or force
2533                 (and type (let ((case-fold-search t))
2534                             (string-match "quoted-printable" type))))
2535         (article-goto-body)
2536         (quoted-printable-decode-region
2537          (point) (point-max) (mm-charset-to-coding-system charset))))))
2538
2539 (defun article-de-base64-unreadable (&optional force read-charset)
2540   "Translate a base64 article.
2541 If FORCE, decode the article whether it is marked as base64 not.
2542 If READ-CHARSET, ask for a coding system."
2543   (interactive (list 'force current-prefix-arg))
2544   (save-excursion
2545     (let ((inhibit-read-only t) type charset)
2546       (if (gnus-buffer-live-p gnus-original-article-buffer)
2547           (with-current-buffer gnus-original-article-buffer
2548             (setq type
2549                   (gnus-fetch-field "content-transfer-encoding"))
2550             (let* ((ct (gnus-fetch-field "content-type"))
2551                    (ctl (and ct (mail-header-parse-content-type ct))))
2552               (setq charset (and ctl
2553                                  (mail-content-type-get ctl 'charset)))
2554               (if (stringp charset)
2555                   (setq charset (intern (downcase charset)))))))
2556       (if read-charset
2557           (setq charset (mm-read-coding-system "Charset: " charset)))
2558       (unless charset
2559         (setq charset gnus-newsgroup-charset))
2560       (when (or force
2561                 (and type (let ((case-fold-search t))
2562                             (string-match "base64" type))))
2563         (article-goto-body)
2564         (save-restriction
2565           (narrow-to-region (point) (point-max))
2566           (base64-decode-region (point-min) (point-max))
2567           (mm-decode-coding-region
2568            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2569
2570 (eval-when-compile
2571   (require 'rfc1843))
2572
2573 (defun article-decode-HZ ()
2574   "Translate a HZ-encoded article."
2575   (interactive)
2576   (require 'rfc1843)
2577   (save-excursion
2578     (let ((inhibit-read-only t))
2579       (rfc1843-decode-region (point-min) (point-max)))))
2580
2581 (defun article-unsplit-urls ()
2582   "Remove the newlines that some other mailers insert into URLs."
2583   (interactive)
2584   (save-excursion
2585     (let ((inhibit-read-only t))
2586       (goto-char (point-min))
2587       (while (re-search-forward
2588               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2589         (replace-match "\\1\\3" t)))
2590     (when (interactive-p)
2591       (gnus-treat-article nil))))
2592
2593
2594 (defun article-wash-html (&optional read-charset)
2595   "Format an HTML article.
2596 If READ-CHARSET, ask for a coding system.  If it is a number, the
2597 charset defined in `gnus-summary-show-article-charset-alist' is used."
2598   (interactive "P")
2599   (save-excursion
2600     (let ((inhibit-read-only t)
2601           charset)
2602       (if read-charset
2603           (if (or (and (numberp read-charset)
2604                        (setq charset
2605                              (cdr
2606                               (assq read-charset
2607                                     gnus-summary-show-article-charset-alist))))
2608                   (setq charset (mm-read-coding-system "Charset: ")))
2609               (let ((gnus-summary-show-article-charset-alist
2610                      (list (cons 1 charset))))
2611                 (with-current-buffer gnus-summary-buffer
2612                   (gnus-summary-show-article 1)))
2613             (error "No charset is given"))
2614         (when (gnus-buffer-live-p gnus-original-article-buffer)
2615           (with-current-buffer gnus-original-article-buffer
2616             (let* ((ct (gnus-fetch-field "content-type"))
2617                    (ctl (and ct (mail-header-parse-content-type ct))))
2618               (setq charset (and ctl
2619                                  (mail-content-type-get ctl 'charset)))
2620               (when (stringp charset)
2621                 (setq charset (intern (downcase charset)))))))
2622         (unless charset
2623           (setq charset gnus-newsgroup-charset)))
2624       (article-goto-body)
2625       (save-window-excursion
2626         (save-restriction
2627           (narrow-to-region (point) (point-max))
2628           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2629                  (entry (assq func mm-text-html-washer-alist)))
2630             (when entry
2631               (setq func (cdr entry)))
2632             (cond
2633              ((functionp func)
2634               (funcall func))
2635              (t
2636               (apply (car func) (cdr func))))))))))
2637
2638 (defun gnus-article-wash-html-with-w3 ()
2639   "Wash the current buffer with w3."
2640   (mm-setup-w3)
2641   (let ((w3-strict-width (window-width))
2642         (url-standalone-mode t)
2643         (url-gateway-unplugged t)
2644         (w3-honor-stylesheets nil))
2645     (condition-case ()
2646         (w3-region (point-min) (point-max))
2647       (error))))
2648
2649 (defun gnus-article-wash-html-with-w3m ()
2650   "Wash the current buffer with emacs-w3m."
2651   (mm-setup-w3m)
2652   (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2653         w3m-force-redisplay)
2654     (w3m-region (point-min) (point-max)))
2655   (when (and mm-inline-text-html-with-w3m-keymap
2656              (boundp 'w3m-minor-mode-map)
2657              w3m-minor-mode-map)
2658     (add-text-properties
2659      (point-min) (point-max)
2660      (list 'keymap w3m-minor-mode-map
2661            ;; Put the mark meaning this part was rendered by emacs-w3m.
2662            'mm-inline-text-html-with-w3m t))))
2663
2664 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2665
2666 (defun gnus-article-wash-html-with-w3m-standalone ()
2667   "Wash the current buffer with w3m."
2668   (if (mm-w3m-standalone-supports-m17n-p)
2669       (progn
2670         (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2671           ;; The default.
2672           (setq charset 'iso-8859-1))
2673         (let ((coding-system-for-write charset)
2674               (coding-system-for-read charset))
2675           (call-process-region
2676            (point-min) (point-max)
2677            "w3m" t t nil "-dump" "-T" "text/html"
2678            "-I" (symbol-name charset) "-O" (symbol-name charset))))
2679     (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2680
2681 (defvar gnus-article-browse-html-temp-list nil
2682   "List of temporary files created by `gnus-article-browse-html-parts'.
2683 Internal variable.")
2684
2685 (defcustom gnus-article-browse-delete-temp 'ask
2686   "What to do with temporary files from `gnus-article-browse-html-parts'.
2687 If nil, don't delete temporary files.  If it is t, delete them on
2688 exit from the summary buffer.  If it is the symbol `file', query
2689 on each file, if it is `ask' ask once when exiting from the
2690 summary buffer."
2691   :group 'gnus-article
2692   :version "23.0" ;; No Gnus
2693   :type '(choice (const :tag "Don't delete" nil)
2694                  (const :tag "Don't ask" t)
2695                  (const :tag "Ask" ask)
2696                  (const :tag "Ask for each file" file)))
2697
2698 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2699
2700 (defun gnus-article-browse-delete-temp-files (&optional how)
2701   "Delete temp-files created by `gnus-article-browse-html-parts'."
2702   (when (and gnus-article-browse-html-temp-list
2703              (or how
2704                  (setq how gnus-article-browse-delete-temp)))
2705     (when (and (eq how 'ask)
2706                (y-or-n-p (format
2707                           "Delete all %s temporary HTML file(s)? "
2708                           (length gnus-article-browse-html-temp-list)))
2709                (setq how t)))
2710     (dolist (file gnus-article-browse-html-temp-list)
2711       (when (and (file-exists-p file)
2712                  (or (eq how t)
2713                      ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2714                      (gnus-y-or-n-p
2715                       (format "Delete temporary HTML file `%s'? " file))))
2716         (delete-file file)))
2717     ;; Also remove file from the list when not deleted or if file doesn't
2718     ;; exist anymore.
2719     (setq gnus-article-browse-html-temp-list nil))
2720   gnus-article-browse-html-temp-list)
2721
2722 (defun gnus-article-browse-html-parts (list)
2723   "View all \"text/html\" parts from LIST.
2724 Recurse into multiparts."
2725   ;; Internal function used by `gnus-article-browse-html-article'.
2726   (let ((showed))
2727     ;; Find and show the html-parts.
2728     (dolist (handle list)
2729       ;; If HTML, show it:
2730       (when (listp handle)
2731         (cond ((and (bufferp (car handle))
2732                     (string-match "text/html" (car (mm-handle-type handle))))
2733                (let ((tmp-file (mm-make-temp-file
2734                                 ;; Do we need to care for 8.3 filenames?
2735                                 "mm-" nil ".html")))
2736                  (mm-save-part-to-file handle tmp-file)
2737                  (add-to-list 'gnus-article-browse-html-temp-list tmp-file)
2738                  (add-hook 'gnus-summary-prepare-exit-hook
2739                            'gnus-article-browse-delete-temp-files)
2740                  (add-hook 'gnus-exit-gnus-hook
2741                            (lambda  ()
2742                              (gnus-article-browse-delete-temp-files t)))
2743                  (browse-url tmp-file)
2744                  (setq showed t)))
2745               ;; If multipart, recurse
2746               ((and (stringp (car handle))
2747                     (string-match "^multipart/" (car handle))
2748                     (setq showed
2749                           (or showed
2750                               (gnus-article-browse-html-parts handle))))))))
2751     showed))
2752
2753 (defun gnus-article-browse-html-article ()
2754   "View \"text/html\" parts of the current article with a WWW browser."
2755   (interactive)
2756   (save-window-excursion
2757     ;; Open raw article and select the buffer
2758     (gnus-summary-show-article t)
2759     (gnus-summary-select-article-buffer)
2760     (let ((parts (mm-dissect-buffer t t)))
2761       ;; If singlepart, enforce a list.
2762       (when (and (bufferp (car parts))
2763                  (stringp (car (mm-handle-type parts))))
2764         (setq parts (list parts)))
2765       ;; Process the list
2766       (unless (gnus-article-browse-html-parts parts)
2767         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2768       (gnus-summary-show-article))))
2769
2770 (defun article-hide-list-identifiers ()
2771   "Remove list identifies from the Subject header.
2772 The `gnus-list-identifiers' variable specifies what to do."
2773   (interactive)
2774   (let ((inhibit-point-motion-hooks t)
2775         (regexp (if (consp gnus-list-identifiers)
2776                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2777                   gnus-list-identifiers))
2778         (inhibit-read-only t))
2779     (when regexp
2780       (save-excursion
2781         (save-restriction
2782           (article-narrow-to-head)
2783           (goto-char (point-min))
2784           (while (re-search-forward
2785                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2786                   nil t)
2787             (delete-region (match-beginning 2) (match-end 0))
2788             (beginning-of-line))
2789           (when (re-search-forward
2790                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2791             (delete-region (match-beginning 1) (match-end 1))))))))
2792
2793 (defun article-hide-pem (&optional arg)
2794   "Toggle hiding of any PEM headers and signatures in the current article.
2795 If given a negative prefix, always show; if given a positive prefix,
2796 always hide."
2797   (interactive (gnus-article-hidden-arg))
2798   (unless (gnus-article-check-hidden-text 'pem arg)
2799     (save-excursion
2800       (let ((inhibit-read-only t) end)
2801         (goto-char (point-min))
2802         ;; Hide the horrendously ugly "header".
2803         (when (and (search-forward
2804                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2805                     nil t)
2806                    (setq end (1+ (match-beginning 0))))
2807           (gnus-add-wash-type 'pem)
2808           (gnus-article-hide-text-type
2809            end
2810            (if (search-forward "\n\n" nil t)
2811                (match-end 0)
2812              (point-max))
2813            'pem)
2814           ;; Hide the trailer as well
2815           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2816                                 nil t)
2817             (gnus-article-hide-text-type
2818              (match-beginning 0) (match-end 0) 'pem)))))))
2819
2820 (defun article-strip-banner ()
2821   "Strip the banners specified by the `banner' group parameter and by
2822 `gnus-article-address-banner-alist'."
2823   (interactive)
2824   (save-excursion
2825     (save-restriction
2826       (let ((inhibit-point-motion-hooks t))
2827         (when (gnus-parameter-banner gnus-newsgroup-name)
2828           (article-really-strip-banner
2829            (gnus-parameter-banner gnus-newsgroup-name)))
2830         (when gnus-article-address-banner-alist
2831           ;; Note that the From header is decoded here, so it is
2832           ;; required that the *-extract-address-components function
2833           ;; supports non-ASCII text.
2834           (let ((from (save-restriction
2835                         (widen)
2836                         (article-narrow-to-head)
2837                         (mail-fetch-field "from"))))
2838             (when (and from
2839                        (setq from
2840                              (cadr (funcall gnus-extract-address-components
2841                                             from))))
2842               (catch 'found
2843                 (dolist (pair gnus-article-address-banner-alist)
2844                   (when (string-match (car pair) from)
2845                     (throw 'found
2846                            (article-really-strip-banner (cdr pair)))))))))))))
2847
2848 (defun article-really-strip-banner (banner)
2849   "Strip the banner specified by the argument."
2850   (save-excursion
2851     (save-restriction
2852       (let ((inhibit-point-motion-hooks t)
2853             (gnus-signature-limit nil)
2854             (inhibit-read-only t))
2855         (article-goto-body)
2856         (cond
2857          ((eq banner 'signature)
2858           (when (gnus-article-narrow-to-signature)
2859             (widen)
2860             (forward-line -1)
2861             (delete-region (point) (point-max))))
2862          ((symbolp banner)
2863           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2864               (while (re-search-forward banner nil t)
2865                 (delete-region (match-beginning 0) (match-end 0)))))
2866          ((stringp banner)
2867           (while (re-search-forward banner nil t)
2868             (delete-region (match-beginning 0) (match-end 0)))))))))
2869
2870 (defun article-babel ()
2871   "Translate article using an online translation service."
2872   (interactive)
2873   (require 'babel)
2874   (gnus-with-article-buffer
2875     (when (article-goto-body)
2876       (let* ((start (point))
2877              (end (point-max))
2878              (orig (buffer-substring start end))
2879              (trans (babel-as-string orig)))
2880         (save-restriction
2881           (narrow-to-region start end)
2882           (delete-region start end)
2883           (insert trans))))))
2884
2885 (defun article-hide-signature (&optional arg)
2886   "Hide the signature in the current article.
2887 If given a negative prefix, always show; if given a positive prefix,
2888 always hide."
2889   (interactive (gnus-article-hidden-arg))
2890   (unless (gnus-article-check-hidden-text 'signature arg)
2891     (save-excursion
2892       (save-restriction
2893         (let ((inhibit-read-only t))
2894           (when (gnus-article-narrow-to-signature)
2895             (gnus-article-hide-text-type
2896              (point-min) (point-max) 'signature))))))
2897   (gnus-set-mode-line 'article))
2898
2899 (defun article-strip-headers-in-body ()
2900   "Strip offensive headers from bodies."
2901   (interactive)
2902   (save-excursion
2903     (article-goto-body)
2904     (let ((case-fold-search t))
2905       (when (looking-at "x-no-archive:")
2906         (gnus-delete-line)))))
2907
2908 (defun article-strip-leading-blank-lines ()
2909   "Remove all blank lines from the beginning of the article."
2910   (interactive)
2911   (save-excursion
2912     (let ((inhibit-point-motion-hooks t)
2913           (inhibit-read-only t))
2914       (when (article-goto-body)
2915         (while (and (not (eobp))
2916                     (looking-at "[ \t]*$"))
2917           (gnus-delete-line))))))
2918
2919 (defun article-narrow-to-head ()
2920   "Narrow the buffer to the head of the message.
2921 Point is left at the beginning of the narrowed-to region."
2922   (narrow-to-region
2923    (goto-char (point-min))
2924    (if (search-forward "\n\n" nil 1)
2925        (1- (point))
2926      (point-max)))
2927   (goto-char (point-min)))
2928
2929 (defun article-goto-body ()
2930   "Place point at the start of the body."
2931   (goto-char (point-min))
2932   (cond
2933    ;; This variable is only bound when dealing with separate
2934    ;; MIME body parts.
2935    (article-goto-body-goes-to-point-min-p
2936     t)
2937    ((search-forward "\n\n" nil t)
2938     t)
2939    (t
2940     (goto-char (point-max))
2941     nil)))
2942
2943 (defun article-strip-multiple-blank-lines ()
2944   "Replace consecutive blank lines with one empty line."
2945   (interactive)
2946   (save-excursion
2947     (let ((inhibit-point-motion-hooks t)
2948           (inhibit-read-only t))
2949       ;; First make all blank lines empty.
2950       (article-goto-body)
2951       (while (re-search-forward "^[ \t]+$" nil t)
2952         (unless (gnus-annotation-in-region-p
2953                  (match-beginning 0) (match-end 0))
2954           (replace-match "" nil t)))
2955       ;; Then replace multiple empty lines with a single empty line.
2956       (article-goto-body)
2957       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2958         (unless (gnus-annotation-in-region-p
2959                  (match-beginning 0) (match-end 0))
2960           (delete-region (match-beginning 1) (match-end 1)))))))
2961
2962 (defun article-strip-leading-space ()
2963   "Remove all white space from the beginning of the lines in the article."
2964   (interactive)
2965   (save-excursion
2966     (let ((inhibit-point-motion-hooks t)
2967           (inhibit-read-only t))
2968       (article-goto-body)
2969       (while (re-search-forward "^[ \t]+" nil t)
2970         (replace-match "" t t)))))
2971
2972 (defun article-strip-trailing-space ()
2973   "Remove all white space from the end of the lines in the article."
2974   (interactive)
2975   (save-excursion
2976     (let ((inhibit-point-motion-hooks t)
2977           (inhibit-read-only t))
2978       (article-goto-body)
2979       (while (re-search-forward "[ \t]+$" nil t)
2980         (replace-match "" t t)))))
2981
2982 (defun article-strip-blank-lines ()
2983   "Strip leading, trailing and multiple blank lines."
2984   (interactive)
2985   (article-strip-leading-blank-lines)
2986   (article-remove-trailing-blank-lines)
2987   (article-strip-multiple-blank-lines))
2988
2989 (defun article-strip-all-blank-lines ()
2990   "Strip all blank lines."
2991   (interactive)
2992   (save-excursion
2993     (let ((inhibit-point-motion-hooks t)
2994           (inhibit-read-only t))
2995       (article-goto-body)
2996       (while (re-search-forward "^[ \t]*\n" nil t)
2997         (replace-match "" t t)))))
2998
2999 (defun gnus-article-narrow-to-signature ()
3000   "Narrow to the signature; return t if a signature is found, else nil."
3001   (let ((inhibit-point-motion-hooks t))
3002     (when (gnus-article-search-signature)
3003       (forward-line 1)
3004       ;; Check whether we have some limits to what we consider
3005       ;; to be a signature.
3006       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3007                       (list gnus-signature-limit)))
3008             limit limited)
3009         (while (setq limit (pop limits))
3010           (if (or (and (integerp limit)
3011                        (< (- (point-max) (point)) limit))
3012                   (and (floatp limit)
3013                        (< (count-lines (point) (point-max)) limit))
3014                   (and (functionp limit)
3015                        (funcall limit))
3016                   (and (stringp limit)
3017                        (not (re-search-forward limit nil t))))
3018               ()                        ; This limit did not succeed.
3019             (setq limited t
3020                   limits nil)))
3021         (unless limited
3022           (narrow-to-region (point) (point-max))
3023           t)))))
3024
3025 (defun gnus-article-search-signature ()
3026   "Search the current buffer for the signature separator.
3027 Put point at the beginning of the signature separator."
3028   (let ((cur (point)))
3029     (goto-char (point-max))
3030     (if (if (stringp gnus-signature-separator)
3031             (re-search-backward gnus-signature-separator nil t)
3032           (let ((seps gnus-signature-separator))
3033             (while (and seps
3034                         (not (re-search-backward (car seps) nil t)))
3035               (pop seps))
3036             seps))
3037         t
3038       (goto-char cur)
3039       nil)))
3040
3041 (defun gnus-article-hidden-arg ()
3042   "Return the current prefix arg as a number, or 0 if no prefix."
3043   (list (if current-prefix-arg
3044             (prefix-numeric-value current-prefix-arg)
3045           0)))
3046
3047 (defun gnus-article-check-hidden-text (type arg)
3048   "Return nil if hiding is necessary.
3049 Arg can be nil or a number.  nil and positive means hide, negative
3050 means show, 0 means toggle."
3051   (save-excursion
3052     (save-restriction
3053       (let ((hide (gnus-article-hidden-text-p type)))
3054         (cond
3055          ((or (null arg)
3056               (> arg 0))
3057           nil)
3058          ((< arg 0)
3059           (gnus-article-show-hidden-text type)
3060           t)
3061          (t
3062           (if (eq hide 'hidden)
3063               (progn
3064                 (gnus-article-show-hidden-text type)
3065                 t)
3066             nil)))))))
3067
3068 (defun gnus-article-hidden-text-p (type)
3069   "Say whether the current buffer contains hidden text of type TYPE."
3070   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3071     (while (and pos
3072                 (not (get-text-property pos 'invisible))
3073                 (not (get-text-property pos 'dummy-invisible)))
3074       (setq pos
3075             (text-property-any (1+ pos) (point-max) 'article-type type)))
3076     (if pos
3077         'hidden
3078       nil)))
3079
3080 (defun gnus-article-show-hidden-text (type &optional dummy)
3081   "Show all hidden text of type TYPE.
3082 Originally it is hide instead of DUMMY."
3083   (let ((inhibit-read-only t)
3084         (inhibit-point-motion-hooks t))
3085     (gnus-remove-text-properties-when
3086      'article-type type
3087      (point-min) (point-max)
3088      (cons 'article-type (cons type
3089                                gnus-hidden-properties)))
3090     (gnus-delete-wash-type type)))
3091
3092 (defconst article-time-units
3093   `((year . ,(* 365.25 24 60 60))
3094     (week . ,(* 7 24 60 60))
3095     (day . ,(* 24 60 60))
3096     (hour . ,(* 60 60))
3097     (minute . 60)
3098     (second . 1))
3099   "Mapping from time units to seconds.")
3100
3101 (defun gnus-article-forward-header ()
3102   "Move point to the start of the next header.
3103 If the current header is a continuation header, this can be several
3104 lines forward."
3105   (let ((ended nil))
3106     (while (not ended)
3107       (forward-line 1)
3108       (if (looking-at "[ \t]+[^ \t]")
3109           (forward-line 1)
3110         (setq ended t)))))
3111
3112 (defun article-date-ut (&optional type highlight)
3113   "Convert DATE date to universal time in the current article.
3114 If TYPE is `local', convert to local time; if it is `lapsed', output
3115 how much time has lapsed since DATE.  For `lapsed', the value of
3116 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3117 should replace the \"Date:\" one, or should be added below it."
3118   (interactive (list 'ut t))
3119   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3120          (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3121                              tdate-regexp)
3122                             ((eq type 'lapsed)
3123                              "^X-Sent:[ \t]")
3124                             (article-lapsed-timer
3125                              "^Date:[ \t]")
3126                             (t
3127                              tdate-regexp)))
3128          (case-fold-search t)
3129          (inhibit-read-only t)
3130          (inhibit-point-motion-hooks t)
3131          pos date bface eface)
3132     (save-excursion
3133       (save-restriction
3134         (widen)
3135         (goto-char (point-min))
3136         (while (or (setq date (get-text-property (setq pos (point))
3137                                                  'original-date))
3138                    (when (setq pos (next-single-property-change
3139                                     (point) 'original-date))
3140                      (setq date (get-text-property pos 'original-date))
3141                      t))
3142           (narrow-to-region pos (or (text-property-any pos (point-max)
3143                                                        'original-date nil)
3144                                     (point-max)))
3145           (goto-char (point-min))
3146           (when (re-search-forward tdate-regexp nil t)
3147             (setq bface (get-text-property (point-at-bol) 'face)
3148                   eface (get-text-property (1- (point-at-eol)) 'face)))
3149           (goto-char (point-min))
3150           (setq pos nil)
3151           ;; Delete any old Date headers.
3152           (while (re-search-forward date-regexp nil t)
3153             (if pos
3154                 (delete-region (point-at-bol) (progn
3155                                                 (gnus-article-forward-header)
3156                                                 (point)))
3157               (delete-region (point-at-bol) (progn
3158                                               (gnus-article-forward-header)
3159                                               (forward-char -1)
3160                                               (point)))
3161               (setq pos (point))))
3162           (when (and (not pos)
3163                      (re-search-forward tdate-regexp nil t))
3164             (forward-line 1))
3165           (gnus-goto-char pos)
3166           (insert (article-make-date-line date (or type 'ut)))
3167           (unless pos
3168             (insert "\n")
3169             (forward-line -1))
3170           ;; Do highlighting.
3171           (beginning-of-line)
3172           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3173             (put-text-property (match-beginning 1) (1+ (match-end 1))
3174                                'face bface)
3175             (put-text-property (match-beginning 2) (match-end 2)
3176                                'face eface))
3177           (put-text-property (point-min) (1- (point-max)) 'original-date date)
3178           (goto-char (point-max))
3179           (widen))))))
3180
3181 (defun article-make-date-line (date type)
3182   "Return a DATE line of TYPE."
3183   (unless (memq type '(local ut original user iso8601 lapsed english))
3184     (error "Unknown conversion type: %s" type))
3185   (condition-case ()
3186       (let ((time (date-to-time date)))
3187         (cond
3188          ;; Convert to the local timezone.
3189          ((eq type 'local)
3190           (concat "Date: " (message-make-date time)))
3191          ;; Convert to Universal Time.
3192          ((eq type 'ut)
3193           (concat "Date: "
3194                   (substring
3195                    (message-make-date
3196                     (let* ((e (parse-time-string date))
3197                            (tm (apply 'encode-time e))
3198                            (ms (car tm))
3199                            (ls (- (cadr tm) (car (current-time-zone time)))))
3200                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3201                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3202                             (t (list ms ls)))))
3203                    0 -5)
3204                   "UT"))
3205          ;; Get the original date from the article.
3206          ((eq type 'original)
3207           (concat "Date: " (if (string-match "\n+$" date)
3208                                (substring date 0 (match-beginning 0))
3209                              date)))
3210          ;; Let the user define the format.
3211          ((eq type 'user)
3212           (let ((format (or (condition-case nil
3213                                 (with-current-buffer gnus-summary-buffer
3214                                   gnus-article-time-format)
3215                               (error nil))
3216                             gnus-article-time-format)))
3217             (if (functionp format)
3218                 (funcall format time)
3219               (concat "Date: " (format-time-string format time)))))
3220          ;; ISO 8601.
3221          ((eq type 'iso8601)
3222           (let ((tz (car (current-time-zone time))))
3223             (concat
3224              "Date: "
3225              (format-time-string "%Y%m%dT%H%M%S" time)
3226              (format "%s%02d%02d"
3227                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3228                      (/ (% (abs tz) 3600) 60)))))
3229          ;; Do an X-Sent lapsed format.
3230          ((eq type 'lapsed)
3231           ;; If the date is seriously mangled, the timezone functions are
3232           ;; liable to bug out, so we ignore all errors.
3233           (let* ((now (current-time))
3234                  (real-time (subtract-time now time))
3235                  (real-sec (and real-time
3236                                 (+ (* (float (car real-time)) 65536)
3237                                    (cadr real-time))))
3238                  (sec (and real-time (abs real-sec)))
3239                  num prev)
3240             (cond
3241              ((null real-time)
3242               "X-Sent: Unknown")
3243              ((zerop sec)
3244               "X-Sent: Now")
3245              (t
3246               (concat
3247                "X-Sent: "
3248                ;; This is a bit convoluted, but basically we go
3249                ;; through the time units for years, weeks, etc,
3250                ;; and divide things to see whether that results
3251                ;; in positive answers.
3252                (mapconcat
3253                 (lambda (unit)
3254                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3255                       ;; The (remaining) seconds are too few to
3256                       ;; be divided into this time unit.
3257                       ""
3258                     ;; It's big enough, so we output it.
3259                     (setq sec (- sec (* num (cdr unit))))
3260                     (prog1
3261                         (concat (if prev ", " "") (int-to-string
3262                                                    (floor num))
3263                                 " " (symbol-name (car unit))
3264                                 (if (> num 1) "s" ""))
3265                       (setq prev t))))
3266                 article-time-units "")
3267                ;; If dates are odd, then it might appear like the
3268                ;; article was sent in the future.
3269                (if (> real-sec 0)
3270                    " ago"
3271                  " in the future"))))))
3272          ;; Display the date in proper English
3273          ((eq type 'english)
3274           (let ((dtime (decode-time time)))
3275             (concat
3276              "Date: the "
3277              (number-to-string (nth 3 dtime))
3278              (let ((digit (% (nth 3 dtime) 10)))
3279                (cond
3280                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3281                 ((= digit 1) "st")
3282                 ((= digit 2) "nd")
3283                 ((= digit 3) "rd")
3284                 (t "th")))
3285              " of "
3286              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3287              " "
3288              (number-to-string (nth 5 dtime))
3289              " at "
3290              (format "%02d" (nth 2 dtime))
3291              ":"
3292              (format "%02d" (nth 1 dtime)))))))
3293     (error
3294      (format "Date: %s (from Gnus)" date))))
3295
3296 (defun article-date-local (&optional highlight)
3297   "Convert the current article date to the local timezone."
3298   (interactive (list t))
3299   (article-date-ut 'local highlight))
3300
3301 (defun article-date-english (&optional highlight)
3302   "Convert the current article date to something that is proper English."
3303   (interactive (list t))
3304   (article-date-ut 'english highlight))
3305
3306 (defun article-date-original (&optional highlight)
3307   "Convert the current article date to what it was originally.
3308 This is only useful if you have used some other date conversion
3309 function and want to see what the date was before converting."
3310   (interactive (list t))
3311   (article-date-ut 'original highlight))
3312
3313 (defun article-date-lapsed (&optional highlight)
3314   "Convert the current article date to time lapsed since it was sent."
3315   (interactive (list t))
3316   (article-date-ut 'lapsed highlight))
3317
3318 (defun article-update-date-lapsed ()
3319   "Function to be run from a timer to update the lapsed time line."
3320   (save-match-data
3321     (let (deactivate-mark)
3322       (save-excursion
3323         (ignore-errors
3324          (walk-windows
3325           (lambda (w)
3326             (set-buffer (window-buffer w))
3327             (when (eq major-mode 'gnus-article-mode)
3328               (let ((mark (point-marker)))
3329                 (goto-char (point-min))
3330                 (when (re-search-forward "^X-Sent:" nil t)
3331                   (article-date-lapsed t))
3332                 (goto-char (marker-position mark))
3333                 (move-marker mark nil))))
3334           nil 'visible))))))
3335
3336 (defun gnus-start-date-timer (&optional n)
3337   "Start a timer to update the X-Sent header in the article buffers.
3338 The numerical prefix says how frequently (in seconds) the function
3339 is to run."
3340   (interactive "p")
3341   (unless n
3342     (setq n 1))
3343   (gnus-stop-date-timer)
3344   (setq article-lapsed-timer
3345         (run-at-time 1 n 'article-update-date-lapsed)))
3346
3347 (defun gnus-stop-date-timer ()
3348   "Stop the X-Sent timer."
3349   (interactive)
3350   (when article-lapsed-timer
3351     (nnheader-cancel-timer article-lapsed-timer)
3352     (setq article-lapsed-timer nil)))
3353
3354 (defun article-date-user (&optional highlight)
3355   "Convert the current article date to the user-defined format.
3356 This format is defined by the `gnus-article-time-format' variable."
3357   (interactive (list t))
3358   (article-date-ut 'user highlight))
3359
3360 (defun article-date-iso8601 (&optional highlight)
3361   "Convert the current article date to ISO8601."
3362   (interactive (list t))
3363   (article-date-ut 'iso8601 highlight))
3364
3365 (defmacro gnus-article-save-original-date (&rest forms)
3366   "Save the original date as a text property and evaluate FORMS."
3367   `(let* ((case-fold-search t)
3368           (start (progn
3369                    (goto-char (point-min))
3370                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3371                               (not (bolp)))
3372                      (match-end 0))))
3373           (date (when (and start
3374                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3375                                               nil t))
3376                   (buffer-substring-no-properties start
3377                                                   (match-beginning 0)))))
3378      (goto-char (point-max))
3379      (skip-chars-backward "\n")
3380      (put-text-property (point-min) (point) 'original-date date)
3381      ,@forms
3382      (goto-char (point-max))
3383      (skip-chars-backward "\n")
3384      (put-text-property (point-min) (point) 'original-date date)))
3385
3386 ;; (defun article-show-all ()
3387 ;;   "Show all hidden text in the article buffer."
3388 ;;   (interactive)
3389 ;;   (save-excursion
3390 ;;     (let ((inhibit-read-only t))
3391 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3392
3393 (defun article-remove-leading-whitespace ()
3394   "Remove excessive whitespace from all headers."
3395   (interactive)
3396   (save-excursion
3397     (save-restriction
3398       (let ((inhibit-read-only t))
3399         (article-narrow-to-head)
3400         (goto-char (point-min))
3401         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3402           (delete-region (match-beginning 1) (match-end 1)))))))
3403
3404 (defun article-emphasize (&optional arg)
3405   "Emphasize text according to `gnus-emphasis-alist'."
3406   (interactive (gnus-article-hidden-arg))
3407   (unless (gnus-article-check-hidden-text 'emphasis arg)
3408     (save-excursion
3409       (let ((alist (or
3410                     (condition-case nil
3411                         (with-current-buffer gnus-summary-buffer
3412                           gnus-article-emphasis-alist)
3413                       (error))
3414                     gnus-emphasis-alist))
3415             (inhibit-read-only t)
3416             (props (append '(article-type emphasis)
3417                            gnus-hidden-properties))
3418             regexp elem beg invisible visible face)
3419         (article-goto-body)
3420         (setq beg (point))
3421         (while (setq elem (pop alist))
3422           (goto-char beg)
3423           (setq regexp (car elem)
3424                 invisible (nth 1 elem)
3425                 visible (nth 2 elem)
3426                 face (nth 3 elem))
3427           (while (re-search-forward regexp nil t)
3428             (when (and (match-beginning visible) (match-beginning invisible))
3429               (gnus-article-hide-text
3430                (match-beginning invisible) (match-end invisible) props)
3431               (gnus-article-unhide-text-type
3432                (match-beginning visible) (match-end visible) 'emphasis)
3433               (gnus-put-overlay-excluding-newlines
3434                (match-beginning visible) (match-end visible) 'face face)
3435               (gnus-add-wash-type 'emphasis)
3436               (goto-char (match-end invisible)))))))))
3437
3438 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3439   "Setup newsgroup emphasis alist."
3440   (unless gnus-article-emphasis-alist
3441     (let ((name (and gnus-newsgroup-name
3442                      (gnus-group-real-name gnus-newsgroup-name))))
3443       (make-local-variable 'gnus-article-emphasis-alist)
3444       (setq gnus-article-emphasis-alist
3445             (nconc
3446              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3447                (while (setq elem (pop alist))
3448                  (when (and name (string-match (car elem) name))
3449                    (setq alist nil
3450                          highlight (copy-sequence (cdr elem)))))
3451                highlight)
3452              (copy-sequence highlight-words)
3453              (if gnus-newsgroup-name
3454                  (copy-sequence (gnus-group-find-parameter
3455                                  gnus-newsgroup-name 'highlight-words t)))
3456              gnus-emphasis-alist)))))
3457
3458 (eval-when-compile
3459   (defvar gnus-summary-article-menu)
3460   (defvar gnus-summary-post-menu))
3461
3462 ;;; Saving functions.
3463
3464 (defun gnus-article-save (save-buffer file &optional num)
3465   "Save the currently selected article."
3466   (unless gnus-save-all-headers
3467     ;; Remove headers according to `gnus-saved-headers'.
3468     (let ((gnus-visible-headers
3469            (or gnus-saved-headers gnus-visible-headers))
3470           (gnus-article-buffer save-buffer))
3471       (save-excursion
3472         (set-buffer save-buffer)
3473         (article-hide-headers 1 t))))
3474   (save-window-excursion
3475     (if (not gnus-default-article-saver)
3476         (error "No default saver is defined")
3477       ;; !!! Magic!  The saving functions all save
3478       ;; `gnus-save-article-buffer' (or so they think), but we
3479       ;; bind that variable to our save-buffer.
3480       (set-buffer gnus-article-buffer)
3481       (let* ((gnus-save-article-buffer save-buffer)
3482              (filename
3483               (cond
3484                ((not gnus-prompt-before-saving) 'default)
3485                ((eq gnus-prompt-before-saving 'always) nil)
3486                (t file)))
3487              (gnus-number-of-articles-to-be-saved
3488               (when (eq gnus-prompt-before-saving t)
3489                 num)))                  ; Magic
3490         (set-buffer gnus-article-current-summary)
3491         (funcall gnus-default-article-saver filename)))))
3492
3493 (defun gnus-read-save-file-name (prompt &optional filename
3494                                         function group headers variable
3495                                         dir-var)
3496   (let ((default-name
3497           (funcall function group headers (symbol-value variable)))
3498         result)
3499     (setq result
3500           (expand-file-name
3501            (cond
3502             ((eq filename 'default)
3503              default-name)
3504             ((eq filename t)
3505              default-name)
3506             (filename filename)
3507             (t
3508              (when (symbol-value dir-var)
3509                (setq default-name (expand-file-name
3510                                    (file-name-nondirectory default-name)
3511                                    (symbol-value dir-var))))
3512              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3513                     (prompt
3514                      (format prompt
3515                              (if (and gnus-number-of-articles-to-be-saved
3516                                       (> gnus-number-of-articles-to-be-saved 1))
3517                                  (format "these %d articles"
3518                                          gnus-number-of-articles-to-be-saved)
3519                                "this article")))
3520                     (file
3521                      ;; Let the split methods have their say.
3522                      (cond
3523                       ;; No split name was found.
3524                       ((null split-name)
3525                        (read-file-name
3526                         (concat prompt " (default "
3527                                 (file-name-nondirectory default-name) "): ")
3528                         (file-name-directory default-name)
3529                         default-name))
3530                       ;; A single group name is returned.
3531                       ((stringp split-name)
3532                        (setq default-name
3533                              (funcall function split-name headers
3534                                       (symbol-value variable)))
3535                        (read-file-name
3536                         (concat prompt " (default "
3537                                 (file-name-nondirectory default-name) "): ")
3538                         (file-name-directory default-name)
3539                         default-name))
3540                       ;; A single split name was found
3541                       ((= 1 (length split-name))
3542                        (let* ((name (expand-file-name
3543                                      (car split-name)
3544                                      gnus-article-save-directory))
3545                               (dir (cond ((file-directory-p name)
3546                                           (file-name-as-directory name))
3547                                          ((file-exists-p name) name)
3548                                          (t gnus-article-save-directory))))
3549                          (read-file-name
3550                           (concat prompt " (default " name "): ")
3551                           dir name)))
3552                       ;; A list of splits was found.
3553                       (t
3554                        (setq split-name (nreverse split-name))
3555                        (let (result)
3556                          (let ((file-name-history
3557                                 (nconc split-name file-name-history)))
3558                            (setq result
3559                                  (expand-file-name
3560                                   (read-file-name
3561                                    (concat prompt " (`M-p' for defaults): ")
3562                                    gnus-article-save-directory
3563                                    (car split-name))
3564                                   gnus-article-save-directory)))
3565                          (car (push result file-name-history)))))))
3566                ;; Create the directory.
3567                (gnus-make-directory (file-name-directory file))
3568                ;; If we have read a directory, we append the default file name.
3569                (when (file-directory-p file)
3570                  (setq file (expand-file-name (file-name-nondirectory
3571                                                default-name)
3572                                               (file-name-as-directory file))))
3573                ;; Possibly translate some characters.
3574                (nnheader-translate-file-chars file))))))
3575     (gnus-make-directory (file-name-directory result))
3576     (when variable
3577       (set variable result))
3578     (when dir-var
3579       (set dir-var (file-name-directory result)))
3580     result))
3581
3582 (defun gnus-article-archive-name (group)
3583   "Return the first instance of an \"Archive-name\" in the current buffer."
3584   (let ((case-fold-search t))
3585     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3586       (nnheader-concat gnus-article-save-directory
3587                        (match-string 1)))))
3588
3589 (defun gnus-article-nndoc-name (group)
3590   "If GROUP is an nndoc group, return the name of the parent group."
3591   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3592     (gnus-group-get-parameter group 'save-article-group)))
3593
3594 (defun gnus-summary-save-in-rmail (&optional filename)
3595   "Append this article to Rmail file.
3596 Optional argument FILENAME specifies file name.
3597 Directory to save to is default to `gnus-article-save-directory'."
3598   (setq filename (gnus-read-save-file-name
3599                   "Save %s in rmail file" filename
3600                   gnus-rmail-save-name gnus-newsgroup-name
3601                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3602   (gnus-eval-in-buffer-window gnus-save-article-buffer
3603     (save-excursion
3604       (save-restriction
3605         (widen)
3606         (gnus-output-to-rmail filename))))
3607   filename)
3608
3609 (defun gnus-summary-save-in-mail (&optional filename)
3610   "Append this article to Unix mail file.
3611 Optional argument FILENAME specifies file name.
3612 Directory to save to is default to `gnus-article-save-directory'."
3613   (setq filename (gnus-read-save-file-name
3614                   "Save %s in Unix mail file" filename
3615                   gnus-mail-save-name gnus-newsgroup-name
3616                   gnus-current-headers 'gnus-newsgroup-last-mail))
3617   (gnus-eval-in-buffer-window gnus-save-article-buffer
3618     (save-excursion
3619       (save-restriction
3620         (widen)
3621         (if (and (file-readable-p filename)
3622                  (file-regular-p filename)
3623                  (mail-file-babyl-p filename))
3624             (rmail-output-to-rmail-file filename t)
3625           (gnus-output-to-mail filename)))))
3626   filename)
3627
3628 (put 'gnus-summary-save-in-file :decode t)
3629 (defun gnus-summary-save-in-file (&optional filename overwrite)
3630   "Append this article to file.
3631 Optional argument FILENAME specifies file name.
3632 Directory to save to is default to `gnus-article-save-directory'."
3633   (setq filename (gnus-read-save-file-name
3634                   "Save %s in file" filename
3635                   gnus-file-save-name gnus-newsgroup-name
3636                   gnus-current-headers 'gnus-newsgroup-last-file))
3637   (gnus-eval-in-buffer-window gnus-save-article-buffer
3638     (save-excursion
3639       (save-restriction
3640         (widen)
3641         (when (and overwrite
3642                    (file-exists-p filename))
3643           (delete-file filename))
3644         (gnus-output-to-file filename))))
3645   filename)
3646
3647 (put 'gnus-summary-write-to-file :decode t)
3648 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3649 (defun gnus-summary-write-to-file (&optional filename)
3650   "Write this article to a file, overwriting it if the file exists.
3651 Optional argument FILENAME specifies file name.
3652 The directory to save in defaults to `gnus-article-save-directory'."
3653   (setq filename (gnus-read-save-file-name
3654                   "Save %s in file" filename
3655                   gnus-file-save-name gnus-newsgroup-name
3656                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3657   (gnus-summary-save-in-file filename t))
3658
3659 (put 'gnus-summary-save-body-in-file :decode t)
3660 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3661   "Append this article body to a file.
3662 Optional argument FILENAME specifies file name.
3663 The directory to save in defaults to `gnus-article-save-directory'."
3664   (setq filename (gnus-read-save-file-name
3665                   "Save %s body in file" filename
3666                   gnus-file-save-name gnus-newsgroup-name
3667                   gnus-current-headers 'gnus-newsgroup-last-file))
3668   (gnus-eval-in-buffer-window gnus-save-article-buffer
3669     (save-excursion
3670       (save-restriction
3671         (widen)
3672         (when (article-goto-body)
3673           (narrow-to-region (point) (point-max)))
3674         (when (and overwrite
3675                    (file-exists-p filename))
3676           (delete-file filename))
3677         (gnus-output-to-file filename))))
3678   filename)
3679
3680 (put 'gnus-summary-write-body-to-file :decode t)
3681 (put 'gnus-summary-write-body-to-file
3682      :function 'gnus-summary-save-body-in-file)
3683 (defun gnus-summary-write-body-to-file (&optional filename)
3684   "Write this article body to a file, overwriting it if the file exists.
3685 Optional argument FILENAME specifies file name.
3686 The directory to save in defaults to `gnus-article-save-directory'."
3687   (setq filename (gnus-read-save-file-name
3688                   "Save %s body in file" filename
3689                   gnus-file-save-name gnus-newsgroup-name
3690                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3691   (gnus-summary-save-body-in-file filename t))
3692
3693 (defun gnus-summary-save-in-pipe (&optional command)
3694   "Pipe this article to subprocess."
3695   (setq command
3696         (cond ((and (eq command 'default)
3697                     gnus-last-shell-command)
3698                gnus-last-shell-command)
3699               ((stringp command)
3700                command)
3701               (t (read-string
3702                   (format
3703                    "Shell command on %s: "
3704                    (if (and gnus-number-of-articles-to-be-saved
3705                             (> gnus-number-of-articles-to-be-saved 1))
3706                        (format "these %d articles"
3707                                gnus-number-of-articles-to-be-saved)
3708                      "this article"))
3709                   gnus-last-shell-command))))
3710   (when (string-equal command "")
3711     (if gnus-last-shell-command
3712         (setq command gnus-last-shell-command)
3713       (error "A command is required")))
3714   (gnus-eval-in-buffer-window gnus-article-buffer
3715     (save-restriction
3716       (widen)
3717       (shell-command-on-region (point-min) (point-max) command nil)))
3718   (setq gnus-last-shell-command command))
3719
3720 (defun gnus-summary-pipe-to-muttprint (&optional command)
3721   "Pipe this article to muttprint."
3722   (setq command (read-string
3723                  "Print using command: " gnus-summary-muttprint-program
3724                  nil gnus-summary-muttprint-program))
3725   (gnus-summary-save-in-pipe command))
3726
3727 ;;; Article file names when saving.
3728
3729 (defun gnus-capitalize-newsgroup (newsgroup)
3730   "Capitalize NEWSGROUP name."
3731   (when (not (zerop (length newsgroup)))
3732     (concat (char-to-string (upcase (aref newsgroup 0)))
3733             (substring newsgroup 1))))
3734
3735 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3736   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3737 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3738 Otherwise, it is like ~/News/news/group/num."
3739   (let ((default
3740           (expand-file-name
3741            (concat (if (gnus-use-long-file-name 'not-save)
3742                        (gnus-capitalize-newsgroup newsgroup)
3743                      (gnus-newsgroup-directory-form newsgroup))
3744                    "/" (int-to-string (mail-header-number headers)))
3745            gnus-article-save-directory)))
3746     (if (and last-file
3747              (string-equal (file-name-directory default)
3748                            (file-name-directory last-file))
3749              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3750         default
3751       (or last-file default))))
3752
3753 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3754   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3755 If variable `gnus-use-long-file-name' is non-nil, it is
3756 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3757   (let ((default
3758           (expand-file-name
3759            (concat (if (gnus-use-long-file-name 'not-save)
3760                        newsgroup
3761                      (gnus-newsgroup-directory-form newsgroup))
3762                    "/" (int-to-string (mail-header-number headers)))
3763            gnus-article-save-directory)))
3764     (if (and last-file
3765              (string-equal (file-name-directory default)
3766                            (file-name-directory last-file))
3767              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3768         default
3769       (or last-file default))))
3770
3771 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3772   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3773 If variable `gnus-use-long-file-name' is non-nil, it is
3774 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3775   (or last-file
3776       (expand-file-name
3777        (if (gnus-use-long-file-name 'not-save)
3778            newsgroup
3779          (file-relative-name
3780           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3781           default-directory))
3782        gnus-article-save-directory)))
3783
3784 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3785   "Generate file name from sender."
3786   (let ((from (mail-header-from headers)))
3787     (expand-file-name
3788      (if (and from (string-match "\\([^ <]+\\)@" from))
3789          (match-string 1 from)
3790        "nobody")
3791      gnus-article-save-directory)))
3792
3793 (defun article-verify-x-pgp-sig ()
3794   "Verify X-PGP-Sig."
3795   (interactive)
3796   (if (gnus-buffer-live-p gnus-original-article-buffer)
3797       (let ((sig (with-current-buffer gnus-original-article-buffer
3798                    (gnus-fetch-field "X-PGP-Sig")))
3799             items info headers)
3800         (when (and sig
3801                    mml2015-use
3802                    (mml2015-clear-verify-function))
3803           (with-temp-buffer
3804             (insert-buffer-substring gnus-original-article-buffer)
3805             (setq items (split-string sig))
3806             (message-narrow-to-head)
3807             (let ((inhibit-point-motion-hooks t)
3808                   (case-fold-search t))
3809               ;; Don't verify multiple headers.
3810               (setq headers (mapconcat (lambda (header)
3811                                          (concat header ": "
3812                                                  (mail-fetch-field header)
3813                                                  "\n"))
3814                                        (split-string (nth 1 items) ",") "")))
3815             (delete-region (point-min) (point-max))
3816             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3817             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3818             (insert headers)
3819             (widen)
3820             (forward-line)
3821             (while (not (eobp))
3822               (if (looking-at "^-")
3823                   (insert "- "))
3824               (forward-line))
3825             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3826             (insert "Version: " (car items) "\n\n")
3827             (insert (mapconcat 'identity (cddr items) "\n"))
3828             (insert "\n-----END PGP SIGNATURE-----\n")
3829             (let ((mm-security-handle (list (format "multipart/signed"))))
3830               (mml2015-clean-buffer)
3831               (let ((coding-system-for-write (or gnus-newsgroup-charset
3832                                                  'iso-8859-1)))
3833                 (funcall (mml2015-clear-verify-function)))
3834               (setq info
3835                     (or (mm-handle-multipart-ctl-parameter
3836                          mm-security-handle 'gnus-details)
3837                         (mm-handle-multipart-ctl-parameter
3838                          mm-security-handle 'gnus-info)))))
3839           (when info
3840             (let ((inhibit-read-only t) bface eface)
3841               (save-restriction
3842                 (message-narrow-to-head)
3843                 (goto-char (point-max))
3844                 (forward-line -1)
3845                 (setq bface (get-text-property (point-at-bol) 'face)
3846                       eface (get-text-property (1- (point-at-eol)) 'face))
3847                 (message-remove-header "X-Gnus-PGP-Verify")
3848                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3849                     (forward-line)
3850                   (goto-char (point-max)))
3851                 (narrow-to-region (point) (point))
3852                 (insert "X-Gnus-PGP-Verify: " info "\n")
3853                 (goto-char (point-min))
3854                 (forward-line)
3855                 (while (not (eobp))
3856                   (if (not (looking-at "^[ \t]"))
3857                       (insert " "))
3858                   (forward-line))
3859                 ;; Do highlighting.
3860                 (goto-char (point-min))
3861                 (when (looking-at "\\([^:]+\\): *")
3862                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3863                                      'face bface)
3864                   (put-text-property (match-end 0) (point-max)
3865                                      'face eface)))))))))
3866
3867 (defun article-verify-cancel-lock ()
3868   "Verify Cancel-Lock header."
3869   (interactive)
3870   (if (gnus-buffer-live-p gnus-original-article-buffer)
3871       (canlock-verify gnus-original-article-buffer)))
3872
3873 (eval-and-compile
3874   (mapcar
3875    (lambda (func)
3876      (let (afunc gfunc)
3877        (if (consp func)
3878            (setq afunc (car func)
3879                  gfunc (cdr func))
3880          (setq afunc func
3881                gfunc (intern (format "gnus-%s" func))))
3882        (defalias gfunc
3883          (when (fboundp afunc)
3884            `(lambda (&optional interactive &rest args)
3885               ,(documentation afunc t)
3886               (interactive (list t))
3887               (save-excursion
3888                 (set-buffer gnus-article-buffer)
3889                 (if interactive
3890                     (call-interactively ',afunc)
3891                   (apply ',afunc args))))))))
3892    '(article-hide-headers
3893      article-verify-x-pgp-sig
3894      article-verify-cancel-lock
3895      article-hide-boring-headers
3896      article-treat-overstrike
3897      article-treat-ansi-sequences
3898      article-fill-long-lines
3899      article-capitalize-sentences
3900      article-remove-cr
3901      article-remove-leading-whitespace
3902      article-display-x-face
3903      article-display-face
3904      article-de-quoted-unreadable
3905      article-de-base64-unreadable
3906      article-decode-HZ
3907      article-wash-html
3908      article-unsplit-urls
3909      article-hide-list-identifiers
3910      article-strip-banner
3911      article-babel
3912      article-hide-pem
3913      article-hide-signature
3914      article-strip-headers-in-body
3915      article-remove-trailing-blank-lines
3916      article-strip-leading-blank-lines
3917      article-strip-multiple-blank-lines
3918      article-strip-leading-space
3919      article-strip-trailing-space
3920      article-strip-blank-lines
3921      article-strip-all-blank-lines
3922      article-date-local
3923      article-date-english
3924      article-date-iso8601
3925      article-date-original
3926      article-date-ut
3927      article-decode-mime-words
3928      article-decode-charset
3929      article-decode-encoded-words
3930      article-date-user
3931      article-date-lapsed
3932      article-emphasize
3933      article-treat-dumbquotes
3934      article-normalize-headers
3935 ;;     (article-show-all . gnus-article-show-all-headers)
3936      )))
3937 \f
3938 ;;;
3939 ;;; Gnus article mode
3940 ;;;
3941
3942 (put 'gnus-article-mode 'mode-class 'special)
3943
3944 (set-keymap-parent gnus-article-mode-map widget-keymap)
3945
3946 (gnus-define-keys gnus-article-mode-map
3947   " " gnus-article-goto-next-page
3948   "\177" gnus-article-goto-prev-page
3949   [delete] gnus-article-goto-prev-page
3950   [backspace] gnus-article-goto-prev-page
3951   "\C-c^" gnus-article-refer-article
3952   "h" gnus-article-show-summary
3953   "s" gnus-article-show-summary
3954   "\C-c\C-m" gnus-article-mail
3955   "?" gnus-article-describe-briefly
3956   "e" gnus-summary-edit-article
3957   "<" beginning-of-buffer
3958   ">" end-of-buffer
3959   "\C-c\C-i" gnus-info-find-node
3960   "\C-c\C-b" gnus-bug
3961   "R" gnus-article-reply-with-original
3962   "F" gnus-article-followup-with-original
3963   "\C-hk" gnus-article-describe-key
3964   "\C-hc" gnus-article-describe-key-briefly
3965
3966   "\C-d" gnus-article-read-summary-keys
3967   "\M-*" gnus-article-read-summary-keys
3968   "\M-#" gnus-article-read-summary-keys
3969   "\M-^" gnus-article-read-summary-keys
3970   "\M-g" gnus-article-read-summary-keys)
3971
3972 (substitute-key-definition
3973  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3974
3975 (defun gnus-article-make-menu-bar ()
3976   (unless (boundp 'gnus-article-commands-menu)
3977     (gnus-summary-make-menu-bar))
3978   (gnus-turn-off-edit-menu 'article)
3979   (unless (boundp 'gnus-article-article-menu)
3980     (easy-menu-define
3981      gnus-article-article-menu gnus-article-mode-map ""
3982      '("Article"
3983        ["Scroll forwards" gnus-article-goto-next-page t]
3984        ["Scroll backwards" gnus-article-goto-prev-page t]
3985        ["Show summary" gnus-article-show-summary t]
3986        ["Fetch Message-ID at point" gnus-article-refer-article t]
3987        ["Mail to address at point" gnus-article-mail t]
3988        ["Send a bug report" gnus-bug t]))
3989
3990     (easy-menu-define
3991      gnus-article-treatment-menu gnus-article-mode-map ""
3992      ;; Fixme: this should use :active (and maybe :visible).
3993      '("Treatment"
3994        ["Hide headers" gnus-article-hide-headers t]
3995        ["Hide signature" gnus-article-hide-signature t]
3996        ["Hide citation" gnus-article-hide-citation t]
3997        ["Treat overstrike" gnus-article-treat-overstrike t]
3998        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3999        ["Remove carriage return" gnus-article-remove-cr t]
4000        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4001        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4002        ["Remove base64" gnus-article-de-base64-unreadable t]
4003        ["Treat html" gnus-article-wash-html t]
4004        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4005        ["Decode HZ" gnus-article-decode-HZ t]))
4006
4007     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4008
4009     ;; Note "Post" menu is defined in gnus-sum.el for consistency
4010
4011     (gnus-run-hooks 'gnus-article-menu-hook)))
4012
4013 (defun gnus-article-mode ()
4014   "Major mode for displaying an article.
4015
4016 All normal editing commands are switched off.
4017
4018 The following commands are available in addition to all summary mode
4019 commands:
4020 \\<gnus-article-mode-map>
4021 \\[gnus-article-next-page]\t Scroll the article one page forwards
4022 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4023 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4024 \\[gnus-article-show-summary]\t Display the summary buffer
4025 \\[gnus-article-mail]\t Send a reply to the address near point
4026 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4027 \\[gnus-info-find-node]\t Go to the Gnus info node"
4028   (interactive)
4029   (kill-all-local-variables)
4030   (gnus-simplify-mode-line)
4031   (setq mode-name "Article")
4032   (setq major-mode 'gnus-article-mode)
4033   (make-local-variable 'minor-mode-alist)
4034   (use-local-map gnus-article-mode-map)
4035   (when (gnus-visual-p 'article-menu 'menu)
4036     (gnus-article-make-menu-bar)
4037     (when gnus-summary-tool-bar-map
4038       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4039   (gnus-update-format-specifications nil 'article-mode)
4040   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4041   (set (make-local-variable 'gnus-page-broken) nil)
4042   (make-local-variable 'gnus-button-marker-list)
4043   (make-local-variable 'gnus-article-current-summary)
4044   (make-local-variable 'gnus-article-mime-handles)
4045   (make-local-variable 'gnus-article-decoded-p)
4046   (make-local-variable 'gnus-article-mime-handle-alist)
4047   (make-local-variable 'gnus-article-wash-types)
4048   (make-local-variable 'gnus-article-image-alist)
4049   (make-local-variable 'gnus-article-charset)
4050   (make-local-variable 'gnus-article-ignored-charsets)
4051   ;; Prevent recent Emacsen from displaying non-break space as "\ ".
4052   (set (make-local-variable 'nobreak-char-display) nil)
4053   (setq cursor-in-non-selected-windows nil)
4054   (gnus-set-default-directory)
4055   (buffer-disable-undo)
4056   (setq buffer-read-only t
4057         show-trailing-whitespace nil)
4058   (set-syntax-table gnus-article-mode-syntax-table)
4059   (mm-enable-multibyte)
4060   (gnus-run-mode-hooks 'gnus-article-mode-hook))
4061
4062 (defun gnus-article-setup-buffer ()
4063   "Initialize the article buffer."
4064   (let* ((name (if gnus-single-article-buffer "*Article*"
4065                  (concat "*Article " gnus-newsgroup-name "*")))
4066          (original
4067           (progn (string-match "\\*Article" name)
4068                  (concat " *Original Article"
4069                          (substring name (match-end 0))))))
4070     (setq gnus-article-buffer name)
4071     (setq gnus-original-article-buffer original)
4072     (setq gnus-article-mime-handle-alist nil)
4073     (with-current-buffer gnus-summary-buffer
4074       ;; This might be a variable local to the summary buffer.
4075       (unless gnus-single-article-buffer
4076         (setq gnus-article-buffer name)
4077         (setq gnus-original-article-buffer original)
4078         (gnus-set-global-variables)))
4079     (gnus-article-setup-highlight-words)
4080     ;; Init original article buffer.
4081     (save-excursion
4082       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4083       (mm-enable-multibyte)
4084       (setq major-mode 'gnus-original-article-mode)
4085       (make-local-variable 'gnus-original-article))
4086     (if (and (get-buffer name)
4087              (with-current-buffer name
4088                (if gnus-article-edit-mode
4089                    (if (y-or-n-p "Article mode edit in progress; discard? ")
4090                        (progn
4091                          (set-buffer-modified-p nil)
4092                          (gnus-kill-buffer name)
4093                          (message "")
4094                          nil)
4095                      (error "Action aborted"))
4096                  t)))
4097         (save-excursion
4098           (set-buffer name)
4099           (set (make-local-variable 'gnus-article-edit-mode) nil)
4100           (when gnus-article-mime-handles
4101             (mm-destroy-parts gnus-article-mime-handles)
4102             (setq gnus-article-mime-handles nil))
4103           ;; Set it to nil in article-buffer!
4104           (setq gnus-article-mime-handle-alist nil)
4105           (buffer-disable-undo)
4106           (setq buffer-read-only t)
4107           ;; This list just keeps growing if we don't reset it.
4108           (setq gnus-button-marker-list nil)
4109           (unless (eq major-mode 'gnus-article-mode)
4110             (gnus-article-mode))
4111           (current-buffer))
4112       (save-excursion
4113         (set-buffer (gnus-get-buffer-create name))
4114         (gnus-article-mode)
4115         (make-local-variable 'gnus-summary-buffer)
4116         (gnus-summary-set-local-parameters gnus-newsgroup-name)
4117         (current-buffer)))))
4118
4119 ;; Set article window start at LINE, where LINE is the number of lines
4120 ;; from the head of the article.
4121 (defun gnus-article-set-window-start (&optional line)
4122   (set-window-start
4123    (gnus-get-buffer-window gnus-article-buffer t)
4124    (save-excursion
4125      (set-buffer gnus-article-buffer)
4126      (goto-char (point-min))
4127      (if (not line)
4128          (point-min)
4129        (gnus-message 6 "Moved to bookmark")
4130        (search-forward "\n\n" nil t)
4131        (forward-line line)
4132        (point)))))
4133
4134 (defun gnus-article-prepare (article &optional all-headers header)
4135   "Prepare ARTICLE in article mode buffer.
4136 ARTICLE should either be an article number or a Message-ID.
4137 If ARTICLE is an id, HEADER should be the article headers.
4138 If ALL-HEADERS is non-nil, no headers are hidden."
4139   (save-excursion
4140     ;; Make sure we start in a summary buffer.
4141     (unless (eq major-mode 'gnus-summary-mode)
4142       (set-buffer gnus-summary-buffer))
4143     (setq gnus-summary-buffer (current-buffer))
4144     (let* ((gnus-article (if header (mail-header-number header) article))
4145            (summary-buffer (current-buffer))
4146            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4147            (group gnus-newsgroup-name)
4148            result)
4149       (save-excursion
4150         (gnus-article-setup-buffer)
4151         (set-buffer gnus-article-buffer)
4152         ;; Deactivate active regions.
4153         (when (and (boundp 'transient-mark-mode)
4154                    transient-mark-mode)
4155           (setq mark-active nil))
4156         (if (not (setq result (let ((inhibit-read-only t))
4157                                 (gnus-request-article-this-buffer
4158                                  article group))))
4159             ;; There is no such article.
4160             (save-excursion
4161               (when (and (numberp article)
4162                          (not (memq article gnus-newsgroup-sparse)))
4163                 (setq gnus-article-current
4164                       (cons gnus-newsgroup-name article))
4165                 (set-buffer gnus-summary-buffer)
4166                 (setq gnus-current-article article)
4167                 (if (and (memq article gnus-newsgroup-undownloaded)
4168                          (not (gnus-online (gnus-find-method-for-group
4169                                             gnus-newsgroup-name))))
4170                     (progn
4171                       (gnus-summary-set-agent-mark article)
4172                       (message "Message marked for downloading"))
4173                   (gnus-summary-mark-article article gnus-canceled-mark)
4174                   (unless (memq article gnus-newsgroup-sparse)
4175                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4176           (if (or (eq result 'pseudo)
4177                   (eq result 'nneething))
4178               (progn
4179                 (save-excursion
4180                   (set-buffer summary-buffer)
4181                   (push article gnus-newsgroup-history)
4182                   (setq gnus-last-article gnus-current-article
4183                         gnus-current-article 0
4184                         gnus-current-headers nil
4185                         gnus-article-current nil)
4186                   (if (eq result 'nneething)
4187                       (gnus-configure-windows 'summary)
4188                     (gnus-configure-windows 'article))
4189                   (gnus-set-global-variables))
4190                 (let ((gnus-article-mime-handle-alist-1
4191                        gnus-article-mime-handle-alist))
4192                   (gnus-set-mode-line 'article)))
4193             ;; The result from the `request' was an actual article -
4194             ;; or at least some text that is now displayed in the
4195             ;; article buffer.
4196             (when (and (numberp article)
4197                        (not (eq article gnus-current-article)))
4198               ;; Seems like a new article has been selected.
4199               ;; `gnus-current-article' must be an article number.
4200               (save-excursion
4201                 (set-buffer summary-buffer)
4202                 (push article gnus-newsgroup-history)
4203                 (setq gnus-last-article gnus-current-article
4204                       gnus-current-article article
4205                       gnus-current-headers
4206                       (gnus-summary-article-header gnus-current-article)
4207                       gnus-article-current
4208                       (cons gnus-newsgroup-name gnus-current-article))
4209                 (unless (vectorp gnus-current-headers)
4210                   (setq gnus-current-headers nil))
4211                 (gnus-summary-goto-subject gnus-current-article)
4212                 (when (gnus-summary-show-thread)
4213                   ;; If the summary buffer really was folded, the
4214                   ;; previous goto may not actually have gone to
4215                   ;; the right article, but the thread root instead.
4216                   ;; So we go again.
4217                   (gnus-summary-goto-subject gnus-current-article))
4218                 (gnus-run-hooks 'gnus-mark-article-hook)
4219                 (gnus-set-mode-line 'summary)
4220                 (when (gnus-visual-p 'article-highlight 'highlight)
4221                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4222                 ;; Set the global newsgroup variables here.
4223                 (gnus-set-global-variables)
4224                 (setq gnus-have-all-headers
4225                       (or all-headers gnus-show-all-headers))))
4226             (save-excursion
4227               (gnus-configure-windows 'article))
4228             (when (or (numberp article)
4229                       (stringp article))
4230               (gnus-article-prepare-display)
4231               ;; Do page break.
4232               (goto-char (point-min))
4233               (when gnus-break-pages
4234                 (gnus-narrow-to-page)))
4235             (let ((gnus-article-mime-handle-alist-1
4236                    gnus-article-mime-handle-alist))
4237               (gnus-set-mode-line 'article))
4238             (article-goto-body)
4239             (unless (bobp)
4240               (forward-line -1))
4241             (set-window-point (get-buffer-window (current-buffer)) (point))
4242             (gnus-configure-windows 'article)
4243             t))))))
4244
4245 ;;;###autoload
4246 (defun gnus-article-prepare-display ()
4247   "Make the current buffer look like a nice article."
4248   ;; Hooks for getting information from the article.
4249   ;; This hook must be called before being narrowed.
4250   (let ((gnus-article-buffer (current-buffer))
4251         buffer-read-only
4252         (inhibit-read-only t))
4253     (unless (eq major-mode 'gnus-article-mode)
4254       (gnus-article-mode))
4255     (setq buffer-read-only nil
4256           gnus-article-wash-types nil
4257           gnus-article-image-alist nil)
4258     (gnus-run-hooks 'gnus-tmp-internal-hook)
4259     (when gnus-display-mime-function
4260       (funcall gnus-display-mime-function))
4261     (gnus-run-hooks 'gnus-article-prepare-hook)))
4262
4263 ;;;
4264 ;;; Gnus MIME viewing functions
4265 ;;;
4266
4267 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4268   "Format of the MIME buttons.
4269
4270 Valid specifiers include:
4271 %t  The MIME type
4272 %T  MIME type, along with additional info
4273 %n  The `name' parameter
4274 %d  The description, if any
4275 %l  The length of the encoded part
4276 %p  The part identifier number
4277 %e  Dots if the part isn't displayed
4278
4279 General format specifiers can also be used.  See Info node
4280 `(gnus)Formatting Variables'.")
4281
4282 (defvar gnus-mime-button-line-format-alist
4283   '((?t gnus-tmp-type ?s)
4284     (?T gnus-tmp-type-long ?s)
4285     (?n gnus-tmp-name ?s)
4286     (?d gnus-tmp-description ?s)
4287     (?p gnus-tmp-id ?s)
4288     (?l gnus-tmp-length ?d)
4289     (?e gnus-tmp-dots ?s)))
4290
4291 (defvar gnus-mime-button-commands
4292   '((gnus-article-press-button "\r" "Toggle Display")
4293     (gnus-mime-view-part "v" "View Interactively...")
4294     (gnus-mime-view-part-as-type "t" "View As Type...")
4295     (gnus-mime-view-part-as-charset "C" "View As charset...")
4296     (gnus-mime-save-part "o" "Save...")
4297     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4298     (gnus-mime-replace-part "r" "Replace part")
4299     (gnus-mime-delete-part "d" "Delete part")
4300     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4301     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4302     (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4303     (gnus-mime-view-part-externally "e" "View Externally")
4304     (gnus-mime-print-part "p" "Print")
4305     (gnus-mime-pipe-part "|" "Pipe To Command...")
4306     (gnus-mime-action-on-part "." "Take action on the part...")))
4307
4308 (defun gnus-article-mime-part-status ()
4309   (if gnus-article-mime-handle-alist-1
4310       (if (eq 1 (length gnus-article-mime-handle-alist-1))
4311           " (1 part)"
4312         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4313     ""))
4314
4315 (defvar gnus-mime-button-map
4316   (let ((map (make-sparse-keymap)))
4317     (define-key map gnus-mouse-2 'gnus-article-push-button)
4318     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4319     (dolist (c gnus-mime-button-commands)
4320       (define-key map (cadr c) (car c)))
4321     map))
4322
4323 (easy-menu-define
4324   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4325   `("MIME Part"
4326     ,@(mapcar (lambda (c)
4327                 (vector (caddr c) (car c) :active t))
4328               gnus-mime-button-commands)))
4329
4330 (defun gnus-mime-button-menu (event prefix)
4331  "Construct a context-sensitive menu of MIME commands."
4332  (interactive "e\nP")
4333  (save-window-excursion
4334    (let ((pos (event-start event)))
4335      (select-window (posn-window pos))
4336      (goto-char (posn-point pos))
4337      (gnus-article-check-buffer)
4338      (popup-menu gnus-mime-button-menu nil prefix))))
4339
4340 (defun gnus-mime-view-all-parts (&optional handles)
4341   "View all the MIME parts."
4342   (interactive)
4343   (with-current-buffer gnus-article-buffer
4344     (let ((handles (or handles gnus-article-mime-handles))
4345           (mail-parse-charset gnus-newsgroup-charset)
4346           (mail-parse-ignored-charsets
4347            (with-current-buffer gnus-summary-buffer
4348              gnus-newsgroup-ignored-charsets)))
4349       (when handles
4350         (mm-remove-parts handles)
4351         (goto-char (point-min))
4352         (or (search-forward "\n\n") (goto-char (point-max)))
4353         (let ((inhibit-read-only t))
4354           (delete-region (point) (point-max))
4355           (mm-display-parts handles))))))
4356
4357 (defun gnus-article-jump-to-part (n)
4358   "Jump to MIME part N."
4359   (interactive "P")
4360   (pop-to-buffer gnus-article-buffer)
4361   ;; FIXME: why is it necessary?
4362   (sit-for 0)
4363   (let ((parts (length gnus-article-mime-handle-alist)))
4364     (or n (setq n
4365                 (string-to-number
4366                  (read-string ;; Emacs 21 doesn't have `read-number'.
4367                   (format "Jump to part (2..%s): " parts)))))
4368     (unless (and (integerp n) (<= n parts) (>= n 1))
4369       (setq n
4370             (progn
4371               (gnus-message 7 "Invalid part `%s', using %s instead."
4372                             n parts)
4373               parts)))
4374     (gnus-message 9 "Jumping to part %s." n)
4375     (cond ((>= gnus-auto-select-part 1)
4376            (while (and (<= n parts)
4377                        (not (gnus-article-goto-part n)))
4378              (setq n (1+ n))))
4379           ((< gnus-auto-select-part 0)
4380            (while (and (>= n 1)
4381                        (not (gnus-article-goto-part n)))
4382              (setq n (1- n))))
4383           (t
4384            (gnus-article-goto-part n)))))
4385
4386 (eval-when-compile
4387   (defsubst gnus-article-edit-part (handles &optional current-id)
4388     "Edit an article in order to delete a mime part.
4389 This function is exclusively used by `gnus-mime-save-part-and-strip'
4390 and `gnus-mime-delete-part', and not provided at run-time normally."
4391     (gnus-article-edit-article
4392      `(lambda ()
4393         (buffer-disable-undo)
4394         (erase-buffer)
4395         (let ((mail-parse-charset (or gnus-article-charset
4396                                       ',gnus-newsgroup-charset))
4397               (mail-parse-ignored-charsets
4398                (or gnus-article-ignored-charsets
4399                    ',gnus-newsgroup-ignored-charsets))
4400               (mbl mml-buffer-list))
4401           (setq mml-buffer-list nil)
4402           (insert-buffer-substring gnus-original-article-buffer)
4403           (mime-to-mml ',handles)
4404           (setq gnus-article-mime-handles nil)
4405           (let ((mbl1 mml-buffer-list))
4406             (setq mml-buffer-list mbl)
4407             (set (make-local-variable 'mml-buffer-list) mbl1))
4408           (gnus-make-local-hook 'kill-buffer-hook)
4409           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4410      `(lambda (no-highlight)
4411         (let ((mail-parse-charset (or gnus-article-charset
4412                                       ',gnus-newsgroup-charset))
4413               (message-options message-options)
4414               (message-options-set-recipient)
4415               (mail-parse-ignored-charsets
4416                (or gnus-article-ignored-charsets
4417                    ',gnus-newsgroup-ignored-charsets)))
4418           (mml-to-mime)
4419           (mml-destroy-buffers)
4420           (remove-hook 'kill-buffer-hook
4421                        'mml-destroy-buffers t)
4422           (kill-local-variable 'mml-buffer-list))
4423         (gnus-summary-edit-article-done
4424          ,(or (mail-header-references gnus-current-headers) "")
4425          ,(gnus-group-read-only-p)
4426          ,gnus-summary-buffer no-highlight))
4427      t)
4428     (gnus-article-edit-done)
4429     (gnus-summary-expand-window)
4430     (gnus-summary-show-article)
4431     (when (and current-id (integerp gnus-auto-select-part))
4432       (gnus-article-jump-to-part
4433        (+ current-id gnus-auto-select-part)))))
4434
4435 (defun gnus-mime-replace-part (file)
4436   "Replace MIME part under point with an external body."
4437   ;; Useful if file has already been saved to disk
4438   (interactive
4439    (list
4440     (mm-with-multibyte
4441       (read-file-name "Replace MIME part with file: "
4442                       (or mm-default-directory default-directory)
4443                       nil nil))))
4444   (gnus-mime-save-part-and-strip file))
4445
4446 (defun gnus-mime-save-part-and-strip (&optional file)
4447   "Save the MIME part under point then replace it with an external body.
4448 If FILE is given, use it for the external part."
4449   (interactive)
4450   (gnus-article-check-buffer)
4451   (when (gnus-group-read-only-p)
4452     (error "The current group does not support deleting of parts"))
4453   (when (mm-complicated-handles gnus-article-mime-handles)
4454     (error "\
4455 The current article has a complicated MIME structure, giving up..."))
4456   (let* ((data (get-text-property (point) 'gnus-data))
4457          (id (get-text-property (point) 'gnus-part))
4458          param
4459          (handles gnus-article-mime-handles))
4460     (unless file
4461       (setq file
4462             (and data (mm-save-part data "Delete MIME part and save to: "))))
4463     (when file
4464       (with-current-buffer (mm-handle-buffer data)
4465         (erase-buffer)
4466         (insert "Content-Type: " (mm-handle-media-type data))
4467         (mml-insert-parameter-string (cdr (mm-handle-type data))
4468                                      '(charset))
4469         ;; Add a filename for the sake of saving the part again.
4470         (mml-insert-parameter
4471          (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4472         (insert "\n")
4473         (insert "Content-ID: " (message-make-message-id) "\n")
4474         (insert "Content-Transfer-Encoding: binary\n")
4475         (insert "\n"))
4476       (setcdr data
4477               (cdr (mm-make-handle nil
4478                                    `("message/external-body"
4479                                      (access-type . "LOCAL-FILE")
4480                                      (name . ,file)))))
4481       ;; (set-buffer gnus-summary-buffer)
4482       (gnus-article-edit-part handles id))))
4483
4484 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4485 ;; parts...>') but with stripping would be nice.
4486
4487 (defun gnus-mime-delete-part ()
4488   "Delete the MIME part under point.
4489 Replace it with some information about the removed part."
4490   (interactive)
4491   (gnus-article-check-buffer)
4492   (when (gnus-group-read-only-p)
4493     (error "The current group does not support deleting of parts"))
4494   (when (mm-complicated-handles gnus-article-mime-handles)
4495     (error "\
4496 The current article has a complicated MIME structure, giving up..."))
4497   (when (or gnus-expert-user
4498             (gnus-yes-or-no-p "\
4499 Deleting parts may malfunction or destroy the article; continue? "))
4500     (let* ((data (get-text-property (point) 'gnus-data))
4501            (id (get-text-property (point) 'gnus-part))
4502            (handles gnus-article-mime-handles)
4503            (none "(none)")
4504            (description
4505             (or
4506              (mail-decode-encoded-word-string (or (mm-handle-description data)
4507                                                   none))))
4508            (filename
4509             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4510                 none))
4511            (type (mm-handle-media-type data)))
4512       (unless data
4513         (error "No MIME part under point"))
4514       (with-current-buffer (mm-handle-buffer data)
4515         (let ((bsize (format "%s" (buffer-size))))
4516           (erase-buffer)
4517           (insert
4518            (concat
4519             ",----\n"
4520             "| The following attachment has been deleted:\n"
4521             "|\n"
4522             "| Type:           " type "\n"
4523             "| Filename:       " filename "\n"
4524             "| Size (encoded): " bsize " Byte\n"
4525             "| Description:    " description "\n"
4526             "`----\n"))
4527           (setcdr data
4528                   (cdr (mm-make-handle
4529                         nil `("text/plain") nil nil
4530                         (list "attachment")
4531                         (format "Deleted attachment (%s bytes)" bsize))))))
4532       ;; (set-buffer gnus-summary-buffer)
4533       (gnus-article-edit-part handles id))))
4534
4535 (defun gnus-mime-save-part ()
4536   "Save the MIME part under point."
4537   (interactive)
4538   (gnus-article-check-buffer)
4539   (let ((data (get-text-property (point) 'gnus-data)))
4540     (when data
4541       (mm-save-part data))))
4542
4543 (defun gnus-mime-pipe-part ()
4544   "Pipe the MIME part under point to a process."
4545   (interactive)
4546   (gnus-article-check-buffer)
4547   (let ((data (get-text-property (point) 'gnus-data)))
4548     (when data
4549       (mm-pipe-part data))))
4550
4551 (defun gnus-mime-view-part ()
4552   "Interactively choose a viewing method for the MIME part under point."
4553   (interactive)
4554   (gnus-article-check-buffer)
4555   (let ((data (get-text-property (point) 'gnus-data)))
4556     (when data
4557       (setq gnus-article-mime-handles
4558             (mm-merge-handles
4559              gnus-article-mime-handles (setq data (copy-sequence data))))
4560       (mm-interactively-view-part data))))
4561
4562 (defun gnus-mime-view-part-as-type-internal ()
4563   (gnus-article-check-buffer)
4564   (let* ((handle (get-text-property (point) 'gnus-data))
4565          (name (or
4566                 ;; Content-Type: foo/bar; name=...
4567                 (mail-content-type-get (mm-handle-type handle) 'name)
4568                 ;; Content-Disposition: attachment; filename=...
4569                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4570          (def-type (and name (mm-default-file-encoding name))))
4571     (and def-type (cons def-type 0))))
4572
4573 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4574   "Choose a MIME media type, and view the part as such.
4575 If non-nil, PRED is a predicate to use during completion to limit the
4576 available media-types."
4577   (interactive)
4578   (unless mime-type
4579     (setq mime-type
4580           (let ((default (gnus-mime-view-part-as-type-internal)))
4581             (completing-read
4582              (format "View as MIME type (default %s): "
4583                      (car default))
4584              (mapcar #'list (mailcap-mime-types))
4585              pred nil nil nil
4586              (car default)))))
4587   (gnus-article-check-buffer)
4588   (let ((handle (get-text-property (point) 'gnus-data)))
4589     (when handle
4590       (when (equal (mm-handle-media-type handle) "message/external-body")
4591         (unless (mm-handle-cache handle)
4592           (mm-extern-cache-contents handle))
4593         (setq handle (mm-handle-cache handle)))
4594       (setq handle
4595             (mm-make-handle (mm-handle-buffer handle)
4596                             (cons mime-type (cdr (mm-handle-type handle)))
4597                             (mm-handle-encoding handle)
4598                             (mm-handle-undisplayer handle)
4599                             (mm-handle-disposition handle)
4600                             (mm-handle-description handle)
4601                             nil
4602                             (mm-handle-id handle)))
4603       (setq gnus-article-mime-handles
4604             (mm-merge-handles gnus-article-mime-handles handle))
4605       (gnus-mm-display-part handle))))
4606
4607 (defun gnus-mime-copy-part (&optional handle arg)
4608   "Put the MIME part under point into a new buffer.
4609 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4610 are decompressed."
4611   (interactive (list nil current-prefix-arg))
4612   (gnus-article-check-buffer)
4613   (unless handle
4614     (setq handle (get-text-property (point) 'gnus-data)))
4615   (when handle
4616     (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4617                                                'name)
4618                         (mail-content-type-get (mm-handle-disposition handle)
4619                                                'filename)))
4620           contents dont-decode charset coding-system)
4621       (mm-with-unibyte-buffer
4622         (mm-insert-part handle)
4623         (setq contents (or (condition-case nil
4624                                (mm-decompress-buffer filename nil 'sig)
4625                              (error
4626                               (setq dont-decode t)
4627                               nil))
4628                            (buffer-string))))
4629       (setq filename (cond (filename (file-name-nondirectory filename))
4630                            (dont-decode "*raw data*")
4631                            (t "*decoded*")))
4632       (cond
4633        (dont-decode)
4634        ((not arg)
4635         (unless (setq charset (mail-content-type-get
4636                                (mm-handle-type handle) 'charset))
4637           (unless (setq coding-system (mm-with-unibyte-buffer
4638                                         (insert contents)
4639                                         (mm-find-buffer-file-coding-system)))
4640             (setq charset gnus-newsgroup-charset))))
4641        ((numberp arg)
4642         (setq charset (or (cdr (assq arg
4643                                      gnus-summary-show-article-charset-alist))
4644                           (mm-read-coding-system "Charset: ")))))
4645       (switch-to-buffer (generate-new-buffer filename))
4646       (if (or coding-system
4647               (and charset
4648                    (setq coding-system (mm-charset-to-coding-system charset))
4649                    (not (eq charset 'ascii))))
4650           (progn
4651             (mm-enable-multibyte)
4652             (insert (mm-decode-coding-string contents coding-system))
4653             (setq buffer-file-coding-system
4654                   (if (boundp 'last-coding-system-used)
4655                       (symbol-value 'last-coding-system-used)
4656                     coding-system)))
4657         (mm-disable-multibyte)
4658         (insert contents)
4659         (setq buffer-file-coding-system mm-binary-coding-system))
4660       ;; We do it this way to make `normal-mode' set the appropriate mode.
4661       (unwind-protect
4662           (progn
4663             (setq buffer-file-name (expand-file-name filename))
4664             (normal-mode))
4665         (setq buffer-file-name nil))
4666       (goto-char (point-min)))))
4667
4668 (defun gnus-mime-print-part (&optional handle filename)
4669   "Print the MIME part under point."
4670   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4671   (gnus-article-check-buffer)
4672   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4673          (contents (and handle (mm-get-part handle)))
4674          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4675          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4676     (when contents
4677         (if printer
4678             (unwind-protect
4679                 (progn
4680                   (mm-save-part-to-file handle file)
4681                   (call-process shell-file-name nil
4682                                 (generate-new-buffer " *mm*")
4683                                 nil
4684                                 shell-command-switch
4685                                 (mm-mailcap-command
4686                                  printer file (mm-handle-type handle))))
4687               (delete-file file))
4688           (with-temp-buffer
4689             (insert contents)
4690             (gnus-print-buffer))
4691           (ps-despool filename)))))
4692
4693 (defun gnus-mime-inline-part (&optional handle arg)
4694   "Insert the MIME part under point into the current buffer.
4695 Compressed files like .gz and .bz2 are decompressed."
4696   (interactive (list nil current-prefix-arg))
4697   (gnus-article-check-buffer)
4698   (unless handle
4699     (setq handle (get-text-property (point) 'gnus-data)))
4700   (when handle
4701     (let ((b (point))
4702           (inhibit-read-only t)
4703           contents charset coding-system)
4704       (if (and (not arg) (mm-handle-undisplayer handle))
4705           (mm-remove-part handle)
4706         (mm-with-unibyte-buffer
4707           (mm-insert-part handle)
4708           (setq contents
4709                 (or (mm-decompress-buffer
4710                      (or (mail-content-type-get (mm-handle-type handle)
4711                                                 'name)
4712                          (mail-content-type-get (mm-handle-disposition handle)
4713                                                 'filename))
4714                      nil t)
4715                     (buffer-string))))
4716         (cond
4717          ((not arg)
4718           (unless (setq charset (mail-content-type-get
4719                                  (mm-handle-type handle) 'charset))
4720             (unless (setq coding-system
4721                           (mm-with-unibyte-buffer
4722                             (insert contents)
4723                             (mm-find-buffer-file-coding-system)))
4724               (setq charset gnus-newsgroup-charset))))
4725          ((numberp arg)
4726           (if (mm-handle-undisplayer handle)
4727               (mm-remove-part handle))
4728           (setq charset
4729                 (or (cdr (assq arg
4730                                gnus-summary-show-article-charset-alist))
4731                     (mm-read-coding-system "Charset: "))))
4732          (t
4733           (if (mm-handle-undisplayer handle)
4734               (mm-remove-part handle))))
4735         (forward-line 2)
4736         (mm-insert-inline
4737          handle
4738          (if (or coding-system
4739                  (and charset
4740                       (setq coding-system
4741                             (mm-charset-to-coding-system charset))
4742                       (not (eq coding-system 'ascii))))
4743              (mm-decode-coding-string contents coding-system)
4744            (mm-string-to-multibyte contents)))
4745         (goto-char b)))))
4746
4747 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4748   "Insert the MIME part under point into the current buffer using the
4749 specified charset."
4750   (interactive (list nil current-prefix-arg))
4751   (gnus-article-check-buffer)
4752   (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4753         (fun (get-text-property (point) 'gnus-callback))
4754         (gnus-newsgroup-ignored-charsets 'gnus-all)
4755         gnus-newsgroup-charset type charset)
4756     (when handle
4757       (if (mm-handle-undisplayer handle)
4758           (mm-remove-part handle))
4759       (when fun
4760         (setq gnus-newsgroup-charset
4761               (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4762                   (mm-read-coding-system "Charset: ")))
4763         ;; Strip the charset parameter from `handle'.
4764         (setq type (mm-handle-type
4765                     (if (equal (mm-handle-media-type handle)
4766                                "message/external-body")
4767                         (progn
4768                           (unless (mm-handle-cache handle)
4769                             (mm-extern-cache-contents handle))
4770                           (mm-handle-cache handle))
4771                       handle))
4772               charset (assq 'charset (cdr type)))
4773         (delq charset type)
4774         (funcall fun handle)))))
4775
4776 (defun gnus-mime-view-part-externally (&optional handle)
4777   "View the MIME part under point with an external viewer."
4778   (interactive)
4779   (gnus-article-check-buffer)
4780   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4781          (mm-user-display-methods nil)
4782          (mm-inlined-types nil)
4783          (mail-parse-charset gnus-newsgroup-charset)
4784          (mail-parse-ignored-charsets
4785           (with-current-buffer gnus-summary-buffer
4786             gnus-newsgroup-ignored-charsets))
4787          (type (mm-handle-media-type handle))
4788          (method (mailcap-mime-info type))
4789          (mm-enable-external t))
4790     (if (not (stringp method))
4791         (gnus-mime-view-part-as-type
4792          nil (lambda (type) (stringp (mailcap-mime-info type))))
4793       (when handle
4794         (if (mm-handle-undisplayer handle)
4795             (mm-remove-part handle)
4796           (mm-display-part handle))))))
4797
4798 (defun gnus-mime-view-part-internally (&optional handle)
4799   "View the MIME part under point with an internal viewer.
4800 If no internal viewer is available, use an external viewer."
4801   (interactive)
4802   (gnus-article-check-buffer)
4803   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4804          (mm-inlined-types '(".*"))
4805          (mm-inline-large-images t)
4806          (mail-parse-charset gnus-newsgroup-charset)
4807          (mail-parse-ignored-charsets
4808           (with-current-buffer gnus-summary-buffer
4809             gnus-newsgroup-ignored-charsets))
4810          (inhibit-read-only t))
4811     (if (not (mm-inlinable-p handle))
4812         (gnus-mime-view-part-as-type
4813          nil (lambda (type) (mm-inlinable-p handle type)))
4814       (when handle
4815         (if (mm-handle-undisplayer handle)
4816             (mm-remove-part handle)
4817           (mm-display-part handle))))))
4818
4819 (defun gnus-mime-action-on-part (&optional action)
4820   "Do something with the MIME attachment at \(point\)."
4821   (interactive
4822    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4823   (gnus-article-check-buffer)
4824   (let ((action-pair (assoc action gnus-mime-action-alist)))
4825     (if action-pair
4826         (funcall (cdr action-pair)))))
4827
4828 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4829   "Call FUNCTION on MIME part N.
4830 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4831 If INTERACTIVE, call FUNCTION interactivly."
4832   (let (window frame)
4833     ;; Check whether the article is displayed.
4834     (unless (and (gnus-buffer-live-p gnus-article-buffer)
4835                  (setq window (get-buffer-window gnus-article-buffer t))
4836                  (frame-visible-p (setq frame (window-frame window))))
4837       (error "No article is displayed"))
4838     (with-current-buffer gnus-article-buffer
4839       ;; Check whether the article displays the right contents.
4840       (unless (with-current-buffer gnus-summary-buffer
4841                 (eq gnus-current-article (gnus-summary-article-number)))
4842         (error "You should select the right article first"))
4843       ;; Check whether the specified part exists.
4844       (when (> n (length gnus-article-mime-handle-alist))
4845         (error "No such part")))
4846     (unless
4847         (progn
4848           ;; To select the window is needed so that the cursor
4849           ;; might be visible on the MIME button.
4850           (select-window (prog1
4851                              window
4852                            (setq window (selected-window))
4853                            ;; Article may be displayed in the other frame.
4854                            (gnus-select-frame-set-input-focus
4855                             (prog1
4856                                 frame
4857                               (setq frame (selected-frame))))))
4858           (when (gnus-article-goto-part n)
4859             ;; We point the cursor and the arrow at the MIME button
4860             ;; when the `function' prompt the user for something.
4861             (let ((cursor-in-non-selected-windows t)
4862                   (overlay-arrow-string "=>")
4863                   (overlay-arrow-position (point-marker)))
4864               (unwind-protect
4865                   (cond
4866                    ((and no-handle interactive)
4867                     (call-interactively function))
4868                    (no-handle
4869                     (funcall function))
4870                    (interactive
4871                     (call-interactively
4872                      function
4873                      (cdr (assq n gnus-article-mime-handle-alist))))
4874                    (t
4875                     (funcall function
4876                              (cdr (assq n gnus-article-mime-handle-alist)))))
4877                 (set-marker overlay-arrow-position nil)
4878                 (unless gnus-auto-select-part
4879                   (gnus-select-frame-set-input-focus frame)
4880                   (select-window window))))
4881             t))
4882       (if gnus-inhibit-mime-unbuttonizing
4883           ;; This is the default though the program shouldn't reach here.
4884           (error "No such part")
4885         ;; The part which doesn't have the MIME button is selected.
4886         ;; So, we display all the buttons and redo it.
4887         (let ((gnus-inhibit-mime-unbuttonizing t))
4888           (gnus-summary-show-article)
4889           (gnus-article-part-wrapper n function no-handle))))))
4890
4891 (defun gnus-article-pipe-part (n)
4892   "Pipe MIME part N, which is the numerical prefix."
4893   (interactive "p")
4894   (gnus-article-part-wrapper n 'mm-pipe-part))
4895
4896 (defun gnus-article-save-part (n)
4897   "Save MIME part N, which is the numerical prefix."
4898   (interactive "p")
4899   (gnus-article-part-wrapper n 'mm-save-part))
4900
4901 (defun gnus-article-interactively-view-part (n)
4902   "View MIME part N interactively, which is the numerical prefix."
4903   (interactive "p")
4904   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4905
4906 (defun gnus-article-copy-part (n)
4907   "Copy MIME part N, which is the numerical prefix."
4908   (interactive "p")
4909   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4910
4911 (defun gnus-article-view-part-as-charset (n)
4912   "View MIME part N using a specified charset.
4913 N is the numerical prefix."
4914   (interactive "p")
4915   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4916
4917 (defun gnus-article-view-part-externally (n)
4918   "View MIME part N externally, which is the numerical prefix."
4919   (interactive "p")
4920   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4921
4922 (defun gnus-article-inline-part (n)
4923   "Inline MIME part N, which is the numerical prefix."
4924   (interactive "p")
4925   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4926
4927 (defun gnus-article-save-part-and-strip (n)
4928   "Save MIME part N and replace it with an external body.
4929 N is the numerical prefix."
4930   (interactive "p")
4931   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
4932
4933 (defun gnus-article-replace-part (n)
4934   "Replace MIME part N with an external body.
4935 N is the numerical prefix."
4936   (interactive "p")
4937   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
4938
4939 (defun gnus-article-delete-part (n)
4940   "Delete MIME part N and add some information about the removed part.
4941 N is the numerical prefix."
4942   (interactive "p")
4943   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
4944
4945 (defun gnus-article-view-part-as-type (n)
4946   "Choose a MIME media type, and view part N as such.
4947 N is the numerical prefix."
4948   (interactive "p")
4949   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
4950
4951 (defun gnus-article-mime-match-handle-first (condition)
4952   (if condition
4953       (let (n)
4954         (dolist (ihandle gnus-article-mime-handle-alist)
4955           (if (and (cond
4956                     ((functionp condition)
4957                      (funcall condition (cdr ihandle)))
4958                     ((eq condition 'undisplayed)
4959                      (not (or (mm-handle-undisplayer (cdr ihandle))
4960                               (equal (mm-handle-media-type (cdr ihandle))
4961                                      "multipart/alternative"))))
4962                     ((eq condition 'undisplayed-alternative)
4963                      (not (mm-handle-undisplayer (cdr ihandle))))
4964                     (t t))
4965                    (gnus-article-goto-part (car ihandle))
4966                    (or (not n) (< (car ihandle) n)))
4967               (setq n (car ihandle))))
4968         (or n 1))
4969     1))
4970
4971 (defun gnus-article-view-part (&optional n)
4972   "View MIME part N, which is the numerical prefix."
4973   (interactive "P")
4974   (with-current-buffer gnus-article-buffer
4975     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4976                              gnus-article-mime-match-handle-function)))
4977     (when (> n (length gnus-article-mime-handle-alist))
4978       (error "No such part"))
4979     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4980       (when (gnus-article-goto-part n)
4981         (if (equal (car handle) "multipart/alternative")
4982             (gnus-article-press-button)
4983           (when (eq (gnus-mm-display-part handle) 'internal)
4984             (gnus-set-window-start)))))))
4985
4986 (defsubst gnus-article-mime-total-parts ()
4987   (if (bufferp (car gnus-article-mime-handles))
4988       1 ;; single part
4989     (1- (length gnus-article-mime-handles))))
4990
4991 (defun gnus-mm-display-part (handle)
4992   "Display HANDLE and fix MIME button."
4993   (let ((id (get-text-property (point) 'gnus-part))
4994         (point (point))
4995         (inhibit-read-only t))
4996     (forward-line 1)
4997     (prog1
4998         (let ((window (selected-window))
4999               (mail-parse-charset gnus-newsgroup-charset)
5000               (mail-parse-ignored-charsets
5001                (if (gnus-buffer-live-p gnus-summary-buffer)
5002                    (with-current-buffer gnus-summary-buffer
5003                      gnus-newsgroup-ignored-charsets)
5004                  nil)))
5005           (save-excursion
5006             (unwind-protect
5007                 (let ((win (gnus-get-buffer-window (current-buffer) t))
5008                       (beg (point)))
5009                   (when win
5010                     (select-window win))
5011                   (goto-char point)
5012                   (forward-line)
5013                   (if (mm-handle-displayed-p handle)
5014                       ;; This will remove the part.
5015                       (mm-display-part handle)
5016                     (save-restriction
5017                       (narrow-to-region (point)
5018                                         (if (eobp) (point) (1+ (point))))
5019                       (mm-display-part handle)
5020                       ;; We narrow to the part itself and
5021                       ;; then call the treatment functions.
5022                       (goto-char (point-min))
5023                       (forward-line 1)
5024                       (narrow-to-region (point) (point-max))
5025                       (gnus-treat-article
5026                        nil id
5027                        (gnus-article-mime-total-parts)
5028                        (mm-handle-media-type handle)))))
5029               (if (window-live-p window)
5030                   (select-window window)))))
5031       (goto-char point)
5032       (gnus-delete-line)
5033       (gnus-insert-mime-button
5034        handle id (list (mm-handle-displayed-p handle)))
5035       (goto-char point))))
5036
5037 (defun gnus-article-goto-part (n)
5038   "Go to MIME part N."
5039   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5040
5041 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5042   (let ((gnus-tmp-name
5043          (or (mail-content-type-get (mm-handle-type handle) 'name)
5044              (mail-content-type-get (mm-handle-disposition handle) 'filename)
5045              (mail-content-type-get (mm-handle-type handle) 'url)
5046              ""))
5047         (gnus-tmp-type (mm-handle-media-type handle))
5048         (gnus-tmp-description
5049          (mail-decode-encoded-word-string (or (mm-handle-description handle)
5050                                               "")))
5051         (gnus-tmp-dots
5052          (if (if displayed (car displayed)
5053                (mm-handle-displayed-p handle))
5054              "" "..."))
5055         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5056                            (buffer-size)))
5057         gnus-tmp-type-long b e)
5058     (when (string-match ".*/" gnus-tmp-name)
5059       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5060     (setq gnus-tmp-type-long (concat gnus-tmp-type
5061                                      (and (not (equal gnus-tmp-name ""))
5062                                           (concat "; " gnus-tmp-name))))
5063     (unless (equal gnus-tmp-description "")
5064       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5065     (unless (bolp)
5066       (insert "\n"))
5067     (setq b (point))
5068     (gnus-eval-format
5069      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5070      `(keymap ,gnus-mime-button-map
5071               gnus-callback gnus-mm-display-part
5072               gnus-part ,gnus-tmp-id
5073               article-type annotation
5074               gnus-data ,handle))
5075     (setq e (if (bolp)
5076                 ;; Exclude a newline.
5077                 (1- (point))
5078               (point)))
5079     (widget-convert-button
5080      'link b e
5081      :mime-handle handle
5082      :action 'gnus-widget-press-button
5083      :button-keymap gnus-mime-button-map
5084      :help-echo
5085      (lambda (widget/window &optional overlay pos)
5086        ;; Needed to properly clear the message due to a bug in
5087        ;; wid-edit (XEmacs only).
5088        (if (boundp 'help-echo-owns-message)
5089            (setq help-echo-owns-message t))
5090        (format
5091         "%S: %s the MIME part; %S: more options"
5092         (aref gnus-mouse-2 0)
5093         ;; XEmacs will get a single widget arg; Emacs 21 will get
5094         ;; window, overlay, position.
5095         (if (mm-handle-displayed-p
5096              (if overlay
5097                  (with-current-buffer (gnus-overlay-buffer overlay)
5098                    (widget-get (widget-at (gnus-overlay-start overlay))
5099                                :mime-handle))
5100                (widget-get widget/window :mime-handle)))
5101             "hide" "show")
5102         (aref gnus-down-mouse-3 0))))))
5103
5104 (defun gnus-widget-press-button (elems el)
5105   (goto-char (widget-get elems :from))
5106   (gnus-article-press-button))
5107
5108 (defvar gnus-displaying-mime nil)
5109
5110 (defun gnus-display-mime (&optional ihandles)
5111   "Display the MIME parts."
5112   (save-excursion
5113     (save-selected-window
5114       (let ((window (get-buffer-window gnus-article-buffer))
5115             (point (point)))
5116         (when window
5117           (select-window window)
5118           ;; We have to do this since selecting the window
5119           ;; may change the point.  So we set the window point.
5120           (set-window-point window point)))
5121       (let ((handles ihandles)
5122             (inhibit-read-only t)
5123             handle)
5124         (cond (handles)