(gnus-article-send-map): New keymap for S prefix keys; bind SW key to
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 ;; For Emacs < 22.2.
31 (eval-and-compile
32   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (eval-when-compile
34   (require 'cl))
35 (defvar tool-bar-map)
36 (defvar w3m-minor-mode-map)
37
38 (require 'gnus)
39 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
40 (eval-and-compile
41   (let ((recursive-load-depth-limit 100))
42     (require 'gnus-sum)))
43 (require 'gnus-spec)
44 (require 'gnus-int)
45 (require 'gnus-win)
46 (require 'mm-bodies)
47 (require 'mail-parse)
48 (require 'mm-decode)
49 (require 'mm-view)
50 (require 'wid-edit)
51 (require 'mm-uu)
52 (require 'message)
53
54 (autoload 'gnus-msg-mail "gnus-msg" nil t)
55 (autoload 'gnus-button-mailto "gnus-msg")
56 (autoload 'gnus-button-reply "gnus-msg" nil t)
57 (autoload 'parse-time-string "parse-time" nil nil)
58 (autoload 'ansi-color-apply-on-region "ansi-color")
59 (autoload 'mm-url-insert-file-contents-external "mm-url")
60 (autoload 'mm-extern-cache-contents "mm-extern")
61
62 (defgroup gnus-article nil
63   "Article display."
64   :link '(custom-manual "(gnus)Article Buffer")
65   :group 'gnus)
66
67 (defgroup gnus-article-treat nil
68   "Treating article parts."
69   :link '(custom-manual "(gnus)Article Hiding")
70   :group 'gnus-article)
71
72 (defgroup gnus-article-hiding nil
73   "Hiding article parts."
74   :link '(custom-manual "(gnus)Article Hiding")
75   :group 'gnus-article)
76
77 (defgroup gnus-article-highlight nil
78   "Article highlighting."
79   :link '(custom-manual "(gnus)Article Highlighting")
80   :group 'gnus-article
81   :group 'gnus-visual)
82
83 (defgroup gnus-article-signature nil
84   "Article signatures."
85   :link '(custom-manual "(gnus)Article Signature")
86   :group 'gnus-article)
87
88 (defgroup gnus-article-headers nil
89   "Article headers."
90   :link '(custom-manual "(gnus)Hiding Headers")
91   :group 'gnus-article)
92
93 (defgroup gnus-article-washing nil
94   "Special commands on articles."
95   :link '(custom-manual "(gnus)Article Washing")
96   :group 'gnus-article)
97
98 (defgroup gnus-article-emphasis nil
99   "Fontisizing articles."
100   :link '(custom-manual "(gnus)Article Fontisizing")
101   :group 'gnus-article)
102
103 (defgroup gnus-article-saving nil
104   "Saving articles."
105   :link '(custom-manual "(gnus)Saving Articles")
106   :group 'gnus-article)
107
108 (defgroup gnus-article-mime nil
109   "Worshiping the MIME wonder."
110   :link '(custom-manual "(gnus)Using MIME")
111   :group 'gnus-article)
112
113 (defgroup gnus-article-buttons nil
114   "Pushable buttons in the article buffer."
115   :link '(custom-manual "(gnus)Article Buttons")
116   :group 'gnus-article)
117
118 (defgroup gnus-article-various nil
119   "Other article options."
120   :link '(custom-manual "(gnus)Misc Article")
121   :group 'gnus-article)
122
123 (defcustom gnus-ignored-headers
124   (mapcar
125    (lambda (header)
126      (concat "^" header ":"))
127    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
128      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
129      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
130      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
131      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
132      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
133      "X-Attribution" "X-Originating-IP" "Delivered-To"
134      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
135      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
136      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
137      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
138      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
139      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
140      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
141      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
142      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
143      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
144      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
145      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
146      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
147      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
148      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
149      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
150      "List-[A-Za-z]+" "X-Listprocessor-Version"
151      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
152      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
153      "X-Received" "Content-length" "X-precedence"
154      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
155      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
156      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
157      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
158      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
159      "X-Content-length" "X-Posting-Agent" "Original-Received"
160      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
161      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
162      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
163      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
164      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
165      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
166      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
167      "Envelope-Sender" "Envelope-Recipients"))
168   "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171   :type '(choice :custom-show nil
172                  regexp
173                  (repeat regexp))
174   :group 'gnus-article-hiding)
175
176 (defcustom gnus-visible-headers
177   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
178   "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181   :type '(repeat :value-to-internal (lambda (widget value)
182                                       (custom-split-regexp-maybe value))
183                  :match (lambda (widget value)
184                           (or (stringp value)
185                               (widget-editable-list-match widget value)))
186                  regexp)
187   :group 'gnus-article-hiding)
188
189 (defcustom gnus-sorted-header-list
190   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192   "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
195 this list."
196   :type '(repeat regexp)
197   :group 'gnus-article-hiding)
198
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200   "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
202
203   'empty       Headers with no content.
204   'newsgroups  Newsgroup identical to Gnus group.
205   'to-address  To identical to To-address.
206   'to-list     To identical to To-list.
207   'cc-list     CC identical to To-list.
208   'followup-to Followup-to identical to Newsgroups.
209   'reply-to    Reply-to identical to From.
210   'date        Date less than four days old.
211   'long-to     To and/or Cc longer than 1024 characters.
212   'many-to     Multiple To and/or Cc."
213   :type '(set (const :tag "Headers with no content." empty)
214               (const :tag "Newsgroups identical to Gnus group." newsgroups)
215               (const :tag "To identical to To-address." to-address)
216               (const :tag "To identical to To-list." to-list)
217               (const :tag "CC identical to To-list." cc-list)
218               (const :tag "Followup-to identical to Newsgroups." followup-to)
219               (const :tag "Reply-to identical to From." reply-to)
220               (const :tag "Date less than four days old." date)
221               (const :tag "To and/or Cc longer than 1024 characters." long-to)
222               (const :tag "Multiple To and/or Cc headers." many-to))
223   :group 'gnus-article-hiding)
224
225 (defcustom gnus-article-skip-boring nil
226   "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text.  Boring text is controlled by
230 `gnus-article-boring-faces'."
231   :version "22.1"
232   :type 'boolean
233   :group 'gnus-article-hiding)
234
235 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
236   "Regexp matching signature separator.
237 This can also be a list of regexps.  In that case, it will be checked
238 from head to tail looking for a separator.  Searches will be done from
239 the end of the buffer."
240   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
241                  (regexp)
242                  (repeat :tag "List of regexp" regexp))
243   :group 'gnus-article-signature)
244
245 (defcustom gnus-signature-limit nil
246   "Provide a limit to what is considered a signature.
247 If it is a number, no signature may not be longer (in characters) than
248 that number.  If it is a floating point number, no signature may be
249 longer (in lines) than that number.  If it is a function, the function
250 will be called without any parameters, and if it returns nil, there is
251 no signature in the buffer.  If it is a string, it will be used as a
252 regexp.  If it matches, the text in question is not a signature.
253
254 This can also be a list of the above values."
255   :type '(choice (const nil)
256                  (integer :value 200)
257                  (number :value 4.0)
258                  function
259                  (regexp :value ".*"))
260   :group 'gnus-article-signature)
261
262 (defcustom gnus-hidden-properties '(invisible t intangible t)
263   "Property list to use for hiding text."
264   :type 'sexp
265   :group 'gnus-article-hiding)
266
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270   (if (featurep 'xemacs)
271       (if (or (gnus-image-type-available-p 'xface)
272               (gnus-image-type-available-p 'pbm))
273           'gnus-display-x-face-in-from
274         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
275     (if (gnus-image-type-available-p 'pbm)
276         'gnus-display-x-face-in-from
277       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
278 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 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540   "A function to save articles in your favourite format.
541 The function will be called by way of the `gnus-summary-save-article'
542 command, and friends such as `gnus-summary-save-article-rmail'.
543
544 Gnus provides the following functions:
545
546 * gnus-summary-save-in-rmail (Rmail format)
547 * gnus-summary-save-in-mail (Unix mail format)
548 * gnus-summary-save-in-folder (MH folder)
549 * gnus-summary-save-in-file (article format)
550 * gnus-summary-save-body-in-file (article body)
551 * gnus-summary-save-in-vm (use VM's folder format)
552 * gnus-summary-write-to-file (article format -- overwrite)
553 * gnus-summary-write-body-to-file (article body -- overwrite)
554
555 The symbol of each function may have the following properties:
556
557 * :decode
558 The value non-nil means save decoded articles.  This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
561
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file.  This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file.  This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved.  If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574   :group 'gnus-article-saving
575   :type '(radio (function-item gnus-summary-save-in-rmail)
576                 (function-item gnus-summary-save-in-mail)
577                 (function-item gnus-summary-save-in-folder)
578                 (function-item gnus-summary-save-in-file)
579                 (function-item gnus-summary-save-body-in-file)
580                 (function-item gnus-summary-save-in-vm)
581                 (function-item gnus-summary-write-to-file)
582                 (function-item gnus-summary-write-body-to-file)
583                 (function)))
584
585 (defcustom gnus-article-save-coding-system
586   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
587       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
588       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
589       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
590   "Coding system used to save decoded articles to a file.
591
592 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
593 which can safely encode any characters in text.  This is used by the
594 commands including:
595
596 * gnus-summary-save-article-file
597 * gnus-summary-save-article-body-file
598 * gnus-summary-write-article-file
599 * gnus-summary-write-article-body-file
600
601 and the functions to which you may set `gnus-default-article-saver':
602
603 * gnus-summary-save-in-file
604 * gnus-summary-save-body-in-file
605 * gnus-summary-write-to-file
606 * gnus-summary-write-body-to-file
607
608 Those commands and functions save just text displayed in the article
609 buffer to a file if the value of this variable is non-nil.  Note that
610 buttonized MIME parts will be lost in a saved file in that case.
611 Otherwise, raw articles will be saved."
612   :group 'gnus-article-saving
613   :type `(choice
614           :format "%{%t%}:\n %[Value Menu%] %v"
615           (const :tag "Save raw articles" nil)
616           ,@(delq nil
617                   (mapcar
618                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
619                    '((const :tag "UTF-8" utf-8)
620                      (const :tag "iso-2022-7bit" iso-2022-7bit)
621                      (const :tag "Emacs internal" emacs-mule)
622                      (const :tag "escape-quoted" escape-quoted))))
623           (symbol :tag "Coding system")))
624
625 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
626   "A function generating a file name to save articles in Rmail format.
627 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
628   :group 'gnus-article-saving
629   :type 'function)
630
631 (defcustom gnus-mail-save-name 'gnus-plain-save-name
632   "A function generating a file name to save articles in Unix mail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634   :group 'gnus-article-saving
635   :type 'function)
636
637 (defcustom gnus-folder-save-name 'gnus-folder-save-name
638   "A function generating a file name to save articles in MH folder.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
640   :group 'gnus-article-saving
641   :type 'function)
642
643 (defcustom gnus-file-save-name 'gnus-numeric-save-name
644   "A function generating a file name to save articles in article format.
645 The function is called with NEWSGROUP, HEADERS, and optional
646 LAST-FILE."
647   :group 'gnus-article-saving
648   :type 'function)
649
650 (defcustom gnus-split-methods
651   '((gnus-article-archive-name)
652     (gnus-article-nndoc-name))
653   "*Variable used to suggest where articles are to be saved.
654 For instance, if you would like to save articles related to Gnus in
655 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
656 you could set this variable to something like:
657
658  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
659    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
660
661 This variable is an alist where the key is the match and the
662 value is a list of possible files to save in if the match is
663 non-nil.
664
665 If the match is a string, it is used as a regexp match on the
666 article.  If the match is a symbol, that symbol will be funcalled
667 from the buffer of the article to be saved with the newsgroup as the
668 parameter.  If it is a list, it will be evaled in the same buffer.
669
670 If this form or function returns a string, this string will be used as a
671 possible file name; and if it returns a non-nil list, that list will be
672 used as possible file names."
673   :group 'gnus-article-saving
674   :type '(repeat (choice (list :value (fun) function)
675                          (cons :value ("" "") regexp (repeat string))
676                          (sexp :value nil))))
677
678 (defcustom gnus-page-delimiter "^\^L"
679   "*Regexp describing what to use as article page delimiters.
680 The default value is \"^\^L\", which is a form linefeed at the
681 beginning of a line."
682   :type 'regexp
683   :group 'gnus-article-various)
684
685 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
686   "*The format specification for the article mode line.
687 See `gnus-summary-mode-line-format' for a closer description.
688
689 The following additional specs are available:
690
691 %w  The article washing status.
692 %m  The number of MIME parts in the article."
693   :type 'string
694   :group 'gnus-article-various)
695
696 (defcustom gnus-article-mode-hook nil
697   "*A hook for Gnus article mode."
698   :type 'hook
699   :group 'gnus-article-various)
700
701 (when (featurep 'xemacs)
702   ;; Extracted from gnus-xmas-define in order to preserve user settings
703   (when (fboundp 'turn-off-scroll-in-place)
704     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
705   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
706   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
707
708 (defcustom gnus-article-menu-hook nil
709   "*Hook run after the creation of the article mode menu."
710   :type 'hook
711   :group 'gnus-article-various)
712
713 (defcustom gnus-article-prepare-hook nil
714   "*A hook called after an article has been prepared in the article buffer."
715   :type 'hook
716   :group 'gnus-article-various)
717
718 (defcustom gnus-copy-article-ignored-headers nil
719   "List of headers to be removed when copying an article.
720 Each element is a regular expression."
721   :version "23.0" ;; No Gnus
722   :type '(repeat regexp)
723   :group 'gnus-article-various)
724
725 (make-obsolete-variable 'gnus-article-hide-pgp-hook
726                         "This variable is obsolete in Gnus 5.10.")
727
728 (defface gnus-button
729   '((t (:weight bold)))
730   "Face used for highlighting a button in the article buffer."
731   :group 'gnus-article-buttons)
732
733 (defcustom gnus-article-button-face 'gnus-button
734   "Face used for highlighting buttons in the article buffer.
735
736 An article button is a piece of text that you can activate by pressing
737 `RET' or `mouse-2' above it."
738   :type 'face
739   :group 'gnus-article-buttons)
740
741 (defcustom gnus-article-mouse-face 'highlight
742   "Face used for mouse highlighting in the article buffer.
743
744 Article buttons will be displayed in this face when the cursor is
745 above them."
746   :type 'face
747   :group 'gnus-article-buttons)
748
749 (defcustom gnus-signature-face 'gnus-signature
750   "Face used for highlighting a signature in the article buffer.
751 Obsolete; use the face `gnus-signature' for customizations instead."
752   :type 'face
753   :group 'gnus-article-highlight
754   :group 'gnus-article-signature)
755
756 (defface gnus-signature
757   '((t
758      (:italic t)))
759   "Face used for highlighting a signature in the article buffer."
760   :group 'gnus-article-highlight
761   :group 'gnus-article-signature)
762 ;; backward-compatibility alias
763 (put 'gnus-signature-face 'face-alias 'gnus-signature)
764
765 (defface gnus-header-from
766   '((((class color)
767       (background dark))
768      (:foreground "PaleGreen1"))
769     (((class color)
770       (background light))
771      (:foreground "red3"))
772     (t
773      (:italic t)))
774   "Face used for displaying from headers."
775   :group 'gnus-article-headers
776   :group 'gnus-article-highlight)
777 ;; backward-compatibility alias
778 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
779
780 (defface gnus-header-subject
781   '((((class color)
782       (background dark))
783      (:foreground "SeaGreen1"))
784     (((class color)
785       (background light))
786      (:foreground "red4"))
787     (t
788      (:bold t :italic t)))
789   "Face used for displaying subject headers."
790   :group 'gnus-article-headers
791   :group 'gnus-article-highlight)
792 ;; backward-compatibility alias
793 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
794
795 (defface gnus-header-newsgroups
796   '((((class color)
797       (background dark))
798      (:foreground "yellow" :italic t))
799     (((class color)
800       (background light))
801      (:foreground "MidnightBlue" :italic t))
802     (t
803      (:italic t)))
804   "Face used for displaying newsgroups headers.
805 In the default setup this face is only used for crossposted
806 articles."
807   :group 'gnus-article-headers
808   :group 'gnus-article-highlight)
809 ;; backward-compatibility alias
810 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
811
812 (defface gnus-header-name
813   '((((class color)
814       (background dark))
815      (:foreground "SpringGreen2"))
816     (((class color)
817       (background light))
818      (:foreground "maroon"))
819     (t
820      (:bold t)))
821   "Face used for displaying header names."
822   :group 'gnus-article-headers
823   :group 'gnus-article-highlight)
824 ;; backward-compatibility alias
825 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
826
827 (defface gnus-header-content
828   '((((class color)
829       (background dark))
830      (:foreground "SpringGreen1" :italic t))
831     (((class color)
832       (background light))
833      (:foreground "indianred4" :italic t))
834     (t
835      (:italic t)))  "Face used for displaying header content."
836   :group 'gnus-article-headers
837   :group 'gnus-article-highlight)
838 ;; backward-compatibility alias
839 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
840
841 (defcustom gnus-header-face-alist
842   '(("From" nil gnus-header-from)
843     ("Subject" nil gnus-header-subject)
844     ("Newsgroups:.*," nil gnus-header-newsgroups)
845     ("" gnus-header-name gnus-header-content))
846   "*Controls highlighting of article headers.
847
848 An alist of the form (HEADER NAME CONTENT).
849
850 HEADER is a regular expression which should match the name of a
851 header and NAME and CONTENT are either face names or nil.
852
853 The name of each header field will be displayed using the face
854 specified by the first element in the list where HEADER matches
855 the header name and NAME is non-nil.  Similarly, the content will
856 be displayed by the first non-nil matching CONTENT face."
857   :group 'gnus-article-headers
858   :group 'gnus-article-highlight
859   :type '(repeat (list (regexp :tag "Header")
860                        (choice :tag "Name"
861                                (item :tag "skip" nil)
862                                (face :value default))
863                        (choice :tag "Content"
864                                (item :tag "skip" nil)
865                                (face :value default)))))
866
867 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
868                                           '((xface . (:face gnus-x-face)))
869                                         '((pbm . (:face gnus-x-face))
870                                           (png . nil)))
871   "Alist of image types and properties applied to Face and X-Face images.
872 Here are examples:
873
874 ;; Specify the altitude of Face images in the From header.
875 \(setq gnus-face-properties-alist
876       '((pbm . (:face gnus-x-face :ascent 80))
877         (png . (:ascent 80))))
878
879 ;; Show Face images as pressed buttons.
880 \(setq gnus-face-properties-alist
881       '((pbm . (:face gnus-x-face :relief -2))
882         (png . (:relief -2))))
883
884 See the manual for the valid properties for various image types.
885 Currently, `pbm' is used for X-Face images and `png' is used for Face
886 images in Emacs.  Only the `:face' property is effective on the `xface'
887 image type in XEmacs if it is built with the libcompface library."
888   :version "23.0" ;; No Gnus
889   :group 'gnus-article-headers
890   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
891
892 (defcustom gnus-article-decode-hook
893   '(article-decode-charset article-decode-encoded-words
894                            article-decode-group-name article-decode-idna-rhs)
895   "*Hook run to decode charsets in articles."
896   :group 'gnus-article-headers
897   :type 'hook)
898
899 (defcustom gnus-display-mime-function 'gnus-display-mime
900   "Function to display MIME articles."
901   :group 'gnus-article-mime
902   :type 'function)
903
904 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905   "Function used to decode headers.")
906
907 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908   "Function used to decode addresses.")
909
910 (defvar gnus-article-dumbquotes-map
911   '(("\200" "EUR")
912     ("\202" ",")
913     ("\203" "f")
914     ("\204" ",,")
915     ("\205" "...")
916     ("\213" "<")
917     ("\214" "OE")
918     ("\221" "`")
919     ("\222" "'")
920     ("\223" "``")
921     ("\224" "\"")
922     ("\225" "*")
923     ("\226" "-")
924     ("\227" "--")
925     ("\230" "~")
926     ("\231" "(TM)")
927     ("\233" ">")
928     ("\234" "oe")
929     ("\264" "'"))
930   "Table for MS-to-Latin1 translation.")
931
932 (defcustom gnus-ignored-mime-types nil
933   "List of MIME types that should be ignored by Gnus."
934   :version "21.1"
935   :group 'gnus-article-mime
936   :type '(repeat regexp))
937
938 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
939   "List of MIME types that should not be given buttons when rendered inline.
940 See also `gnus-buttonized-mime-types' which may override this variable.
941 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
942   :version "21.1"
943   :group 'gnus-article-mime
944   :type '(repeat regexp))
945
946 (defcustom gnus-buttonized-mime-types nil
947   "List of MIME types that should be given buttons when rendered inline.
948 If set, this variable overrides `gnus-unbuttonized-mime-types'.
949 To see e.g. security buttons you could set this to
950 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
951 this list to display radio buttons that allow you to choose one of two
952 media types those mails include.  See also `mm-discouraged-alternatives'.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
954   :version "22.1"
955   :group 'gnus-article-mime
956   :type '(repeat regexp))
957
958 (defcustom gnus-inhibit-mime-unbuttonizing nil
959   "If non-nil, all MIME parts get buttons.
960 When nil (the default value), then some MIME parts do not get buttons,
961 as described by the variables `gnus-buttonized-mime-types' and
962 `gnus-unbuttonized-mime-types'."
963   :version "22.1"
964   :group 'gnus-article-mime
965   :type 'boolean)
966
967 (defcustom gnus-body-boundary-delimiter "_"
968   "String used to delimit header and body.
969 This variable is used by `gnus-article-treat-body-boundary' which can
970 be controlled by `gnus-treat-body-boundary'."
971   :version "22.1"
972   :group 'gnus-article-various
973   :type '(choice (item :tag "None" :value nil)
974                  string))
975
976 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
977                                   "/usr/share/picons")
978   "Defines the location of the faces database.
979 For information on obtaining this database of pretty pictures, please
980 see http://www.cs.indiana.edu/picons/ftp/index.html"
981   :version "22.1"
982   :type '(repeat directory)
983   :link '(url-link :tag "download"
984                    "http://www.cs.indiana.edu/picons/ftp/index.html")
985   :link '(custom-manual "(gnus)Picons")
986   :group 'gnus-picon)
987
988 (defun gnus-picons-installed-p ()
989   "Say whether picons are installed on your machine."
990   (let ((installed nil))
991     (dolist (database gnus-picon-databases)
992       (when (file-exists-p database)
993         (setq installed t)))
994     installed))
995
996 (defcustom gnus-article-mime-part-function nil
997   "Function called with a MIME handle as the argument.
998 This is meant for people who want to do something automatic based
999 on parts -- for instance, adding Vcard info to a database."
1000   :group 'gnus-article-mime
1001   :type '(choice (const nil)
1002                  function))
1003
1004 (defcustom gnus-mime-multipart-functions nil
1005   "An alist of MIME types to functions to display them."
1006   :version "21.1"
1007   :group 'gnus-article-mime
1008   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1009
1010 (defcustom gnus-article-date-lapsed-new-header nil
1011   "Whether the X-Sent and Date headers can coexist.
1012 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1013 either replace the old \"Date:\" header (if this variable is nil), or
1014 be added below it (otherwise)."
1015   :version "21.1"
1016   :group 'gnus-article-headers
1017   :type 'boolean)
1018
1019 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1020   "Function called with a MIME handle as the argument.
1021 This is meant for people who want to view first matched part.
1022 For `undisplayed-alternative' (default), the first undisplayed
1023 part or alternative part is used.  For `undisplayed', the first
1024 undisplayed part is used.  For a function, the first part which
1025 the function return t is used.  For nil, the first part is
1026 used."
1027   :version "21.1"
1028   :group 'gnus-article-mime
1029   :type '(choice
1030           (item :tag "first" :value nil)
1031           (item :tag "undisplayed" :value undisplayed)
1032           (item :tag "undisplayed or alternative"
1033                 :value undisplayed-alternative)
1034           (function)))
1035
1036 (defcustom gnus-mime-action-alist
1037   '(("save to file" . gnus-mime-save-part)
1038     ("save and strip" . gnus-mime-save-part-and-strip)
1039     ("replace with file" . gnus-mime-replace-part)
1040     ("delete part" . gnus-mime-delete-part)
1041     ("display as text" . gnus-mime-inline-part)
1042     ("view the part" . gnus-mime-view-part)
1043     ("pipe to command" . gnus-mime-pipe-part)
1044     ("toggle display" . gnus-article-press-button)
1045     ("toggle display" . gnus-article-view-part-as-charset)
1046     ("view as type" . gnus-mime-view-part-as-type)
1047     ("view internally" . gnus-mime-view-part-internally)
1048     ("view externally" . gnus-mime-view-part-externally))
1049   "An alist of actions that run on the MIME attachment."
1050   :group 'gnus-article-mime
1051   :type '(repeat (cons (string :tag "name")
1052                        (function))))
1053
1054 (defcustom gnus-auto-select-part 1
1055   "Advance to next MIME part when deleting or stripping parts.
1056
1057 When 0, point will be placed on the same part as before.  When
1058 positive (negative), move point forward (backwards) this many
1059 parts.  When nil, redisplay article."
1060   :version "23.0" ;; No Gnus
1061   :group 'gnus-article-mime
1062   :type '(choice (const nil :tag "Redisplay article.")
1063                  (const 1 :tag "Next part.")
1064                  (const 0 :tag "Current part.")
1065                  integer))
1066
1067 ;;;
1068 ;;; The treatment variables
1069 ;;;
1070
1071 (defvar gnus-part-display-hook nil
1072   "Hook called on parts that are to receive treatment.")
1073
1074 (defvar gnus-article-treat-custom
1075   '(choice (const :tag "Off" nil)
1076            (const :tag "On" t)
1077            (const :tag "Header" head)
1078            (const :tag "First" first)
1079            (const :tag "Last" last)
1080            (integer :tag "Less")
1081            (repeat :tag "Groups" regexp)
1082            (sexp :tag "Predicate")))
1083
1084 (defvar gnus-article-treat-head-custom
1085   '(choice (const :tag "Off" nil)
1086            (const :tag "Header" head)))
1087
1088 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1089                                    "text/x-patch")
1090   "Parts to treat.")
1091
1092 (defvar gnus-inhibit-treatment nil
1093   "Whether to inhibit treatment.")
1094
1095 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1096   "Highlight the signature.
1097 Valid values are nil, t, `head', `first', `last', an integer or a
1098 predicate.  See Info node `(gnus)Customizing Articles'."
1099   :group 'gnus-article-treat
1100   :link '(custom-manual "(gnus)Customizing Articles")
1101   :type gnus-article-treat-custom)
1102 (put 'gnus-treat-highlight-signature 'highlight t)
1103
1104 (defcustom gnus-treat-buttonize 100000
1105   "Add buttons.
1106 Valid values are nil, t, `head', `first', `last', an integer or a
1107 predicate.  See Info node `(gnus)Customizing Articles'."
1108   :group 'gnus-article-treat
1109   :link '(custom-manual "(gnus)Customizing Articles")
1110   :type gnus-article-treat-custom)
1111 (put 'gnus-treat-buttonize 'highlight t)
1112
1113 (defcustom gnus-treat-buttonize-head 'head
1114   "Add buttons to the head.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate.  See Info node `(gnus)Customizing Articles'."
1117   :group 'gnus-article-treat
1118   :link '(custom-manual "(gnus)Customizing Articles")
1119   :type gnus-article-treat-head-custom)
1120 (put 'gnus-treat-buttonize-head 'highlight t)
1121
1122 (defcustom gnus-treat-emphasize 50000
1123   "Emphasize text.
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate.  See Info node `(gnus)Customizing Articles'."
1126   :group 'gnus-article-treat
1127   :link '(custom-manual "(gnus)Customizing Articles")
1128   :type gnus-article-treat-custom)
1129 (put 'gnus-treat-emphasize 'highlight t)
1130
1131 (defcustom gnus-treat-strip-cr nil
1132   "Remove carriage returns.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate.  See Info node `(gnus)Customizing Articles'."
1135   :version "22.1"
1136   :group 'gnus-article-treat
1137   :link '(custom-manual "(gnus)Customizing Articles")
1138   :type gnus-article-treat-custom)
1139
1140 (defcustom gnus-treat-unsplit-urls nil
1141   "Remove newlines from within URLs.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate.  See Info node `(gnus)Customizing Articles'."
1144   :version "22.1"
1145   :group 'gnus-article-treat
1146   :link '(custom-manual "(gnus)Customizing Articles")
1147   :type gnus-article-treat-custom)
1148
1149 (defcustom gnus-treat-leading-whitespace nil
1150   "Remove leading whitespace in headers.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate.  See Info node `(gnus)Customizing Articles'."
1153   :version "22.1"
1154   :group 'gnus-article-treat
1155   :link '(custom-manual "(gnus)Customizing Articles")
1156   :type gnus-article-treat-custom)
1157
1158 (defcustom gnus-treat-hide-headers 'head
1159   "Hide headers.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate.  See Info node `(gnus)Customizing Articles'."
1162   :group 'gnus-article-treat
1163   :link '(custom-manual "(gnus)Customizing Articles")
1164   :type gnus-article-treat-head-custom)
1165
1166 (defcustom gnus-treat-hide-boring-headers nil
1167   "Hide boring headers.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate.  See Info node `(gnus)Customizing Articles'."
1170   :group 'gnus-article-treat
1171   :link '(custom-manual "(gnus)Customizing Articles")
1172   :type gnus-article-treat-head-custom)
1173
1174 (defcustom gnus-treat-hide-signature nil
1175   "Hide the signature.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate.  See Info node `(gnus)Customizing Articles'."
1178   :group 'gnus-article-treat
1179   :link '(custom-manual "(gnus)Customizing Articles")
1180   :type gnus-article-treat-custom)
1181
1182 (defcustom gnus-treat-fill-article nil
1183   "Fill the article.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate.  See Info node `(gnus)Customizing Articles'."
1186   :group 'gnus-article-treat
1187   :link '(custom-manual "(gnus)Customizing Articles")
1188   :type gnus-article-treat-custom)
1189
1190 (defcustom gnus-treat-hide-citation nil
1191   "Hide cited text.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate.  See Info node `(gnus)Customizing Articles'."
1194   :group 'gnus-article-treat
1195   :link '(custom-manual "(gnus)Customizing Articles")
1196   :type gnus-article-treat-custom)
1197
1198 (defcustom gnus-treat-hide-citation-maybe nil
1199   "Hide cited text.
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate.  See Info node `(gnus)Customizing Articles'."
1202   :group 'gnus-article-treat
1203   :link '(custom-manual "(gnus)Customizing Articles")
1204   :type gnus-article-treat-custom)
1205
1206 (defcustom gnus-treat-strip-list-identifiers 'head
1207   "Strip list identifiers from `gnus-list-identifiers`.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate.  See Info node `(gnus)Customizing Articles'."
1210   :version "21.1"
1211   :group 'gnus-article-treat
1212   :link '(custom-manual "(gnus)Customizing Articles")
1213   :type gnus-article-treat-custom)
1214
1215 (make-obsolete-variable 'gnus-treat-strip-pgp
1216                         "This option is obsolete in Gnus 5.10.")
1217
1218 (defcustom gnus-treat-strip-pem nil
1219   "Strip PEM signatures.
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-strip-banner t
1227   "Strip banners from articles.
1228 The banner to be stripped is specified in the `banner' group parameter.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate.  See Info node `(gnus)Customizing Articles'."
1231   :group 'gnus-article-treat
1232   :link '(custom-manual "(gnus)Customizing Articles")
1233   :type gnus-article-treat-custom)
1234
1235 (defcustom gnus-treat-highlight-headers 'head
1236   "Highlight the headers.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate.  See Info node `(gnus)Customizing Articles'."
1239   :group 'gnus-article-treat
1240   :link '(custom-manual "(gnus)Customizing Articles")
1241   :type gnus-article-treat-head-custom)
1242 (put 'gnus-treat-highlight-headers 'highlight t)
1243
1244 (defcustom gnus-treat-highlight-citation t
1245   "Highlight cited text.
1246 Valid values are nil, t, `head', `first', `last', an integer or a
1247 predicate.  See Info node `(gnus)Customizing Articles'."
1248   :group 'gnus-article-treat
1249   :link '(custom-manual "(gnus)Customizing Articles")
1250   :type gnus-article-treat-custom)
1251 (put 'gnus-treat-highlight-citation 'highlight t)
1252
1253 (defcustom gnus-treat-date-ut nil
1254   "Display the Date in UT (GMT).
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate.  See Info node `(gnus)Customizing Articles'."
1257   :group 'gnus-article-treat
1258   :link '(custom-manual "(gnus)Customizing Articles")
1259   :type gnus-article-treat-head-custom)
1260
1261 (defcustom gnus-treat-date-local nil
1262   "Display the Date in the local timezone.
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate.  See Info node `(gnus)Customizing Articles'."
1265   :group 'gnus-article-treat
1266   :link '(custom-manual "(gnus)Customizing Articles")
1267   :type gnus-article-treat-head-custom)
1268
1269 (defcustom gnus-treat-date-english nil
1270   "Display the Date in a format that can be read aloud in English.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate.  See Info node `(gnus)Customizing Articles'."
1273   :version "22.1"
1274   :group 'gnus-article-treat
1275   :link '(custom-manual "(gnus)Customizing Articles")
1276   :type gnus-article-treat-head-custom)
1277
1278 (defcustom gnus-treat-date-lapsed nil
1279   "Display the Date header in a way that says how much time has elapsed.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate.  See Info node `(gnus)Customizing Articles'."
1282   :group 'gnus-article-treat
1283   :link '(custom-manual "(gnus)Customizing Articles")
1284   :type gnus-article-treat-head-custom)
1285
1286 (defcustom gnus-treat-date-original nil
1287   "Display the date in the original timezone.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate.  See Info node `(gnus)Customizing Articles'."
1290   :group 'gnus-article-treat
1291   :link '(custom-manual "(gnus)Customizing Articles")
1292   :type gnus-article-treat-head-custom)
1293
1294 (defcustom gnus-treat-date-iso8601 nil
1295   "Display the date in the ISO8601 format.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate.  See Info node `(gnus)Customizing Articles'."
1298   :version "21.1"
1299   :group 'gnus-article-treat
1300   :link '(custom-manual "(gnus)Customizing Articles")
1301   :type gnus-article-treat-head-custom)
1302
1303 (defcustom gnus-treat-date-user-defined nil
1304   "Display the date in a user-defined format.
1305 The format is defined by the `gnus-article-time-format' variable.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate.  See Info node `(gnus)Customizing Articles'."
1308   :group 'gnus-article-treat
1309   :link '(custom-manual "(gnus)Customizing Articles")
1310   :type gnus-article-treat-head-custom)
1311
1312 (defcustom gnus-treat-strip-headers-in-body t
1313   "Strip the X-No-Archive header line from the beginning of the body.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate.  See Info node `(gnus)Customizing Articles'."
1316   :version "21.1"
1317   :group 'gnus-article-treat
1318   :link '(custom-manual "(gnus)Customizing Articles")
1319   :type gnus-article-treat-custom)
1320
1321 (defcustom gnus-treat-strip-trailing-blank-lines nil
1322   "Strip trailing blank lines.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate.  See Info node `(gnus)Customizing Articles'.
1325
1326 When set to t, it also strips trailing blanks in all MIME parts.
1327 Consider to use `last' instead."
1328   :group 'gnus-article-treat
1329   :link '(custom-manual "(gnus)Customizing Articles")
1330   :type gnus-article-treat-custom)
1331
1332 (defcustom gnus-treat-strip-leading-blank-lines nil
1333   "Strip leading blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate.  See Info node `(gnus)Customizing Articles'.
1336
1337 When set to t, it also strips trailing blanks in all MIME parts."
1338   :group 'gnus-article-treat
1339   :link '(custom-manual "(gnus)Customizing Articles")
1340   :type gnus-article-treat-custom)
1341
1342 (defcustom gnus-treat-strip-multiple-blank-lines nil
1343   "Strip multiple blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate.  See Info node `(gnus)Customizing Articles'."
1346   :group 'gnus-article-treat
1347   :link '(custom-manual "(gnus)Customizing Articles")
1348   :type gnus-article-treat-custom)
1349
1350 (defcustom gnus-treat-unfold-headers 'head
1351   "Unfold folded header lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate.  See Info node `(gnus)Customizing Articles'."
1354   :version "22.1"
1355   :group 'gnus-article-treat
1356   :link '(custom-manual "(gnus)Customizing Articles")
1357   :type gnus-article-treat-custom)
1358
1359 (defcustom gnus-article-unfold-long-headers nil
1360   "If non-nil, allow unfolding headers even if the header is long.
1361 If it is a regexp, only long headers matching this regexp are unfolded.
1362 If it is t, all long headers are unfolded.
1363
1364 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1365   :version "23.0" ;; No Gnus
1366   :group 'gnus-article-treat
1367   :type '(choice (const nil)
1368                  (const :tag "all" t)
1369                  (regexp)))
1370
1371 (defcustom gnus-treat-fold-headers nil
1372   "Fold headers.
1373 Valid values are nil, t, `head', `first', `last', an integer or a
1374 predicate.  See Info node `(gnus)Customizing Articles'."
1375   :version "22.1"
1376   :group 'gnus-article-treat
1377   :link '(custom-manual "(gnus)Customizing Articles")
1378   :type gnus-article-treat-custom)
1379
1380 (defcustom gnus-treat-fold-newsgroups 'head
1381   "Fold the Newsgroups and Followup-To 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-overstrike t
1390   "Treat overstrike highlighting.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate.  See Info node `(gnus)Customizing Articles'."
1393   :group 'gnus-article-treat
1394   :link '(custom-manual "(gnus)Customizing Articles")
1395   :type gnus-article-treat-custom)
1396 (put 'gnus-treat-overstrike 'highlight t)
1397
1398 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399   "Treat ANSI SGR control sequences.
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
1406 (make-obsolete-variable 'gnus-treat-display-xface
1407                         'gnus-treat-display-x-face)
1408
1409 (defcustom gnus-treat-display-x-face
1410   (and (not noninteractive)
1411        (gnus-image-type-available-p 'xbm)
1412        (if (featurep 'xemacs)
1413            (featurep 'xface)
1414          (and (string-match "^0x" (shell-command-to-string "uncompface"))
1415               (executable-find "icontopbm")))
1416        'head)
1417   "Display X-Face headers.
1418 Valid values are nil and `head'.
1419 See Info node `(gnus)Customizing Articles' and Info node
1420 `(gnus)X-Face' for details."
1421   :group 'gnus-article-treat
1422   :version "21.1"
1423   :link '(custom-manual "(gnus)Customizing Articles")
1424   :link '(custom-manual "(gnus)X-Face")
1425   :type gnus-article-treat-head-custom
1426   :set (lambda (symbol value)
1427          (set-default
1428           symbol
1429           (cond ((or (boundp symbol) (get symbol 'saved-value))
1430                  value)
1431                 ((boundp 'gnus-treat-display-xface)
1432                  (message "\
1433 ** gnus-treat-display-xface is an obsolete variable;\
1434  use gnus-treat-display-x-face instead")
1435                  (default-value 'gnus-treat-display-xface))
1436                 ((get 'gnus-treat-display-xface 'saved-value)
1437                  (message "\
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439  use gnus-treat-display-x-face instead")
1440                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1441                 (t
1442                  value)))))
1443 (put 'gnus-treat-display-x-face 'highlight t)
1444
1445 (defcustom gnus-treat-display-face
1446   (and (not noninteractive)
1447        (gnus-image-type-available-p 'png)
1448        'head)
1449   "Display Face headers.
1450 Valid values are nil, t, `head', `first', `last', an integer or a
1451 predicate.  See Info node `(gnus)Customizing Articles' and Info
1452 node `(gnus)X-Face' for details."
1453   :group 'gnus-article-treat
1454   :version "22.1"
1455   :link '(custom-manual "(gnus)Customizing Articles")
1456   :link '(custom-manual "(gnus)X-Face")
1457   :type gnus-article-treat-head-custom)
1458 (put 'gnus-treat-display-face 'highlight t)
1459
1460 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1461   "Display smileys.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate.  See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Smileys' for details."
1465   :group 'gnus-article-treat
1466   :version "21.1"
1467   :link '(custom-manual "(gnus)Customizing Articles")
1468   :link '(custom-manual "(gnus)Smileys")
1469   :type gnus-article-treat-custom)
1470 (put 'gnus-treat-display-smileys 'highlight t)
1471
1472 (defcustom gnus-treat-from-picon
1473   (if (and (gnus-image-type-available-p 'xpm)
1474            (gnus-picons-installed-p))
1475       'head nil)
1476   "Display picons in the From header.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate.  See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Picons' for details."
1480   :version "22.1"
1481   :group 'gnus-article-treat
1482   :group 'gnus-picon
1483   :link '(custom-manual "(gnus)Customizing Articles")
1484   :link '(custom-manual "(gnus)Picons")
1485   :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-from-picon 'highlight t)
1487
1488 (defcustom gnus-treat-mail-picon
1489   (if (and (gnus-image-type-available-p 'xpm)
1490            (gnus-picons-installed-p))
1491       'head nil)
1492   "Display picons in To and Cc headers.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate.  See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496   :version "22.1"
1497   :group 'gnus-article-treat
1498   :group 'gnus-picon
1499   :link '(custom-manual "(gnus)Customizing Articles")
1500   :link '(custom-manual "(gnus)Picons")
1501   :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-mail-picon 'highlight t)
1503
1504 (defcustom gnus-treat-newsgroups-picon
1505   (if (and (gnus-image-type-available-p 'xpm)
1506            (gnus-picons-installed-p))
1507       'head nil)
1508   "Display picons in the Newsgroups and Followup-To headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate.  See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512   :version "22.1"
1513   :group 'gnus-article-treat
1514   :group 'gnus-picon
1515   :link '(custom-manual "(gnus)Customizing Articles")
1516   :link '(custom-manual "(gnus)Picons")
1517   :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-newsgroups-picon 'highlight t)
1519
1520 (defcustom gnus-treat-body-boundary
1521   (if (or gnus-treat-newsgroups-picon
1522           gnus-treat-mail-picon
1523           gnus-treat-from-picon)
1524       ;; If there's much decoration, the user might prefer a boundery.
1525       'head
1526     nil)
1527   "Draw a boundary at the end of the headers.
1528 Valid values are nil and `head'.
1529 See Info node `(gnus)Customizing Articles' for details."
1530   :version "22.1"
1531   :group 'gnus-article-treat
1532   :link '(custom-manual "(gnus)Customizing Articles")
1533   :type gnus-article-treat-head-custom)
1534
1535 (defcustom gnus-treat-capitalize-sentences nil
1536   "Capitalize sentence-starting words.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate.  See Info node `(gnus)Customizing Articles'."
1539   :version "21.1"
1540   :group 'gnus-article-treat
1541   :link '(custom-manual "(gnus)Customizing Articles")
1542   :type gnus-article-treat-custom)
1543
1544 (defcustom gnus-treat-wash-html nil
1545   "Format as HTML.
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate.  See Info node `(gnus)Customizing Articles'."
1548   :version "22.1"
1549   :group 'gnus-article-treat
1550   :link '(custom-manual "(gnus)Customizing Articles")
1551   :type gnus-article-treat-custom)
1552
1553 (defcustom gnus-treat-fill-long-lines nil
1554   "Fill long lines.
1555 Valid values are nil, t, `head', `first', `last', an integer or a
1556 predicate.  See Info node `(gnus)Customizing Articles'."
1557   :group 'gnus-article-treat
1558   :link '(custom-manual "(gnus)Customizing Articles")
1559   :type gnus-article-treat-custom)
1560
1561 (defcustom gnus-treat-play-sounds nil
1562   "Play sounds.
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate.  See Info node `(gnus)Customizing Articles'."
1565   :version "21.1"
1566   :group 'gnus-article-treat
1567   :link '(custom-manual "(gnus)Customizing Articles")
1568   :type gnus-article-treat-custom)
1569
1570 (defcustom gnus-treat-translate nil
1571   "Translate articles from one language to another.
1572 Valid values are nil, t, `head', `first', `last', an integer or a
1573 predicate.  See Info node `(gnus)Customizing Articles'."
1574   :version "21.1"
1575   :group 'gnus-article-treat
1576   :link '(custom-manual "(gnus)Customizing Articles")
1577   :type gnus-article-treat-custom)
1578
1579 (defcustom gnus-treat-x-pgp-sig nil
1580   "Verify X-PGP-Sig.
1581 To automatically treat X-PGP-Sig, set it to head.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate.  See Info node `(gnus)Customizing Articles'."
1584   :version "22.1"
1585   :group 'gnus-article-treat
1586   :group 'mime-security
1587   :link '(custom-manual "(gnus)Customizing Articles")
1588   :type gnus-article-treat-custom)
1589
1590 (defvar gnus-article-encrypt-protocol-alist
1591   '(("PGP" . mml2015-self-encrypt)))
1592
1593 ;; Set to nil if more than one protocol added to
1594 ;; gnus-article-encrypt-protocol-alist.
1595 (defcustom gnus-article-encrypt-protocol "PGP"
1596   "The protocol used for encrypt articles.
1597 It is a string, such as \"PGP\". If nil, ask user."
1598   :version "22.1"
1599   :type 'string
1600   :group 'mime-security)
1601
1602 (defvar gnus-article-wash-function nil
1603   "Function used for converting HTML into text.")
1604
1605 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1606                               (mm-coding-system-p 'utf-8)
1607                               (executable-find idna-program))
1608   "Whether IDNA decoding of headers is used when viewing messages.
1609 This requires GNU Libidn, and by default only enabled if it is found."
1610   :version "22.1"
1611   :group 'gnus-article-headers
1612   :type 'boolean)
1613
1614 (defcustom gnus-article-over-scroll nil
1615   "If non-nil, allow scrolling the article buffer even when there no more text."
1616   :version "22.1"
1617   :group 'gnus-article
1618   :type 'boolean)
1619
1620 ;;; Internal variables
1621
1622 (defvar gnus-english-month-names
1623   '("January" "February" "March" "April" "May" "June" "July" "August"
1624     "September" "October" "November" "December"))
1625
1626 (defvar article-goto-body-goes-to-point-min-p nil)
1627 (defvar gnus-article-wash-types nil)
1628 (defvar gnus-article-emphasis-alist nil)
1629 (defvar gnus-article-image-alist nil)
1630
1631 (defvar gnus-article-mime-handle-alist-1 nil)
1632 (defvar gnus-treatment-function-alist
1633   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1634     (gnus-treat-strip-banner gnus-article-strip-banner)
1635     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1636     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637     (gnus-treat-buttonize gnus-article-add-buttons)
1638     (gnus-treat-fill-article gnus-article-fill-cited-article)
1639     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1640     (gnus-treat-strip-cr gnus-article-remove-cr)
1641     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1642     (gnus-treat-date-ut gnus-article-date-ut)
1643     (gnus-treat-date-local gnus-article-date-local)
1644     (gnus-treat-date-english gnus-article-date-english)
1645     (gnus-treat-date-original gnus-article-date-original)
1646     (gnus-treat-date-user-defined gnus-article-date-user)
1647     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1648     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1649     (gnus-treat-display-x-face gnus-article-display-x-face)
1650     (gnus-treat-display-face gnus-article-display-face)
1651     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1652     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1653     (gnus-treat-hide-signature gnus-article-hide-signature)
1654     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1655     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1656     (gnus-treat-strip-pem gnus-article-hide-pem)
1657     (gnus-treat-from-picon gnus-treat-from-picon)
1658     (gnus-treat-mail-picon gnus-treat-mail-picon)
1659     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1660     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1661     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1662     (gnus-treat-strip-trailing-blank-lines
1663      gnus-article-remove-trailing-blank-lines)
1664     (gnus-treat-strip-leading-blank-lines
1665      gnus-article-strip-leading-blank-lines)
1666     (gnus-treat-strip-multiple-blank-lines
1667      gnus-article-strip-multiple-blank-lines)
1668     (gnus-treat-overstrike gnus-article-treat-overstrike)
1669     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1670     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1671     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1672     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1673     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1674     (gnus-treat-display-smileys gnus-treat-smiley)
1675     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1676     (gnus-treat-wash-html gnus-article-wash-html)
1677     (gnus-treat-emphasize gnus-article-emphasize)
1678     (gnus-treat-hide-citation gnus-article-hide-citation)
1679     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1680     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1681     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1682     (gnus-treat-play-sounds gnus-earcon-display)))
1683
1684 (defvar gnus-article-mime-handle-alist nil)
1685 (defvar article-lapsed-timer nil)
1686 (defvar gnus-article-current-summary nil)
1687
1688 (defvar gnus-article-mode-syntax-table
1689   (let ((table (copy-syntax-table text-mode-syntax-table)))
1690     ;; This causes the citation match run O(2^n).
1691     ;; (modify-syntax-entry ?- "w" table)
1692     (modify-syntax-entry ?> ")<" table)
1693     (modify-syntax-entry ?< "(>" table)
1694     ;; make M-. in article buffers work for `foo' strings
1695     (modify-syntax-entry ?' " " table)
1696     (modify-syntax-entry ?` " " table)
1697     table)
1698   "Syntax table used in article mode buffers.
1699 Initialized from `text-mode-syntax-table.")
1700
1701 (defvar gnus-save-article-buffer nil)
1702
1703 (defvar gnus-article-mode-line-format-alist
1704   (nconc '((?w (gnus-article-wash-status) ?s)
1705            (?m (gnus-article-mime-part-status) ?s))
1706          gnus-summary-mode-line-format-alist))
1707
1708 (defvar gnus-number-of-articles-to-be-saved nil)
1709
1710 (defvar gnus-inhibit-hiding nil)
1711
1712 (defvar gnus-article-edit-mode nil)
1713
1714 ;;; Macros for dealing with the article buffer.
1715
1716 (defmacro gnus-with-article-headers (&rest forms)
1717   `(save-excursion
1718      (set-buffer gnus-article-buffer)
1719      (save-restriction
1720        (let ((inhibit-read-only t)
1721              (inhibit-point-motion-hooks t)
1722              (case-fold-search t))
1723          (article-narrow-to-head)
1724          ,@forms))))
1725
1726 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1727 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1728
1729 (defmacro gnus-with-article-buffer (&rest forms)
1730   `(save-excursion
1731      (set-buffer gnus-article-buffer)
1732      (let ((inhibit-read-only t))
1733        ,@forms)))
1734
1735 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1736 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1737
1738 (defun gnus-article-goto-header (header)
1739   "Go to HEADER, which is a regular expression."
1740   (re-search-forward (concat "^\\(" header "\\):") nil t))
1741
1742 (defsubst gnus-article-hide-text (b e props)
1743   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1744   (gnus-add-text-properties-when 'article-type nil b e props)
1745   (when (memq 'intangible props)
1746     (put-text-property
1747      (max (1- b) (point-min))
1748      b 'intangible (cddr (memq 'intangible props)))))
1749
1750 (defsubst gnus-article-unhide-text (b e)
1751   "Remove hidden text properties from region between B and E."
1752   (remove-text-properties b e gnus-hidden-properties)
1753   (when (memq 'intangible gnus-hidden-properties)
1754     (put-text-property (max (1- b) (point-min))
1755                        b 'intangible nil)))
1756
1757 (defun gnus-article-hide-text-type (b e type)
1758   "Hide text of TYPE between B and E."
1759   (gnus-add-wash-type type)
1760   (gnus-article-hide-text
1761    b e (cons 'article-type (cons type gnus-hidden-properties))))
1762
1763 (defun gnus-article-unhide-text-type (b e type)
1764   "Unhide text of TYPE between B and E."
1765   (gnus-delete-wash-type type)
1766   (remove-text-properties
1767    b e (cons 'article-type (cons type gnus-hidden-properties)))
1768   (when (memq 'intangible gnus-hidden-properties)
1769     (put-text-property (max (1- b) (point-min))
1770                        b 'intangible nil)))
1771
1772 (defun gnus-article-hide-text-of-type (type)
1773   "Hide text of TYPE in the current buffer."
1774   (save-excursion
1775     (let ((b (point-min))
1776           (e (point-max)))
1777       (while (setq b (text-property-any b e 'article-type type))
1778         (add-text-properties b (incf b) gnus-hidden-properties)))))
1779
1780 (defun gnus-article-delete-text-of-type (type)
1781   "Delete text of TYPE in the current buffer."
1782   (save-excursion
1783     (let ((b (point-min)))
1784       (if (eq type 'multipart)
1785           ;; Remove MIME buttons associated with multipart/alternative parts.
1786           (progn
1787             (goto-char b)
1788             (while (if (get-text-property (point) 'gnus-part)
1789                        (setq b (point))
1790                      (when (setq b (next-single-property-change (point)
1791                                                                 'gnus-part))
1792                        (goto-char b)
1793                        t))
1794               (end-of-line)
1795               (skip-chars-forward "\n")
1796               (when (eq (get-text-property b 'article-type) 'multipart)
1797                 (delete-region b (point)))))
1798         (while (setq b (text-property-any b (point-max) 'article-type type))
1799           (delete-region
1800            b (or (text-property-not-all b (point-max) 'article-type type)
1801                  (point-max))))))))
1802
1803 (defun gnus-article-delete-invisible-text ()
1804   "Delete all invisible text in the current buffer."
1805   (save-excursion
1806     (let ((b (point-min)))
1807       (while (setq b (text-property-any b (point-max) 'invisible t))
1808         (delete-region
1809          b (or (text-property-not-all b (point-max) 'invisible t)
1810                (point-max)))))))
1811
1812 (defun gnus-article-text-type-exists-p (type)
1813   "Say whether any text of type TYPE exists in the buffer."
1814   (text-property-any (point-min) (point-max) 'article-type type))
1815
1816 (defsubst gnus-article-header-rank ()
1817   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1818   (let ((list gnus-sorted-header-list)
1819         (i 1))
1820     (while list
1821       (if (looking-at (car list))
1822           (setq list nil)
1823         (setq list (cdr list))
1824         (incf i)))
1825       i))
1826
1827 (defun article-hide-headers (&optional arg delete)
1828   "Hide unwanted headers and possibly sort them as well."
1829   (interactive)
1830   ;; This function might be inhibited.
1831   (unless gnus-inhibit-hiding
1832     (let ((inhibit-read-only t)
1833           (case-fold-search t)
1834           (max (1+ (length gnus-sorted-header-list)))
1835           (inhibit-point-motion-hooks t)
1836           (cur (current-buffer))
1837           ignored visible beg)
1838       (save-excursion
1839         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1840         ;; group parameters, so we should go to the summary buffer.
1841         (when (prog1
1842                   (condition-case nil
1843                       (progn (set-buffer gnus-summary-buffer) t)
1844                     (error nil))
1845                 (setq ignored (when (not gnus-visible-headers)
1846                                 (cond ((stringp gnus-ignored-headers)
1847                                        gnus-ignored-headers)
1848                                       ((listp gnus-ignored-headers)
1849                                        (mapconcat 'identity
1850                                                   gnus-ignored-headers
1851                                                   "\\|"))))
1852                       visible (cond ((stringp gnus-visible-headers)
1853                                      gnus-visible-headers)
1854                                     ((and gnus-visible-headers
1855                                           (listp gnus-visible-headers))
1856                                      (mapconcat 'identity
1857                                                 gnus-visible-headers
1858                                                 "\\|")))))
1859           (set-buffer cur))
1860         (save-restriction
1861           ;; First we narrow to just the headers.
1862           (article-narrow-to-head)
1863           ;; Hide any "From " lines at the beginning of (mail) articles.
1864           (while (looking-at "From ")
1865             (forward-line 1))
1866           (unless (bobp)
1867             (delete-region (point-min) (point)))
1868           ;; Then treat the rest of the header lines.
1869           ;; Then we use the two regular expressions
1870           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1871           ;; select which header lines is to remain visible in the
1872           ;; article buffer.
1873           (while (re-search-forward "^[^ \t:]*:" nil t)
1874             (beginning-of-line)
1875             ;; Mark the rank of the header.
1876             (put-text-property
1877              (point) (1+ (point)) 'message-rank
1878              (if (or (and visible (looking-at visible))
1879                      (and ignored
1880                           (not (looking-at ignored))))
1881                  (gnus-article-header-rank)
1882                (+ 2 max)))
1883             (forward-line 1))
1884           (message-sort-headers-1)
1885           (when (setq beg (text-property-any
1886                            (point-min) (point-max) 'message-rank (+ 2 max)))
1887             ;; We delete the unwanted headers.
1888             (gnus-add-wash-type 'headers)
1889             (add-text-properties (point-min) (+ 5 (point-min))
1890                                  '(article-type headers dummy-invisible t))
1891             (delete-region beg (point-max))))))))
1892
1893 (defun article-hide-boring-headers (&optional arg)
1894   "Toggle hiding of headers that aren't very interesting.
1895 If given a negative prefix, always show; if given a positive prefix,
1896 always hide."
1897   (interactive (gnus-article-hidden-arg))
1898   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1899              (not gnus-show-all-headers))
1900     (save-excursion
1901       (save-restriction
1902         (let ((inhibit-read-only t)
1903               (inhibit-point-motion-hooks t))
1904           (article-narrow-to-head)
1905           (dolist (elem gnus-boring-article-headers)
1906             (goto-char (point-min))
1907             (cond
1908              ;; Hide empty headers.
1909              ((eq elem 'empty)
1910               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1911                 (forward-line -1)
1912                 (gnus-article-hide-text-type
1913                  (point-at-bol)
1914                  (progn
1915                    (end-of-line)
1916                    (if (re-search-forward "^[^ \t]" nil t)
1917                        (match-beginning 0)
1918                      (point-max)))
1919                  'boring-headers)))
1920              ;; Hide boring Newsgroups header.
1921              ((eq elem 'newsgroups)
1922               (when (gnus-string-equal
1923                      (gnus-fetch-field "newsgroups")
1924                      (gnus-group-real-name
1925                       (if (boundp 'gnus-newsgroup-name)
1926                           gnus-newsgroup-name
1927                         "")))
1928                 (gnus-article-hide-header "newsgroups")))
1929              ((eq elem 'to-address)
1930               (let ((to (message-fetch-field "to"))
1931                     (to-address
1932                      (gnus-parameter-to-address
1933                       (if (boundp 'gnus-newsgroup-name)
1934                           gnus-newsgroup-name ""))))
1935                 (when (and to to-address
1936                            (ignore-errors
1937                              (gnus-string-equal
1938                               ;; only one address in To
1939                               (nth 1 (mail-extract-address-components to))
1940                               to-address)))
1941                   (gnus-article-hide-header "to"))))
1942              ((eq elem 'to-list)
1943               (let ((to (message-fetch-field "to"))
1944                     (to-list
1945                      (gnus-parameter-to-list
1946                       (if (boundp 'gnus-newsgroup-name)
1947                           gnus-newsgroup-name ""))))
1948                 (when (and to to-list
1949                            (ignore-errors
1950                              (gnus-string-equal
1951                               ;; only one address in To
1952                               (nth 1 (mail-extract-address-components to))
1953                               to-list)))
1954                   (gnus-article-hide-header "to"))))
1955              ((eq elem 'cc-list)
1956               (let ((cc (message-fetch-field "cc"))
1957                     (to-list
1958                      (gnus-parameter-to-list
1959                       (if (boundp 'gnus-newsgroup-name)
1960                           gnus-newsgroup-name ""))))
1961                 (when (and cc to-list
1962                            (ignore-errors
1963                              (gnus-string-equal
1964                               ;; only one address in CC
1965                               (nth 1 (mail-extract-address-components cc))
1966                               to-list)))
1967                   (gnus-article-hide-header "cc"))))
1968              ((eq elem 'followup-to)
1969               (when (gnus-string-equal
1970                      (message-fetch-field "followup-to")
1971                      (message-fetch-field "newsgroups"))
1972                 (gnus-article-hide-header "followup-to")))
1973              ((eq elem 'reply-to)
1974               (if (gnus-group-find-parameter
1975                    gnus-newsgroup-name 'broken-reply-to)
1976                   (gnus-article-hide-header "reply-to")
1977                 (let ((from (message-fetch-field "from"))
1978                       (reply-to (message-fetch-field "reply-to")))
1979                   (when
1980                       (and
1981                        from reply-to
1982                        (ignore-errors
1983                          (equal
1984                           (sort (mapcar
1985                                  (lambda (x) (downcase (cadr x)))
1986                                  (mail-extract-address-components from t))
1987                                 'string<)
1988                           (sort (mapcar
1989                                  (lambda (x) (downcase (cadr x)))
1990                                  (mail-extract-address-components reply-to t))
1991                                 'string<))))
1992                     (gnus-article-hide-header "reply-to")))))
1993              ((eq elem 'date)
1994               (let ((date (with-current-buffer gnus-original-article-buffer
1995                             ;; If date in `gnus-article-buffer' is localized
1996                             ;; (`gnus-treat-date-user-defined'),
1997                             ;; `days-between' might fail.
1998                             (message-fetch-field "date"))))
1999                 (when (and date
2000                            (< (days-between (current-time-string) date)
2001                               4))
2002                   (gnus-article-hide-header "date"))))
2003              ((eq elem 'long-to)
2004               (let ((to (message-fetch-field "to"))
2005                     (cc (message-fetch-field "cc")))
2006                 (when (> (length to) 1024)
2007                   (gnus-article-hide-header "to"))
2008                 (when (> (length cc) 1024)
2009                   (gnus-article-hide-header "cc"))))
2010              ((eq elem 'many-to)
2011               (let ((to-count 0)
2012                     (cc-count 0))
2013                 (goto-char (point-min))
2014                 (while (re-search-forward "^to:" nil t)
2015                   (setq to-count (1+ to-count)))
2016                 (when (> to-count 1)
2017                   (while (> to-count 0)
2018                     (goto-char (point-min))
2019                     (save-restriction
2020                       (re-search-forward "^to:" nil nil to-count)
2021                       (forward-line -1)
2022                       (narrow-to-region (point) (point-max))
2023                       (gnus-article-hide-header "to"))
2024                     (setq to-count (1- to-count))))
2025                 (goto-char (point-min))
2026                 (while (re-search-forward "^cc:" nil t)
2027                   (setq cc-count (1+ cc-count)))
2028                 (when (> cc-count 1)
2029                   (while (> cc-count 0)
2030                     (goto-char (point-min))
2031                     (save-restriction
2032                       (re-search-forward "^cc:" nil nil cc-count)
2033                       (forward-line -1)
2034                       (narrow-to-region (point) (point-max))
2035                       (gnus-article-hide-header "cc"))
2036                     (setq cc-count (1- cc-count)))))))))))))
2037
2038 (defun gnus-article-hide-header (header)
2039   (save-excursion
2040     (goto-char (point-min))
2041     (when (re-search-forward (concat "^" header ":") nil t)
2042       (gnus-article-hide-text-type
2043        (point-at-bol)
2044        (progn
2045          (end-of-line)
2046          (if (re-search-forward "^[^ \t]" nil t)
2047              (match-beginning 0)
2048            (point-max)))
2049        'boring-headers))))
2050
2051 (defvar gnus-article-normalized-header-length 40
2052   "Length of normalized headers.")
2053
2054 (defun article-normalize-headers ()
2055   "Make all header lines 40 characters long."
2056   (interactive)
2057   (let ((inhibit-read-only t)
2058         column)
2059     (save-excursion
2060       (save-restriction
2061         (article-narrow-to-head)
2062         (while (not (eobp))
2063           (cond
2064            ((< (setq column (- (point-at-eol) (point)))
2065                gnus-article-normalized-header-length)
2066             (end-of-line)
2067             (insert (make-string
2068                      (- gnus-article-normalized-header-length column)
2069                      ? )))
2070            ((> column gnus-article-normalized-header-length)
2071             (gnus-put-text-property
2072              (progn
2073                (forward-char gnus-article-normalized-header-length)
2074                (point))
2075              (point-at-eol)
2076              'invisible t))
2077            (t
2078             ;; Do nothing.
2079             ))
2080           (forward-line 1))))))
2081
2082 (defun article-treat-dumbquotes ()
2083   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2084 Note that this function guesses whether a character is a sm*rtq**t* or
2085 not, so it should only be used interactively.
2086
2087 Sm*rtq**t*s are M****s***'s unilateral extension to the
2088 iso-8859-1 character map in an attempt to provide more quoting
2089 characters.  If you see something like \\222 or \\264 where
2090 you're expecting some kind of apostrophe or quotation mark, then
2091 try this wash."
2092   (interactive)
2093   (article-translate-strings gnus-article-dumbquotes-map))
2094
2095 (defun article-translate-characters (from to)
2096   "Translate all characters in the body of the article according to FROM and TO.
2097 FROM is a string of characters to translate from; to is a string of
2098 characters to translate to."
2099   (save-excursion
2100     (when (article-goto-body)
2101       (let ((inhibit-read-only t)
2102             (x (make-string 225 ?x))
2103             (i -1))
2104         (while (< (incf i) (length x))
2105           (aset x i i))
2106         (setq i 0)
2107         (while (< i (length from))
2108           (aset x (aref from i) (aref to i))
2109           (incf i))
2110         (translate-region (point) (point-max) x)))))
2111
2112 (defun article-translate-strings (map)
2113   "Translate all string in the body of the article according to MAP.
2114 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2115   (save-excursion
2116     (when (article-goto-body)
2117       (let ((inhibit-read-only t))
2118         (dolist (elem map)
2119           (save-excursion
2120             (while (search-forward (car elem) nil t)
2121               (replace-match (cadr elem)))))))))
2122
2123 (defun article-treat-overstrike ()
2124   "Translate overstrikes into bold text."
2125   (interactive)
2126   (save-excursion
2127     (when (article-goto-body)
2128       (let ((inhibit-read-only t))
2129         (while (search-forward "\b" nil t)
2130           (let ((next (char-after))
2131                 (previous (char-after (- (point) 2))))
2132             ;; We do the boldification/underlining by hiding the
2133             ;; overstrikes and putting the proper text property
2134             ;; on the letters.
2135             (cond
2136              ((eq next previous)
2137               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2138               (put-text-property (point) (1+ (point)) 'face 'bold))
2139              ((eq next ?_)
2140               (gnus-article-hide-text-type
2141                (1- (point)) (1+ (point)) 'overstrike)
2142               (put-text-property
2143                (- (point) 2) (1- (point)) 'face 'underline))
2144              ((eq previous ?_)
2145               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2146               (put-text-property
2147                (point) (1+ (point)) 'face 'underline)))))))))
2148
2149 (defun article-treat-ansi-sequences ()
2150   "Translate ANSI SGR control sequences into overlays or extents."
2151   (interactive)
2152   (save-excursion
2153     (when (article-goto-body)
2154       (let ((inhibit-read-only t))
2155         (ansi-color-apply-on-region (point) (point-max))))))
2156
2157 (defun gnus-article-treat-unfold-headers ()
2158   "Unfold folded message headers.
2159 Only the headers that fit into the current window width will be
2160 unfolded."
2161   (interactive)
2162   (gnus-with-article-headers
2163     (let (length)
2164       (while (not (eobp))
2165         (save-restriction
2166           (mail-header-narrow-to-field)
2167           (let* ((header (buffer-string))
2168                  (unfoldable
2169                   (or (equal gnus-article-unfold-long-headers t)
2170                       (and (stringp gnus-article-unfold-long-headers)
2171                            (string-match gnus-article-unfold-long-headers header)))))
2172             (with-temp-buffer
2173               (insert header)
2174               (goto-char (point-min))
2175               (while (re-search-forward "\n[\t ]" nil t)
2176                 (replace-match " " t t)))
2177             (setq length (- (point-max) (point-min) 1))
2178             (when (or unfoldable
2179                       (< length (window-width)))
2180               (while (re-search-forward "\n[\t ]" nil t)
2181                 (replace-match " " t t))))
2182           (goto-char (point-max)))))))
2183
2184 (defun gnus-article-treat-fold-headers ()
2185   "Fold message headers."
2186   (interactive)
2187   (gnus-with-article-headers
2188     (while (not (eobp))
2189       (save-restriction
2190         (mail-header-narrow-to-field)
2191         (mail-header-fold-field)
2192         (goto-char (point-max))))))
2193
2194 (defun gnus-treat-smiley ()
2195   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2196   (interactive)
2197   (gnus-with-article-buffer
2198     (if (memq 'smiley gnus-article-wash-types)
2199         (gnus-delete-images 'smiley)
2200       (article-goto-body)
2201       (let ((images (smiley-region (point) (point-max))))
2202         (when images
2203           (gnus-add-wash-type 'smiley)
2204           (dolist (image images)
2205             (gnus-add-image 'smiley image)))))))
2206
2207 (defun gnus-article-remove-images ()
2208   "Remove all images from the article buffer."
2209   (interactive)
2210   (gnus-with-article-buffer
2211     (dolist (elem gnus-article-image-alist)
2212       (gnus-delete-images (car elem)))))
2213
2214 (defun gnus-article-treat-fold-newsgroups ()
2215   "Unfold folded message headers.
2216 Only the headers that fit into the current window width will be
2217 unfolded."
2218   (interactive)
2219   (gnus-with-article-headers
2220     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2221       (save-restriction
2222         (mail-header-narrow-to-field)
2223         (while (re-search-forward ", *" nil t)
2224           (replace-match ", " t t))
2225         (mail-header-fold-field)
2226         (goto-char (point-max))))))
2227
2228 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2229   "Value of `truncate-lines' in Gnus Article buffer.
2230 Valid values are nil, t, `head', `first', `last', an integer or a
2231 predicate.  See Info node `(gnus)Customizing Articles'."
2232   :version "23.0" ;; No Gnus
2233   :group 'gnus-article
2234   ;; :link '(custom-manual "(gnus)Customizing Articles")
2235   :type 'boolean)
2236
2237 (defun gnus-article-toggle-truncate-lines (&optional arg)
2238   "Toggle whether to fold or truncate long lines in article the buffer.
2239 If ARG is non-nil and not a number, toggle
2240 `gnus-article-truncate-lines' too.  If ARG is a number, truncate
2241 long lines iff arg is positive."
2242   (interactive "P")
2243   (cond
2244    ((and (numberp arg) (> arg 0))
2245     (setq gnus-article-truncate-lines t))
2246    ((numberp arg)
2247     (setq gnus-article-truncate-lines nil))
2248    (arg
2249     (setq gnus-article-truncate-lines
2250           (not gnus-article-truncate-lines))))
2251   (gnus-with-article-buffer
2252     (cond
2253      ((and (numberp arg) (> arg 0))
2254       (setq truncate-lines nil))
2255      ((numberp arg)
2256       (setq truncate-lines t)))
2257     ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2258     ;; `toggle-truncate-lines' needs an argument.
2259     (toggle-truncate-lines)))
2260
2261 (defun gnus-article-treat-body-boundary ()
2262   "Place a boundary line at the end of the headers."
2263   (interactive)
2264   (when (and gnus-body-boundary-delimiter
2265              (> (length gnus-body-boundary-delimiter) 0))
2266     (gnus-with-article-headers
2267       (goto-char (point-max))
2268       (let ((start (point)))
2269         (insert "X-Boundary: ")
2270         (gnus-add-text-properties start (point) '(invisible t intangible t))
2271         (insert (let (str)
2272                   (while (>= (1- (window-width)) (length str))
2273                     (setq str (concat str gnus-body-boundary-delimiter)))
2274                   (substring str 0 (1- (window-width))))
2275                 "\n")
2276         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2277
2278 (defun article-fill-long-lines ()
2279   "Fill lines that are wider than the window width."
2280   (interactive)
2281   (save-excursion
2282     (let ((inhibit-read-only t)
2283           (width (window-width (get-buffer-window (current-buffer)))))
2284       (save-restriction
2285         (article-goto-body)
2286         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2287           (while (not (eobp))
2288             (end-of-line)
2289             (when (>= (current-column) (min fill-column width))
2290               (narrow-to-region (min (1+ (point)) (point-max))
2291                                 (point-at-bol))
2292               (let ((goback (point-marker)))
2293                 (fill-paragraph nil)
2294                 (goto-char (marker-position goback)))
2295               (widen))
2296             (forward-line 1)))))))
2297
2298 (defun article-capitalize-sentences ()
2299   "Capitalize the first word in each sentence."
2300   (interactive)
2301   (save-excursion
2302     (let ((inhibit-read-only t)
2303           (paragraph-start "^[\n\^L]"))
2304       (article-goto-body)
2305       (while (not (eobp))
2306         (capitalize-word 1)
2307         (forward-sentence)))))
2308
2309 (defun article-remove-cr ()
2310   "Remove trailing CRs and then translate remaining CRs into LFs."
2311   (interactive)
2312   (save-excursion
2313     (let ((inhibit-read-only t))
2314       (goto-char (point-min))
2315       (while (re-search-forward "\r+$" nil t)
2316         (replace-match "" t t))
2317       (goto-char (point-min))
2318       (while (search-forward "\r" nil t)
2319         (replace-match "\n" t t)))))
2320
2321 (defun article-remove-trailing-blank-lines ()
2322   "Remove all trailing blank lines from the article."
2323   (interactive)
2324   (save-excursion
2325     (let ((inhibit-read-only t))
2326       (goto-char (point-max))
2327       (delete-region
2328        (point)
2329        (progn
2330          (while (and (not (bobp))
2331                      (looking-at "^[ \t]*$")
2332                      (not (gnus-annotation-in-region-p
2333                            (point) (point-at-eol))))
2334            (forward-line -1))
2335          (forward-line 1)
2336          (point))))))
2337
2338 (defvar gnus-face-properties-alist)
2339
2340 (defun article-display-face (&optional force)
2341   "Display any Face headers in the header."
2342   (interactive (list 'force))
2343   (let ((wash-face-p buffer-read-only))
2344     (gnus-with-article-headers
2345       ;; When displaying parts, this function can be called several times on
2346       ;; the same article, without any intended toggle semantic (as typing `W
2347       ;; D d' would have). So face deletion must occur only when we come from
2348       ;; an interactive command, that is when the *Article* buffer is
2349       ;; read-only.
2350       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2351           (gnus-delete-images 'face)
2352         (let ((from (message-fetch-field "from"))
2353               face faces)
2354           (save-current-buffer
2355             (when (and wash-face-p
2356                        (gnus-buffer-live-p gnus-original-article-buffer)
2357                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2358               (set-buffer gnus-original-article-buffer))
2359             (save-restriction
2360               (mail-narrow-to-head)
2361               (when (or force
2362                         ;; Check whether this face is censored.
2363                         (not (and gnus-article-x-face-too-ugly
2364                                   (or from
2365                                       (setq from (message-fetch-field "from")))
2366                                   (string-match gnus-article-x-face-too-ugly
2367                                                 from))))
2368                 (while (gnus-article-goto-header "Face")
2369                   (push (mail-header-field-value) faces)))))
2370           (when faces
2371             (goto-char (point-min))
2372             (let (png image)
2373               (unless (setq from (gnus-article-goto-header "from"))
2374                 (insert "From:")
2375                 (setq from (point))
2376                 (insert " [no `from' set]\n"))
2377               (while faces
2378                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2379                   (setq image
2380                         (apply 'gnus-create-image png 'png t
2381                                (cdr (assq 'png gnus-face-properties-alist))))
2382                   (goto-char from)
2383                   (gnus-add-wash-type 'face)
2384                   (gnus-add-image 'face image)
2385                   (gnus-put-image image nil 'face))))))))))
2386
2387 (defun article-display-x-face (&optional force)
2388   "Look for an X-Face header and display it if present."
2389   (interactive (list 'force))
2390   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2391     (gnus-with-article-headers
2392       ;; Delete the old process, if any.
2393       (when (process-status "article-x-face")
2394         (delete-process "article-x-face"))
2395       ;; See the comment in `article-display-face'.
2396       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2397           ;; We have already displayed X-Faces, so we remove them
2398           ;; instead.
2399           (gnus-delete-images 'xface)
2400         ;; Display X-Faces.
2401         (let ((from (message-fetch-field "from"))
2402               x-faces face)
2403           (save-current-buffer
2404             (when (and wash-face-p
2405                        (gnus-buffer-live-p gnus-original-article-buffer)
2406                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2407               ;; If type `W f', use gnus-original-article-buffer,
2408               ;; otherwise use the current buffer because displaying
2409               ;; RFC822 parts calls this function too.
2410               (set-buffer gnus-original-article-buffer))
2411             (save-restriction
2412               (mail-narrow-to-head)
2413               (and gnus-article-x-face-command
2414                    (or force
2415                        ;; Check whether this face is censored.
2416                        (not (and gnus-article-x-face-too-ugly
2417                                  (or from
2418                                      (setq from (message-fetch-field "from")))
2419                                  (string-match gnus-article-x-face-too-ugly
2420                                                from))))
2421                    (while (gnus-article-goto-header "X-Face")
2422                      (push (mail-header-field-value) x-faces)))))
2423           (when x-faces
2424             ;; We display the face.
2425             (cond ((functionp gnus-article-x-face-command)
2426                    ;; The command is a lisp function, so we call it.
2427                    (mapc gnus-article-x-face-command x-faces))
2428                   ((stringp gnus-article-x-face-command)
2429                    ;; The command is a string, so we interpret the command
2430                    ;; as a, well, command, and fork it off.
2431                    (let ((process-connection-type nil))
2432                      (gnus-set-process-query-on-exit-flag
2433                       (start-process
2434                        "article-x-face" nil shell-file-name
2435                        shell-command-switch gnus-article-x-face-command)
2436                       nil)
2437                      ;; Sending multiple EOFs to xv doesn't work,
2438                      ;; so we only do a single external face.
2439                      (with-temp-buffer
2440                        (insert (car x-faces))
2441                        (process-send-region "article-x-face"
2442                                             (point-min) (point-max)))
2443                      (process-send-eof "article-x-face")))
2444                   (t
2445                    (error "`%s' set to `%s' is not a function"
2446                           gnus-article-x-face-command
2447                           'gnus-article-x-face-command)))))))))
2448
2449 (defun article-decode-mime-words ()
2450   "Decode all MIME-encoded words in the article."
2451   (interactive)
2452   (gnus-with-article-buffer
2453     (let ((inhibit-point-motion-hooks t)
2454           (mail-parse-charset gnus-newsgroup-charset)
2455           (mail-parse-ignored-charsets
2456            (with-current-buffer gnus-summary-buffer
2457              gnus-newsgroup-ignored-charsets)))
2458       (mail-decode-encoded-word-region (point-min) (point-max)))))
2459
2460 (defun article-decode-charset (&optional prompt)
2461   "Decode charset-encoded text in the article.
2462 If PROMPT (the prefix), prompt for a coding system to use."
2463   (interactive "P")
2464   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2465         (inhibit-read-only t)
2466         (mail-parse-charset gnus-newsgroup-charset)
2467         (mail-parse-ignored-charsets
2468          (save-excursion (condition-case nil
2469                              (set-buffer gnus-summary-buffer)
2470                            (error))
2471                          gnus-newsgroup-ignored-charsets))
2472         ct cte ctl charset format)
2473     (save-excursion
2474       (save-restriction
2475         (article-narrow-to-head)
2476         (setq ct (message-fetch-field "Content-Type" t)
2477               cte (message-fetch-field "Content-Transfer-Encoding" t)
2478               ctl (and ct (mail-header-parse-content-type ct))
2479               charset (cond
2480                        (prompt
2481                         (mm-read-coding-system "Charset to decode: "))
2482                        (ctl
2483                         (mail-content-type-get ctl 'charset)))
2484               format (and ctl (mail-content-type-get ctl 'format)))
2485         (when cte
2486           (setq cte (mail-header-strip cte)))
2487         (if (and ctl (not (string-match "/" (car ctl))))
2488             (setq ctl nil))
2489         (goto-char (point-max)))
2490       (forward-line 1)
2491       (save-restriction
2492         (narrow-to-region (point) (point-max))
2493         (when (and (eq mail-parse-charset 'gnus-decoded)
2494                    (eq (mm-body-7-or-8) '8bit))
2495           ;; The text code could have been decoded.
2496           (setq charset mail-parse-charset))
2497         (when (and (or (not ctl)
2498                        (equal (car ctl) "text/plain"))
2499                    (not format)) ;; article with format will decode later.
2500           (mm-decode-body
2501            charset (and cte (intern (downcase
2502                                      (gnus-strip-whitespace cte))))
2503            (car ctl)))))))
2504
2505 (defun article-decode-encoded-words ()
2506   "Remove encoded-word encoding from headers."
2507   (let ((inhibit-point-motion-hooks t)
2508         (mail-parse-charset gnus-newsgroup-charset)
2509         (mail-parse-ignored-charsets
2510          (save-excursion (condition-case nil
2511                              (set-buffer gnus-summary-buffer)
2512                            (error))
2513                          gnus-newsgroup-ignored-charsets))
2514         (inhibit-read-only t)
2515         end start)
2516     (goto-char (point-min))
2517     (when (search-forward "\n\n" nil 'move)
2518       (forward-line -1))
2519     (setq end (point))
2520     (while (not (bobp))
2521       (while (progn
2522                (forward-line -1)
2523                (and (not (bobp))
2524                     (memq (char-after) '(?\t ? )))))
2525       (setq start (point))
2526       (if (looking-at "\
2527 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2528 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2529           (funcall gnus-decode-address-function start end)
2530         (funcall gnus-decode-header-function start end))
2531       (goto-char (setq end start)))))
2532
2533 (defun article-decode-group-name ()
2534   "Decode group names in Newsgroups, Followup-To and Xref headers."
2535   (let ((inhibit-point-motion-hooks t)
2536         (inhibit-read-only t)
2537         (method (gnus-find-method-for-group gnus-newsgroup-name))
2538         regexp)
2539     (when (and (or gnus-group-name-charset-method-alist
2540                    gnus-group-name-charset-group-alist)
2541                (gnus-buffer-live-p gnus-original-article-buffer))
2542       (save-restriction
2543         (article-narrow-to-head)
2544         (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2545           (with-current-buffer gnus-original-article-buffer
2546             (goto-char (point-min)))
2547           (setq regexp (concat "^" header
2548                                ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2549           (while (re-search-forward regexp nil t)
2550             (replace-match (save-match-data
2551                              (gnus-decode-newsgroups
2552                               ;; XXX how to use data in article buffer?
2553                               (with-current-buffer gnus-original-article-buffer
2554                                 (re-search-forward regexp nil t)
2555                                 (match-string 1))
2556                               gnus-newsgroup-name method))
2557                            t t nil 1))
2558           (goto-char (point-min)))))))
2559
2560 (autoload 'idna-to-unicode "idna")
2561
2562 (defun article-decode-idna-rhs ()
2563   "Decode IDNA strings in RHS in various headers in current buffer.
2564 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2565 Mail-Reply-To: and Mail-Followup-To:."
2566   (when gnus-use-idna
2567     (save-restriction
2568       (let ((inhibit-point-motion-hooks t)
2569             (inhibit-read-only t))
2570         (article-narrow-to-head)
2571         (goto-char (point-min))
2572         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2573           (let (ace unicode)
2574             (when (save-match-data
2575                     (and (setq ace (match-string 1))
2576                          (save-excursion
2577                            (and (re-search-backward "^[^ \t]" nil t)
2578                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2579                          (setq unicode (idna-to-unicode ace))))
2580               (unless (string= ace unicode)
2581                 (replace-match unicode nil nil nil 1)))))))))
2582
2583 (defun article-de-quoted-unreadable (&optional force read-charset)
2584   "Translate a quoted-printable-encoded article.
2585 If FORCE, decode the article whether it is marked as quoted-printable
2586 or not.
2587 If READ-CHARSET, ask for a coding system."
2588   (interactive (list 'force current-prefix-arg))
2589   (save-excursion
2590     (let ((inhibit-read-only t) type charset)
2591       (if (gnus-buffer-live-p gnus-original-article-buffer)
2592           (with-current-buffer gnus-original-article-buffer
2593             (setq type
2594                   (gnus-fetch-field "content-transfer-encoding"))
2595             (let* ((ct (gnus-fetch-field "content-type"))
2596                    (ctl (and ct (mail-header-parse-content-type ct))))
2597               (setq charset (and ctl
2598                                  (mail-content-type-get ctl 'charset)))
2599               (if (stringp charset)
2600                   (setq charset (intern (downcase charset)))))))
2601       (if read-charset
2602           (setq charset (mm-read-coding-system "Charset: " charset)))
2603       (unless charset
2604         (setq charset gnus-newsgroup-charset))
2605       (when (or force
2606                 (and type (let ((case-fold-search t))
2607                             (string-match "quoted-printable" type))))
2608         (article-goto-body)
2609         (quoted-printable-decode-region
2610          (point) (point-max) (mm-charset-to-coding-system charset))))))
2611
2612 (defun article-de-base64-unreadable (&optional force read-charset)
2613   "Translate a base64 article.
2614 If FORCE, decode the article whether it is marked as base64 not.
2615 If READ-CHARSET, ask for a coding system."
2616   (interactive (list 'force current-prefix-arg))
2617   (save-excursion
2618     (let ((inhibit-read-only t) type charset)
2619       (if (gnus-buffer-live-p gnus-original-article-buffer)
2620           (with-current-buffer gnus-original-article-buffer
2621             (setq type
2622                   (gnus-fetch-field "content-transfer-encoding"))
2623             (let* ((ct (gnus-fetch-field "content-type"))
2624                    (ctl (and ct (mail-header-parse-content-type ct))))
2625               (setq charset (and ctl
2626                                  (mail-content-type-get ctl 'charset)))
2627               (if (stringp charset)
2628                   (setq charset (intern (downcase charset)))))))
2629       (if read-charset
2630           (setq charset (mm-read-coding-system "Charset: " charset)))
2631       (unless charset
2632         (setq charset gnus-newsgroup-charset))
2633       (when (or force
2634                 (and type (let ((case-fold-search t))
2635                             (string-match "base64" type))))
2636         (article-goto-body)
2637         (save-restriction
2638           (narrow-to-region (point) (point-max))
2639           (base64-decode-region (point-min) (point-max))
2640           (mm-decode-coding-region
2641            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2642
2643 (eval-when-compile
2644   (require 'rfc1843))
2645
2646 (defun article-decode-HZ ()
2647   "Translate a HZ-encoded article."
2648   (interactive)
2649   (require 'rfc1843)
2650   (save-excursion
2651     (let ((inhibit-read-only t))
2652       (rfc1843-decode-region (point-min) (point-max)))))
2653
2654 (defun article-unsplit-urls ()
2655   "Remove the newlines that some other mailers insert into URLs."
2656   (interactive)
2657   (save-excursion
2658     (let ((inhibit-read-only t))
2659       (goto-char (point-min))
2660       (while (re-search-forward
2661               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2662         (replace-match "\\1\\3" t)))
2663     (when (interactive-p)
2664       (gnus-treat-article nil))))
2665
2666
2667 (defun article-wash-html (&optional read-charset)
2668   "Format an HTML article.
2669 If READ-CHARSET, ask for a coding system.  If it is a number, the
2670 charset defined in `gnus-summary-show-article-charset-alist' is used."
2671   (interactive "P")
2672   (save-excursion
2673     (let ((inhibit-read-only t)
2674           charset)
2675       (if read-charset
2676           (if (or (and (numberp read-charset)
2677                        (setq charset
2678                              (cdr
2679                               (assq read-charset
2680                                     gnus-summary-show-article-charset-alist))))
2681                   (setq charset (mm-read-coding-system "Charset: ")))
2682               (let ((gnus-summary-show-article-charset-alist
2683                      (list (cons 1 charset))))
2684                 (with-current-buffer gnus-summary-buffer
2685                   (gnus-summary-show-article 1)))
2686             (error "No charset is given"))
2687         (when (gnus-buffer-live-p gnus-original-article-buffer)
2688           (with-current-buffer gnus-original-article-buffer
2689             (let* ((ct (gnus-fetch-field "content-type"))
2690                    (ctl (and ct (mail-header-parse-content-type ct))))
2691               (setq charset (and ctl
2692                                  (mail-content-type-get ctl 'charset)))
2693               (when (stringp charset)
2694                 (setq charset (intern (downcase charset)))))))
2695         (unless charset
2696           (setq charset gnus-newsgroup-charset)))
2697       (article-goto-body)
2698       (save-window-excursion
2699         (save-restriction
2700           (narrow-to-region (point) (point-max))
2701           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2702                  (entry (assq func mm-text-html-washer-alist)))
2703             (when entry
2704               (setq func (cdr entry)))
2705             (cond
2706              ((functionp func)
2707               (funcall func))
2708              (t
2709               (apply (car func) (cdr func))))))))))
2710
2711 ;; External.
2712 (declare-function w3-region "ext:w3-display" (st nd))
2713
2714 (defun gnus-article-wash-html-with-w3 ()
2715   "Wash the current buffer with w3."
2716   (mm-setup-w3)
2717   (let ((w3-strict-width (window-width))
2718         (url-standalone-mode t)
2719         (url-gateway-unplugged t)
2720         (w3-honor-stylesheets nil))
2721     (condition-case ()
2722         (w3-region (point-min) (point-max))
2723       (error))))
2724
2725 ;; External.
2726 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2727
2728 (defun gnus-article-wash-html-with-w3m ()
2729   "Wash the current buffer with emacs-w3m."
2730   (mm-setup-w3m)
2731   (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2732         w3m-force-redisplay)
2733     (w3m-region (point-min) (point-max)))
2734   (when (and mm-inline-text-html-with-w3m-keymap
2735              (boundp 'w3m-minor-mode-map)
2736              w3m-minor-mode-map)
2737     (add-text-properties
2738      (point-min) (point-max)
2739      (list 'keymap w3m-minor-mode-map
2740            ;; Put the mark meaning this part was rendered by emacs-w3m.
2741            'mm-inline-text-html-with-w3m t))))
2742
2743 (defvar charset) ;; Bound by `article-wash-html'.
2744
2745 (defun gnus-article-wash-html-with-w3m-standalone ()
2746   "Wash the current buffer with w3m."
2747   (if (mm-w3m-standalone-supports-m17n-p)
2748       (progn
2749         (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2750           ;; The default.
2751           (setq charset 'iso-8859-1))
2752         (let ((coding-system-for-write charset)
2753               (coding-system-for-read charset))
2754           (call-process-region
2755            (point-min) (point-max)
2756            "w3m" t t nil "-dump" "-T" "text/html"
2757            "-I" (symbol-name charset) "-O" (symbol-name charset))))
2758     (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2759
2760 (defvar gnus-article-browse-html-temp-list nil
2761   "List of temporary files created by `gnus-article-browse-html-parts'.
2762 Internal variable.")
2763
2764 (defcustom gnus-article-browse-delete-temp 'ask
2765   "What to do with temporary files from `gnus-article-browse-html-parts'.
2766 If nil, don't delete temporary files.  If it is t, delete them on
2767 exit from the summary buffer.  If it is the symbol `file', query
2768 on each file, if it is `ask' ask once when exiting from the
2769 summary buffer."
2770   :group 'gnus-article
2771   :version "23.0" ;; No Gnus
2772   :type '(choice (const :tag "Don't delete" nil)
2773                  (const :tag "Don't ask" t)
2774                  (const :tag "Ask" ask)
2775                  (const :tag "Ask for each file" file)))
2776
2777 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2778
2779 (defun gnus-article-browse-delete-temp-files (&optional how)
2780   "Delete temp-files created by `gnus-article-browse-html-parts'."
2781   (when (and gnus-article-browse-html-temp-list
2782              (or how
2783                  (setq how gnus-article-browse-delete-temp)))
2784     (when (and (eq how 'ask)
2785                (gnus-y-or-n-p (format
2786                                "Delete all %s temporary HTML file(s)? "
2787                                (length gnus-article-browse-html-temp-list)))
2788                (setq how t)))
2789     (dolist (file gnus-article-browse-html-temp-list)
2790       (when (and (file-exists-p file)
2791                  (or (eq how t)
2792                      ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2793                      (gnus-y-or-n-p
2794                       (format "Delete temporary HTML file `%s'? " file))))
2795         (delete-file file)))
2796     ;; Also remove file from the list when not deleted or if file doesn't
2797     ;; exist anymore.
2798     (setq gnus-article-browse-html-temp-list nil))
2799   gnus-article-browse-html-temp-list)
2800
2801 (defun gnus-article-browse-html-parts (list &optional header)
2802   "View all \"text/html\" parts from LIST.
2803 Recurse into multiparts.  The optional HEADER that should be a decoded
2804 message header will be added to the bodies of the \"text/html\" parts."
2805   ;; Internal function used by `gnus-article-browse-html-article'.
2806   (let (type file charset tmp-file showed)
2807     ;; Find and show the html-parts.
2808     (dolist (handle list)
2809       ;; If HTML, show it:
2810       (cond ((not (listp handle)))
2811             ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2812                  (and (equal (car type) "message/external-body")
2813                       (or header
2814                           (setq file (or (mail-content-type-get type 'name)
2815                                          (mail-content-type-get
2816                                           (mm-handle-disposition handle)
2817                                           'filename))))
2818                       (or (mm-handle-cache handle)
2819                           (condition-case code
2820                               (progn (mm-extern-cache-contents handle) t)
2821                             (error
2822                              (gnus-message 3 "%s" (error-message-string code))
2823                              (when (>= gnus-verbose 3) (sit-for 2))
2824                              nil)))
2825                       (progn
2826                         (setq handle (mm-handle-cache handle)
2827                               type (mm-handle-type handle))
2828                         (equal (car type) "text/html"))))
2829              (when (or (setq charset (mail-content-type-get type 'charset))
2830                        header
2831                        (not file))
2832                (setq tmp-file (mm-make-temp-file
2833                                ;; Do we need to care for 8.3 filenames?
2834                                "mm-" nil ".html")))
2835              ;; Add a meta html tag to specify charset and a header.
2836              (cond
2837               (header
2838                (let (title eheader body hcharset coding)
2839                  (with-temp-buffer
2840                    (mm-enable-multibyte)
2841                    (setq case-fold-search t)
2842                    (insert header "\n")
2843                    (setq title (message-fetch-field "subject"))
2844                    (goto-char (point-min))
2845                    (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2846                      (replace-match (cond ((match-beginning 1) "&lt;")
2847                                           ((match-beginning 2) "&gt;")
2848                                           (t "&amp;"))))
2849                    (goto-char (point-min))
2850                    (insert "<pre>\n")
2851                    (goto-char (point-max))
2852                    (insert "</pre>\n<hr>\n")
2853                    ;; We have to examine charset one by one since
2854                    ;; charset specified in parts might be different.
2855                    (if (eq charset 'gnus-decoded)
2856                        (setq charset 'utf-8
2857                              eheader (mm-encode-coding-string (buffer-string)
2858                                                               charset)
2859                              title (when title
2860                                      (mm-encode-coding-string title charset))
2861                              body (mm-encode-coding-string (mm-get-part handle)
2862                                                            charset))
2863                      (setq hcharset (mm-find-mime-charset-region (point-min)
2864                                                                  (point-max)))
2865                      (cond ((= (length hcharset) 1)
2866                             (setq hcharset (car hcharset)
2867                                   coding (mm-charset-to-coding-system
2868                                           hcharset)))
2869                            ((> (length hcharset) 1)
2870                             (setq hcharset 'utf-8
2871                                   coding hcharset)))
2872                      (if coding
2873                          (if charset
2874                              (progn
2875                                (setq body
2876                                      (mm-charset-to-coding-system charset))
2877                                (if (eq coding body)
2878                                    (setq eheader (mm-encode-coding-string
2879                                                   (buffer-string) coding)
2880                                          title (when title
2881                                                  (mm-encode-coding-string
2882                                                   title coding))
2883                                          body (mm-get-part handle))
2884                                  (setq charset 'utf-8
2885                                        eheader (mm-encode-coding-string
2886                                                 (buffer-string) charset)
2887                                        title (when title
2888                                                (mm-encode-coding-string
2889                                                 title charset))
2890                                        body (mm-encode-coding-string
2891                                              (mm-decode-coding-string
2892                                               (mm-get-part handle) body)
2893                                              charset))))
2894                            (setq charset hcharset
2895                                  eheader (mm-encode-coding-string
2896                                           (buffer-string) coding)
2897                                  title (when title
2898                                          (mm-encode-coding-string
2899                                           title coding))
2900                                  body (mm-get-part handle)))
2901                        (setq eheader (mm-string-as-unibyte (buffer-string))
2902                              body (mm-get-part handle))))
2903                    (erase-buffer)
2904                    (mm-disable-multibyte)
2905                    (insert body)
2906                    (when charset
2907                      (mm-add-meta-html-tag handle charset))
2908                    (when title
2909                      (goto-char (point-min))
2910                      (unless (search-forward "<title>" nil t)
2911                        (re-search-forward "<head>\\s-*" nil t)
2912                        (insert "<title>" title "</title>\n")))
2913                    (goto-char (point-min))
2914                    (or (re-search-forward
2915                         "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2916                        (re-search-forward
2917                         "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2918                    (insert eheader)
2919                    (mm-write-region (point-min) (point-max)
2920                                     tmp-file nil nil nil 'binary t))))
2921               (charset
2922                (mm-with-unibyte-buffer
2923                  (insert (if (eq charset 'gnus-decoded)
2924                              (mm-encode-coding-string
2925                               (mm-get-part handle)
2926                               (setq charset 'utf-8))
2927                            (mm-get-part handle)))
2928                  (if (or (mm-add-meta-html-tag handle charset)
2929                          (not file))
2930                      (mm-write-region (point-min) (point-max)
2931                                       tmp-file nil nil nil 'binary t)
2932                    (setq tmp-file nil))))
2933               (tmp-file
2934                (mm-save-part-to-file handle tmp-file)))
2935              (when tmp-file
2936                (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2937              (add-hook 'gnus-summary-prepare-exit-hook
2938                        'gnus-article-browse-delete-temp-files)
2939              (add-hook 'gnus-exit-gnus-hook
2940                        (lambda  ()
2941                          (gnus-article-browse-delete-temp-files t)))
2942              ;; FIXME: Warn if there's an <img> tag?
2943              (browse-url-of-file (or tmp-file (expand-file-name file)))
2944              (setq showed t))
2945             ;; If multipart, recurse
2946             ((equal (mm-handle-media-supertype handle) "multipart")
2947              (when (gnus-article-browse-html-parts handle header)
2948                (setq showed t)))
2949             ((equal (mm-handle-media-type handle) "message/rfc822")
2950              (mm-with-multibyte-buffer
2951                (mm-insert-part handle)
2952                (setq handle (mm-dissect-buffer t t))
2953                (when (and (bufferp (car handle))
2954                           (stringp (car (mm-handle-type handle))))
2955                  (setq handle (list handle)))
2956                (when header
2957                  (article-decode-encoded-words)
2958                  (let ((gnus-visible-headers
2959                         (or (get 'gnus-visible-headers 'standard-value)
2960                             gnus-visible-headers)))
2961                    (article-hide-headers))
2962                  (goto-char (point-min))
2963                  (search-forward "\n\n" nil 'move)
2964                  (skip-chars-backward "\t\n ")
2965                  (setq header (buffer-substring (point-min) (point)))))
2966              (when (prog1
2967                        (gnus-article-browse-html-parts handle header)
2968                      (mm-destroy-parts handle))
2969                (setq showed t)))))
2970     showed))
2971
2972 ;; FIXME: Documentation in texi/gnus.texi missing.
2973 (defun gnus-article-browse-html-article (&optional arg)
2974   "View \"text/html\" parts of the current article with a WWW browser.
2975 The message header is added to the beginning of every html part unless
2976 the prefix argument ARG is given.
2977
2978 Warning: Spammers use links to images in HTML articles to verify
2979 whether you have read the message.  As
2980 `gnus-article-browse-html-article' passes the unmodified HTML
2981 content to the browser without eliminating these \"web bugs\" you
2982 should only use it for mails from trusted senders.
2983
2984 If you alwasy want to display HTML part in the browser, set
2985 `mm-text-html-renderer' to nil."
2986   ;; Cf. `mm-w3m-safe-url-regexp'
2987   (interactive "P")
2988   (if arg
2989       (gnus-summary-show-article)
2990     (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
2991                                     gnus-visible-headers)))
2992       (gnus-summary-show-article)))
2993   (with-current-buffer gnus-article-buffer
2994     (let ((header (unless arg
2995                     (save-restriction
2996                       (widen)
2997                       (buffer-substring-no-properties
2998                        (goto-char (point-min))
2999                        (if (search-forward "\n\n" nil t)
3000                            (match-beginning 0)
3001                          (goto-char (point-max))
3002                          (skip-chars-backward "\t\n ")
3003                          (point))))))
3004           parts)
3005       (set-buffer gnus-original-article-buffer)
3006       (setq parts (mm-dissect-buffer t t))
3007       ;; If singlepart, enforce a list.
3008       (when (and (bufferp (car parts))
3009                  (stringp (car (mm-handle-type parts))))
3010         (setq parts (list parts)))
3011       ;; Process the list
3012       (unless (gnus-article-browse-html-parts parts header)
3013         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3014       (mm-destroy-parts parts)
3015       (unless arg
3016         (gnus-summary-show-article)))))
3017
3018 (defun article-hide-list-identifiers ()
3019   "Remove list identifies from the Subject header.
3020 The `gnus-list-identifiers' variable specifies what to do."
3021   (interactive)
3022   (let ((inhibit-point-motion-hooks t)
3023         (regexp (if (consp gnus-list-identifiers)
3024                     (mapconcat 'identity gnus-list-identifiers " *\\|")
3025                   gnus-list-identifiers))
3026         (inhibit-read-only t))
3027     (when regexp
3028       (save-excursion
3029         (save-restriction
3030           (article-narrow-to-head)
3031           (goto-char (point-min))
3032           (while (re-search-forward
3033                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3034                   nil t)
3035             (delete-region (match-beginning 2) (match-end 0))
3036             (beginning-of-line))
3037           (when (re-search-forward
3038                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3039             (delete-region (match-beginning 1) (match-end 1))))))))
3040
3041 (defun article-hide-pem (&optional arg)
3042   "Toggle hiding of any PEM headers and signatures in the current article.
3043 If given a negative prefix, always show; if given a positive prefix,
3044 always hide."
3045   (interactive (gnus-article-hidden-arg))
3046   (unless (gnus-article-check-hidden-text 'pem arg)
3047     (save-excursion
3048       (let ((inhibit-read-only t) end)
3049         (goto-char (point-min))
3050         ;; Hide the horrendously ugly "header".
3051         (when (and (search-forward
3052                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3053                     nil t)
3054                    (setq end (1+ (match-beginning 0))))
3055           (gnus-add-wash-type 'pem)
3056           (gnus-article-hide-text-type
3057            end
3058            (if (search-forward "\n\n" nil t)
3059                (match-end 0)
3060              (point-max))
3061            'pem)
3062           ;; Hide the trailer as well
3063           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3064                                 nil t)
3065             (gnus-article-hide-text-type
3066              (match-beginning 0) (match-end 0) 'pem)))))))
3067
3068 (defun article-strip-banner ()
3069   "Strip the banners specified by the `banner' group parameter and by
3070 `gnus-article-address-banner-alist'."
3071   (interactive)
3072   (save-excursion
3073     (save-restriction
3074       (let ((inhibit-point-motion-hooks t))
3075         (when (gnus-parameter-banner gnus-newsgroup-name)
3076           (article-really-strip-banner
3077            (gnus-parameter-banner gnus-newsgroup-name)))
3078         (when gnus-article-address-banner-alist
3079           ;; Note that the From header is decoded here, so it is
3080           ;; required that the *-extract-address-components function
3081           ;; supports non-ASCII text.
3082           (let ((from (save-restriction
3083                         (widen)
3084                         (article-narrow-to-head)
3085                         (mail-fetch-field "from"))))
3086             (when (and from
3087                        (setq from
3088                              (cadr (funcall gnus-extract-address-components
3089                                             from))))
3090               (catch 'found
3091                 (dolist (pair gnus-article-address-banner-alist)
3092                   (when (string-match (car pair) from)
3093                     (throw 'found
3094                            (article-really-strip-banner (cdr pair)))))))))))))
3095
3096 (defun article-really-strip-banner (banner)
3097   "Strip the banner specified by the argument."
3098   (save-excursion
3099     (save-restriction
3100       (let ((inhibit-point-motion-hooks t)
3101             (gnus-signature-limit nil)
3102             (inhibit-read-only t))
3103         (article-goto-body)
3104         (cond
3105          ((eq banner 'signature)
3106           (when (gnus-article-narrow-to-signature)
3107             (widen)
3108             (forward-line -1)
3109             (delete-region (point) (point-max))))
3110          ((symbolp banner)
3111           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3112               (while (re-search-forward banner nil t)
3113                 (delete-region (match-beginning 0) (match-end 0)))))
3114          ((stringp banner)
3115           (while (re-search-forward banner nil t)
3116             (delete-region (match-beginning 0) (match-end 0)))))))))
3117
3118 (defun article-babel ()
3119   "Translate article using an online translation service."
3120   (interactive)
3121   (require 'babel)
3122   (gnus-with-article-buffer
3123     (when (article-goto-body)
3124       (let* ((start (point))
3125              (end (point-max))
3126              (orig (buffer-substring start end))
3127              (trans (babel-as-string orig)))
3128         (save-restriction
3129           (narrow-to-region start end)
3130           (delete-region start end)
3131           (insert trans))))))
3132
3133 (defun article-hide-signature (&optional arg)
3134   "Hide the signature in the current article.
3135 If given a negative prefix, always show; if given a positive prefix,
3136 always hide."
3137   (interactive (gnus-article-hidden-arg))
3138   (unless (gnus-article-check-hidden-text 'signature arg)
3139     (save-excursion
3140       (save-restriction
3141         (let ((inhibit-read-only t))
3142           (when (gnus-article-narrow-to-signature)
3143             (gnus-article-hide-text-type
3144              (point-min) (point-max) 'signature))))))
3145   (gnus-set-mode-line 'article))
3146
3147 (defun article-strip-headers-in-body ()
3148   "Strip offensive headers from bodies."
3149   (interactive)
3150   (save-excursion
3151     (article-goto-body)
3152     (let ((case-fold-search t))
3153       (when (looking-at "x-no-archive:")
3154         (gnus-delete-line)))))
3155
3156 (defun article-strip-leading-blank-lines ()
3157   "Remove all blank lines from the beginning of the article."
3158   (interactive)
3159   (save-excursion
3160     (let ((inhibit-point-motion-hooks t)
3161           (inhibit-read-only t))
3162       (when (article-goto-body)
3163         (while (and (not (eobp))
3164                     (looking-at "[ \t]*$"))
3165           (gnus-delete-line))))))
3166
3167 (defun article-narrow-to-head ()
3168   "Narrow the buffer to the head of the message.
3169 Point is left at the beginning of the narrowed-to region."
3170   (narrow-to-region
3171    (goto-char (point-min))
3172    (if (search-forward "\n\n" nil 1)
3173        (1- (point))
3174      (point-max)))
3175   (goto-char (point-min)))
3176
3177 (defun article-goto-body ()
3178   "Place point at the start of the body."
3179   (goto-char (point-min))
3180   (cond
3181    ;; This variable is only bound when dealing with separate
3182    ;; MIME body parts.
3183    (article-goto-body-goes-to-point-min-p
3184     t)
3185    ((search-forward "\n\n" nil t)
3186     t)
3187    (t
3188     (goto-char (point-max))
3189     nil)))
3190
3191 (defun article-strip-multiple-blank-lines ()
3192   "Replace consecutive blank lines with one empty line."
3193   (interactive)
3194   (save-excursion
3195     (let ((inhibit-point-motion-hooks t)
3196           (inhibit-read-only t))
3197       ;; First make all blank lines empty.
3198       (article-goto-body)
3199       (while (re-search-forward "^[ \t]+$" nil t)
3200         (unless (gnus-annotation-in-region-p
3201                  (match-beginning 0) (match-end 0))
3202           (replace-match "" nil t)))
3203       ;; Then replace multiple empty lines with a single empty line.
3204       (article-goto-body)
3205       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3206         (unless (gnus-annotation-in-region-p
3207                  (match-beginning 0) (match-end 0))
3208           (delete-region (match-beginning 1) (match-end 1)))))))
3209
3210 (defun article-strip-leading-space ()
3211   "Remove all white space from the beginning of the lines in the article."
3212   (interactive)
3213   (save-excursion
3214     (let ((inhibit-point-motion-hooks t)
3215           (inhibit-read-only t))
3216       (article-goto-body)
3217       (while (re-search-forward "^[ \t]+" nil t)
3218         (replace-match "" t t)))))
3219
3220 (defun article-strip-trailing-space ()
3221   "Remove all white space from the end of the lines in the article."
3222   (interactive)
3223   (save-excursion
3224     (let ((inhibit-point-motion-hooks t)
3225           (inhibit-read-only t))
3226       (article-goto-body)
3227       (while (re-search-forward "[ \t]+$" nil t)
3228         (replace-match "" t t)))))
3229
3230 (defun article-strip-blank-lines ()
3231   "Strip leading, trailing and multiple blank lines."
3232   (interactive)
3233   (article-strip-leading-blank-lines)
3234   (article-remove-trailing-blank-lines)
3235   (article-strip-multiple-blank-lines))
3236
3237 (defun article-strip-all-blank-lines ()
3238   "Strip all blank lines."
3239   (interactive)
3240   (save-excursion
3241     (let ((inhibit-point-motion-hooks t)
3242           (inhibit-read-only t))
3243       (article-goto-body)
3244       (while (re-search-forward "^[ \t]*\n" nil t)
3245         (replace-match "" t t)))))
3246
3247 (defun gnus-article-narrow-to-signature ()
3248   "Narrow to the signature; return t if a signature is found, else nil."
3249   (let ((inhibit-point-motion-hooks t))
3250     (when (gnus-article-search-signature)
3251       (forward-line 1)
3252       ;; Check whether we have some limits to what we consider
3253       ;; to be a signature.
3254       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3255                       (list gnus-signature-limit)))
3256             limit limited)
3257         (while (setq limit (pop limits))
3258           (if (or (and (integerp limit)
3259                        (< (- (point-max) (point)) limit))
3260                   (and (floatp limit)
3261                        (< (count-lines (point) (point-max)) limit))
3262                   (and (functionp limit)
3263                        (funcall limit))
3264                   (and (stringp limit)
3265                        (not (re-search-forward limit nil t))))
3266               ()                        ; This limit did not succeed.
3267             (setq limited t
3268                   limits nil)))
3269         (unless limited
3270           (narrow-to-region (point) (point-max))
3271           t)))))
3272
3273 (defun gnus-article-search-signature ()
3274   "Search the current buffer for the signature separator.
3275 Put point at the beginning of the signature separator."
3276   (let ((cur (point)))
3277     (goto-char (point-max))
3278     (if (if (stringp gnus-signature-separator)
3279             (re-search-backward gnus-signature-separator nil t)
3280           (let ((seps gnus-signature-separator))
3281             (while (and seps
3282                         (not (re-search-backward (car seps) nil t)))
3283               (pop seps))
3284             seps))
3285         t
3286       (goto-char cur)
3287       nil)))
3288
3289 (defun gnus-article-hidden-arg ()
3290   "Return the current prefix arg as a number, or 0 if no prefix."
3291   (list (if current-prefix-arg
3292             (prefix-numeric-value current-prefix-arg)
3293           0)))
3294
3295 (defun gnus-article-check-hidden-text (type arg)
3296   "Return nil if hiding is necessary.
3297 Arg can be nil or a number.  nil and positive means hide, negative
3298 means show, 0 means toggle."
3299   (save-excursion
3300     (save-restriction
3301       (let ((hide (gnus-article-hidden-text-p type)))
3302         (cond
3303          ((or (null arg)
3304               (> arg 0))
3305           nil)
3306          ((< arg 0)
3307           (gnus-article-show-hidden-text type)
3308           t)
3309          (t
3310           (if (eq hide 'hidden)
3311               (progn
3312                 (gnus-article-show-hidden-text type)
3313                 t)
3314             nil)))))))
3315
3316 (defun gnus-article-hidden-text-p (type)
3317   "Say whether the current buffer contains hidden text of type TYPE."
3318   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3319     (while (and pos
3320                 (not (get-text-property pos 'invisible))
3321                 (not (get-text-property pos 'dummy-invisible)))
3322       (setq pos
3323             (text-property-any (1+ pos) (point-max) 'article-type type)))
3324     (if pos
3325         'hidden
3326       nil)))
3327
3328 (defun gnus-article-show-hidden-text (type &optional dummy)
3329   "Show all hidden text of type TYPE.
3330 Originally it is hide instead of DUMMY."
3331   (let ((inhibit-read-only t)
3332         (inhibit-point-motion-hooks t))
3333     (gnus-remove-text-properties-when
3334      'article-type type
3335      (point-min) (point-max)
3336      (cons 'article-type (cons type
3337                                gnus-hidden-properties)))
3338     (gnus-delete-wash-type type)))
3339
3340 (defconst article-time-units
3341   `((year . ,(* 365.25 24 60 60))
3342     (week . ,(* 7 24 60 60))
3343     (day . ,(* 24 60 60))
3344     (hour . ,(* 60 60))
3345     (minute . 60)
3346     (second . 1))
3347   "Mapping from time units to seconds.")
3348
3349 (defun gnus-article-forward-header ()
3350   "Move point to the start of the next header.
3351 If the current header is a continuation header, this can be several
3352 lines forward."
3353   (let ((ended nil))
3354     (while (not ended)
3355       (forward-line 1)
3356       (if (looking-at "[ \t]+[^ \t]")
3357           (forward-line 1)
3358         (setq ended t)))))
3359
3360 (defun article-date-ut (&optional type highlight)
3361   "Convert DATE date to universal time in the current article.
3362 If TYPE is `local', convert to local time; if it is `lapsed', output
3363 how much time has lapsed since DATE.  For `lapsed', the value of
3364 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3365 should replace the \"Date:\" one, or should be added below it."
3366   (interactive (list 'ut t))
3367   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3368          (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3369                              tdate-regexp)
3370                             ((eq type 'lapsed)
3371                              "^X-Sent:[ \t]")
3372                             (article-lapsed-timer
3373                              "^Date:[ \t]")
3374                             (t
3375                              tdate-regexp)))
3376          (case-fold-search t)
3377          (inhibit-read-only t)
3378          (inhibit-point-motion-hooks t)
3379          pos date bface eface)
3380     (save-excursion
3381       (save-restriction
3382         (widen)
3383         (goto-char (point-min))
3384         (while (or (setq date (get-text-property (setq pos (point))
3385                                                  'original-date))
3386                    (when (setq pos (next-single-property-change
3387                                     (point) 'original-date))
3388                      (setq date (get-text-property pos 'original-date))
3389                      t))
3390           (narrow-to-region pos (or (text-property-any pos (point-max)
3391                                                        'original-date nil)
3392                                     (point-max)))
3393           (goto-char (point-min))
3394           (when (re-search-forward tdate-regexp nil t)
3395             (setq bface (get-text-property (point-at-bol) 'face)
3396                   eface (get-text-property (1- (point-at-eol)) 'face)))
3397           (goto-char (point-min))
3398           (setq pos nil)
3399           ;; Delete any old Date headers.
3400           (while (re-search-forward date-regexp nil t)
3401             (if pos
3402                 (delete-region (point-at-bol) (progn
3403                                                 (gnus-article-forward-header)
3404                                                 (point)))
3405               (delete-region (point-at-bol) (progn
3406                                               (gnus-article-forward-header)
3407                                               (forward-char -1)
3408                                               (point)))
3409               (setq pos (point))))
3410           (when (and (not pos)
3411                      (re-search-forward tdate-regexp nil t))
3412             (forward-line 1))
3413           (gnus-goto-char pos)
3414           (insert (article-make-date-line date (or type 'ut)))
3415           (unless pos
3416             (insert "\n")
3417             (forward-line -1))
3418           ;; Do highlighting.
3419           (beginning-of-line)
3420           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3421             (put-text-property (match-beginning 1) (1+ (match-end 1))
3422                                'face bface)
3423             (put-text-property (match-beginning 2) (match-end 2)
3424                                'face eface))
3425           (put-text-property (point-min) (1- (point-max)) 'original-date date)
3426           (goto-char (point-max))
3427           (widen))))))
3428
3429 (defun article-make-date-line (date type)
3430   "Return a DATE line of TYPE."
3431   (unless (memq type '(local ut original user iso8601 lapsed english))
3432     (error "Unknown conversion type: %s" type))
3433   (condition-case ()
3434       (let ((time (date-to-time date)))
3435         (cond
3436          ;; Convert to the local timezone.
3437          ((eq type 'local)
3438           (concat "Date: " (message-make-date time)))
3439          ;; Convert to Universal Time.
3440          ((eq type 'ut)
3441           (concat "Date: "
3442                   (substring
3443                    (message-make-date
3444                     (let* ((e (parse-time-string date))
3445                            (tm (apply 'encode-time e))
3446                            (ms (car tm))
3447                            (ls (- (cadr tm) (car (current-time-zone time)))))
3448                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3449                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3450                             (t (list ms ls)))))
3451                    0 -5)
3452                   "UT"))
3453          ;; Get the original date from the article.
3454          ((eq type 'original)
3455           (concat "Date: " (if (string-match "\n+$" date)
3456                                (substring date 0 (match-beginning 0))
3457                              date)))
3458          ;; Let the user define the format.
3459          ((eq type 'user)
3460           (let ((format (or (condition-case nil
3461                                 (with-current-buffer gnus-summary-buffer
3462                                   gnus-article-time-format)
3463                               (error nil))
3464                             gnus-article-time-format)))
3465             (if (functionp format)
3466                 (funcall format time)
3467               (concat "Date: " (format-time-string format time)))))
3468          ;; ISO 8601.
3469          ((eq type 'iso8601)
3470           (let ((tz (car (current-time-zone time))))
3471             (concat
3472              "Date: "
3473              (format-time-string "%Y%m%dT%H%M%S" time)
3474              (format "%s%02d%02d"
3475                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3476                      (/ (% (abs tz) 3600) 60)))))
3477          ;; Do an X-Sent lapsed format.
3478          ((eq type 'lapsed)
3479           ;; If the date is seriously mangled, the timezone functions are
3480           ;; liable to bug out, so we ignore all errors.
3481           (let* ((now (current-time))
3482                  (real-time (subtract-time now time))
3483                  (real-sec (and real-time
3484                                 (+ (* (float (car real-time)) 65536)
3485                                    (cadr real-time))))
3486                  (sec (and real-time (abs real-sec)))
3487                  num prev)
3488             (cond
3489              ((null real-time)
3490               "X-Sent: Unknown")
3491              ((zerop sec)
3492               "X-Sent: Now")
3493              (t
3494               (concat
3495                "X-Sent: "
3496                ;; This is a bit convoluted, but basically we go
3497                ;; through the time units for years, weeks, etc,
3498                ;; and divide things to see whether that results
3499                ;; in positive answers.
3500                (mapconcat
3501                 (lambda (unit)
3502                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3503                       ;; The (remaining) seconds are too few to
3504                       ;; be divided into this time unit.
3505                       ""
3506                     ;; It's big enough, so we output it.
3507                     (setq sec (- sec (* num (cdr unit))))
3508                     (prog1
3509                         (concat (if prev ", " "") (int-to-string
3510                                                    (floor num))
3511                                 " " (symbol-name (car unit))
3512                                 (if (> num 1) "s" ""))
3513                       (setq prev t))))
3514                 article-time-units "")
3515                ;; If dates are odd, then it might appear like the
3516                ;; article was sent in the future.
3517                (if (> real-sec 0)
3518                    " ago"
3519                  " in the future"))))))
3520          ;; Display the date in proper English
3521          ((eq type 'english)
3522           (let ((dtime (decode-time time)))
3523             (concat
3524              "Date: the "
3525              (number-to-string (nth 3 dtime))
3526              (let ((digit (% (nth 3 dtime) 10)))
3527                (cond
3528                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3529                 ((= digit 1) "st")
3530                 ((= digit 2) "nd")
3531                 ((= digit 3) "rd")
3532                 (t "th")))
3533              " of "
3534              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3535              " "
3536              (number-to-string (nth 5 dtime))
3537              " at "
3538              (format "%02d" (nth 2 dtime))
3539              ":"
3540              (format "%02d" (nth 1 dtime)))))))
3541     (error
3542      (format "Date: %s (from Gnus)" date))))
3543
3544 (defun article-date-local (&optional highlight)
3545   "Convert the current article date to the local timezone."
3546   (interactive (list t))
3547   (article-date-ut 'local highlight))
3548
3549 (defun article-date-english (&optional highlight)
3550   "Convert the current article date to something that is proper English."
3551   (interactive (list t))
3552   (article-date-ut 'english highlight))
3553
3554 (defun article-date-original (&optional highlight)
3555   "Convert the current article date to what it was originally.
3556 This is only useful if you have used some other date conversion
3557 function and want to see what the date was before converting."
3558   (interactive (list t))
3559   (article-date-ut 'original highlight))
3560
3561 (defun article-date-lapsed (&optional highlight)
3562   "Convert the current article date to time lapsed since it was sent."
3563   (interactive (list t))
3564   (article-date-ut 'lapsed highlight))
3565
3566 (defun article-update-date-lapsed ()
3567   "Function to be run from a timer to update the lapsed time line."
3568   (save-match-data
3569     (let (deactivate-mark)
3570       (save-excursion
3571         (ignore-errors
3572          (walk-windows
3573           (lambda (w)
3574             (set-buffer (window-buffer w))
3575             (when (eq major-mode 'gnus-article-mode)
3576               (let ((mark (point-marker)))
3577                 (goto-char (point-min))
3578                 (when (re-search-forward "^X-Sent:" nil t)
3579                   (article-date-lapsed t))
3580                 (goto-char (marker-position mark))
3581                 (move-marker mark nil))))
3582           nil 'visible))))))
3583
3584 (defun gnus-start-date-timer (&optional n)
3585   "Start a timer to update the X-Sent header in the article buffers.
3586 The numerical prefix says how frequently (in seconds) the function
3587 is to run."
3588   (interactive "p")
3589   (unless n
3590     (setq n 1))
3591   (gnus-stop-date-timer)
3592   (setq article-lapsed-timer
3593         (run-at-time 1 n 'article-update-date-lapsed)))
3594
3595 (defun gnus-stop-date-timer ()
3596   "Stop the X-Sent timer."
3597   (interactive)
3598   (when article-lapsed-timer
3599     (nnheader-cancel-timer article-lapsed-timer)
3600     (setq article-lapsed-timer nil)))
3601
3602 (defun article-date-user (&optional highlight)
3603   "Convert the current article date to the user-defined format.
3604 This format is defined by the `gnus-article-time-format' variable."
3605   (interactive (list t))
3606   (article-date-ut 'user highlight))
3607
3608 (defun article-date-iso8601 (&optional highlight)
3609   "Convert the current article date to ISO8601."
3610   (interactive (list t))
3611   (article-date-ut 'iso8601 highlight))
3612
3613 (defmacro gnus-article-save-original-date (&rest forms)
3614   "Save the original date as a text property and evaluate FORMS."
3615   `(let* ((case-fold-search t)
3616           (start (progn
3617                    (goto-char (point-min))
3618                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3619                               (not (bolp)))
3620                      (match-end 0))))
3621           (date (when (and start
3622                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3623                                               nil t))
3624                   (buffer-substring-no-properties start
3625                                                   (match-beginning 0)))))
3626      (goto-char (point-max))
3627      (skip-chars-backward "\n")
3628      (put-text-property (point-min) (point) 'original-date date)
3629      ,@forms
3630      (goto-char (point-max))
3631      (skip-chars-backward "\n")
3632      (put-text-property (point-min) (point) 'original-date date)))
3633
3634 ;; (defun article-show-all ()
3635 ;;   "Show all hidden text in the article buffer."
3636 ;;   (interactive)
3637 ;;   (save-excursion
3638 ;;     (let ((inhibit-read-only t))
3639 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3640
3641 (defun article-remove-leading-whitespace ()
3642   "Remove excessive whitespace from all headers."
3643   (interactive)
3644   (save-excursion
3645     (save-restriction
3646       (let ((inhibit-read-only t))
3647         (article-narrow-to-head)
3648         (goto-char (point-min))
3649         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3650           (delete-region (match-beginning 1) (match-end 1)))))))
3651
3652 (defun article-emphasize (&optional arg)
3653   "Emphasize text according to `gnus-emphasis-alist'."
3654   (interactive (gnus-article-hidden-arg))
3655   (unless (gnus-article-check-hidden-text 'emphasis arg)
3656     (save-excursion
3657       (let ((alist (or
3658                     (condition-case nil
3659                         (with-current-buffer gnus-summary-buffer
3660                           gnus-article-emphasis-alist)
3661                       (error))
3662                     gnus-emphasis-alist))
3663             (inhibit-read-only t)
3664             (props (append '(article-type emphasis)
3665                            gnus-hidden-properties))
3666             regexp elem beg invisible visible face)
3667         (article-goto-body)
3668         (setq beg (point))
3669         (while (setq elem (pop alist))
3670           (goto-char beg)
3671           (setq regexp (car elem)
3672                 invisible (nth 1 elem)
3673                 visible (nth 2 elem)
3674                 face (nth 3 elem))
3675           (while (re-search-forward regexp nil t)
3676             (when (and (match-beginning visible) (match-beginning invisible))
3677               (gnus-article-hide-text
3678                (match-beginning invisible) (match-end invisible) props)
3679               (gnus-article-unhide-text-type
3680                (match-beginning visible) (match-end visible) 'emphasis)
3681               (gnus-put-overlay-excluding-newlines
3682                (match-beginning visible) (match-end visible) 'face face)
3683               (gnus-add-wash-type 'emphasis)
3684               (goto-char (match-end invisible)))))))))
3685
3686 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3687   "Setup newsgroup emphasis alist."
3688   (unless gnus-article-emphasis-alist
3689     (let ((name (and gnus-newsgroup-name
3690                      (gnus-group-real-name gnus-newsgroup-name))))
3691       (make-local-variable 'gnus-article-emphasis-alist)
3692       (setq gnus-article-emphasis-alist
3693             (nconc
3694              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3695                (while (setq elem (pop alist))
3696                  (when (and name (string-match (car elem) name))
3697                    (setq alist nil
3698                          highlight (copy-sequence (cdr elem)))))
3699                highlight)
3700              (copy-sequence highlight-words)
3701              (if gnus-newsgroup-name
3702                  (copy-sequence (gnus-group-find-parameter
3703                                  gnus-newsgroup-name 'highlight-words t)))
3704              gnus-emphasis-alist)))))
3705
3706 (defvar gnus-summary-article-menu)
3707 (defvar gnus-summary-post-menu)
3708
3709 ;;; Saving functions.
3710
3711 (defun gnus-article-save (save-buffer file &optional num)
3712   "Save the currently selected article."
3713   (when (or (get gnus-default-article-saver :headers)
3714             (not gnus-save-all-headers))
3715     ;; Remove headers according to `gnus-saved-headers' or the value
3716     ;; of the `:headers' property that the saver function might have.
3717     (let ((gnus-visible-headers
3718            (or (symbol-value (get gnus-default-article-saver :headers))
3719                gnus-saved-headers gnus-visible-headers))
3720           (gnus-article-buffer save-buffer))
3721       (save-excursion
3722         (set-buffer save-buffer)
3723         (article-hide-headers 1 t))))
3724   (save-window-excursion
3725     (if (not gnus-default-article-saver)
3726         (error "No default saver is defined")
3727       ;; !!! Magic!  The saving functions all save
3728       ;; `gnus-save-article-buffer' (or so they think), but we
3729       ;; bind that variable to our save-buffer.
3730       (set-buffer gnus-article-buffer)
3731       (let* ((gnus-save-article-buffer save-buffer)
3732              (filename
3733               (cond
3734                ((not gnus-prompt-before-saving) 'default)
3735                ((eq gnus-prompt-before-saving 'always) nil)
3736                (t file)))
3737              (gnus-number-of-articles-to-be-saved
3738               (when (eq gnus-prompt-before-saving t)
3739                 num)))                  ; Magic
3740         (set-buffer gnus-article-current-summary)
3741         (funcall gnus-default-article-saver filename)))))
3742
3743 (defun gnus-read-save-file-name (prompt &optional filename
3744                                         function group headers variable
3745                                         dir-var)
3746   (let ((default-name
3747           (funcall function group headers (symbol-value variable)))
3748         result)
3749     (setq result
3750           (expand-file-name
3751            (cond
3752             ((eq filename 'default)
3753              default-name)
3754             ((eq filename t)
3755              default-name)
3756             (filename filename)
3757             (t
3758              (when (symbol-value dir-var)
3759                (setq default-name (expand-file-name
3760                                    (file-name-nondirectory default-name)
3761                                    (symbol-value dir-var))))
3762              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3763                     (prompt
3764                      (format prompt
3765                              (if (and gnus-number-of-articles-to-be-saved
3766                                       (> gnus-number-of-articles-to-be-saved 1))
3767                                  (format "these %d articles"
3768                                          gnus-number-of-articles-to-be-saved)
3769                                "this article")))
3770                     (file
3771                      ;; Let the split methods have their say.
3772                      (cond
3773                       ;; No split name was found.
3774                       ((null split-name)
3775                        (read-file-name
3776                         (concat prompt " (default "
3777                                 (file-name-nondirectory default-name) "): ")
3778                         (file-name-directory default-name)
3779                         default-name))
3780                       ;; A single group name is returned.
3781                       ((stringp split-name)
3782                        (setq default-name
3783                              (funcall function split-name headers
3784                                       (symbol-value variable)))
3785                        (read-file-name
3786                         (concat prompt " (default "
3787                                 (file-name-nondirectory default-name) "): ")
3788                         (file-name-directory default-name)
3789                         default-name))
3790                       ;; A single split name was found
3791                       ((= 1 (length split-name))
3792                        (let* ((name (expand-file-name
3793                                      (car split-name)
3794                                      gnus-article-save-directory))
3795                               (dir (cond ((file-directory-p name)
3796                                           (file-name-as-directory name))
3797                                          ((file-exists-p name) name)
3798                                          (t gnus-article-save-directory))))
3799                          (read-file-name
3800                           (concat prompt " (default " name "): ")
3801                           dir name)))
3802                       ;; A list of splits was found.
3803                       (t
3804                        (setq split-name (nreverse split-name))
3805                        (let (result)
3806                          (let ((file-name-history
3807                                 (nconc split-name file-name-history)))
3808                            (setq result
3809                                  (expand-file-name
3810                                   (read-file-name
3811                                    (concat prompt " (`M-p' for defaults): ")
3812                                    gnus-article-save-directory
3813                                    (car split-name))
3814                                   gnus-article-save-directory)))
3815                          (car (push result file-name-history)))))))
3816                ;; Create the directory.
3817                (gnus-make-directory (file-name-directory file))
3818                ;; If we have read a directory, we append the default file name.
3819                (when (file-directory-p file)
3820                  (setq file (expand-file-name (file-name-nondirectory
3821                                                default-name)
3822                                               (file-name-as-directory file))))
3823                ;; Possibly translate some characters.
3824                (nnheader-translate-file-chars file))))))
3825     (gnus-make-directory (file-name-directory result))
3826     (when variable
3827       (set variable result))
3828     (when dir-var
3829       (set dir-var (file-name-directory result)))
3830     result))
3831
3832 (defun gnus-article-archive-name (group)
3833   "Return the first instance of an \"Archive-name\" in the current buffer."
3834   (let ((case-fold-search t))
3835     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3836       (nnheader-concat gnus-article-save-directory
3837                        (match-string 1)))))
3838
3839 (defun gnus-article-nndoc-name (group)
3840   "If GROUP is an nndoc group, return the name of the parent group."
3841   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3842     (gnus-group-get-parameter group 'save-article-group)))
3843
3844 (defun gnus-summary-save-in-rmail (&optional filename)
3845   "Append this article to Rmail file.
3846 Optional argument FILENAME specifies file name.
3847 Directory to save to is default to `gnus-article-save-directory'."
3848   (setq filename (gnus-read-save-file-name
3849                   "Save %s in rmail file" filename
3850                   gnus-rmail-save-name gnus-newsgroup-name
3851                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3852   (gnus-eval-in-buffer-window gnus-save-article-buffer
3853     (save-excursion
3854       (save-restriction
3855         (widen)
3856         (gnus-output-to-rmail filename))))
3857   filename)
3858
3859 (defun gnus-summary-save-in-mail (&optional filename)
3860   "Append this article to Unix mail file.
3861 Optional argument FILENAME specifies file name.
3862 Directory to save to is default to `gnus-article-save-directory'."
3863   (setq filename (gnus-read-save-file-name
3864                   "Save %s in Unix mail file" filename
3865                   gnus-mail-save-name gnus-newsgroup-name
3866                   gnus-current-headers 'gnus-newsgroup-last-mail))
3867   (gnus-eval-in-buffer-window gnus-save-article-buffer
3868     (save-excursion
3869       (save-restriction
3870         (widen)
3871         (if (and (file-readable-p filename)
3872                  (file-regular-p filename)
3873                  (mail-file-babyl-p filename))
3874             (rmail-output-to-rmail-file filename t)
3875           (gnus-output-to-mail filename)))))
3876   filename)
3877
3878 (put 'gnus-summary-save-in-file :decode t)
3879 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3880 (defun gnus-summary-save-in-file (&optional filename overwrite)
3881   "Append this article to file.
3882 Optional argument FILENAME specifies file name.
3883 Directory to save to is default to `gnus-article-save-directory'."
3884   (setq filename (gnus-read-save-file-name
3885                   "Save %s in file" filename
3886                   gnus-file-save-name gnus-newsgroup-name
3887                   gnus-current-headers 'gnus-newsgroup-last-file))
3888   (gnus-eval-in-buffer-window gnus-save-article-buffer
3889     (save-excursion
3890       (save-restriction
3891         (widen)
3892         (when (and overwrite
3893                    (file-exists-p filename))
3894           (delete-file filename))
3895         (gnus-output-to-file filename))))
3896   filename)
3897
3898 (put 'gnus-summary-write-to-file :decode t)
3899 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3900 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3901 (defun gnus-summary-write-to-file (&optional filename)
3902   "Write this article to a file, overwriting it if the file exists.
3903 Optional argument FILENAME specifies file name.
3904 The directory to save in defaults to `gnus-article-save-directory'."
3905   (setq filename (gnus-read-save-file-name
3906                   "Save %s in file" filename
3907                   gnus-file-save-name gnus-newsgroup-name
3908                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3909   (gnus-summary-save-in-file filename t))
3910
3911 (put 'gnus-summary-save-body-in-file :decode t)
3912 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3913   "Append this article body to a file.
3914 Optional argument FILENAME specifies file name.
3915 The directory to save in defaults to `gnus-article-save-directory'."
3916   (setq filename (gnus-read-save-file-name
3917                   "Save %s body in file" filename
3918                   gnus-file-save-name gnus-newsgroup-name
3919                   gnus-current-headers 'gnus-newsgroup-last-file))
3920   (gnus-eval-in-buffer-window gnus-save-article-buffer
3921     (save-excursion
3922       (save-restriction
3923         (widen)
3924         (when (article-goto-body)
3925           (narrow-to-region (point) (point-max)))
3926         (when (and overwrite
3927                    (file-exists-p filename))
3928           (delete-file filename))
3929         (gnus-output-to-file filename))))
3930   filename)
3931
3932 (put 'gnus-summary-write-body-to-file :decode t)
3933 (put 'gnus-summary-write-body-to-file
3934      :function 'gnus-summary-save-body-in-file)
3935 (defun gnus-summary-write-body-to-file (&optional filename)
3936   "Write this article body to a file, overwriting it if the file exists.
3937 Optional argument FILENAME specifies file name.
3938 The directory to save in defaults to `gnus-article-save-directory'."
3939   (setq filename (gnus-read-save-file-name
3940                   "Save %s body in file" filename
3941                   gnus-file-save-name gnus-newsgroup-name
3942                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3943   (gnus-summary-save-body-in-file filename t))
3944
3945 (defun gnus-summary-save-in-pipe (&optional command)
3946   "Pipe this article to subprocess."
3947   (setq command
3948         (cond ((and (eq command 'default)
3949                     gnus-last-shell-command)
3950                gnus-last-shell-command)
3951               ((stringp command)
3952                command)
3953               (t (read-string
3954                   (format
3955                    "Shell command on %s: "
3956                    (if (and gnus-number-of-articles-to-be-saved
3957                             (> gnus-number-of-articles-to-be-saved 1))
3958                        (format "these %d articles"
3959                                gnus-number-of-articles-to-be-saved)
3960                      "this article"))
3961                   gnus-last-shell-command))))
3962   (when (string-equal command "")
3963     (if gnus-last-shell-command
3964         (setq command gnus-last-shell-command)
3965       (error "A command is required")))
3966   (gnus-eval-in-buffer-window gnus-article-buffer
3967     (save-restriction
3968       (widen)
3969       (shell-command-on-region (point-min) (point-max) command nil)))
3970   (setq gnus-last-shell-command command))
3971
3972 (defun gnus-summary-pipe-to-muttprint (&optional command)
3973   "Pipe this article to muttprint."
3974   (setq command (read-string
3975                  "Print using command: " gnus-summary-muttprint-program
3976                  nil gnus-summary-muttprint-program))
3977   (gnus-summary-save-in-pipe command))
3978
3979 ;;; Article file names when saving.
3980
3981 (defun gnus-capitalize-newsgroup (newsgroup)
3982   "Capitalize NEWSGROUP name."
3983   (when (not (zerop (length newsgroup)))
3984     (concat (char-to-string (upcase (aref newsgroup 0)))
3985             (substring newsgroup 1))))
3986
3987 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3988   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3989 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3990 Otherwise, it is like ~/News/news/group/num."
3991   (let ((default
3992           (expand-file-name
3993            (concat (if (gnus-use-long-file-name 'not-save)
3994                        (gnus-capitalize-newsgroup newsgroup)
3995                      (gnus-newsgroup-directory-form newsgroup))
3996                    "/" (int-to-string (mail-header-number headers)))
3997            gnus-article-save-directory)))
3998     (if (and last-file
3999              (string-equal (file-name-directory default)
4000                            (file-name-directory last-file))
4001              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4002         default
4003       (or last-file default))))
4004
4005 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4006   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4007 If variable `gnus-use-long-file-name' is non-nil, it is
4008 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
4009   (let ((default
4010           (expand-file-name
4011            (concat (if (gnus-use-long-file-name 'not-save)
4012                        newsgroup
4013                      (gnus-newsgroup-directory-form newsgroup))
4014                    "/" (int-to-string (mail-header-number headers)))
4015            gnus-article-save-directory)))
4016     (if (and last-file
4017              (string-equal (file-name-directory default)
4018                            (file-name-directory last-file))
4019              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4020         default
4021       (or last-file default))))
4022
4023 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4024   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4025 If variable `gnus-use-long-file-name' is non-nil, it is
4026 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
4027   (or last-file
4028       (expand-file-name
4029        (if (gnus-use-long-file-name 'not-save)
4030            newsgroup
4031          (file-relative-name
4032           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4033           default-directory))
4034        gnus-article-save-directory)))
4035
4036 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4037   "Generate file name from sender."
4038   (let ((from (mail-header-from headers)))
4039     (expand-file-name
4040      (if (and from (string-match "\\([^ <]+\\)@" from))
4041          (match-string 1 from)
4042        "nobody")
4043      gnus-article-save-directory)))
4044
4045 (defun article-verify-x-pgp-sig ()
4046   "Verify X-PGP-Sig."
4047   ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4048   (interactive)
4049   (if (gnus-buffer-live-p gnus-original-article-buffer)
4050       (let ((sig (with-current-buffer gnus-original-article-buffer
4051                    (gnus-fetch-field "X-PGP-Sig")))
4052             items info headers)
4053         (when (and sig
4054                    mml2015-use
4055                    (mml2015-clear-verify-function))
4056           (with-temp-buffer
4057             (insert-buffer-substring gnus-original-article-buffer)
4058             (setq items (split-string sig))
4059             (message-narrow-to-head)
4060             (let ((inhibit-point-motion-hooks t)
4061                   (case-fold-search t))
4062               ;; Don't verify multiple headers.
4063               (setq headers (mapconcat (lambda (header)
4064                                          (concat header ": "
4065                                                  (mail-fetch-field header)
4066                                                  "\n"))
4067                                        (split-string (nth 1 items) ",") "")))
4068             (delete-region (point-min) (point-max))
4069             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4070             (insert "X-Signed-Headers: " (nth 1 items) "\n")
4071             (insert headers)
4072             (widen)
4073             (forward-line)
4074             (while (not (eobp))
4075               (if (looking-at "^-")
4076                   (insert "- "))
4077               (forward-line))
4078             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4079             (insert "Version: " (car items) "\n\n")
4080             (insert (mapconcat 'identity (cddr items) "\n"))
4081             (insert "\n-----END PGP SIGNATURE-----\n")
4082             (let ((mm-security-handle (list (format "multipart/signed"))))
4083               (mml2015-clean-buffer)
4084               (let ((coding-system-for-write (or gnus-newsgroup-charset
4085                                                  'iso-8859-1)))
4086                 (funcall (mml2015-clear-verify-function)))
4087               (setq info
4088                     (or (mm-handle-multipart-ctl-parameter
4089                          mm-security-handle 'gnus-details)
4090                         (mm-handle-multipart-ctl-parameter
4091                          mm-security-handle 'gnus-info)))))
4092           (when info
4093             (let ((inhibit-read-only t) bface eface)
4094               (save-restriction
4095                 (message-narrow-to-head)
4096                 (goto-char (point-max))
4097                 (forward-line -1)
4098                 (setq bface (get-text-property (point-at-bol) 'face)
4099                       eface (get-text-property (1- (point-at-eol)) 'face))
4100                 (message-remove-header "X-Gnus-PGP-Verify")
4101                 (if (re-search-forward "^X-PGP-Sig:" nil t)
4102                     (forward-line)
4103                   (goto-char (point-max)))
4104                 (narrow-to-region (point) (point))
4105                 (insert "X-Gnus-PGP-Verify: " info "\n")
4106                 (goto-char (point-min))
4107                 (forward-line)
4108                 (while (not (eobp))
4109                   (if (not (looking-at "^[ \t]"))
4110                       (insert " "))
4111                   (forward-line))
4112                 ;; Do highlighting.
4113                 (goto-char (point-min))
4114                 (when (looking-at "\\([^:]+\\): *")
4115                   (put-text-property (match-beginning 1) (1+ (match-end 1))
4116                                      'face bface)
4117                   (put-text-property (match-end 0) (point-max)
4118                                      'face eface)))))))))
4119
4120 (defun article-verify-cancel-lock ()
4121   "Verify Cancel-Lock header."
4122   (interactive)
4123   (if (gnus-buffer-live-p gnus-original-article-buffer)
4124       (canlock-verify gnus-original-article-buffer)))
4125
4126 (eval-and-compile
4127   (mapc
4128    (lambda (func)
4129      (let (afunc gfunc)
4130        (if (consp func)
4131            (setq afunc (car func)
4132                  gfunc (cdr func))
4133          (setq afunc func
4134                gfunc (intern (format "gnus-%s" func))))
4135        (defalias gfunc
4136          (when (fboundp afunc)
4137            `(lambda (&optional interactive &rest args)
4138               ,(documentation afunc t)
4139               (interactive (list t))
4140               (save-excursion
4141                 (set-buffer gnus-article-buffer)
4142                 (if interactive
4143                     (call-interactively ',afunc)
4144                   (apply ',afunc args))))))))
4145    '(article-hide-headers
4146      article-verify-x-pgp-sig
4147      article-verify-cancel-lock
4148      article-hide-boring-headers
4149      article-treat-overstrike
4150      article-treat-ansi-sequences
4151      article-fill-long-lines
4152      article-capitalize-sentences
4153      article-remove-cr
4154      article-remove-leading-whitespace
4155      article-display-x-face
4156      article-display-face
4157      article-de-quoted-unreadable
4158      article-de-base64-unreadable
4159      article-decode-HZ
4160      article-wash-html
4161      article-unsplit-urls
4162      article-hide-list-identifiers
4163      article-strip-banner
4164      article-babel
4165      article-hide-pem
4166      article-hide-signature
4167      article-strip-headers-in-body
4168      article-remove-trailing-blank-lines
4169      article-strip-leading-blank-lines
4170      article-strip-multiple-blank-lines
4171      article-strip-leading-space
4172      article-strip-trailing-space
4173      article-strip-blank-lines
4174      article-strip-all-blank-lines
4175      article-date-local
4176      article-date-english
4177      article-date-iso8601
4178      article-date-original
4179      article-date-ut
4180      article-decode-mime-words
4181      article-decode-charset
4182      article-decode-encoded-words
4183      article-date-user
4184      article-date-lapsed
4185      article-emphasize
4186      article-treat-dumbquotes
4187      article-normalize-headers
4188      ;;(article-show-all . gnus-article-show-all-headers)
4189      )))
4190 \f
4191 ;;;
4192 ;;; Gnus article mode
4193 ;;;
4194
4195 (put 'gnus-article-mode 'mode-class 'special)
4196
4197 (set-keymap-parent gnus-article-mode-map widget-keymap)
4198
4199 (gnus-define-keys gnus-article-mode-map
4200   " " gnus-article-goto-next-page
4201   "\177" gnus-article-goto-prev-page
4202   [delete] gnus-article-goto-prev-page
4203   [backspace] gnus-article-goto-prev-page
4204   "\C-c^" gnus-article-refer-article
4205   "h" gnus-article-show-summary
4206   "s" gnus-article-show-summary
4207   "\C-c\C-m" gnus-article-mail
4208   "?" gnus-article-describe-briefly
4209   "e" gnus-summary-edit-article
4210   "<" beginning-of-buffer
4211   ">" end-of-buffer
4212   "\C-c\C-i" gnus-info-find-node
4213   "\C-c\C-b" gnus-bug
4214   "R" gnus-article-reply-with-original
4215   "F" gnus-article-followup-with-original
4216   "\C-hk" gnus-article-describe-key
4217   "\C-hc" gnus-article-describe-key-briefly
4218
4219   "\C-d" gnus-article-read-summary-keys
4220   "\M-*" gnus-article-read-summary-keys
4221   "\M-#" gnus-article-read-summary-keys
4222   "\M-^" gnus-article-read-summary-keys
4223   "\M-g" gnus-article-read-summary-keys)
4224
4225 (substitute-key-definition
4226  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4227
4228 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4229   "W" gnus-article-wide-reply-with-original)
4230 (if (featurep 'xemacs)
4231     (set-keymap-default-binding gnus-article-send-map
4232                                 'gnus-article-read-summary-send-keys)
4233   (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4234
4235 (defun gnus-article-make-menu-bar ()
4236   (unless (boundp 'gnus-article-commands-menu)
4237     (gnus-summary-make-menu-bar))
4238   (gnus-turn-off-edit-menu 'article)
4239   (unless (boundp 'gnus-article-article-menu)
4240     (easy-menu-define
4241      gnus-article-article-menu gnus-article-mode-map ""
4242      '("Article"
4243        ["Scroll forwards" gnus-article-goto-next-page t]
4244        ["Scroll backwards" gnus-article-goto-prev-page t]
4245        ["Show summary" gnus-article-show-summary t]
4246        ["Fetch Message-ID at point" gnus-article-refer-article t]
4247        ["Mail to address at point" gnus-article-mail t]
4248        ["Send a bug report" gnus-bug t]))
4249
4250     (easy-menu-define
4251      gnus-article-treatment-menu gnus-article-mode-map ""
4252      ;; Fixme: this should use :active (and maybe :visible).
4253      '("Treatment"
4254        ["Hide headers" gnus-article-hide-headers t]
4255        ["Hide signature" gnus-article-hide-signature t]
4256        ["Hide citation" gnus-article-hide-citation t]
4257        ["Treat overstrike" gnus-article-treat-overstrike t]
4258        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4259        ["Remove carriage return" gnus-article-remove-cr t]
4260        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4261        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4262        ["Remove base64" gnus-article-de-base64-unreadable t]
4263        ["Treat html" gnus-article-wash-html t]
4264        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4265        ["Decode HZ" gnus-article-decode-HZ t]))
4266
4267     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4268
4269     ;; Note "Post" menu is defined in gnus-sum.el for consistency
4270
4271     (gnus-run-hooks 'gnus-article-menu-hook)))
4272
4273 (defun gnus-article-mode ()
4274   "Major mode for displaying an article.
4275
4276 All normal editing commands are switched off.
4277
4278 The following commands are available in addition to all summary mode
4279 commands:
4280 \\<gnus-article-mode-map>
4281 \\[gnus-article-next-page]\t Scroll the article one page forwards
4282 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4283 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4284 \\[gnus-article-show-summary]\t Display the summary buffer
4285 \\[gnus-article-mail]\t Send a reply to the address near point
4286 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4287 \\[gnus-info-find-node]\t Go to the Gnus info node"
4288   (interactive)
4289   (kill-all-local-variables)
4290   (gnus-simplify-mode-line)
4291   (setq mode-name "Article")
4292   (setq major-mode 'gnus-article-mode)
4293   (make-local-variable 'minor-mode-alist)
4294   (use-local-map gnus-article-mode-map)
4295   (when (gnus-visual-p 'article-menu 'menu)
4296     (gnus-article-make-menu-bar)
4297     (when gnus-summary-tool-bar-map
4298       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4299   (gnus-update-format-specifications nil 'article-mode)
4300   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4301   (set (make-local-variable 'gnus-page-broken) nil)
4302   (make-local-variable 'gnus-button-marker-list)
4303   (make-local-variable 'gnus-article-current-summary)
4304   (make-local-variable 'gnus-article-mime-handles)
4305   (make-local-variable 'gnus-article-decoded-p)
4306   (make-local-variable 'gnus-article-mime-handle-alist)
4307   (make-local-variable 'gnus-article-wash-types)
4308   (make-local-variable 'gnus-article-image-alist)
4309   (make-local-variable 'gnus-article-charset)
4310   (make-local-variable 'gnus-article-ignored-charsets)
4311   ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4312   ;; face.
4313   (set (make-local-variable 'nobreak-char-display) nil)
4314   (setq cursor-in-non-selected-windows nil)
4315   (setq truncate-lines gnus-article-truncate-lines)
4316   (gnus-set-default-directory)
4317   (buffer-disable-undo)
4318   (setq buffer-read-only t
4319         show-trailing-whitespace nil)
4320   (set-syntax-table gnus-article-mode-syntax-table)
4321   (mm-enable-multibyte)
4322   (gnus-run-mode-hooks 'gnus-article-mode-hook))
4323
4324 (defvar gnus-button-marker-list nil
4325   "Regexp matching any of the regexps from `gnus-button-alist'.
4326 Internal variable.")
4327
4328 (defun gnus-article-setup-buffer ()
4329   "Initialize the article buffer."
4330   (let* ((name (if gnus-single-article-buffer "*Article*"
4331                  (concat "*Article " gnus-newsgroup-name "*")))
4332          (original
4333           (progn (string-match "\\*Article" name)
4334                  (concat " *Original Article"
4335                          (substring name (match-end 0))))))
4336     (setq gnus-article-buffer name)
4337     (setq gnus-original-article-buffer original)
4338     (setq gnus-article-mime-handle-alist nil)
4339     (with-current-buffer gnus-summary-buffer
4340       ;; This might be a variable local to the summary buffer.
4341       (unless gnus-single-article-buffer
4342         (setq gnus-article-buffer name)
4343         (setq gnus-original-article-buffer original)
4344         (gnus-set-global-variables)))
4345     (gnus-article-setup-highlight-words)
4346     ;; Init original article buffer.
4347     (save-excursion
4348       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4349       (mm-enable-multibyte)
4350       (setq major-mode 'gnus-original-article-mode)
4351       (make-local-variable 'gnus-original-article))
4352     (if (and (get-buffer name)
4353              (with-current-buffer name
4354                (if gnus-article-edit-mode
4355                    (if (y-or-n-p "Article mode edit in progress; discard? ")
4356                        (progn
4357                          (set-buffer-modified-p nil)
4358                          (gnus-kill-buffer name)
4359                          (message "")
4360                          nil)
4361                      (error "Action aborted"))
4362                  t)))
4363         (save-excursion
4364           (set-buffer name)
4365           (set (make-local-variable 'gnus-article-edit-mode) nil)
4366           (when gnus-article-mime-handles
4367             (mm-destroy-parts gnus-article-mime-handles)
4368             (setq gnus-article-mime-handles nil))
4369           ;; Set it to nil in article-buffer!
4370           (setq gnus-article-mime-handle-alist nil)
4371           (buffer-disable-undo)
4372           (setq buffer-read-only t)
4373           ;; This list just keeps growing if we don't reset it.
4374           (setq gnus-button-marker-list nil)
4375           (unless (eq major-mode 'gnus-article-mode)
4376             (gnus-article-mode))
4377           (current-buffer))
4378       (save-excursion
4379         (set-buffer (gnus-get-buffer-create name))
4380         (gnus-article-mode)
4381         (make-local-variable 'gnus-summary-buffer)
4382         (setq gnus-summary-buffer
4383               (gnus-summary-buffer-name gnus-newsgroup-name))
4384         (gnus-summary-set-local-parameters gnus-newsgroup-name)
4385         (current-buffer)))))
4386
4387 ;; Set article window start at LINE, where LINE is the number of lines
4388 ;; from the head of the article.
4389 (defun gnus-article-set-window-start (&optional line)
4390   (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4391     (when article-window
4392       (set-window-start
4393        article-window
4394        (save-excursion
4395          (set-buffer gnus-article-buffer)
4396          (goto-char (point-min))
4397          (if (not line)
4398              (point-min)
4399            (gnus-message 6 "Moved to bookmark")
4400            (search-forward "\n\n" nil t)
4401            (forward-line line)
4402            (point)))))))
4403
4404 (defun gnus-article-prepare (article &optional all-headers header)
4405   "Prepare ARTICLE in article mode buffer.
4406 ARTICLE should either be an article number or a Message-ID.
4407 If ARTICLE is an id, HEADER should be the article headers.
4408 If ALL-HEADERS is non-nil, no headers are hidden."
4409   (save-excursion
4410     ;; Make sure we start in a summary buffer.
4411     (unless (eq major-mode 'gnus-summary-mode)
4412       (set-buffer gnus-summary-buffer))
4413     (setq gnus-summary-buffer (current-buffer))
4414     (let* ((gnus-article (if header (mail-header-number header) article))
4415            (summary-buffer (current-buffer))
4416            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4417            (group gnus-newsgroup-name)
4418            result)
4419       (save-excursion
4420         (gnus-article-setup-buffer)
4421         (set-buffer gnus-article-buffer)
4422         ;; Deactivate active regions.
4423         (when (and (boundp 'transient-mark-mode)
4424                    transient-mark-mode)
4425           (setq mark-active nil))
4426         (if (not (setq result (let ((inhibit-read-only t))
4427                                 (gnus-request-article-this-buffer
4428                                  article group))))
4429             ;; There is no such article.
4430             (save-excursion
4431               (when (and (numberp article)
4432                          (not (memq article gnus-newsgroup-sparse)))
4433                 (setq gnus-article-current
4434                       (cons gnus-newsgroup-name article))
4435                 (set-buffer gnus-summary-buffer)
4436                 (setq gnus-current-article article)
4437                 (if (and (memq article gnus-newsgroup-undownloaded)
4438                          (not (gnus-online (gnus-find-method-for-group
4439                                             gnus-newsgroup-name))))
4440                     (progn
4441                       (gnus-summary-set-agent-mark article)
4442                       (message "Message marked for downloading"))
4443                   (gnus-summary-mark-article article gnus-canceled-mark)
4444                   (unless (memq article gnus-newsgroup-sparse)
4445                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4446           (if (or (eq result 'pseudo)
4447                   (eq result 'nneething))
4448               (progn
4449                 (save-excursion
4450                   (set-buffer summary-buffer)
4451                   (push article gnus-newsgroup-history)
4452                   (setq gnus-last-article gnus-current-article
4453                         gnus-current-article 0
4454                         gnus-current-headers nil
4455                         gnus-article-current nil)
4456                   (if (eq result 'nneething)
4457                       (gnus-configure-windows 'summary)
4458                     (gnus-configure-windows 'article))
4459                   (gnus-set-global-variables))
4460                 (let ((gnus-article-mime-handle-alist-1
4461                        gnus-article-mime-handle-alist))
4462                   (gnus-set-mode-line 'article)))
4463             ;; The result from the `request' was an actual article -
4464             ;; or at least some text that is now displayed in the
4465             ;; article buffer.
4466             (when (and (numberp article)
4467                        (not (eq article gnus-current-article)))
4468               ;; Seems like a new article has been selected.
4469               ;; `gnus-current-article' must be an article number.
4470               (save-excursion
4471                 (set-buffer summary-buffer)
4472                 (push article gnus-newsgroup-history)
4473                 (setq gnus-last-article gnus-current-article
4474                       gnus-current-article article
4475                       gnus-current-headers
4476                       (gnus-summary-article-header gnus-current-article)
4477                       gnus-article-current
4478                       (cons gnus-newsgroup-name gnus-current-article))
4479                 (unless (vectorp gnus-current-headers)
4480                   (setq gnus-current-headers nil))
4481                 (gnus-summary-goto-subject gnus-current-article)
4482                 (when (gnus-summary-show-thread)
4483                   ;; If the summary buffer really was folded, the
4484                   ;; previous goto may not actually have gone to
4485                   ;; the right article, but the thread root instead.
4486                   ;; So we go again.
4487                   (gnus-summary-goto-subject gnus-current-article))
4488                 (gnus-run-hooks 'gnus-mark-article-hook)
4489                 (gnus-set-mode-line 'summary)
4490                 (when (gnus-visual-p 'article-highlight 'highlight)
4491                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4492                 ;; Set the global newsgroup variables here.
4493                 (gnus-set-global-variables)
4494                 (setq gnus-have-all-headers
4495                       (or all-headers gnus-show-all-headers))))
4496             (save-excursion
4497               (gnus-configure-windows 'article))
4498             (when (or (numberp article)
4499                       (stringp article))
4500               (gnus-article-prepare-display)
4501               ;; Do page break.
4502               (goto-char (point-min))
4503               (when gnus-break-pages
4504                 (gnus-narrow-to-page)))
4505             (let ((gnus-article-mime-handle-alist-1
4506                    gnus-article-mime-handle-alist))
4507               (gnus-set-mode-line 'article))
4508             (article-goto-body)
4509             (unless (bobp)
4510               (forward-line -1))
4511             (set-window-point (get-buffer-window (current-buffer)) (point))
4512             (gnus-configure-windows 'article)
4513             t))))))
4514
4515 ;;;###autoload
4516 (defun gnus-article-prepare-display ()
4517   "Make the current buffer look like a nice article."
4518   ;; Hooks for getting information from the article.
4519   ;; This hook must be called before being narrowed.
4520   (let ((gnus-article-buffer (current-buffer))
4521         buffer-read-only
4522         (inhibit-read-only t))
4523     (unless (eq major-mode 'gnus-article-mode)
4524       (gnus-article-mode))
4525     (setq buffer-read-only nil
4526           gnus-article-wash-types nil
4527           gnus-article-image-alist nil)
4528     (gnus-run-hooks 'gnus-tmp-internal-hook)
4529     (when gnus-display-mime-function
4530       (funcall gnus-display-mime-function))
4531     (gnus-run-hooks 'gnus-article-prepare-hook)))
4532
4533 ;;;
4534 ;;; Gnus Sticky Article Mode
4535 ;;;
4536
4537 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4538   "Mode for sticky articles."
4539   ;; Release bindings that won't work.
4540   (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4541                              gnus-sticky-article-mode-map)
4542   (substitute-key-definition 'gnus-article-refer-article 'undefined
4543                              gnus-sticky-article-mode-map)
4544   (dolist (k '("e" "h" "s" "F" "R"))
4545     (define-key gnus-sticky-article-mode-map k nil))
4546   (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4547   (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4548   (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4549   (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4550
4551 (defun gnus-sticky-article (arg)
4552   "Make the current article sticky.
4553 If a prefix ARG is given, ask for a name for this sticky article buffer."
4554   (interactive "P")
4555   (gnus-summary-show-thread)
4556   (gnus-summary-select-article nil nil 'pseudo)
4557   (let (new-art-buf-name)
4558     (gnus-eval-in-buffer-window gnus-article-buffer
4559       (setq new-art-buf-name
4560             (concat
4561              "*Sticky Article: "
4562              (if arg
4563                  (read-from-minibuffer "Sticky article buffer name: ")
4564                (gnus-with-article-headers
4565                  (gnus-article-goto-header "subject")
4566                  (setq new-art-buf-name
4567                        (buffer-substring-no-properties
4568                         (line-beginning-position) (line-end-position)))
4569                  (goto-char (point-min))
4570                  (gnus-article-goto-header "from")
4571                  (setq new-art-buf-name
4572                        (concat
4573                         new-art-buf-name ", "
4574                         (buffer-substring-no-properties
4575                          (line-beginning-position) (line-end-position))))
4576                  (goto-char (point-min))
4577                  (gnus-article-goto-header "date")
4578                  (setq new-art-buf-name
4579                        (concat
4580                         new-art-buf-name ", "
4581                         (buffer-substring-no-properties
4582                          (line-beginning-position) (line-end-position))))))
4583              "*"))
4584       (if (and (gnus-buffer-live-p new-art-buf-name)
4585                (with-current-buffer new-art-buf-name
4586                  (eq major-mode 'gnus-sticky-article-mode)))
4587           (switch-to-buffer new-art-buf-name)
4588         (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4589       (gnus-sticky-article-mode))
4590     (setq gnus-article-buffer new-art-buf-name))
4591   (gnus-summary-recenter)
4592   (gnus-summary-position-point))
4593
4594 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4595   "Kill the given sticky article BUFFER.
4596 If none is given, assume the current buffer and kill it if it has
4597 `gnus-sticky-article-mode'."
4598   (interactive)
4599   (unless buffer
4600     (setq buffer (current-buffer)))
4601   (with-current-buffer buffer
4602     (when (eq major-mode 'gnus-sticky-article-mode)
4603       (gnus-kill-buffer buffer))))
4604
4605 (defun gnus-kill-sticky-article-buffers (arg)
4606   "Kill all sticky article buffers.
4607 If a prefix ARG is given, ask for confirmation."
4608   (interactive "P")
4609   (dolist (buf (gnus-buffers))
4610     (with-current-buffer buf
4611       (when (eq major-mode 'gnus-sticky-article-mode)
4612         (if (not arg)
4613             (gnus-kill-buffer buf)
4614           (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4615             (gnus-kill-buffer buf)))))))
4616
4617 ;;;
4618 ;;; Gnus MIME viewing functions
4619 ;;;
4620
4621 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4622   "Format of the MIME buttons.
4623
4624 Valid specifiers include:
4625 %t  The MIME type
4626 %T  MIME type, along with additional info
4627 %n  The `name' parameter
4628 %d  The description, if any
4629 %l  The length of the encoded part
4630 %p  The part identifier number
4631 %e  Dots if the part isn't displayed
4632
4633 General format specifiers can also be used.  See Info node
4634 `(gnus)Formatting Variables'.")
4635
4636 (defvar gnus-mime-button-line-format-alist
4637   '((?t gnus-tmp-type ?s)
4638     (?T gnus-tmp-type-long ?s)
4639     (?n gnus-tmp-name ?s)
4640     (?d gnus-tmp-description ?s)
4641     (?p gnus-tmp-id ?s)
4642     (?l gnus-tmp-length ?d)
4643     (?e gnus-tmp-dots ?s)))
4644
4645 (defvar gnus-mime-button-commands
4646   '((gnus-article-press-button "\r" "Toggle Display")
4647     (gnus-mime-view-part "v" "View Interactively...")
4648     (gnus-mime-view-part-as-type "t" "View As Type...")
4649     (gnus-mime-view-part-as-charset "C" "View As charset...")
4650     (gnus-mime-save-part "o" "Save...")
4651     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4652     (gnus-mime-replace-part "r" "Replace part")
4653     (gnus-mime-delete-part "d" "Delete part")
4654     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4655     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4656     (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4657     (gnus-mime-view-part-externally "e" "View Externally")
4658     (gnus-mime-print-part "p" "Print")
4659     (gnus-mime-pipe-part "|" "Pipe To Command...")
4660     (gnus-mime-action-on-part "." "Take action on the part...")))
4661
4662 (defun gnus-article-mime-part-status ()
4663   (if gnus-article-mime-handle-alist-1
4664       (if (eq 1 (length gnus-article-mime-handle-alist-1))
4665           " (1 part)"
4666         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4667     ""))
4668
4669 (defvar gnus-mime-button-map
4670   (let ((map (make-sparse-keymap)))
4671     (define-key map gnus-mouse-2 'gnus-article-push-button)
4672     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4673     (dolist (c gnus-mime-button-commands)
4674       (define-key map (cadr c) (car c)))
4675     map))
4676
4677 (easy-menu-define
4678   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4679   `("MIME Part"
4680     ,@(mapcar (lambda (c)
4681                 (vector (caddr c) (car c) :active t))
4682               gnus-mime-button-commands)))
4683
4684 (defun gnus-mime-button-menu (event prefix)
4685  "Construct a context-sensitive menu of MIME commands."
4686  (interactive "e\nP")
4687  (save-window-excursion
4688    (let ((pos (event-start event)))
4689      (select-window (posn-window pos))
4690      (goto-char (posn-point pos))
4691      (gnus-article-check-buffer)
4692      (popup-menu gnus-mime-button-menu nil prefix))))
4693
4694 (defun gnus-mime-view-all-parts (&optional handles)
4695   "View all the MIME parts."
4696   (interactive)
4697   (with-current-buffer gnus-article-buffer
4698     (let ((handles (or handles gnus-article-mime-handles))
4699           (mail-parse-charset gnus-newsgroup-charset)
4700           (mail-parse-ignored-charsets
4701            (with-current-buffer gnus-summary-buffer
4702              gnus-newsgroup-ignored-charsets)))
4703       (when handles
4704         (mm-remove-parts handles)
4705         (goto-char (point-min))
4706         (or (search-forward "\n\n") (goto-char (point-max)))
4707         (let ((inhibit-read-only t))
4708           (delete-region (point) (point-max))
4709           (mm-display-parts handles))))))
4710
4711 (defun gnus-article-jump-to-part (n)
4712   "Jump to MIME part N."
4713   (interactive "P")
4714   (pop-to-buffer gnus-article-buffer)
4715   ;; FIXME: why is it necessary?
4716   (sit-for 0)
4717   (let ((parts (length gnus-article-mime-handle-alist)))
4718     (or n (setq n
4719                 (string-to-number
4720                  (read-string ;; Emacs 21 doesn't have `read-number'.
4721                   (format "Jump to part (2..%s): " parts)))))
4722     (unless (and (integerp n) (<= n parts) (>= n 1))
4723       (setq n
4724             (progn
4725               (gnus-message 7 "Invalid part `%s', using %s instead."
4726                             n parts)
4727               parts)))
4728     (gnus-message 9 "Jumping to part %s." n)
4729     (cond ((>= gnus-auto-select-part 1)
4730            (while (and (<= n parts)
4731                        (not (gnus-article-goto-part n)))
4732              (setq n (1+ n))))
4733           ((< gnus-auto-select-part 0)
4734            (while (and (>= n 1)
4735                        (not (gnus-article-goto-part n)))
4736              (setq n (1- n))))
4737           (t
4738            (gnus-article-goto-part n)))))
4739
4740 (eval-when-compile
4741   (defsubst gnus-article-edit-part (handles &optional current-id)
4742     "Edit an article in order to delete a mime part.
4743 This function is exclusively used by `gnus-mime-save-part-and-strip'
4744 and `gnus-mime-delete-part', and not provided at run-time normally."
4745     (gnus-article-edit-article
4746      `(lambda ()
4747         (buffer-disable-undo)
4748         (erase-buffer)
4749         (let ((mail-parse-charset (or gnus-article-charset
4750                                       ',gnus-newsgroup-charset))
4751               (mail-parse-ignored-charsets
4752                (or gnus-article-ignored-charsets
4753                    ',gnus-newsgroup-ignored-charsets))
4754               (mbl mml-buffer-list))
4755           (setq mml-buffer-list nil)
4756           (insert-buffer-substring gnus-original-article-buffer)
4757           (mime-to-mml ',handles)
4758           (setq gnus-article-mime-handles nil)
4759           (let ((mbl1 mml-buffer-list))
4760             (setq mml-buffer-list mbl)
4761             (set (make-local-variable 'mml-buffer-list) mbl1))
4762           (gnus-make-local-hook 'kill-buffer-hook)
4763           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4764      `(lambda (no-highlight)
4765         (let ((mail-parse-charset (or gnus-article-charset
4766                                       ',gnus-newsgroup-charset))
4767               (message-options message-options)
4768               (message-options-set-recipient)
4769               (mail-parse-ignored-charsets
4770                (or gnus-article-ignored-charsets
4771                    ',gnus-newsgroup-ignored-charsets)))
4772           (mml-to-mime)
4773           (mml-destroy-buffers)
4774           (remove-hook 'kill-buffer-hook
4775                        'mml-destroy-buffers t)
4776           (kill-local-variable 'mml-buffer-list))
4777         (gnus-summary-edit-article-done
4778          ,(or (mail-header-references gnus-current-headers) "")
4779          ,(gnus-group-read-only-p)
4780          ,gnus-summary-buffer no-highlight))
4781      t)
4782     (gnus-article-edit-done)
4783     (gnus-summary-expand-window)
4784     (gnus-summary-show-article)
4785     (when (and current-id (integerp gnus-auto-select-part))
4786       (gnus-article-jump-to-part
4787        (if (text-property-any (point-min) (point-max)
4788                               'gnus-part (+ current-id gnus-auto-select-part))
4789            (+ current-id gnus-auto-select-part)
4790          (with-current-buffer gnus-article-buffer
4791            (length gnus-article-mime-handle-alist)))))))
4792
4793 (defun gnus-mime-replace-part (file)
4794   "Replace MIME part under point with an external body."
4795   ;; Useful if file has already been saved to disk
4796   (interactive
4797    (list
4798     (mm-with-multibyte
4799       (read-file-name "Replace MIME part with file: "
4800                       (or mm-default-directory default-directory)
4801                       nil nil))))
4802   (gnus-mime-save-part-and-strip file))
4803
4804 (defun gnus-mime-save-part-and-strip (&optional file)
4805   "Save the MIME part under point then replace it with an external body.
4806 If FILE is given, use it for the external part."
4807   (interactive)
4808   (gnus-article-check-buffer)
4809   (when (gnus-group-read-only-p)
4810     (error "The current group does not support deleting of parts"))
4811   (when (mm-complicated-handles gnus-article-mime-handles)
4812     (error "\
4813 The current article has a complicated MIME structure, giving up..."))
4814   (let* ((data (get-text-property (point) 'gnus-data))
4815          (id (get-text-property (point) 'gnus-part))
4816          param
4817          (handles gnus-article-mime-handles))
4818     (unless file
4819       (setq file
4820             (and data (mm-save-part data "Delete MIME part and save to: "))))
4821     (when file
4822       (with-current-buffer (mm-handle-buffer data)
4823         (erase-buffer)
4824         (insert "Content-Type: " (mm-handle-media-type data))
4825         (mml-insert-parameter-string (cdr (mm-handle-type data))
4826                                      '(charset))
4827         ;; Add a filename for the sake of saving the part again.
4828         (mml-insert-parameter
4829          (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4830         (insert "\n")
4831         (insert "Content-ID: " (message-make-message-id) "\n")
4832         (insert "Content-Transfer-Encoding: binary\n")
4833         (insert "\n"))
4834       (setcdr data
4835               (cdr (mm-make-handle nil
4836                                    `("message/external-body"
4837                                      (access-type . "LOCAL-FILE")
4838                                      (name . ,file)))))
4839       ;; (set-buffer gnus-summary-buffer)
4840       (gnus-article-edit-part handles id))))
4841
4842 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4843 ;; parts...>') but with stripping would be nice.
4844
4845 (defun gnus-mime-delete-part ()
4846   "Delete the MIME part under point.
4847 Replace it with some information about the removed part."
4848   (interactive)
4849   (gnus-article-check-buffer)
4850   (when (gnus-group-read-only-p)
4851     (error "The current group does not support deleting of parts"))
4852   (when (mm-complicated-handles gnus-article-mime-handles)
4853     (error "\
4854 The current article has a complicated MIME structure, giving up..."))
4855   (when (or gnus-expert-user
4856             (gnus-yes-or-no-p "\
4857 Deleting parts may malfunction or destroy the article; continue? "))
4858     (let* ((data (get-text-property (point) 'gnus-data))
4859            (id (get-text-property (point) 'gnus-part))
4860            (handles gnus-article-mime-handles)
4861            (none "(none)")
4862            (description
4863             (let ((desc (mm-handle-description data)))
4864               (when desc
4865                 (mail-decode-encoded-word-string desc))))
4866            (filename
4867             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4868                 none))
4869            (type (mm-handle-media-type data)))
4870       (unless data
4871         (error "No MIME part under point"))
4872       (with-current-buffer (mm-handle-buffer data)
4873         (let ((bsize (format "%s" (buffer-size))))
4874           (erase-buffer)
4875           (insert
4876            (concat
4877             ",----\n"
4878             "| The following attachment has been deleted:\n"
4879             "|\n"
4880             "| Type:           " type "\n"
4881             "| Filename:       " filename "\n"
4882             "| Size (encoded): " bsize " Byte\n"
4883             (when description
4884               (concat    "| Description:    " description "\n"))
4885             "`----\n"))
4886           (setcdr data
4887                   (cdr (mm-make-handle
4888                         nil `("text/plain") nil nil
4889                         (list "attachment")
4890                         (format "Deleted attachment (%s bytes)" bsize))))))
4891       ;; (set-buffer gnus-summary-buffer)
4892       (gnus-article-edit-part handles id))))
4893
4894 (defun gnus-mime-save-part ()
4895   "Save the MIME part under point."
4896   (interactive)
4897   (gnus-article-check-buffer)
4898   (let ((data (get-text-property (point) 'gnus-data)))
4899     (when data
4900       (mm-save-part data))))
4901
4902 (defun gnus-mime-pipe-part ()
4903   "Pipe the MIME part under point to a process."
4904   (interactive)
4905   (gnus-article-check-buffer)
4906   (let ((data (get-text-property (point) 'gnus-data)))
4907     (when data
4908       (mm-pipe-part data))))
4909
4910 (defun gnus-mime-view-part ()
4911   "Interactively choose a viewing method for the MIME part under point."
4912   (interactive)
4913   (gnus-article-check-buffer)
4914   (let ((data (get-text-property (point) 'gnus-data)))
4915     (when data
4916       (setq gnus-article-mime-handles
4917             (mm-merge-handles
4918              gnus-article-mime-handles (setq data (copy-sequence data))))
4919       (mm-interactively-view-part data))))
4920
4921 (defun gnus-mime-view-part-as-type-internal ()
4922   (gnus-article-check-buffer)
4923   (let* ((handle (get-text-property (point) 'gnus-data))
4924          (name (or
4925                 ;; Content-Type: foo/bar; name=...
4926                 (mail-content-type-get (mm-handle-type handle) 'name)
4927                 ;; Content-Disposition: attachment; filename=...
4928                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4929          (def-type (and name (mm-default-file-encoding name))))
4930     (or (and def-type (cons def-type 0))
4931         (and handle
4932              (equal (mm-handle-media-supertype handle) "text")
4933              '("text/plain" . 0))
4934         '("application/octet-stream" . 0))))
4935
4936 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4937   "Choose a MIME media type, and view the part as such.
4938 If non-nil, PRED is a predicate to use during completion to limit the
4939 available media-types."
4940   (interactive)
4941   (unless mime-type
4942     (setq mime-type
4943           (let ((default (gnus-mime-view-part-as-type-internal)))
4944             (completing-read
4945              (format "View as MIME type (default %s): "
4946                      (car default))
4947              (mapcar #'list (mailcap-mime-types))
4948              pred nil nil nil
4949              (car default)))))
4950   (gnus-article-check-buffer)
4951   (let ((handle (get-text-property (point) 'gnus-data)))
4952     (when handle
4953       (when (equal (mm-handle-media-type handle) "message/external-body")
4954         (unless (mm-handle-cache handle)
4955           (mm-extern-cache-contents handle))
4956         (setq handle (mm-handle-cache handle)))
4957       (setq handle
4958             (mm-make-handle (mm-handle-buffer handle)
4959                             (cons mime-type (cdr (mm-handle-type handle)))
4960                             (mm-handle-encoding handle)
4961                             (mm-handle-undisplayer handle)
4962                             (mm-handle-disposition handle)
4963                             (mm-handle-description handle)
4964                             nil
4965                             (mm-handle-id handle)))
4966       (setq gnus-article-mime-handles
4967             (mm-merge-handles gnus-article-mime-handles handle))
4968       (when (mm-handle-displayed-p handle)
4969         (mm-remove-part handle))
4970       (gnus-mm-display-part handle))))
4971
4972 (defun gnus-mime-copy-part (&optional handle arg)
4973   "Put the MIME part under point into a new buffer.
4974 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4975 are decompressed."
4976   (interactive (list nil current-prefix-arg))
4977   (gnus-article-check-buffer)
4978   (unless handle
4979     (setq handle (get-text-property (point) 'gnus-data)))
4980   (when handle
4981     (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4982                                                'name)
4983                         (mail-content-type-get (mm-handle-disposition handle)
4984                                                'filename)))
4985           contents dont-decode charset coding-system)
4986       (mm-with-unibyte-buffer
4987         (mm-insert-part handle)
4988         (setq contents (or (condition-case nil
4989                                (mm-decompress-buffer filename nil 'sig)
4990                              (error
4991                               (setq dont-decode t)
4992                               nil))
4993                            (buffer-string))))
4994       (setq filename (cond (filename (file-name-nondirectory filename))
4995                            (dont-decode "*raw data*")
4996                            (t "*decoded*")))
4997       (cond
4998        (dont-decode)
4999        ((not arg)
5000         (unless (setq charset (mail-content-type-get
5001                                (mm-handle-type handle) 'charset))
5002           (unless (setq coding-system (mm-with-unibyte-buffer
5003                                         (insert contents)
5004                                         (mm-find-buffer-file-coding-system)))
5005             (setq charset gnus-newsgroup-charset))))
5006        ((numberp arg)
5007         (setq charset (or (cdr (assq arg
5008                                      gnus-summary-show-article-charset-alist))
5009                           (mm-read-coding-system "Charset: ")))))
5010       (switch-to-buffer (generate-new-buffer filename))
5011       (if (or coding-system
5012               (and charset
5013                    (setq coding-system (mm-charset-to-coding-system charset))
5014                    (not (eq charset 'ascii))))
5015           (progn
5016             (mm-enable-multibyte)
5017             (insert (mm-decode-coding-string contents coding-system))
5018             (setq buffer-file-coding-system
5019                   (if (boundp 'last-coding-system-used)
5020                       (symbol-value 'last-coding-system-used)
5021                     coding-system)))
5022         (mm-disable-multibyte)
5023         (insert contents)
5024         (setq buffer-file-coding-system mm-binary-coding-system))
5025       ;; We do it this way to make `normal-mode' set the appropriate mode.
5026       (unwind-protect
5027           (progn
5028             (setq buffer-file-name (expand-file-name filename))
5029             (normal-mode))
5030         (setq buffer-file-name nil))
5031       (goto-char (point-min)))))
5032
5033 (defun gnus-mime-print-part (&optional handle filename)
5034   "Print the MIME part under point."
5035   (interactive (list nil (ps-print-preprint current-prefix-arg)))
5036   (gnus-article-check-buffer)
5037   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5038          (contents (and handle (mm-get-part handle)))
5039          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5040          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5041     (when contents
5042         (if printer
5043             (unwind-protect
5044                 (progn
5045                   (mm-save-part-to-file handle file)
5046                   (call-process shell-file-name nil
5047                                 (generate-new-buffer " *mm*")
5048                                 nil
5049                                 shell-command-switch
5050                                 (mm-mailcap-command
5051                                  printer file (mm-handle-type handle))))
5052               (delete-file file))
5053           (with-temp-buffer
5054             (insert contents)
5055             (gnus-print-buffer))
5056           (ps-despool filename)))))
5057
5058 (defun gnus-mime-inline-part (&optional handle arg)
5059   "Insert the MIME part under point into the current buffer.
5060 Compressed files like .gz and .bz2 are decompressed."
5061   (interactive (list nil current-prefix-arg))
5062   (gnus-article-check-buffer)
5063   (unless handle
5064     (setq handle (get-text-property (point) 'gnus-data)))
5065   (when handle
5066     (let ((b (point))
5067           (inhibit-read-only t)
5068           contents charset coding-system)
5069       (if (and (not arg) (mm-handle-undisplayer handle))
5070           (mm-remove-part handle)
5071         (mm-with-unibyte-buffer
5072           (mm-insert-part handle)
5073           (setq contents
5074                 (or (mm-decompress-buffer
5075                      (or (mail-content-type-get (mm-handle-type handle)
5076                                                 'name)
5077                          (mail-content-type-get (mm-handle-disposition handle)
5078                                                 'filename))
5079                      nil t)
5080                     (buffer-string))))
5081         (cond
5082          ((not arg)
5083           (unless (setq charset (mail-content-type-get
5084                                  (mm-handle-type handle) 'charset))
5085             (unless (setq coding-system
5086                           (mm-with-unibyte-buffer
5087                             (insert contents)
5088                             (mm-find-buffer-file-coding-system)))
5089               (setq charset gnus-newsgroup-charset))))
5090          ((numberp arg)
5091           (if (mm-handle-undisplayer handle)
5092               (mm-remove-part handle))
5093           (setq charset
5094                 (or (cdr (assq arg
5095                                gnus-summary-show-article-charset-alist))
5096                     (mm-read-coding-system "Charset: "))))
5097          (t
5098           (if (mm-handle-undisplayer handle)
5099               (mm-remove-part handle))))
5100         (forward-line 2)
5101         (mm-insert-inline
5102          handle
5103          (if (or coding-system
5104                  (and charset
5105                       (setq coding-system
5106                             (mm-charset-to-coding-system charset))
5107                       (not (eq coding-system 'ascii))))
5108              (mm-decode-coding-string contents coding-system)
5109            (mm-string-to-multibyte contents)))
5110         (goto-char b)))))
5111
5112 (defun gnus-mime-strip-charset-parameters (handle)
5113   "Strip charset parameters from HANDLE."
5114   (if (stringp (car handle))
5115       (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
5116     (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5117                                             "message/external-body")
5118                                      (progn
5119                                        (unless (mm-handle-cache handle)
5120                                          (mm-extern-cache-contents handle))
5121                                        (mm-handle-cache handle))
5122                                    handle)))
5123            (charset (assq 'charset (cdr type))))
5124       (when charset
5125         (delq charset type)))))
5126
5127 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5128   "Insert the MIME part under point into the current buffer using the
5129 specified charset."
5130   (interactive (list nil current-prefix-arg))
5131   (gnus-article-check-buffer)
5132   (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5133         (fun (get-text-property (point) 'gnus-callback))
5134         (gnus-newsgroup-ignored-charsets 'gnus-all)
5135         gnus-newsgroup-charset form preferred parts)
5136     (when handle
5137       (when (prog1
5138                 (and fun
5139                      (setq gnus-newsgroup-charset
5140                            (or (cdr (assq
5141                                      arg
5142                                      gnus-summary-show-article-charset-alist))
5143                                (mm-read-coding-system "Charset: "))))
5144               (if (mm-handle-undisplayer handle)
5145                   (mm-remove-part handle)))
5146         (gnus-mime-strip-charset-parameters handle)
5147         (when (and (consp (setq form (cdr-safe fun)))
5148                    (setq form (ignore-errors
5149                                 (assq 'gnus-mime-display-alternative form)))
5150                    (setq preferred (caddr form))
5151                    (progn
5152                      (when (eq (car preferred) 'quote)
5153                        (setq preferred (cadr preferred)))
5154                      (not (equal preferred
5155                                  (get-text-property (point) 'gnus-data))))
5156                    (setq parts (get-text-property (point) 'gnus-part))
5157                    (setq parts (cdr (assq parts
5158                                           gnus-article-mime-handle-alist)))
5159                    (equal (mm-handle-media-type parts) "multipart/alternative")
5160                    (setq parts (reverse (cdr parts))))
5161           (setcar (cddr form)
5162                   (list 'quote (or (cadr (member preferred parts))
5163                                    (car parts)))))
5164         (funcall fun handle)))))
5165
5166 (defun gnus-mime-view-part-externally (&optional handle)
5167   "View the MIME part under point with an external viewer."
5168   (interactive)
5169   (gnus-article-check-buffer)
5170   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5171          (mm-user-display-methods nil)
5172          (mm-inlined-types nil)
5173          (mail-parse-charset gnus-newsgroup-charset)
5174          (mail-parse-ignored-charsets
5175           (with-current-buffer gnus-summary-buffer
5176             gnus-newsgroup-ignored-charsets))
5177          (type (mm-handle-media-type handle))
5178          (method (mailcap-mime-info type))
5179          (mm-enable-external t))
5180     (if (not (stringp method))
5181         (gnus-mime-view-part-as-type
5182          nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5183       (when handle
5184         (if (mm-handle-undisplayer handle)
5185             (mm-remove-part handle)
5186           (mm-display-part handle))))))
5187
5188 (defun gnus-mime-view-part-internally (&optional handle)
5189   "View the MIME part under point with an internal viewer.
5190 If no internal viewer is available, use an external viewer."
5191   (interactive)
5192   (gnus-article-check-buffer)
5193   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5194          (mm-inlined-types '(".*"))
5195          (mm-inline-large-images t)
5196          (mail-parse-charset gnus-newsgroup-charset)
5197          (mail-parse-ignored-charsets
5198           (with-current-buffer gnus-summary-buffer
5199             gnus-newsgroup-ignored-charsets))
5200          (inhibit-read-only t))
5201     (if (not (mm-inlinable-p handle))
5202         (gnus-mime-view-part-as-type
5203          nil (lambda (types) (mm-inlinable-p handle (car types))))
5204       (when handle
5205         (if (mm-handle-undisplayer handle)
5206             (mm-remove-part handle)
5207           (mm-display-part handle))))))
5208
5209 (defun gnus-mime-action-on-part (&optional action)
5210   "Do something with the MIME attachment at \(point\)."
5211   (interactive
5212    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5213   (gnus-article-check-buffer)
5214   (let ((action-pair (assoc action gnus-mime-action-alist)))
5215     (if action-pair
5216         (funcall (cdr action-pair)))))
5217
5218 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5219   "Call FUNCTION on MIME part N.
5220 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5221 If INTERACTIVE, call FUNCTION interactivly."
5222   (let (window frame)
5223     ;; Check whether the article is displayed.
5224     (unless (and (gnus-buffer-live-p gnus-article-buffer)
5225                  (setq window (get-buffer-window gnus-article-buffer t))
5226                  (frame-visible-p (setq frame (window-frame window))))
5227       (error "No article is displayed"))
5228     (with-current-buffer gnus-article-buffer
5229       ;; Check whether the article displays the right contents.
5230       (unless (with-current-buffer gnus-summary-buffer
5231                 (eq gnus-current-article (gnus-summary-article-number)))
5232         (error "You should select the right article first"))
5233       (if n
5234           (setq n (prefix-numeric-value n))
5235         (let ((pt (point)))
5236           (setq n (or (get-text-property pt 'gnus-part)
5237                       (and (not (bobp))
5238                            (get-text-property (1- pt) 'gnus-part))
5239                       (get-text-property (prog2
5240                                              (forward-line 1)
5241                                              (point)
5242                                            (goto-char pt))
5243                                          'gnus-part)
5244                       (get-text-property
5245                        (or (and (setq pt (previous-single-property-change
5246                                           pt 'gnus-part))
5247                                 (1- pt))
5248                            (next-single-property-change (point) 'gnus-part)
5249                            (point))
5250                        'gnus-part)
5251                       1))))
5252       ;; Check whether the specified part exists.
5253       (when (> n (length gnus-article-mime-handle-alist))
5254         (error "No such part")))
5255     (unless
5256         (progn
5257           ;; To select the window is needed so that the cursor
5258           ;; might be visible on the MIME button.
5259           (select-window (prog1
5260                              window
5261                            (setq window (selected-window))
5262                            ;; Article may be displayed in the other frame.
5263                            (gnus-select-frame-set-input-focus
5264                             (prog1
5265                                 frame
5266                               (setq frame (selected-frame))))))
5267           (when (gnus-article-goto-part n)
5268             ;; We point the cursor and the arrow at the MIME button
5269             ;; when the `function' prompt the user for something.
5270             (let ((cursor-in-non-selected-windows t)
5271                   (overlay-arrow-string "=>")
5272                   (overlay-arrow-position (point-marker)))
5273               (unwind-protect
5274                   (cond
5275                    ((and no-handle interactive)
5276                     (call-interactively function))
5277                    (no-handle
5278                     (funcall function))
5279                    (interactive
5280                     (call-interactively
5281                      function
5282                      (cdr (assq n gnus-article-mime-handle-alist))))
5283                    (t
5284                     (funcall function
5285                              (cdr (assq n gnus-article-mime-handle-alist)))))
5286                 (set-marker overlay-arrow-position nil)
5287                 (unless gnus-auto-select-part
5288                   (gnus-select-frame-set-input-focus frame)
5289                   (select-window window))))
5290             t))
5291       (if gnus-inhibit-mime-unbuttonizing
5292           ;; This is the default though the program shouldn't reach here.
5293           (error "No such part")
5294         ;; The part which doesn't have the MIME button is selected.
5295         ;; So, we display all the buttons and redo it.
5296         (let ((gnus-inhibit-mime-unbuttonizing t))
5297           (gnus-summary-show-article)
5298           (gnus-article-part-wrapper n function no-handle))))))
5299
5300 (defun gnus-article-pipe-part (n)
5301   "Pipe MIME part N, which is the numerical prefix."
5302   (interactive "P")
5303   (gnus-article-part-wrapper n 'mm-pipe-part))
5304
5305 (defun gnus-article-save-part (n)
5306   "Save MIME part N, which is the numerical prefix."
5307   (interactive "P")
5308   (gnus-article-part-wrapper n 'mm-save-part))
5309
5310 (defun gnus-article-interactively-view-part (n)
5311   "View MIME part N interactively, which is the numerical prefix."
5312   (interactive "P")
5313   (gnus-article-part-wrapper n 'mm-interactively-view-part))
5314
5315 (defun gnus-article-copy-part (n)
5316   "Copy MIME part N, which is the numerical prefix."
5317   (interactive "P")
5318   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5319
5320 (defun gnus-article-view-part-as-charset (n)
5321   "View MIME part N using a specified charset.
5322 N is the numerical prefix."
5323   (interactive "P")
5324   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5325
5326 (defun gnus-article-view-part-externally (n)
5327   "View MIME part N externally, which is the numerical prefix."
5328   (interactive "P")
5329   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5330
5331 (defun gnus-article-inline-part (n)
5332   "Inline MIME part N, which is the numerical prefix."
5333   (interactive "P")
5334   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5335
5336 (defun gnus-article-save-part-and-strip (n)
5337   "Save MIME part N and replace it with an external body.
5338 N is the numerical prefix."
5339   (interactive "P")
5340   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5341
5342 (defun gnus-article-replace-part (n)
5343   "Replace MIME part N with an external body.
5344 N is the numerical prefix."
5345   (interactive "P")
5346   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5347
5348 (defun gnus-article-delete-part (n)
5349   "Delete MIME part N and add some information about the removed part.
5350 N is the numerical prefix."
5351   (interactive "P")
5352   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5353
5354 (defun gnus-article-view-part-as-type (n)
5355   "Choose a MIME media type, and view part N as such.
5356 N is the numerical prefix."
5357   (interactive "P")
5358   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5359
5360 (defun gnus-article-mime-match-handle-first (condition)
5361   (if condition
5362       (let (n)
5363         (dolist (ihandle gnus-article-mime-handle-alist)
5364           (if (and (cond
5365                     ((functionp condition)
5366                      (funcall condition (cdr ihandle)))
5367                     ((eq condition 'undisplayed)
5368                      (not (or (mm-handle-undisplayer (cdr ihandle))
5369                               (equal (mm-handle-media-type (cdr ihandle))
5370                                      "multipart/alternative"))))
5371                     ((eq condition 'undisplayed-alternative)
5372                      (not (mm-handle-undisplayer (cdr ihandle))))
5373                     (t t))
5374                    (gnus-article-goto-part (car ihandle))
5375                    (or (not n) (< (car ihandle) n)))
5376               (setq n (car ihandle))))
5377         (or n 1))
5378     1))
5379
5380 (defun gnus-article-view-part (&optional n)
5381   "View MIME part N, which is the numerical prefix."
5382   (interactive "P")
5383   (with-current-buffer gnus-article-buffer
5384     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5385                              gnus-article-mime-match-handle-function)))
5386     (when (> n (length gnus-article-mime-handle-alist))
5387       (error "No such part"))
5388     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5389       (when (gnus-article-goto-part n)
5390         (if (equal (car handle) "multipart/alternative")
5391             (gnus-article-press-button)
5392           (when (eq (gnus-mm-display-part handle) 'internal)
5393             (gnus-set-window-start)))))))
5394
5395 (defsubst gnus-article-mime-total-parts ()
5396   (if (bufferp (car gnus-article-mime-handles))
5397       1 ;; single part
5398     (1- (length gnus-article-mime-handles))))
5399
5400 (defun gnus-mm-display-part (handle)
5401   "Display HANDLE and fix MIME button."
5402   (let ((id (get-text-property (point) 'gnus-part))
5403         (point (point))
5404         (inhibit-read-only t))
5405     (forward-line 1)
5406     (prog1
5407         (let ((window (selected-window))
5408               (mail-parse-charset gnus-newsgroup-charset)
5409               (mail-parse-ignored-charsets
5410                (if (gnus-buffer-live-p gnus-summary-buffer)
5411                    (with-current-buffer gnus-summary-buffer
5412                      gnus-newsgroup-ignored-charsets)
5413                  nil)))
5414           (save-excursion
5415             (unwind-protect
5416                 (let ((win (gnus-get-buffer-window (current-buffer) t))
5417                       (beg (point)))
5418                   (when win
5419                     (select-window win))
5420                   (goto-char point)
5421                   (forward-line)
5422                   (if (mm-handle-displayed-p handle)
5423                       ;; This will remove the part.
5424                       (mm-display-part handle)
5425                     (save-restriction
5426                       (narrow-to-region (point)
5427                                         (if (eobp) (point) (1+ (point))))
5428                       (mm-display-part handle)
5429                       ;; We narrow to the part itself and
5430                       ;; then call the treatment functions.
5431                       (goto-char (point-min))
5432                       (forward-line 1)
5433                       (narrow-to-region (point) (point-max))
5434                       (gnus-treat-article
5435                        nil id
5436                        (gnus-article-mime-total-parts)
5437                        (mm-handle-media-type handle)))))
5438               (if (window-live-p window)
5439                   (select-window window)))))
5440       (goto-char point)
5441       (gnus-delete-line)
5442       (gnus-insert-mime-button
5443        handle id (list (mm-handle-displayed-p handle)))
5444       (goto-char point))))
5445
5446 (defun gnus-article-goto-part (n)
5447   "Go to MIME part N."
5448   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5449
5450 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5451   (let ((gnus-tmp-name
5452          (or (mail-content-type-get (mm-handle-type handle) 'name)
5453              (mail-content-type-get (mm-handle-disposition handle) 'filename)
5454              (mail-content-type-get (mm-handle-type handle) 'url)
5455              ""))
5456         (gnus-tmp-type (mm-handle-media-type handle))
5457         (gnus-tmp-description
5458          (mail-decode-encoded-word-string (or (mm-handle-description handle)
5459                                               "")))
5460         (gnus-tmp-dots
5461          (if (if displayed (car displayed)
5462                (mm-handle-displayed-p handle))
5463              "" "..."))
5464         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5465                            (buffer-size)))
5466         gnus-tmp-type-long b e)
5467     (when (string-match ".*/" gnus-tmp-name)
5468       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5469     (setq gnus-tmp-type-long (concat gnus-tmp-type
5470                                      (and (not (equal gnus-tmp-name ""))
5471                                           (concat "; " gnus-tmp-name))))
5472     (unless (equal gnus-tmp-description "")
5473       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5474     (unless (bolp)
5475       (insert "\n"))
5476     (setq b (point))
5477     (gnus-eval-format
5478      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5479      `(keymap ,gnus-mime-button-map
5480               gnus-callback gnus-mm-display-part
5481               gnus-part ,gnus-tmp-id
5482               article-type annotation
5483               gnus-data ,handle))
5484     (setq e (if (bolp)
5485                 ;; Exclude a newline.
5486                 (1- (point))
5487               (point)))
5488     (when gnus-article-button-face
5489       (gnus-overlay-put (gnus-make-overlay b e nil t)
5490                         'face gnus-article-button-face))
5491     (widget-convert-button
5492      'link b e
5493      :mime-handle handle
5494      :action 'gnus-widget-press-button
5495      :button-keymap gnus-mime-button-map
5496      :help-echo
5497      (lambda (widget/window &optional overlay pos)
5498        ;; Needed to properly clear the message due to a bug in
5499        ;; wid-edit (XEmacs only).
5500        (if (boundp 'help-echo-owns-message)
5501            (setq help-echo-owns-message t))
5502        (format
5503         "%S: %s the MIME part; %S: more options"
5504         (aref gnus-mouse-2 0)
5505         ;; XEmacs will get a single widget arg; Emacs 21 will get
5506         ;; window, overlay, position.
5507         (if (mm-handle-displayed-p
5508              (if overlay
5509                  (with-current-buffer (gnus-overlay-buffer overlay)
5510                    (widget-get (widget-at (gnus-overlay-start overlay))
5511                                :mime-handle))
5512                (widget-get widget/window :mime-handle)))
5513             "hide" "show")
5514         (aref gnus-down-mouse-3 0))))))
5515
5516 (defun gnus-widget-press-button (elems el)
5517   (goto-char (widget-get elems :from))
5518   (gnus-article-press-button))
5519
5520 (defvar gnus-displaying-mime nil)
5521
5522 (defun gnus-display-mime (&optional ihandles)
5523   "Display the MIME parts."
5524   (save-excursion
5525     (save-selected-window
5526       (let ((window (get-buffer-window gnus-article-buffer))
5527             (point (point)))
5528         (when window
5529           (select-window window)
5530           ;; We have to do this since selecting the window
5531           ;; may change the point.  So we set the window point.
5532           (set-window-point window point)))
5533       (let ((handles ihandles)
5534             (inhibit-read-only t)
5535             handle)
5536         (cond (handles)
5537               ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5538                (when gnus-article-emulate-mime
5539                  (mm-uu-dissect-text-parts handles)))
5540               (gnus-article-emulate-mime
5541                (setq handles (mm-uu-dissect))))
5542         (when (and (not ihandles)
5543                    (not gnus-displaying-mime))
5544           ;; Top-level call; we clean up.
5545           (when gnus-article-mime-handles
5546             (mm-destroy-parts gnus-article-mime-handles)
5547             (setq gnus-article-mime-handle-alist nil));; A trick.
5548           (setq gnus-article-mime-handles handles)
5549           ;; We allow users to glean info from the handles.
5550           (when gnus-article-mime-part-function
5551             (gnus-mime-part-function handles)))
5552         (if (and handles
5553                  (or (not (stringp (car handles)))
5554                      (cdr handles)))
5555             (progn
5556               (when (and (not ihandles)
5557                          (not gnus-displaying-mime))
5558                 ;; Clean up for mime parts.
5559                 (article-goto-body)
5560                 (delete-region (point) (point-max)))
5561               (let ((gnus-displaying-mime t))
5562                 (gnus-mime-display-part handles)))
5563           (save-restriction
5564             (article-goto-body)
5565             (narrow-to-region (point) (point-max))
5566             (gnus-treat-article nil 1 1)
5567             (widen)))
5568         (unless ihandles
5569           ;; Highlight the headers.
5570           (save-excursion
5571             (save-restriction
5572               (article-goto-body)
5573               (narrow-to-region (point-min) (point))
5574               (gnus-article-save-original-date
5575                (gnus-treat-article 'head)))))))
5576     ;; Cope with broken MIME messages.
5577     (goto-char (point-max))
5578     (unless (bolp)
5579       (insert "\n"))))
5580
5581 (defcustom gnus-mime-display-multipart-as-mixed nil
5582   "Display \"multipart\" parts as  \"multipart/mixed\".
5583
5584 If t, it overrides nil values of
5585 `gnus-mime-display-multipart-alternative-as-mixed' and
5586 `gnus-mime-display-multipart-related-as-mixed'."
5587   :group 'gnus-article-mime
5588   :type 'boolean)
5589
5590 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5591   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
5592   :version "22.1"
5593   :group 'gnus-article-mime
5594   :type 'boolean)
5595
5596 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5597   "Display \"multipart/related\" parts as  \"multipart/mixed\".
5598
5599 If displaying \"text/html\" is discouraged \(see
5600 `mm-discouraged-alternatives'\) images or other material inside a
5601 \"multipart/related\" part might be overlooked when this variable is nil."
5602   :version "22.1"
5603   :group 'gnus-article-mime
5604   :type 'boolean)
5605
5606 (defun gnus-mime-display-part (handle)
5607   (cond
5608    ;; Maybe a broken MIME message.
5609    ((null handle))
5610    ;; Single part.
5611    ((not (stringp (car handle)))
5612     (gnus-mime-display-single handle))
5613    ;; User-defined multipart
5614    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5615     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5616              handle))
5617    ;; multipart/alternative
5618    ((and (equal (car handle) "multipart/alternative")
5619          (not (or gnus-mime-display-multipart-as-mixed
5620                   gnus-mime-display-multipart-alternative-as-mixed)))
5621     (let ((id (1+ (length gnus-article-mime-handle-alist))))
5622       (push (cons id handle) gnus-article-mime-handle-alist)
5623       (gnus-mime-display-alternative (cdr handle) nil nil id)))
5624    ;; multipart/related
5625    ((and (equal (car handle) "multipart/related")
5626          (not (or gnus-mime-display-multipart-as-mixed
5627                   gnus-mime-display-multipart-related-as-mixed)))
5628     ;;;!!!We should find the start part, but we just default
5629     ;;;!!!to the first part.
5630     ;;(gnus-mime-display-part (cadr handle))
5631     ;;;!!! Most multipart/related is an HTML message plus images.
5632     ;;;!!! Unfortunately we are unable to let W3 display those
5633     ;;;!!! included images, so we just display it as a mixed multipart.
5634     ;;(gnus-mime-display-mixed (cdr handle))
5635     ;;;!!! No, w3 can display everything just fine.
5636     (gnus-mime-display-part (cadr handle)))
5637    ((equal (car handle) "multipart/signed")
5638     (gnus-add-wash-type 'signed)
5639     (gnus-mime-display-security handle))
5640    ((equal (car handle) "multipart/encrypted")
5641     (gnus-add-wash-type 'encrypted)
5642     (gnus-mime-display-security handle))
5643    ;; Other multiparts are handled like multipart/mixed.
5644    (t
5645     (gnus-mime-display-mixed (cdr handle)))))
5646
5647 (defun gnus-mime-part-function (handles)
5648   (if (stringp (car handles))
5649       (mapcar 'gnus-mime-part-function (cdr handles))
5650     (funcall gnus-article-mime-part-function handles)))
5651
5652 (defun gnus-mime-display-mixed (handles)
5653   (mapcar 'gnus-mime-display-part handles))
5654
5655 (defun gnus-mime-display-single (handle)
5656   (let ((type (mm-handle-media-type handle))
5657         (ignored gnus-ignored-mime-types)
5658         (not-attachment t)
5659         (move nil)
5660         display text)
5661     (catch 'ignored
5662       (progn
5663         (while ignored
5664           (when (string-match (pop ignored) type)
5665             (throw 'ignored nil)))
5666         (if (and (setq not-attachment
5667                        (and (not (mm-inline-override-p handle))
5668                             (or (not (mm-handle-disposition handle))
5669                                 (equal (car (mm-handle-disposition handle))
5670                                        "inline")
5671                                 (mm-attachment-override-p handle))))
5672                  (mm-automatic-display-p handle)
5673                  (or (and
5674                       (mm-inlinable-p handle)
5675                       (mm-inlined-p handle))
5676                      (mm-automatic-external-display-p type)))
5677             (setq display t)
5678           (when (equal (mm-handle-media-supertype handle) "text")
5679             (setq text t)))
5680         (let ((id (1+ (length gnus-article-mime-handle-alist)))
5681               beg)
5682           (push (cons id handle) gnus-article-mime-handle-alist)
5683           (when (and display
5684                      (equal (mm-handle-media-supertype handle) "message"))
5685             (insert-char
5686              ?\n
5687              (cond ((not (bolp)) 2)
5688                    ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5689                    (t 1))))
5690           (when (or (not display)
5691                     (not (gnus-unbuttonized-mime-type-p type)))
5692             (gnus-insert-mime-button
5693              handle id (list (or display (and not-attachment text))))
5694             (gnus-article-insert-newline)
5695             ;; Remember modify the number of forward lines.
5696             (setq move t))
5697           (setq beg (point))
5698           (cond
5699            (display
5700             (when move
5701               (forward-line -1)
5702               (setq beg (point)))
5703             (let ((mail-parse-charset gnus-newsgroup-charset)
5704                   (mail-parse-ignored-charsets
5705                    (save-excursion (condition-case ()
5706                                        (set-buffer gnus-summary-buffer)
5707                                      (error))
5708                                    gnus-newsgroup-ignored-charsets)))
5709               (mm-display-part handle t))
5710             (goto-char (point-max)))
5711            ((and text not-attachment)
5712             (when move
5713               (forward-line -1)
5714               (setq beg (point)))
5715             (gnus-article-insert-newline)
5716             (mm-insert-inline
5717              handle
5718              (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5719                                                        'charset)
5720                                 (and (equal type "text/calendar") 'utf-8))))
5721                (cond ((not charset)
5722                       (mm-string-as-multibyte (mm-get-part handle)))
5723                      ((eq charset 'gnus-decoded)
5724                       (with-current-buffer (mm-handle-buffer handle)
5725                         (buffer-string)))
5726                      (t
5727                       (mm-decode-string (mm-get-part handle) charset)))))
5728             (goto-char (point-max))))
5729           ;; Do highlighting.
5730           (save-excursion
5731             (save-restriction
5732               (narrow-to-region beg (point))
5733               (if (eq handle gnus-article-mime-handles)
5734                   ;; The format=flowed case.
5735                   (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5736                 ;; Don't count signature parts that are never displayed.
5737                 ;; The part number should be re-calculated supposing this
5738                 ;; might be a message/rfc822 part.
5739                 (let (handles)
5740                   (dolist (part gnus-article-mime-handles)
5741                     (unless (or (stringp part)
5742                                 (equal (car (mm-handle-type part))
5743                                        "application/pgp-signature"))
5744                       (push part handles)))
5745                   (gnus-treat-article
5746                    nil (length (memq handle handles)) (length handles)
5747                    (mm-handle-media-type handle)))))))))))
5748
5749 (defun gnus-unbuttonized-mime-type-p (type)
5750   "Say whether TYPE is to be unbuttonized."
5751   (unless gnus-inhibit-mime-unbuttonizing
5752     (when (catch 'found
5753             (let ((types gnus-unbuttonized-mime-types))
5754               (while types
5755                 (when (string-match (pop types) type)
5756                   (throw 'found t)))))
5757       (not (catch 'found
5758              (let ((types gnus-buttonized-mime-types))
5759                (while types
5760                  (when (string-match (pop types) type)
5761                    (throw 'found t)))))))))
5762
5763 (defun gnus-article-insert-newline ()
5764   "Insert a newline, but mark it as undeletable."
5765   (gnus-put-text-property
5766    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5767
5768 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5769   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5770          (ihandles handles)
5771          (point (point))
5772          handle (inhibit-read-only t) from props begend not-pref)
5773     (save-window-excursion
5774       (save-restriction
5775         (when ibegend
5776           (narrow-to-region (car ibegend)
5777                             (or (cdr ibegend)
5778                                 (progn
5779                                   (goto-char (car ibegend))
5780                                   (forward-line 2)
5781                                   (point))))
5782           (delete-region (point-min) (point-max))
5783           (mm-remove-parts handles))
5784         (setq begend (list (point-marker)))
5785         ;; Do the toggle.
5786         (unless (setq not-pref (cadr (member preferred ihandles)))
5787           (setq not-pref (car ihandles)))
5788         (when (or ibegend
5789                   (not preferred)
5790                   (not (gnus-unbuttonized-mime-type-p
5791                         "multipart/alternative")))
5792           (gnus-add-text-properties
5793            (setq from (point))
5794            (progn
5795              (insert (format "%d.  " id))
5796              (point))
5797            `(gnus-callback
5798              (lambda (handles)
5799                (unless ,(not ibegend)
5800                  (setq gnus-article-mime-handle-alist
5801                        ',gnus-article-mime-handle-alist))
5802                (gnus-mime-display-alternative
5803                 ',ihandles ',not-pref ',begend ,id))
5804              keymap ,gnus-mime-button-map
5805              ,gnus-mouse-face-prop ,gnus-article-mouse-face
5806              face ,gnus-article-button-face
5807              gnus-part ,id
5808              article-type multipart))
5809           (widget-convert-button 'link from (point)
5810                                  :action 'gnus-widget-press-button
5811                                  :button-keymap gnus-widget-button-keymap)
5812           ;; Do the handles
5813           (while (setq handle (pop handles))
5814             (gnus-add-text-properties
5815              (setq from (point))
5816              (progn
5817                (insert (format "(%c) %-18s"
5818                                (if (equal handle preferred) ?* ? )
5819                                (mm-handle-media-type handle)))
5820                (point))
5821              `(gnus-callback
5822                (lambda (handles)
5823                  (unless ,(not ibegend)
5824                    (setq gnus-article-mime-handle-alist
5825                          ',gnus-article-mime-handle-alist))
5826                  (gnus-mime-display-alternative
5827                   ',ihandles ',handle ',begend ,id))
5828                keymap ,gnus-mime-button-map
5829                ,gnus-mouse-face-prop ,gnus-article-mouse-face
5830                face ,gnus-article-button-face
5831                gnus-part ,id
5832                gnus-data ,handle))
5833             (widget-convert-button 'link from (point)
5834                                    :action 'gnus-widget-press-button
5835                                    :button-keymap gnus-widget-button-keymap)
5836             (insert "  "))
5837           (insert "\n\n"))
5838         (when preferred
5839           (if (stringp (car preferred))
5840               (gnus-display-mime preferred)
5841             (let ((mail-parse-charset gnus-newsgroup-charset)
5842                   (mail-parse-ignored-charsets
5843                    (with-current-buffer gnus-summary-buffer
5844                      gnus-newsgroup-ignored-charsets)))
5845               (mm-display-part preferred)
5846               ;; Do highlighting.
5847               (save-excursion
5848                 (save-restriction
5849                   (narrow-to-region (car begend) (point-max))
5850                   (gnus-treat-article
5851                    nil (length gnus-article-mime-handle-alist)
5852                    (gnus-article-mime-total-parts)
5853                    (mm-handle-media-type handle))))))
5854           (goto-char (point-max))
5855           (setcdr begend (point-marker)))))
5856     (when ibegend
5857       (goto-char point))))
5858
5859 (defconst gnus-article-wash-status-strings
5860   (let ((alist '((cite "c" "Possible hidden citation text"
5861                        " " "All citation text visible")
5862                  (headers "h" "Hidden headers"
5863                           " " "All headers visible.")
5864                  (pgp "p" "Encrypted or signed message status hidden"
5865                       " " "No hidden encryption nor digital signature status")
5866                  (signature "s" "Signature has been hidden"
5867                             " " "Signature is visible")
5868                  (overstrike "o" "Overstrike (^H) characters applied"
5869                              " " "No overstrike characters applied")
5870                  (emphasis "e" "/*_Emphasis_*/ characters applied"
5871                            " " "No /*_emphasis_*/ characters applied")))
5872         result)
5873     (dolist (entry alist result)
5874       (let ((key (nth 0 entry))
5875             (on (copy-sequence (nth 1 entry)))
5876             (on-help (nth 2 entry))
5877             (off (copy-sequence (nth 3 entry)))
5878             (off-help (nth 4 entry)))
5879         (put-text-property 0 1 'help-echo on-help on)
5880         (put-text-property 0 1 'help-echo off-help off)
5881         (push (list key on off) result))))
5882   "Alist of strings describing wash status in the mode line.
5883 Each entry has the form (KEY ON OF), where the KEY is a symbol
5884 representing the particular washing function, ON is the string to use
5885 in the article mode line when the washing function is active, and OFF
5886 is the string to use when it is inactive.")
5887
5888 (defun gnus-article-wash-status-entry (key value)
5889   (let ((entry (assoc key gnus-article-wash-status-strings)))
5890     (if value (nth 1 entry) (nth 2 entry))))
5891
5892 (defun gnus-article-wash-status ()
5893   "Return a string which display status of article washing."
5894   (with-current-buffer gnus-article-buffer
5895     (let ((cite (memq 'cite gnus-article-wash-types))
5896           (headers (memq 'headers gnus-article-wash-types))
5897           (boring (memq 'boring-headers gnus-article-wash-types))
5898           (pgp (memq 'pgp gnus-article-wash-types))
5899           (pem (memq 'pem gnus-article-wash-types))
5900           (signed (memq 'signed gnus-article-wash-types))
5901           (encrypted (memq 'encrypted gnus-article-wash-types))
5902           (signature (memq 'signature gnus-article-wash-types))
5903           (overstrike (memq 'overstrike gnus-article-wash-types))
5904           (emphasis (memq 'emphasis gnus-article-wash-types)))
5905       (concat
5906        (gnus-article-wash-status-entry 'cite cite)
5907        (gnus-article-wash-status-entry 'headers (or headers boring))
5908        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5909        (gnus-article-wash-status-entry 'signature signature)
5910        (gnus-article-wash-status-entry 'overstrike overstrike)
5911        (gnus-article-wash-status-entry 'emphasis emphasis)))))
5912
5913 (defun gnus-add-wash-type (type)
5914   "Add a washing of TYPE to the current status."
5915   (add-to-list 'gnus-article-wash-types type))
5916
5917 (defun gnus-delete-wash-type (type)
5918   "Add a washing of TYPE to the current status."
5919   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5920
5921 (defun gnus-add-image (category image)
5922   "Add IMAGE of CATEGORY to the list of displayed images."
5923   (let ((entry (assq category gnus-article-image-alist)))
5924     (unless entry
5925       (setq entry (list category))
5926       (push entry gnus-article-image-alist))
5927     (nconc entry (list image))))
5928
5929 (defun gnus-delete-images (category)
5930   "Delete all images in CATEGORY."
5931   (let ((entry (assq category gnus-article-image-alist)))
5932     (dolist (image (cdr entry))
5933       (gnus-remove-image image category))
5934     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5935     (gnus-delete-wash-type category)))
5936
5937 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5938
5939 (defun gnus-article-maybe-hide-headers ()
5940   "Hide unwanted headers if `gnus-have-all-headers' is nil.
5941 Provided for backwards compatibility."
5942   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5943                  (not (with-current-buffer gnus-summary-buffer
5944                         gnus-have-all-headers)))
5945              (not gnus-inhibit-hiding))
5946     (gnus-article-hide-headers)))
5947
5948 ;;; Article savers.
5949
5950 (defun gnus-output-to-file (file-name)
5951   "Append the current article to a file named FILE-NAME.
5952 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5953 text and used as the value of the coding cookie which is added to the
5954 top of a file.  Otherwise, this function saves a raw article without
5955 the coding cookie."
5956   (let* ((artbuf (current-buffer))
5957          (file-name-coding-system nnmail-pathname-coding-system)
5958          (coding gnus-article-save-coding-system)
5959          (coding-system-for-read (if coding
5960                                      nil ;; Rely on the coding cookie.
5961                                    mm-text-coding-system))
5962          (coding-system-for-write (or coding
5963                                       mm-text-coding-system-for-write
5964                                       mm-text-coding-system))
5965          (exists (file-exists-p file-name)))
5966     (with-temp-buffer
5967       (when exists
5968         (insert-file-contents file-name)
5969         (goto-char (point-min))
5970         ;; Remove the existing coding cookie.
5971         (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5972           (delete-region (match-beginning 0) (match-end 0))))
5973       (goto-char (point-max))
5974       (insert-buffer-substring artbuf)
5975       ;; Append newline at end of the buffer as separator, and then
5976       ;; save it to file.
5977       (goto-char (point-max))
5978       (insert "\n")
5979       (when coding
5980         ;; If the coding system is not suitable to encode the text,
5981         ;; ask a user for a proper one.
5982         (when (fboundp 'select-safe-coding-system)
5983           (setq coding (coding-system-base
5984                         (save-window-excursion
5985                           (select-safe-coding-system (point-min) (point-max)
5986                                                      coding))))
5987           (setq coding-system-for-write
5988                 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5989                     coding)))
5990         (goto-char (point-min))
5991         ;; Add the coding cookie.
5992         (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5993                         coding-system-for-write)))
5994       (if exists
5995           (progn
5996             (write-region (point-min) (point-max) file-name nil 'no-message)
5997             (message "Appended to %s" file-name))
5998         (write-region (point-min) (point-max) file-name))))
5999   t)
6000
6001 (defun gnus-narrow-to-page (&optional arg)
6002   "Narrow the article buffer to a page.
6003 If given a numerical ARG, move forward ARG pages."
6004   (interactive "P")
6005   (setq arg (if arg (prefix-numeric-value arg) 0))
6006   (save-excursion
6007     (set-buffer gnus-article-buffer)
6008     (goto-char (point-min))
6009     (widen)
6010     ;; Remove any old next/prev buttons.
6011     (when (gnus-visual-p 'page-marker)
6012       (let ((inhibit-read-only t))
6013         (gnus-remove-text-with-property 'gnus-prev)
6014         (gnus-remove-text-with-property 'gnus-next)))
6015     (if
6016         (cond ((< arg 0)
6017                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
6018               ((> arg 0)
6019                (re-search-forward page-delimiter nil 'move arg)))
6020         (goto-char (match-end 0))
6021       (save-excursion
6022         (goto-char (point-min))
6023         (setq gnus-page-broken
6024               (and (re-search-forward page-delimiter nil t) t))))
6025     (when gnus-page-broken
6026       (narrow-to-region
6027        (point)
6028        (if (re-search-forward page-delimiter nil 'move)
6029            (match-beginning 0)
6030          (point)))
6031       (when (and (gnus-visual-p 'page-marker)
6032                  (> (point-min) (save-restriction (widen) (point-min))))
6033         (save-excursion
6034           (goto-char (point-min))
6035           (gnus-insert-prev-page-button)))
6036       (when (and (gnus-visual-p 'page-marker)
6037                  (< (point-max) (save-restriction (widen) (point-max))))
6038         (save-excursion
6039           (goto-char (point-max))
6040           (gnus-insert-next-page-button))))))
6041
6042 ;; Article mode commands
6043
6044 (defun gnus-article-goto-next-page ()
6045   "Show the next page of the article."
6046   (interactive)
6047   (when (gnus-article-next-page)
6048     (goto-char (point-min))
6049     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6050
6051
6052 (defun gnus-article-goto-prev-page ()
6053   "Show the previous page of the article."
6054   (interactive)
6055   (if (bobp)
6056       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6057     (gnus-article-prev-page nil)))
6058
6059 ;; This is cleaner but currently breaks `gnus-pick-mode':
6060 ;;
6061 ;; (defun gnus-article-goto-next-page ()
6062 ;;   "Show the next page of the article."
6063 ;;   (interactive)
6064 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6065 ;;     (gnus-summary-next-page)))
6066 ;;
6067 ;; (defun gnus-article-goto-prev-page ()
6068 ;;   "Show the next page of the article."
6069 ;;   (interactive)
6070 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6071 ;;     (gnus-summary-prev-page)))
6072
6073 (defun gnus-article-next-page (&optional lines)
6074   "Show the next page of the current article.
6075 If end of article, return non-nil.  Otherwise return nil.
6076 Argument LINES specifies lines to be scrolled up."
6077   (interactive "p")
6078   (move-to-window-line -1)
6079   (if (and (not (and gnus-article-over-scroll
6080                      (> (count-lines (window-start) (point-max))
6081                         (+ (or lines (1- (window-height)))
6082                            (or (and (boundp 'scroll-margin)
6083                                     (symbol-value 'scroll-margin))
6084                                0)))))
6085            (save-excursion
6086              (end-of-line)
6087              (and (pos-visible-in-window-p)     ;Not continuation line.
6088                   (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6089       ;; Nothing in this page.
6090       (if (or (not gnus-page-broken)
6091               (save-excursion
6092                 (save-restriction
6093                   (widen)
6094                   (forward-line)
6095                   (eobp)))) ;Real end-of-buffer?
6096           (progn
6097             (when gnus-article-over-scroll
6098               (gnus-article-next-page-1 lines))
6099             t)                  ;Nothing more.
6100         (gnus-narrow-to-page 1)         ;Go to next page.
6101         nil)
6102     ;; More in this page.
6103     (gnus-article-next-page-1 lines)
6104     nil))
6105
6106 (defmacro gnus-article-beginning-of-window ()
6107   "Move point to the beginning of the window.
6108 In Emacs, the point is placed at the line number which `scroll-margin'
6109 specifies."
6110   (if (featurep 'xemacs)
6111       '(move-to-window-line 0)
6112     '(move-to-window-line
6113       (min (max 0 scroll-margin)
6114            (max 1 (- (window-height)
6115                      (if mode-line-format 1 0)
6116                      (if header-line-format 1 0)))))))
6117
6118 (defun gnus-article-next-page-1 (lines)
6119   (when (and (not (featurep 'xemacs))
6120              (numberp lines)
6121              (> lines 0)
6122              (numberp (symbol-value 'scroll-margin))
6123              (> (symbol-value 'scroll-margin) 0))
6124     ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6125     ;; too many number of lines if `scroll-margin' is set as two or greater.
6126     (setq lines (min lines
6127                      (max 0 (- (count-lines (window-start) (point-max))
6128                                (symbol-value 'scroll-margin))))))
6129   (condition-case ()
6130       (let ((scroll-in-place nil))
6131         (scroll-up lines))
6132     (end-of-buffer
6133      ;; Long lines may cause an end-of-buffer error.
6134      (goto-char (point-max))))
6135   (gnus-article-beginning-of-window))
6136
6137 (defun gnus-article-prev-page (&optional lines)
6138   "Show previous page of current article.
6139 Argument LINES specifies lines to be scrolled down."
6140   (interactive "p")
6141   (move-to-window-line 0)
6142   (if (and gnus-page-broken
6143            (bobp)
6144            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6145       (progn
6146         (gnus-narrow-to-page -1)        ;Go to previous page.
6147         (goto-char (point-max))
6148         (recenter (if gnus-article-over-scroll
6149                       (if lines
6150                           (max (+ lines (or (and (boundp 'scroll-margin)
6151                                                  (symbol-value 'scroll-margin))
6152                                             0))
6153                                3)
6154                         (- (window-height) 2))
6155                     -1)))
6156     (prog1
6157         (condition-case ()
6158             (let ((scroll-in-place nil))
6159               (scroll-down lines))
6160           (beginning-of-buffer
6161            (goto-char (point-min))))
6162       (gnus-article-beginning-of-window))))
6163
6164 (defun gnus-article-only-boring-p ()
6165   "Decide whether there is only boring text remaining in the article.
6166 Something \"interesting\" is a word of at least two letters that does
6167 not have a face in `gnus-article-boring-faces'."
6168   (when (and gnus-article-skip-boring
6169              (boundp 'gnus-article-boring-faces)
6170              (symbol-value 'gnus-article-boring-faces))
6171     (save-excursion
6172       (let ((inhibit-point-motion-hooks t))
6173         (catch 'only-boring
6174           (while (re-search-forward "\\b\\w\\w" nil t)
6175             (forward-char -1)
6176             (when (not (gnus-intersection
6177                         (gnus-faces-at (point))
6178                         (symbol-value 'gnus-article-boring-faces)))
6179               (throw 'only-boring nil)))
6180           (throw 'only-boring t))))))
6181
6182 (defun gnus-article-refer-article ()
6183   "Read article specified by message-id around point."
6184   (interactive)
6185   (save-excursion
6186     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6187     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6188     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6189         (let ((msg-id (concat "<" (match-string 0) ">")))
6190           (set-buffer gnus-summary-buffer)
6191           (gnus-summary-refer-article msg-id))
6192       (error "No references around point"))))
6193
6194 (defun gnus-article-show-summary ()
6195   "Reconfigure windows to show summary buffer."
6196   (interactive)
6197   (if (not (gnus-buffer-live-p gnus-summary-buffer))
6198       (error "There is no summary buffer for this article buffer")
6199     (gnus-article-set-globals)
6200     (gnus-configure-windows 'article)
6201     (gnus-summary-goto-subject gnus-current-article)
6202     (gnus-summary-position-point)))
6203
6204 (defun gnus-article-describe-briefly ()
6205   "Describe article mode commands briefly."
6206   (interactive)
6207   (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page   \\[gnus-article-goto-prev-page]:Prev page  \\[gnus-article-show-summary]:Show summary  \\[gnus-info-find-node]:Run Info  \\[gnus-article-describe-briefly]:This help")))
6208
6209 (defun gnus-article-summary-command ()
6210   "Execute the last keystroke in the summary buffer."
6211   (interactive)
6212   (let ((obuf (current-buffer))
6213         (owin (current-window-configuration))
6214         func)
6215     (switch-to-buffer gnus-article-current-summary 'norecord)
6216     (setq func (lookup-key (current-local-map) (this-command-keys)))
6217     (call-interactively func)
6218     (set-buffer obuf)
6219     (set-window-configuration owin)
6220     (set-window-point (get-buffer-window (current-buffer)) (point))))
6221
6222 (defun gnus-article-summary-command-nosave ()
6223   "Execute the last keystroke in the summary buffer."
6224   (interactive)
6225   (let (func)
6226     (pop-to-buffer gnus-article-current-summary)
6227     (setq func (lookup-key (current-local-map) (this-command-keys)))
6228     (call-interactively func)))
6229
6230 (defun gnus-article-check-buffer ()
6231   "Beep if not in an article buffer."
6232   (unless (equal major-mode 'gnus-article-mode)
6233     (error "Command invoked outside of a Gnus article buffer")))
6234
6235 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6236   "Read a summary buffer key sequence and execute it from the article buffer."
6237   (interactive "P")
6238   (gnus-article-check-buffer)
6239   (let ((nosaves
6240          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
6241            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6242            "=" "^" "\M-^" "|"))
6243         (nosave-but-article
6244          '("A\r"))
6245         (nosave-in-article
6246          '("\C-d"))
6247         (up-to-top
6248          '("n" "Gn" "p" "Gp"))
6249         keys new-sum-point)
6250     (save-excursion
6251       (set-buffer gnus-article-current-summary)
6252       (let (gnus-pick-mode)
6253         (setq unread-command-events (nconc unread-command-events
6254                                            (list (or key last-command-event)))
6255               keys (if (featurep 'xemacs)
6256                        (events-to-keys (read-key-sequence nil t))
6257                      (read-key-sequence nil t)))))
6258
6259     (message "")
6260
6261     (cond
6262      ((eq (aref keys (1- (length keys))) ?\C-h)
6263       ;; FIXME: XEmacs doesn't show the S-prefixed keys that are defined
6264       ;; in the parent keymap (try `S C-h' in the article buffer).
6265       (let ((keymap (make-sparse-keymap))
6266             (map (copy-keymap gnus-article-send-map)))
6267         (define-key keymap "S" map)
6268         (if (featurep 'xemacs)
6269             (set-keymap-default-binding map nil)
6270           (define-key map [t] nil))
6271         (set-keymap-parent keymap
6272                            (with-current-buffer gnus-article-current-summary
6273                              (current-local-map)))
6274         (with-temp-buffer
6275           (use-local-map keymap)
6276           (describe-bindings (substring keys 0 -1)))))
6277      ((or (member keys nosaves)
6278           (member keys nosave-but-article)
6279           (member keys nosave-in-article))
6280       (let (func)
6281         (save-window-excursion
6282           (pop-to-buffer gnus-article-current-summary)
6283           ;; We disable the pick minor mode commands.
6284           (let (gnus-pick-mode)
6285             (setq func (lookup-key (current-local-map) keys))))
6286         (if (or (not func)
6287                 (numberp func))
6288             (ding)
6289           (unless (member keys nosave-in-article)
6290             (set-buffer gnus-article-current-summary))
6291           (call-interactively func)
6292           (setq new-sum-point (point)))
6293         (when (member keys nosave-but-article)
6294           (pop-to-buffer gnus-article-buffer))))
6295      (t
6296       ;; These commands should restore window configuration.
6297       (let ((obuf (current-buffer))
6298             (owin (current-window-configuration))
6299             win func in-buffer selected new-sum-start new-sum-hscroll err)
6300         (cond (not-restore-window
6301                (pop-to-buffer gnus-article-current-summary)
6302                (setq win (selected-window)))
6303               ((setq win (get-buffer-window gnus-article-current-summary))
6304                (select-window win))
6305               (t
6306                (let ((summary-buffer gnus-article-current-summary))
6307                  (gnus-configure-windows 'article)
6308                  (unless (setq win (get-buffer-window summary-buffer 'visible))
6309                    (let ((gnus-buffer-configuration
6310                           '(article ((vertical 1.0
6311                                                (summary 0.25 point)
6312                                                (article 1.0))))))
6313                      (gnus-configure-windows 'article))
6314                    (setq win (get-buffer-window summary-buffer 'visible)))
6315                  (gnus-select-frame-set-input-focus (window-frame win))
6316                  (select-window win))))
6317         (setq in-buffer (current-buffer))
6318         ;; We disable the pick minor mode commands.
6319         (if (and (setq func (let (gnus-pick-mode)
6320                               (lookup-key (current-local-map) keys)))
6321                  (functionp func)
6322                  (condition-case code
6323                      (progn
6324                        (call-interactively func)
6325                        t)
6326                    (error
6327                     (setq err code)
6328                     nil)))
6329             (progn
6330               (when (eq win (selected-window))
6331                 (setq new-sum-point (point)
6332                       new-sum-start (window-start win)
6333                       new-sum-hscroll (window-hscroll win)))
6334               (when (or (eq in-buffer (current-buffer))
6335                         (when (eq obuf (current-buffer))
6336                           (set-buffer in-buffer)
6337                           t))
6338                 (setq selected (gnus-summary-select-article))
6339                 (set-buffer obuf)
6340                 (unless not-restore-window
6341                   (set-window-configuration owin))
6342                 (when (and (eq selected 'old)
6343                            new-sum-point)
6344                   (set-window-start (get-buffer-window (current-buffer))
6345                                     1)
6346                   (set-window-point (get-buffer-window (current-buffer))
6347                                     (if (article-goto-body)
6348                                         (1- (point))
6349                                       (point))))
6350                 (when (and (not not-restore-window)
6351                            new-sum-point
6352                            (with-current-buffer (window-buffer win)
6353                              (eq major-mode 'gnus-summary-mode)))
6354                   (set-window-point win new-sum-point)
6355                   (set-window-start win new-sum-start)
6356                   (set-window-hscroll win new-sum-hscroll))))
6357           (set-window-configuration owin)
6358           (if err
6359               (signal (car err) (cdr err))
6360             (ding))))))))
6361
6362 (defun gnus-article-read-summary-send-keys ()
6363   (interactive)
6364   (let ((unread-command-events (list (if (featurep 'xemacs)
6365                                          (character-to-event ?S)
6366                                        ?S))))
6367     (gnus-article-read-summary-keys)))
6368
6369 (defun gnus-article-describe-key (key)
6370   "Display documentation of the function invoked by KEY.  KEY is a string."
6371   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6372                        (read-key-sequence "Describe key: "))))
6373   (gnus-article-check-buffer)
6374   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6375                                   gnus-article-read-summary-send-keys))
6376       (save-excursion
6377         (set-buffer gnus-article-current-summary)
6378         (setq unread-command-events
6379               (if (featurep 'xemacs)
6380                   (append key nil)
6381                 (mapcar (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6382                         key)))
6383         (let ((cursor-in-echo-area t)
6384               gnus-pick-mode)
6385           (describe-key (read-key-sequence nil t))))
6386     (describe-key key)))
6387
6388 (defun gnus-article-describe-key-briefly (key &optional insert)
6389   "Display documentation of the function invoked by KEY.  KEY is a string."
6390   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6391                        (read-key-sequence "Describe key: "))
6392                      current-prefix-arg))
6393   (gnus-article-check-buffer)
6394   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6395                                   gnus-article-read-summary-send-keys))
6396       (save-excursion
6397         (set-buffer gnus-article-current-summary)
6398         (setq unread-command-events
6399               (if (featurep 'xemacs)
6400                   (append key nil)
6401                 (mapcar (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6402                         key)))
6403         (let ((cursor-in-echo-area t)
6404               gnus-pick-mode)
6405           (describe-key-briefly (read-key-sequence nil t) insert)))
6406     (describe-key-briefly key insert)))
6407
6408 (defun gnus-article-reply-with-original (&optional wide)
6409   "Start composing a reply mail to the current message.
6410 The text in the region will be yanked.  If the region isn't active,
6411 the entire article will be yanked."
6412   (interactive)
6413   (let ((article (cdr gnus-article-current))
6414         contents)
6415     (if (not (gnus-region-active-p))
6416         (with-current-buffer gnus-summary-buffer
6417           (gnus-summary-reply (list (list article)) wide))
6418       (setq contents (buffer-substring (point) (mark t)))
6419       ;; Deactivate active regions.
6420       (when (and (boundp 'transient-mark-mode)
6421                  transient-mark-mode)
6422         (setq mark-active nil))
6423       (with-current-buffer gnus-summary-buffer
6424         (gnus-summary-reply
6425          (list (list article contents)) wide)))))
6426
6427 (defun gnus-article-wide-reply-with-original ()
6428   "Start composing a wide reply mail to the current message.
6429 The text in the region will be yanked.  If the region isn't active,
6430 the entire article will be yanked."
6431   (interactive)
6432   (gnus-article-reply-with-original t))
6433
6434 (defun gnus-article-followup-with-original ()
6435   "Compose a followup to the current article.
6436 The text in the region will be yanked.  If the region isn't active,
6437 the entire article will be yanked."
6438   (interactive)
6439   (let ((article (cdr gnus-article-current))
6440         contents)
6441       (if (not (gnus-region-active-p))
6442           (with-current-buffer gnus-summary-buffer
6443             (gnus-summary-followup (list (list article))))
6444         (setq contents (buffer-substring (point) (mark t)))
6445         ;; Deactivate active regions.
6446         (when (and (boundp 'transient-mark-mode)
6447                    transient-mark-mode)
6448           (setq mark-active nil))
6449         (with-current-buffer gnus-summary-buffer
6450           (gnus-summary-followup
6451            (list (list article contents)))))))
6452
6453 (defun gnus-article-hide (&optional arg force)
6454   "Hide all the gruft in the current article.
6455 This means that signatures, cited text and (some) headers will be
6456 hidden.
6457 If given a prefix, show the hidden text instead."
6458   (interactive (append (gnus-article-hidden-arg) (list 'force)))
6459   (gnus-article-hide-headers arg)
6460   (gnus-article-hide-list-identifiers arg)
6461   (gnus-article-hide-citation-maybe arg force)
6462   (gnus-article-hide-signature arg))
6463
6464 (defun gnus-article-maybe-highlight ()
6465   "Do some article highlighting if article highlighting is requested."
6466   (when (gnus-visual-p 'article-highlight 'highlight)
6467     (gnus-article-highlight-some)))
6468
6469 (defun gnus-check-group-server ()
6470   ;; Make sure the connection to the server is alive.
6471   (unless (gnus-server-opened
6472            (gnus-find-method-for-group gnus-newsgroup-name))
6473     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6474     (gnus-request-group gnus-newsgroup-name t)))
6475
6476 (eval-when-compile
6477   (autoload 'nneething-get-file-name "nneething"))
6478
6479 (defun gnus-request-article-this-buffer (article group)
6480   "Get an article and insert it into this buffer."
6481   (let (do-update-line sparse-header)
6482     (prog1
6483         (save-excursion
6484           (erase-buffer)
6485           (gnus-kill-all-overlays)
6486           (setq group (or group gnus-newsgroup-name))
6487
6488           ;; Using `gnus-request-article' directly will insert the article into
6489           ;; `nntp-server-buffer' - so we'll save some time by not having to
6490           ;; copy it from the server buffer into the article buffer.
6491
6492           ;; We only request an article by message-id when we do not have the
6493           ;; headers for it, so we'll have to get those.
6494           (when (stringp article)
6495             (gnus-read-header article))
6496
6497           ;; If the article number is negative, that means that this article
6498           ;; doesn't belong in this newsgroup (possibly), so we find its
6499           ;; message-id and request it by id instead of number.
6500           (when (and (numberp article)
6501                      gnus-summary-buffer
6502                      (get-buffer gnus-summary-buffer)
6503                      (gnus-buffer-exists-p gnus-summary-buffer))
6504             (save-excursion
6505               (set-buffer gnus-summary-buffer)
6506               (let ((header (gnus-summary-article-header article)))
6507                 (when (< article 0)
6508                   (cond
6509                    ((memq article gnus-newsgroup-sparse)
6510                     ;; This is a sparse gap article.
6511                     (setq do-update-line article)
6512                     (setq article (mail-header-id header))
6513                     (setq sparse-header (gnus-read-header article))
6514                     (setq gnus-newsgroup-sparse
6515                           (delq article gnus-newsgroup-sparse)))
6516                    ((vectorp header)
6517                     ;; It's a real article.
6518                     (setq article (mail-header-id header)))
6519                    (t
6520                     ;; It is an extracted pseudo-article.
6521                     (setq article 'pseudo)
6522                     (gnus-request-pseudo-article header))))
6523
6524                 (let ((method (gnus-find-method-for-group
6525                                gnus-newsgroup-name)))
6526                   (when (and (eq (car method) 'nneething)
6527                              (vectorp header))
6528                     (let ((dir (nneething-get-file-name
6529                                 (mail-header-id header))))
6530                       (when (and (stringp dir)
6531                                  (file-directory-p dir))
6532                         (setq article 'nneething)
6533                         (gnus-group-enter-directory dir))))))))
6534
6535           (cond
6536            ;; Refuse to select canceled articles.
6537            ((and (numberp article)
6538                  gnus-summary-buffer
6539                  (get-buffer gnus-summary-buffer)
6540                  (gnus-buffer-exists-p gnus-summary-buffer)
6541                  (eq (cdr (with-current-buffer gnus-summary-buffer
6542                             (assq article gnus-newsgroup-reads)))
6543                      gnus-canceled-mark))
6544             nil)
6545            ;; We first check `gnus-original-article-buffer'.
6546            ((and (get-buffer gnus-original-article-buffer)
6547                  (numberp article)
6548                  (with-current-buffer gnus-original-article-buffer
6549                    (and (equal (car gnus-original-article) group)
6550                         (eq (cdr gnus-original-article) article))))
6551             (insert-buffer-substring gnus-original-article-buffer)
6552             'article)
6553            ;; Check the backlog.
6554            ((and gnus-keep-backlog
6555                  (gnus-backlog-request-article group article (current-buffer)))
6556             'article)
6557            ;; Check asynchronous pre-fetch.
6558            ((gnus-async-request-fetched-article group article (current-buffer))
6559             (gnus-async-prefetch-next group article gnus-summary-buffer)
6560             (when (and (numberp article) gnus-keep-backlog)
6561               (gnus-backlog-enter-article group article (current-buffer)))
6562             'article)
6563            ;; Check the cache.
6564            ((and gnus-use-cache
6565                  (numberp article)
6566                  (gnus-cache-request-article article group))
6567             'article)
6568            ;; Check the agent cache.
6569            ((gnus-agent-request-article article group)
6570             'article)
6571            ;; Get the article and put into the article buffer.
6572            ((or (stringp article)
6573                 (numberp article))
6574             (let ((gnus-override-method gnus-override-method)
6575                   (methods (and (stringp article)
6576                                 gnus-refer-article-method))
6577                   (backend (car (gnus-find-method-for-group
6578                                  gnus-newsgroup-name)))
6579                   result
6580                   (inhibit-read-only t))
6581               (if (or (not (listp methods))
6582                       (and (symbolp (car methods))
6583                            (assq (car methods) nnoo-definition-alist)))
6584                   (setq methods (list methods)))
6585               (when (and (null gnus-override-method)
6586                          methods)
6587                 (setq gnus-override-method (pop methods)))
6588               (while (not result)
6589                 (when (eq gnus-override-method 'current)
6590                   (setq gnus-override-method
6591                         (with-current-buffer gnus-summary-buffer
6592                           gnus-current-select-method)))
6593                 (erase-buffer)
6594                 (gnus-kill-all-overlays)
6595                 (let ((gnus-newsgroup-name group))
6596                   (gnus-check-group-server))
6597                 (cond
6598                  ((gnus-request-article article group (current-buffer))
6599                   (when (numberp article)
6600                     (gnus-async-prefetch-next group article
6601                                               gnus-summary-buffer)
6602                     (when gnus-keep-backlog
6603                       (gnus-backlog-enter-article
6604                        group article (current-buffer))))
6605                   (setq result 'article))
6606                  (methods
6607                   (setq gnus-override-method (pop methods)))
6608                  ((not (string-match "^400 "
6609                                      (nnheader-get-report backend)))
6610                   ;; If we get 400 server disconnect, reconnect and
6611                   ;; retry; otherwise, assume the article has expired.
6612                   (setq result 'done))))
6613               (and (eq result 'article) 'article)))
6614            ;; It was a pseudo.
6615            (t article)))
6616
6617       ;; Associate this article with the current summary buffer.
6618       (setq gnus-article-current-summary gnus-summary-buffer)
6619
6620       ;; Take the article from the original article buffer
6621       ;; and place it in the buffer it's supposed to be in.
6622       (when (and (get-buffer gnus-article-buffer)
6623                  (equal (buffer-name (current-buffer))
6624                         (buffer-name (get-buffer gnus-article-buffer))))
6625         (save-excursion
6626           (if (get-buffer gnus-original-article-buffer)
6627               (set-buffer gnus-original-article-buffer)
6628             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6629             (buffer-disable-undo)
6630             (setq major-mode 'gnus-original-article-mode)
6631             (setq buffer-read-only t))
6632           (let ((inhibit-read-only t))
6633             (erase-buffer)
6634             (insert-buffer-substring gnus-article-buffer))
6635           (setq gnus-original-article (cons group article)))
6636
6637         ;; Decode charsets.
6638         (run-hooks 'gnus-article-decode-hook)
6639         ;; Mark article as decoded or not.
6640         (setq gnus-article-decoded-p gnus-article-decode-hook))
6641
6642       ;; Update sparse articles.
6643       (when (and do-update-line
6644                  (or (numberp article)
6645                      (stringp article)))
6646         (let ((buf (current-buffer)))
6647           (set-buffer gnus-summary-buffer)
6648           (gnus-summary-update-article do-update-line sparse-header)
6649           (gnus-summary-goto-subject do-update-line nil t)
6650           (set-window-point (gnus-get-buffer-window (current-buffer) t)
6651                             (point))
6652           (set-buffer buf))))))
6653
6654 ;;;
6655 ;;; Article editing
6656 ;;;
6657
6658 (defcustom gnus-article-edit-mode-hook nil
6659   "Hook run in article edit mode buffers."
6660   :group 'gnus-article-various
6661   :type 'hook)
6662
6663 (defvar gnus-article-edit-done-function nil)
6664
6665 (defvar gnus-article-edit-mode-map nil)
6666
6667 ;; Should we be using derived.el for this?
6668 (unless gnus-article-edit-mode-map
6669   (setq gnus-article-edit-mode-map (make-keymap))
6670   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6671
6672   (gnus-define-keys gnus-article-edit-mode-map
6673     "\C-c?"    describe-mode
6674     "\C-c\C-c" gnus-article-edit-done
6675     "\C-c\C-k" gnus-article-edit-exit
6676     "\C-c\C-f\C-t" message-goto-to
6677     "\C-c\C-f\C-o" message-goto-from
6678     "\C-c\C-f\C-b" message-goto-bcc
6679     ;;"\C-c\C-f\C-w" message-goto-fcc
6680     "\C-c\C-f\C-c" message-goto-cc
6681     "\C-c\C-f\C-s" message-goto-subject
6682     "\C-c\C-f\C-r" message-goto-reply-to
6683     "\C-c\C-f\C-n" message-goto-newsgroups
6684     "\C-c\C-f\C-d" message-goto-distribution
6685     "\C-c\C-f\C-f" message-goto-followup-to
6686     "\C-c\C-f\C-m" message-goto-mail-followup-to
6687     "\C-c\C-f\C-k" message-goto-keywords
6688     "\C-c\C-f\C-u" message-goto-summary
6689     "\C-c\C-f\C-i" message-insert-or-toggle-importance
6690     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6691     "\C-c\C-b" message-goto-body
6692     "\C-c\C-i" message-goto-signature
6693
6694     "\C-c\C-t" message-insert-to
6695     "\C-c\C-n" message-insert-newsgroups
6696     "\C-c\C-o" message-sort-headers
6697     "\C-c\C-e" message-elide-region
6698     "\C-c\C-v" message-delete-not-region
6699     "\C-c\C-z" message-kill-to-signature
6700     "\M-\r" message-newline-and-reformat
6701     "\C-c\C-a" mml-attach-file
6702     "\C-a" message-beginning-of-line
6703     "\t" message-tab
6704     "\M-;" comment-region)
6705
6706   (gnus-define-keys (gnus-article-edit-wash-map
6707                      "\C-c\C-w" gnus-article-edit-mode-map)
6708     "f" gnus-article-edit-full-stops))
6709
6710 (easy-menu-define
6711   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6712   '("Field"
6713     ["Fetch To" message-insert-to t]
6714     ["Fetch Newsgroups" message-insert-newsgroups t]
6715     "----"
6716     ["To" message-goto-to t]
6717     ["From" message-goto-from t]
6718     ["Subject" message-goto-subject t]
6719     ["Cc" message-goto-cc t]
6720     ["Reply-To" message-goto-reply-to t]
6721     ["Summary" message-goto-summary t]
6722     ["Keywords" message-goto-keywords t]
6723     ["Newsgroups" message-goto-newsgroups t]
6724     ["Followup-To" message-goto-followup-to t]
6725     ["Mail-Followup-To" message-goto-mail-followup-to t]
6726     ["Distribution" message-goto-distribution t]
6727     ["Body" message-goto-body t]
6728     ["Signature" message-goto-signature t]))
6729
6730 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6731   "Major mode for editing articles.
6732 This is an extended text-mode.
6733
6734 \\{gnus-article-edit-mode-map}"
6735   (make-local-variable 'gnus-article-edit-done-function)
6736   (make-local-variable 'gnus-prev-winconf)
6737   (set (make-local-variable 'font-lock-defaults)
6738        '(message-font-lock-keywords t))
6739   (set (make-local-variable 'mail-header-separator) "")
6740   (set (make-local-variable 'gnus-article-edit-mode) t)
6741   (easy-menu-add message-mode-field-menu message-mode-map)
6742   (mml-mode)
6743   (setq buffer-read-only nil)
6744   (buffer-enable-undo)
6745   (widen))
6746
6747 (defun gnus-article-edit (&optional force)
6748   "Edit the current article.
6749 This will have permanent effect only in mail groups.
6750 If FORCE is non-nil, allow editing of articles even in read-only
6751 groups."
6752   (interactive "P")
6753   (when (and (not force)
6754              (gnus-group-read-only-p))
6755     (error "The current newsgroup does not support article editing"))
6756   (gnus-article-date-original)
6757   (gnus-article-edit-article
6758    'ignore
6759    `(lambda (no-highlight)
6760       'ignore
6761       (gnus-summary-edit-article-done
6762        ,(or (mail-header-references gnus-current-headers) "")
6763        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6764
6765 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6766   "Start editing the contents of the current article buffer."
6767   (let ((winconf (current-window-configuration)))
6768     (set-buffer gnus-article-buffer)
6769     (let ((message-auto-save-directory
6770            ;; Don't associate the article buffer with a draft file.
6771            nil))
6772       (gnus-article-edit-mode))
6773     (funcall start-func)
6774     (set-buffer-modified-p nil)
6775     (gnus-configure-windows 'edit-article)
6776     (setq gnus-article-edit-done-function exit-func)
6777     (setq gnus-prev-winconf winconf)
6778     (unless quiet
6779       (gnus-message 6 "C-c C-c to end edits"))))
6780
6781 (defun gnus-article-edit-done (&optional arg)
6782   "Update the article edits and exit."
6783   (interactive "P")
6784   (let ((func gnus-article-edit-done-function)
6785         (buf (current-buffer))
6786         (start (window-start))
6787         (p (point))
6788         (winconf gnus-prev-winconf))
6789     (widen) ;; Widen it in case that users narrowed the buffer.
6790     (funcall func arg)
6791     (set-buffer buf)
6792     ;; The cache and backlog have to be flushed somewhat.
6793     (when gnus-keep-backlog
6794       (gnus-backlog-remove-article
6795        (car gnus-article-current) (cdr gnus-article-current)))
6796     ;; Flush original article as well.
6797     (save-excursion
6798       (when (get-buffer gnus-original-article-buffer)
6799         (set-buffer gnus-original-article-buffer)
6800         (setq gnus-original-article nil)))
6801     (when gnus-use-cache
6802       (gnus-cache-update-article
6803        (car gnus-article-current) (cdr gnus-article-current)))
6804     ;; We remove all text props from the article buffer.
6805     (kill-all-local-variables)
6806     (set-text-properties (point-min) (point-max) nil)
6807     (gnus-article-mode)
6808     (set-window-configuration winconf)
6809     (set-buffer buf)
6810     (set-window-start (get-buffer-window buf) start)
6811     (set-window-point (get-buffer-window buf) (point)))
6812   (gnus-summary-show-article))
6813
6814 (defun gnus-article-edit-exit ()
6815   "Exit the article editing without updating."
6816   (interactive)
6817   (when (or (not (buffer-modified-p))
6818             (yes-or-no-p "Article modified; kill anyway? "))
6819     (let ((curbuf (current-buffer))
6820           (p (point))
6821           (window-start (window-start)))
6822       (erase-buffer)
6823       (if (gnus-buffer-live-p gnus-original-article-buffer)
6824           (insert-buffer-substring gnus-original-article-buffer))
6825       (let ((winconf gnus-prev-winconf))
6826         (kill-all-local-variables)
6827         (gnus-article-mode)
6828         (set-window-configuration winconf)
6829         ;; Tippy-toe some to make sure that point remains where it was.
6830         (save-current-buffer
6831           (set-buffer curbuf)
6832           (set-window-start (get-buffer-window (current-buffer)) window-start)
6833           (goto-char p))))
6834     (gnus-summary-show-article)))
6835
6836 (defun gnus-article-edit-full-stops ()
6837   "Interactively repair spacing at end of sentences."
6838   (interactive)
6839   (save-excursion
6840     (goto-char (point-min))
6841     (search-forward-regexp "^$" nil t)
6842     (let ((case-fold-search nil))
6843       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6844
6845 ;;;
6846 ;;; Article highlights
6847 ;;;
6848
6849 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6850
6851 ;;; Internal Variables:
6852
6853 (defcustom gnus-button-url-regexp
6854   (concat
6855    "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6856    "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6857    "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6858    (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6859        (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6860              (punct "!?:;.,"))
6861          (concat
6862           "\\(?:"
6863           ;; Match paired parentheses, e.g. in Wikipedia URLs:
6864           "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6865           "\\|"
6866           "[" chars punct     "]+" "[" chars "]"
6867           "\\)"))
6868      (concat ;; XEmacs 21.4 doesn't support POSIX.
6869       "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6870       "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6871    "\\)")
6872   "Regular expression that matches URLs."
6873   :group 'gnus-article-buttons
6874   :type 'regexp)
6875
6876 (defcustom gnus-button-valid-fqdn-regexp
6877   message-valid-fqdn-regexp
6878   "Regular expression that matches a valid FQDN."
6879   :version "22.1"
6880   :group 'gnus-article-buttons
6881   :type 'regexp)
6882
6883 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6884 (defcustom gnus-button-valid-localpart-regexp
6885   "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6886   "Regular expression that matches a localpart of mail addresses or MIDs."
6887   :version "22.1"
6888   :group 'gnus-article-buttons
6889   :type 'regexp)
6890
6891 (defcustom gnus-button-man-handler 'manual-entry
6892   "Function to use for displaying man pages.
6893 The function must take at least one argument with a string naming the
6894 man page."
6895   :version "22.1"
6896   :type '(choice (function-item :tag "Man" manual-entry)
6897                  (function-item :tag "Woman" woman)
6898                  (function :tag "Other"))
6899   :group 'gnus-article-buttons)
6900
6901 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6902   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6903 If the default site is too slow, try to find a CTAN mirror, see
6904 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
6905 the variable `gnus-button-handle-ctan'."
6906   :version "22.1"
6907   :group 'gnus-article-buttons
6908   :link '(custom-manual "(gnus)Group Parameters")
6909   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6910                  (const "http://tug.ctan.org/tex-archive/")
6911                  (const "http://www.dante.de/CTAN/")
6912                  (string :tag "Other")))
6913
6914 (defcustom gnus-button-ctan-handler 'browse-url
6915   "Function to use for displaying CTAN links.
6916 The function must take one argument, the string naming the URL."
6917   :version "22.1"
6918   :type '(choice (function-item :tag "Browse Url" browse-url)
6919                  (function :tag "Other"))
6920   :group 'gnus-article-buttons)
6921
6922 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6923   "Bogus strings removed from CTAN URLs."
6924   :version "22.1"
6925   :group 'gnus-article-buttons
6926   :type '(choice (const "^/?tex-archive/\\|/")
6927                  (regexp :tag "Other")))
6928
6929 (defcustom gnus-button-ctan-directory-regexp
6930   (regexp-opt
6931    (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6932          "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6933          "languages" "macros" "nonfree" "obsolete" "support" "systems"
6934          "tds" "tools" "usergrps" "web") t)
6935   "Regular expression for ctan directories.
6936 It should match all directories in the top level of `gnus-ctan-url'."
6937   :version "22.1"
6938   :group 'gnus-article-buttons
6939   :type 'regexp)
6940
6941 (defcustom gnus-button-mid-or-mail-regexp
6942   (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6943           gnus-button-valid-fqdn-regexp
6944           ">?\\)\\b")
6945   "Regular expression that matches a message ID or a mail address."
6946   :version "22.1"
6947   :group 'gnus-article-buttons
6948   :type 'regexp)
6949
6950 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6951   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6952 Strings like this can be either a message ID or a mail address.  If it is one
6953 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6954 message ID or a mail address, respectively.  If this variable is set to the
6955 symbol `ask', always query the user what do do.  If it is a function, this
6956 function will be called with the string as its only argument.  The function
6957 must return `mid', `mail', `invalid' or `ask'."
6958   :version "22.1"
6959   :group 'gnus-article-buttons
6960   :type '(choice (function-item :tag "Heuristic function"
6961                                 gnus-button-mid-or-mail-heuristic)
6962                  (const ask)
6963                  (const mid)
6964                  (const mail)))
6965
6966 (defcustom gnus-button-mid-or-mail-heuristic-alist
6967   '((-10.0 . ".+\\$.+@")
6968     (-10.0 . "#")
6969     (-10.0 . "\\*")
6970     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
6971     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6972     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6973     (-1.0  . "^[^a-z]+@")
6974     ;;
6975     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6976     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6977     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
6978     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6979     ;;
6980     (-2.0  . "^[0-9]")
6981     (-1.0  . "^[0-9][0-9]")
6982     ;;
6983     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6984     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6985     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6986     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6987     ;;
6988     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6989     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6990     ;;       "[0-9]{8,}.*\@"
6991     (-3.0
6992      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6993     ;; "[0-9]{12,}.*\@"
6994     ;; compensation for TDMA dated mail addresses:
6995     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6996     ;;
6997     (-20.0 . "\\.fsf@") ;; Gnus
6998     (-20.0 . "^slrn")
6999     (-20.0 . "^Pine")
7000     (-20.0 . "^alpine\\.")
7001     (-20.0 . "_-_") ;; Subject change in thread
7002     ;;
7003     (-20.0 . "\\.ln@") ;; leafnode
7004     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7005     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7006     ;;
7007     ;; (5.0 . "") ;; $local_part_len <= 7
7008     (10.0  . "^[^0-9]+@")
7009     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7010     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7011     (3.0   . "\@stud")
7012     ;;
7013     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
7014     ;;
7015     (0.5   . "^[A-Z][a-z]")
7016     (0.5   . "^[A-Z][a-z][a-z]")
7017     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7018     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7019   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7020
7021 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7022 address.  The REGEXP is processed with `case-fold-search' set to nil."
7023   :version "22.1"
7024   :group 'gnus-article-buttons
7025   :type '(repeat (cons (number :tag "Rate")
7026                        (regexp :tag "Regexp"))))
7027
7028 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7029   "Guess whether MID-OR-MAIL is a message ID or a mail address.
7030 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7031 address, `ask' if unsure and `invalid' if the string is invalid."
7032   (let ((case-fold-search nil)
7033         (list gnus-button-mid-or-mail-heuristic-alist)
7034         (result 0) rate regexp lpartlen elem)
7035     (setq lpartlen
7036           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7037     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7038     ;; Certain special cases...
7039     (when (string-match
7040            (concat
7041             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7042             "^[0-9]+\\.[0-9]+@compuserve\\|"
7043             "@public\\.gmane\\.org")
7044            mid-or-mail)
7045       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7046       (setq result 'mail))
7047     (when (string-match "@.*@\\| " mid-or-mail)
7048       (gnus-message 8 "`%s' is invalid." mid-or-mail)
7049       (setq result 'invalid))
7050     ;; Nothing more to do, if result is not a number here...
7051     (when (numberp result)
7052       (while list
7053         (setq elem (car list)
7054               rate (car elem)
7055               regexp (cdr elem)
7056               list (cdr list))
7057         (when (string-match regexp mid-or-mail)
7058           (setq result (+ result rate))
7059           (gnus-message
7060            9 "`%s' matched `%s', rate `%s', result `%s'."
7061            mid-or-mail regexp rate result)))
7062       (when (<= lpartlen 7)
7063         (setq result (+ result 5.0))
7064         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7065                       mid-or-mail result))
7066       (when (>= lpartlen 12)
7067         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7068         (cond
7069          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7070           ;; Long local part should contain realname if e-mail address,
7071           ;; too many digits: message-id.
7072           ;; $score -= 5.0 + 0.1 * $local_part_len;
7073           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7074           (setq result (+ result rate))
7075           (gnus-message
7076            9 "Many digits in `%s', rate `%s', result `%s'."
7077            mid-or-mail rate result))
7078          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7079                         mid-or-mail)
7080           ;; Too few vowels [^aeiouy]{4,}.*\@
7081           (setq result (+ result -5.0))
7082           (gnus-message
7083            9 "Few vowels in `%s', rate `%s', result `%s'."
7084            mid-or-mail -5.0 result))
7085          (t
7086           (setq result (+ result 5.0))
7087           (gnus-message
7088            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7089     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7090     ;; Maybe we should make this a customizable alist: (condition . 'result)
7091     (cond
7092      ((symbolp result) result)
7093      ;; Now convert number into proper results:
7094      ((< result -10.0) 'mid)
7095      ((> result  10.0) 'mail)
7096      (t 'ask))))
7097
7098 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7099   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7100          (url-mid (concat "news" ":" mid-or-mail))
7101          (url-mailto (concat "mailto" ":" mid-or-mail)))
7102     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7103     (when (fboundp pref)
7104       (setq guessed
7105             ;; get rid of surrounding angles...
7106             (funcall pref
7107                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7108       (if (or (eq 'mid guessed) (eq 'mail guessed))
7109           (setq pref guessed)
7110         (setq pref 'ask)))
7111     (if (eq pref 'ask)
7112         (save-window-excursion
7113           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7114               (setq pref 'mail)
7115             (setq pref 'mid))))
7116     (cond ((eq pref 'mid)
7117            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7118            (gnus-button-handle-news url-mid))
7119           ((eq pref 'mail)
7120            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
7121            (gnus-url-mailto url-mailto))
7122           (t (gnus-message 3 "Invalid string.")))))
7123
7124 (defun gnus-button-handle-custom (fun arg)
7125   "Call function FUN on argument ARG.
7126 Both FUN and ARG are supposed to be strings.  ARG will be passed
7127 as a symbol to FUN."
7128   (funcall (intern fun)
7129            (if (string-match "^customize-apropos" fun)
7130                arg
7131              (intern arg))))
7132
7133 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7134
7135 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7136 ;; stuff?
7137
7138 (defun gnus-button-handle-describe-function (url)
7139   "Call `describe-function' when pushing the corresponding URL button."
7140   (describe-function
7141    (intern
7142     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7143
7144 (defun gnus-button-handle-describe-variable (url)
7145   "Call `describe-variable' when pushing the corresponding URL button."
7146   (describe-variable
7147    (intern
7148     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7149
7150 (defun gnus-button-handle-symbol (url)
7151 "Display help on variable or function.
7152 Calls `describe-variable' or `describe-function'."
7153   (let ((sym (intern url)))
7154     (cond
7155      ((fboundp sym) (describe-function sym))
7156      ((boundp sym) (describe-variable sym))
7157      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7158
7159 (defun gnus-button-handle-describe-key (url)
7160   "Call `describe-key' when pushing the corresponding URL button."
7161   (let* ((key-string
7162           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7163          (keys (ignore-errors (eval `(kbd ,key-string)))))
7164     (if keys
7165         (describe-key keys)
7166       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7167
7168 (defun gnus-button-handle-apropos (url)
7169   "Call `apropos' when pushing the corresponding URL button."
7170   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7171
7172 (defun gnus-button-handle-apropos-command (url)
7173   "Call `apropos' when pushing the corresponding URL button."
7174   (apropos-command
7175    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7176
7177 (defun gnus-button-handle-apropos-variable (url)
7178   "Call `apropos' when pushing the corresponding URL button."
7179   (funcall
7180    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7181    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7182
7183 (defun gnus-button-handle-apropos-documentation (url)
7184   "Call `apropos' when pushing the corresponding URL button."
7185   (funcall
7186    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7187    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7188
7189 (defun gnus-button-handle-library (url)
7190   "Call `locate-library' when pushing the corresponding URL button."
7191   (gnus-message 9 "url=`%s'" url)
7192   (let* ((lib (locate-library url))
7193          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7194     (if (not lib)
7195         (gnus-message 1 "Cannot locale library `%s'." url)
7196       (find-file-read-only file))))
7197
7198 (defun gnus-button-handle-ctan (url)
7199   "Call `browse-url' when pushing a CTAN URL button."
7200   (funcall
7201    gnus-button-ctan-handler
7202    (concat
7203     gnus-ctan-url
7204     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7205
7206 (defcustom gnus-button-tex-level 5
7207   "*Integer that says how many TeX-related buttons Gnus will show.
7208 The higher the number, the more buttons will appear and the more false
7209 positives are possible.  Note that you can set this variable local to
7210 specific groups.  Setting it higher in TeX groups is probably a good idea.
7211 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7212 how to set variables in specific groups."
7213   :version "22.1"
7214   :group 'gnus-article-buttons
7215   :link '(custom-manual "(gnus)Group Parameters")
7216   :type 'integer)
7217
7218 (defcustom gnus-button-man-level 5
7219   "*Integer that says how many man-related buttons Gnus will show.
7220 The higher the number, the more buttons will appear and the more false
7221 positives are possible.  Note that you can set this variable local to
7222 specific groups.  Setting it higher in Unix groups is probably a good idea.
7223 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7224 how to set variables in specific groups."
7225   :version "22.1"
7226   :group 'gnus-article-buttons
7227   :link '(custom-manual "(gnus)Group Parameters")
7228   :type 'integer)
7229
7230 (defcustom gnus-button-emacs-level 5
7231   "*Integer that says how many emacs-related buttons Gnus will show.
7232 The higher the number, the more buttons will appear and the more false
7233 positives are possible.  Note that you can set this variable local to
7234 specific groups.  Setting it higher in Emacs or Gnus related groups is
7235 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
7236 `gnus-parameters' on how to set variables in specific groups."
7237   :version "22.1"
7238   :group 'gnus-article-buttons
7239   :link '(custom-manual "(gnus)Group Parameters")
7240   :type 'integer)
7241
7242 (defcustom gnus-button-message-level 5
7243   "*Integer that says how many buttons for news or mail messages will appear.
7244 The higher the number, the more buttons will appear and the more false
7245 positives are possible."
7246   ;; mail addresses, MIDs, URLs for news, ...
7247   :version "22.1"
7248   :group 'gnus-article-buttons
7249   :type 'integer)
7250
7251 (defcustom gnus-button-browse-level 5
7252   "*Integer that says how many buttons for browsing will appear.
7253 The higher the number, the more buttons will appear and the more false
7254 positives are possible."
7255   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7256   :version "22.1"
7257   :group 'gnus-article-buttons
7258   :type 'integer)
7259
7260 (defcustom gnus-button-alist
7261   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7262      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7263     ((concat "\\b\\(nntp\\|news\\):\\("
7264              gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7265      0 t gnus-button-handle-news 2)
7266     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7267      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7268     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7269      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7270     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7271     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7272      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7273     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7274      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7275     ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7276      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7277     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7278      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7279     ;; RFC 2368 (The mailto URL scheme)
7280     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7281      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7282     ("\\bmailto:\\([^ \n\t]+\\)"
7283      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7284     ;; CTAN
7285     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7286              gnus-button-ctan-directory-regexp
7287              "[^][>)!;:,'\n\t ]+\\)")
7288      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7289     ((concat "\\btex-archive/\\("
7290              gnus-button-ctan-directory-regexp
7291              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7292      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7293     ((concat
7294       "\\b\\("
7295       gnus-button-ctan-directory-regexp
7296       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7297      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7298     ;; This is info (home-grown style) <info://foo/bar+baz>
7299     ("\\binfo://\\([^'\">\n\t ]+\\)"
7300      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7301     ;; Info GNOME style <info:foo#bar_baz>
7302     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7303      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7304     ;; Info KDE style <info:(foo)bar baz>
7305     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7306      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7307     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7308      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7309     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7310      ;; Info links like `C-h i d m CC Mode RET'
7311      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7312     ;; This is custom
7313     ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7314      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7315     ;; Emacs help commands
7316     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7317      ;; regexp doesn't match arguments containing ` '.
7318      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7319     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7320      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7321     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7322      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7323     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7324      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7325     ;; The following entries may lead to many false positives so don't enable
7326     ;; them by default (use a high button level).
7327     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7328      ;; Exclude [.?] for URLs in gmane.emacs.cvs
7329      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7330     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7331      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7332     ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7333      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7334     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7335      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7336     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7337      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7338     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7339      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7340     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7341      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7342     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7343      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7344     ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7345      ;; Unlike the other regexps we really have to require quoting
7346      ;; here to determine where it ends.
7347      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7348     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7349     ("<URL: *\\([^\n<>]*\\)>"
7350      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7351     ;; RFC 2396 (2.4.3., delims) ...
7352     ("\"URL: *\\([^\n\"]*\\)\""
7353      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7354     ;; Raw URLs.
7355     (gnus-button-url-regexp
7356      0 (>= gnus-button-browse-level 0) browse-url 0)
7357     ;; man pages
7358     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7359      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7360      gnus-button-handle-man 1)
7361     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7362     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7363      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7364      gnus-button-handle-man 1)
7365     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7366     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7367     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7368      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7369     ;; Recognizing patches to .el files.  This is somewhat obscure,
7370     ;; but considering the percentage of Gnus users who hack Emacs
7371     ;; Lisp files...
7372     ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7373      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7374     ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7375      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7376     ;; MID or mail: To avoid too many false positives we don't try to catch
7377     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
7378     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
7379     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
7380     ;; so that non-ambiguous entries (see above) match first.
7381     (gnus-button-mid-or-mail-regexp
7382      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7383   "*Alist of regexps matching buttons in article bodies.
7384
7385 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7386 REGEXP: is the string (case insensitive) matching text around the button (can
7387 also be Lisp expression evaluating to a string),
7388 BUTTON: is the number of the regexp grouping actually matching the button,
7389 FORM: is a Lisp expression which must eval to true for the button to
7390 be added,
7391 CALLBACK: is the function to call when the user push this button, and each
7392 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7393
7394 CALLBACK can also be a variable, in that case the value of that
7395 variable it the real callback function."
7396   :group 'gnus-article-buttons
7397   :type '(repeat (list (choice regexp variable sexp)
7398                        (integer :tag "Button")
7399                        (sexp :tag "Form")
7400                        (function :tag "Callback")
7401                        (repeat :tag "Par"
7402                                :inline t
7403                                (integer :tag "Regexp group")))))
7404 (put 'gnus-button-alist 'risky-local-variable t)
7405
7406 (defcustom gnus-header-button-alist
7407   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7408      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7409     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7410      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7411     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7412      0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7413     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7414      0 (>= gnus-button-browse-level 0) browse-url 0)
7415     ("^Subject:" gnus-button-url-regexp
7416      0 (>= gnus-button-browse-level 0) browse-url 0)
7417     ("^[^:]+:" gnus-button-url-regexp
7418      0 (>= gnus-button-browse-level 0) browse-url 0)
7419     ("^OpenPGP:.*url=" gnus-button-url-regexp
7420      0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7421     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7422      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7423     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7424      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7425   "*Alist of headers and regexps to match buttons in article heads.
7426
7427 This alist is very similar to `gnus-button-alist', except that each
7428 alist has an additional HEADER element first in each entry:
7429
7430 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7431
7432 HEADER is a regexp to match a header.  For a fuller explanation, see
7433 `gnus-button-alist'."
7434   :group 'gnus-article-buttons
7435   :group 'gnus-article-headers
7436   :type '(repeat (list (regexp :tag "Header")
7437                        (choice regexp variable)
7438                        (integer :tag "Button")
7439                        (sexp :tag "Form")
7440                        (function :tag "Callback")
7441                        (repeat :tag "Par"
7442                                :inline t
7443                                (integer :tag "Regexp group")))))
7444 (put 'gnus-header-button-alist 'risky-local-variable t)
7445
7446 ;;; Commands:
7447
7448 (defun gnus-article-push-button (event)
7449   "Check text under the mouse pointer for a callback function.
7450 If the text under the mouse pointer has a `gnus-callback' property,
7451 call it with the value of the `gnus-data' text property."
7452   (interactive "e")
7453   (set-buffer (window-buffer (posn-window (event-start event))))
7454   (let* ((pos (posn-point (event-start event)))
7455          (data (get-text-property pos 'gnus-data))
7456          (fun (get-text-property pos 'gnus-callback)))
7457     (goto-char pos)
7458     (when fun
7459       (funcall fun data))))
7460
7461 (defun gnus-article-press-button ()
7462   "Check text at point for a callback function.
7463 If the text at point has a `gnus-callback' property,
7464 call it with the value of the `gnus-data' text property."
7465   (interactive)
7466   (let ((data (get-text-property (point) 'gnus-data))
7467         (fun (get-text-property (point) 'gnus-callback)))
7468     (when fun
7469       (funcall fun data))))
7470
7471 (defun gnus-article-highlight (&optional force)
7472   "Highlight current article.
7473 This function calls `gnus-article-highlight-headers',
7474 `gnus-article-highlight-citation',
7475 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7476 do the highlighting.  See the documentation for those functions."
7477   (interactive (list 'force))
7478   (gnus-article-highlight-headers)
7479   (gnus-article-highlight-citation force)
7480   (gnus-article-highlight-signature)
7481   (gnus-article-add-buttons force)
7482   (gnus-article-add-buttons-to-head))
7483
7484 (defun gnus-article-highlight-some (&optional force)
7485   "Highlight current article.
7486 This function calls `gnus-article-highlight-headers',
7487 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7488 do the highlighting.  See the documentation for those functions."
7489   (interactive (list 'force))
7490   (gnus-article-highlight-headers)
7491   (gnus-article-highlight-signature)
7492   (gnus-article-add-buttons))
7493
7494 (defun gnus-article-highlight-headers ()
7495   "Highlight article headers as specified by `gnus-header-face-alist'."
7496   (interactive)
7497   (gnus-with-article-headers
7498     (let (regexp header-face field-face from hpoints fpoints)
7499       (dolist (entry gnus-header-face-alist)
7500         (goto-char (point-min))
7501         (setq regexp (concat "^\\("
7502                              (if (string-equal "" (nth 0 entry))
7503                                  "[^\t ]"
7504                                (nth 0 entry))
7505                              "\\)")
7506               header-face (nth 1 entry)
7507               field-face (nth 2 entry))
7508         (while (and (re-search-forward regexp nil t)
7509                     (not (eobp)))
7510           (beginning-of-line)
7511           (setq from (point))
7512           (unless (search-forward ":" nil t)
7513             (forward-char 1))
7514           (when (and header-face
7515                      (not (memq (point) hpoints)))
7516             (push (point) hpoints)
7517             (gnus-put-text-property from (point) 'face header-face))
7518           (when (and field-face
7519                      (not (memq (setq from (point)) fpoints)))
7520             (push from fpoints)
7521             (if (re-search-forward "^[^ \t]" nil t)
7522                 (forward-char -2)
7523               (goto-char (point-max)))
7524             (gnus-put-text-property from (point) 'face field-face)))))))
7525
7526 (defun gnus-article-highlight-signature ()
7527   "Highlight the signature in an article.
7528 It does this by highlighting everything after
7529 `gnus-signature-separator' using the face `gnus-signature'."
7530   (interactive)
7531   (gnus-with-article-buffer
7532     (let ((inhibit-point-motion-hooks t))
7533       (save-restriction
7534         (when (and gnus-signature-face
7535                    (gnus-article-narrow-to-signature))
7536           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7537                             'face gnus-signature-face)
7538           (widen)
7539           (gnus-article-search-signature)
7540           (let ((start (match-beginning 0))
7541                 (end (set-marker (make-marker) (1+ (match-end 0)))))
7542             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7543                                      end)))))))
7544
7545 (defun gnus-button-in-region-p (b e prop)
7546   "Say whether PROP exists in the region."
7547   (text-property-not-all b e prop nil))
7548
7549 (defun gnus-article-add-buttons (&optional force)
7550   "Find external references in the article and make buttons of them.
7551 \"External references\" are things like Message-IDs and URLs, as
7552 specified by `gnus-button-alist'."
7553   (interactive (list 'force))
7554   (gnus-with-article-buffer
7555     (let ((inhibit-point-motion-hooks t)
7556           (case-fold-search t)
7557           (alist gnus-button-alist)
7558           beg entry regexp)
7559       ;; Remove all old markers.
7560       (let (marker entry new-list)
7561         (while (setq marker (pop gnus-button-marker-list))
7562           (if (or (< marker (point-min)) (>= marker (point-max)))
7563               (push marker new-list)
7564             (goto-char marker)
7565             (when (setq entry (gnus-button-entry))
7566               (put-text-property (match-beginning (nth 1 entry))
7567                                  (match-end (nth 1 entry))
7568                                  'gnus-callback nil))
7569             (set-marker marker nil)))
7570         (setq gnus-button-marker-list new-list))
7571       ;; We skip the headers.
7572       (article-goto-body)
7573       (setq beg (point))
7574       (while (setq entry (pop alist))
7575         (setq regexp (eval (car entry)))
7576         (goto-char beg)
7577         (while (re-search-forward regexp nil t)
7578           (let ((start (match-beginning (nth 1 entry)))
7579                 (end (match-end (nth 1 entry)))
7580                 (from (match-beginning 0)))
7581             (when (and (or (eq t (nth 2 entry))
7582                            (eval (nth 2 entry)))
7583                        (not (gnus-button-in-region-p
7584                              start end 'gnus-callback)))
7585               ;; That optional form returned non-nil, so we add the
7586               ;; button.
7587               (setq from (set-marker (make-marker) from))
7588               (push from gnus-button-marker-list)
7589               (unless (and (eq (car entry) 'gnus-button-url-regexp)
7590                            (gnus-article-extend-url-button from start end))
7591                 (gnus-article-add-button start end
7592                                          'gnus-button-push from)))))))))
7593
7594 (defun gnus-article-extend-url-button (beg start end)
7595   "Extend url button if url is folded into two or more lines.
7596 Return non-nil if button is extended.  BEG is a marker that points to
7597 the beginning position of a text containing url.  START and END are
7598 the endpoints of a url button before it is extended.  The concatenated
7599 url is put as the `gnus-button-url' overlay property on the button."
7600   (let ((opoint (point))
7601         (points (list start end))
7602         url delim regexp)
7603     (prog1
7604         (when (and (progn
7605                      (goto-char end)
7606                      (not (looking-at "[\t ]*[\">]")))
7607                    (progn
7608                      (goto-char start)
7609                      (string-match
7610                       "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7611                       (buffer-substring (point-at-bol) start)))
7612                    (progn
7613                      (setq url (list (buffer-substring start end))
7614                            delim (if (match-beginning 1) ">" "\""))
7615                      (beginning-of-line)
7616                      (setq regexp (concat
7617                                    (when (and (looking-at
7618                                                message-cite-prefix-regexp)
7619                                               (< (match-end 0) start))
7620                                      (regexp-quote (match-string 0)))
7621                                    "\
7622 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7623                                    delim "\\)"))
7624                      (while (progn
7625                               (forward-line 1)
7626                               (and (looking-at regexp)
7627                                    (prog1
7628                                        (match-beginning 1)
7629                                      (push (or (match-string 2)
7630                                                (match-string 1))
7631                                            url)
7632                                      (push (setq end (or (match-end 2)
7633                                                          (match-end 1)))
7634                                            points)
7635                                      (push (or (match-beginning 2)
7636                                                (match-beginning 1))
7637                                            points)))))
7638                      (match-beginning 2)))
7639           (let (gnus-article-mouse-face widget-mouse-face)
7640             (while points
7641               (gnus-article-add-button (pop points) (pop points)
7642                                        'gnus-button-push beg)))
7643           (let ((overlay (gnus-make-overlay start end)))
7644             (gnus-overlay-put overlay 'evaporate t)
7645             (gnus-overlay-put overlay 'gnus-button-url
7646                               (list (mapconcat 'identity (nreverse url) "")))
7647             (when gnus-article-mouse-face
7648               (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7649           t)
7650       (goto-char opoint))))
7651
7652 ;; Add buttons to the head of an article.
7653 (defun gnus-article-add-buttons-to-head ()
7654   "Add buttons to the head of the article."
7655   (interactive)
7656   (gnus-with-article-headers
7657     (let (beg end)
7658       (dolist (entry gnus-header-button-alist)
7659         ;; Each alist entry.
7660         (goto-char (point-min))
7661         (while (re-search-forward (car entry) nil t)
7662           ;; Each header matching the entry.
7663           (setq beg (match-beginning 0))
7664           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7665                              (match-beginning 0))
7666                         (point-max)))
7667           (goto-char beg)
7668           (while (re-search-forward (eval (nth 1 entry)) end t)
7669             ;; Each match within a header.
7670             (let* ((entry (cdr entry))
7671                    (start (match-beginning (nth 1 entry)))
7672                    (end (match-end (nth 1 entry)))
7673                    (form (nth 2 entry)))
7674               (goto-char (match-end 0))
7675               (when (eval form)
7676                 (gnus-article-add-button
7677                  start end (nth 3 entry)
7678                  (buffer-substring (match-beginning (nth 4 entry))
7679                                    (match-end (nth 4 entry)))))))
7680           (goto-char end))))))
7681
7682 ;;; External functions:
7683
7684 (defun gnus-article-add-button (from to fun &optional data)
7685   "Create a button between FROM and TO with callback FUN and data DATA."
7686   (when gnus-article-button-face
7687     (gnus-overlay-put (gnus-make-overlay from to nil t)
7688                       'face gnus-article-button-face))
7689   (gnus-add-text-properties
7690    from to
7691    (nconc (and gnus-article-mouse-face
7692                (list gnus-mouse-face-prop gnus-article-mouse-face))
7693           (list 'gnus-callback fun)
7694           (and data (list 'gnus-data data))))
7695   (widget-convert-button 'link from to :action 'gnus-widget-press-button
7696                          :button-keymap gnus-widget-button-keymap))
7697
7698 ;;; Internal functions:
7699
7700 (defun gnus-article-set-globals ()
7701   (with-current-buffer gnus-summary-buffer
7702     (gnus-set-global-variables)))
7703
7704 (defun gnus-signature-toggle (end)
7705   (gnus-with-article-buffer
7706     (let ((inhibit-point-motion-hooks t))
7707       (if (text-property-any end (point-max) 'article-type 'signature)
7708           (progn
7709             (gnus-delete-wash-type 'signature)
7710             (gnus-remove-text-properties-when
7711              'article-type 'signature end (point-max)
7712              (cons 'article-type (cons 'signature
7713                                        gnus-hidden-properties))))
7714         (gnus-add-wash-type 'signature)
7715         (gnus-add-text-properties-when
7716          'article-type nil end (point-max)
7717          (cons 'article-type (cons 'signature
7718                                    gnus-hidden-properties)))))
7719     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7720       (gnus-set-mode-line 'article))))
7721
7722 (defun gnus-button-entry ()
7723   ;; Return the first entry in `gnus-button-alist' matching this place.
7724   (let ((alist gnus-button-alist)
7725         (entry nil))
7726     (while alist
7727       (setq entry (pop alist))
7728       (if (looking-at (eval (car entry)))
7729           (setq alist nil)
7730         (setq entry nil)))
7731     entry))
7732
7733 (defun gnus-button-push (marker)
7734   ;; Push button starting at MARKER.
7735   (save-excursion
7736     (goto-char marker)
7737     (let* ((entry (gnus-button-entry))
7738            (inhibit-point-motion-hooks t)
7739            (fun (nth 3 entry))
7740            (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7741                           (get-char-property marker 'gnus-button-url))
7742                      (mapcar (lambda (group)
7743                                (let ((string (match-string group)))
7744                                  (set-text-properties
7745                                   0 (length string) nil string)
7746                                  string))
7747                              (nthcdr 4 entry)))))
7748       (cond
7749        ((fboundp fun)
7750         (apply fun args))
7751        ((and (boundp fun)
7752              (fboundp (symbol-value fun)))
7753         (apply (symbol-value fun) args))
7754        (t
7755         (gnus-message 1 "You must define `%S' to use this button"
7756                       (cons fun args)))))))
7757
7758 (defun gnus-parse-news-url (url)
7759   (let (scheme server port group message-id articles)
7760     (with-temp-buffer
7761       (insert url)
7762       (goto-char (point-min))
7763       (when (looking-at "\\([A-Za-z]+\\):")
7764         (setq scheme (match-string 1))
7765         (goto-char (match-end 0)))
7766       (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7767         (setq server (match-string 1))
7768         (setq port (if (stringp (match-string 3))
7769                        (string-to-number (match-string 3))
7770                      (match-string 3)))
7771         (goto-char (match-end 0)))
7772
7773       (cond
7774        ((looking-at "\\(.*@.*\\)")
7775         (setq message-id (match-string 1)))
7776        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7777         (setq group (match-string 1)
7778               articles (split-string (match-string 2) "-")))
7779        ((looking-at "\\([^/]+\\)/?")
7780         (setq group (match-string 1)))
7781        (t
7782         (error "Unknown news URL syntax"))))
7783     (list scheme server port group message-id articles)))
7784
7785 (defun gnus-button-handle-news (url)
7786   "Fetch a news URL."
7787   (destructuring-bind (scheme server port group message-id articles)
7788       (gnus-parse-news-url url)
7789     (cond
7790      (message-id
7791       (save-excursion
7792         (set-buffer gnus-summary-buffer)
7793         (if server
7794             (let ((gnus-refer-article-method
7795                    (nconc (list (list 'nntp server))
7796                           gnus-refer-article-method))
7797                   (nntp-port-number (or port "nntp")))
7798               (gnus-message 7 "Fetching %s with %s"
7799                             message-id gnus-refer-article-method)
7800               (gnus-summary-refer-article message-id))
7801           (gnus-summary-refer-article message-id))))
7802      (group
7803       (gnus-button-fetch-group url)))))
7804
7805 (defun gnus-button-patch (library line)
7806   "Visit an Emacs Lisp library LIBRARY on line LINE."
7807   (interactive)
7808   (let ((file (locate-library (file-name-nondirectory library))))
7809     (unless file
7810       (error "Couldn't find library %s" library))
7811     (find-file file)
7812     (goto-line (string-to-number line))))
7813
7814 (defun gnus-button-handle-man (url)
7815   "Fetch a man page."
7816   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7817   (when (eq gnus-button-man-handler 'woman)
7818     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7819   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7820   (funcall gnus-button-man-handler url))
7821
7822 (defun gnus-button-handle-info-url (url)
7823   "Fetch an info URL."
7824   (setq url (mm-subst-char-in-string ?+ ?\  url))
7825   (cond
7826    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7827     (gnus-info-find-node
7828      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7829                      "Gnus")
7830              ")" (gnus-url-unhex-string (match-string 2 url)))))
7831    ((string-match "([^)\"]+)[^\"]+" url)
7832     (setq url
7833           (gnus-replace-in-string
7834            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7835     (gnus-info-find-node url))
7836    (t (error "Can't parse %s" url))))
7837
7838 (defun gnus-button-handle-info-url-gnome (url)
7839   "Fetch GNOME style info URL."
7840   (setq url (mm-subst-char-in-string ?_ ?\  url))
7841   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7842       (gnus-info-find-node
7843        (concat "("
7844                (gnus-url-unhex-string
7845                  (match-string 1 url))
7846                ")"
7847                (or (gnus-url-unhex-string
7848                     (match-string 2 url))
7849                    "Top")))
7850     (error "Can't parse %s" url)))
7851
7852 (defun gnus-button-handle-info-url-kde (url)
7853   "Fetch KDE style info URL."
7854   (gnus-info-find-node (gnus-url-unhex-string url)))
7855
7856 ;; (info) will autoload info.el
7857 (declare-function Info-menu "info" (menu-item &optional fork))
7858
7859 (defun gnus-button-handle-info-keystrokes (url)
7860   "Call `info' when pushing the corresponding URL button."
7861   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7862   (info)
7863   (Info-directory)
7864   (Info-menu url))
7865
7866 (defun gnus-button-openpgp (url)
7867   "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7868   (with-temp-buffer
7869     (mm-url-insert-file-contents-external url)
7870     (pgg-snarf-keys-region (point-min) (point-max))
7871     (pgg-display-output-buffer nil nil nil)))
7872
7873 (defun gnus-button-message-id (message-id)
7874   "Fetch MESSAGE-ID."
7875   (with-current-buffer gnus-summary-buffer
7876     (gnus-summary-refer-article message-id)))
7877
7878 (defun gnus-button-fetch-group (address &rest ignore)
7879   "Fetch GROUP specified by ADDRESS."
7880   (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7881                       address)
7882     ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7883     ;; for nntp:// and news://
7884     (setq address (match-string 3 address)))
7885   (if (not (string-match "[:/]" address))
7886       ;; This is just a simple group url.
7887       (gnus-group-read-ephemeral-group address gnus-select-method)
7888     (if (not
7889          (string-match
7890           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7891           address))
7892         (error "Can't parse %s" address)
7893       (gnus-group-read-ephemeral-group
7894        (match-string 4 address)
7895        `(nntp ,(match-string 1 address)
7896               (nntp-address ,(match-string 1 address))
7897               (nntp-port-number ,(if (match-end 3)
7898                                      (match-string 3 address)
7899                                    "nntp")))
7900        nil nil nil
7901        (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7902
7903 (defun gnus-url-parse-query-string (query &optional downcase)
7904   (let (retval pairs cur key val)
7905     (setq pairs (split-string query "&"))
7906     (while pairs
7907       (setq cur (car pairs)
7908             pairs (cdr pairs))
7909       (if (not (string-match "=" cur))
7910           nil                           ; Grace
7911         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7912               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7913         (if downcase
7914             (setq key (downcase key)))
7915         (setq cur (assoc key retval))
7916         (if cur
7917             (setcdr cur (cons val (cdr cur)))
7918           (setq retval (cons (list key val) retval)))))
7919     retval))
7920
7921 (defun gnus-url-mailto (url)
7922   ;; Send mail to someone
7923   (when (string-match "mailto:/*\\(.*\\)" url)
7924     (setq url (substring url (match-beginning 1) nil)))
7925   (let (to args subject func)
7926     (setq args (gnus-url-parse-query-string
7927                 (if (string-match "^\\?" url)
7928                     (substring url 1)
7929                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7930                       (concat "to=" (match-string 1 url) "&"
7931                               (match-string 2 url))
7932                     (concat "to=" url)))
7933                 t)
7934           subject (cdr-safe (assoc "subject" args)))
7935     (gnus-msg-mail)
7936     (while args
7937       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7938       (if (fboundp func)
7939           (funcall func)
7940         (message-position-on-field (caar args)))
7941       (insert (gnus-replace-in-string
7942                (mapconcat 'identity (reverse (cdar args)) ", ")
7943                "\r\n" "\n" t))
7944       (setq args (cdr args)))
7945     (if subject
7946         (message-goto-body)
7947       (message-goto-subject))))
7948
7949 (defun gnus-button-embedded-url (address)
7950   "Activate ADDRESS with `browse-url'."
7951   (browse-url (gnus-strip-whitespace address)))
7952
7953 ;;; Next/prev buttons in the article buffer.
7954
7955 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7956 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7957
7958 (defvar gnus-prev-page-map
7959   (let ((map (make-sparse-keymap)))
7960     (define-key map gnus-mouse-2 'gnus-button-prev-page)
7961     (define-key map "\r" 'gnus-button-prev-page)
7962     map))
7963
7964 (defvar gnus-next-page-map
7965   (let ((map (make-sparse-keymap)))
7966     (unless (>= emacs-major-version 21)
7967       ;; XEmacs doesn't care.
7968       (set-keymap-parent map gnus-article-mode-map))
7969     (define-key map gnus-mouse-2 'gnus-button-next-page)
7970     (define-key map "\r" 'gnus-button-next-page)
7971     map))
7972
7973 (defun gnus-insert-prev-page-button ()
7974   (let ((b (point)) e
7975         (inhibit-read-only t))
7976     (gnus-eval-format
7977      gnus-prev-page-line-format nil
7978      `(keymap ,gnus-prev-page-map
7979               gnus-prev t
7980               gnus-callback gnus-article-button-prev-page
7981               article-type annotation))
7982     (setq e (if (bolp)
7983                 ;; Exclude a newline.
7984                 (1- (point))
7985               (point)))
7986     (when gnus-article-button-face
7987       (gnus-overlay-put (gnus-make-overlay b e nil t)
7988                         'face gnus-article-button-face))
7989     (widget-convert-button
7990      'link b e
7991      :action 'gnus-button-prev-page
7992      :button-keymap gnus-prev-page-map)))
7993
7994 (defun gnus-button-next-page (&optional args more-args)
7995   "Go to the next page."
7996   (interactive)
7997   (let ((win (selected-window)))
7998     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7999     (gnus-article-next-page)
8000     (select-window win)))
8001
8002 (defun gnus-button-prev-page (&optional args more-args)
8003   "Go to the prev page."
8004   (interactive)
8005   (let ((win (selected-window)))
8006     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8007     (gnus-article-prev-page)
8008     (select-window win)))
8009
8010 (defun gnus-insert-next-page-button ()
8011   (let ((b (point)) e
8012         (inhibit-read-only t))
8013     (gnus-eval-format gnus-next-page-line-format nil
8014                       `(keymap ,gnus-next-page-map
8015                                gnus-next t
8016                                gnus-callback gnus-article-button-next-page
8017                                article-type annotation))
8018     (setq e (if (bolp)
8019                 ;; Exclude a newline.
8020                 (1- (point))
8021               (point)))
8022     (when gnus-article-button-face
8023       (gnus-overlay-put (gnus-make-overlay b e nil t)
8024                         'face gnus-article-button-face))
8025     (widget-convert-button
8026      'link b e
8027      :action 'gnus-button-next-page
8028      :button-keymap gnus-next-page-map)))
8029
8030 (defun gnus-article-button-next-page (arg)
8031   "Go to the next page."
8032   (interactive "P")
8033   (let ((win (selected-window)))
8034     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8035     (gnus-article-next-page)
8036     (select-window win)))
8037
8038 (defun gnus-article-button-prev-page (arg)
8039   "Go to the prev page."
8040   (interactive "P")
8041   (let ((win (selected-window)))
8042     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8043     (gnus-article-prev-page)
8044     (select-window win)))
8045
8046 (defvar gnus-decode-header-methods
8047   '(mail-decode-encoded-word-region)
8048   "List of methods used to decode headers.
8049
8050 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
8051 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
8052 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8053 whose names match REGEXP.
8054
8055 For example:
8056 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8057  mail-decode-encoded-word-region
8058  (\"chinese\" . rfc1843-decode-region))
8059 ")
8060
8061 (defvar gnus-decode-header-methods-cache nil)
8062
8063 (defun gnus-multi-decode-header (start end)
8064   "Apply the functions from `gnus-encoded-word-methods' that match."
8065   (unless (and gnus-decode-header-methods-cache
8066                (eq gnus-newsgroup-name
8067                    (car gnus-decode-header-methods-cache)))
8068     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8069     (dolist (x gnus-decode-header-methods)
8070       (if (symbolp x)
8071           (nconc gnus-decode-header-methods-cache (list x))
8072         (if (and gnus-newsgroup-name
8073                  (string-match (car x) gnus-newsgroup-name))
8074             (nconc gnus-decode-header-methods-cache
8075                    (list (cdr x)))))))
8076   (let ((xlist gnus-decode-header-methods-cache))
8077     (pop xlist)
8078     (save-restriction
8079       (narrow-to-region start end)
8080       (while xlist
8081         (funcall (pop xlist) (point-min) (point-max))))))
8082
8083 ;;;
8084 ;;; Treatment top-level handling.
8085 ;;;
8086
8087 (defun gnus-treat-article (condition &optional part-number total-parts type)
8088   (let ((length (- (point-max) (point-min)))
8089         (alist gnus-treatment-function-alist)
8090         (article-goto-body-goes-to-point-min-p t)
8091         (treated-type
8092          (or (not type)
8093              (catch 'found
8094                (let ((list gnus-article-treat-types))
8095                  (while list
8096                    (when (string-match (pop list) type)
8097                      (throw 'found t)))))))
8098         (highlightp (gnus-visual-p 'article-highlight 'highlight))
8099         val elem)
8100     (gnus-run-hooks 'gnus-part-display-hook)
8101     (dolist (elem alist)
8102       (setq val
8103             (save-excursion
8104               (when (gnus-buffer-live-p gnus-summary-buffer)
8105                 (set-buffer gnus-summary-buffer))
8106               (symbol-value (car elem))))
8107       (when (and (or (consp val)
8108                      treated-type)
8109                  (gnus-treat-predicate val)
8110                  (or (not (get (car elem) 'highlight))
8111                      highlightp))
8112         (save-restriction
8113           (funcall (cadr elem)))))))
8114
8115 ;; Dynamic variables.
8116 (defvar part-number)
8117 (defvar total-parts)
8118 (defvar type)
8119 (defvar condition)
8120 (defvar length)
8121
8122 (defun gnus-treat-predicate (val)
8123   (cond
8124    ((null val)
8125     nil)
8126    (condition
8127     (eq condition val))
8128    ((and (listp val)
8129          (stringp (car val)))
8130     (apply 'gnus-or (mapcar `(lambda (s)
8131                                (string-match s ,(or gnus-newsgroup-name "")))
8132                             val)))
8133    ((listp val)
8134     (let ((pred (pop val)))
8135       (cond
8136        ((eq pred 'or)
8137         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8138        ((eq pred 'and)
8139         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8140        ((eq pred 'not)
8141         (not (gnus-treat-predicate (car val))))
8142        ((eq pred 'typep)
8143         (equal (car val) type))
8144        (t
8145         (error "%S is not a valid predicate" pred)))))
8146    ((eq val t)
8147     t)
8148    ((eq val 'head)
8149     nil)
8150    ((eq val 'first)
8151     (eq part-number 1))
8152    ((eq val 'last)
8153     (eq part-number total-parts))
8154    ((numberp val)
8155     (< length val))
8156    (t
8157     (error "%S is not a valid value" val))))
8158
8159 (defun gnus-article-encrypt-body (protocol &optional n)
8160   "Encrypt the article body."
8161   (interactive
8162    (list
8163     (or gnus-article-encrypt-protocol
8164         (completing-read "Encrypt protocol: "
8165                          gnus-article-encrypt-protocol-alist
8166                          nil t))
8167     current-prefix-arg))
8168   ;; User might hit `K E' instead of `K e', so prompt once.
8169   (when (and gnus-article-encrypt-protocol
8170              gnus-novice-user)
8171     (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8172       (error "Encrypt aborted.")))
8173   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8174     (unless func
8175       (error "Can't find the encrypt protocol %s" protocol))
8176     (if (member gnus-newsgroup-name '("nndraft:delayed"
8177                                       "nndraft:drafts"
8178                                       "nndraft:queue"))
8179         (error "Can't encrypt the article in group %s"
8180                gnus-newsgroup-name))
8181     (gnus-summary-iterate n
8182       (save-excursion
8183         (set-buffer gnus-summary-buffer)
8184         (let ((mail-parse-charset gnus-newsgroup-charset)
8185               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8186               (summary-buffer gnus-summary-buffer)
8187               references point)
8188           (gnus-set-global-variables)
8189           (when (gnus-group-read-only-p)
8190             (error "The current newsgroup does not support article encrypt"))
8191           (gnus-summary-show-article t)
8192           (setq references
8193               (or (mail-header-references gnus-current-headers) ""))
8194           (set-buffer gnus-article-buffer)
8195           (let* ((inhibit-read-only t)
8196                  (headers
8197                   (mapcar (lambda (field)
8198                             (and (save-restriction
8199                                    (message-narrow-to-head)
8200                                    (goto-char (point-min))
8201                                    (search-forward field nil t))
8202                                  (prog2
8203                                      (message-narrow-to-field)
8204                                      (buffer-string)
8205                                    (delete-region (point-min) (point-max))
8206                                    (widen))))
8207                           '("Content-Type:" "Content-Transfer-Encoding:"
8208                             "Content-Disposition:"))))
8209             (message-narrow-to-head)
8210             (message-remove-header "MIME-Version")
8211             (goto-char (point-max))
8212             (setq point (point))
8213             (insert (apply 'concat headers))
8214             (widen)
8215             (narrow-to-region point (point-max))
8216             (let ((message-options message-options))
8217               (message-options-set 'message-sender user-mail-address)
8218               (message-options-set 'message-recipients user-mail-address)
8219               (message-options-set 'message-sign-encrypt 'not)
8220               (funcall func))
8221             (goto-char (point-min))
8222             (insert "MIME-Version: 1.0\n")
8223             (widen)
8224             (gnus-summary-edit-article-done
8225              references nil summary-buffer t))
8226           (when gnus-keep-backlog
8227             (gnus-backlog-remove-article
8228              (car gnus-article-current) (cdr gnus-article-current)))
8229           (save-excursion
8230             (when (get-buffer gnus-original-article-buffer)
8231               (set-buffer gnus-original-article-buffer)
8232               (setq gnus-original-article nil)))
8233           (when gnus-use-cache
8234             (gnus-cache-update-article
8235              (car gnus-article-current) (cdr gnus-article-current))))))))
8236
8237 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8238   "The following specs can be used:
8239 %t  The security MIME type
8240 %i  Additional info
8241 %d  Details
8242 %D  Details if button is pressed")
8243
8244 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8245   "The following specs can be used:
8246 %t  The security MIME type
8247 %i  Additional info
8248 %d  Details
8249 %D  Details if button is pressed")
8250
8251 (defvar gnus-mime-security-button-line-format-alist
8252   '((?t gnus-tmp-type ?s)
8253     (?i gnus-tmp-info ?s)
8254     (?d gnus-tmp-details ?s)
8255     (?D gnus-tmp-pressed-details ?s)))
8256
8257 (defvar gnus-mime-security-button-commands
8258   '((gnus-article-press-button "\r" "Show Detail")
8259     (undefined "v")
8260     (undefined "t")
8261     (undefined "C")
8262     (gnus-mime-security-save-part "o" "Save...")
8263     (undefined "\C-o")
8264     (undefined "r")
8265     (undefined "d")
8266     (undefined "c")
8267     (undefined "i")
8268     (undefined "E")
8269     (undefined "e")
8270     (undefined "p")
8271     (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8272     (undefined ".")))
8273
8274 (defvar gnus-mime-security-button-map
8275   (let ((map (make-sparse-keymap)))
8276     (define-key map gnus-mouse-2 'gnus-article-push-button)
8277     (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8278     (dolist (c gnus-mime-security-button-commands)
8279       (define-key map (cadr c) (car c)))
8280     map))
8281
8282 (easy-menu-define
8283   gnus-mime-security-button-menu gnus-mime-security-button-map
8284   "Security button menu."
8285   `("Security Part"
8286     ,@(delq nil
8287             (mapcar (lambda (c)
8288                       (unless (eq (car c) 'undefined)
8289                         (vector (caddr c) (car c) :active t)))
8290                     gnus-mime-security-button-commands))))
8291
8292 (defun gnus-mime-security-button-menu (event prefix)
8293   "Construct a context-sensitive menu of security commands."
8294   (interactive "e\nP")
8295   (save-window-excursion
8296     (let ((pos (event-start event)))
8297       (select-window (posn-window pos))
8298       (goto-char (posn-point pos))
8299       (gnus-article-check-buffer)
8300       (popup-menu gnus-mime-security-button-menu nil prefix))))
8301
8302 (defvar gnus-mime-security-details-buffer nil)
8303
8304 (defvar gnus-mime-security-button-pressed nil)
8305
8306 (defvar gnus-mime-security-show-details-inline t
8307   "If non-nil, show details in the article buffer.")
8308
8309 (defun gnus-mime-security-verify-or-decrypt (handle)
8310   (mm-remove-parts (cdr handle))
8311   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8312         point (inhibit-read-only t))
8313     (if region
8314         (goto-char (car region)))
8315     (setq point (point))
8316     (with-current-buffer (mm-handle-multipart-original-buffer handle)
8317       (let* ((mm-verify-option 'known)
8318              (mm-decrypt-option 'known)
8319              (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8320         (unless (eq nparts (cdr handle))
8321           (mm-destroy-parts (cdr handle))
8322           (setcdr handle nparts))))
8323     (gnus-mime-display-security handle)
8324     (when region
8325       (delete-region (point) (cdr region))
8326       (set-marker (car region) nil)
8327       (set-marker (cdr region) nil))
8328     (goto-char point)))
8329
8330 (defun gnus-mime-security-show-details (handle)
8331   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8332     (if (not details)
8333         (gnus-message 5 "No details.")
8334       (if gnus-mime-security-show-details-inline
8335           (let ((gnus-mime-security-button-pressed
8336                  (not (get-text-property (point) 'gnus-mime-details)))
8337                 (gnus-mime-security-button-line-format
8338                  (get-text-property (point) 'gnus-line-format))
8339                 (inhibit-read-only t))
8340             (forward-char -1)
8341             (while (eq (get-text-property (point) 'gnus-line-format)
8342                        gnus-mime-security-button-line-format)
8343               (forward-char -1))
8344             (forward-char)
8345             (save-restriction
8346               (narrow-to-region (point) (point))
8347               (gnus-insert-mime-security-button handle))
8348             (delete-region (point)
8349                            (or (text-property-not-all
8350                                 (point) (point-max)
8351                                 'gnus-line-format
8352                                 gnus-mime-security-button-line-format)
8353                                (point-max))))
8354         ;; Not inlined.
8355         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8356             (with-current-buffer gnus-mime-security-details-buffer
8357               (erase-buffer)
8358               t)
8359           (setq gnus-mime-security-details-buffer
8360                 (gnus-get-buffer-create "*MIME Security Details*")))
8361         (with-current-buffer gnus-mime-security-details-buffer
8362           (insert details)
8363           (goto-char (point-min)))
8364         (pop-to-buffer gnus-mime-security-details-buffer)))))
8365
8366 (defun gnus-mime-security-press-button (handle)
8367   (save-excursion
8368     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8369         (gnus-mime-security-show-details handle)
8370       (gnus-mime-security-verify-or-decrypt handle))))
8371
8372 (defun gnus-insert-mime-security-button (handle &optional displayed)
8373   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8374          (gnus-tmp-type
8375           (concat
8376            (or (nth 2 (assoc protocol mm-verify-function-alist))
8377                (nth 2 (assoc protocol mm-decrypt-function-alist))
8378                "Unknown")
8379            (if (equal (car handle) "multipart/signed")
8380                " Signed" " Encrypted")
8381            " Part"))
8382          (gnus-tmp-info
8383           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8384               "Undecided"))
8385          (gnus-tmp-details
8386           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8387          gnus-tmp-pressed-details
8388          b e)
8389     (setq gnus-tmp-details
8390           (if gnus-tmp-details
8391               (concat "\n" gnus-tmp-details)
8392             ""))
8393     (setq gnus-tmp-pressed-details
8394           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8395     (unless (bolp)
8396       (insert "\n"))
8397     (setq b (point))
8398     (gnus-eval-format
8399      gnus-mime-security-button-line-format
8400      gnus-mime-security-button-line-format-alist
8401      `(keymap ,gnus-mime-security-button-map
8402          gnus-callback gnus-mime-security-press-button
8403          gnus-line-format ,gnus-mime-security-button-line-format
8404          gnus-mime-details ,gnus-mime-security-button-pressed
8405          article-type annotation
8406          gnus-data ,handle))
8407     (setq e (if (bolp)
8408                 ;; Exclude a newline.
8409                 (1- (point))
8410               (point)))
8411     (when gnus-article-button-face
8412       (gnus-overlay-put (gnus-make-overlay b e nil t)
8413                         'face gnus-article-button-face))
8414     (widget-convert-button
8415      'link b e
8416      :mime-handle handle
8417      :action 'gnus-widget-press-button
8418      :button-keymap gnus-mime-security-button-map
8419      :help-echo
8420      (lambda (widget/window &optional overlay pos)
8421        ;; Needed to properly clear the message due to a bug in
8422        ;; wid-edit (XEmacs only).
8423        (when (boundp 'help-echo-owns-message)
8424          (setq help-echo-owns-message t))
8425        (format
8426         "%S: show detail; %S: more options"
8427         (aref gnus-mouse-2 0)
8428         (aref gnus-down-mouse-3 0))))))
8429
8430 (defun gnus-mime-display-security (handle)
8431   (save-restriction
8432     (narrow-to-region (point) (point))
8433     (unless (gnus-unbuttonized-mime-type-p (car handle))
8434       (gnus-insert-mime-security-button handle))
8435     (gnus-mime-display-part (cadr handle))
8436     (unless (bolp)
8437       (insert "\n"))
8438     (unless (gnus-unbuttonized-mime-type-p (car handle))
8439       (let ((gnus-mime-security-button-line-format
8440              gnus-mime-security-button-end-line-format))
8441         (gnus-insert-mime-security-button handle)))
8442     (mm-set-handle-multipart-parameter
8443      handle 'gnus-region
8444      (cons (set-marker (make-marker) (point-min))
8445            (set-marker (make-marker) (point-max))))
8446     (goto-char (point-max))))
8447
8448 (defun gnus-mime-security-run-function (function)
8449   "Run FUNCTION with the security part under point."
8450   (gnus-article-check-buffer)
8451   (let ((data (get-text-property (point) 'gnus-data))
8452         buffer handle)
8453     (when (and (stringp (car-safe data))
8454                (setq buffer (mm-handle-multipart-original-buffer data))
8455                (setq handle (cadr data)))
8456       (if (bufferp (mm-handle-buffer handle))
8457           (progn
8458             (setq handle (cons buffer (copy-sequence (cdr handle))))
8459             (mm-handle-set-undisplayer handle nil))
8460         (setq handle (mm-make-handle
8461                       buffer
8462                       (mm-handle-multipart-ctl-parameter handle 'protocol)
8463                       nil nil nil nil nil nil)))
8464       (funcall function handle))))
8465
8466 (defun gnus-mime-security-save-part ()
8467   "Save the security part under point."
8468   (interactive)
8469   (gnus-mime-security-run-function 'mm-save-part))
8470
8471 (defun gnus-mime-security-pipe-part ()
8472   "Pipe the security part under point to a process."
8473   (interactive)
8474   (gnus-mime-security-run-function 'mm-pipe-part))
8475
8476 (gnus-ems-redefine)
8477
8478 (provide 'gnus-art)
8479
8480 (run-hooks 'gnus-art-load-hook)
8481
8482 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8483 ;;; gnus-art.el ends here