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