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