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