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