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