Synch to No Gnus 200510131326.
[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* ((handle (get-text-property (point) 'gnus-data))
4670          (name (or
4671                 ;; Content-Type: foo/bar; name=...
4672                 (mail-content-type-get (mm-handle-type handle) 'name)
4673                 ;; Content-Disposition: attachment; filename=...
4674                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4675          (def-type (and name (mm-default-file-encoding name))))
4676     (and def-type (cons def-type 0))))
4677
4678 (defun gnus-mime-view-part-as-type (&optional mime-type)
4679   "Choose a MIME media type, and view the part as such."
4680   (interactive)
4681   (unless mime-type
4682     (setq mime-type
4683           (let ((default (gnus-mime-view-part-as-type-internal)))
4684             (completing-read
4685              (format "View as MIME type (default %s): "
4686                      (car default))
4687              (mapcar #'list (mailcap-mime-types))
4688              nil nil nil nil
4689              (car default)))))
4690   (gnus-article-check-buffer)
4691   (let ((handle (get-text-property (point) 'gnus-data)))
4692     (when handle
4693       (setq handle
4694             (mm-make-handle (mm-handle-buffer handle)
4695                             (cons mime-type (cdr (mm-handle-type handle)))
4696                             (mm-handle-encoding handle)
4697                             (mm-handle-undisplayer handle)
4698                             (mm-handle-disposition handle)
4699                             (mm-handle-description handle)
4700                             nil
4701                             (mm-handle-id handle)))
4702       (setq gnus-article-mime-handles
4703             (mm-merge-handles gnus-article-mime-handles handle))
4704       (gnus-mm-display-part handle))))
4705
4706 (defun gnus-mime-copy-part (&optional handle arg)
4707   "Put the MIME part under point into a new buffer.
4708 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4709 are decompressed."
4710   (interactive (list nil current-prefix-arg))
4711   (gnus-article-check-buffer)
4712   (unless handle
4713     (setq handle (get-text-property (point) 'gnus-data)))
4714   (when handle
4715     (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4716                                                'name)
4717                         (mail-content-type-get (mm-handle-disposition handle)
4718                                                'filename)))
4719           contents dont-decode charset coding-system)
4720       (mm-with-unibyte-buffer
4721         (mm-insert-part handle)
4722         (setq contents (or (condition-case nil
4723                                (mm-decompress-buffer filename nil 'sig)
4724                              (error
4725                               (setq dont-decode t)
4726                               nil))
4727                            (buffer-string))))
4728       (setq filename (cond (filename (file-name-nondirectory filename))
4729                            (dont-decode "*raw data*")
4730                            (t "*decoded*")))
4731       (cond
4732        (dont-decode)
4733        ((not arg)
4734         (unless (setq charset (mail-content-type-get
4735                                (mm-handle-type handle) 'charset))
4736           (unless (setq coding-system (mm-with-unibyte-buffer
4737                                         (insert contents)
4738                                         (mm-find-buffer-file-coding-system)))
4739             (setq charset gnus-newsgroup-charset))))
4740        ((numberp arg)
4741         (setq charset (or (cdr (assq arg
4742                                      gnus-summary-show-article-charset-alist))
4743                           (mm-read-coding-system "Charset: ")))))
4744       (switch-to-buffer (generate-new-buffer filename))
4745       (if (or coding-system
4746               (and charset
4747                    (setq coding-system (mm-charset-to-coding-system charset))
4748                    (not (eq charset 'ascii))))
4749           (progn
4750             (mm-enable-multibyte)
4751             (insert (mm-decode-coding-string contents coding-system))
4752             (setq buffer-file-coding-system
4753                   (if (boundp 'last-coding-system-used)
4754                       (symbol-value 'last-coding-system-used)
4755                     coding-system)))
4756         (mm-disable-multibyte)
4757         (insert contents)
4758         (setq buffer-file-coding-system mm-binary-coding-system))
4759       ;; We do it this way to make `normal-mode' set the appropriate mode.
4760       (unwind-protect
4761           (progn
4762             (setq buffer-file-name (expand-file-name filename))
4763             (normal-mode))
4764         (setq buffer-file-name nil))
4765       (goto-char (point-min)))))
4766
4767 (defun gnus-mime-print-part (&optional handle filename)
4768   "Print the MIME part under point."
4769   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4770   (gnus-article-check-buffer)
4771   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4772          (contents (and handle (mm-get-part handle)))
4773          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4774          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4775     (when contents
4776         (if printer
4777             (unwind-protect
4778                 (progn
4779                   (mm-save-part-to-file handle file)
4780                   (call-process shell-file-name nil
4781                                 (generate-new-buffer " *mm*")
4782                                 nil
4783                                 shell-command-switch
4784                                 (mm-mailcap-command
4785                                  printer file (mm-handle-type handle))))
4786               (delete-file file))
4787           (with-temp-buffer
4788             (insert contents)
4789             (gnus-print-buffer))
4790           (ps-despool filename)))))
4791
4792 (defun gnus-mime-inline-part (&optional handle arg)
4793   "Insert the MIME part under point into the current buffer.
4794 Compressed files like .gz and .bz2 are decompressed."
4795   (interactive (list nil current-prefix-arg))
4796   (gnus-article-check-buffer)
4797   (unless handle
4798     (setq handle (get-text-property (point) 'gnus-data)))
4799   (when handle
4800     (let ((b (point))
4801           (inhibit-read-only t)
4802           contents charset coding-system)
4803       (if (and (not arg) (mm-handle-undisplayer handle))
4804           (mm-remove-part handle)
4805         (mm-with-unibyte-buffer
4806           (mm-insert-part handle)
4807           (setq contents
4808                 (or (mm-decompress-buffer
4809                      (or (mail-content-type-get (mm-handle-disposition handle)
4810                                                 'name)
4811                          (mail-content-type-get (mm-handle-disposition handle)
4812                                                 'filename))
4813                      nil t)
4814                     (buffer-string))))
4815         (cond
4816          ((not arg)
4817           (unless (setq charset (mail-content-type-get
4818                                  (mm-handle-type handle) 'charset))
4819             (unless (setq coding-system
4820                           (mm-with-unibyte-buffer
4821                             (insert contents)
4822                             (mm-find-buffer-file-coding-system)))
4823               (setq charset gnus-newsgroup-charset))))
4824          ((numberp arg)
4825           (if (mm-handle-undisplayer handle)
4826               (mm-remove-part handle))
4827           (setq charset
4828                 (or (cdr (assq arg
4829                                gnus-summary-show-article-charset-alist))
4830                     (mm-read-coding-system "Charset: "))))
4831          (t
4832           (if (mm-handle-undisplayer handle)
4833               (mm-remove-part handle))))
4834         (forward-line 2)
4835         (mm-insert-inline
4836          handle
4837          (if (or coding-system
4838                  (and charset
4839                       (setq coding-system
4840                             (mm-charset-to-coding-system charset))
4841                       (not (eq coding-system 'ascii))))
4842              (mm-decode-coding-string contents coding-system)
4843            (mm-string-to-multibyte contents)))
4844         (goto-char b)))))
4845
4846 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4847   "Insert the MIME part under point into the current buffer using the
4848 specified charset."
4849   (interactive (list nil current-prefix-arg))
4850   (gnus-article-check-buffer)
4851   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4852          contents charset
4853          (b (point))
4854          (inhibit-read-only t))
4855     (when handle
4856       (if (mm-handle-undisplayer handle)
4857           (mm-remove-part handle))
4858       (let ((gnus-newsgroup-charset
4859              (or (cdr (assq arg
4860                             gnus-summary-show-article-charset-alist))
4861                  (mm-read-coding-system "Charset: ")))
4862             (gnus-newsgroup-ignored-charsets 'gnus-all))
4863         (gnus-article-press-button)))))
4864
4865 (defun gnus-mime-view-part-externally (&optional handle)
4866   "View the MIME part under point with an external viewer."
4867   (interactive)
4868   (gnus-article-check-buffer)
4869   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4870          (mm-user-display-methods nil)
4871          (mm-inlined-types nil)
4872          (mail-parse-charset gnus-newsgroup-charset)
4873          (mail-parse-ignored-charsets
4874           (with-current-buffer gnus-summary-buffer
4875             gnus-newsgroup-ignored-charsets)))
4876     (when handle
4877       (if (mm-handle-undisplayer handle)
4878           (mm-remove-part handle)
4879         (mm-display-part handle)))))
4880
4881 (defun gnus-mime-view-part-internally (&optional handle)
4882   "View the MIME part under point with an internal viewer.
4883 If no internal viewer is available, use an external viewer."
4884   (interactive)
4885   (gnus-article-check-buffer)
4886   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4887          (mm-inlined-types '(".*"))
4888          (mm-inline-large-images t)
4889          (mail-parse-charset gnus-newsgroup-charset)
4890          (mail-parse-ignored-charsets
4891           (with-current-buffer gnus-summary-buffer
4892             gnus-newsgroup-ignored-charsets))
4893          (inhibit-read-only t))
4894     (when handle
4895       (if (mm-handle-undisplayer handle)
4896           (mm-remove-part handle)
4897         (mm-display-part handle)))))
4898
4899 (defun gnus-mime-action-on-part (&optional action)
4900   "Do something with the MIME attachment at \(point\)."
4901   (interactive
4902    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4903   (gnus-article-check-buffer)
4904   (let ((action-pair (assoc action gnus-mime-action-alist)))
4905     (if action-pair
4906         (funcall (cdr action-pair)))))
4907
4908 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4909   "Call FUNCTION on MIME part N.
4910 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4911 If INTERACTIVE, call FUNCTION interactivly."
4912   (let (window frame)
4913     ;; Check whether the article is displayed.
4914     (unless (and (gnus-buffer-live-p gnus-article-buffer)
4915                  (setq window (get-buffer-window gnus-article-buffer t))
4916                  (frame-visible-p (setq frame (window-frame window))))
4917       (error "No article is displayed"))
4918     (with-current-buffer gnus-article-buffer
4919       ;; Check whether the article displays the right contents.
4920       (unless (with-current-buffer gnus-summary-buffer
4921                 (eq gnus-current-article (gnus-summary-article-number)))
4922         (error "You should select the right article first"))
4923       ;; Check whether the specified part exists.
4924       (when (> n (length gnus-article-mime-handle-alist))
4925         (error "No such part")))
4926     (unless
4927         (progn
4928           ;; To select the window is needed so that the cursor
4929           ;; might be visible on the MIME button.
4930           (select-window (prog1
4931                              window
4932                            (setq window (selected-window))
4933                            ;; Article may be displayed in the other frame.
4934                            (gnus-select-frame-set-input-focus
4935                             (prog1
4936                                 frame
4937                               (setq frame (selected-frame))))))
4938           (when (gnus-article-goto-part n)
4939             ;; We point the cursor and the arrow at the MIME button
4940             ;; when the `function' prompt the user for something.
4941             (let ((cursor-in-non-selected-windows t)
4942                   (overlay-arrow-string "=>")
4943                   (overlay-arrow-position (point-marker)))
4944               (unwind-protect
4945                   (cond
4946                    ((and no-handle interactive)
4947                     (call-interactively function))
4948                    (no-handle
4949                     (funcall function))
4950                    (interactive
4951                     (call-interactively
4952                      function
4953                      (cdr (assq n gnus-article-mime-handle-alist))))
4954                    (t
4955                     (funcall function
4956                              (cdr (assq n gnus-article-mime-handle-alist)))))
4957                 (set-marker overlay-arrow-position nil)
4958                 (unless gnus-auto-select-part
4959                   (gnus-select-frame-set-input-focus frame)
4960                   (select-window window))))
4961             t))
4962       (if gnus-inhibit-mime-unbuttonizing
4963           ;; This is the default though the program shouldn't reach here.
4964           (error "No such part")
4965         ;; The part which doesn't have the MIME button is selected.
4966         ;; So, we display all the buttons and redo it.
4967         (let ((gnus-inhibit-mime-unbuttonizing t))
4968           (gnus-summary-show-article)
4969           (gnus-article-part-wrapper n function no-handle))))))
4970
4971 (defun gnus-article-pipe-part (n)
4972   "Pipe MIME part N, which is the numerical prefix."
4973   (interactive "p")
4974   (gnus-article-part-wrapper n 'mm-pipe-part))
4975
4976 (defun gnus-article-save-part (n)
4977   "Save MIME part N, which is the numerical prefix."
4978   (interactive "p")
4979   (gnus-article-part-wrapper n 'mm-save-part))
4980
4981 (defun gnus-article-interactively-view-part (n)
4982   "View MIME part N interactively, which is the numerical prefix."
4983   (interactive "p")
4984   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4985
4986 (defun gnus-article-copy-part (n)
4987   "Copy MIME part N, which is the numerical prefix."
4988   (interactive "p")
4989   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4990
4991 (defun gnus-article-view-part-as-charset (n)
4992   "View MIME part N using a specified charset.
4993 N is the numerical prefix."
4994   (interactive "p")
4995   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4996
4997 (defun gnus-article-view-part-externally (n)
4998   "View MIME part N externally, which is the numerical prefix."
4999   (interactive "p")
5000   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5001
5002 (defun gnus-article-inline-part (n)
5003   "Inline MIME part N, which is the numerical prefix."
5004   (interactive "p")
5005   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5006
5007 (defun gnus-article-save-part-and-strip (n)
5008   "Save MIME part N and replace it with an external body.
5009 N is the numerical prefix."
5010   (interactive "p")
5011   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5012
5013 (defun gnus-article-replace-part (n)
5014   "Replace MIME part N with an external body.
5015 N is the numerical prefix."
5016   (interactive "p")
5017   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5018
5019 (defun gnus-article-delete-part (n)
5020   "Delete MIME part N and add some information about the removed part.
5021 N is the numerical prefix."
5022   (interactive "p")
5023   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5024
5025 (defun gnus-article-mime-match-handle-first (condition)
5026   (if condition
5027       (let (n)
5028         (dolist (ihandle gnus-article-mime-handle-alist)
5029           (if (and (cond
5030                     ((functionp condition)
5031                      (funcall condition (cdr ihandle)))
5032                     ((eq condition 'undisplayed)
5033                      (not (or (mm-handle-undisplayer (cdr ihandle))
5034                               (equal (mm-handle-media-type (cdr ihandle))
5035                                      "multipart/alternative"))))
5036                     ((eq condition 'undisplayed-alternative)
5037                      (not (mm-handle-undisplayer (cdr ihandle))))
5038                     (t t))
5039                    (gnus-article-goto-part (car ihandle))
5040                    (or (not n) (< (car ihandle) n)))
5041               (setq n (car ihandle))))
5042         (or n 1))
5043     1))
5044
5045 (defun gnus-article-view-part (&optional n)
5046   "View MIME part N, which is the numerical prefix."
5047   (interactive "P")
5048   (with-current-buffer gnus-article-buffer
5049     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5050                              gnus-article-mime-match-handle-function)))
5051     (when (> n (length gnus-article-mime-handle-alist))
5052       (error "No such part"))
5053     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5054       (when (gnus-article-goto-part n)
5055         (if (equal (car handle) "multipart/alternative")
5056             (gnus-article-press-button)
5057           (when (eq (gnus-mm-display-part handle) 'internal)
5058             (gnus-set-window-start)))))))
5059
5060 (defsubst gnus-article-mime-total-parts ()
5061   (if (bufferp (car gnus-article-mime-handles))
5062       1 ;; single part
5063     (1- (length gnus-article-mime-handles))))
5064
5065 (defun gnus-mm-display-part (handle)
5066   "Display HANDLE and fix MIME button."
5067   (let ((id (get-text-property (point) 'gnus-part))
5068         (point (point))
5069         (inhibit-read-only t))
5070     (forward-line 1)
5071     (prog1
5072         (let ((window (selected-window))
5073               (mail-parse-charset gnus-newsgroup-charset)
5074               (mail-parse-ignored-charsets
5075                (if (gnus-buffer-live-p gnus-summary-buffer)
5076                    (with-current-buffer gnus-summary-buffer
5077                      gnus-newsgroup-ignored-charsets)
5078                  nil)))
5079           (save-excursion
5080             (unwind-protect
5081                 (let ((win (gnus-get-buffer-window (current-buffer) t))
5082                       (beg (point)))
5083                   (when win
5084                     (select-window win))
5085                   (goto-char point)
5086                   (forward-line)
5087                   (if (mm-handle-displayed-p handle)
5088                       ;; This will remove the part.
5089                       (mm-display-part handle)
5090                     (save-restriction
5091                       (narrow-to-region (point)
5092                                         (if (eobp) (point) (1+ (point))))
5093                       (mm-display-part handle)
5094                       ;; We narrow to the part itself and
5095                       ;; then call the treatment functions.
5096                       (goto-char (point-min))
5097                       (forward-line 1)
5098                       (narrow-to-region (point) (point-max))
5099                       (gnus-treat-article
5100                        nil id
5101                        (gnus-article-mime-total-parts)
5102                        (mm-handle-media-type handle)))))
5103               (if (window-live-p window)
5104                   (select-window window)))))
5105       (goto-char point)
5106       (gnus-delete-line)
5107       (gnus-insert-mime-button
5108        handle id (list (mm-handle-displayed-p handle)))
5109       (goto-char point))))
5110
5111 (defun gnus-article-goto-part (n)
5112   "Go to MIME part N."
5113   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5114
5115 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5116   (let ((gnus-tmp-name
5117          (or (mail-content-type-get (mm-handle-type handle) 'name)
5118              (mail-content-type-get (mm-handle-disposition handle) 'filename)
5119              (mail-content-type-get (mm-handle-type handle) 'url)
5120              ""))
5121         (gnus-tmp-type (mm-handle-media-type handle))
5122         (gnus-tmp-description
5123          (mail-decode-encoded-word-string (or (mm-handle-description handle)
5124                                               "")))
5125         (gnus-tmp-dots
5126          (if (if displayed (car displayed)
5127                (mm-handle-displayed-p handle))
5128              "" "..."))
5129         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5130                            (buffer-size)))
5131         gnus-tmp-type-long b e)
5132     (when (string-match ".*/" gnus-tmp-name)
5133       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5134     (setq gnus-tmp-type-long (concat gnus-tmp-type
5135                                      (and (not (equal gnus-tmp-name ""))
5136                                           (concat "; " gnus-tmp-name))))
5137     (unless (equal gnus-tmp-description "")
5138       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5139     (unless (bolp)
5140       (insert "\n"))
5141     (setq b (point))
5142     (gnus-eval-format
5143      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5144      `(keymap ,gnus-mime-button-map
5145               gnus-callback gnus-mm-display-part
5146               gnus-part ,gnus-tmp-id
5147               article-type annotation
5148               gnus-data ,handle))
5149     (setq e (if (bolp)
5150                 ;; Exclude a newline.
5151                 (1- (point))
5152               (point)))
5153     (widget-convert-button
5154      'link b e
5155      :mime-handle handle
5156      :action 'gnus-widget-press-button
5157      :button-keymap gnus-mime-button-map
5158      :help-echo
5159      (lambda (widget/window &optional overlay pos)
5160        ;; Needed to properly clear the message due to a bug in
5161        ;; wid-edit (XEmacs only).
5162        (if (boundp 'help-echo-owns-message)
5163            (setq help-echo-owns-message t))
5164        (format
5165         "%S: %s the MIME part; %S: more options"
5166         (aref gnus-mouse-2 0)
5167         ;; XEmacs will get a single widget arg; Emacs 21 will get
5168         ;; window, overlay, position.
5169         (if (mm-handle-displayed-p
5170              (if overlay
5171                  (with-current-buffer (gnus-overlay-buffer overlay)
5172                    (widget-get (widget-at (gnus-overlay-start overlay))
5173                                :mime-handle))
5174                (widget-get widget/window :mime-handle)))
5175             "hide" "show")
5176         (aref gnus-down-mouse-3 0))))))
5177
5178 (defun gnus-widget-press-button (elems el)
5179   (goto-char (widget-get elems :from))
5180   (gnus-article-press-button))
5181
5182 (defvar gnus-displaying-mime nil)
5183
5184 (defun gnus-display-mime (&optional ihandles)
5185   "Display the MIME parts."
5186   (save-excursion
5187     (save-selected-window
5188       (let ((window (get-buffer-window gnus-article-buffer))
5189             (point (point)))
5190         (when window
5191           (select-window window)
5192           ;; We have to do this since selecting the window
5193           ;; may change the point.  So we set the window point.
5194           (set-window-point window point)))
5195       (let ((handles ihandles)
5196             (inhibit-read-only t)
5197             handle)
5198         (cond (handles)
5199               ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5200                (when gnus-article-emulate-mime
5201                  (mm-uu-dissect-text-parts handles)))
5202               (gnus-article-emulate-mime
5203                (setq handles (mm-uu-dissect))))
5204         (when (and (not ihandles)
5205                    (not gnus-displaying-mime))
5206           ;; Top-level call; we clean up.
5207           (when gnus-article-mime-handles
5208             (mm-destroy-parts gnus-article-mime-handles)
5209             (setq gnus-article-mime-handle-alist nil));; A trick.
5210           (setq gnus-article-mime-handles handles)
5211           ;; We allow users to glean info from the handles.
5212           (when gnus-article-mime-part-function
5213             (gnus-mime-part-function handles)))
5214         (if (and handles
5215                  (or (not (stringp (car handles)))
5216                      (cdr handles)))
5217             (progn
5218               (when (and (not ihandles)
5219                          (not gnus-displaying-mime))
5220                 ;; Clean up for mime parts.
5221                 (article-goto-body)
5222                 (delete-region (point) (point-max)))
5223               (let ((gnus-displaying-mime t))
5224                 (gnus-mime-display-part handles)))
5225           (save-restriction
5226             (article-goto-body)
5227             (narrow-to-region (point) (point-max))
5228             (gnus-treat-article nil 1 1)
5229             (widen)))
5230         (unless ihandles
5231           ;; Highlight the headers.
5232           (save-excursion
5233             (save-restriction
5234               (article-goto-body)
5235               (narrow-to-region (point-min) (point))
5236               (gnus-article-save-original-date
5237                (gnus-treat-article 'head)))))))))
5238
5239 (defcustom gnus-mime-display-multipart-as-mixed nil
5240   "Display \"multipart\" parts as  \"multipart/mixed\".
5241
5242 If t, it overrides nil values of
5243 `gnus-mime-display-multipart-alternative-as-mixed' and
5244 `gnus-mime-display-multipart-related-as-mixed'."
5245   :group 'gnus-article-mime
5246   :type 'boolean)
5247
5248 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5249   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
5250   :version "22.1"
5251   :group 'gnus-article-mime
5252   :type 'boolean)
5253
5254 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5255   "Display \"multipart/related\" parts as  \"multipart/mixed\".
5256
5257 If displaying \"text/html\" is discouraged \(see
5258 `mm-discouraged-alternatives'\) images or other material inside a
5259 \"multipart/related\" part might be overlooked when this variable is nil."
5260   :version "22.1"
5261   :group 'gnus-article-mime
5262   :type 'boolean)
5263
5264 (defun gnus-mime-display-part (handle)
5265   (cond
5266    ;; Maybe a broken MIME message.
5267    ((null handle))
5268    ;; Single part.
5269    ((not (stringp (car handle)))
5270     (gnus-mime-display-single handle))
5271    ;; User-defined multipart
5272    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5273     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5274              handle))
5275    ;; multipart/alternative
5276    ((and (equal (car handle) "multipart/alternative")
5277          (not (or gnus-mime-display-multipart-as-mixed
5278                   gnus-mime-display-multipart-alternative-as-mixed)))
5279     (let ((id (1+ (length gnus-article-mime-handle-alist))))
5280       (push (cons id handle) gnus-article-mime-handle-alist)
5281       (gnus-mime-display-alternative (cdr handle) nil nil id)))
5282    ;; multipart/related
5283    ((and (equal (car handle) "multipart/related")
5284          (not (or gnus-mime-display-multipart-as-mixed
5285                   gnus-mime-display-multipart-related-as-mixed)))
5286     ;;;!!!We should find the start part, but we just default
5287     ;;;!!!to the first part.
5288     ;;(gnus-mime-display-part (cadr handle))
5289     ;;;!!! Most multipart/related is an HTML message plus images.
5290     ;;;!!! Unfortunately we are unable to let W3 display those
5291     ;;;!!! included images, so we just display it as a mixed multipart.
5292     ;;(gnus-mime-display-mixed (cdr handle))
5293     ;;;!!! No, w3 can display everything just fine.
5294     (gnus-mime-display-part (cadr handle)))
5295    ((equal (car handle) "multipart/signed")
5296     (gnus-add-wash-type 'signed)
5297     (gnus-mime-display-security handle))
5298    ((equal (car handle) "multipart/encrypted")
5299     (gnus-add-wash-type 'encrypted)
5300     (gnus-mime-display-security handle))
5301    ;; Other multiparts are handled like multipart/mixed.
5302    (t
5303     (gnus-mime-display-mixed (cdr handle)))))
5304
5305 (defun gnus-mime-part-function (handles)
5306   (if (stringp (car handles))
5307       (mapcar 'gnus-mime-part-function (cdr handles))
5308     (funcall gnus-article-mime-part-function handles)))
5309
5310 (defun gnus-mime-display-mixed (handles)
5311   (mapcar 'gnus-mime-display-part handles))
5312
5313 (defun gnus-mime-display-single (handle)
5314   (let ((type (mm-handle-media-type handle))
5315         (ignored gnus-ignored-mime-types)
5316         (not-attachment t)
5317         (move nil)
5318         display text)
5319     (catch 'ignored
5320       (progn
5321         (while ignored
5322           (when (string-match (pop ignored) type)
5323             (throw 'ignored nil)))
5324         (if (and (setq not-attachment
5325                        (and (not (mm-inline-override-p handle))
5326                             (or (not (mm-handle-disposition handle))
5327                                 (equal (car (mm-handle-disposition handle))
5328                                        "inline")
5329                                 (mm-attachment-override-p handle))))
5330                  (mm-automatic-display-p handle)
5331                  (or (and
5332                       (mm-inlinable-p handle)
5333                       (mm-inlined-p handle))
5334                      (mm-automatic-external-display-p type)))
5335             (setq display t)
5336           (when (equal (mm-handle-media-supertype handle) "text")
5337             (setq text t)))
5338         (let ((id (1+ (length gnus-article-mime-handle-alist)))
5339               beg)
5340           (push (cons id handle) gnus-article-mime-handle-alist)
5341           (when (or (not display)
5342                     (not (gnus-unbuttonized-mime-type-p type)))
5343             (gnus-insert-mime-button
5344              handle id (list (or display (and not-attachment text))))
5345             (gnus-article-insert-newline)
5346             ;; Remember modify the number of forward lines.
5347             (setq move t))
5348           (setq beg (point))
5349           (cond
5350            (display
5351             (when move
5352               (forward-line -1)
5353               (setq beg (point)))
5354             (let ((mail-parse-charset gnus-newsgroup-charset)
5355                   (mail-parse-ignored-charsets
5356                    (save-excursion (condition-case ()
5357                                        (set-buffer gnus-summary-buffer)
5358                                      (error))
5359                                    gnus-newsgroup-ignored-charsets)))
5360               (mm-display-part handle t))
5361             (goto-char (point-max)))
5362            ((and text not-attachment)
5363             (when move
5364               (forward-line -1)
5365               (setq beg (point)))
5366             (gnus-article-insert-newline)
5367             (mm-insert-inline
5368              handle
5369              (let ((charset (mail-content-type-get (mm-handle-type handle)
5370                                                    'charset)))
5371                (cond ((not charset)
5372                       (mm-string-as-multibyte (mm-get-part handle)))
5373                      ((eq charset 'gnus-decoded)
5374                       (with-current-buffer (mm-handle-buffer handle)
5375                         (buffer-string)))
5376                      (t
5377                       (mm-decode-string (mm-get-part handle) charset)))))
5378             (goto-char (point-max))))
5379           ;; Do highlighting.
5380           (save-excursion
5381             (save-restriction
5382               (narrow-to-region beg (point))
5383               (gnus-treat-article
5384                nil id
5385                (gnus-article-mime-total-parts)
5386                (mm-handle-media-type handle)))))))))
5387
5388 (defun gnus-unbuttonized-mime-type-p (type)
5389   "Say whether TYPE is to be unbuttonized."
5390   (unless gnus-inhibit-mime-unbuttonizing
5391     (when (catch 'found
5392             (let ((types gnus-unbuttonized-mime-types))
5393               (while types
5394                 (when (string-match (pop types) type)
5395                   (throw 'found t)))))
5396       (not (catch 'found
5397              (let ((types gnus-buttonized-mime-types))
5398                (while types
5399                  (when (string-match (pop types) type)
5400                    (throw 'found t)))))))))
5401
5402 (defun gnus-article-insert-newline ()
5403   "Insert a newline, but mark it as undeletable."
5404   (gnus-put-text-property
5405    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5406
5407 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5408   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5409          (ihandles handles)
5410          (point (point))
5411          handle (inhibit-read-only t) from props begend not-pref)
5412     (save-window-excursion
5413       (save-restriction
5414         (when ibegend
5415           (narrow-to-region (car ibegend)
5416                             (or (cdr ibegend)
5417                                 (progn
5418                                   (goto-char (car ibegend))
5419                                   (forward-line 2)
5420                                   (point))))
5421           (delete-region (point-min) (point-max))
5422           (mm-remove-parts handles))
5423         (setq begend (list (point-marker)))
5424         ;; Do the toggle.
5425         (unless (setq not-pref (cadr (member preferred ihandles)))
5426           (setq not-pref (car ihandles)))
5427         (when (or ibegend
5428                   (not preferred)
5429                   (not (gnus-unbuttonized-mime-type-p
5430                         "multipart/alternative")))
5431           (gnus-add-text-properties
5432            (setq from (point))
5433            (progn
5434              (insert (format "%d.  " id))
5435              (point))
5436            `(gnus-callback
5437              (lambda (handles)
5438                (unless ,(not ibegend)
5439                  (setq gnus-article-mime-handle-alist
5440                        ',gnus-article-mime-handle-alist))
5441                (gnus-mime-display-alternative
5442                 ',ihandles ',not-pref ',begend ,id))
5443              keymap ,gnus-mime-button-map
5444              ,gnus-mouse-face-prop ,gnus-article-mouse-face
5445              face ,gnus-article-button-face
5446              gnus-part ,id
5447              gnus-data ,handle))
5448           (widget-convert-button 'link from (point)
5449                                  :action 'gnus-widget-press-button
5450                                  :button-keymap gnus-widget-button-keymap)
5451           ;; Do the handles
5452           (while (setq handle (pop handles))
5453             (gnus-add-text-properties
5454              (setq from (point))
5455              (progn
5456                (insert (format "(%c) %-18s"
5457                                (if (equal handle preferred) ?* ? )
5458                                (mm-handle-media-type handle)))
5459                (point))
5460              `(gnus-callback
5461                (lambda (handles)
5462                  (unless ,(not ibegend)
5463                    (setq gnus-article-mime-handle-alist
5464                          ',gnus-article-mime-handle-alist))
5465                  (gnus-mime-display-alternative
5466                   ',ihandles ',handle ',begend ,id))
5467                keymap ,gnus-mime-button-map
5468                ,gnus-mouse-face-prop ,gnus-article-mouse-face
5469                face ,gnus-article-button-face
5470                gnus-part ,id
5471                gnus-data ,handle))
5472             (widget-convert-button 'link from (point)
5473                                    :action 'gnus-widget-press-button
5474                                    :button-keymap gnus-widget-button-keymap)
5475             (insert "  "))
5476           (insert "\n\n"))
5477         (when preferred
5478           (if (stringp (car preferred))
5479               (gnus-display-mime preferred)
5480             (let ((mail-parse-charset gnus-newsgroup-charset)
5481                   (mail-parse-ignored-charsets
5482                    (with-current-buffer gnus-summary-buffer
5483                      gnus-newsgroup-ignored-charsets)))
5484               (mm-display-part preferred)
5485               ;; Do highlighting.
5486               (save-excursion
5487                 (save-restriction
5488                   (narrow-to-region (car begend) (point-max))
5489                   (gnus-treat-article
5490                    nil (length gnus-article-mime-handle-alist)
5491                    (gnus-article-mime-total-parts)
5492                    (mm-handle-media-type handle))))))
5493           (goto-char (point-max))
5494           (setcdr begend (point-marker)))))
5495     (when ibegend
5496       (goto-char point))))
5497
5498 (defconst gnus-article-wash-status-strings
5499   (let ((alist '((cite "c" "Possible hidden citation text"
5500                        " " "All citation text visible")
5501                  (headers "h" "Hidden headers"
5502                           " " "All headers visible.")
5503                  (pgp "p" "Encrypted or signed message status hidden"
5504                       " " "No hidden encryption nor digital signature status")
5505                  (signature "s" "Signature has been hidden"
5506                             " " "Signature is visible")
5507                  (overstrike "o" "Overstrike (^H) characters applied"
5508                              " " "No overstrike characters applied")
5509                  (gnus-show-mime "m" "Mime processing is activated"
5510                                  " " "Mime processing is not activated")
5511                  (emphasis "e" "/*_Emphasis_*/ characters applied"
5512                            " " "No /*_emphasis_*/ characters applied")))
5513         result)
5514     (dolist (entry alist result)
5515       (let ((key (nth 0 entry))
5516             (on (copy-sequence (nth 1 entry)))
5517             (on-help (nth 2 entry))
5518             (off (copy-sequence (nth 3 entry)))
5519             (off-help (nth 4 entry)))
5520         (put-text-property 0 1 'help-echo on-help on)
5521         (put-text-property 0 1 'help-echo off-help off)
5522         (push (list key on off) result))))
5523   "Alist of strings describing wash status in the mode line.
5524 Each entry has the form (KEY ON OF), where the KEY is a symbol
5525 representing the particular washing function, ON is the string to use
5526 in the article mode line when the washing function is active, and OFF
5527 is the string to use when it is inactive.")
5528
5529 (defun gnus-article-wash-status-entry (key value)
5530   (let ((entry (assoc key gnus-article-wash-status-strings)))
5531     (if value (nth 1 entry) (nth 2 entry))))
5532
5533 (defun gnus-article-wash-status ()
5534   "Return a string which display status of article washing."
5535   (with-current-buffer gnus-article-buffer
5536     (let ((cite (memq 'cite gnus-article-wash-types))
5537           (headers (memq 'headers gnus-article-wash-types))
5538           (boring (memq 'boring-headers gnus-article-wash-types))
5539           (pgp (memq 'pgp gnus-article-wash-types))
5540           (pem (memq 'pem gnus-article-wash-types))
5541           (signed (memq 'signed gnus-article-wash-types))
5542           (encrypted (memq 'encrypted gnus-article-wash-types))
5543           (signature (memq 'signature gnus-article-wash-types))
5544           (overstrike (memq 'overstrike gnus-article-wash-types))
5545           (emphasis (memq 'emphasis gnus-article-wash-types)))
5546       (concat
5547        (gnus-article-wash-status-entry 'cite cite)
5548        (gnus-article-wash-status-entry 'headers (or headers boring))
5549        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5550        (gnus-article-wash-status-entry 'signature signature)
5551        (gnus-article-wash-status-entry 'overstrike overstrike)
5552        (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
5553        (gnus-article-wash-status-entry 'emphasis emphasis)))))
5554
5555 (defun gnus-add-wash-type (type)
5556   "Add a washing of TYPE to the current status."
5557   (add-to-list 'gnus-article-wash-types type))
5558
5559 (defun gnus-delete-wash-type (type)
5560   "Add a washing of TYPE to the current status."
5561   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5562
5563 (defun gnus-add-image (category image)
5564   "Add IMAGE of CATEGORY to the list of displayed images."
5565   (let ((entry (assq category gnus-article-image-alist)))
5566     (unless entry
5567       (setq entry (list category))
5568       (push entry gnus-article-image-alist))
5569     (nconc entry (list image))))
5570
5571 (defun gnus-delete-images (category)
5572   "Delete all images in CATEGORY."
5573   (let ((entry (assq category gnus-article-image-alist)))
5574     (dolist (image (cdr entry))
5575       (gnus-remove-image image category))
5576     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5577     (gnus-delete-wash-type category)))
5578
5579 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5580
5581 (defun gnus-article-maybe-hide-headers ()
5582   "Hide unwanted headers if `gnus-have-all-headers' is nil.
5583 Provided for backwards compatibility."
5584   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5585                  (not (with-current-buffer gnus-summary-buffer
5586                         gnus-have-all-headers)))
5587              (not gnus-inhibit-hiding))
5588     (gnus-article-hide-headers)))
5589
5590 ;;; Article savers.
5591
5592 (defun gnus-output-to-file (file-name)
5593   "Append the current article to a file named FILE-NAME."
5594   (let ((artbuf (current-buffer)))
5595     (with-temp-buffer
5596       (insert-buffer-substring artbuf)
5597       ;; Append newline at end of the buffer as separator, and then
5598       ;; save it to file.
5599       (goto-char (point-max))
5600       (insert "\n")
5601       (let ((file-name-coding-system nnmail-pathname-coding-system))
5602         (write-region-as-binary (point-min) (point-max) file-name 'append))
5603       t)))
5604
5605 (defun gnus-narrow-to-page (&optional arg)
5606   "Narrow the article buffer to a page.
5607 If given a numerical ARG, move forward ARG pages."
5608   (interactive "P")
5609   (setq arg (if arg (prefix-numeric-value arg) 0))
5610   (save-excursion
5611     (set-buffer gnus-article-buffer)
5612     (goto-char (point-min))
5613     (widen)
5614     ;; Remove any old next/prev buttons.
5615     (when (gnus-visual-p 'page-marker)
5616       (let ((inhibit-read-only t))
5617         (gnus-remove-text-with-property 'gnus-prev)
5618         (gnus-remove-text-with-property 'gnus-next)))
5619     (if
5620         (cond ((< arg 0)
5621                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5622               ((> arg 0)
5623                (re-search-forward page-delimiter nil 'move arg)))
5624         (goto-char (match-end 0))
5625       (save-excursion
5626         (goto-char (point-min))
5627         (setq gnus-page-broken
5628               (and (re-search-forward page-delimiter nil t) t))))
5629     (when gnus-page-broken
5630       (narrow-to-region
5631        (point)
5632        (if (re-search-forward page-delimiter nil 'move)
5633            (match-beginning 0)
5634          (point)))
5635       (when (and (gnus-visual-p 'page-marker)
5636                  (> (point-min) (save-restriction (widen) (point-min))))
5637         (save-excursion
5638           (goto-char (point-min))
5639           (gnus-insert-prev-page-button)))
5640       (when (and (gnus-visual-p 'page-marker)
5641                  (< (point-max) (save-restriction (widen) (point-max))))
5642         (save-excursion
5643           (goto-char (point-max))
5644           (gnus-insert-next-page-button))))))
5645
5646 ;; Article mode commands
5647
5648 (defun gnus-article-goto-next-page ()
5649   "Show the next page of the article."
5650   (interactive)
5651   (when (gnus-article-next-page)
5652     (goto-char (point-min))
5653     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5654
5655
5656 (defun gnus-article-goto-prev-page ()
5657   "Show the previous page of the article."
5658   (interactive)
5659   (if (bobp)
5660       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5661     (gnus-article-prev-page nil)))
5662
5663 ;; This is cleaner but currently breaks `gnus-pick-mode':
5664 ;;
5665 ;; (defun gnus-article-goto-next-page ()
5666 ;;   "Show the next page of the article."
5667 ;;   (interactive)
5668 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5669 ;;     (gnus-summary-next-page)))
5670 ;;
5671 ;; (defun gnus-article-goto-prev-page ()
5672 ;;   "Show the next page of the article."
5673 ;;   (interactive)
5674 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5675 ;;     (gnus-summary-prev-page)))
5676
5677 (defun gnus-article-next-page (&optional lines)
5678   "Show the next page of the current article.
5679 If end of article, return non-nil.  Otherwise return nil.
5680 Argument LINES specifies lines to be scrolled up."
5681   (interactive "p")
5682   (move-to-window-line -1)
5683   (if (save-excursion
5684         (end-of-line)
5685         (and (pos-visible-in-window-p)  ;Not continuation line.
5686              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5687       ;; Nothing in this page.
5688       (if (or (not gnus-page-broken)
5689               (save-excursion
5690                 (save-restriction
5691                   (widen)
5692                   (forward-line)
5693                   (eobp)))) ;Real end-of-buffer?
5694           (progn
5695             (when gnus-article-over-scroll
5696               (gnus-article-next-page-1 lines))
5697             t)                  ;Nothing more.
5698         (gnus-narrow-to-page 1)         ;Go to next page.
5699         nil)
5700     ;; More in this page.
5701     (gnus-article-next-page-1 lines)
5702     nil))
5703
5704 (defmacro gnus-article-beginning-of-window ()
5705   "Move point to the beginning of the window.
5706 In Emacs, the point is placed at the line number which `scroll-margin'
5707 specifies."
5708   (if (featurep 'xemacs)
5709       '(move-to-window-line 0)
5710     '(move-to-window-line
5711       (min (max 0 scroll-margin)
5712            (max 1 (- (window-height)
5713                      (if mode-line-format 1 0)
5714                      (if header-line-format 1 0)))))))
5715
5716 (defun gnus-article-next-page-1 (lines)
5717   (when (and (not (featurep 'xemacs))
5718              (numberp lines)
5719              (> lines 0)
5720              (numberp (symbol-value 'scroll-margin))
5721              (> (symbol-value 'scroll-margin) 0))
5722     ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5723     ;; too many number of lines if `scroll-margin' is set as two or greater.
5724     (setq lines (min lines
5725                      (max 0 (- (count-lines (window-start) (point-max))
5726                                (symbol-value 'scroll-margin))))))
5727   (condition-case ()
5728       (let ((scroll-in-place nil))
5729         (scroll-up lines))
5730     (end-of-buffer
5731      ;; Long lines may cause an end-of-buffer error.
5732      (goto-char (point-max))))
5733   (gnus-article-beginning-of-window))
5734
5735 (defun gnus-article-prev-page (&optional lines)
5736   "Show previous page of current article.
5737 Argument LINES specifies lines to be scrolled down."
5738   (interactive "p")
5739   (move-to-window-line 0)
5740   (if (and gnus-page-broken
5741            (bobp)
5742            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5743       (progn
5744         (gnus-narrow-to-page -1)        ;Go to previous page.
5745         (goto-char (point-max))
5746         (recenter -1))
5747     (prog1
5748         (condition-case ()
5749             (let ((scroll-in-place nil))
5750               (scroll-down lines))
5751           (beginning-of-buffer
5752            (goto-char (point-min))))
5753       (gnus-article-beginning-of-window))))
5754
5755 (defun gnus-article-only-boring-p ()
5756   "Decide whether there is only boring text remaining in the article.
5757 Something \"interesting\" is a word of at least two letters that does
5758 not have a face in `gnus-article-boring-faces'."
5759   (when (and gnus-article-skip-boring
5760              (boundp 'gnus-article-boring-faces)
5761              (symbol-value 'gnus-article-boring-faces))
5762     (save-excursion
5763       (catch 'only-boring
5764         (while (re-search-forward "\\b\\w\\w" nil t)
5765           (forward-char -1)
5766           (when (not (gnus-intersection
5767                       (gnus-faces-at (point))
5768                       (symbol-value 'gnus-article-boring-faces)))
5769             (throw 'only-boring nil)))
5770         (throw 'only-boring t)))))
5771
5772 (defun gnus-article-refer-article ()
5773   "Read article specified by message-id around point."
5774   (interactive)
5775   (save-excursion
5776     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5777     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5778     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5779         (let ((msg-id (concat "<" (match-string 0) ">")))
5780           (set-buffer gnus-summary-buffer)
5781           (gnus-summary-refer-article msg-id))
5782       (error "No references around point"))))
5783
5784 (defun gnus-article-show-summary ()
5785   "Reconfigure windows to show summary buffer."
5786   (interactive)
5787   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5788       (error "There is no summary buffer for this article buffer")
5789     (gnus-article-set-globals)
5790     (gnus-configure-windows 'article)
5791     (gnus-summary-goto-subject gnus-current-article)
5792     (gnus-summary-position-point)))
5793
5794 (defun gnus-article-describe-briefly ()
5795   "Describe article mode commands briefly."
5796   (interactive)
5797   (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")))
5798
5799 (defun gnus-article-summary-command ()
5800   "Execute the last keystroke in the summary buffer."
5801   (interactive)
5802   (let ((obuf (current-buffer))
5803         (owin (current-window-configuration))
5804         func)
5805     (switch-to-buffer gnus-article-current-summary 'norecord)
5806     (setq func (lookup-key (current-local-map) (this-command-keys)))
5807     (call-interactively func)
5808     (set-buffer obuf)
5809     (set-window-configuration owin)
5810     (set-window-point (get-buffer-window (current-buffer)) (point))))
5811
5812 (defun gnus-article-summary-command-nosave ()
5813   "Execute the last keystroke in the summary buffer."
5814   (interactive)
5815   (let (func)
5816     (pop-to-buffer gnus-article-current-summary 'norecord)
5817     (setq func (lookup-key (current-local-map) (this-command-keys)))
5818     (call-interactively func)))
5819
5820 (defun gnus-article-check-buffer ()
5821   "Beep if not in an article buffer."
5822   (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5823     (error "Command invoked outside of a Gnus article buffer")))
5824
5825 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5826   "Read a summary buffer key sequence and execute it from the article buffer."
5827   (interactive "P")
5828   (gnus-article-check-buffer)
5829   (let ((nosaves
5830          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5831            "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5832            "=" "^" "\M-^" "|"))
5833         (nosave-but-article
5834          '("A\r"))
5835         (nosave-in-article
5836          '("\C-d"))
5837         (up-to-top
5838          '("n" "Gn" "p" "Gp"))
5839         keys new-sum-point)
5840     (save-excursion
5841       (set-buffer gnus-article-current-summary)
5842       (let (gnus-pick-mode)
5843         (push (or key last-command-event) unread-command-events)
5844         (setq keys (static-if (featurep 'xemacs)
5845                        (events-to-keys (read-key-sequence nil))
5846                      (read-key-sequence nil)))))
5847     (message "")
5848
5849     (if (or (member keys nosaves)
5850             (member keys nosave-but-article)
5851             (member keys nosave-in-article))
5852         (let (func)
5853           (save-window-excursion
5854             (pop-to-buffer gnus-article-current-summary 'norecord)
5855             ;; We disable the pick minor mode commands.
5856             (let (gnus-pick-mode)
5857               (setq func (lookup-key (current-local-map) keys))))
5858           (if (or (not func)
5859                   (numberp func))
5860               (ding)
5861             (unless (member keys nosave-in-article)
5862               (set-buffer gnus-article-current-summary))
5863             (call-interactively func)
5864             (setq new-sum-point (point)))
5865           (when (member keys nosave-but-article)
5866             (pop-to-buffer gnus-article-buffer 'norecord)))
5867       ;; These commands should restore window configuration.
5868       (let ((obuf (current-buffer))
5869             (owin (current-window-configuration))
5870             (opoint (point))
5871             win func in-buffer selected new-sum-start new-sum-hscroll)
5872         (cond (not-restore-window
5873                (pop-to-buffer gnus-article-current-summary 'norecord))
5874               ((setq win (get-buffer-window gnus-article-current-summary))
5875                (select-window win))
5876               (t
5877                (switch-to-buffer gnus-article-current-summary 'norecord)))
5878         (setq in-buffer (current-buffer))
5879         ;; We disable the pick minor mode commands.
5880         (if (and (setq func (let (gnus-pick-mode)
5881                               (lookup-key (current-local-map) keys)))
5882                  (functionp func))
5883             (progn
5884               (call-interactively func)
5885               (when (eq win (selected-window))
5886                 (setq new-sum-point (point)
5887                       new-sum-start (window-start win)
5888                       new-sum-hscroll (window-hscroll win)))
5889               (when (eq in-buffer (current-buffer))
5890                 (setq selected (gnus-summary-select-article))
5891                 (set-buffer obuf)
5892                 (unless not-restore-window
5893                   (set-window-configuration owin))
5894                 (when (eq selected 'old)
5895                   (article-goto-body)
5896                   (set-window-start (get-buffer-window (current-buffer))
5897                                     1)
5898                   (set-window-point (get-buffer-window (current-buffer))
5899                                     (point)))
5900                 (when (and (not not-restore-window)
5901                            new-sum-point)
5902                   (set-window-point win new-sum-point)
5903                   (set-window-start win new-sum-start)
5904                   (set-window-hscroll win new-sum-hscroll))))
5905           (set-window-configuration owin)
5906           (ding))))))
5907
5908 (defun gnus-article-describe-key (key)
5909   "Display documentation of the function invoked by KEY.  KEY is a string."
5910   (interactive "kDescribe key: ")
5911   (gnus-article-check-buffer)
5912   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5913       (save-excursion
5914         (set-buffer gnus-article-current-summary)
5915         (let (gnus-pick-mode)
5916           (if (featurep 'xemacs)
5917               (progn
5918                 (push (elt key 0) unread-command-events)
5919                 (setq key (events-to-keys
5920                            (read-key-sequence "Describe key: "))))
5921             (setq unread-command-events
5922                   (mapcar
5923                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5924                    key))
5925             (setq key (read-key-sequence "Describe key: "))))
5926         (describe-key key))
5927     (describe-key key)))
5928
5929 (defun gnus-article-describe-key-briefly (key &optional insert)
5930   "Display documentation of the function invoked by KEY.  KEY is a string."
5931   (interactive "kDescribe key: \nP")
5932   (gnus-article-check-buffer)
5933   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5934       (save-excursion
5935         (set-buffer gnus-article-current-summary)
5936         (let (gnus-pick-mode)
5937           (if (featurep 'xemacs)
5938               (progn
5939                 (push (elt key 0) unread-command-events)
5940                 (setq key (events-to-keys
5941                            (read-key-sequence "Describe key: "))))
5942             (setq unread-command-events
5943                   (mapcar
5944                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5945                    key))
5946             (setq key (read-key-sequence "Describe key: "))))
5947         (describe-key-briefly key insert))
5948     (describe-key-briefly key insert)))
5949
5950 (defun gnus-article-reply-with-original (&optional wide)
5951   "Start composing a reply mail to the current message.
5952 The text in the region will be yanked.  If the region isn't active,
5953 the entire article will be yanked."
5954   (interactive "P")
5955   (let ((article (cdr gnus-article-current))
5956         contents)
5957     (if (not (gnus-region-active-p))
5958         (with-current-buffer gnus-summary-buffer
5959           (gnus-summary-reply (list (list article)) wide))
5960       (setq contents (buffer-substring (point) (mark t)))
5961       ;; Deactivate active regions.
5962       (when (and (boundp 'transient-mark-mode)
5963                  transient-mark-mode)
5964         (setq mark-active nil))
5965       (with-current-buffer gnus-summary-buffer
5966         (gnus-summary-reply
5967          (list (list article contents)) wide)))))
5968
5969 (defun gnus-article-followup-with-original ()
5970   "Compose a followup to the current article.
5971 The text in the region will be yanked.  If the region isn't active,
5972 the entire article will be yanked."
5973   (interactive)
5974   (let ((article (cdr gnus-article-current))
5975         contents)
5976       (if (not (gnus-region-active-p))
5977           (with-current-buffer gnus-summary-buffer
5978             (gnus-summary-followup (list (list article))))
5979         (setq contents (buffer-substring (point) (mark t)))
5980         ;; Deactivate active regions.
5981         (when (and (boundp 'transient-mark-mode)
5982                    transient-mark-mode)
5983           (setq mark-active nil))
5984         (with-current-buffer gnus-summary-buffer
5985           (gnus-summary-followup
5986            (list (list article contents)))))))
5987
5988 (defun gnus-article-hide (&optional arg force)
5989   "Hide all the gruft in the current article.
5990 This means that signatures, cited text and (some) headers will be
5991 hidden.
5992 If given a prefix, show the hidden text instead."
5993   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5994   (gnus-article-hide-headers arg)
5995   (gnus-article-hide-list-identifiers arg)
5996   (gnus-article-hide-citation-maybe arg force)
5997   (gnus-article-hide-signature arg))
5998
5999 (defun gnus-article-maybe-highlight ()
6000   "Do some article highlighting if article highlighting is requested."
6001   (when (gnus-visual-p 'article-highlight 'highlight)
6002     (gnus-article-highlight-some)))
6003
6004 (defun gnus-check-group-server ()
6005   ;; Make sure the connection to the server is alive.
6006   (unless (gnus-server-opened
6007            (gnus-find-method-for-group gnus-newsgroup-name))
6008     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6009     (gnus-request-group gnus-newsgroup-name t)))
6010
6011 (eval-when-compile
6012   (autoload 'nneething-get-file-name "nneething"))
6013
6014 (defun gnus-request-article-this-buffer (article group)
6015   "Get an article and insert it into this buffer."
6016   (let (do-update-line sparse-header)
6017     (prog1
6018         (save-excursion
6019           (erase-buffer)
6020           (gnus-kill-all-overlays)
6021           (setq group (or group gnus-newsgroup-name))
6022
6023           ;; Using `gnus-request-article' directly will insert the article into
6024           ;; `nntp-server-buffer' - so we'll save some time by not having to
6025           ;; copy it from the server buffer into the article buffer.
6026
6027           ;; We only request an article by message-id when we do not have the
6028           ;; headers for it, so we'll have to get those.
6029           (when (stringp article)
6030             (gnus-read-header article))
6031
6032           ;; If the article number is negative, that means that this article
6033           ;; doesn't belong in this newsgroup (possibly), so we find its
6034           ;; message-id and request it by id instead of number.
6035           (when (and (numberp article)
6036                      gnus-summary-buffer
6037                      (get-buffer gnus-summary-buffer)
6038                      (gnus-buffer-exists-p gnus-summary-buffer))
6039             (save-excursion
6040               (set-buffer gnus-summary-buffer)
6041               (let ((header (gnus-summary-article-header article)))
6042                 (when (< article 0)
6043                   (cond
6044                    ((memq article gnus-newsgroup-sparse)
6045                     ;; This is a sparse gap article.
6046                     (setq do-update-line article)
6047                     (setq article (mail-header-id header))
6048                     (setq sparse-header (gnus-read-header article))
6049                     (setq gnus-newsgroup-sparse
6050                           (delq article gnus-newsgroup-sparse)))
6051                    ((vectorp header)
6052                     ;; It's a real article.
6053                     (setq article (mail-header-id header)))
6054                    (t
6055                     ;; It is an extracted pseudo-article.
6056                     (setq article 'pseudo)
6057                     (gnus-request-pseudo-article header))))
6058
6059                 (let ((method (gnus-find-method-for-group
6060                                gnus-newsgroup-name)))
6061                   (when (and (eq (car method) 'nneething)
6062                              (vectorp header))
6063                     (let ((dir (nneething-get-file-name
6064                                 (mail-header-id header))))
6065                       (when (and (stringp dir)
6066                                  (file-directory-p dir))
6067                         (setq article 'nneething)
6068                         (gnus-group-enter-directory dir))))))))
6069
6070           (cond
6071            ;; Refuse to select canceled articles.
6072            ((and (numberp article)
6073                  gnus-summary-buffer
6074                  (get-buffer gnus-summary-buffer)
6075                  (gnus-buffer-exists-p gnus-summary-buffer)
6076                  (eq (cdr (with-current-buffer gnus-summary-buffer
6077                             (assq article gnus-newsgroup-reads)))
6078                      gnus-canceled-mark))
6079             nil)
6080            ;; We first check `gnus-original-article-buffer'.
6081            ((and (get-buffer gnus-original-article-buffer)
6082                  (numberp article)
6083                  (with-current-buffer gnus-original-article-buffer
6084                    (and (equal (car gnus-original-article) group)
6085                         (eq (cdr gnus-original-article) article))))
6086             (insert-buffer-substring gnus-original-article-buffer)
6087             'article)
6088            ;; Check the backlog.
6089            ((and gnus-keep-backlog
6090                  (gnus-backlog-request-article group article (current-buffer)))
6091             'article)
6092            ;; Check asynchronous pre-fetch.
6093            ((gnus-async-request-fetched-article group article (current-buffer))
6094             (gnus-async-prefetch-next group article gnus-summary-buffer)
6095             (when (and (numberp article) gnus-keep-backlog)
6096               (gnus-backlog-enter-article group article (current-buffer)))
6097             'article)
6098            ;; Check the cache.
6099            ((and gnus-use-cache
6100                  (numberp article)
6101                  (gnus-cache-request-article article group))
6102             'article)
6103            ;; Check the agent cache.
6104            ((gnus-agent-request-article article group)
6105             'article)
6106            ;; Get the article and put into the article buffer.
6107            ((or (stringp article)
6108                 (numberp article))
6109             (let ((gnus-override-method gnus-override-method)
6110                   (methods (and (stringp article)
6111                                 gnus-refer-article-method))
6112                   (backend (car (gnus-find-method-for-group
6113                                  gnus-newsgroup-name)))
6114                   result
6115                   (inhibit-read-only t))
6116               (if (or (not (listp methods))
6117                       (and (symbolp (car methods))
6118                            (assq (car methods) nnoo-definition-alist)))
6119                   (setq methods (list methods)))
6120               (when (and (null gnus-override-method)
6121                          methods)
6122                 (setq gnus-override-method (pop methods)))
6123               (while (not result)
6124                 (when (eq gnus-override-method 'current)
6125                   (setq gnus-override-method
6126                         (with-current-buffer gnus-summary-buffer
6127                           gnus-current-select-method)))
6128                 (erase-buffer)
6129                 (gnus-kill-all-overlays)
6130                 (let ((gnus-newsgroup-name group))
6131                   (gnus-check-group-server))
6132                 (cond
6133                  ((gnus-request-article article group (current-buffer))
6134                   (when (numberp article)
6135                     (gnus-async-prefetch-next group article
6136                                               gnus-summary-buffer)
6137                     (when gnus-keep-backlog
6138                       (gnus-backlog-enter-article
6139                        group article (current-buffer))))
6140                   (setq result 'article))
6141                  (methods
6142                   (setq gnus-override-method (pop methods)))
6143                  ((not (string-match "^400 "
6144                                      (nnheader-get-report backend)))
6145                   ;; If we get 400 server disconnect, reconnect and
6146                   ;; retry; otherwise, assume the article has expired.
6147                   (setq result 'done))))
6148               (and (eq result 'article) 'article)))
6149            ;; It was a pseudo.
6150            (t article)))
6151
6152       ;; Associate this article with the current summary buffer.
6153       (setq gnus-article-current-summary gnus-summary-buffer)
6154
6155       ;; Take the article from the original article buffer
6156       ;; and place it in the buffer it's supposed to be in.
6157       (when (and (get-buffer gnus-article-buffer)
6158                  (equal (buffer-name (current-buffer))
6159                         (buffer-name (get-buffer gnus-article-buffer))))
6160         (save-excursion
6161           (if (get-buffer gnus-original-article-buffer)
6162               (set-buffer gnus-original-article-buffer)
6163             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6164             (buffer-disable-undo)
6165             (setq major-mode 'gnus-original-article-mode)
6166             (setq buffer-read-only t))
6167           (let ((inhibit-read-only t))
6168             (erase-buffer)
6169             (insert-buffer-substring gnus-article-buffer))
6170           (setq gnus-original-article (cons group article)))
6171
6172         ;; Decode charsets.
6173         (run-hooks 'gnus-article-decode-hook)
6174         ;; Mark article as decoded or not.
6175         (setq gnus-article-decoded-p gnus-article-decode-hook))
6176
6177       ;; Update sparse articles.
6178       (when (and do-update-line
6179                  (or (numberp article)
6180                      (stringp article)))
6181         (let ((buf (current-buffer)))
6182           (set-buffer gnus-summary-buffer)
6183           (gnus-summary-update-article do-update-line sparse-header)
6184           (gnus-summary-goto-subject do-update-line nil t)
6185           (set-window-point (gnus-get-buffer-window (current-buffer) t)
6186                             (point))
6187           (set-buffer buf))))))
6188
6189 ;;;
6190 ;;; Article editing
6191 ;;;
6192
6193 (defcustom gnus-article-edit-mode-hook nil
6194   "Hook run in article edit mode buffers."
6195   :group 'gnus-article-various
6196   :type 'hook)
6197
6198 (defcustom gnus-article-edit-article-setup-function
6199   'gnus-article-mime-edit-article-setup
6200   "Function called to setup an editing article buffer."
6201   :group 'gnus-article-various
6202   :type 'function)
6203
6204 (defvar gnus-article-edit-done-function nil)
6205
6206 (defvar gnus-article-edit-mode-map nil)
6207
6208 ;; Should we be using derived.el for this?
6209 (unless gnus-article-edit-mode-map
6210   (setq gnus-article-edit-mode-map (make-keymap))
6211   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6212
6213   (gnus-define-keys gnus-article-edit-mode-map
6214     "\C-c?"    describe-mode
6215     "\C-c\C-c" gnus-article-edit-done
6216     "\C-c\C-k" gnus-article-edit-exit
6217     "\C-c\C-f\C-t" message-goto-to
6218     "\C-c\C-f\C-o" message-goto-from
6219     "\C-c\C-f\C-b" message-goto-bcc
6220     ;;"\C-c\C-f\C-w" message-goto-fcc
6221     "\C-c\C-f\C-c" message-goto-cc
6222     "\C-c\C-f\C-s" message-goto-subject
6223     "\C-c\C-f\C-r" message-goto-reply-to
6224     "\C-c\C-f\C-n" message-goto-newsgroups
6225     "\C-c\C-f\C-d" message-goto-distribution
6226     "\C-c\C-f\C-f" message-goto-followup-to
6227     "\C-c\C-f\C-m" message-goto-mail-followup-to
6228     "\C-c\C-f\C-k" message-goto-keywords
6229     "\C-c\C-f\C-u" message-goto-summary
6230     "\C-c\C-f\C-i" message-insert-or-toggle-importance
6231     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6232     "\C-c\C-b" message-goto-body
6233     "\C-c\C-i" message-goto-signature
6234
6235     "\C-c\C-t" message-insert-to
6236     "\C-c\C-n" message-insert-newsgroups
6237     "\C-c\C-o" message-sort-headers
6238     "\C-c\C-e" message-elide-region
6239     "\C-c\C-v" message-delete-not-region
6240     "\C-c\C-z" message-kill-to-signature
6241     "\M-\r" message-newline-and-reformat
6242     "\C-c\C-a" mml-attach-file
6243     "\C-a" message-beginning-of-line
6244     "\t" message-tab
6245     "\M-;" comment-region)
6246
6247   (gnus-define-keys (gnus-article-edit-wash-map
6248                      "\C-c\C-w" gnus-article-edit-mode-map)
6249     "f" gnus-article-edit-full-stops))
6250
6251 (easy-menu-define
6252   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6253   '("Field"
6254     ["Fetch To" message-insert-to t]
6255     ["Fetch Newsgroups" message-insert-newsgroups t]
6256     "----"
6257     ["To" message-goto-to t]
6258     ["From" message-goto-from t]
6259     ["Subject" message-goto-subject t]
6260     ["Cc" message-goto-cc t]
6261     ["Reply-To" message-goto-reply-to t]
6262     ["Summary" message-goto-summary t]
6263     ["Keywords" message-goto-keywords t]
6264     ["Newsgroups" message-goto-newsgroups t]
6265     ["Followup-To" message-goto-followup-to t]
6266     ["Mail-Followup-To" message-goto-mail-followup-to t]
6267     ["Distribution" message-goto-distribution t]
6268     ["Body" message-goto-body t]
6269     ["Signature" message-goto-signature t]))
6270
6271 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6272   "Major mode for editing articles.
6273 This is an extended text-mode.
6274
6275 \\{gnus-article-edit-mode-map}"
6276   (make-local-variable 'gnus-article-edit-done-function)
6277   (make-local-variable 'gnus-prev-winconf)
6278   (set (make-local-variable 'font-lock-defaults)
6279        '(message-font-lock-keywords t))
6280   (set (make-local-variable 'mail-header-separator) "")
6281   (set (make-local-variable 'gnus-article-edit-mode) t)
6282   (easy-menu-add message-mode-field-menu message-mode-map)
6283   (setq buffer-read-only nil)
6284   (buffer-enable-undo)
6285   (widen))
6286
6287 (defun gnus-article-edit (&optional force)
6288   "Edit the current article.
6289 This will have permanent effect only in mail groups.
6290 If FORCE is non-nil, allow editing of articles even in read-only
6291 groups."
6292   (interactive "P")
6293   (when (and (not force)
6294              (gnus-group-read-only-p))
6295     (error "The current newsgroup does not support article editing"))
6296   (gnus-article-date-original)
6297   (gnus-article-edit-article
6298    'ignore
6299    `(lambda (no-highlight)
6300       'ignore
6301       (gnus-summary-edit-article-done
6302        ,(or (mail-header-references gnus-current-headers) "")
6303        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6304
6305 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6306   "Start editing the contents of the current article buffer."
6307   (let ((winconf (current-window-configuration)))
6308     (set-buffer gnus-article-buffer)
6309     (let ((message-auto-save-directory
6310            ;; Don't associate the article buffer with a draft file.
6311            nil))
6312       (gnus-article-edit-mode))
6313     (funcall start-func)
6314     (set-buffer-modified-p nil)
6315     (gnus-configure-windows 'edit-article)
6316     (setq gnus-article-edit-done-function exit-func)
6317     (setq gnus-prev-winconf winconf)
6318     (when gnus-article-edit-article-setup-function
6319       (funcall gnus-article-edit-article-setup-function))
6320     (unless quiet
6321       (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit"))))
6322
6323 (defun gnus-article-edit-done (&optional arg)
6324   "Update the article edits and exit."
6325   (interactive "P")
6326   (let ((func gnus-article-edit-done-function)
6327         (buf (current-buffer))
6328         (start (window-start))
6329         (p (point))
6330         (winconf gnus-prev-winconf))
6331     (remove-hook 'gnus-article-mode-hook
6332                  'gnus-article-mime-edit-article-unwind)
6333     (widen) ;; Widen it in case that users narrowed the buffer.
6334     (funcall func arg)
6335     (set-buffer buf)
6336     ;; The cache and backlog have to be flushed somewhat.
6337     (when gnus-keep-backlog
6338       (gnus-backlog-remove-article
6339        (car gnus-article-current) (cdr gnus-article-current)))
6340     ;; Flush original article as well.
6341     (save-excursion
6342       (when (get-buffer gnus-original-article-buffer)
6343         (set-buffer gnus-original-article-buffer)
6344         (setq gnus-original-article nil)))
6345     (when gnus-use-cache
6346       (gnus-cache-update-article
6347        (car gnus-article-current) (cdr gnus-article-current)))
6348     ;; We remove all text props from the article buffer.
6349     (kill-all-local-variables)
6350     (set-text-properties (point-min) (point-max) nil)
6351     (gnus-article-mode)
6352     (set-window-configuration winconf)
6353     (set-buffer buf)
6354     (set-window-start (get-buffer-window buf) start)
6355     (set-window-point (get-buffer-window buf) (point)))
6356   (gnus-summary-show-article))
6357
6358 (defun gnus-article-edit-exit ()
6359   "Exit the article editing without updating."
6360   (interactive)
6361   (when (or (not (buffer-modified-p))
6362             (yes-or-no-p "Article modified; kill anyway? "))
6363     (let ((curbuf (current-buffer))
6364           (p (point))
6365           (window-start (window-start)))
6366       (erase-buffer)
6367       (if (gnus-buffer-live-p gnus-original-article-buffer)
6368           (insert-buffer-substring gnus-original-article-buffer))
6369       (let ((winconf gnus-prev-winconf))
6370         (kill-all-local-variables)
6371         (gnus-article-mode)
6372         (set-window-configuration winconf)
6373         ;; Tippy-toe some to make sure that point remains where it was.
6374         (save-current-buffer
6375           (set-buffer curbuf)
6376           (set-window-start (get-buffer-window (current-buffer)) window-start)
6377           (goto-char p))))
6378     (gnus-summary-show-article)))
6379
6380 (defun gnus-article-edit-full-stops ()
6381   "Interactively repair spacing at end of sentences."
6382   (interactive)
6383   (save-excursion
6384     (goto-char (point-min))
6385     (search-forward-regexp "^$" nil t)
6386     (let ((case-fold-search nil))
6387       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6388
6389 ;;;
6390 ;;; Article editing with MIME-Edit
6391 ;;;
6392
6393 (defcustom gnus-article-mime-edit-article-setup-hook nil
6394   "Hook run after setting up a MIME editing article buffer."
6395   :group 'gnus-article-various
6396   :type 'hook)
6397
6398 (defun gnus-article-mime-edit-article-unwind ()
6399   "Unwind `gnus-article-buffer' if article editing was given up."
6400   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6401   (when (featurep 'font-lock)
6402     (setq font-lock-defaults nil)
6403     (font-lock-mode -1))
6404   (when mime-edit-mode-flag
6405     (mime-edit-exit 'nomime 'no-error)
6406     (message "")))
6407
6408 (defun gnus-article-mime-edit-article-setup ()
6409   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
6410 after replacing with the original article."
6411   (setq gnus-show-mime t)
6412   (setq gnus-article-edit-done-function
6413         `(lambda (&rest args)
6414            (when mime-edit-mode-flag
6415              (let (mime-edit-insert-user-agent-field)
6416                (mime-edit-exit))
6417              (message ""))
6418            (goto-char (point-min))
6419            (let (case-fold-search)
6420              (when (re-search-forward
6421                     (format "^%s$" (regexp-quote mail-header-separator))
6422                     nil t)
6423                (replace-match "")))
6424            (apply ,gnus-article-edit-done-function args)
6425            (insert
6426             (prog1
6427                 (buffer-substring-no-properties (point-min) (point-max))
6428               (set-buffer (get-buffer-create gnus-original-article-buffer))
6429               (erase-buffer)))
6430            (setq gnus-current-headers (gnus-article-make-full-mail-header))
6431            (set-buffer gnus-article-buffer)
6432            (gnus-article-prepare-display)))
6433   (substitute-key-definition 'gnus-article-edit-done
6434                              'gnus-article-mime-edit-done
6435                              gnus-article-edit-mode-map)
6436   (substitute-key-definition 'gnus-article-edit-exit
6437                              'gnus-article-mime-edit-exit
6438                              gnus-article-edit-mode-map)
6439   (erase-buffer)
6440   (insert-buffer-substring gnus-original-article-buffer)
6441   (unless (member (with-current-buffer gnus-summary-buffer
6442                     gnus-newsgroup-name)
6443                   '("nndraft:delayed" "nndraft:drafts"))
6444     (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
6445       (fset 'mime-edit-decode-single-part-in-buffer
6446             (lambda (&rest args)
6447               (if (let ((content-type (car args)))
6448                     (and (eq 'message (mime-content-type-primary-type
6449                                        content-type))
6450                          (eq 'rfc822 (mime-content-type-subtype
6451                                       content-type))))
6452                   (setcar (cdr args) 'not-decode-text))
6453               (apply ofn args)))
6454       (unwind-protect
6455           (mime-edit-again)
6456         (fset 'mime-edit-decode-single-part-in-buffer ofn))))
6457   (when (featurep 'font-lock)
6458     (set (make-local-variable 'font-lock-defaults)
6459          '(message-font-lock-keywords t))
6460     (font-lock-set-defaults)
6461     (turn-on-font-lock))
6462   (set-buffer-modified-p nil)
6463   (delete-other-windows)
6464   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6465   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
6466
6467 (defun gnus-article-mime-edit-done (&optional arg)
6468   "Update the article MIME edits and exit."
6469   (interactive "P")
6470   (when (featurep 'font-lock)
6471     (setq font-lock-defaults nil)
6472     (font-lock-mode -1))
6473   (let ((inhibit-read-only t))
6474     (gnus-article-edit-done arg)))
6475
6476 (defun gnus-article-mime-edit-exit ()
6477   "Exit the article MIME editing without updating."
6478   (interactive)
6479   (when (or (not (buffer-modified-p))
6480             (yes-or-no-p "Article modified; kill anyway? "))
6481     (when (featurep 'font-lock)
6482       (setq font-lock-defaults nil)
6483       (font-lock-mode -1))
6484     (when mime-edit-mode-flag
6485       (let (mime-edit-insert-user-agent-field)
6486         (mime-edit-exit))
6487       (message ""))
6488     (goto-char (point-min))
6489     (let (case-fold-search)
6490       (when (re-search-forward
6491              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
6492         (replace-match "")))
6493     (let ((winconf gnus-prev-winconf))
6494       (insert (prog1
6495                   (buffer-substring-no-properties (point-min) (point-max))
6496                 (set-buffer (get-buffer-create gnus-original-article-buffer))
6497                 (erase-buffer)))
6498       (setq gnus-current-headers (gnus-article-make-full-mail-header))
6499       (set-buffer gnus-article-buffer)
6500       (gnus-article-prepare-display)
6501       (set-window-configuration winconf))))
6502
6503 ;;;
6504 ;;; Article highlights
6505 ;;;
6506
6507 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6508
6509 ;;; Internal Variables:
6510
6511 (defcustom gnus-button-url-regexp
6512   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6513       "\\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:]]\\)"
6514     "\\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\\)\\)")
6515   "Regular expression that matches URLs."
6516   :group 'gnus-article-buttons
6517   :type 'regexp)
6518
6519 (defcustom gnus-button-valid-fqdn-regexp
6520   message-valid-fqdn-regexp
6521   "Regular expression that matches a valid FQDN."
6522   :version "22.1"
6523   :group 'gnus-article-buttons
6524   :type 'regexp)
6525
6526 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6527 (defcustom gnus-button-valid-localpart-regexp
6528   "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
6529   "Regular expression that matches a localpart of mail addresses or MIDs."
6530   :version "22.1"
6531   :group 'gnus-article-buttons
6532   :type 'regexp)
6533
6534 (defcustom gnus-button-man-handler 'manual-entry
6535   "Function to use for displaying man pages.
6536 The function must take at least one argument with a string naming the
6537 man page."
6538   :version "22.1"
6539   :type '(choice (function-item :tag "Man" manual-entry)
6540                  (function-item :tag "Woman" woman)
6541                  (function :tag "Other"))
6542   :group 'gnus-article-buttons)
6543
6544 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6545   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6546 If the default site is too slow, try to find a CTAN mirror, see
6547 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
6548 the variable `gnus-button-handle-ctan'."
6549   :version "22.1"
6550   :group 'gnus-article-buttons
6551   :link '(custom-manual "(gnus)Group Parameters")
6552   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6553                  (const "http://tug.ctan.org/tex-archive/")
6554                  (const "http://www.dante.de/CTAN/")
6555                  (string :tag "Other")))
6556
6557 (defcustom gnus-button-ctan-handler 'browse-url
6558   "Function to use for displaying CTAN links.
6559 The function must take one argument, the string naming the URL."
6560   :version "22.1"
6561   :type '(choice (function-item :tag "Browse Url" browse-url)
6562                  (function :tag "Other"))
6563   :group 'gnus-article-buttons)
6564
6565 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6566   "Bogus strings removed from CTAN URLs."
6567   :version "22.1"
6568   :group 'gnus-article-buttons
6569   :type '(choice (const "^/?tex-archive/\\|/")
6570                  (regexp :tag "Other")))
6571
6572 (defcustom gnus-button-ctan-directory-regexp
6573   (regexp-opt
6574    (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6575          "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6576          "languages" "macros" "nonfree" "obsolete" "support" "systems"
6577          "tds" "tools" "usergrps" "web") t)
6578   "Regular expression for ctan directories.
6579 It should match all directories in the top level of `gnus-ctan-url'."
6580   :version "22.1"
6581   :group 'gnus-article-buttons
6582   :type 'regexp)
6583
6584 (defcustom gnus-button-mid-or-mail-regexp
6585   (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6586           gnus-button-valid-fqdn-regexp
6587           ">?\\)\\b")
6588   "Regular expression that matches a message ID or a mail address."
6589   :version "22.1"
6590   :group 'gnus-article-buttons
6591   :type 'regexp)
6592
6593 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6594   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6595 Strings like this can be either a message ID or a mail address.  If it is one
6596 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6597 message ID or a mail address, respectively.  If this variable is set to the
6598 symbol `ask', always query the user what do do.  If it is a function, this
6599 function will be called with the string as it's only argument.  The function
6600 must return `mid', `mail', `invalid' or `ask'."
6601   :version "22.1"
6602   :group 'gnus-article-buttons
6603   :type '(choice (function-item :tag "Heuristic function"
6604                                 gnus-button-mid-or-mail-heuristic)
6605                  (const ask)
6606                  (const mid)
6607                  (const mail)))
6608
6609 (defcustom gnus-button-mid-or-mail-heuristic-alist
6610   '((-10.0 . ".+\\$.+@")
6611     (-10.0 . "#")
6612     (-10.0 . "\\*")
6613     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
6614     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6615     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6616     (-1.0  . "^[^a-z]+@")
6617     ;;
6618     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6619     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6620     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
6621     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6622     ;;
6623     (-2.0  . "^[0-9]")
6624     (-1.0  . "^[0-9][0-9]")
6625     ;;
6626     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6627     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6628     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6629     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6630     ;;
6631     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6632     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6633     ;;       "[0-9]{8,}.*\@"
6634     (-3.0
6635      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6636     ;; "[0-9]{12,}.*\@"
6637     ;; compensation for TDMA dated mail addresses:
6638     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6639     ;;
6640     (-20.0 . "\\.fsf@") ;; Gnus
6641     (-20.0 . "^slrn")
6642     (-20.0 . "^Pine")
6643     (-20.0 . "_-_") ;; Subject change in thread
6644     ;;
6645     (-20.0 . "\\.ln@") ;; leafnode
6646     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6647     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6648     ;;
6649     ;; (5.0 . "") ;; $local_part_len <= 7
6650     (10.0  . "^[^0-9]+@")
6651     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6652     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6653     (3.0   . "\@stud")
6654     ;;
6655     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
6656     ;;
6657     (0.5   . "^[A-Z][a-z]")
6658     (0.5   . "^[A-Z][a-z][a-z]")
6659     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6660     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6661   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6662
6663 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6664 address.  The REGEXP is processed with `case-fold-search' set to nil."
6665   :version "22.1"
6666   :group 'gnus-article-buttons
6667   :type '(repeat (cons (number :tag "Rate")
6668                        (regexp :tag "Regexp"))))
6669
6670 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6671   "Guess whether MID-OR-MAIL is a message ID or a mail address.
6672 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6673 address, `ask' if unsure and `invalid' if the string is invalid."
6674   (let ((case-fold-search nil)
6675         (list gnus-button-mid-or-mail-heuristic-alist)
6676         (result 0) rate regexp lpartlen elem)
6677     (setq lpartlen
6678           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6679     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6680     ;; Certain special cases...
6681     (when (string-match
6682            (concat
6683             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6684             "^[0-9]+\\.[0-9]+@compuserve\\|"
6685             "@public\\.gmane\\.org")
6686            mid-or-mail)
6687       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6688       (setq result 'mail))
6689     (when (string-match "@.*@\\| " mid-or-mail)
6690       (gnus-message 8 "`%s' is invalid." mid-or-mail)
6691       (setq result 'invalid))
6692     ;; Nothing more to do, if result is not a number here...
6693     (when (numberp result)
6694       (while list
6695         (setq elem (car list)
6696               rate (car elem)
6697               regexp (cdr elem)
6698               list (cdr list))
6699         (when (string-match regexp mid-or-mail)
6700           (setq result (+ result rate))
6701           (gnus-message
6702            9 "`%s' matched `%s', rate `%s', result `%s'."
6703            mid-or-mail regexp rate result)))
6704       (when (<= lpartlen 7)
6705         (setq result (+ result 5.0))
6706         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6707                       mid-or-mail result))
6708       (when (>= lpartlen 12)
6709         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6710         (cond
6711          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6712           ;; Long local part should contain realname if e-mail address,
6713           ;; too many digits: message-id.
6714           ;; $score -= 5.0 + 0.1 * $local_part_len;
6715           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6716           (setq result (+ result rate))
6717           (gnus-message
6718            9 "Many digits in `%s', rate `%s', result `%s'."
6719            mid-or-mail rate result))
6720          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6721                         mid-or-mail)
6722           ;; Too few vowels [^aeiouy]{4,}.*\@
6723           (setq result (+ result -5.0))
6724           (gnus-message
6725            9 "Few vowels in `%s', rate `%s', result `%s'."
6726            mid-or-mail -5.0 result))
6727          (t
6728           (setq result (+ result 5.0))
6729           (gnus-message
6730            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6731     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6732     ;; Maybe we should make this a customizable alist: (condition . 'result)
6733     (cond
6734      ((symbolp result) result)
6735      ;; Now convert number into proper results:
6736      ((< result -10.0) 'mid)
6737      ((> result  10.0) 'mail)
6738      (t 'ask))))
6739
6740 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6741   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6742          (url-mid (concat "news" ":" mid-or-mail))
6743          (url-mailto (concat "mailto" ":" mid-or-mail)))
6744     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6745     (when (fboundp pref)
6746       (setq guessed
6747             ;; get rid of surrounding angles...
6748             (funcall pref
6749                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6750       (if (or (eq 'mid guessed) (eq 'mail guessed))
6751           (setq pref guessed)
6752         (setq pref 'ask)))
6753     (if (eq pref 'ask)
6754         (save-window-excursion
6755           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6756               (setq pref 'mail)
6757             (setq pref 'mid))))
6758     (cond ((eq pref 'mid)
6759            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6760            (gnus-button-handle-news url-mid))
6761           ((eq pref 'mail)
6762            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
6763            (gnus-url-mailto url-mailto))
6764           (t (gnus-message 3 "Invalid string.")))))
6765
6766 (defun gnus-button-handle-custom (url)
6767   "Follow a Custom URL."
6768   (customize-apropos (gnus-url-unhex-string url)))
6769
6770 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6771
6772 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6773 ;; stuff?
6774
6775 (defun gnus-button-handle-describe-function (url)
6776   "Call `describe-function' when pushing the corresponding URL button."
6777   (describe-function
6778    (intern
6779     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6780
6781 (defun gnus-button-handle-describe-variable (url)
6782   "Call `describe-variable' when pushing the corresponding URL button."
6783   (describe-variable
6784    (intern
6785     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6786
6787 (defun gnus-button-handle-symbol (url)
6788 "Display help on variable or function.
6789 Calls `describe-variable' or `describe-function'."
6790   (let ((sym (intern url)))
6791     (cond
6792      ((fboundp sym) (describe-function sym))
6793      ((boundp sym) (describe-variable sym))
6794      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6795
6796 (defun gnus-button-handle-describe-key (url)
6797   "Call `describe-key' when pushing the corresponding URL button."
6798   (let* ((key-string
6799           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6800          (keys (ignore-errors (eval `(kbd ,key-string)))))
6801     (if keys
6802         (describe-key keys)
6803       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6804
6805 (defun gnus-button-handle-apropos (url)
6806   "Call `apropos' when pushing the corresponding URL button."
6807   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6808
6809 (defun gnus-button-handle-apropos-command (url)
6810   "Call `apropos' when pushing the corresponding URL button."
6811   (apropos-command
6812    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6813
6814 (defun gnus-button-handle-apropos-variable (url)
6815   "Call `apropos' when pushing the corresponding URL button."
6816   (funcall
6817    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6818    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6819
6820 (defun gnus-button-handle-apropos-documentation (url)
6821   "Call `apropos' when pushing the corresponding URL button."
6822   (funcall
6823    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6824    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6825
6826 (defun gnus-button-handle-library (url)
6827   "Call `locate-library' when pushing the corresponding URL button."
6828   (gnus-message 9 "url=`%s'" url)
6829   (let* ((lib (locate-library url))
6830          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6831     (if (not lib)
6832         (gnus-message 1 "Cannot locale library `%s'." url)
6833       (find-file-read-only file))))
6834
6835 (defun gnus-button-handle-ctan (url)
6836   "Call `browse-url' when pushing a CTAN URL button."
6837   (funcall
6838    gnus-button-ctan-handler
6839    (concat
6840     gnus-ctan-url
6841     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6842
6843 (defcustom gnus-button-tex-level 5
6844   "*Integer that says how many TeX-related buttons Gnus will show.
6845 The higher the number, the more buttons will appear and the more false
6846 positives are possible.  Note that you can set this variable local to
6847 specific groups.  Setting it higher in TeX groups is probably a good idea.
6848 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6849 how to set variables in specific groups."
6850   :version "22.1"
6851   :group 'gnus-article-buttons
6852   :link '(custom-manual "(gnus)Group Parameters")
6853   :type 'integer)
6854
6855 (defcustom gnus-button-man-level 5
6856   "*Integer that says how many man-related buttons Gnus will show.
6857 The higher the number, the more buttons will appear and the more false
6858 positives are possible.  Note that you can set this variable local to
6859 specific groups.  Setting it higher in Unix groups is probably a good idea.
6860 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6861 how to set variables in specific groups."
6862   :version "22.1"
6863   :group 'gnus-article-buttons
6864   :link '(custom-manual "(gnus)Group Parameters")
6865   :type 'integer)
6866
6867 (defcustom gnus-button-emacs-level 5
6868   "*Integer that says how many emacs-related buttons Gnus will show.
6869 The higher the number, the more buttons will appear and the more false
6870 positives are possible.  Note that you can set this variable local to
6871 specific groups.  Setting it higher in Emacs or Gnus related groups is
6872 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
6873 `gnus-parameters' on how to set variables in specific groups."
6874   :version "22.1"
6875   :group 'gnus-article-buttons
6876   :link '(custom-manual "(gnus)Group Parameters")
6877   :type 'integer)
6878
6879 (defcustom gnus-button-message-level 5
6880   "*Integer that says how many buttons for news or mail messages will appear.
6881 The higher the number, the more buttons will appear and the more false
6882 positives are possible."
6883   ;; mail addresses, MIDs, URLs for news, ...
6884   :version "22.1"
6885   :group 'gnus-article-buttons
6886   :type 'integer)
6887
6888 (defcustom gnus-button-browse-level 5
6889   "*Integer that says how many buttons for browsing will appear.
6890 The higher the number, the more buttons will appear and the more false
6891 positives are possible."
6892   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6893   :version "22.1"
6894   :group 'gnus-article-buttons
6895   :type 'integer)
6896
6897 (defcustom gnus-button-alist
6898   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6899      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6900     ((concat "\\b\\(nntp\\|news\\):\\("
6901              gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6902      0 t gnus-button-handle-news 2)
6903     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6904      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6905     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6906      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6907     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6908     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6909      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6910     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6911      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6912     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6913      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6914     ;; RFC 2368 (The mailto URL scheme)
6915     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6916      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6917     ("\\bmailto:\\([^ \n\t]+\\)"
6918      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6919     ;; CTAN
6920     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6921              gnus-button-ctan-directory-regexp
6922              "[^][>)!;:,'\n\t ]+\\)")
6923      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6924     ((concat "\\btex-archive/\\("
6925              gnus-button-ctan-directory-regexp
6926              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6927      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6928     ((concat
6929       "\\b\\("
6930       gnus-button-ctan-directory-regexp
6931       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6932      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6933     ;; This is info (home-grown style) <info://foo/bar+baz>
6934     ("\\binfo://\\([^'\">\n\t ]+\\)"
6935      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6936     ;; Info GNOME style <info:foo#bar_baz>
6937     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6938      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6939     ;; Info KDE style <info:(foo)bar baz>
6940     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6941      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6942     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6943      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6944     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6945      ;; Info links like `C-h i d m CC Mode RET'
6946      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6947     ;; This is custom
6948     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6949      0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6950     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6951      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6952     ;; Emacs help commands
6953     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6954      ;; regexp doesn't match arguments containing ` '.
6955      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6956     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6957      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6958     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6959      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6960     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6961      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6962     ;; The following entries may lead to many false positives so don't enable
6963     ;; them by default (use a high button level).
6964     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6965      ;; Exclude [.?] for URLs in gmane.emacs.cvs
6966      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6967     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6968      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6969     ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6970      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6971     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6972      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6973     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6974      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6975     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6976      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6977     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6978      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6979     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6980      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6981     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6982      ;; Unlike the other regexps we really have to require quoting
6983      ;; here to determine where it ends.
6984      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6985     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6986     ("<URL: *\\([^<>]*\\)>"
6987      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6988     ;; RFC 2396 (2.4.3., delims) ...
6989     ("\"URL: *\\([^\"]*\\)\""
6990      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6991     ;; RFC 2396 (2.4.3., delims) ...
6992     ("\"URL: *\\([^\"]*\\)\""
6993      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6994     ;; Raw URLs.
6995     (gnus-button-url-regexp
6996      0 (>= gnus-button-browse-level 0) browse-url 0)
6997     ;; man pages
6998     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6999      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7000      gnus-button-handle-man 1)
7001     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7002     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7003      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7004      gnus-button-handle-man 1)
7005     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7006     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7007     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7008      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7009     ;; MID or mail: To avoid too many false positives we don't try to catch
7010     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
7011     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
7012     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
7013     ;; so that non-ambiguous entries (see above) match first.
7014     (gnus-button-mid-or-mail-regexp
7015      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7016   "*Alist of regexps matching buttons in article bodies.
7017
7018 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7019 REGEXP: is the string (case insensitive) matching text around the button (can
7020 also be Lisp expression evaluating to a string),
7021 BUTTON: is the number of the regexp grouping actually matching the button,
7022 FORM: is a Lisp expression which must eval to true for the button to
7023 be added,
7024 CALLBACK: is the function to call when the user push this button, and each
7025 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7026
7027 CALLBACK can also be a variable, in that case the value of that
7028 variable it the real callback function."
7029   :group 'gnus-article-buttons
7030   :type '(repeat (list (choice regexp variable sexp)
7031                        (integer :tag "Button")
7032                        (sexp :tag "Form")
7033                        (function :tag "Callback")
7034                        (repeat :tag "Par"
7035                                :inline t
7036                                (integer :tag "Regexp group")))))
7037
7038 (defcustom gnus-header-button-alist
7039   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7040      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7041     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7042      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7043     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7044      0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7045     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7046      0 (>= gnus-button-browse-level 0) browse-url 0)
7047     ("^Subject:" gnus-button-url-regexp
7048      0 (>= gnus-button-browse-level 0) browse-url 0)
7049     ("^[^:]+:" gnus-button-url-regexp
7050      0 (>= gnus-button-browse-level 0) browse-url 0)
7051     ("^OpenPGP:.*url=" gnus-button-url-regexp
7052      0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7053     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7054      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7055     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7056      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7057   "*Alist of headers and regexps to match buttons in article heads.
7058
7059 This alist is very similar to `gnus-button-alist', except that each
7060 alist has an additional HEADER element first in each entry:
7061
7062 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7063
7064 HEADER is a regexp to match a header.  For a fuller explanation, see
7065 `gnus-button-alist'."
7066   :group 'gnus-article-buttons
7067   :group 'gnus-article-headers
7068   :type '(repeat (list (regexp :tag "Header")
7069                        (choice regexp variable)
7070                        (integer :tag "Button")
7071                        (sexp :tag "Form")
7072                        (function :tag "Callback")
7073                        (repeat :tag "Par"
7074                                :inline t
7075                                (integer :tag "Regexp group")))))
7076
7077 ;;; Commands:
7078
7079 (defun gnus-article-push-button (event)
7080   "Check text under the mouse pointer for a callback function.
7081 If the text under the mouse pointer has a `gnus-callback' property,
7082 call it with the value of the `gnus-data' text property."
7083   (interactive "e")
7084   (set-buffer (window-buffer (posn-window (event-start event))))
7085   (let* ((pos (posn-point (event-start event)))
7086          (data (get-text-property pos 'gnus-data))
7087          (fun (get-text-property pos 'gnus-callback)))
7088     (goto-char pos)
7089     (when fun
7090       (funcall fun data))))
7091
7092 (defun gnus-article-press-button ()
7093   "Check text at point for a callback function.
7094 If the text at point has a `gnus-callback' property,
7095 call it with the value of the `gnus-data' text property."
7096   (interactive)
7097   (let ((data (get-text-property (point) 'gnus-data))
7098         (fun (get-text-property (point) 'gnus-callback)))
7099     (when fun
7100       (funcall fun data))))
7101
7102 (defun gnus-article-prev-button (n)
7103   "Move point to N buttons backward.
7104 If N is negative, move forward instead."
7105   (interactive "p")
7106   (gnus-article-next-button (- n)))
7107
7108 (defun gnus-article-next-button (n)
7109   "Move point to N buttons forward.
7110 If N is negative, move backward instead."
7111   (interactive "p")
7112   (let ((function (if (< n 0) 'previous-single-property-change
7113                     'next-single-property-change))
7114         (inhibit-point-motion-hooks t)
7115         (backward (< n 0))
7116         (limit (if (< n 0) (point-min) (point-max))))
7117     (setq n (abs n))
7118     (while (and (not (= limit (point)))
7119                 (> n 0))
7120       ;; Skip past the current button.
7121       (when (get-text-property (point) 'gnus-callback)
7122         (goto-char (funcall function (point) 'gnus-callback nil limit)))
7123       ;; Go to the next (or previous) button.
7124       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
7125       ;; Put point at the start of the button.
7126       (when (and backward (not (get-text-property (point) 'gnus-callback)))
7127         (goto-char (funcall function (point) 'gnus-callback nil limit)))
7128       ;; Skip past intangible buttons.
7129       (when (get-text-property (point) 'intangible)
7130         (incf n))
7131       (decf n))
7132     (unless (zerop n)
7133       (gnus-message 5 "No more buttons"))
7134     n))
7135
7136 (defun gnus-article-highlight (&optional force)
7137   "Highlight current article.
7138 This function calls `gnus-article-highlight-headers',
7139 `gnus-article-highlight-citation',
7140 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7141 do the highlighting.  See the documentation for those functions."
7142   (interactive (list 'force))
7143   (gnus-article-highlight-headers)
7144   (gnus-article-highlight-citation force)
7145   (gnus-article-highlight-signature)
7146   (gnus-article-add-buttons force)
7147   (gnus-article-add-buttons-to-head))
7148
7149 (defun gnus-article-highlight-some (&optional force)
7150   "Highlight current article.
7151 This function calls `gnus-article-highlight-headers',
7152 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7153 do the highlighting.  See the documentation for those functions."
7154   (interactive (list 'force))
7155   (gnus-article-highlight-headers)
7156   (gnus-article-highlight-signature)
7157   (gnus-article-add-buttons))
7158
7159 (defun gnus-article-highlight-headers ()
7160   "Highlight article headers as specified by `gnus-header-face-alist'."
7161   (interactive)
7162   (gnus-with-article-headers
7163     (let (regexp header-face field-face from hpoints fpoints)
7164       (dolist (entry gnus-header-face-alist)
7165         (goto-char (point-min))
7166         (setq regexp (concat "^\\("
7167                              (if (string-equal "" (nth 0 entry))
7168                                  "[^\t ]"
7169                                (nth 0 entry))
7170                              "\\)")
7171               header-face (nth 1 entry)
7172               field-face (nth 2 entry))
7173         (while (and (re-search-forward regexp nil t)
7174                     (not (eobp)))
7175           (beginning-of-line)
7176           (setq from (point))
7177           (unless (search-forward ":" nil t)
7178             (forward-char 1))
7179           (when (and header-face
7180                      (not (memq (point) hpoints)))
7181             (push (point) hpoints)
7182             (gnus-put-text-property from (point) 'face header-face))
7183           (when (and field-face
7184                      (not (memq (setq from (point)) fpoints)))
7185             (push from fpoints)
7186             (if (re-search-forward "^[^ \t]" nil t)
7187                 (forward-char -2)
7188               (goto-char (point-max)))
7189             (gnus-put-text-property from (point) 'face field-face)))))))
7190
7191 (defun gnus-article-highlight-signature ()
7192   "Highlight the signature in an article.
7193 It does this by highlighting everything after
7194 `gnus-signature-separator' using the face `gnus-signature'."
7195   (interactive)
7196   (when gnus-signature-face
7197     (gnus-with-article-buffer
7198       (let ((inhibit-point-motion-hooks t))
7199         (save-restriction
7200           (when (gnus-article-narrow-to-signature)
7201             (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
7202                               'face gnus-signature-face)))))))
7203
7204 (defun gnus-article-buttonize-signature ()
7205   "Add button to the signature."
7206   (interactive)
7207   (save-excursion
7208     (set-buffer gnus-article-buffer)
7209     (let ((inhibit-read-only t)
7210           (inhibit-point-motion-hooks t))
7211       (when (gnus-article-search-signature)
7212         (gnus-article-add-button (match-beginning 0) (match-end 0)
7213                                  'gnus-signature-toggle
7214                                  (set-marker (make-marker)
7215                                              (1+ (match-end 0))))))))
7216
7217 (defun gnus-button-in-region-p (b e prop)
7218   "Say whether PROP exists in the region."
7219   (text-property-not-all b e prop nil))
7220
7221 (defun gnus-article-add-buttons (&optional force)
7222   "Find external references in the article and make buttons of them.
7223 \"External references\" are things like Message-IDs and URLs, as
7224 specified by `gnus-button-alist'."
7225   (interactive (list 'force))
7226   (gnus-with-article-buffer
7227     (let ((inhibit-point-motion-hooks t)
7228           (case-fold-search t)
7229           (alist gnus-button-alist)
7230           beg entry regexp)
7231       ;; Remove all old markers.
7232       (let (marker entry new-list)
7233         (while (setq marker (pop gnus-button-marker-list))
7234           (if (or (< marker (point-min)) (>= marker (point-max)))
7235               (push marker new-list)
7236             (goto-char marker)
7237             (when (setq entry (gnus-button-entry))
7238               (put-text-property (match-beginning (nth 1 entry))
7239                                  (match-end (nth 1 entry))
7240                                  'gnus-callback nil))
7241             (set-marker marker nil)))
7242         (setq gnus-button-marker-list new-list))
7243       ;; We skip the headers.
7244       (article-goto-body)
7245       (setq beg (point))
7246       (while (setq entry (pop alist))
7247         (setq regexp (eval (car entry)))
7248         (goto-char beg)
7249         (while (re-search-forward regexp nil t)
7250           (let* ((start (and entry (match-beginning (nth 1 entry))))
7251                  (end (and entry (match-end (nth 1 entry))))
7252                  (from (match-beginning 0)))
7253             (when (and (or (eq t (nth 2 entry))
7254                            (eval (nth 2 entry)))
7255                        (not (gnus-button-in-region-p
7256                              start end 'gnus-callback)))
7257               ;; That optional form returned non-nil, so we add the
7258               ;; button.
7259               (gnus-article-add-button
7260                start end 'gnus-button-push
7261                (car (push (set-marker (make-marker) from)
7262                           gnus-button-marker-list))))))))))
7263
7264 ;; Add buttons to the head of an article.
7265 (defun gnus-article-add-buttons-to-head ()
7266   "Add buttons to the head of the article."
7267   (interactive)
7268   (gnus-with-article-headers
7269     (let (beg end)
7270       (dolist (entry gnus-header-button-alist)
7271         ;; Each alist entry.
7272         (goto-char (point-min))
7273         (while (re-search-forward (car entry) nil t)
7274           ;; Each header matching the entry.
7275           (setq beg (match-beginning 0))
7276           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7277                              (match-beginning 0))
7278                         (point-max)))
7279           (goto-char beg)
7280           (while (re-search-forward (eval (nth 1 entry)) end t)
7281             ;; Each match within a header.
7282             (let* ((entry (cdr entry))
7283                    (start (match-beginning (nth 1 entry)))
7284                    (end (match-end (nth 1 entry)))
7285                    (form (nth 2 entry)))
7286               (goto-char (match-end 0))
7287               (when (eval form)
7288                 (gnus-article-add-button
7289                  start end (nth 3 entry)
7290                  (buffer-substring (match-beginning (nth 4 entry))
7291                                    (match-end (nth 4 entry)))))))
7292           (goto-char end))))))
7293
7294 ;;; External functions:
7295
7296 (defun gnus-article-add-button (from to fun &optional data)
7297   "Create a button between FROM and TO with callback FUN and data DATA."
7298   (when gnus-article-button-face
7299     (gnus-overlay-put (gnus-make-overlay from to)
7300                       'face gnus-article-button-face))
7301   (gnus-add-text-properties
7302    from to
7303    (nconc (and gnus-article-mouse-face
7304                (list gnus-mouse-face-prop gnus-article-mouse-face))
7305           (list 'gnus-callback fun)
7306           (and data (list 'gnus-data data))))
7307   (widget-convert-button 'link from to :action 'gnus-widget-press-button
7308                          :button-keymap gnus-widget-button-keymap))
7309
7310 ;;; Internal functions:
7311
7312 (defun gnus-article-set-globals ()
7313   (with-current-buffer gnus-summary-buffer
7314     (gnus-set-global-variables)))
7315
7316 (defun gnus-signature-toggle (end)
7317   (gnus-with-article-buffer
7318     (let ((inhibit-point-motion-hooks t)
7319           (limit (next-single-property-change end 'mime-view-entity
7320                                               nil (point-max))))
7321       (if (text-property-any end limit 'article-type 'signature)
7322           (progn
7323             (gnus-delete-wash-type 'signature)
7324             (gnus-remove-text-properties-when
7325              'article-type 'signature end limit
7326              (cons 'article-type (cons 'signature
7327                                        gnus-hidden-properties))))
7328         (gnus-add-wash-type 'signature)
7329         (gnus-add-text-properties-when
7330          'article-type nil end limit
7331          (cons 'article-type (cons 'signature
7332                                    gnus-hidden-properties)))))
7333     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7334       (gnus-set-mode-line 'article))))
7335
7336 (defun gnus-button-entry ()
7337   ;; Return the first entry in `gnus-button-alist' matching this place.
7338   (let ((alist gnus-button-alist)
7339         (entry nil))
7340     (while alist
7341       (setq entry (pop alist))
7342       (if (looking-at (eval (car entry)))
7343           (setq alist nil)
7344         (setq entry nil)))
7345     entry))
7346
7347 (defun gnus-button-push (marker)
7348   ;; Push button starting at MARKER.
7349   (save-excursion
7350     (goto-char marker)
7351     (let* ((entry (gnus-button-entry))
7352            (inhibit-point-motion-hooks t)
7353            (fun (nth 3 entry))
7354            (args (mapcar (lambda (group)
7355                            (let ((string (match-string group)))
7356                              (set-text-properties
7357                               0 (length string) nil string)
7358                              string))
7359                          (nthcdr 4 entry))))
7360       (cond
7361        ((fboundp fun)
7362         (apply fun args))
7363        ((and (boundp fun)
7364              (fboundp (symbol-value fun)))
7365         (apply (symbol-value fun) args))
7366        (t
7367         (gnus-message 1 "You must define `%S' to use this button"
7368                       (cons fun args)))))))
7369
7370 (defun gnus-parse-news-url (url)
7371   (let (scheme server port group message-id articles)
7372     (with-temp-buffer
7373       (insert url)
7374       (goto-char (point-min))
7375       (when (looking-at "\\([A-Za-z]+\\):")
7376         (setq scheme (match-string 1))
7377         (goto-char (match-end 0)))
7378       (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7379         (setq server (match-string 1))
7380         (setq port (if (stringp (match-string 3))
7381                        (string-to-number (match-string 3))
7382                      (match-string 3)))
7383         (goto-char (match-end 0)))
7384
7385       (cond
7386        ((looking-at "\\(.*@.*\\)")
7387         (setq message-id (match-string 1)))
7388        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7389         (setq group (match-string 1)
7390               articles (split-string (match-string 2) "-")))
7391        ((looking-at "\\([^/]+\\)/?")
7392         (setq group (match-string 1)))
7393        (t
7394         (error "Unknown news URL syntax"))))
7395     (list scheme server port group message-id articles)))
7396
7397 (defun gnus-button-handle-news (url)
7398   "Fetch a news URL."
7399   (destructuring-bind (scheme server port group message-id articles)
7400       (gnus-parse-news-url url)
7401     (cond
7402      (message-id
7403       (save-excursion
7404         (set-buffer gnus-summary-buffer)
7405         (if server
7406             (let ((gnus-refer-article-method
7407                    (nconc (list (list 'nntp server))
7408                           gnus-refer-article-method))
7409                   (nntp-port-number (or port "nntp")))
7410               (gnus-message 7 "Fetching %s with %s"
7411                             message-id gnus-refer-article-method)
7412               (gnus-summary-refer-article message-id))
7413           (gnus-summary-refer-article message-id))))
7414      (group
7415       (gnus-button-fetch-group url)))))
7416
7417 (defun gnus-button-handle-man (url)
7418   "Fetch a man page."
7419   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7420   (when (eq gnus-button-man-handler 'woman)
7421     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7422   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7423   (funcall gnus-button-man-handler url))
7424
7425 (defun gnus-button-handle-info-url (url)
7426   "Fetch an info URL."
7427   (setq url (mm-subst-char-in-string ?+ ?\  url))
7428   (cond
7429    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7430     (gnus-info-find-node
7431      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7432                      "Gnus")
7433              ")" (gnus-url-unhex-string (match-string 2 url)))))
7434    ((string-match "([^)\"]+)[^\"]+" url)
7435     (setq url
7436           (gnus-replace-in-string
7437            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7438     (gnus-info-find-node url))
7439    (t (error "Can't parse %s" url))))
7440
7441 (defun gnus-button-handle-info-url-gnome (url)
7442   "Fetch GNOME style info URL."
7443   (setq url (mm-subst-char-in-string ?_ ?\  url))
7444   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7445       (gnus-info-find-node
7446        (concat "("
7447                (gnus-url-unhex-string
7448                  (match-string 1 url))
7449                ")"
7450                (or (gnus-url-unhex-string
7451                     (match-string 2 url))
7452                    "Top")))
7453     (error "Can't parse %s" url)))
7454
7455 (defun gnus-button-handle-info-url-kde (url)
7456   "Fetch KDE style info URL."
7457   (gnus-info-find-node (gnus-url-unhex-string url)))
7458
7459 (defun gnus-button-handle-info-keystrokes (url)
7460   "Call `info' when pushing the corresponding URL button."
7461   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7462   (info)
7463   (Info-directory)
7464   (Info-menu url))
7465
7466 (defun gnus-button-openpgp (url)
7467   "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7468   (with-temp-buffer
7469     (mm-url-insert-file-contents-external url)
7470     (pgg-snarf-keys-region (point-min) (point-max))
7471     (pgg-display-output-buffer nil nil nil)))
7472
7473 (defun gnus-button-message-id (message-id)
7474   "Fetch MESSAGE-ID."
7475   (with-current-buffer gnus-summary-buffer
7476     (gnus-summary-refer-article message-id)))
7477
7478 (defun gnus-button-fetch-group (address)
7479   "Fetch GROUP specified by ADDRESS."
7480   (if (not (string-match "[:/]" address))
7481       ;; This is just a simple group url.
7482       (gnus-group-read-ephemeral-group address gnus-select-method)
7483     (if (not
7484          (string-match
7485           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7486           address))
7487         (error "Can't parse %s" address)
7488       (gnus-group-read-ephemeral-group
7489        (match-string 4 address)
7490        `(nntp ,(match-string 1 address)
7491               (nntp-address ,(match-string 1 address))
7492               (nntp-port-number ,(if (match-end 3)
7493                                      (match-string 3 address)
7494                                    "nntp")))
7495        nil nil nil
7496        (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7497
7498 (defun gnus-url-parse-query-string (query &optional downcase)
7499   (let (retval pairs cur key val)
7500     (setq pairs (split-string query "&"))
7501     (while pairs
7502       (setq cur (car pairs)
7503             pairs (cdr pairs))
7504       (if (not (string-match "=" cur))
7505           nil                           ; Grace
7506         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7507               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7508         (if downcase
7509             (setq key (downcase key)))
7510         (setq cur (assoc key retval))
7511         (if cur
7512             (setcdr cur (cons val (cdr cur)))
7513           (setq retval (cons (list key val) retval)))))
7514     retval))
7515
7516 (defun gnus-url-mailto (url)
7517   ;; Send mail to someone
7518   (when (string-match "mailto:/*\\(.*\\)" url)
7519     (setq url (substring url (match-beginning 1) nil)))
7520   (let (to args subject func)
7521     (setq args (gnus-url-parse-query-string
7522                 (if (string-match "^\\?" url)
7523                     (substring url 1)
7524                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7525                       (concat "to=" (match-string 1 url) "&"
7526                               (match-string 2 url))
7527                     (concat "to=" url)))
7528                 t)
7529           subject (cdr-safe (assoc "subject" args)))
7530     (gnus-msg-mail)
7531     (while args
7532       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7533       (if (fboundp func)
7534           (funcall func)
7535         (message-position-on-field (caar args)))
7536       (insert (gnus-replace-in-string
7537                (mapconcat 'identity (reverse (cdar args)) ", ")
7538                "\r\n" "\n" t))
7539       (setq args (cdr args)))
7540     (if subject
7541         (message-goto-body)
7542       (message-goto-subject))))
7543
7544 (defun gnus-button-embedded-url (address)
7545   "Activate ADDRESS with `browse-url'."
7546   (browse-url (gnus-strip-whitespace address)))
7547
7548 ;;; Next/prev buttons in the article buffer.
7549
7550 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7551 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7552
7553 (defvar gnus-prev-page-map
7554   (let ((map (make-sparse-keymap)))
7555     (define-key map gnus-mouse-2 'gnus-button-prev-page)
7556     (define-key map "\r" 'gnus-button-prev-page)
7557     map))
7558
7559 (defvar gnus-next-page-map
7560   (let ((map (make-sparse-keymap)))
7561     (unless (>= emacs-major-version 21)
7562       ;; XEmacs doesn't care.
7563       (set-keymap-parent map gnus-article-mode-map))
7564     (define-key map gnus-mouse-2 'gnus-button-next-page)
7565     (define-key map "\r" 'gnus-button-next-page)
7566     map))
7567
7568 (defun gnus-insert-prev-page-button ()
7569   (let ((b (point))
7570         (inhibit-read-only t)
7571         (situation (get-text-property (point-min) 'mime-view-situation)))
7572     (gnus-eval-format
7573      gnus-prev-page-line-format nil
7574      `(keymap ,gnus-prev-page-map
7575          gnus-prev t
7576          gnus-callback gnus-article-button-prev-page
7577          article-type annotation
7578          mime-view-situation ,situation))
7579     (widget-convert-button
7580      'link b (if (bolp)
7581                  ;; Exclude a newline.
7582                  (1- (point))
7583                (point))
7584      :action 'gnus-button-prev-page
7585      :button-keymap gnus-prev-page-map)))
7586
7587 (defun gnus-button-next-page (&optional args more-args)
7588   "Go to the next page."
7589   (interactive)
7590   (let ((win (selected-window)))
7591     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7592     (gnus-article-next-page)
7593     (select-window win)))
7594
7595 (defun gnus-button-prev-page (&optional args more-args)
7596   "Go to the prev page."
7597   (interactive)
7598   (let ((win (selected-window)))
7599     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7600     (gnus-article-prev-page)
7601     (select-window win)))
7602
7603 (defun gnus-insert-next-page-button ()
7604   (let ((b (point))
7605         (inhibit-read-only t)
7606         (situation (get-text-property (point-min) 'mime-view-situation)))
7607     (gnus-eval-format gnus-next-page-line-format nil
7608                       `(keymap ,gnus-next-page-map
7609                           gnus-next t
7610                           gnus-callback gnus-article-button-next-page
7611                           article-type annotation
7612                           mime-view-situation ,situation))
7613     (widget-convert-button
7614      'link b (if (bolp)
7615                  ;; Exclude a newline.
7616                  (1- (point))
7617                (point))
7618      :action 'gnus-button-next-page
7619      :button-keymap gnus-next-page-map)))
7620
7621 (defun gnus-article-button-next-page (arg)
7622   "Go to the next page."
7623   (interactive "P")
7624   (let ((win (selected-window)))
7625     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7626     (gnus-article-next-page)
7627     (select-window win)))
7628
7629 (defun gnus-article-button-prev-page (arg)
7630   "Go to the prev page."
7631   (interactive "P")
7632   (let ((win (selected-window)))
7633     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7634     (gnus-article-prev-page)
7635     (select-window win)))
7636
7637 (defvar gnus-decode-header-methods
7638   '(mail-decode-encoded-word-region)
7639   "List of methods used to decode headers.
7640
7641 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
7642 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
7643 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7644 whose names match REGEXP.
7645
7646 For example:
7647 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7648  mail-decode-encoded-word-region
7649  (\"chinese\" . rfc1843-decode-region))
7650 ")
7651
7652 (defvar gnus-decode-header-methods-cache nil)
7653
7654 (defun gnus-multi-decode-header (start end)
7655   "Apply the functions from `gnus-encoded-word-methods' that match."
7656   (unless (and gnus-decode-header-methods-cache
7657                (eq gnus-newsgroup-name
7658                    (car gnus-decode-header-methods-cache)))
7659     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7660     (mapcar (lambda (x)
7661               (if (symbolp x)
7662                   (nconc gnus-decode-header-methods-cache (list x))
7663                 (if (and gnus-newsgroup-name
7664                          (string-match (car x) gnus-newsgroup-name))
7665                     (nconc gnus-decode-header-methods-cache
7666                            (list (cdr x))))))
7667             gnus-decode-header-methods))
7668   (let ((xlist gnus-decode-header-methods-cache))
7669     (pop xlist)
7670     (save-restriction
7671       (narrow-to-region start end)
7672       (while xlist
7673         (funcall (pop xlist) (point-min) (point-max))))))
7674
7675 ;;;
7676 ;;; Treatment top-level handling.
7677 ;;;
7678
7679 (defun gnus-treat-article (condition &optional part-number total-parts type)
7680   (let ((length (- (point-max) (point-min)))
7681         (alist gnus-treatment-function-alist)
7682         (article-goto-body-goes-to-point-min-p t)
7683         (treated-type
7684          (or (not type)
7685              (catch 'found
7686                (let ((list gnus-article-treat-types))
7687                  (while list
7688                    (when (string-match (pop list) type)
7689                      (throw 'found t)))))))
7690         (highlightp (gnus-visual-p 'article-highlight 'highlight))
7691         (entity (static-unless (featurep 'xemacs)
7692                   (when (eq 'head condition)
7693                     (get-text-property (point-min) 'mime-view-entity))))
7694         val elem buttonized)
7695     (gnus-run-hooks 'gnus-part-display-hook)
7696     (unless gnus-inhibit-treatment
7697       (dolist (elem alist)
7698         (setq val
7699               (save-excursion
7700                 (when (gnus-buffer-live-p gnus-summary-buffer)
7701                   (set-buffer gnus-summary-buffer))
7702                 (symbol-value (car elem))))
7703         (when (and (or (consp val)
7704                        treated-type)
7705                    (gnus-treat-predicate val)
7706                    (or (not (get (car elem) 'highlight))
7707                        highlightp))
7708           (when (and (not buttonized)
7709                      (memq (car elem)
7710                            '(gnus-treat-hide-signature
7711                              gnus-treat-highlight-signature)))
7712             (gnus-article-buttonize-signature)
7713             (setq buttonized t))
7714           (save-restriction
7715             (funcall (cadr elem)))))
7716       ;; FSF Emacsen does not inherit the existing text properties
7717       ;; in the new text, so we should do it for `mime-view-entity'.
7718       (static-unless (featurep 'xemacs)
7719         (when entity
7720           (put-text-property (point-min) (point-max)
7721                              'mime-view-entity entity))))))
7722
7723 ;; Dynamic variables.
7724 (eval-when-compile
7725   (defvar part-number)
7726   (defvar total-parts)
7727   (defvar type)
7728   (defvar condition)
7729   (defvar length))
7730
7731 (defun gnus-treat-predicate (val)
7732   (cond
7733    ((null val)
7734     nil)
7735    ((and (listp val)
7736          (stringp (car val)))
7737     (apply 'gnus-or (mapcar `(lambda (s)
7738                                (string-match s ,(or gnus-newsgroup-name "")))
7739                             val)))
7740    ((listp val)
7741     (let ((pred (pop val)))
7742       (cond
7743        ((eq pred 'or)
7744         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7745        ((eq pred 'and)
7746         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7747        ((eq pred 'not)
7748         (not (gnus-treat-predicate (car val))))
7749        ((eq pred 'typep)
7750         (equal (car val) type))
7751        (t
7752         (error "%S is not a valid predicate" pred)))))
7753    ((eq val 'mime)
7754     gnus-show-mime)
7755    (condition
7756     (eq condition val))
7757    ((eq val t)
7758     t)
7759    ((eq val 'head)
7760     nil)
7761    ((eq val 'first)
7762     (eq part-number 1))
7763    ((eq val 'last)
7764     (eq part-number total-parts))
7765    ((numberp val)
7766     (< length val))
7767    (t
7768     (error "%S is not a valid value" val))))
7769
7770 (defun gnus-article-encrypt-body (protocol &optional n)
7771   "Encrypt the article body."
7772   (interactive
7773    (list
7774     (or gnus-article-encrypt-protocol
7775         (completing-read "Encrypt protocol: "
7776                          gnus-article-encrypt-protocol-alist
7777                          nil t))
7778     current-prefix-arg))
7779   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7780     (unless func
7781       (error "Can't find the encrypt protocol %s" protocol))
7782     (if (member gnus-newsgroup-name '("nndraft:delayed"
7783                                       "nndraft:drafts"
7784                                       "nndraft:queue"))
7785         (error "Can't encrypt the article in group %s"
7786                gnus-newsgroup-name))
7787     (gnus-summary-iterate n
7788       (save-excursion
7789         (set-buffer gnus-summary-buffer)
7790         (let ((mail-parse-charset gnus-newsgroup-charset)
7791               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7792               (summary-buffer gnus-summary-buffer)
7793               references point)
7794           (gnus-set-global-variables)
7795           (when (gnus-group-read-only-p)
7796             (error "The current newsgroup does not support article encrypt"))
7797           (gnus-summary-show-article t)
7798           (setq references
7799                 (or (mail-header-references gnus-current-headers) ""))
7800           (set-buffer gnus-article-buffer)
7801           (let* ((inhibit-read-only t)
7802                  (headers
7803                   (mapcar (lambda (field)
7804                             (and (save-restriction
7805                                    (message-narrow-to-head)
7806                                    (goto-char (point-min))
7807                                    (search-forward field nil t))
7808                                  (prog2
7809                                      (message-narrow-to-field)
7810                                      (buffer-string)
7811                                    (delete-region (point-min) (point-max))
7812                                    (widen))))
7813                           '("Content-Type:" "Content-Transfer-Encoding:"
7814                             "Content-Disposition:"))))
7815             (message-narrow-to-head)
7816             (message-remove-header "MIME-Version")
7817             (goto-char (point-max))
7818             (setq point (point))
7819             (insert (apply 'concat headers))
7820             (widen)
7821             (narrow-to-region point (point-max))
7822             (let ((message-options message-options))
7823               (message-options-set 'message-sender user-mail-address)
7824               (message-options-set 'message-recipients user-mail-address)
7825               (message-options-set 'message-sign-encrypt 'not)
7826               (funcall func))
7827             (goto-char (point-min))
7828             (insert "MIME-Version: 1.0\n")
7829             (widen)
7830             (gnus-summary-edit-article-done
7831              references nil summary-buffer t))
7832           (when gnus-keep-backlog
7833             (gnus-backlog-remove-article
7834              (car gnus-article-current) (cdr gnus-article-current)))
7835           (save-excursion
7836             (when (get-buffer gnus-original-article-buffer)
7837               (set-buffer gnus-original-article-buffer)
7838               (setq gnus-original-article nil)))
7839           (when gnus-use-cache
7840             (gnus-cache-update-article
7841              (car gnus-article-current) (cdr gnus-article-current))))))))
7842
7843 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7844   "The following specs can be used:
7845 %t  The security MIME type
7846 %i  Additional info
7847 %d  Details
7848 %D  Details if button is pressed")
7849
7850 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7851   "The following specs can be used:
7852 %t  The security MIME type
7853 %i  Additional info
7854 %d  Details
7855 %D  Details if button is pressed")
7856
7857 (defvar gnus-mime-security-button-line-format-alist
7858   '((?t gnus-tmp-type ?s)
7859     (?i gnus-tmp-info ?s)
7860     (?d gnus-tmp-details ?s)
7861     (?D gnus-tmp-pressed-details ?s)))
7862
7863 (defvar gnus-mime-security-button-map
7864   (let ((map (make-sparse-keymap)))
7865     (define-key map gnus-mouse-2 'gnus-article-push-button)
7866     (define-key map "\r" 'gnus-article-press-button)
7867     map))
7868
7869 (defvar gnus-mime-security-details-buffer nil)
7870
7871 (defvar gnus-mime-security-button-pressed nil)
7872
7873 (defvar gnus-mime-security-show-details-inline t
7874   "If non-nil, show details in the article buffer.")
7875
7876 (defun gnus-mime-security-verify-or-decrypt (handle)
7877   (mm-remove-parts (cdr handle))
7878   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7879         point (inhibit-read-only t))
7880     (if region
7881         (goto-char (car region)))
7882     (save-restriction
7883       (narrow-to-region (point) (point))
7884       (with-current-buffer (mm-handle-multipart-original-buffer handle)
7885         (let* ((mm-verify-option 'known)
7886                (mm-decrypt-option 'known)
7887                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7888           (unless (eq nparts (cdr handle))
7889             (mm-destroy-parts (cdr handle))
7890             (setcdr handle nparts))))
7891       (setq point (point))
7892       (gnus-mime-display-security handle)
7893       (goto-char (point-max)))
7894     (when region
7895       (delete-region (point) (cdr region))
7896       (set-marker (car region) nil)
7897       (set-marker (cdr region) nil))
7898     (goto-char point)))
7899
7900 (defun gnus-mime-security-show-details (handle)
7901   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7902     (if (not details)
7903         (gnus-message 5 "No details.")
7904       (if gnus-mime-security-show-details-inline
7905           (let ((gnus-mime-security-button-pressed
7906                  (not (get-text-property (point) 'gnus-mime-details)))
7907                 (gnus-mime-security-button-line-format
7908                  (get-text-property (point) 'gnus-line-format))
7909                 (inhibit-read-only t))
7910             (forward-char -1)
7911             (while (eq (get-text-property (point) 'gnus-line-format)
7912                        gnus-mime-security-button-line-format)
7913               (forward-char -1))
7914             (forward-char)
7915             (save-restriction
7916               (narrow-to-region (point) (point))
7917               (gnus-insert-mime-security-button handle))
7918             (delete-region (point)
7919                            (or (text-property-not-all
7920                                 (point) (point-max)
7921                                 'gnus-line-format
7922                                 gnus-mime-security-button-line-format)
7923                                (point-max))))
7924         ;; Not inlined.
7925         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7926             (with-current-buffer gnus-mime-security-details-buffer
7927               (erase-buffer)
7928               t)
7929           (setq gnus-mime-security-details-buffer
7930                 (gnus-get-buffer-create "*MIME Security Details*")))
7931         (with-current-buffer gnus-mime-security-details-buffer
7932           (insert details)
7933           (goto-char (point-min)))
7934         (pop-to-buffer gnus-mime-security-details-buffer)))))
7935
7936 (defun gnus-mime-security-press-button (handle)
7937   (save-excursion
7938     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7939         (gnus-mime-security-show-details handle)
7940       (gnus-mime-security-verify-or-decrypt handle))))
7941
7942 (defun gnus-insert-mime-security-button (handle &optional displayed)
7943   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7944          (gnus-tmp-type
7945           (concat
7946            (or (nth 2 (assoc protocol mm-verify-function-alist))
7947                (nth 2 (assoc protocol mm-decrypt-function-alist))
7948                "Unknown")
7949            (if (equal (car handle) "multipart/signed")
7950                " Signed" " Encrypted")
7951            " Part"))
7952          (gnus-tmp-info
7953           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7954               "Undecided"))
7955          (gnus-tmp-details
7956           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7957          gnus-tmp-pressed-details
7958          b e)
7959     (setq gnus-tmp-details
7960           (if gnus-tmp-details
7961               (concat "\n" gnus-tmp-details)
7962             ""))
7963     (setq gnus-tmp-pressed-details
7964           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7965     (unless (bolp)
7966       (insert "\n"))
7967     (setq b (point))
7968     (gnus-eval-format
7969      gnus-mime-security-button-line-format
7970      gnus-mime-security-button-line-format-alist
7971      `(keymap ,gnus-mime-security-button-map
7972          gnus-callback gnus-mime-security-press-button
7973          gnus-line-format ,gnus-mime-security-button-line-format
7974          gnus-mime-details ,gnus-mime-security-button-pressed
7975          article-type annotation
7976          gnus-data ,handle))
7977     (setq e (if (bolp)
7978                 ;; Exclude a newline.
7979                 (1- (point))
7980               (point)))
7981     (widget-convert-button
7982      'link b e
7983      :mime-handle handle
7984      :action 'gnus-widget-press-button
7985      :button-keymap gnus-mime-security-button-map
7986      :help-echo
7987      (lambda (widget/window &optional overlay pos)
7988        ;; Needed to properly clear the message due to a bug in
7989        ;; wid-edit (XEmacs only).
7990        (when (boundp 'help-echo-owns-message)
7991          (setq help-echo-owns-message t))
7992        (format
7993         "%S: show detail"
7994         (aref gnus-mouse-2 0))))))
7995
7996 (defun gnus-mime-display-security (handle)
7997   (save-restriction
7998     (narrow-to-region (point) (point))
7999     (unless (gnus-unbuttonized-mime-type-p (car handle))
8000       (gnus-insert-mime-security-button handle))
8001     (gnus-mime-display-part (cadr handle))
8002     (unless (bolp)
8003       (insert "\n"))
8004     (unless (gnus-unbuttonized-mime-type-p (car handle))
8005       (let ((gnus-mime-security-button-line-format
8006              gnus-mime-security-button-end-line-format))
8007         (gnus-insert-mime-security-button handle)))
8008     (mm-set-handle-multipart-parameter
8009      handle 'gnus-region
8010      (cons (set-marker (make-marker) (point-min))
8011            (set-marker (make-marker) (point-max))))))
8012
8013
8014 ;;; @ for mime-view
8015 ;;;
8016
8017 (defun gnus-article-header-presentation-method (entity situation)
8018   (mime-insert-header entity)
8019   (article-decode-group-name))
8020
8021 (set-alist 'mime-header-presentation-method-alist
8022            'gnus-original-article-mode
8023            #'gnus-article-header-presentation-method)
8024
8025 (defun gnus-mime-preview-quitting-method ()
8026   (mime-preview-kill-buffer)
8027   (delete-other-windows)
8028   (gnus-article-show-summary)
8029   (gnus-summary-select-article gnus-show-all-headers t))
8030
8031 (set-alist 'mime-preview-quitting-method-alist
8032            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
8033
8034 (set-alist 'mime-preview-following-method-alist
8035            'gnus-original-article-mode #'gnus-following-method)
8036
8037 (set-alist 'mime-preview-over-to-previous-method-alist
8038            'gnus-original-article-mode
8039            (lambda ()
8040              (if (> (point-min) 1)
8041                  (gnus-article-prev-page)
8042                (gnus-article-read-summary-keys
8043                 nil (gnus-character-to-event ?P)))))
8044
8045 (set-alist 'mime-preview-over-to-next-method-alist
8046            'gnus-original-article-mode'
8047            (lambda ()
8048              (if (< (point-max) (buffer-size))
8049                  (gnus-article-next-page)
8050                (gnus-article-read-summary-keys
8051                 nil (gnus-character-to-event ?N)))))
8052
8053
8054 ;;; @ end
8055 ;;;
8056
8057 (gnus-ems-redefine)
8058
8059 (provide 'gnus-art)
8060
8061 (run-hooks 'gnus-art-load-hook)
8062
8063 ;;; gnus-art.el ends here