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