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