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