72dabccc2e8de80e986fb8d6c9c155c5a6913e9d
[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                               (caar (mail-header-parse-addresses
2413                                      (mail-fetch-field "from"))))))
2414                   (catch 'found
2415                     (dolist (pair gnus-article-address-banner-alist)
2416                       (when (string-match (car pair) from)
2417                         (throw 'found (cdr pair))))))))
2418         (when banner
2419           (article-goto-body)
2420           (cond
2421            ((eq banner 'signature)
2422             (when (gnus-article-narrow-to-signature)
2423               (widen)
2424               (forward-line -1)
2425               (delete-region (point) (point-max))))
2426            ((symbolp banner)
2427             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2428                 (while (re-search-forward banner nil t)
2429                   (delete-region (match-beginning 0) (match-end 0)))))
2430            ((stringp banner)
2431             (while (re-search-forward banner nil t)
2432               (delete-region (match-beginning 0) (match-end 0))))))))))
2433
2434 (defun article-babel ()
2435   "Translate article using an online translation service."
2436   (interactive)
2437   (require 'babel)
2438   (save-excursion
2439     (set-buffer gnus-article-buffer)
2440     (when (article-goto-body)
2441       (let* ((buffer-read-only nil)
2442              (start (point))
2443              (end (point-max))
2444              (orig (buffer-substring start end))
2445              (trans (babel-as-string orig)))
2446         (save-restriction
2447           (narrow-to-region start end)
2448           (delete-region start end)
2449           (insert trans))))))
2450
2451 (defun article-hide-signature (&optional arg)
2452   "Hide the signature in the current article.
2453 If given a negative prefix, always show; if given a positive prefix,
2454 always hide."
2455   (interactive (gnus-article-hidden-arg))
2456   (save-excursion
2457     (save-restriction
2458       (if (interactive-p)
2459           (progn
2460             (widen)
2461             (article-goto-body))
2462         (goto-char (point-min)))
2463       (unless (gnus-article-check-hidden-text 'signature arg)
2464         (let ((buffer-read-only nil)
2465               (button (point)))
2466           (while (setq button (text-property-any button (point-max)
2467                                                  'gnus-callback
2468                                                  'gnus-signature-toggle))
2469             (setq button (text-property-not-all button (point-max)
2470                                                 'gnus-callback
2471                                                 'gnus-signature-toggle))
2472             (when (and button (not (eobp)))
2473               (gnus-article-hide-text-type
2474                (1+ button)
2475                (next-single-property-change (1+ button) 'mime-view-entity
2476                                             nil (point-max))
2477                'signature)))))))
2478   (gnus-set-mode-line 'article))
2479
2480 (defun article-strip-headers-in-body ()
2481   "Strip offensive headers from bodies."
2482   (interactive)
2483   (save-excursion
2484     (article-goto-body)
2485     (let ((case-fold-search t))
2486       (when (looking-at "x-no-archive:")
2487         (gnus-delete-line)))))
2488
2489 (defun article-strip-leading-blank-lines ()
2490   "Remove all blank lines from the beginning of the article."
2491   (interactive)
2492   (save-excursion
2493     (let ((inhibit-point-motion-hooks t)
2494           buffer-read-only)
2495       (when (article-goto-body)
2496         (while (and (not (eobp))
2497                     (looking-at "[ \t]*$"))
2498           (gnus-delete-line))))))
2499
2500 (defun article-narrow-to-head ()
2501   "Narrow the buffer to the head of the message.
2502 Point is left at the beginning of the narrowed-to region."
2503   (narrow-to-region
2504    (goto-char (point-min))
2505    (if (search-forward "\n\n" nil 1)
2506        (1- (point))
2507      (point-max)))
2508   (goto-char (point-min)))
2509
2510 (defun article-goto-body ()
2511   "Place point at the start of the body."
2512   (goto-char (point-min))
2513   (cond
2514    ;; This variable is only bound when dealing with separate
2515    ;; MIME body parts.
2516    (article-goto-body-goes-to-point-min-p
2517     t)
2518    ((search-forward "\n\n" nil t)
2519     t)
2520    (t
2521     (goto-char (point-max))
2522     nil)))
2523
2524 (defun article-strip-multiple-blank-lines ()
2525   "Replace consecutive blank lines with one empty line."
2526   (interactive)
2527   (save-excursion
2528     (let ((inhibit-point-motion-hooks t)
2529           buffer-read-only)
2530       ;; First make all blank lines empty.
2531       (article-goto-body)
2532       (while (re-search-forward "^[ \t]+$" nil t)
2533         (unless (gnus-annotation-in-region-p
2534                  (match-beginning 0) (match-end 0))
2535           (replace-match "" nil t)))
2536       ;; Then replace multiple empty lines with a single empty line.
2537       (article-goto-body)
2538       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2539         (unless (gnus-annotation-in-region-p
2540                  (match-beginning 0) (match-end 0))
2541           (delete-region (match-beginning 1) (match-end 1)))))))
2542
2543 (defun article-strip-leading-space ()
2544   "Remove all white space from the beginning of the lines in the article."
2545   (interactive)
2546   (save-excursion
2547     (let ((inhibit-point-motion-hooks t)
2548           buffer-read-only)
2549       (article-goto-body)
2550       (while (re-search-forward "^[ \t]+" nil t)
2551         (replace-match "" t t)))))
2552
2553 (defun article-strip-trailing-space ()
2554   "Remove all white space from the end of the lines in the article."
2555   (interactive)
2556   (save-excursion
2557     (let ((inhibit-point-motion-hooks t)
2558           buffer-read-only)
2559       (article-goto-body)
2560       (while (re-search-forward "[ \t]+$" nil t)
2561         (replace-match "" t t)))))
2562
2563 (defun article-strip-blank-lines ()
2564   "Strip leading, trailing and multiple blank lines."
2565   (interactive)
2566   (article-strip-leading-blank-lines)
2567   (article-remove-trailing-blank-lines)
2568   (article-strip-multiple-blank-lines))
2569
2570 (defun article-strip-all-blank-lines ()
2571   "Strip all blank lines."
2572   (interactive)
2573   (save-excursion
2574     (let ((inhibit-point-motion-hooks t)
2575           buffer-read-only)
2576       (article-goto-body)
2577       (while (re-search-forward "^[ \t]*\n" nil t)
2578         (replace-match "" t t)))))
2579
2580 (defun gnus-article-narrow-to-signature ()
2581   "Narrow to the signature; return t if a signature is found, else nil."
2582   (let ((inhibit-point-motion-hooks t))
2583     (when (gnus-article-search-signature)
2584       (forward-line 1)
2585       ;; Check whether we have some limits to what we consider
2586       ;; to be a signature.
2587       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2588                       (list gnus-signature-limit)))
2589             limit limited)
2590         (while (setq limit (pop limits))
2591           (if (or (and (integerp limit)
2592                        (< (- (point-max) (point)) limit))
2593                   (and (floatp limit)
2594                        (< (count-lines (point) (point-max)) limit))
2595                   (and (gnus-functionp limit)
2596                        (funcall limit))
2597                   (and (stringp limit)
2598                        (not (re-search-forward limit nil t))))
2599               ()                        ; This limit did not succeed.
2600             (setq limited t
2601                   limits nil)))
2602         (unless limited
2603           (narrow-to-region (point) (point-max))
2604           t)))))
2605
2606 (defun gnus-article-search-signature ()
2607   "Search the current buffer for the signature separator.
2608 Put point at the beginning of the signature separator."
2609   (let ((cur (point)))
2610     (goto-char (point-max))
2611     (if (if (stringp gnus-signature-separator)
2612             (re-search-backward gnus-signature-separator nil t)
2613           (let ((seps gnus-signature-separator))
2614             (while (and seps
2615                         (not (re-search-backward (car seps) nil t)))
2616               (pop seps))
2617             seps))
2618         t
2619       (goto-char cur)
2620       nil)))
2621
2622 (defun gnus-article-hidden-arg ()
2623   "Return the current prefix arg as a number, or 0 if no prefix."
2624   (list (if current-prefix-arg
2625             (prefix-numeric-value current-prefix-arg)
2626           0)))
2627
2628 (defun gnus-article-check-hidden-text (type arg)
2629   "Return nil if hiding is necessary.
2630 Arg can be nil or a number.  nil and positive means hide, negative
2631 means show, 0 means toggle."
2632   (save-excursion
2633     (save-restriction
2634       (let ((hide (gnus-article-hidden-text-p type)))
2635         (cond
2636          ((or (null arg)
2637               (> arg 0))
2638           nil)
2639          ((< arg 0)
2640           (gnus-article-show-hidden-text type)
2641           t)
2642          (t
2643           (if (eq hide 'hidden)
2644               (progn
2645                 (gnus-article-show-hidden-text type)
2646                 t)
2647             nil)))))))
2648
2649 (defun gnus-article-hidden-text-p (type)
2650   "Say whether the current buffer contains hidden text of type TYPE."
2651   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2652     (while (and pos
2653                 (not (get-text-property pos 'invisible))
2654                 (not (get-text-property pos 'dummy-invisible)))
2655       (setq pos
2656             (text-property-any (1+ pos) (point-max) 'article-type type)))
2657     (if pos
2658         'hidden
2659       nil)))
2660
2661 (defun gnus-article-show-hidden-text (type &optional dummy)
2662   "Show all hidden text of type TYPE.
2663 Originally it is hide instead of DUMMY."
2664   (let ((buffer-read-only nil)
2665         (inhibit-point-motion-hooks t))
2666     (gnus-remove-text-properties-when
2667      'article-type type
2668      (point-min) (point-max)
2669      (cons 'article-type (cons type
2670                                gnus-hidden-properties)))
2671     (gnus-delete-wash-type type)))
2672
2673 (defconst article-time-units
2674   `((year . ,(* 365.25 24 60 60))
2675     (week . ,(* 7 24 60 60))
2676     (day . ,(* 24 60 60))
2677     (hour . ,(* 60 60))
2678     (minute . 60)
2679     (second . 1))
2680   "Mapping from time units to seconds.")
2681
2682 (defun article-date-ut (&optional type highlight header)
2683   "Convert DATE date to universal time in the current article.
2684 If TYPE is `local', convert to local time; if it is `lapsed', output
2685 how much time has lapsed since DATE.  For `lapsed', the value of
2686 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2687 should replace the \"Date:\" one, or should be added below it."
2688   (interactive (list 'ut t))
2689   (let* ((header (or header
2690                      (and (eq 1 (point-min))
2691                           (mail-header-date (save-excursion
2692                                               (set-buffer gnus-summary-buffer)
2693                                               gnus-current-headers)))
2694                      (message-fetch-field "date")
2695                      ""))
2696          (date (if (vectorp header) (mail-header-date header)
2697                  header))
2698          (inhibit-point-motion-hooks t)
2699          bface eface date-pos)
2700     (when (and date (not (string= date "")))
2701       (save-excursion
2702         (save-restriction
2703           (article-narrow-to-head)
2704           (when (or (and (eq type 'lapsed)
2705                          gnus-article-date-lapsed-new-header
2706                          ;; Attempt to get the face of X-Sent first.
2707                          (re-search-forward "^X-Sent:[ \t]" nil t))
2708                     (re-search-forward "^Date:[ \t]" nil t)
2709                     ;; If Date is missing, try again for X-Sent.
2710                     (re-search-forward "^X-Sent:[ \t]" nil t))
2711             (setq bface (get-text-property (gnus-point-at-bol) 'face)
2712                   date (or (get-text-property (gnus-point-at-bol)
2713                                               'original-date)
2714                            date)
2715                   eface (get-text-property (1- (gnus-point-at-eol))
2716                                            'face)))
2717           (let ((buffer-read-only nil))
2718             ;; Delete any old X-Sent headers.
2719             (when (setq date-pos
2720                         (text-property-any (point-min) (point-max)
2721                                            'article-date-lapsed t))
2722               (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2723               (delete-region (match-beginning 0)
2724                              (progn (forward-line 1) (point))))
2725             (goto-char (point-min))
2726             ;; Delete any old Date headers.
2727             (while (re-search-forward "^Date:[ \t]" nil t)
2728               (unless date-pos
2729                 (setq date-pos (match-beginning 0)))
2730               (unless (and (eq type 'lapsed)
2731                            gnus-article-date-lapsed-new-header)
2732                 (delete-region (match-beginning 0)
2733                                (progn (message-next-header) (point)))))
2734             (if date-pos
2735                 (progn
2736                   (goto-char date-pos)
2737                   (unless (bolp)
2738                     ;; Possibly, Date has been deleted.
2739                     (insert "\n"))
2740                   (when (and (eq type 'lapsed)
2741                              gnus-article-date-lapsed-new-header
2742                              (looking-at "Date:"))
2743                     (forward-line 1)))
2744               (goto-char (point-min)))
2745             (insert (article-make-date-line date type))
2746             (when (eq type 'lapsed)
2747               (put-text-property (gnus-point-at-bol) (point)
2748                                  'article-date-lapsed t))
2749             (insert "\n")
2750             (forward-line -1)
2751             ;; Do highlighting.
2752             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2753               (put-text-property (match-beginning 1) (1+ (match-end 1))
2754                                  'original-date date)
2755               (put-text-property (match-beginning 1) (1+ (match-end 1))
2756                                  'face bface)
2757               (put-text-property (match-beginning 2) (match-end 2)
2758                                  'face eface))))))))
2759
2760 (defun article-make-date-line (date type)
2761   "Return a DATE line of TYPE."
2762   (unless (memq type '(local ut original user iso8601 lapsed english))
2763     (error "Unknown conversion type: %s" type))
2764   (condition-case ()
2765       (let ((time (date-to-time date)))
2766         (cond
2767          ;; Convert to the local timezone.
2768          ((eq type 'local)
2769           (let ((tz (car (current-time-zone time))))
2770             (format "Date: %s %s%02d%02d" (current-time-string time)
2771                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2772                     (/ (% (abs tz) 3600) 60))))
2773          ;; Convert to Universal Time.
2774          ((eq type 'ut)
2775           (concat "Date: "
2776                   (current-time-string
2777                    (let* ((e (parse-time-string date))
2778                           (tm (apply 'encode-time e))
2779                           (ms (car tm))
2780                           (ls (- (cadr tm) (car (current-time-zone time)))))
2781                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2782                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2783                            (t (list ms ls)))))
2784                   " UT"))
2785          ;; Get the original date from the article.
2786          ((eq type 'original)
2787           (concat "Date: " (if (string-match "\n+$" date)
2788                                (substring date 0 (match-beginning 0))
2789                              date)))
2790          ;; Let the user define the format.
2791          ((eq type 'user)
2792           (let ((format (or (condition-case nil
2793                                 (with-current-buffer gnus-summary-buffer
2794                                   gnus-article-time-format)
2795                               (error nil))
2796                             gnus-article-time-format)))
2797             (if (gnus-functionp format)
2798                 (funcall format time)
2799               (concat "Date: " (format-time-string format time)))))
2800          ;; ISO 8601.
2801          ((eq type 'iso8601)
2802           (let ((tz (car (current-time-zone time))))
2803             (concat
2804              "Date: "
2805              (format-time-string "%Y%m%dT%H%M%S" time)
2806              (format "%s%02d%02d"
2807                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2808                      (/ (% (abs tz) 3600) 60)))))
2809          ;; Do an X-Sent lapsed format.
2810          ((eq type 'lapsed)
2811           ;; If the date is seriously mangled, the timezone functions are
2812           ;; liable to bug out, so we ignore all errors.
2813           (let* ((now (current-time))
2814                  (real-time (subtract-time now time))
2815                  (real-sec (and real-time
2816                                 (+ (* (float (car real-time)) 65536)
2817                                    (cadr real-time))))
2818                  (sec (and real-time (abs real-sec)))
2819                  num prev)
2820             (cond
2821              ((null real-time)
2822               "X-Sent: Unknown")
2823              ((zerop sec)
2824               "X-Sent: Now")
2825              (t
2826               (concat
2827                "X-Sent: "
2828                ;; This is a bit convoluted, but basically we go
2829                ;; through the time units for years, weeks, etc,
2830                ;; and divide things to see whether that results
2831                ;; in positive answers.
2832                (mapconcat
2833                 (lambda (unit)
2834                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2835                       ;; The (remaining) seconds are too few to
2836                       ;; be divided into this time unit.
2837                       ""
2838                     ;; It's big enough, so we output it.
2839                     (setq sec (- sec (* num (cdr unit))))
2840                     (prog1
2841                         (concat (if prev ", " "") (int-to-string
2842                                                    (floor num))
2843                                 " " (symbol-name (car unit))
2844                                 (if (> num 1) "s" ""))
2845                       (setq prev t))))
2846                 article-time-units "")
2847                ;; If dates are odd, then it might appear like the
2848                ;; article was sent in the future.
2849                (if (> real-sec 0)
2850                    " ago"
2851                  " in the future"))))))
2852          ;; Display the date in proper English
2853          ((eq type 'english)
2854           (let ((dtime (decode-time time)))
2855             (concat
2856              "Date: the "
2857              (number-to-string (nth 3 dtime))
2858              (let ((digit (% (nth 3 dtime) 10)))
2859                (cond
2860                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2861                 ((= digit 1) "st")
2862                 ((= digit 2) "nd")
2863                 ((= digit 3) "rd")
2864                 (t "th")))
2865              " of "
2866              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2867              " "
2868              (number-to-string (nth 5 dtime))
2869              " at "
2870              (format "%02d" (nth 2 dtime))
2871              ":"
2872              (format "%02d" (nth 1 dtime)))))))
2873     (error
2874      (format "Date: %s (from T-gnus)" date))))
2875
2876 (defun article-date-local (&optional highlight)
2877   "Convert the current article date to the local timezone."
2878   (interactive (list t))
2879   (article-date-ut 'local highlight))
2880
2881 (defun article-date-english (&optional highlight)
2882   "Convert the current article date to something that is proper English."
2883   (interactive (list t))
2884   (article-date-ut 'english highlight))
2885
2886 (defun article-date-original (&optional highlight)
2887   "Convert the current article date to what it was originally.
2888 This is only useful if you have used some other date conversion
2889 function and want to see what the date was before converting."
2890   (interactive (list t))
2891   (article-date-ut 'original highlight))
2892
2893 (defun article-date-lapsed (&optional highlight)
2894   "Convert the current article date to time lapsed since it was sent."
2895   (interactive (list t))
2896   (article-date-ut 'lapsed highlight))
2897
2898 (defun article-update-date-lapsed ()
2899   "Function to be run from a timer to update the lapsed time line."
2900   (let (deactivate-mark)
2901     (save-excursion
2902       (ignore-errors
2903         (walk-windows
2904          (lambda (w)
2905            (set-buffer (window-buffer w))
2906            (when (eq major-mode 'gnus-article-mode)
2907              (goto-char (point-min))
2908              (when (re-search-forward "^X-Sent:" nil t)
2909                (article-date-lapsed t))))
2910          nil 'visible)))))
2911
2912 (defun gnus-start-date-timer (&optional n)
2913   "Start a timer to update the X-Sent header in the article buffers.
2914 The numerical prefix says how frequently (in seconds) the function
2915 is to run."
2916   (interactive "p")
2917   (unless n
2918     (setq n 1))
2919   (gnus-stop-date-timer)
2920   (setq article-lapsed-timer
2921         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2922
2923 (defun gnus-stop-date-timer ()
2924   "Stop the X-Sent timer."
2925   (interactive)
2926   (when article-lapsed-timer
2927     (nnheader-cancel-timer article-lapsed-timer)
2928     (setq article-lapsed-timer nil)))
2929
2930 (defun article-date-user (&optional highlight)
2931   "Convert the current article date to the user-defined format.
2932 This format is defined by the `gnus-article-time-format' variable."
2933   (interactive (list t))
2934   (article-date-ut 'user highlight))
2935
2936 (defun article-date-iso8601 (&optional highlight)
2937   "Convert the current article date to ISO8601."
2938   (interactive (list t))
2939   (article-date-ut 'iso8601 highlight))
2940
2941 ;; (defun article-show-all ()
2942 ;;   "Show all hidden text in the article buffer."
2943 ;;   (interactive)
2944 ;;   (save-excursion
2945 ;;     (widen)
2946 ;;     (let ((buffer-read-only nil))
2947 ;;       (gnus-article-unhide-text (point-min) (point-max))
2948 ;;       (gnus-remove-text-with-property 'gnus-prev)
2949 ;;       (gnus-remove-text-with-property 'gnus-next))))
2950
2951 (defun article-show-all-headers ()
2952   "Show all hidden headers in the article buffer."
2953   (interactive)
2954   (save-excursion
2955     (save-restriction
2956       (widen)
2957       (article-narrow-to-head)
2958       (let ((buffer-read-only nil))
2959         (gnus-article-unhide-text (point-min) (point-max))))))
2960
2961 (defun article-remove-leading-whitespace ()
2962   "Remove excessive whitespace from all headers."
2963   (interactive)
2964   (save-excursion
2965     (save-restriction
2966       (let ((buffer-read-only nil))
2967         (article-narrow-to-head)
2968         (goto-char (point-min))
2969         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2970           (delete-region (match-beginning 1) (match-end 1)))))))
2971
2972 (defun article-emphasize (&optional arg)
2973   "Emphasize text according to `gnus-emphasis-alist'."
2974   (interactive (gnus-article-hidden-arg))
2975   (unless (gnus-article-check-hidden-text 'emphasis arg)
2976     (save-excursion
2977       (let ((alist (or
2978                     (condition-case nil
2979                         (with-current-buffer gnus-summary-buffer
2980                           gnus-article-emphasis-alist)
2981                       (error))
2982                     gnus-emphasis-alist))
2983             (buffer-read-only nil)
2984             (props (append '(article-type emphasis)
2985                            gnus-hidden-properties))
2986             regexp elem beg invisible visible face)
2987         (article-goto-body)
2988         (setq beg (point))
2989         (while (setq elem (pop alist))
2990           (goto-char beg)
2991           (setq regexp (car elem)
2992                 invisible (nth 1 elem)
2993                 visible (nth 2 elem)
2994                 face (nth 3 elem))
2995           (while (re-search-forward regexp nil t)
2996             (when (and (match-beginning visible) (match-beginning invisible))
2997               (gnus-article-hide-text
2998                (match-beginning invisible) (match-end invisible) props)
2999               (gnus-article-unhide-text-type
3000                (match-beginning visible) (match-end visible) 'emphasis)
3001               (gnus-put-overlay-excluding-newlines
3002                (match-beginning visible) (match-end visible) 'face face)
3003               (gnus-add-wash-type 'emphasis)
3004               (goto-char (match-end invisible)))))))))
3005
3006 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3007   "Setup newsgroup emphasis alist."
3008   (unless gnus-article-emphasis-alist
3009     (let ((name (and gnus-newsgroup-name
3010                      (gnus-group-real-name gnus-newsgroup-name))))
3011       (make-local-variable 'gnus-article-emphasis-alist)
3012       (setq gnus-article-emphasis-alist
3013             (nconc
3014              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3015                (while (setq elem (pop alist))
3016                  (when (and name (string-match (car elem) name))
3017                    (setq alist nil
3018                          highlight (copy-sequence (cdr elem)))))
3019                highlight)
3020              (copy-sequence highlight-words)
3021              (if gnus-newsgroup-name
3022                  (copy-sequence (gnus-group-find-parameter
3023                                  gnus-newsgroup-name 'highlight-words t)))
3024              gnus-emphasis-alist)))))
3025
3026 (eval-when-compile
3027   (defvar gnus-summary-article-menu)
3028   (defvar gnus-summary-post-menu))
3029
3030 ;;; Saving functions.
3031
3032 (defun gnus-article-save (save-buffer file &optional num)
3033   "Save the currently selected article."
3034   (unless gnus-save-all-headers
3035     ;; Remove headers according to `gnus-saved-headers'.
3036     (let ((gnus-visible-headers
3037            (or gnus-saved-headers gnus-visible-headers))
3038           (gnus-article-buffer save-buffer))
3039       (save-excursion
3040         (set-buffer save-buffer)
3041         (article-hide-headers 1 t))))
3042   (save-window-excursion
3043     (if (not gnus-default-article-saver)
3044         (error "No default saver is defined")
3045       ;; !!! Magic!  The saving functions all save
3046       ;; `gnus-save-article-buffer' (or so they think), but we
3047       ;; bind that variable to our save-buffer.
3048       (set-buffer gnus-article-buffer)
3049       (let* ((gnus-save-article-buffer save-buffer)
3050              (filename
3051               (cond
3052                ((not gnus-prompt-before-saving) 'default)
3053                ((eq gnus-prompt-before-saving 'always) nil)
3054                (t file)))
3055              (gnus-number-of-articles-to-be-saved
3056               (when (eq gnus-prompt-before-saving t)
3057                 num)))                  ; Magic
3058         (set-buffer gnus-article-current-summary)
3059         (funcall gnus-default-article-saver filename)))))
3060
3061 (defun gnus-read-save-file-name (prompt &optional filename
3062                                         function group headers variable)
3063   (let ((default-name
3064           (funcall function group headers (symbol-value variable)))
3065         result)
3066     (setq result
3067           (expand-file-name
3068            (cond
3069             ((eq filename 'default)
3070              default-name)
3071             ((eq filename t)
3072              default-name)
3073             (filename filename)
3074             (t
3075              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3076                     (prompt
3077                      (format prompt
3078                              (if (and gnus-number-of-articles-to-be-saved
3079                                       (> gnus-number-of-articles-to-be-saved 1))
3080                                  (format "these %d articles"
3081                                          gnus-number-of-articles-to-be-saved)
3082                                "this article")))
3083                     (file
3084                      ;; Let the split methods have their say.
3085                      (cond
3086                       ;; No split name was found.
3087                       ((null split-name)
3088                        (read-file-name
3089                         (concat prompt " (default "
3090                                 (file-name-nondirectory default-name) ") ")
3091                         (file-name-directory default-name)
3092                         default-name))
3093                       ;; A single group name is returned.
3094                       ((stringp split-name)
3095                        (setq default-name
3096                              (funcall function split-name headers
3097                                       (symbol-value variable)))
3098                        (read-file-name
3099                         (concat prompt " (default "
3100                                 (file-name-nondirectory default-name) ") ")
3101                         (file-name-directory default-name)
3102                         default-name))
3103                       ;; A single split name was found
3104                       ((= 1 (length split-name))
3105                        (let* ((name (expand-file-name
3106                                      (car split-name)
3107                                      gnus-article-save-directory))
3108                               (dir (cond ((file-directory-p name)
3109                                           (file-name-as-directory name))
3110                                          ((file-exists-p name) name)
3111                                          (t gnus-article-save-directory))))
3112                          (read-file-name
3113                           (concat prompt " (default " name ") ")
3114                           dir name)))
3115                       ;; A list of splits was found.
3116                       (t
3117                        (setq split-name (nreverse split-name))
3118                        (let (result)
3119                          (let ((file-name-history
3120                                 (nconc split-name file-name-history)))
3121                            (setq result
3122                                  (expand-file-name
3123                                   (read-file-name
3124                                    (concat prompt " (`M-p' for defaults) ")
3125                                    gnus-article-save-directory
3126                                    (car split-name))
3127                                   gnus-article-save-directory)))
3128                          (car (push result file-name-history)))))))
3129                ;; Create the directory.
3130                (gnus-make-directory (file-name-directory file))
3131                ;; If we have read a directory, we append the default file name.
3132                (when (file-directory-p file)
3133                  (setq file (expand-file-name (file-name-nondirectory
3134                                                default-name)
3135                                               (file-name-as-directory file))))
3136                ;; Possibly translate some characters.
3137                (nnheader-translate-file-chars file))))))
3138     (gnus-make-directory (file-name-directory result))
3139     (set variable result)))
3140
3141 (defun gnus-article-archive-name (group)
3142   "Return the first instance of an \"Archive-name\" in the current buffer."
3143   (let ((case-fold-search t))
3144     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3145       (nnheader-concat gnus-article-save-directory
3146                        (match-string 1)))))
3147
3148 (defun gnus-article-nndoc-name (group)
3149   "If GROUP is an nndoc group, return the name of the parent group."
3150   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3151     (gnus-group-get-parameter group 'save-article-group)))
3152
3153 (defun gnus-summary-save-in-rmail (&optional filename)
3154   "Append this article to Rmail file.
3155 Optional argument FILENAME specifies file name.
3156 Directory to save to is default to `gnus-article-save-directory'."
3157   (setq filename (gnus-read-save-file-name
3158                   "Save %s in rmail file:" filename
3159                   gnus-rmail-save-name gnus-newsgroup-name
3160                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3161   (gnus-eval-in-buffer-window gnus-save-article-buffer
3162     (save-excursion
3163       (save-restriction
3164         (widen)
3165         (gnus-output-to-rmail filename))))
3166   filename)
3167
3168 (defun gnus-summary-save-in-mail (&optional filename)
3169   "Append this article to Unix mail file.
3170 Optional argument FILENAME specifies file name.
3171 Directory to save to is default to `gnus-article-save-directory'."
3172   (setq filename (gnus-read-save-file-name
3173                   "Save %s in Unix mail file:" filename
3174                   gnus-mail-save-name gnus-newsgroup-name
3175                   gnus-current-headers 'gnus-newsgroup-last-mail))
3176   (gnus-eval-in-buffer-window gnus-save-article-buffer
3177     (save-excursion
3178       (save-restriction
3179         (widen)
3180         (if (and (file-readable-p filename)
3181                  (mail-file-babyl-p filename))
3182             (rmail-output-to-rmail-file filename t)
3183           (gnus-output-to-mail filename)))))
3184   filename)
3185
3186 (defun gnus-summary-save-in-file (&optional filename overwrite)
3187   "Append this article to file.
3188 Optional argument FILENAME specifies file name.
3189 Directory to save to is default to `gnus-article-save-directory'."
3190   (setq filename (gnus-read-save-file-name
3191                   "Save %s in file:" filename
3192                   gnus-file-save-name gnus-newsgroup-name
3193                   gnus-current-headers 'gnus-newsgroup-last-file))
3194   (gnus-eval-in-buffer-window gnus-save-article-buffer
3195     (save-excursion
3196       (save-restriction
3197         (widen)
3198         (when (and overwrite
3199                    (file-exists-p filename))
3200           (delete-file filename))
3201         (gnus-output-to-file filename))))
3202   filename)
3203
3204 (defun gnus-summary-write-to-file (&optional filename)
3205   "Write this article to a file, overwriting it if the file exists.
3206 Optional argument FILENAME specifies file name.
3207 The directory to save in defaults to `gnus-article-save-directory'."
3208   (gnus-summary-save-in-file nil t))
3209
3210 (defun gnus-summary-save-body-in-file (&optional filename)
3211   "Append this article body to a file.
3212 Optional argument FILENAME specifies file name.
3213 The directory to save in defaults to `gnus-article-save-directory'."
3214   (setq filename (gnus-read-save-file-name
3215                   "Save %s body in file:" filename
3216                   gnus-file-save-name gnus-newsgroup-name
3217                   gnus-current-headers 'gnus-newsgroup-last-file))
3218   (gnus-eval-in-buffer-window gnus-save-article-buffer
3219     (save-excursion
3220       (save-restriction
3221         (widen)
3222         (when (article-goto-body)
3223           (narrow-to-region (point) (point-max)))
3224         (gnus-output-to-file filename))))
3225   filename)
3226
3227 (defun gnus-summary-save-in-pipe (&optional command)
3228   "Pipe this article to subprocess."
3229   (setq command
3230         (cond ((and (eq command 'default)
3231                     gnus-last-shell-command)
3232                gnus-last-shell-command)
3233               ((stringp command)
3234                command)
3235               (t (read-string
3236                   (format
3237                    "Shell command on %s: "
3238                    (if (and gnus-number-of-articles-to-be-saved
3239                             (> gnus-number-of-articles-to-be-saved 1))
3240                        (format "these %d articles"
3241                                gnus-number-of-articles-to-be-saved)
3242                      "this article"))
3243                   gnus-last-shell-command))))
3244   (when (string-equal command "")
3245     (if gnus-last-shell-command
3246         (setq command gnus-last-shell-command)
3247       (error "A command is required")))
3248   (gnus-eval-in-buffer-window gnus-article-buffer
3249     (save-restriction
3250       (widen)
3251       (shell-command-on-region (point-min) (point-max) command nil)))
3252   (setq gnus-last-shell-command command))
3253
3254 (defun gnus-summary-pipe-to-muttprint (&optional command)
3255   "Pipe this article to muttprint."
3256   (setq command (read-string
3257                  "Print using command: " gnus-summary-muttprint-program
3258                  nil gnus-summary-muttprint-program))
3259   (gnus-summary-save-in-pipe command))
3260
3261 ;;; Article file names when saving.
3262
3263 (defun gnus-capitalize-newsgroup (newsgroup)
3264   "Capitalize NEWSGROUP name."
3265   (when (not (zerop (length newsgroup)))
3266     (concat (char-to-string (upcase (aref newsgroup 0)))
3267             (substring newsgroup 1))))
3268
3269 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3270   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3271 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3272 Otherwise, it is like ~/News/news/group/num."
3273   (let ((default
3274           (expand-file-name
3275            (concat (if (gnus-use-long-file-name 'not-save)
3276                        (gnus-capitalize-newsgroup newsgroup)
3277                      (gnus-newsgroup-directory-form newsgroup))
3278                    "/" (int-to-string (mail-header-number headers)))
3279            gnus-article-save-directory)))
3280     (if (and last-file
3281              (string-equal (file-name-directory default)
3282                            (file-name-directory last-file))
3283              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3284         default
3285       (or last-file default))))
3286
3287 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3288   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3289 If variable `gnus-use-long-file-name' is non-nil, it is
3290 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3291   (let ((default
3292           (expand-file-name
3293            (concat (if (gnus-use-long-file-name 'not-save)
3294                        newsgroup
3295                      (gnus-newsgroup-directory-form newsgroup))
3296                    "/" (int-to-string (mail-header-number headers)))
3297            gnus-article-save-directory)))
3298     (if (and last-file
3299              (string-equal (file-name-directory default)
3300                            (file-name-directory last-file))
3301              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3302         default
3303       (or last-file default))))
3304
3305 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3306   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3307 If variable `gnus-use-long-file-name' is non-nil, it is
3308 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3309   (or last-file
3310       (expand-file-name
3311        (if (gnus-use-long-file-name 'not-save)
3312            newsgroup
3313          (file-relative-name
3314           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3315           default-directory))
3316        gnus-article-save-directory)))
3317
3318 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3319   "Generate file name from sender."
3320   (let ((from (mail-header-from headers)))
3321     (expand-file-name
3322      (if (and from (string-match "\\([^ <]+\\)@" from))
3323          (match-string 1 from)
3324        "nobody")
3325      gnus-article-save-directory)))
3326
3327 (defun article-verify-x-pgp-sig ()
3328   "Verify X-PGP-Sig."
3329   (interactive)
3330   (if (gnus-buffer-live-p gnus-original-article-buffer)
3331       (let ((sig (with-current-buffer gnus-original-article-buffer
3332                    (gnus-fetch-field "X-PGP-Sig")))
3333             items info headers)
3334         (when (and sig
3335                    mml2015-use
3336                    (mml2015-clear-verify-function))
3337           (with-temp-buffer
3338             (insert-buffer-substring gnus-original-article-buffer)
3339             (setq items (split-string sig))
3340             (message-narrow-to-head)
3341             (let ((inhibit-point-motion-hooks t)
3342                   (case-fold-search t))
3343               ;; Don't verify multiple headers.
3344               (setq headers (mapconcat (lambda (header)
3345                                          (concat header ": "
3346                                                  (mail-fetch-field header) "\n"))
3347                                        (split-string (nth 1 items) ",") "")))
3348             (delete-region (point-min) (point-max))
3349             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3350             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3351             (insert headers)
3352             (widen)
3353             (forward-line)
3354             (while (not (eobp))
3355               (if (looking-at "^-")
3356                   (insert "- "))
3357               (forward-line))
3358             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3359             (insert "Version: " (car items) "\n\n")
3360             (insert (mapconcat 'identity (cddr items) "\n"))
3361             (insert "\n-----END PGP SIGNATURE-----\n")
3362             (let ((mm-security-handle (list (format "multipart/signed"))))
3363               (mml2015-clean-buffer)
3364               (let ((coding-system-for-write (or gnus-newsgroup-charset
3365                                                  'iso-8859-1)))
3366                 (funcall (mml2015-clear-verify-function)))
3367               (setq info
3368                     (or (mm-handle-multipart-ctl-parameter
3369                          mm-security-handle 'gnus-details)
3370                         (mm-handle-multipart-ctl-parameter
3371                          mm-security-handle 'gnus-info)))))
3372           (when info
3373             (let (buffer-read-only bface eface)
3374               (save-restriction
3375                 (message-narrow-to-head)
3376                 (goto-char (point-max))
3377                 (forward-line -1)
3378                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3379                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3380                 (message-remove-header "X-Gnus-PGP-Verify")
3381                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3382                     (forward-line)
3383                   (goto-char (point-max)))
3384                 (narrow-to-region (point) (point))
3385                 (insert "X-Gnus-PGP-Verify: " info "\n")
3386                 (goto-char (point-min))
3387                 (forward-line)
3388                 (while (not (eobp))
3389                   (if (not (looking-at "^[ \t]"))
3390                       (insert " "))
3391                   (forward-line))
3392                 ;; Do highlighting.
3393                 (goto-char (point-min))
3394                 (when (looking-at "\\([^:]+\\): *")
3395                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3396                                      'face bface)
3397                   (put-text-property (match-end 0) (point-max)
3398                                      'face eface)))))))))
3399
3400 (defun article-verify-cancel-lock ()
3401   "Verify Cancel-Lock header."
3402   (interactive)
3403   (if (gnus-buffer-live-p gnus-original-article-buffer)
3404       (canlock-verify gnus-original-article-buffer)))
3405
3406 (defun article-monafy ()
3407   "Display body part with mona font."
3408   (interactive)
3409   (unless (if (featurep 'xemacs)
3410               (find-face 'gnus-mona-face)
3411             (facep 'gnus-mona-face))
3412     (require 'navi2ch-mona)
3413     (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3414   (save-excursion
3415     (let ((buffer-read-only nil))
3416       (article-goto-body)
3417       (gnus-overlay-put
3418        (gnus-make-overlay (point) (point-max))
3419        'face 'gnus-mona-face))))
3420
3421 (eval-and-compile
3422   (mapcar
3423    (lambda (func)
3424      (let (afunc gfunc)
3425        (if (consp func)
3426            (setq afunc (car func)
3427                  gfunc (cdr func))
3428          (setq afunc func
3429                gfunc (intern (format "gnus-%s" func))))
3430        (defalias gfunc
3431          (when (fboundp afunc)
3432            `(lambda (&optional interactive &rest args)
3433               ,(documentation afunc t)
3434               (interactive (list t))
3435               (save-excursion
3436                 (set-buffer gnus-article-buffer)
3437                 (if interactive
3438                     (call-interactively ',afunc)
3439                   (apply ',afunc args))))))))
3440    '(article-hide-headers
3441      article-verify-x-pgp-sig
3442      article-verify-cancel-lock
3443      article-monafy
3444      article-hide-boring-headers
3445      article-treat-overstrike
3446      article-fill-long-lines
3447      article-capitalize-sentences
3448      article-remove-cr
3449      article-remove-leading-whitespace
3450      article-display-x-face
3451      article-de-quoted-unreadable
3452      article-de-base64-unreadable
3453      article-decode-HZ
3454      article-wash-html
3455      article-unsplit-urls
3456      article-hide-list-identifiers
3457      article-hide-pgp
3458      article-strip-banner
3459      article-babel
3460      article-hide-pem
3461      article-hide-signature
3462      article-strip-headers-in-body
3463      article-remove-trailing-blank-lines
3464      article-strip-leading-blank-lines
3465      article-strip-multiple-blank-lines
3466      article-strip-leading-space
3467      article-strip-trailing-space
3468      article-strip-blank-lines
3469      article-strip-all-blank-lines
3470      article-date-local
3471      article-date-english
3472      article-date-iso8601
3473      article-date-original
3474      article-date-ut
3475      article-decode-mime-words
3476      article-decode-charset
3477      article-decode-encoded-words
3478      article-date-user
3479      article-date-lapsed
3480      article-emphasize
3481      article-treat-dumbquotes
3482      article-normalize-headers
3483      (article-show-all-headers . gnus-article-show-all-headers)
3484 ;;      (article-show-all . gnus-article-show-all)
3485      )))
3486 \f
3487 ;;;
3488 ;;; Gnus article mode
3489 ;;;
3490
3491 (put 'gnus-article-mode 'mode-class 'special)
3492
3493 (gnus-define-keys gnus-article-mode-map
3494   " " gnus-article-goto-next-page
3495   "\177" gnus-article-goto-prev-page
3496   [delete] gnus-article-goto-prev-page
3497   [backspace] gnus-article-goto-prev-page
3498   "\C-c^" gnus-article-refer-article
3499   "h" gnus-article-show-summary
3500   "s" gnus-article-show-summary
3501   "\C-c\C-m" gnus-article-mail
3502   "?" gnus-article-describe-briefly
3503   "e" gnus-summary-edit-article
3504   "<" beginning-of-buffer
3505   ">" end-of-buffer
3506   "\C-c\C-i" gnus-info-find-node
3507   "\C-c\C-b" gnus-bug
3508   "R" gnus-article-reply-with-original
3509   "F" gnus-article-followup-with-original
3510   "\C-hk" gnus-article-describe-key
3511   "\C-hc" gnus-article-describe-key-briefly
3512
3513   "\C-d" gnus-article-read-summary-keys
3514   "\M-*" gnus-article-read-summary-keys
3515   "\M-#" gnus-article-read-summary-keys
3516   "\M-^" gnus-article-read-summary-keys
3517   "\M-g" gnus-article-read-summary-keys)
3518
3519 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3520 (let (keys)
3521   (let ((key 32))
3522     (while (<= key 127)
3523       (push (char-to-string key) keys)
3524       (incf key))
3525     (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3526       (setq key (car elem))
3527       (when (and (> (length key) 0)
3528                  (not (eq 'menu-bar (aref key 0)))
3529                  (symbolp (lookup-key gnus-summary-mode-map key)))
3530         (push key keys))))
3531   (dolist (key keys)
3532     (unless (lookup-key gnus-article-mode-map key)
3533       (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3534
3535 (defun gnus-article-make-menu-bar ()
3536   (unless (boundp 'gnus-article-commands-menu)
3537     (gnus-summary-make-menu-bar))
3538   (gnus-turn-off-edit-menu 'article)
3539   (unless (boundp 'gnus-article-article-menu)
3540     (easy-menu-define
3541      gnus-article-article-menu gnus-article-mode-map ""
3542      '("Article"
3543        ["Scroll forwards" gnus-article-goto-next-page t]
3544        ["Scroll backwards" gnus-article-goto-prev-page t]
3545        ["Show summary" gnus-article-show-summary t]
3546        ["Fetch Message-ID at point" gnus-article-refer-article t]
3547        ["Mail to address at point" gnus-article-mail t]
3548        ["Send a bug report" gnus-bug t]))
3549
3550     (easy-menu-define
3551      gnus-article-treatment-menu gnus-article-mode-map ""
3552      ;; Fixme: this should use :active (and maybe :visible).
3553      '("Treatment"
3554        ["Hide headers" gnus-article-hide-headers t]
3555        ["Hide signature" gnus-article-hide-signature t]
3556        ["Hide citation" gnus-article-hide-citation t]
3557        ["Treat overstrike" gnus-article-treat-overstrike t]
3558        ["Remove carriage return" gnus-article-remove-cr t]
3559        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3560        ["Treat html" gnus-article-wash-html t]
3561        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3562        ["Decode HZ" gnus-article-decode-HZ t]))
3563
3564     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3565
3566     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3567
3568     (gnus-run-hooks 'gnus-article-menu-hook)))
3569
3570 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3571 ;; Summary.
3572
3573 (defun gnus-article-mode ()
3574   "Major mode for displaying an article.
3575
3576 All normal editing commands are switched off.
3577
3578 The following commands are available in addition to all summary mode
3579 commands:
3580 \\<gnus-article-mode-map>
3581 \\[gnus-article-next-page]\t Scroll the article one page forwards
3582 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3583 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3584 \\[gnus-article-show-summary]\t Display the summary buffer
3585 \\[gnus-article-mail]\t Send a reply to the address near point
3586 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3587 \\[gnus-info-find-node]\t Go to the Gnus info node"
3588   (interactive)
3589   (gnus-simplify-mode-line)
3590   (setq mode-name "Article")
3591   (setq major-mode 'gnus-article-mode)
3592   (make-local-variable 'minor-mode-alist)
3593   (unless (assq 'gnus-show-mime minor-mode-alist)
3594     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3595   (use-local-map gnus-article-mode-map)
3596   (when (gnus-visual-p 'article-menu 'menu)
3597     (gnus-article-make-menu-bar))
3598   (gnus-update-format-specifications nil 'article-mode)
3599   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3600   (make-local-variable 'gnus-page-broken)
3601   (make-local-variable 'gnus-button-marker-list)
3602   (make-local-variable 'gnus-article-current-summary)
3603   (make-local-variable 'gnus-article-mime-handles)
3604   (make-local-variable 'gnus-article-decoded-p)
3605   (make-local-variable 'gnus-article-mime-handle-alist)
3606   (make-local-variable 'gnus-article-wash-types)
3607   (make-local-variable 'gnus-article-image-alist)
3608   (make-local-variable 'gnus-article-charset)
3609   (make-local-variable 'gnus-article-ignored-charsets)
3610   (gnus-set-default-directory)
3611   (buffer-disable-undo)
3612   (setq buffer-read-only t)
3613   (set-syntax-table gnus-article-mode-syntax-table)
3614   (gnus-run-hooks 'gnus-article-mode-hook))
3615
3616 (defun gnus-article-setup-buffer ()
3617   "Initialize the article buffer."
3618   (let* ((name (if gnus-single-article-buffer "*Article*"
3619                  (concat "*Article " gnus-newsgroup-name "*")))
3620          (original
3621           (progn (string-match "\\*Article" name)
3622                  (concat " *Original Article"
3623                          (substring name (match-end 0))))))
3624     (setq gnus-article-buffer name)
3625     (setq gnus-original-article-buffer original)
3626     (setq gnus-article-mime-handle-alist nil)
3627     ;; This might be a variable local to the summary buffer.
3628     (unless gnus-single-article-buffer
3629       (save-excursion
3630         (set-buffer gnus-summary-buffer)
3631         (setq gnus-article-buffer name)
3632         (setq gnus-original-article-buffer original)
3633         (gnus-set-global-variables)))
3634     (gnus-article-setup-highlight-words)
3635     ;; Init original article buffer.
3636     (save-excursion
3637       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3638       (set-buffer-multibyte t)
3639       (setq major-mode 'gnus-original-article-mode)
3640       (make-local-variable 'gnus-original-article))
3641     (if (get-buffer name)
3642         (save-excursion
3643           (set-buffer name)
3644           (buffer-disable-undo)
3645           (setq buffer-read-only t)
3646           (unless (eq major-mode 'gnus-article-mode)
3647             (gnus-article-mode))
3648           (current-buffer))
3649       (save-excursion
3650         (set-buffer (gnus-get-buffer-create name))
3651         (gnus-article-mode)
3652         (make-local-variable 'gnus-summary-buffer)
3653         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3654         (current-buffer)))))
3655
3656 ;; Set article window start at LINE, where LINE is the number of lines
3657 ;; from the head of the article.
3658 (defun gnus-article-set-window-start (&optional line)
3659   (set-window-start
3660    (gnus-get-buffer-window gnus-article-buffer t)
3661    (save-excursion
3662      (set-buffer gnus-article-buffer)
3663      (goto-char (point-min))
3664      (if (not line)
3665          (point-min)
3666        (gnus-message 6 "Moved to bookmark")
3667        (search-forward "\n\n" nil t)
3668        (forward-line line)
3669        (point)))))
3670
3671 ;;; @@ article filters
3672 ;;;
3673
3674 (defun gnus-article-display-mime-message ()
3675   "Article display method for MIME message."
3676   ;; called from `gnus-original-article-buffer'.
3677   (let (charset all-headers)
3678     (with-current-buffer gnus-summary-buffer
3679       (setq charset default-mime-charset
3680             all-headers gnus-have-all-headers))
3681     (make-local-variable 'default-mime-charset)
3682     (setq default-mime-charset charset)
3683     (with-current-buffer (get-buffer-create gnus-article-buffer)
3684       (make-local-variable 'default-mime-charset)
3685       (setq default-mime-charset charset))
3686     (mime-display-message mime-message-structure
3687                           gnus-article-buffer nil gnus-article-mode-map)
3688     (when all-headers
3689       (gnus-article-hide-headers nil -1)))
3690   (run-hooks 'gnus-mime-article-prepare-hook))
3691
3692 (defun gnus-article-display-traditional-message ()
3693   "Article display method for traditional message."
3694   (set-buffer gnus-article-buffer)
3695   (let (buffer-read-only)
3696     (erase-buffer)
3697     (insert-buffer-substring gnus-original-article-buffer)))
3698
3699 (defun gnus-article-make-full-mail-header (&optional number charset)
3700   "Create a new mail header structure in a raw article buffer."
3701   (unless (and number charset)
3702     (save-current-buffer
3703       (set-buffer gnus-summary-buffer)
3704       (unless number
3705         (setq number (or (cdr gnus-article-current) 0)))
3706       (unless charset
3707         (setq charset (or default-mime-charset 'x-ctext)))))
3708   (goto-char (point-min))
3709   (let ((header-end (if (search-forward "\n\n" nil t)
3710                         (1- (point))
3711                       (goto-char (point-max))))
3712         (chars (- (point-max) (point)))
3713         (lines (count-lines (point) (point-max)))
3714         (default-mime-charset charset)
3715         xref)
3716     (narrow-to-region (point-min) header-end)
3717     (setq xref (std11-fetch-field "xref"))
3718     (prog1
3719         (make-full-mail-header
3720          number
3721          (std11-fetch-field "subject")
3722          (std11-fetch-field "from")
3723          (std11-fetch-field "date")
3724          (std11-fetch-field "message-id")
3725          (std11-fetch-field "references")
3726          chars
3727          lines
3728          (when xref (concat "Xref: " xref)))
3729       (widen))))
3730
3731 (defun gnus-article-prepare (article &optional all-headers header)
3732   "Prepare ARTICLE in article mode buffer.
3733 ARTICLE should either be an article number or a Message-ID.
3734 If ARTICLE is an id, HEADER should be the article headers.
3735 If ALL-HEADERS is non-nil, no headers are hidden."
3736   (save-excursion
3737     ;; Make sure we start in a summary buffer.
3738     (unless (eq major-mode 'gnus-summary-mode)
3739       (set-buffer gnus-summary-buffer))
3740     (setq gnus-summary-buffer (current-buffer))
3741     (let* ((gnus-article (if header (mail-header-number header) article))
3742            (summary-buffer (current-buffer))
3743            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3744            (group gnus-newsgroup-name)
3745            result)
3746       (save-excursion
3747         (gnus-article-setup-buffer)
3748         (set-buffer gnus-article-buffer)
3749         ;; Deactivate active regions.
3750         (when (and (boundp 'transient-mark-mode)
3751                    transient-mark-mode)
3752           (setq mark-active nil))
3753         (if (not (setq result (let ((buffer-read-only nil))
3754                                 (gnus-request-article-this-buffer
3755                                  article group))))
3756             ;; There is no such article.
3757             (save-excursion
3758               (when (and (numberp article)
3759                          (not (memq article gnus-newsgroup-sparse)))
3760                 (setq gnus-article-current
3761                       (cons gnus-newsgroup-name article))
3762                 (set-buffer gnus-summary-buffer)
3763                 (setq gnus-current-article article)
3764                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3765                     (progn
3766                       (gnus-summary-set-agent-mark article)
3767                       (message "Message marked for downloading"))
3768                   (gnus-summary-mark-article article gnus-canceled-mark)
3769                   (unless (memq article gnus-newsgroup-sparse)
3770                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3771           (if (or (eq result 'pseudo)
3772                   (eq result 'nneething))
3773               (progn
3774                 (save-excursion
3775                   (set-buffer summary-buffer)
3776                   (push article gnus-newsgroup-history)
3777                   (setq gnus-last-article gnus-current-article
3778                         gnus-current-article 0
3779                         gnus-current-headers nil
3780                         gnus-article-current nil)
3781                   (if (eq result 'nneething)
3782                       (gnus-configure-windows 'summary)
3783                     (gnus-configure-windows 'article))
3784                   (gnus-set-global-variables))
3785                 (let ((gnus-article-mime-handle-alist-1
3786                        gnus-article-mime-handle-alist))
3787                   (gnus-set-mode-line 'article)))
3788             ;; The result from the `request' was an actual article -
3789             ;; or at least some text that is now displayed in the
3790             ;; article buffer.
3791             (when (and (numberp article)
3792                        (not (eq article gnus-current-article)))
3793               ;; Seems like a new article has been selected.
3794               ;; `gnus-current-article' must be an article number.
3795               (save-excursion
3796                 (set-buffer summary-buffer)
3797                 (push article gnus-newsgroup-history)
3798                 (setq gnus-last-article gnus-current-article
3799                       gnus-current-article article
3800                       gnus-current-headers
3801                       (gnus-summary-article-header gnus-current-article)
3802                       gnus-article-current
3803                       (cons gnus-newsgroup-name gnus-current-article))
3804                 (unless (vectorp gnus-current-headers)
3805                   (setq gnus-current-headers nil))
3806                 (gnus-summary-goto-subject gnus-current-article)
3807                 (when (gnus-summary-show-thread)
3808                   ;; If the summary buffer really was folded, the
3809                   ;; previous goto may not actually have gone to
3810                   ;; the right article, but the thread root instead.
3811                   ;; So we go again.
3812                   (gnus-summary-goto-subject gnus-current-article))
3813                 (gnus-run-hooks 'gnus-mark-article-hook)
3814                 (gnus-set-mode-line 'summary)
3815                 (when (gnus-visual-p 'article-highlight 'highlight)
3816                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3817                 ;; Set the global newsgroup variables here.
3818                 (gnus-set-global-variables)
3819                 (setq gnus-have-all-headers
3820                       (or all-headers gnus-show-all-headers))))
3821             (save-excursion
3822               (gnus-configure-windows 'article))
3823             (when (or (numberp article)
3824                       (stringp article))
3825               (gnus-article-prepare-display)
3826               ;; Do page break.
3827               (goto-char (point-min))
3828               (setq gnus-page-broken
3829                     (when gnus-break-pages
3830                       (gnus-narrow-to-page)
3831                       t)))
3832             (let ((gnus-article-mime-handle-alist-1
3833                    gnus-article-mime-handle-alist))
3834               (gnus-set-mode-line 'article))
3835             (article-goto-body)
3836             (unless (bobp)
3837               (forward-line -1))
3838             (set-window-point (get-buffer-window (current-buffer)) (point))
3839             (gnus-configure-windows 'article)
3840             t))))))
3841
3842 (defun gnus-article-prepare-mime-display (&optional number)
3843   (goto-char (point-min))
3844   (when (re-search-forward "^[^\t ]+:" nil t)
3845     (goto-char (match-beginning 0)))
3846   (let ((entity (if (eq 1 (point-min))
3847                     (get-text-property 1 'mime-view-entity)
3848                   (get-text-property (point) 'mime-view-entity)))
3849         last-entity child-entity next type)
3850     (setq child-entity (mime-entity-children entity))
3851     (if child-entity
3852         (setq last-entity (nth (1- (length child-entity))
3853                                child-entity))
3854       (setq last-entity entity))
3855     (save-restriction
3856       (narrow-to-region (point)
3857                         (if (search-forward "\n\n" nil t)
3858                             (point)
3859                           (point-max)))
3860       (gnus-treat-article 'head)
3861       (put-text-property (point-min) (point-max) 'article-treated-header t)
3862       (goto-char (point-max)))
3863     (while (and (not (eobp)) entity)
3864       (setq next (set-marker
3865                   (make-marker)
3866                   (next-single-property-change (point) 'mime-view-entity
3867                                                nil (point-max))))
3868       (let ((types (mime-entity-content-type entity)))
3869         (while (eq 'multipart (mime-content-type-primary-type types))
3870           (setq entity (car (mime-entity-children entity))
3871                 types (mime-entity-content-type entity)))
3872         (when types
3873           (setq type (format "%s/%s"
3874                              (mime-content-type-primary-type types)
3875                              (mime-content-type-subtype types)))))
3876       (if (string-equal type "message/rfc822")
3877           (progn
3878             (setq next (point))
3879             (let ((children (mime-entity-children entity))
3880                   last-children)
3881               (when children
3882                 (setq last-children (nth (1- (length children)) children))
3883                 (while
3884                     (and
3885                      (not (eq last-children
3886                               (get-text-property next 'mime-view-entity)))
3887                      (setq next
3888                            (next-single-property-change next
3889                                                         'mime-view-entity
3890                                                         nil (point-max)))))))
3891             (setq next (next-single-property-change next 'mime-view-entity
3892                                                     nil (point-max)))
3893             (save-restriction
3894               (narrow-to-region (point) next)
3895               (gnus-article-prepare-mime-display)
3896               (goto-char (point-max)))
3897             (setq entity (get-text-property (point) 'mime-view-entity)))
3898         (save-restriction
3899           (narrow-to-region (point) next)
3900           ;; Kludge. We have to count true number, but for now,
3901           ;; part number is here only to achieve `last'.
3902           (gnus-treat-article nil 1
3903                               (if (eq entity last-entity)
3904                                   1 2)
3905                               type)
3906           (goto-char (point-max)))
3907         (setq entity (get-text-property next 'mime-view-entity))))))
3908
3909 ;;;###autoload
3910 (defun gnus-article-prepare-display ()
3911   "Make the current buffer look like a nice article."
3912   (let ((gnus-article-buffer (current-buffer))
3913         buffer-read-only)
3914     (unless (eq major-mode 'gnus-article-mode)
3915       (gnus-article-mode))
3916     (setq buffer-read-only nil
3917           gnus-button-marker-list nil
3918           gnus-article-wash-types nil
3919           gnus-article-image-alist nil)
3920     (save-restriction
3921       (widen)
3922       (static-if (featurep 'xemacs)
3923           (map-extents (lambda (extent maparg) (delete-extent extent)))
3924         (let ((lists (overlay-lists)))
3925           (dolist (overlay (nconc (car lists) (cdr lists)))
3926             (delete-overlay overlay)))))
3927     (gnus-run-hooks 'gnus-tmp-internal-hook))
3928   (set-buffer gnus-original-article-buffer)
3929   ;; Display message.
3930   (setq mime-message-structure gnus-current-headers)
3931   (mime-buffer-entity-set-buffer-internal mime-message-structure
3932                                           gnus-original-article-buffer)
3933   (mime-entity-set-representation-type-internal mime-message-structure
3934                                                 'mime-buffer-entity)
3935   (luna-send mime-message-structure 'initialize-instance
3936              mime-message-structure)
3937   (if gnus-show-mime
3938       (let (mime-display-header-hook mime-display-text/plain-hook)
3939         (funcall gnus-article-display-method-for-mime))
3940     (funcall gnus-article-display-method-for-traditional))
3941   ;; Call the treatment functions.
3942   (let ((inhibit-read-only t))
3943     (save-restriction
3944       (widen)
3945       (if gnus-show-mime
3946           (gnus-article-prepare-mime-display)
3947         (narrow-to-region (goto-char (point-min))
3948                           (if (search-forward "\n\n" nil t)
3949                               (point)
3950                             (point-max)))
3951         (gnus-treat-article 'head)
3952         (put-text-property (point-min) (point-max) 'article-treated-header t)
3953         (goto-char (point-max))
3954         (widen)
3955         (narrow-to-region (point) (point-max))
3956         (gnus-treat-article nil))
3957       (put-text-property (point-min) (point-max) 'read-only nil)))
3958   (gnus-run-hooks 'gnus-article-prepare-hook))
3959
3960 (defun gnus-article-decode-article-as-default-mime-charset ()
3961   "Decode an article as `default-mime-charset'.  It won't work if the
3962 value of the variable `gnus-show-mime' is non-nil."
3963   (unless gnus-show-mime
3964     (set (make-local-variable 'default-mime-charset)
3965          (with-current-buffer gnus-summary-buffer
3966            default-mime-charset))
3967     (decode-mime-charset-region (point-min) (point-max)
3968                                 default-mime-charset)))
3969
3970 ;;;
3971 ;;; Gnus MIME viewing functions
3972 ;;;
3973
3974 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3975   "Format of the MIME buttons.
3976
3977 Valid specifiers include:
3978 %t  The MIME type
3979 %T  MIME type, along with additional info
3980 %n  The `name' parameter
3981 %d  The description, if any
3982 %l  The length of the encoded part
3983 %p  The part identifier number
3984 %e  Dots if the part isn't displayed
3985
3986 General format specifiers can also be used.  See
3987 (gnus)Formatting Variables.")
3988
3989 (defvar gnus-mime-button-line-format-alist
3990   '((?t gnus-tmp-type ?s)
3991     (?T gnus-tmp-type-long ?s)
3992     (?n gnus-tmp-name ?s)
3993     (?d gnus-tmp-description ?s)
3994     (?p gnus-tmp-id ?s)
3995     (?l gnus-tmp-length ?d)
3996     (?e gnus-tmp-dots ?s)))
3997
3998 (defvar gnus-mime-button-commands
3999   '((gnus-article-press-button "\r" "Toggle Display")
4000     (gnus-mime-view-part "v" "View Interactively...")
4001     (gnus-mime-view-part-as-type "t" "View As Type...")
4002     (gnus-mime-view-part-as-charset "C" "View As charset...")
4003     (gnus-mime-save-part "o" "Save...")
4004     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4005     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4006     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4007     (gnus-mime-view-part-internally "E" "View Internally")
4008     (gnus-mime-view-part-externally "e" "View Externally")
4009     (gnus-mime-print-part "p" "Print")
4010     (gnus-mime-pipe-part "|" "Pipe To Command...")
4011     (gnus-mime-action-on-part "." "Take action on the part")))
4012
4013 (defun gnus-article-mime-part-status ()
4014   (with-current-buffer gnus-article-buffer
4015     (let ((entity (get-text-property (point-min) 'mime-view-entity))
4016           children)
4017       (if (and entity
4018                (setq children (mime-entity-children entity))
4019                (setq children (length children)))
4020           (if (eq 1 children)
4021               " (1 part)"
4022             (format " (%d parts)" children))
4023         ""))))
4024
4025 (defvar gnus-mime-button-map
4026   (let ((map (make-sparse-keymap)))
4027     (unless (>= (string-to-number emacs-version) 21)
4028       ;; XEmacs doesn't care.
4029       (set-keymap-parent map gnus-article-mode-map))
4030     (define-key map gnus-mouse-2 'gnus-article-push-button)
4031     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4032     (dolist (c gnus-mime-button-commands)
4033       (define-key map (cadr c) (car c)))
4034     map))
4035
4036 (defun gnus-mime-button-menu (event)
4037   "Construct a context-sensitive menu of MIME commands."
4038   (interactive "e")
4039   (save-window-excursion
4040     (let ((pos (event-start event)))
4041       (select-window (posn-window pos))
4042       (goto-char (posn-point pos))
4043       (gnus-article-check-buffer)
4044       (let ((response (x-popup-menu
4045                        t `("MIME Part"
4046                            ("" ,@(mapcar (lambda (c)
4047                                            (cons (caddr c) (car c)))
4048                                          gnus-mime-button-commands))))))
4049         (if response
4050             (call-interactively response))))))
4051
4052 (defun gnus-mime-view-all-parts (&optional handles)
4053   "View all the MIME parts."
4054   (interactive)
4055   (save-current-buffer
4056     (set-buffer gnus-article-buffer)
4057     (let ((handles (or handles gnus-article-mime-handles))
4058           (mail-parse-charset gnus-newsgroup-charset)
4059           (mail-parse-ignored-charsets
4060            (with-current-buffer gnus-summary-buffer
4061              gnus-newsgroup-ignored-charsets)))
4062       (when handles
4063         (mm-remove-parts handles)
4064         (goto-char (point-min))
4065         (or (search-forward "\n\n") (goto-char (point-max)))
4066         (let (buffer-read-only)
4067           (delete-region (point) (point-max))
4068           (mm-display-parts handles))))))
4069
4070 (defun gnus-mime-save-part-and-strip ()
4071   "Save the MIME part under point then replace it with an external body."
4072   (interactive)
4073   (gnus-article-check-buffer)
4074   (let* ((data (get-text-property (point) 'gnus-data))
4075          file param
4076          (handles gnus-article-mime-handles))
4077     (if (mm-multiple-handles gnus-article-mime-handles)
4078         (error "This function is not implemented"))
4079     (setq file (and data (mm-save-part data)))
4080     (when file
4081       (with-current-buffer (mm-handle-buffer data)
4082         (erase-buffer)
4083         (insert "Content-Type: " (mm-handle-media-type data))
4084         (mml-insert-parameter-string (cdr (mm-handle-type data))
4085                                      '(charset))
4086         (insert "\n")
4087         (insert "Content-ID: " (message-make-message-id) "\n")
4088         (insert "Content-Transfer-Encoding: binary\n")
4089         (insert "\n"))
4090       (setcdr data
4091               (cdr (mm-make-handle nil
4092                                    `("message/external-body"
4093                                      (access-type . "LOCAL-FILE")
4094                                      (name . ,file)))))
4095       (set-buffer gnus-summary-buffer)
4096       (gnus-article-edit-article
4097        `(lambda ()
4098           (erase-buffer)
4099           (let ((mail-parse-charset (or gnus-article-charset
4100                                         ',gnus-newsgroup-charset))
4101                 (mail-parse-ignored-charsets
4102                  (or gnus-article-ignored-charsets
4103                      ',gnus-newsgroup-ignored-charsets))
4104                 (mbl mml-buffer-list))
4105             (setq mml-buffer-list nil)
4106             (insert-buffer gnus-original-article-buffer)
4107             (mime-to-mml ',handles)
4108             (setq gnus-article-mime-handles nil)
4109             (let ((mbl1 mml-buffer-list))
4110               (setq mml-buffer-list mbl)
4111               (set (make-local-variable 'mml-buffer-list) mbl1))
4112             ;; LOCAL argument of add-hook differs between GNU Emacs
4113             ;; and XEmacs. make-local-hook makes sure they are local.
4114             (make-local-hook 'kill-buffer-hook)
4115             (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4116        `(lambda (no-highlight)
4117           (let ((mail-parse-charset (or gnus-article-charset
4118                                         ',gnus-newsgroup-charset))
4119                 (message-options message-options)
4120                 (message-options-set-recipient)
4121                 (mail-parse-ignored-charsets
4122                  (or gnus-article-ignored-charsets
4123                      ',gnus-newsgroup-ignored-charsets)))
4124             (mml-to-mime)
4125             (mml-destroy-buffers)
4126             (remove-hook 'kill-buffer-hook
4127                          'mml-destroy-buffers t)
4128             (kill-local-variable 'mml-buffer-list))
4129           (gnus-summary-edit-article-done
4130            ,(or (mail-header-references gnus-current-headers) "")
4131            ,(gnus-group-read-only-p)
4132            ,gnus-summary-buffer no-highlight))))))
4133
4134 (defun gnus-mime-save-part ()
4135   "Save the MIME part under point."
4136   (interactive)
4137   (gnus-article-check-buffer)
4138   (let ((data (get-text-property (point) 'gnus-data)))
4139     (when data
4140       (mm-save-part data))))
4141
4142 (defun gnus-mime-pipe-part ()
4143   "Pipe the MIME part under point to a process."
4144   (interactive)
4145   (gnus-article-check-buffer)
4146   (let ((data (get-text-property (point) 'gnus-data)))
4147     (when data
4148       (mm-pipe-part data))))
4149
4150 (defun gnus-mime-view-part ()
4151   "Interactively choose a viewing method for the MIME part under point."
4152   (interactive)
4153   (gnus-article-check-buffer)
4154   (let ((data (get-text-property (point) 'gnus-data)))
4155     (when data
4156       (setq gnus-article-mime-handles
4157             (mm-merge-handles
4158              gnus-article-mime-handles (setq data (copy-sequence data))))
4159       (mm-interactively-view-part data))))
4160
4161 (defun gnus-mime-view-part-as-type-internal ()
4162   (gnus-article-check-buffer)
4163   (let* ((name (mail-content-type-get
4164                 (mm-handle-type (get-text-property (point) 'gnus-data))
4165                 'name))
4166          (def-type (and name (mm-default-file-encoding name))))
4167     (and def-type (cons def-type 0))))
4168
4169 (defun gnus-mime-view-part-as-type (&optional mime-type)
4170   "Choose a MIME media type, and view the part as such."
4171   (interactive)
4172   (unless mime-type
4173     (setq mime-type (completing-read
4174                      "View as MIME type: "
4175                      (mapcar #'list (mailcap-mime-types))
4176                      nil nil
4177                      (gnus-mime-view-part-as-type-internal))))
4178   (gnus-article-check-buffer)
4179   (let ((handle (get-text-property (point) 'gnus-data)))
4180     (when handle
4181       (setq handle
4182             (mm-make-handle (mm-handle-buffer handle)
4183                             (cons mime-type (cdr (mm-handle-type handle)))
4184                             (mm-handle-encoding handle)
4185                             (mm-handle-undisplayer handle)
4186                             (mm-handle-disposition handle)
4187                             (mm-handle-description handle)
4188                             nil
4189                             (mm-handle-id handle)))
4190       (setq gnus-article-mime-handles
4191             (mm-merge-handles gnus-article-mime-handles handle))
4192       (gnus-mm-display-part handle))))
4193
4194 (defun gnus-mime-copy-part (&optional handle)
4195   "Put the MIME part under point into a new buffer."
4196   (interactive)
4197   (gnus-article-check-buffer)
4198   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4199          (contents (and handle (mm-get-part handle)))
4200          (base (and handle
4201                     (file-name-nondirectory
4202                      (or
4203                       (mail-content-type-get (mm-handle-type handle) 'name)
4204                       (mail-content-type-get (mm-handle-type handle)
4205                                              'filename)
4206                       "*decoded*"))))
4207          (buffer (and base (generate-new-buffer base))))
4208     (when contents
4209       (switch-to-buffer buffer)
4210       (insert contents)
4211       ;; We do it this way to make `normal-mode' set the appropriate mode.
4212       (unwind-protect
4213           (progn
4214             (setq buffer-file-name (expand-file-name base))
4215             (normal-mode))
4216         (setq buffer-file-name nil))
4217       (goto-char (point-min)))))
4218
4219 (defun gnus-mime-print-part (&optional handle filename)
4220   "Print the MIME part under point."
4221   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4222   (gnus-article-check-buffer)
4223   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4224          (contents (and handle (mm-get-part handle)))
4225          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4226          (printer (mailcap-mime-info (mm-handle-type handle) "print")))
4227     (when contents
4228         (if printer
4229             (unwind-protect
4230                 (progn
4231                   (with-temp-file file
4232                     (insert contents))
4233                   (call-process shell-file-name nil
4234                                 (generate-new-buffer " *mm*")
4235                                 nil
4236                                 shell-command-switch
4237                                 (mm-mailcap-command
4238                                  printer file (mm-handle-type handle))))
4239               (delete-file file))
4240           (with-temp-buffer
4241             (insert contents)
4242             (gnus-print-buffer))
4243           (ps-despool filename)))))
4244
4245 (defun gnus-mime-inline-part (&optional handle arg)
4246   "Insert the MIME part under point into the current buffer."
4247   (interactive (list nil current-prefix-arg))
4248   (gnus-article-check-buffer)
4249   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4250          contents charset
4251          (b (point))
4252          buffer-read-only)
4253     (when handle
4254       (if (and (not arg) (mm-handle-undisplayer handle))
4255           (mm-remove-part handle)
4256         (setq contents (mm-get-part handle))
4257         (cond
4258          ((not arg)
4259           (setq charset (or (mail-content-type-get
4260                              (mm-handle-type handle) 'charset)
4261                             gnus-newsgroup-charset)))
4262          ((numberp arg)
4263           (if (mm-handle-undisplayer handle)
4264               (mm-remove-part handle))
4265           (setq charset
4266                 (or (cdr (assq arg
4267                                gnus-summary-show-article-charset-alist))
4268                     (mm-read-coding-system "Charset: ")))))
4269         (forward-line 2)
4270         (mm-insert-inline handle
4271                           (if (and charset
4272                                    (setq charset (mm-charset-to-coding-system
4273                                                   charset))
4274                                    (not (eq charset 'ascii)))
4275                               (mm-decode-coding-string contents charset)
4276                             contents))
4277         (goto-char b)))))
4278
4279 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4280   "Insert the MIME part under point into the current buffer using the
4281 specified charset."
4282   (interactive (list nil current-prefix-arg))
4283   (gnus-article-check-buffer)
4284   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4285          contents charset
4286          (b (point))
4287          buffer-read-only)
4288     (when handle
4289       (if (mm-handle-undisplayer handle)
4290           (mm-remove-part handle))
4291       (let ((gnus-newsgroup-charset
4292              (or (cdr (assq arg
4293                             gnus-summary-show-article-charset-alist))
4294                  (mm-read-coding-system "Charset: ")))
4295             (gnus-newsgroup-ignored-charsets 'gnus-all))
4296         (gnus-article-press-button)))))
4297
4298 (defun gnus-mime-view-part-externally (&optional handle)
4299   "View the MIME part under point with an external viewer."
4300   (interactive)
4301   (gnus-article-check-buffer)
4302   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4303          (mm-user-display-methods nil)
4304          (mm-inlined-types nil)
4305          (mail-parse-charset gnus-newsgroup-charset)
4306          (mail-parse-ignored-charsets
4307           (save-excursion (set-buffer gnus-summary-buffer)
4308                           gnus-newsgroup-ignored-charsets)))
4309     (when handle
4310       (if (mm-handle-undisplayer handle)
4311           (mm-remove-part handle)
4312         (mm-display-part handle)))))
4313
4314 (defun gnus-mime-view-part-internally (&optional handle)
4315   "View the MIME part under point with an internal viewer.
4316 If no internal viewer is available, use an external viewer."
4317   (interactive)
4318   (gnus-article-check-buffer)
4319   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4320          (mm-inlined-types '(".*"))
4321          (mm-inline-large-images t)
4322          (mail-parse-charset gnus-newsgroup-charset)
4323          (mail-parse-ignored-charsets
4324           (save-excursion (set-buffer gnus-summary-buffer)
4325                           gnus-newsgroup-ignored-charsets)))
4326     (when handle
4327       (if (mm-handle-undisplayer handle)
4328           (mm-remove-part handle)
4329         (mm-display-part handle)))))
4330
4331 (defun gnus-mime-action-on-part (&optional action)
4332   "Do something with the MIME attachment at \(point\)."
4333   (interactive
4334    (list (completing-read "Action: " gnus-mime-action-alist)))
4335   (gnus-article-check-buffer)
4336   (let ((action-pair (assoc action gnus-mime-action-alist)))
4337     (if action-pair
4338         (funcall (cdr action-pair)))))
4339
4340 (defun gnus-article-part-wrapper (n function)
4341   (save-current-buffer
4342     (set-buffer gnus-article-buffer)
4343     (when (> n (length gnus-article-mime-handle-alist))
4344       (error "No such part"))
4345     (gnus-article-goto-part n)
4346     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4347       (funcall function handle))))
4348
4349 (defun gnus-article-pipe-part (n)
4350   "Pipe MIME part N, which is the numerical prefix."
4351   (interactive "p")
4352   (gnus-article-part-wrapper n 'mm-pipe-part))
4353
4354 (defun gnus-article-save-part (n)
4355   "Save MIME part N, which is the numerical prefix."
4356   (interactive "p")
4357   (gnus-article-part-wrapper n 'mm-save-part))
4358
4359 (defun gnus-article-interactively-view-part (n)
4360   "View MIME part N interactively, which is the numerical prefix."
4361   (interactive "p")
4362   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4363
4364 (defun gnus-article-copy-part (n)
4365   "Copy MIME part N, which is the numerical prefix."
4366   (interactive "p")
4367   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4368
4369 (defun gnus-article-view-part-as-charset (n)
4370   "Copy MIME part N, which is the numerical prefix."
4371   (interactive "p")
4372   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4373
4374 (defun gnus-article-view-part-externally (n)
4375   "View MIME part N externally, which is the numerical prefix."
4376   (interactive "p")
4377   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4378
4379 (defun gnus-article-inline-part (n)
4380   "Inline MIME part N, which is the numerical prefix."
4381   (interactive "p")
4382   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4383
4384 (defun gnus-article-mime-match-handle-first (condition)
4385   (if condition
4386       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4387         (while (setq ihandle (pop alist))
4388           (if (and (cond
4389                     ((functionp condition)
4390                      (funcall condition (cdr ihandle)))
4391                     ((eq condition 'undisplayed)
4392                      (not (or (mm-handle-undisplayer (cdr ihandle))
4393                               (equal (mm-handle-media-type (cdr ihandle))
4394                                      "multipart/alternative"))))
4395                     ((eq condition 'undisplayed-alternative)
4396                      (not (mm-handle-undisplayer (cdr ihandle))))
4397                     (t t))
4398                    (gnus-article-goto-part (car ihandle))
4399                    (or (not n) (< (car ihandle) n)))
4400               (setq n (car ihandle))))
4401         (or n 1))
4402     1))
4403
4404 (defun gnus-article-view-part (&optional n)
4405   "View MIME part N, which is the numerical prefix."
4406   (interactive "P")
4407   (save-current-buffer
4408     (set-buffer gnus-article-buffer)
4409     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4410                              gnus-article-mime-match-handle-function)))
4411     (when (> n (length gnus-article-mime-handle-alist))
4412       (error "No such part"))
4413     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4414       (when (gnus-article-goto-part n)
4415         (if (equal (car handle) "multipart/alternative")
4416             (gnus-article-press-button)
4417           (when (eq (gnus-mm-display-part handle) 'internal)
4418             (gnus-set-window-start)))))))
4419
4420 (defsubst gnus-article-mime-total-parts ()
4421   (if (bufferp (car gnus-article-mime-handles))
4422       1 ;; single part
4423     (1- (length gnus-article-mime-handles))))
4424
4425 (defun gnus-mm-display-part (handle)
4426   "Display HANDLE and fix MIME button."
4427   (let ((id (get-text-property (point) 'gnus-part))
4428         (point (point))
4429         buffer-read-only)
4430     (forward-line 1)
4431     (prog1
4432         (let ((window (selected-window))
4433               (mail-parse-charset gnus-newsgroup-charset)
4434               (mail-parse-ignored-charsets
4435                (if (gnus-buffer-live-p gnus-summary-buffer)
4436                    (save-excursion
4437                      (set-buffer gnus-summary-buffer)
4438                      gnus-newsgroup-ignored-charsets)
4439                  nil)))
4440           (save-excursion
4441             (unwind-protect
4442                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4443                       (beg (point)))
4444                   (when win
4445                     (select-window win))
4446                   (goto-char point)
4447                   (forward-line)
4448                   (if (mm-handle-displayed-p handle)
4449                       ;; This will remove the part.
4450                       (mm-display-part handle)
4451                     (save-restriction
4452                       (narrow-to-region (point)
4453                                         (if (eobp) (point) (1+ (point))))
4454                       (mm-display-part handle)
4455                       ;; We narrow to the part itself and
4456                       ;; then call the treatment functions.
4457                       (goto-char (point-min))
4458                       (forward-line 1)
4459                       (narrow-to-region (point) (point-max))
4460                       (gnus-treat-article
4461                        nil id
4462                        (gnus-article-mime-total-parts)
4463                        (mm-handle-media-type handle)))))
4464               (if (window-live-p window)
4465                   (select-window window)))))
4466       (goto-char point)
4467       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4468       (gnus-insert-mime-button
4469        handle id (list (mm-handle-displayed-p handle)))
4470       (goto-char point))))
4471
4472 (defun gnus-article-goto-part (n)
4473   "Go to MIME part N."
4474   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4475     (when point
4476       (goto-char point))))
4477
4478 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4479   (let ((gnus-tmp-name
4480          (or (mail-content-type-get (mm-handle-type handle) 'name)
4481              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4482              (mail-content-type-get (mm-handle-type handle) 'url)
4483              ""))
4484         (gnus-tmp-type (mm-handle-media-type handle))
4485         (gnus-tmp-description
4486          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4487                                               "")))
4488         (gnus-tmp-dots
4489          (if (if displayed (car displayed)
4490                (mm-handle-displayed-p handle))
4491              "" "..."))
4492         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4493                            (buffer-size)))
4494         gnus-tmp-type-long b e)
4495     (when (string-match ".*/" gnus-tmp-name)
4496       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4497     (setq gnus-tmp-type-long (concat gnus-tmp-type
4498                                      (and (not (equal gnus-tmp-name ""))
4499                                           (concat "; " gnus-tmp-name))))
4500     (unless (equal gnus-tmp-description "")
4501       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4502     (unless (bolp)
4503       (insert "\n"))
4504     (setq b (point))
4505     (gnus-eval-format
4506      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4507      `(,@(gnus-local-map-property gnus-mime-button-map)
4508          gnus-callback gnus-mm-display-part
4509          gnus-part ,gnus-tmp-id
4510          article-type annotation
4511          gnus-data ,handle))
4512     (setq e (point))
4513     (widget-convert-button
4514      'link b e
4515      :mime-handle handle
4516      :action 'gnus-widget-press-button
4517      :button-keymap gnus-mime-button-map
4518      :help-echo
4519      (lambda (widget/window &optional overlay pos)
4520        ;; Needed to properly clear the message due to a bug in
4521        ;; wid-edit (XEmacs only).
4522        (if (boundp 'help-echo-owns-message)
4523            (setq help-echo-owns-message t))
4524        (format
4525         "%S: %s the MIME part; %S: more options"
4526         (aref gnus-mouse-2 0)
4527         ;; XEmacs will get a single widget arg; Emacs 21 will get
4528         ;; window, overlay, position.
4529         (if (mm-handle-displayed-p
4530              (if overlay
4531                  (with-current-buffer (gnus-overlay-buffer overlay)
4532                    (widget-get (widget-at (gnus-overlay-start overlay))
4533                                :mime-handle))
4534                (widget-get widget/window :mime-handle)))
4535             "hide" "show")
4536         (aref gnus-down-mouse-3 0))))))
4537
4538 (defun gnus-widget-press-button (elems el)
4539   (goto-char (widget-get elems :from))
4540   (gnus-article-press-button))
4541
4542 (defvar gnus-displaying-mime nil)
4543
4544 (defun gnus-display-mime (&optional ihandles)
4545   "Display the MIME parts."
4546   (save-excursion
4547     (save-selected-window
4548       (let ((window (get-buffer-window gnus-article-buffer))
4549             (point (point)))
4550         (when window
4551           (select-window window)
4552           ;; We have to do this since selecting the window
4553           ;; may change the point.  So we set the window point.
4554           (set-window-point window point)))
4555       (let* ((handles (or ihandles (mm-dissect-buffer
4556                                     nil gnus-article-loose-mime)
4557                           (mm-uu-dissect)))
4558              buffer-read-only handle name type b e display)
4559         (when (and (not ihandles)
4560                    (not gnus-displaying-mime))
4561           ;; Top-level call; we clean up.
4562           (when gnus-article-mime-handles
4563             (mm-destroy-parts gnus-article-mime-handles)
4564             (setq gnus-article-mime-handle-alist nil));; A trick.
4565           (setq gnus-article-mime-handles handles)
4566           ;; We allow users to glean info from the handles.
4567           (when gnus-article-mime-part-function
4568             (gnus-mime-part-function handles)))
4569         (if (and handles
4570                  (or (not (stringp (car handles)))
4571                      (cdr handles)))
4572             (progn
4573               (when (and (not ihandles)
4574                          (not gnus-displaying-mime))
4575                 ;; Clean up for mime parts.
4576                 (article-goto-body)
4577                 (delete-region (point) (point-max)))
4578               (let ((gnus-displaying-mime t))
4579                 (gnus-mime-display-part handles)))
4580           (save-restriction
4581             (article-goto-body)
4582             (narrow-to-region (point) (point-max))
4583             (gnus-treat-article nil 1 1)
4584             (widen)))
4585         (unless ihandles
4586           ;; Highlight the headers.
4587           (save-excursion
4588             (save-restriction
4589               (article-goto-body)
4590               (narrow-to-region (point-min) (point))
4591               (gnus-treat-article 'head))))))))
4592
4593 (defvar gnus-mime-display-multipart-as-mixed nil)
4594 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4595 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4596
4597 (defun gnus-mime-display-part (handle)
4598   (cond
4599    ;; Single part.
4600    ((not (stringp (car handle)))
4601     (gnus-mime-display-single handle))
4602    ;; User-defined multipart
4603    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4604     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4605              handle))
4606    ;; multipart/alternative
4607    ((and (equal (car handle) "multipart/alternative")
4608          (not (or gnus-mime-display-multipart-as-mixed
4609                   gnus-mime-display-multipart-alternative-as-mixed)))
4610     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4611       (push (cons id handle) gnus-article-mime-handle-alist)
4612       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4613    ;; multipart/related
4614    ((and (equal (car handle) "multipart/related")
4615          (not (or gnus-mime-display-multipart-as-mixed
4616                   gnus-mime-display-multipart-related-as-mixed)))
4617     ;;;!!!We should find the start part, but we just default
4618     ;;;!!!to the first part.
4619     ;;(gnus-mime-display-part (cadr handle))
4620     ;;;!!! Most multipart/related is an HTML message plus images.
4621     ;;;!!! Unfortunately we are unable to let W3 display those
4622     ;;;!!! included images, so we just display it as a mixed multipart.
4623     ;;(gnus-mime-display-mixed (cdr handle))
4624     ;;;!!! No, w3 can display everything just fine.
4625     (gnus-mime-display-part (cadr handle)))
4626    ((equal (car handle) "multipart/signed")
4627     (gnus-add-wash-type 'signed)
4628     (gnus-mime-display-security handle))
4629    ((equal (car handle) "multipart/encrypted")
4630     (gnus-add-wash-type 'encrypted)
4631     (gnus-mime-display-security handle))
4632    ;; Other multiparts are handled like multipart/mixed.
4633    (t
4634     (gnus-mime-display-mixed (cdr handle)))))
4635
4636 (defun gnus-mime-part-function (handles)
4637   (if (stringp (car handles))
4638       (mapcar 'gnus-mime-part-function (cdr handles))
4639     (funcall gnus-article-mime-part-function handles)))
4640
4641 (defun gnus-mime-display-mixed (handles)
4642   (mapcar 'gnus-mime-display-part handles))
4643
4644 (defun gnus-mime-display-single (handle)
4645   (let ((type (mm-handle-media-type handle))
4646         (ignored gnus-ignored-mime-types)
4647         (not-attachment t)
4648         (move nil)
4649         display text)
4650     (catch 'ignored
4651       (progn
4652         (while ignored
4653           (when (string-match (pop ignored) type)
4654             (throw 'ignored nil)))
4655         (if (and (setq not-attachment
4656                        (and (not (mm-inline-override-p handle))
4657                             (or (not (mm-handle-disposition handle))
4658                                 (equal (car (mm-handle-disposition handle))
4659                                        "inline")
4660                                 (mm-attachment-override-p handle))))
4661                  (mm-automatic-display-p handle)
4662                  (or (and
4663                       (mm-inlinable-p handle)
4664                       (mm-inlined-p handle))
4665                      (mm-automatic-external-display-p type)))
4666             (setq display t)
4667           (when (equal (mm-handle-media-supertype handle) "text")
4668             (setq text t)))
4669         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4670               beg)
4671           (push (cons id handle) gnus-article-mime-handle-alist)
4672           (when (or (not display)
4673                     (not (gnus-unbuttonized-mime-type-p type)))
4674             ;(gnus-article-insert-newline)
4675             (gnus-insert-mime-button
4676              handle id (list (or display (and not-attachment text))))
4677             (gnus-article-insert-newline)
4678             ;(gnus-article-insert-newline)
4679             ;; Remember modify the number of forward lines.
4680             (setq move t))
4681           (setq beg (point))
4682           (cond
4683            (display
4684             (when move
4685               (forward-line -1)
4686               (setq beg (point)))
4687             (let ((mail-parse-charset gnus-newsgroup-charset)
4688                   (mail-parse-ignored-charsets
4689                    (save-excursion (condition-case ()
4690                                        (set-buffer gnus-summary-buffer)
4691                                      (error))
4692                                    gnus-newsgroup-ignored-charsets)))
4693               (mm-display-part handle t))
4694             (goto-char (point-max)))
4695            ((and text not-attachment)
4696             (when move
4697               (forward-line -1)
4698               (setq beg (point)))
4699             (gnus-article-insert-newline)
4700             (mm-insert-inline handle (mm-get-part handle))
4701             (goto-char (point-max))))
4702           ;; Do highlighting.
4703           (save-excursion
4704             (save-restriction
4705               (narrow-to-region beg (point))
4706               (gnus-treat-article
4707                nil id
4708                (gnus-article-mime-total-parts)
4709                (mm-handle-media-type handle)))))))))
4710
4711 (defun gnus-unbuttonized-mime-type-p (type)
4712   "Say whether TYPE is to be unbuttonized."
4713   (unless gnus-inhibit-mime-unbuttonizing
4714     (when (catch 'found
4715             (let ((types gnus-unbuttonized-mime-types))
4716               (while types
4717                 (when (string-match (pop types) type)
4718                   (throw 'found t)))))
4719       (not (catch 'found
4720              (let ((types gnus-buttonized-mime-types))
4721                (while types
4722                  (when (string-match (pop types) type)
4723                    (throw 'found t)))))))))
4724
4725 (defun gnus-article-insert-newline ()
4726   "Insert a newline, but mark it as undeletable."
4727   (gnus-put-text-property
4728    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4729
4730 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4731   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4732          (ihandles handles)
4733          (point (point))
4734          handle buffer-read-only from props begend not-pref)
4735     (save-window-excursion
4736       (save-restriction
4737         (when ibegend
4738           (narrow-to-region (car ibegend)
4739                             (or (cdr ibegend)
4740                                 (progn
4741                                   (goto-char (car ibegend))
4742                                   (forward-line 2)
4743                                   (point))))
4744           (delete-region (point-min) (point-max))
4745           (mm-remove-parts handles))
4746         (setq begend (list (point-marker)))
4747         ;; Do the toggle.
4748         (unless (setq not-pref (cadr (member preferred ihandles)))
4749           (setq not-pref (car ihandles)))
4750         (when (or ibegend
4751                   (not preferred)
4752                   (not (gnus-unbuttonized-mime-type-p
4753                         "multipart/alternative")))
4754           (gnus-add-text-properties
4755            (setq from (point))
4756            (progn
4757              (insert (format "%d.  " id))
4758              (point))
4759            `(gnus-callback
4760              (lambda (handles)
4761                (unless ,(not ibegend)
4762                  (setq gnus-article-mime-handle-alist
4763                        ',gnus-article-mime-handle-alist))
4764                (gnus-mime-display-alternative
4765                 ',ihandles ',not-pref ',begend ,id))
4766              ,@(gnus-local-map-property gnus-mime-button-map)
4767              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4768              face ,gnus-article-button-face
4769              gnus-part ,id
4770              gnus-data ,handle))
4771           (widget-convert-button 'link from (point)
4772                                  :action 'gnus-widget-press-button
4773                                  :button-keymap gnus-widget-button-keymap)
4774           ;; Do the handles
4775           (while (setq handle (pop handles))
4776             (gnus-add-text-properties
4777              (setq from (point))
4778              (progn
4779                (insert (format "(%c) %-18s"
4780                                (if (equal handle preferred) ?* ? )
4781                                (mm-handle-media-type handle)))
4782                (point))
4783              `(gnus-callback
4784                (lambda (handles)
4785                  (unless ,(not ibegend)
4786                    (setq gnus-article-mime-handle-alist
4787                          ',gnus-article-mime-handle-alist))
4788                  (gnus-mime-display-alternative
4789                   ',ihandles ',handle ',begend ,id))
4790                ,@(gnus-local-map-property gnus-mime-button-map)
4791                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4792                face ,gnus-article-button-face
4793                gnus-part ,id
4794                gnus-data ,handle))
4795             (widget-convert-button 'link from (point)
4796                                    :action 'gnus-widget-press-button
4797                                    :button-keymap gnus-widget-button-keymap)
4798             (insert "  "))
4799           (insert "\n\n"))
4800         (when preferred
4801           (if (stringp (car preferred))
4802               (gnus-display-mime preferred)
4803             (let ((mail-parse-charset gnus-newsgroup-charset)
4804                   (mail-parse-ignored-charsets
4805                    (save-excursion (set-buffer gnus-summary-buffer)
4806                                    gnus-newsgroup-ignored-charsets)))
4807               (mm-display-part preferred)
4808               ;; Do highlighting.
4809               (save-excursion
4810                 (save-restriction
4811                   (narrow-to-region (car begend) (point-max))
4812                   (gnus-treat-article
4813                    nil (length gnus-article-mime-handle-alist)
4814                    (gnus-article-mime-total-parts)
4815                    (mm-handle-media-type handle))))))
4816           (goto-char (point-max))
4817           (setcdr begend (point-marker)))))
4818     (when ibegend
4819       (goto-char point))))
4820
4821 (defconst gnus-article-wash-status-strings
4822   (let ((alist '((cite "c" "Possible hidden citation text"
4823                        " " "All citation text visible")
4824                  (headers "h" "Hidden headers"
4825                           " " "All headers visible.")
4826                  (pgp "p" "Encrypted or signed message status hidden"
4827                       " " "No hidden encryption nor digital signature status")
4828                  (signature "s" "Signature has been hidden"
4829                             " " "Signature is visible")
4830                  (overstrike "o" "Overstrike (^H) characters applied"
4831                              " " "No overstrike characters applied")
4832                  (gnus-show-mime "m" "Mime processing is activated"
4833                                  " " "Mime processing is not activated")
4834                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4835                            " " "No /*_emphasis_*/ characters applied")))
4836         result)
4837     (dolist (entry alist result)
4838       (let ((key (nth 0 entry))
4839             (on (copy-sequence (nth 1 entry)))
4840             (on-help (nth 2 entry))
4841             (off (copy-sequence (nth 3 entry)))
4842             (off-help (nth 4 entry)))
4843         (put-text-property 0 1 'help-echo on-help on)
4844         (put-text-property 0 1 'help-echo off-help off)
4845         (push (list key on off) result))))
4846   "Alist of strings describing wash status in the mode line.
4847 Each entry has the form (KEY ON OF), where the KEY is a symbol
4848 representing the particular washing function, ON is the string to use
4849 in the article mode line when the washing function is active, and OFF
4850 is the string to use when it is inactive.")
4851
4852 (defun gnus-article-wash-status-entry (key value)
4853   (let ((entry (assoc key gnus-article-wash-status-strings)))
4854     (if value (nth 1 entry) (nth 2 entry))))
4855
4856 (defun gnus-article-wash-status ()
4857   "Return a string which display status of article washing."
4858   (save-excursion
4859     (set-buffer gnus-article-buffer)
4860     (let ((cite (memq 'cite gnus-article-wash-types))
4861           (headers (memq 'headers gnus-article-wash-types))
4862           (boring (memq 'boring-headers gnus-article-wash-types))
4863           (pgp (memq 'pgp gnus-article-wash-types))
4864           (pem (memq 'pem gnus-article-wash-types))
4865           (signed (memq 'signed gnus-article-wash-types))
4866           (encrypted (memq 'encrypted gnus-article-wash-types))
4867           (signature (memq 'signature gnus-article-wash-types))
4868           (overstrike (memq 'overstrike gnus-article-wash-types))
4869           (emphasis (memq 'emphasis gnus-article-wash-types)))
4870       (concat
4871        (gnus-article-wash-status-entry 'cite cite)
4872        (gnus-article-wash-status-entry 'headers (or headers boring))
4873        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4874        (gnus-article-wash-status-entry 'signature signature)
4875        (gnus-article-wash-status-entry 'overstrike overstrike)
4876        (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
4877        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4878
4879 (defun gnus-add-wash-type (type)
4880   "Add a washing of TYPE to the current status."
4881   (add-to-list 'gnus-article-wash-types type))
4882
4883 (defun gnus-delete-wash-type (type)
4884   "Add a washing of TYPE to the current status."
4885   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4886
4887 (defun gnus-add-image (category image)
4888   "Add IMAGE of CATEGORY to the list of displayed images."
4889   (let ((entry (assq category gnus-article-image-alist)))
4890     (unless entry
4891       (setq entry (list category))
4892       (push entry gnus-article-image-alist))
4893     (nconc entry (list image))))
4894
4895 (defun gnus-delete-images (category)
4896   "Delete all images in CATEGORY."
4897   (let ((entry (assq category gnus-article-image-alist)))
4898     (dolist (image (cdr entry))
4899       (gnus-remove-image image))
4900     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4901     (gnus-delete-wash-type category)))
4902
4903 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4904
4905 (defun gnus-article-maybe-hide-headers ()
4906   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4907 Provided for backwards compatibility."
4908   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4909                  (not (save-excursion (set-buffer gnus-summary-buffer)
4910                                       gnus-have-all-headers)))
4911              (not gnus-inhibit-hiding))
4912     (gnus-article-hide-headers)))
4913
4914 ;;; Article savers.
4915
4916 (defun gnus-output-to-file (file-name)
4917   "Append the current article to a file named FILE-NAME."
4918   (let ((artbuf (current-buffer)))
4919     (with-temp-buffer
4920       (insert-buffer-substring artbuf)
4921       ;; Append newline at end of the buffer as separator, and then
4922       ;; save it to file.
4923       (goto-char (point-max))
4924       (insert "\n")
4925       (let ((file-name-coding-system nnmail-pathname-coding-system)
4926             (pathname-coding-system nnmail-pathname-coding-system))
4927         (write-region-as-binary (point-min) (point-max) file-name 'append))
4928       t)))
4929
4930 (defun gnus-narrow-to-page (&optional arg)
4931   "Narrow the article buffer to a page.
4932 If given a numerical ARG, move forward ARG pages."
4933   (interactive "P")
4934   (setq arg (if arg (prefix-numeric-value arg) 0))
4935   (save-excursion
4936     (set-buffer gnus-article-buffer)
4937     (goto-char (point-min))
4938     (widen)
4939     ;; Remove any old next/prev buttons.
4940     (when (gnus-visual-p 'page-marker)
4941       (let ((buffer-read-only nil))
4942         (gnus-remove-text-with-property 'gnus-prev)
4943         (gnus-remove-text-with-property 'gnus-next)))
4944     (when
4945         (cond ((< arg 0)
4946                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4947               ((> arg 0)
4948                (re-search-forward page-delimiter nil 'move arg)))
4949       (goto-char (match-end 0)))
4950     (narrow-to-region
4951      (point)
4952      (if (re-search-forward page-delimiter nil 'move)
4953          (match-beginning 0)
4954        (point)))
4955     (when (and (gnus-visual-p 'page-marker)
4956                (not (= (point-min) 1)))
4957       (save-excursion
4958         (goto-char (point-min))
4959         (gnus-insert-prev-page-button)))
4960     (when (and (gnus-visual-p 'page-marker)
4961                (< (+ (point-max) 2) (buffer-size)))
4962       (save-excursion
4963         (goto-char (point-max))
4964         (gnus-insert-next-page-button)))))
4965
4966 ;; Article mode commands
4967
4968 (defun gnus-article-goto-next-page ()
4969   "Show the next page of the article."
4970   (interactive)
4971   (when (gnus-article-next-page)
4972     (goto-char (point-min))
4973     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4974
4975 (defun gnus-article-goto-prev-page ()
4976   "Show the next page of the article."
4977   (interactive)
4978   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4979     (gnus-article-prev-page nil)))
4980
4981 (defun gnus-article-next-page (&optional lines)
4982   "Show the next page of the current article.
4983 If end of article, return non-nil.  Otherwise return nil.
4984 Argument LINES specifies lines to be scrolled up."
4985   (interactive "p")
4986   (let ((start (window-start))
4987         end-of-buffer end-of-page)
4988     (save-excursion
4989       (move-to-window-line -1)
4990       (if (<= (point) start)
4991           (progn
4992             (forward-line 2)
4993             (setq start (point)))
4994         (forward-line 1)
4995         (setq start nil))
4996       (unless (or (cond ((eq (1+ (buffer-size)) (point))
4997                          (and (pos-visible-in-window-p)
4998                               (setq end-of-buffer t)))
4999                         ((eobp)
5000                          (setq end-of-page t)))
5001                   (not lines))
5002         (move-to-window-line lines)
5003         (unless (search-backward "\n\n" nil t)
5004           (setq start (point)))))
5005     (cond (end-of-buffer t)
5006           (end-of-page
5007            (gnus-narrow-to-page 1)
5008            nil)
5009           (t
5010            (if start
5011                (set-window-start (selected-window) start)
5012              (let (window-pixel-scroll-increment)
5013                (scroll-up lines)))
5014            nil))))
5015
5016 (defun gnus-article-prev-page (&optional lines)
5017   "Show previous page of current article.
5018 Argument LINES specifies lines to be scrolled down."
5019   (interactive "p")
5020   (let (beginning-of-buffer beginning-of-page)
5021     (save-excursion
5022       (move-to-window-line 0)
5023       (cond ((eq 1 (point))
5024              (setq beginning-of-buffer t))
5025             ((bobp)
5026              (setq beginning-of-page t))))
5027     (cond (beginning-of-buffer)
5028           (beginning-of-page
5029            (gnus-narrow-to-page -1))
5030           (t
5031            (condition-case nil
5032                (let (window-pixel-scroll-increment)
5033                  (scroll-down lines))
5034              (beginning-of-buffer
5035               (goto-char (point-min))))))))
5036
5037 (defun gnus-article-refer-article ()
5038   "Read article specified by message-id around point."
5039   (interactive)
5040   (let ((point (point)))
5041     (search-forward ">" nil t)          ;Move point to end of "<....>".
5042     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
5043         (let ((message-id (match-string 1)))
5044           (goto-char point)
5045           (set-buffer gnus-summary-buffer)
5046           (gnus-summary-refer-article message-id))
5047       (goto-char (point))
5048       (error "No references around point"))))
5049
5050 (defun gnus-article-show-summary ()
5051   "Reconfigure windows to show summary buffer."
5052   (interactive)
5053   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5054       (error "There is no summary buffer for this article buffer")
5055     (gnus-article-set-globals)
5056     (gnus-configure-windows 'article)
5057     (gnus-summary-goto-subject gnus-current-article)
5058     (gnus-summary-position-point)))
5059
5060 (defun gnus-article-describe-briefly ()
5061   "Describe article mode commands briefly."
5062   (interactive)
5063   (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")))
5064
5065 (defun gnus-article-summary-command ()
5066   "Execute the last keystroke in the summary buffer."
5067   (interactive)
5068   (let ((obuf (current-buffer))
5069         (owin (current-window-configuration))
5070         func)
5071     (switch-to-buffer gnus-article-current-summary 'norecord)
5072     (setq func (lookup-key (current-local-map) (this-command-keys)))
5073     (call-interactively func)
5074     (set-buffer obuf)
5075     (set-window-configuration owin)
5076     (set-window-point (get-buffer-window (current-buffer)) (point))))
5077
5078 (defun gnus-article-summary-command-nosave ()
5079   "Execute the last keystroke in the summary buffer."
5080   (interactive)
5081   (let (func)
5082     (pop-to-buffer gnus-article-current-summary 'norecord)
5083     (setq func (lookup-key (current-local-map) (this-command-keys)))
5084     (call-interactively func)))
5085
5086 (defun gnus-article-check-buffer ()
5087   "Beep if not in an article buffer."
5088   (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5089     (error "Command invoked outside of a Gnus article buffer")))
5090
5091 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5092   "Read a summary buffer key sequence and execute it from the article buffer."
5093   (interactive "P")
5094   (gnus-article-check-buffer)
5095   (let ((nosaves
5096          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5097            "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5098            "=" "^" "\M-^" "|"))
5099         (nosave-but-article
5100          '("A\r"))
5101         (nosave-in-article
5102          '("\C-d"))
5103         (up-to-top
5104          '("n" "Gn" "p" "Gp"))
5105         keys new-sum-point)
5106     (save-excursion
5107       (set-buffer gnus-article-current-summary)
5108       (let (gnus-pick-mode)
5109         (push (or key last-command-event) unread-command-events)
5110         (setq keys (static-if (featurep 'xemacs)
5111                        (events-to-keys (read-key-sequence nil))
5112                      (read-key-sequence nil)))))
5113     (message "")
5114
5115     (if (or (member keys nosaves)
5116             (member keys nosave-but-article)
5117             (member keys nosave-in-article))
5118         (let (func)
5119           (save-window-excursion
5120             (pop-to-buffer gnus-article-current-summary 'norecord)
5121             ;; We disable the pick minor mode commands.
5122             (let (gnus-pick-mode)
5123               (setq func (lookup-key (current-local-map) keys))))
5124           (if (or (not func)
5125                   (numberp func))
5126               (ding)
5127             (unless (member keys nosave-in-article)
5128               (set-buffer gnus-article-current-summary))
5129             (call-interactively func)
5130             (setq new-sum-point (point)))
5131           (when (member keys nosave-but-article)
5132             (pop-to-buffer gnus-article-buffer 'norecord)))
5133       ;; These commands should restore window configuration.
5134       (let ((obuf (current-buffer))
5135             (owin (current-window-configuration))
5136             (opoint (point))
5137             (summary gnus-article-current-summary)
5138             func in-buffer selected)
5139         (if not-restore-window
5140             (pop-to-buffer summary 'norecord)
5141           (switch-to-buffer summary 'norecord))
5142         (setq in-buffer (current-buffer))
5143         ;; We disable the pick minor mode commands.
5144         (if (and (setq func (let (gnus-pick-mode)
5145                               (lookup-key (current-local-map) keys)))
5146                  (functionp func))
5147             (progn
5148               (call-interactively func)
5149               (setq new-sum-point (point))
5150               (when (eq in-buffer (current-buffer))
5151                 (setq selected (gnus-summary-select-article))
5152                 (set-buffer obuf)
5153                 (unless not-restore-window
5154                   (set-window-configuration owin))
5155                 (when (eq selected 'old)
5156                   (article-goto-body)
5157                   (set-window-start (get-buffer-window (current-buffer))
5158                                     1)
5159                   (set-window-point (get-buffer-window (current-buffer))
5160                                     (point)))
5161                 (let ((win (get-buffer-window gnus-article-current-summary)))
5162                   (when win
5163                     (set-window-point win new-sum-point))))    )
5164           (switch-to-buffer gnus-article-buffer)
5165           (ding))))))
5166
5167 (defun gnus-article-describe-key (key)
5168   "Display documentation of the function invoked by KEY.  KEY is a string."
5169   (interactive "kDescribe key: ")
5170   (gnus-article-check-buffer)
5171   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5172       (save-excursion
5173         (set-buffer gnus-article-current-summary)
5174         (let (gnus-pick-mode)
5175           (if (featurep 'xemacs)
5176               (progn
5177                 (push (elt key 0) unread-command-events)
5178                 (setq key (events-to-keys
5179                            (read-key-sequence "Describe key: "))))
5180             (setq unread-command-events
5181                   (mapcar
5182                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5183                    key))
5184             (setq key (read-key-sequence "Describe key: "))))
5185         (describe-key key))
5186     (describe-key key)))
5187
5188 (defun gnus-article-describe-key-briefly (key &optional insert)
5189   "Display documentation of the function invoked by KEY.  KEY is a string."
5190   (interactive "kDescribe key: \nP")
5191   (gnus-article-check-buffer)
5192   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5193       (save-excursion
5194         (set-buffer gnus-article-current-summary)
5195         (let (gnus-pick-mode)
5196           (if (featurep 'xemacs)
5197               (progn
5198                 (push (elt key 0) unread-command-events)
5199                 (setq key (events-to-keys
5200                            (read-key-sequence "Describe key: "))))
5201             (setq unread-command-events
5202                   (mapcar
5203                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5204                    key))
5205             (setq key (read-key-sequence "Describe key: "))))
5206         (describe-key-briefly key insert))
5207     (describe-key-briefly key insert)))
5208
5209 (defun gnus-article-reply-with-original (&optional wide)
5210   "Start composing a reply mail to the current message.
5211 The text in the region will be yanked.  If the region isn't active,
5212 the entire article will be yanked."
5213   (interactive "P")
5214   (let ((article (cdr gnus-article-current)) cont)
5215     (if (not (mark t))
5216         (with-current-buffer gnus-summary-buffer
5217           (gnus-summary-reply (list (list article)) wide))
5218       (setq cont (buffer-substring (point) (mark t)))
5219       ;; Deactivate active regions.
5220       (when (and (boundp 'transient-mark-mode)
5221                  transient-mark-mode)
5222         (setq mark-active nil))
5223       (with-current-buffer gnus-summary-buffer
5224         (gnus-summary-reply
5225          (list (list article cont)) wide)))))
5226
5227 (defun gnus-article-followup-with-original ()
5228   "Compose a followup to the current article.
5229 The text in the region will be yanked.  If the region isn't active,
5230 the entire article will be yanked."
5231   (interactive)
5232   (let ((article (cdr gnus-article-current)) cont)
5233       (if (not (mark t))
5234           (with-current-buffer gnus-summary-buffer
5235             (gnus-summary-followup (list (list article))))
5236         (setq cont (buffer-substring (point) (mark t)))
5237         ;; Deactivate active regions.
5238         (when (and (boundp 'transient-mark-mode)
5239                    transient-mark-mode)
5240           (setq mark-active nil))
5241         (with-current-buffer gnus-summary-buffer
5242           (gnus-summary-followup
5243            (list (list article cont)))))))
5244
5245 (defun gnus-article-hide (&optional arg force)
5246   "Hide all the gruft in the current article.
5247 This means that PGP stuff, signatures, cited text and (some)
5248 headers will be hidden.
5249 If given a prefix, show the hidden text instead."
5250   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5251   (gnus-article-hide-headers arg)
5252   (gnus-article-hide-list-identifiers arg)
5253   (gnus-article-hide-pgp arg)
5254   (gnus-article-hide-citation-maybe arg force)
5255   (gnus-article-hide-signature arg))
5256
5257 (defun gnus-article-maybe-highlight ()
5258   "Do some article highlighting if article highlighting is requested."
5259   (when (gnus-visual-p 'article-highlight 'highlight)
5260     (gnus-article-highlight-some)))
5261
5262 (defun gnus-check-group-server ()
5263   ;; Make sure the connection to the server is alive.
5264   (unless (gnus-server-opened
5265            (gnus-find-method-for-group gnus-newsgroup-name))
5266     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5267     (gnus-request-group gnus-newsgroup-name t)))
5268
5269 (eval-when-compile
5270   (autoload 'nneething-get-file-name "nneething"))
5271
5272 (defun gnus-request-article-this-buffer (article group)
5273   "Get an article and insert it into this buffer."
5274   (let (do-update-line sparse-header)
5275     (prog1
5276         (save-excursion
5277           (erase-buffer)
5278           (gnus-kill-all-overlays)
5279           (setq group (or group gnus-newsgroup-name))
5280
5281           ;; Using `gnus-request-article' directly will insert the article into
5282           ;; `nntp-server-buffer' - so we'll save some time by not having to
5283           ;; copy it from the server buffer into the article buffer.
5284
5285           ;; We only request an article by message-id when we do not have the
5286           ;; headers for it, so we'll have to get those.
5287           (when (stringp article)
5288             (gnus-read-header article))
5289
5290           ;; If the article number is negative, that means that this article
5291           ;; doesn't belong in this newsgroup (possibly), so we find its
5292           ;; message-id and request it by id instead of number.
5293           (when (and (numberp article)
5294                      gnus-summary-buffer
5295                      (get-buffer gnus-summary-buffer)
5296                      (gnus-buffer-exists-p gnus-summary-buffer))
5297             (save-excursion
5298               (set-buffer gnus-summary-buffer)
5299               (let ((header (gnus-summary-article-header article)))
5300                 (when (< article 0)
5301                   (cond
5302                    ((memq article gnus-newsgroup-sparse)
5303                     ;; This is a sparse gap article.
5304                     (setq do-update-line article)
5305                     (setq article (mail-header-id header))
5306                     (setq sparse-header (gnus-read-header article))
5307                     (setq gnus-newsgroup-sparse
5308                           (delq article gnus-newsgroup-sparse)))
5309                    ((vectorp header)
5310                     ;; It's a real article.
5311                     (setq article (mail-header-id header)))
5312                    (t
5313                     ;; It is an extracted pseudo-article.
5314                     (setq article 'pseudo)
5315                     (gnus-request-pseudo-article header))))
5316
5317                 (let ((method (gnus-find-method-for-group
5318                                gnus-newsgroup-name)))
5319                   (when (and (eq (car method) 'nneething)
5320                              (vectorp header))
5321                     (let ((dir (nneething-get-file-name
5322                                 (mail-header-id header))))
5323                       (when (and (stringp dir)
5324                                  (file-directory-p dir))
5325                         (setq article 'nneething)
5326                         (gnus-group-enter-directory dir))))))))
5327
5328           (cond
5329            ;; Refuse to select canceled articles.
5330            ((and (numberp article)
5331                  gnus-summary-buffer
5332                  (get-buffer gnus-summary-buffer)
5333                  (gnus-buffer-exists-p gnus-summary-buffer)
5334                  (eq (cdr (save-excursion
5335                             (set-buffer gnus-summary-buffer)
5336                             (assq article gnus-newsgroup-reads)))
5337                      gnus-canceled-mark))
5338             nil)
5339            ;; We first check `gnus-original-article-buffer'.
5340            ((and (get-buffer gnus-original-article-buffer)
5341                  (numberp article)
5342                  (save-excursion
5343                    (set-buffer gnus-original-article-buffer)
5344                    (and (equal (car gnus-original-article) group)
5345                         (eq (cdr gnus-original-article) article))))
5346             (insert-buffer-substring gnus-original-article-buffer)
5347             'article)
5348            ;; Check the backlog.
5349            ((and gnus-keep-backlog
5350                  (gnus-backlog-request-article group article (current-buffer)))
5351             'article)
5352            ;; Check asynchronous pre-fetch.
5353            ((gnus-async-request-fetched-article group article (current-buffer))
5354             (gnus-async-prefetch-next group article gnus-summary-buffer)
5355             (when (and (numberp article) gnus-keep-backlog)
5356               (gnus-backlog-enter-article group article (current-buffer)))
5357             'article)
5358            ;; Check the cache.
5359            ((and gnus-use-cache
5360                  (numberp article)
5361                  (gnus-cache-request-article article group))
5362             'article)
5363            ;; Check the agent cache.
5364            ((and gnus-agent gnus-agent-cache gnus-plugged
5365                  (numberp article)
5366                  (gnus-agent-request-article article group))
5367             'article)
5368            ;; Get the article and put into the article buffer.
5369            ((or (stringp article)
5370                 (numberp article))
5371             (let ((gnus-override-method gnus-override-method)
5372                   (methods (and (stringp article)
5373                                 gnus-refer-article-method))
5374                   (backend (car (gnus-find-method-for-group
5375                                  gnus-newsgroup-name)))
5376                   result
5377                   (buffer-read-only nil))
5378               (if (or (not (listp methods))
5379                       (and (symbolp (car methods))
5380                            (assq (car methods) nnoo-definition-alist)))
5381                   (setq methods (list methods)))
5382               (when (and (null gnus-override-method)
5383                          methods)
5384                 (setq gnus-override-method (pop methods)))
5385               (while (not result)
5386                 (when (eq gnus-override-method 'current)
5387                   (setq gnus-override-method
5388                         (with-current-buffer gnus-summary-buffer
5389                           gnus-current-select-method)))
5390                 (erase-buffer)
5391                 (gnus-kill-all-overlays)
5392                 (let ((gnus-newsgroup-name group))
5393                   (gnus-check-group-server))
5394                 (cond
5395                  ((gnus-request-article article group (current-buffer))
5396                   (when (numberp article)
5397                     (gnus-async-prefetch-next group article
5398                                               gnus-summary-buffer)
5399                     (when gnus-keep-backlog
5400                       (gnus-backlog-enter-article
5401                        group article (current-buffer))))
5402                   (setq result 'article))
5403                  (methods
5404                   (setq gnus-override-method (pop methods)))
5405                  ((not (string-match "^400 "
5406                                      (nnheader-get-report backend)))
5407                   ;; If we get 400 server disconnect, reconnect and
5408                   ;; retry; otherwise, assume the article has expired.
5409                   (setq result 'done))))
5410               (and (eq result 'article) 'article)))
5411            ;; It was a pseudo.
5412            (t article)))
5413
5414       ;; Associate this article with the current summary buffer.
5415       (setq gnus-article-current-summary gnus-summary-buffer)
5416
5417       ;; Take the article from the original article buffer
5418       ;; and place it in the buffer it's supposed to be in.
5419       (when (and (get-buffer gnus-article-buffer)
5420                  (equal (buffer-name (current-buffer))
5421                         (buffer-name (get-buffer gnus-article-buffer))))
5422         (save-excursion
5423           (if (get-buffer gnus-original-article-buffer)
5424               (set-buffer gnus-original-article-buffer)
5425             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5426             (buffer-disable-undo)
5427             (setq major-mode 'gnus-original-article-mode)
5428             (setq buffer-read-only t))
5429           (let (buffer-read-only)
5430             (erase-buffer)
5431             (insert-buffer-substring gnus-article-buffer))
5432           (setq gnus-original-article (cons group article)))
5433
5434         ;; Decode charsets.
5435         (run-hooks 'gnus-article-decode-hook)
5436         ;; Mark article as decoded or not.
5437         (setq gnus-article-decoded-p gnus-article-decode-hook))
5438
5439       ;; Update sparse articles.
5440       (when (and do-update-line
5441                  (or (numberp article)
5442                      (stringp article)))
5443         (let ((buf (current-buffer)))
5444           (set-buffer gnus-summary-buffer)
5445           (gnus-summary-update-article do-update-line sparse-header)
5446           (gnus-summary-goto-subject do-update-line nil t)
5447           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5448                             (point))
5449           (set-buffer buf))))))
5450
5451 ;;;
5452 ;;; Article editing
5453 ;;;
5454
5455 (defcustom gnus-article-edit-mode-hook nil
5456   "Hook run in article edit mode buffers."
5457   :group 'gnus-article-various
5458   :type 'hook)
5459
5460 (defcustom gnus-article-edit-article-setup-function
5461   'gnus-article-mime-edit-article-setup
5462   "Function called to setup an editing article buffer."
5463   :group 'gnus-article-various
5464   :type 'function)
5465
5466 (defvar gnus-article-edit-done-function nil)
5467
5468 (defvar gnus-article-edit-mode-map nil)
5469
5470 ;; Should we be using derived.el for this?
5471 (unless gnus-article-edit-mode-map
5472   (setq gnus-article-edit-mode-map (make-keymap))
5473   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5474
5475   (gnus-define-keys gnus-article-edit-mode-map
5476     "\C-c?"    describe-mode
5477     "\C-c\C-c" gnus-article-edit-done
5478     "\C-c\C-k" gnus-article-edit-exit
5479     "\C-c\C-f\C-t" message-goto-to
5480     "\C-c\C-f\C-o" message-goto-from
5481     "\C-c\C-f\C-b" message-goto-bcc
5482     ;;"\C-c\C-f\C-w" message-goto-fcc
5483     "\C-c\C-f\C-c" message-goto-cc
5484     "\C-c\C-f\C-s" message-goto-subject
5485     "\C-c\C-f\C-r" message-goto-reply-to
5486     "\C-c\C-f\C-n" message-goto-newsgroups
5487     "\C-c\C-f\C-d" message-goto-distribution
5488     "\C-c\C-f\C-f" message-goto-followup-to
5489     "\C-c\C-f\C-m" message-goto-mail-followup-to
5490     "\C-c\C-f\C-k" message-goto-keywords
5491     "\C-c\C-f\C-u" message-goto-summary
5492     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5493     "\C-c\C-f\C-a" message-gen-unsubscribed-mft
5494     "\C-c\C-b" message-goto-body
5495     "\C-c\C-i" message-goto-signature
5496
5497     "\C-c\C-t" message-insert-to
5498     "\C-c\C-n" message-insert-newsgroups
5499     "\C-c\C-o" message-sort-headers
5500     "\C-c\C-e" message-elide-region
5501     "\C-c\C-v" message-delete-not-region
5502     "\C-c\C-z" message-kill-to-signature
5503     "\M-\r" message-newline-and-reformat
5504     "\C-c\C-a" mml-attach-file
5505     "\C-a" message-beginning-of-line
5506     "\t" message-tab
5507     "\M-;" comment-region)
5508
5509   (gnus-define-keys (gnus-article-edit-wash-map
5510                      "\C-c\C-w" gnus-article-edit-mode-map)
5511     "f" gnus-article-edit-full-stops))
5512
5513 (easy-menu-define
5514   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5515   '("Field"
5516     ["Fetch To" message-insert-to t]
5517     ["Fetch Newsgroups" message-insert-newsgroups t]
5518     "----"
5519     ["To" message-goto-to t]
5520     ["From" message-goto-from t]
5521     ["Subject" message-goto-subject t]
5522     ["Cc" message-goto-cc t]
5523     ["Reply-To" message-goto-reply-to t]
5524     ["Summary" message-goto-summary t]
5525     ["Keywords" message-goto-keywords t]
5526     ["Newsgroups" message-goto-newsgroups t]
5527     ["Followup-To" message-goto-followup-to t]
5528     ["Mail-Followup-To" message-goto-mail-followup-to t]
5529     ["Distribution" message-goto-distribution t]
5530     ["Body" message-goto-body t]
5531     ["Signature" message-goto-signature t]))
5532
5533 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5534   "Major mode for editing articles.
5535 This is an extended text-mode.
5536
5537 \\{gnus-article-edit-mode-map}"
5538   (make-local-variable 'gnus-article-edit-done-function)
5539   (make-local-variable 'gnus-prev-winconf)
5540   (set (make-local-variable 'font-lock-defaults)
5541        '(message-font-lock-keywords t))
5542   (set (make-local-variable 'mail-header-separator) "")
5543   (easy-menu-add message-mode-field-menu message-mode-map)
5544   (setq buffer-read-only nil)
5545   (buffer-enable-undo)
5546   (widen))
5547
5548 (defun gnus-article-edit (&optional force)
5549   "Edit the current article.
5550 This will have permanent effect only in mail groups.
5551 If FORCE is non-nil, allow editing of articles even in read-only
5552 groups."
5553   (interactive "P")
5554   (when (and (not force)
5555              (gnus-group-read-only-p))
5556     (error "The current newsgroup does not support article editing"))
5557   (gnus-article-date-original)
5558   (gnus-article-edit-article
5559    'ignore
5560    `(lambda (no-highlight)
5561       'ignore
5562       (gnus-summary-edit-article-done
5563        ,(or (mail-header-references gnus-current-headers) "")
5564        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5565
5566 (defun gnus-article-edit-article (start-func exit-func)
5567   "Start editing the contents of the current article buffer."
5568   (let ((winconf (current-window-configuration)))
5569     (set-buffer gnus-article-buffer)
5570     (gnus-article-edit-mode)
5571     (funcall start-func)
5572     (set-buffer-modified-p nil)
5573     (gnus-configure-windows 'edit-article)
5574     (setq gnus-article-edit-done-function exit-func)
5575     (setq gnus-prev-winconf winconf)
5576     (when gnus-article-edit-article-setup-function
5577       (funcall gnus-article-edit-article-setup-function))
5578     (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5579
5580 (defun gnus-article-edit-done (&optional arg)
5581   "Update the article edits and exit."
5582   (interactive "P")
5583   (let ((func gnus-article-edit-done-function)
5584         (buf (current-buffer))
5585         (start (window-start))
5586         (p (point))
5587         (winconf gnus-prev-winconf))
5588     (remove-hook 'gnus-article-mode-hook
5589                  'gnus-article-mime-edit-article-unwind)
5590     (widen) ;; Widen it in case that users narrowed the buffer.
5591     (funcall func arg)
5592     (set-buffer buf)
5593     ;; The cache and backlog have to be flushed somewhat.
5594     (when gnus-keep-backlog
5595       (gnus-backlog-remove-article
5596        (car gnus-article-current) (cdr gnus-article-current)))
5597     ;; Flush original article as well.
5598     (save-excursion
5599       (when (get-buffer gnus-original-article-buffer)
5600         (set-buffer gnus-original-article-buffer)
5601         (setq gnus-original-article nil)))
5602     (when gnus-use-cache
5603       (gnus-cache-update-article
5604        (car gnus-article-current) (cdr gnus-article-current)))
5605     ;; We remove all text props from the article buffer.
5606     (kill-all-local-variables)
5607     (gnus-set-text-properties (point-min) (point-max) nil)
5608     (gnus-article-mode)
5609     (set-window-configuration winconf)
5610     (set-buffer buf)
5611     (set-window-start (get-buffer-window buf) start)
5612     (set-window-point (get-buffer-window buf) (point))))
5613
5614 (defun gnus-article-edit-exit ()
5615   "Exit the article editing without updating."
5616   (interactive)
5617   (when (or (not (buffer-modified-p))
5618             (yes-or-no-p "Article modified; kill anyway? "))
5619     (let ((curbuf (current-buffer))
5620           (p (point))
5621           (window-start (window-start)))
5622       (erase-buffer)
5623       (if (gnus-buffer-live-p gnus-original-article-buffer)
5624           (insert-buffer-substring gnus-original-article-buffer))
5625       (let ((winconf gnus-prev-winconf))
5626         (gnus-article-mode)
5627         (set-window-configuration winconf)
5628         ;; Tippy-toe some to make sure that point remains where it was.
5629         (save-current-buffer
5630           (set-buffer curbuf)
5631           (set-window-start (get-buffer-window (current-buffer)) window-start)
5632           (goto-char p))))))
5633
5634 (defun gnus-article-edit-full-stops ()
5635   "Interactively repair spacing at end of sentences."
5636   (interactive)
5637   (save-excursion
5638     (goto-char (point-min))
5639     (search-forward-regexp "^$" nil t)
5640     (let ((case-fold-search nil))
5641       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5642
5643 ;;;
5644 ;;; Article editing with MIME-Edit
5645 ;;;
5646
5647 (defcustom gnus-article-mime-edit-article-setup-hook nil
5648   "Hook run after setting up a MIME editing article buffer."
5649   :group 'gnus-article-various
5650   :type 'hook)
5651
5652 (defun gnus-article-mime-edit-article-unwind ()
5653   "Unwind `gnus-article-buffer' if article editing was given up."
5654   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5655   (when (featurep 'font-lock)
5656     (setq font-lock-defaults nil)
5657     (font-lock-mode -1))
5658   (when mime-edit-mode-flag
5659     (mime-edit-exit 'nomime 'no-error)
5660     (message "")))
5661
5662 (defun gnus-article-mime-edit-article-setup ()
5663   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5664 after replacing with the original article."
5665   (setq gnus-show-mime t)
5666   (setq gnus-article-edit-done-function
5667         `(lambda (&rest args)
5668            (when mime-edit-mode-flag
5669              (let (mime-edit-insert-user-agent-field)
5670                (mime-edit-exit))
5671              (message ""))
5672            (goto-char (point-min))
5673            (let (case-fold-search)
5674              (when (re-search-forward
5675                     (format "^%s$" (regexp-quote mail-header-separator))
5676                     nil t)
5677                (replace-match "")))
5678            (apply ,gnus-article-edit-done-function args)
5679            (insert
5680             (prog1
5681                 (buffer-substring-no-properties (point-min) (point-max))
5682               (set-buffer (get-buffer-create gnus-original-article-buffer))
5683               (erase-buffer)))
5684            (setq gnus-current-headers (gnus-article-make-full-mail-header))
5685            (set-buffer gnus-article-buffer)
5686            (gnus-article-prepare-display)))
5687   (substitute-key-definition 'gnus-article-edit-done
5688                              'gnus-article-mime-edit-done
5689                              gnus-article-edit-mode-map)
5690   (substitute-key-definition 'gnus-article-edit-exit
5691                              'gnus-article-mime-edit-exit
5692                              gnus-article-edit-mode-map)
5693   (erase-buffer)
5694   (insert-buffer-substring gnus-original-article-buffer)
5695   (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5696     (fset 'mime-edit-decode-single-part-in-buffer
5697           (lambda (&rest args)
5698             (if (let ((content-type (car args)))
5699                   (and (eq 'message (mime-content-type-primary-type
5700                                      content-type))
5701                        (eq 'rfc822 (mime-content-type-subtype content-type))))
5702                 (setcar (cdr args) 'not-decode-text))
5703             (apply ofn args)))
5704     (unwind-protect
5705         (mime-edit-again)
5706       (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5707   (when (featurep 'font-lock)
5708     (set (make-local-variable 'font-lock-defaults)
5709          '(message-font-lock-keywords t))
5710     (font-lock-set-defaults)
5711     (turn-on-font-lock))
5712   (set-buffer-modified-p nil)
5713   (delete-other-windows)
5714   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5715   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5716
5717 (defun gnus-article-mime-edit-done (&optional arg)
5718   "Update the article MIME edits and exit."
5719   (interactive "P")
5720   (when (featurep 'font-lock)
5721     (setq font-lock-defaults nil)
5722     (font-lock-mode -1))
5723   (gnus-article-edit-done arg))
5724
5725 (defun gnus-article-mime-edit-exit ()
5726   "Exit the article MIME editing without updating."
5727   (interactive)
5728   (when (or (not (buffer-modified-p))
5729             (yes-or-no-p "Article modified; kill anyway? "))
5730     (when (featurep 'font-lock)
5731       (setq font-lock-defaults nil)
5732       (font-lock-mode -1))
5733     (when mime-edit-mode-flag
5734       (let (mime-edit-insert-user-agent-field)
5735         (mime-edit-exit))
5736       (message ""))
5737     (goto-char (point-min))
5738     (let (case-fold-search)
5739       (when (re-search-forward
5740              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5741         (replace-match "")))
5742     (let ((winconf gnus-prev-winconf))
5743       (insert (prog1
5744                   (buffer-substring-no-properties (point-min) (point-max))
5745                 (set-buffer (get-buffer-create gnus-original-article-buffer))
5746                 (erase-buffer)))
5747       (setq gnus-current-headers (gnus-article-make-full-mail-header))
5748       (set-buffer gnus-article-buffer)
5749       (gnus-article-prepare-display)
5750       (set-window-configuration winconf))))
5751
5752 ;;;
5753 ;;; Article highlights
5754 ;;;
5755
5756 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5757
5758 ;;; Internal Variables:
5759
5760 (defcustom gnus-button-url-regexp 
5761   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5762       "\\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:]]\\)"
5763     "\\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\\)\\)")
5764   "Regular expression that matches URLs."
5765   :group 'gnus-article-buttons
5766   :type 'regexp)
5767
5768 (defcustom gnus-button-man-handler 'man
5769   "Function to use for displaying man pages.
5770 The function must take at least one argument with a string naming the
5771 man page."
5772   :type '(choice (function-item :tag "Man" man)
5773                  (function-item :tag "Woman" woman)
5774                  (function :tag "Other"))
5775   :group 'gnus-article-buttons)
5776
5777 (defcustom gnus-button-prefer-mid-or-mail 'guess
5778   "What to do when the button on a string as \"foo123@bar.com\" is pushed.
5779 Strings like this can be either a message ID or a mail address.  If the
5780 variable is set to the symbol `ask', query the user what do do.  If it is the
5781 symbol `guess', Gnus will do a guess and query the user what do do if it is
5782 ambiguous. If it is one of the sybols `mid' or `mail', Gnus will always assume
5783 that the string is a message ID or a mail address, respectivly.  See the
5784 variable `gnus-button-guessed-mid-regexp' for details concerning the
5785 guessing."
5786   ;; FIXME: doc-string could/should be improved.
5787   :group 'gnus-article-buttons
5788   :type '(choice (const ask)
5789                  (const guess)
5790                  (const mid)
5791                  (const mail)))
5792
5793 (defcustom gnus-button-guessed-mid-regexp
5794   (concat
5795    "^<?\\(slrn\\|Pine\\.\\)"
5796    "\\|\\.fsf@\\|\\.ln@\\|@4ax\\.com\\|@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de"
5797           "\\|^<?.*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*@")
5798   "Regular expression that matches message IDs and not mail addresses."
5799   ;; TODO: Incorporate more matches from
5800   ;; <URL:http://piology.org/perl/id-or-mail.pl.html>. I.e. translate the
5801   ;; Perl-REs to Elisp-REs.
5802   :group 'gnus-article-buttons
5803   :type 'regexp)
5804
5805 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5806   (let* ((pref gnus-button-prefer-mid-or-mail)
5807          (url-mid (concat "news" ":" mid-or-mail))
5808          (url-mailto (concat "mailto" ":" mid-or-mail)))
5809     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5810     ;; If it looks like a MID (well known readers or servers) use 'mid,
5811     ;; otherwise 'ask the user.
5812     (if (eq pref 'guess)
5813         (if (string-match gnus-button-guessed-mid-regexp mid-or-mail)
5814             (setq pref 'mid)
5815           (setq pref 'ask)))
5816     (if (eq pref 'ask)
5817         (save-window-excursion
5818           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
5819               (setq pref 'mail)
5820             (setq pref 'mid))))
5821     (cond ((eq pref 'mid)
5822            (gnus-message 9 "calling `gnus-button-handle-news' %s" url-mid)
5823            (gnus-button-handle-news url-mid))
5824           ((eq pref 'mail)
5825            (gnus-message 9 "calling `gnus-url-mailto'  %s" url-mailto)
5826            (gnus-url-mailto url-mailto)))))
5827
5828 (defun gnus-button-handle-custom (url)
5829   "Follow a Custom URL."
5830   (customize-apropos (gnus-url-unhex-string url)))
5831
5832 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[F1]1>?\\)")
5833
5834 (defun gnus-button-handle-describe-function (url)
5835   "Call describe-function when pushing the corresponing URL button."
5836   (describe-function
5837    (intern
5838     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5839
5840 (defun gnus-button-handle-describe-variable (url)
5841   "Call describe-variable when pushing the corresponing URL button."
5842   (describe-variable
5843    (intern
5844     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5845
5846 ;; FIXME: Is is possible to implement this?  Else it should be removed here
5847 ;; and in `gnus-button-alist'.
5848 (defun gnus-button-handle-describe-key (url)
5849   "Call describe-key when pushing the corresponing URL button."
5850   (error "not implemented"))
5851
5852 (defun gnus-button-handle-apropos (url)
5853   "Call apropos when pushing the corresponing URL button."
5854   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5855
5856 (defun gnus-button-handle-apropos-command (url)
5857   "Call apropos when pushing the corresponing URL button."
5858   (apropos-command (gnus-replace-in-string url
5859                                            gnus-button-handle-describe-prefix "")))
5860
5861 (defun gnus-button-handle-apropos-variable (url)
5862   "Call apropos when pushing the corresponing URL button."
5863   (apropos-variable (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5864
5865 (defcustom gnus-button-man-level 5
5866   "*Integer that says how many man-related buttons Gnus will show.
5867 The higher the number, the more buttons will appear and the more false
5868 positves are possible.  Note that you can set this variable local to
5869 specifific groups.  Setting it higher in Unix groups is probably a good idea.
5870 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5871 how to set variables in specific groups."
5872   :group 'gnus-article-buttons
5873   :type 'integer)
5874
5875 (defcustom gnus-button-emacs-level 5
5876   "*Integer that says how many emacs-related buttons Gnus will show.  
5877 The higher the number, the more buttons will appear and the more false
5878 positves are possible.  Note that you can set this variable local to
5879 specifific groups.  Setting it higher in Emacs or Gnus related groups is
5880 probably a good idea.See Info node `(gnus)Group Parameters' and the variable
5881 `gnus-parameters' on how to set variables in specific groups."
5882   :group 'gnus-article-buttons
5883   :type 'integer)
5884
5885 (defcustom gnus-button-mail-level 5
5886   "*Integer that says how many buttons for message IDs or mail addresses will appear.
5887 The higher the number, the more buttons will appear and the more false
5888 positves are possible."
5889   :group 'gnus-article-buttons
5890   :type 'integer)
5891
5892 (defcustom gnus-button-alist
5893   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5894      0 t gnus-button-handle-news 3)
5895     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5896      gnus-button-handle-news 2)
5897     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5898      1 t
5899      gnus-button-fetch-group 4)
5900     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5901     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5902      t gnus-button-message-id 3)
5903     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5904     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5905     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5906     ;; This is info
5907     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 
5908      (>= gnus-button-emacs-level 1) gnus-button-handle-info 2)
5909     ;; This is custom
5910     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
5911      (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
5912     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5913      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
5914     ;; Emacs help commands
5915     ("M-x[ \t\n]apropos[ \t\n]\\([^ ]+\\)[ \t\n]RET"
5916      ;; regexp doesn't match arguments containing ` '.
5917      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
5918     ("M-x[ \t\n]apropos-command[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5919      (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
5920     ("M-x[ \t\n]apropos-variable[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5921      (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
5922     ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]f[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5923      (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
5924     ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]v[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5925      (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
5926     ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]k[ \t\n]\\([^ ]+\\)[ \t\n]" 0
5927      ;; this regexp needs to be fixed!
5928      (>= gnus-button-emacs-level 9) gnus-button-handle-describe-key 2)
5929     ;; This is how URLs _should_ be embedded in text...
5930     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5931     ;; Raw URLs.
5932     (gnus-button-url-regexp 0 t browse-url 0)
5933     ;; man pages
5934     ("\\b\\([a-z][a-z]+\\)([0-9])\\W" 0
5935      (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
5936      gnus-button-handle-man 1)
5937     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
5938     ("\\b\\([a-zA-Z][-_.a-zA-Z0-9]+\\)([0-9])\\W" 0
5939      (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
5940      gnus-button-handle-man 1)
5941     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm), SoWWWAnchor(3iv)
5942     ("\\b\\([a-zA-Z][-_.:a-zA-Z0-9]+\\)([0-9][a-z]*)\\W" 0
5943      (>= gnus-button-man-level 5) gnus-button-handle-man 1)
5944     ;; MID or mail: To avoid too many false positives we don't try to catch
5945     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
5946     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
5947     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
5948     ;; so that non-ambiguous entries (see above) match first.
5949     ("\\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"
5950      0 (>= gnus-button-mail-level 5) gnus-button-handle-mid-or-mail 1))
5951   "*Alist of regexps matching buttons in article bodies.
5952
5953 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5954 REGEXP: is the string matching text around the button (can also be lisp 
5955 expression evaluating to a string),
5956 BUTTON: is the number of the regexp grouping actually matching the button,
5957 FORM: is a lisp expression which must eval to true for the button to
5958 be added,
5959 CALLBACK: is the function to call when the user push this button, and each
5960 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5961
5962 CALLBACK can also be a variable, in that case the value of that
5963 variable it the real callback function."
5964   :group 'gnus-article-buttons
5965   :type '(repeat (list (choice regexp variable)
5966                        (integer :tag "Button")
5967                        (sexp :tag "Form")
5968                        (function :tag "Callback")
5969                        (repeat :tag "Par"
5970                                :inline t
5971                                (integer :tag "Regexp group")))))
5972
5973 (defcustom gnus-header-button-alist
5974   '(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5975      0 t gnus-button-message-id 0)
5976     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5977     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5978      0 t gnus-button-mailto 0)
5979     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp 0 t browse-url 0)
5980     ("^Subject:" gnus-button-url-regexp 0 t browse-url 0)
5981     ("^[^:]+:" gnus-button-url-regexp 0 t browse-url 0)
5982     ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5983     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5984      gnus-button-message-id 3))
5985   "*Alist of headers and regexps to match buttons in article heads.
5986
5987 This alist is very similar to `gnus-button-alist', except that each
5988 alist has an additional HEADER element first in each entry:
5989
5990 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5991
5992 HEADER is a regexp to match a header.  For a fuller explanation, see
5993 `gnus-button-alist'."
5994   :group 'gnus-article-buttons
5995   :group 'gnus-article-headers
5996   :type '(repeat (list (regexp :tag "Header")
5997                        regexp
5998                        (integer :tag "Button")
5999                        (sexp :tag "Form")
6000                        (function :tag "Callback")
6001                        (repeat :tag "Par"
6002                                :inline t
6003                                (integer :tag "Regexp group")))))
6004
6005 (defvar gnus-button-regexp nil)
6006 (defvar gnus-button-marker-list nil)
6007 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6008
6009 (defvar gnus-button-last nil)
6010 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6011
6012 ;;; Commands:
6013
6014 (defun gnus-article-push-button (event)
6015   "Check text under the mouse pointer for a callback function.
6016 If the text under the mouse pointer has a `gnus-callback' property,
6017 call it with the value of the `gnus-data' text property."
6018   (interactive "e")
6019   (set-buffer (window-buffer (posn-window (event-start event))))
6020   (let* ((pos (posn-point (event-start event)))
6021          (data (get-text-property pos 'gnus-data))
6022          (fun (get-text-property pos 'gnus-callback)))
6023     (goto-char pos)
6024     (when fun
6025       (funcall fun data))))
6026
6027 (defun gnus-article-press-button ()
6028   "Check text at point for a callback function.
6029 If the text at point has a `gnus-callback' property,
6030 call it with the value of the `gnus-data' text property."
6031   (interactive)
6032   (let* ((data (get-text-property (point) 'gnus-data))
6033          (fun (get-text-property (point) 'gnus-callback)))
6034     (when fun
6035       (funcall fun data))))
6036
6037 (defun gnus-article-prev-button (n)
6038   "Move point to N buttons backward.
6039 If N is negative, move forward instead."
6040   (interactive "p")
6041   (gnus-article-next-button (- n)))
6042
6043 (defun gnus-article-next-button (n)
6044   "Move point to N buttons forward.
6045 If N is negative, move backward instead."
6046   (interactive "p")
6047   (let ((function (if (< n 0) 'previous-single-property-change
6048                     'next-single-property-change))
6049         (inhibit-point-motion-hooks t)
6050         (backward (< n 0))
6051         (limit (if (< n 0) (point-min) (point-max))))
6052     (setq n (abs n))
6053     (while (and (not (= limit (point)))
6054                 (> n 0))
6055       ;; Skip past the current button.
6056       (when (get-text-property (point) 'gnus-callback)
6057         (goto-char (funcall function (point) 'gnus-callback nil limit)))
6058       ;; Go to the next (or previous) button.
6059       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
6060       ;; Put point at the start of the button.
6061       (when (and backward (not (get-text-property (point) 'gnus-callback)))
6062         (goto-char (funcall function (point) 'gnus-callback nil limit)))
6063       ;; Skip past intangible buttons.
6064       (when (get-text-property (point) 'intangible)
6065         (incf n))
6066       (decf n))
6067     (unless (zerop n)
6068       (gnus-message 5 "No more buttons"))
6069     n))
6070
6071 (defun gnus-article-highlight (&optional force)
6072   "Highlight current article.
6073 This function calls `gnus-article-highlight-headers',
6074 `gnus-article-highlight-citation',
6075 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6076 do the highlighting.  See the documentation for those functions."
6077   (interactive (list 'force))
6078   (gnus-article-highlight-headers)
6079   (gnus-article-highlight-citation force)
6080   (gnus-article-highlight-signature)
6081   (gnus-article-add-buttons force)
6082   (gnus-article-add-buttons-to-head))
6083
6084 (defun gnus-article-highlight-some (&optional force)
6085   "Highlight current article.
6086 This function calls `gnus-article-highlight-headers',
6087 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6088 do the highlighting.  See the documentation for those functions."
6089   (interactive (list 'force))
6090   (gnus-article-highlight-headers)
6091   (gnus-article-highlight-signature)
6092   (gnus-article-add-buttons))
6093
6094 (defun gnus-article-highlight-headers ()
6095   "Highlight article headers as specified by `gnus-header-face-alist'."
6096   (interactive)
6097   (save-excursion
6098     (set-buffer gnus-article-buffer)
6099     (save-restriction
6100       (let ((alist gnus-header-face-alist)
6101             (buffer-read-only nil)
6102             (case-fold-search t)
6103             (inhibit-point-motion-hooks t)
6104             entry regexp header-face field-face from hpoints fpoints)
6105         (article-narrow-to-head)
6106         (while (setq entry (pop alist))
6107           (goto-char (point-min))
6108           (setq regexp (concat "^\\("
6109                                (if (string-equal "" (nth 0 entry))
6110                                    "[^\t ]"
6111                                  (nth 0 entry))
6112                                "\\)")
6113                 header-face (nth 1 entry)
6114                 field-face (nth 2 entry))
6115           (while (and (re-search-forward regexp nil t)
6116                       (not (eobp)))
6117             (beginning-of-line)
6118             (setq from (point))
6119             (unless (search-forward ":" nil t)
6120               (forward-char 1))
6121             (when (and header-face
6122                        (not (memq (point) hpoints)))
6123               (push (point) hpoints)
6124               (gnus-put-text-property from (point) 'face header-face))
6125             (when (and field-face
6126                        (not (memq (setq from (point)) fpoints)))
6127               (push from fpoints)
6128               (if (re-search-forward "^[^ \t]" nil t)
6129                   (forward-char -2)
6130                 (goto-char (point-max)))
6131               (gnus-put-text-property from (point) 'face field-face))))))))
6132
6133 (defun gnus-article-highlight-signature ()
6134   "Highlight the signature in an article.
6135 It does this by highlighting everything after
6136 `gnus-signature-separator' using `gnus-signature-face'."
6137   (interactive)
6138   (when gnus-signature-face
6139     (save-excursion
6140       (set-buffer gnus-article-buffer)
6141       (let ((buffer-read-only nil)
6142             (inhibit-point-motion-hooks t))
6143         (save-restriction
6144           (when (gnus-article-narrow-to-signature)
6145             (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6146                               'face gnus-signature-face)))))))
6147
6148 (defun gnus-article-buttonize-signature ()
6149   "Add button to the signature."
6150   (interactive)
6151   (save-excursion
6152     (set-buffer gnus-article-buffer)
6153     (let ((buffer-read-only nil)
6154           (inhibit-point-motion-hooks t))
6155       (when (gnus-article-search-signature)
6156         (gnus-article-add-button (match-beginning 0) (match-end 0)
6157                                  'gnus-signature-toggle
6158                                  (set-marker (make-marker)
6159                                              (1+ (match-end 0))))))))
6160
6161 (defun gnus-button-in-region-p (b e prop)
6162   "Say whether PROP exists in the region."
6163   (text-property-not-all b e prop nil))
6164
6165 (defun gnus-article-add-buttons (&optional force)
6166   "Find external references in the article and make buttons of them.
6167 \"External references\" are things like Message-IDs and URLs, as
6168 specified by `gnus-button-alist'."
6169   (interactive (list 'force))
6170   (save-excursion
6171     (set-buffer gnus-article-buffer)
6172     (let ((buffer-read-only nil)
6173           (inhibit-point-motion-hooks t)
6174           (case-fold-search t)
6175           (alist gnus-button-alist)
6176           beg entry regexp)
6177       ;; Remove all old markers.
6178       (let (marker entry new-list)
6179         (while (setq marker (pop gnus-button-marker-list))
6180           (if (or (< marker (point-min)) (>= marker (point-max)))
6181               (push marker new-list)
6182             (goto-char marker)
6183             (when (setq entry (gnus-button-entry))
6184               (put-text-property (match-beginning (nth 1 entry))
6185                                  (match-end (nth 1 entry))
6186                                  'gnus-callback nil))
6187             (set-marker marker nil)))
6188         (setq gnus-button-marker-list new-list))
6189       ;; We skip the headers.
6190       (article-goto-body)
6191       (setq beg (point))
6192       (while (setq entry (pop alist))
6193         (setq regexp (eval (car entry)))
6194         (goto-char beg)
6195         (while (re-search-forward regexp nil t)
6196           (let* ((start (and entry (match-beginning (nth 1 entry))))
6197                  (end (and entry (match-end (nth 1 entry))))
6198                  (from (match-beginning 0)))
6199             (when (and (or (eq t (nth 2 entry))
6200                            (eval (nth 2 entry)))
6201                        (not (gnus-button-in-region-p
6202                              start end 'gnus-callback)))
6203               ;; That optional form returned non-nil, so we add the
6204               ;; button.
6205               (gnus-article-add-button
6206                start end 'gnus-button-push
6207                (car (push (set-marker (make-marker) from)
6208                           gnus-button-marker-list))))))))))
6209
6210 ;; Add buttons to the head of an article.
6211 (defun gnus-article-add-buttons-to-head ()
6212   "Add buttons to the head of the article."
6213   (interactive)
6214   (save-excursion
6215     (set-buffer gnus-article-buffer)
6216     (save-restriction
6217       (let ((buffer-read-only nil)
6218             (inhibit-point-motion-hooks t)
6219             (case-fold-search t)
6220             (alist gnus-header-button-alist)
6221             entry beg end)
6222         (article-narrow-to-head)
6223         (while alist
6224           ;; Each alist entry.
6225           (setq entry (car alist)
6226                 alist (cdr alist))
6227           (goto-char (point-min))
6228           (while (re-search-forward (car entry) nil t)
6229             ;; Each header matching the entry.
6230             (setq beg (match-beginning 0))
6231             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6232                                (match-beginning 0))
6233                           (point-max)))
6234             (goto-char beg)
6235             (while (re-search-forward (eval (nth 1 entry)) end t)
6236               ;; Each match within a header.
6237               (let* ((entry (cdr entry))
6238                      (start (match-beginning (nth 1 entry)))
6239                      (end (match-end (nth 1 entry)))
6240                      (form (nth 2 entry)))
6241                 (goto-char (match-end 0))
6242                 (when (eval form)
6243                   (gnus-article-add-button
6244                    start end (nth 3 entry)
6245                    (buffer-substring (match-beginning (nth 4 entry))
6246                                      (match-end (nth 4 entry)))))))
6247             (goto-char end)))))))
6248
6249 ;;; External functions:
6250
6251 (defun gnus-article-add-button (from to fun &optional data)
6252   "Create a button between FROM and TO with callback FUN and data DATA."
6253   (when gnus-article-button-face
6254     (gnus-overlay-put (gnus-make-overlay from to)
6255                       'face gnus-article-button-face))
6256   (gnus-add-text-properties
6257    from to
6258    (nconc (and gnus-article-mouse-face
6259                (list gnus-mouse-face-prop gnus-article-mouse-face))
6260           (list 'gnus-callback fun)
6261           (and data (list 'gnus-data data))))
6262   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6263                          ;; Quote `:button-keymap' for Mule 2.3
6264                          ;; but it won't work.
6265                          ':button-keymap gnus-widget-button-keymap))
6266
6267 ;;; Internal functions:
6268
6269 (defun gnus-article-set-globals ()
6270   (save-excursion
6271     (set-buffer gnus-summary-buffer)
6272     (gnus-set-global-variables)))
6273
6274 (defun gnus-signature-toggle (end)
6275   (save-excursion
6276     (set-buffer gnus-article-buffer)
6277     (let ((buffer-read-only nil)
6278           (inhibit-point-motion-hooks t)
6279           (limit (next-single-property-change end 'mime-view-entity
6280                                               nil (point-max))))
6281       (if (text-property-any end limit 'article-type 'signature)
6282           (progn
6283             (gnus-delete-wash-type 'signature)
6284             (gnus-remove-text-properties-when
6285              'article-type 'signature end limit
6286              (cons 'article-type (cons 'signature
6287                                        gnus-hidden-properties))))
6288         (gnus-add-wash-type 'signature)
6289         (gnus-add-text-properties-when
6290          'article-type nil end limit
6291          (cons 'article-type (cons 'signature
6292                                    gnus-hidden-properties)))))
6293     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6294       (gnus-set-mode-line 'article))))
6295
6296 (defun gnus-button-entry ()
6297   ;; Return the first entry in `gnus-button-alist' matching this place.
6298   (let ((alist gnus-button-alist)
6299         (entry nil))
6300     (while alist
6301       (setq entry (pop alist))
6302       (if (looking-at (eval (car entry)))
6303           (setq alist nil)
6304         (setq entry nil)))
6305     entry))
6306
6307 (defun gnus-button-push (marker)
6308   ;; Push button starting at MARKER.
6309   (save-excursion
6310     (goto-char marker)
6311     (let* ((entry (gnus-button-entry))
6312            (inhibit-point-motion-hooks t)
6313            (fun (nth 3 entry))
6314            (args (mapcar (lambda (group)
6315                            (let ((string (match-string group)))
6316                              (gnus-set-text-properties
6317                               0 (length string) nil string)
6318                              string))
6319                          (nthcdr 4 entry))))
6320       (cond
6321        ((fboundp fun)
6322         (apply fun args))
6323        ((and (boundp fun)
6324              (fboundp (symbol-value fun)))
6325         (apply (symbol-value fun) args))
6326        (t
6327         (gnus-message 1 "You must define `%S' to use this button"
6328                       (cons fun args)))))))
6329
6330 (defun gnus-parse-news-url (url)
6331   (let (scheme server group message-id articles)
6332     (with-temp-buffer
6333       (insert url)
6334       (goto-char (point-min))
6335       (when (looking-at "\\([A-Za-z]+\\):")
6336         (setq scheme (match-string 1))
6337         (goto-char (match-end 0)))
6338       (when (looking-at "//\\([^/]+\\)/")
6339         (setq server (match-string 1))
6340         (goto-char (match-end 0)))
6341
6342       (cond
6343        ((looking-at "\\(.*@.*\\)")
6344         (setq message-id (match-string 1)))
6345        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6346         (setq group (match-string 1)
6347               articles (split-string (match-string 2) "-")))
6348        ((looking-at "\\([^/]+\\)/?")
6349         (setq group (match-string 1)))
6350        (t
6351         (error "Unknown news URL syntax"))))
6352     (list scheme server group message-id articles)))
6353
6354 (defun gnus-button-handle-news (url)
6355   "Fetch a news URL."
6356   (destructuring-bind (scheme server group message-id articles)
6357       (gnus-parse-news-url url)
6358     (cond
6359      (message-id
6360       (save-excursion
6361         (set-buffer gnus-summary-buffer)
6362         (if server
6363             (let ((gnus-refer-article-method (list (list 'nntp server))))
6364               (gnus-summary-refer-article message-id))
6365           (gnus-summary-refer-article message-id))))
6366      (group
6367       (gnus-button-fetch-group url)))))
6368
6369 (defun gnus-button-handle-man (url)
6370   "Fetch a man page."
6371   (funcall gnus-button-man-handler url))
6372
6373 (defun gnus-button-handle-info (url)
6374   "Fetch an info URL."
6375   (if (string-match
6376        "^\\([^:/]+\\)?/\\(.*\\)"
6377        url)
6378       (gnus-info-find-node
6379        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6380                        "Gnus")
6381                ")"
6382                (gnus-url-unhex-string (match-string 2 url))))
6383     (error "Can't parse %s" url)))
6384
6385 (defun gnus-button-message-id (message-id)
6386   "Fetch MESSAGE-ID."
6387   (save-excursion
6388     (set-buffer gnus-summary-buffer)
6389     (gnus-summary-refer-article message-id)))
6390
6391 (defun gnus-button-fetch-group (address)
6392   "Fetch GROUP specified by ADDRESS."
6393   (if (not (string-match "[:/]" address))
6394       ;; This is just a simple group url.
6395       (gnus-group-read-ephemeral-group address gnus-select-method)
6396     (if (not
6397          (string-match
6398           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6399           address))
6400         (error "Can't parse %s" address)
6401       (gnus-group-read-ephemeral-group
6402        (match-string 4 address)
6403        `(nntp ,(match-string 1 address)
6404               (nntp-address ,(match-string 1 address))
6405               (nntp-port-number ,(if (match-end 3)
6406                                      (match-string 3 address)
6407                                    "nntp")))
6408        nil nil nil
6409        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6410
6411 (defun gnus-url-parse-query-string (query &optional downcase)
6412   (let (retval pairs cur key val)
6413     (setq pairs (split-string query "&"))
6414     (while pairs
6415       (setq cur (car pairs)
6416             pairs (cdr pairs))
6417       (if (not (string-match "=" cur))
6418           nil                           ; Grace
6419         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6420               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6421         (if downcase
6422             (setq key (downcase key)))
6423         (setq cur (assoc key retval))
6424         (if cur
6425             (setcdr cur (cons val (cdr cur)))
6426           (setq retval (cons (list key val) retval)))))
6427     retval))
6428
6429 (defun gnus-url-mailto (url)
6430   ;; Send mail to someone
6431   (when (string-match "mailto:/*\\(.*\\)" url)
6432     (setq url (substring url (match-beginning 1) nil)))
6433   (let (to args subject func)
6434     (if (string-match (regexp-quote "?") url)
6435         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6436               args (gnus-url-parse-query-string
6437                     (substring url (match-end 0) nil) t))
6438       (setq to (gnus-url-unhex-string url)))
6439     (setq args (cons (list "to" to) args)
6440           subject (cdr-safe (assoc "subject" args)))
6441     (gnus-msg-mail)
6442     (while args
6443       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6444       (if (fboundp func)
6445           (funcall func)
6446         (message-position-on-field (caar args)))
6447       (insert (mapconcat 'identity (cdar args) ", "))
6448       (setq args (cdr args)))
6449     (if subject
6450         (message-goto-body)
6451       (message-goto-subject))))
6452
6453 (defun gnus-button-embedded-url (address)
6454   "Activate ADDRESS with `browse-url'."
6455   (browse-url (gnus-strip-whitespace address)))
6456
6457 ;;; Next/prev buttons in the article buffer.
6458
6459 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6460 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6461
6462 (defvar gnus-prev-page-map
6463   (let ((map (make-sparse-keymap)))
6464     (unless (>= emacs-major-version 21)
6465       ;; XEmacs doesn't care.
6466       (set-keymap-parent map gnus-article-mode-map))
6467     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6468     (define-key map "\r" 'gnus-button-prev-page)
6469     map))
6470
6471 (defun gnus-insert-prev-page-button ()
6472   (let ((b (point))
6473         (buffer-read-only nil)
6474         (situation (get-text-property (point-min) 'mime-view-situation)))
6475     (gnus-eval-format
6476      gnus-prev-page-line-format nil
6477      `(,@(gnus-local-map-property gnus-prev-page-map)
6478          gnus-prev t
6479          gnus-callback gnus-article-button-prev-page
6480          article-type annotation
6481          mime-view-situation ,situation))
6482     (widget-convert-button
6483      'link b (point)
6484      :action 'gnus-button-prev-page
6485      :button-keymap gnus-prev-page-map)))
6486
6487 (defvar gnus-next-page-map
6488   (let ((map (make-sparse-keymap)))
6489     (unless (>= emacs-major-version 21)
6490       ;; XEmacs doesn't care.
6491       (set-keymap-parent map gnus-article-mode-map))
6492     (define-key map gnus-mouse-2 'gnus-button-next-page)
6493     (define-key map "\r" 'gnus-button-next-page)
6494     map))
6495
6496 (defun gnus-button-next-page (&optional args more-args)
6497   "Go to the next page."
6498   (interactive)
6499   (let ((win (selected-window)))
6500     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6501     (gnus-article-next-page)
6502     (select-window win)))
6503
6504 (defun gnus-button-prev-page (&optional args more-args)
6505   "Go to the prev page."
6506   (interactive)
6507   (let ((win (selected-window)))
6508     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6509     (gnus-article-prev-page)
6510     (select-window win)))
6511
6512 (defun gnus-insert-next-page-button ()
6513   (let ((b (point))
6514         (buffer-read-only nil)
6515         (situation (get-text-property (point-min) 'mime-view-situation)))
6516     (gnus-eval-format gnus-next-page-line-format nil
6517                       `(,@(gnus-local-map-property gnus-next-page-map)
6518                           gnus-next t
6519                           gnus-callback gnus-article-button-next-page
6520                           article-type annotation
6521                           mime-view-situation ,situation))
6522     (widget-convert-button
6523      'link b (point)
6524      :action 'gnus-button-next-page
6525      :button-keymap gnus-next-page-map)))
6526
6527 (defun gnus-article-button-next-page (arg)
6528   "Go to the next page."
6529   (interactive "P")
6530   (let ((win (selected-window)))
6531     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6532     (gnus-article-next-page)
6533     (select-window win)))
6534
6535 (defun gnus-article-button-prev-page (arg)
6536   "Go to the prev page."
6537   (interactive "P")
6538   (let ((win (selected-window)))
6539     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6540     (gnus-article-prev-page)
6541     (select-window win)))
6542
6543 (defvar gnus-decode-header-methods
6544   '(mail-decode-encoded-word-region)
6545   "List of methods used to decode headers.
6546
6547 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6548 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6549 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6550 whose names match REGEXP.
6551
6552 For example:
6553 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6554  mail-decode-encoded-word-region
6555  (\"chinese\" . rfc1843-decode-region))
6556 ")
6557
6558 (defvar gnus-decode-header-methods-cache nil)
6559
6560 (defun gnus-multi-decode-header (start end)
6561   "Apply the functions from `gnus-encoded-word-methods' that match."
6562   (unless (and gnus-decode-header-methods-cache
6563                (eq gnus-newsgroup-name
6564                    (car gnus-decode-header-methods-cache)))
6565     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6566     (mapcar (lambda (x)
6567               (if (symbolp x)
6568                   (nconc gnus-decode-header-methods-cache (list x))
6569                 (if (and gnus-newsgroup-name
6570                          (string-match (car x) gnus-newsgroup-name))
6571                     (nconc gnus-decode-header-methods-cache
6572                            (list (cdr x))))))
6573             gnus-decode-header-methods))
6574   (let ((xlist gnus-decode-header-methods-cache))
6575     (pop xlist)
6576     (save-restriction
6577       (narrow-to-region start end)
6578       (while xlist
6579         (funcall (pop xlist) (point-min) (point-max))))))
6580
6581 ;;;
6582 ;;; Treatment top-level handling.
6583 ;;;
6584
6585 (defun gnus-treat-article (condition &optional part-number total-parts type)
6586   (let ((length (- (point-max) (point-min)))
6587         (alist gnus-treatment-function-alist)
6588         (article-goto-body-goes-to-point-min-p t)
6589         (treated-type
6590          (or (not type)
6591              (catch 'found
6592                (let ((list gnus-article-treat-types))
6593                  (while list
6594                    (when (string-match (pop list) type)
6595                      (throw 'found t)))))))
6596         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6597         (entity (static-unless (featurep 'xemacs)
6598                   (when (eq 'head condition)
6599                     (get-text-property (point-min) 'mime-view-entity))))
6600         val elem buttonized)
6601     (gnus-run-hooks 'gnus-part-display-hook)
6602     (unless gnus-inhibit-treatment
6603       (while (setq elem (pop alist))
6604         (setq val
6605               (save-excursion
6606                 (if (gnus-buffer-live-p gnus-summary-buffer)
6607                     (set-buffer gnus-summary-buffer))
6608                 (symbol-value (car elem))))
6609         (when (and (or (consp val)
6610                        treated-type)
6611                    (gnus-treat-predicate val)
6612                    (or (not (get (car elem) 'highlight))
6613                        highlightp))
6614           (when (and (not buttonized)
6615                      (memq (car elem)
6616                            '(gnus-treat-hide-signature
6617                              gnus-treat-highlight-signature)))
6618             (gnus-article-buttonize-signature)
6619             (setq buttonized t))
6620           (save-restriction
6621             (funcall (cadr elem)))))
6622       ;; FSF Emacsen does not inherit the existing text properties
6623       ;; in the new text, so we should do it for `mime-view-entity'.
6624       (static-unless (featurep 'xemacs)
6625         (when entity
6626           (put-text-property (point-min) (point-max)
6627                              'mime-view-entity entity))))))
6628
6629 ;; Dynamic variables.
6630 (eval-when-compile
6631   (defvar part-number)
6632   (defvar total-parts)
6633   (defvar type)
6634   (defvar condition)
6635   (defvar length))
6636
6637 (defun gnus-treat-predicate (val)
6638   (cond
6639    ((null val)
6640     nil)
6641    ((and (listp val)
6642          (stringp (car val)))
6643     (apply 'gnus-or (mapcar `(lambda (s)
6644                                (string-match s ,(or gnus-newsgroup-name "")))
6645                             val)))
6646    ((listp val)
6647     (let ((pred (pop val)))
6648       (cond
6649        ((eq pred 'or)
6650         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6651        ((eq pred 'and)
6652         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6653        ((eq pred 'not)
6654         (not (gnus-treat-predicate (car val))))
6655        ((eq pred 'typep)
6656         (equal (car val) type))
6657        (t
6658         (error "%S is not a valid predicate" pred)))))
6659    ((eq val 'mime)
6660     gnus-show-mime)
6661    (condition
6662     (eq condition val))
6663    ((eq val t)
6664     t)
6665    ((eq val 'head)
6666     nil)
6667    ((eq val 'last)
6668     (eq part-number total-parts))
6669    ((numberp val)
6670     (< length val))
6671    (t
6672     (error "%S is not a valid value" val))))
6673
6674 (defun gnus-article-encrypt-body (protocol &optional n)
6675   "Encrypt the article body."
6676   (interactive
6677    (list
6678     (or gnus-article-encrypt-protocol
6679         (completing-read "Encrypt protocol: "
6680                          gnus-article-encrypt-protocol-alist
6681                          nil t))
6682     current-prefix-arg))
6683   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6684     (unless func
6685       (error (format "Can't find the encrypt protocol %s" protocol)))
6686     (if (equal gnus-newsgroup-name "nndraft:drafts")
6687         (error "Can't encrypt the article in group nndraft:drafts"))
6688     (if (equal gnus-newsgroup-name "nndraft:queue")
6689         (error "Don't encrypt the article in group nndraft:queue"))
6690     (gnus-summary-iterate n
6691       (save-excursion
6692         (set-buffer gnus-summary-buffer)
6693         (let ((mail-parse-charset gnus-newsgroup-charset)
6694               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6695               (summary-buffer gnus-summary-buffer)
6696               references point)
6697           (gnus-set-global-variables)
6698           (when (gnus-group-read-only-p)
6699             (error "The current newsgroup does not support article encrypt"))
6700           (gnus-summary-show-article t)
6701           (setq references
6702                 (or (mail-header-references gnus-current-headers) ""))
6703           (set-buffer gnus-article-buffer)
6704           (let* ((buffer-read-only nil)
6705                  (headers
6706                   (mapcar (lambda (field)
6707                             (and (save-restriction
6708                                    (message-narrow-to-head)
6709                                    (goto-char (point-min))
6710                                    (search-forward field nil t))
6711                                  (prog2
6712                                      (message-narrow-to-field)
6713                                      (buffer-substring (point-min) (point-max))
6714                                    (delete-region (point-min) (point-max))
6715                                    (widen))))
6716                           '("Content-Type:" "Content-Transfer-Encoding:"
6717                             "Content-Disposition:"))))
6718             (message-narrow-to-head)
6719             (message-remove-header "MIME-Version")
6720             (goto-char (point-max))
6721             (setq point (point))
6722             (insert (apply 'concat headers))
6723             (widen)
6724             (narrow-to-region point (point-max))
6725             (let ((message-options message-options))
6726               (message-options-set 'message-sender user-mail-address)
6727               (message-options-set 'message-recipients user-mail-address)
6728               (message-options-set 'message-sign-encrypt 'not)
6729               (funcall func))
6730             (goto-char (point-min))
6731             (insert "MIME-Version: 1.0\n")
6732             (widen)
6733             (gnus-summary-edit-article-done
6734              references nil summary-buffer t))
6735           (when gnus-keep-backlog
6736             (gnus-backlog-remove-article
6737              (car gnus-article-current) (cdr gnus-article-current)))
6738           (save-excursion
6739             (when (get-buffer gnus-original-article-buffer)
6740               (set-buffer gnus-original-article-buffer)
6741               (setq gnus-original-article nil)))
6742           (when gnus-use-cache
6743             (gnus-cache-update-article
6744              (car gnus-article-current) (cdr gnus-article-current))))))))
6745
6746 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6747   "The following specs can be used:
6748 %t  The security MIME type
6749 %i  Additional info
6750 %d  Details
6751 %D  Details if button is pressed")
6752
6753 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6754   "The following specs can be used:
6755 %t  The security MIME type
6756 %i  Additional info
6757 %d  Details
6758 %D  Details if button is pressed")
6759
6760 (defvar gnus-mime-security-button-line-format-alist
6761   '((?t gnus-tmp-type ?s)
6762     (?i gnus-tmp-info ?s)
6763     (?d gnus-tmp-details ?s)
6764     (?D gnus-tmp-pressed-details ?s)))
6765
6766 (defvar gnus-mime-security-button-map
6767   (let ((map (make-sparse-keymap)))
6768     (unless (>= (string-to-number emacs-version) 21)
6769       (set-keymap-parent map gnus-article-mode-map))
6770     (define-key map gnus-mouse-2 'gnus-article-push-button)
6771     (define-key map "\r" 'gnus-article-press-button)
6772     map))
6773
6774 (defvar gnus-mime-security-details-buffer nil)
6775
6776 (defvar gnus-mime-security-button-pressed nil)
6777
6778 (defvar gnus-mime-security-show-details-inline t
6779   "If non-nil, show details in the article buffer.")
6780
6781 (defun gnus-mime-security-verify-or-decrypt (handle)
6782   (mm-remove-parts (cdr handle))
6783   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6784         point buffer-read-only)
6785     (if region
6786         (goto-char (car region)))
6787     (save-restriction
6788       (narrow-to-region (point) (point))
6789       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6790         (let* ((mm-verify-option 'known)
6791                (mm-decrypt-option 'known)
6792                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6793           (unless (eq nparts (cdr handle))
6794             (mm-destroy-parts (cdr handle))
6795             (setcdr handle nparts))))
6796       (setq point (point))
6797       (gnus-mime-display-security handle)
6798       (goto-char (point-max)))
6799     (when region
6800       (delete-region (point) (cdr region))
6801       (set-marker (car region) nil)
6802       (set-marker (cdr region) nil))
6803     (goto-char point)))
6804
6805 (defun gnus-mime-security-show-details (handle)
6806   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6807     (if details
6808         (if gnus-mime-security-show-details-inline
6809             (let ((gnus-mime-security-button-pressed t)
6810                   (gnus-mime-security-button-line-format
6811                    (get-text-property (point) 'gnus-line-format))
6812                   buffer-read-only)
6813               (forward-char -1)
6814               (while (eq (get-text-property (point) 'gnus-line-format)
6815                          gnus-mime-security-button-line-format)
6816                 (forward-char -1))
6817               (forward-char)
6818               (save-restriction
6819                 (narrow-to-region (point) (point))
6820                 (gnus-insert-mime-security-button handle))
6821               (delete-region (point)
6822                              (or (text-property-not-all
6823                                   (point) (point-max)
6824                                   'gnus-line-format
6825                                   gnus-mime-security-button-line-format)
6826                                  (point-max))))
6827           (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6828               (with-current-buffer gnus-mime-security-details-buffer
6829                 (erase-buffer)
6830                 t)
6831             (setq gnus-mime-security-details-buffer
6832                   (gnus-get-buffer-create "*MIME Security Details*")))
6833           (with-current-buffer gnus-mime-security-details-buffer
6834             (insert details)
6835             (goto-char (point-min)))
6836           (pop-to-buffer gnus-mime-security-details-buffer))
6837       (gnus-message 5 "No details."))))
6838
6839 (defun gnus-mime-security-press-button (handle)
6840   (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6841       (gnus-mime-security-show-details handle)
6842     (gnus-mime-security-verify-or-decrypt handle)))
6843
6844 (defun gnus-insert-mime-security-button (handle &optional displayed)
6845   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6846          (gnus-tmp-type
6847           (concat
6848            (or (nth 2 (assoc protocol mm-verify-function-alist))
6849                (nth 2 (assoc protocol mm-decrypt-function-alist))
6850                "Unknown")
6851            (if (equal (car handle) "multipart/signed")
6852                " Signed" " Encrypted")
6853            " Part"))
6854          (gnus-tmp-info
6855           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6856               "Undecided"))
6857          (gnus-tmp-details
6858           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6859          gnus-tmp-pressed-details
6860          b e)
6861     (setq gnus-tmp-details
6862           (if gnus-tmp-details
6863               (concat "\n" gnus-tmp-details) ""))
6864     (setq gnus-tmp-pressed-details
6865           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6866     (unless (bolp)
6867       (insert "\n"))
6868     (setq b (point))
6869     (gnus-eval-format
6870      gnus-mime-security-button-line-format
6871      gnus-mime-security-button-line-format-alist
6872      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6873          gnus-callback gnus-mime-security-press-button
6874          gnus-line-format ,gnus-mime-security-button-line-format
6875          article-type annotation
6876          gnus-data ,handle))
6877     (setq e (point))
6878     (widget-convert-button
6879      'link b e
6880      :mime-handle handle
6881      :action 'gnus-widget-press-button
6882      :button-keymap gnus-mime-security-button-map
6883      :help-echo
6884      (lambda (widget/window &optional overlay pos)
6885        ;; Needed to properly clear the message due to a bug in
6886        ;; wid-edit (XEmacs only).
6887        (if (boundp 'help-echo-owns-message)
6888            (setq help-echo-owns-message t))
6889        (format
6890         "%S: show detail"
6891         (aref gnus-mouse-2 0))))))
6892
6893 (defun gnus-mime-display-security (handle)
6894   (save-restriction
6895     (narrow-to-region (point) (point))
6896     (unless (gnus-unbuttonized-mime-type-p (car handle))
6897       (gnus-insert-mime-security-button handle))
6898     (gnus-mime-display-mixed (cdr handle))
6899     (unless (bolp)
6900       (insert "\n"))
6901     (unless (gnus-unbuttonized-mime-type-p (car handle))
6902       (let ((gnus-mime-security-button-line-format
6903              gnus-mime-security-button-end-line-format))
6904         (gnus-insert-mime-security-button handle)))
6905     (mm-set-handle-multipart-parameter
6906      handle 'gnus-region
6907      (cons (set-marker (make-marker) (point-min))
6908            (set-marker (make-marker) (point-max))))))
6909
6910
6911 ;;; @ for mime-view
6912 ;;;
6913
6914 (defun gnus-article-header-presentation-method (entity situation)
6915   (mime-insert-header entity)
6916   (article-decode-group-name))
6917
6918 (set-alist 'mime-header-presentation-method-alist
6919            'gnus-original-article-mode
6920            #'gnus-article-header-presentation-method)
6921
6922 (defun gnus-mime-preview-quitting-method ()
6923   (mime-preview-kill-buffer)
6924   (delete-other-windows)
6925   (gnus-article-show-summary)
6926   (gnus-summary-select-article gnus-show-all-headers t))
6927
6928 (set-alist 'mime-preview-quitting-method-alist
6929            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6930
6931 (set-alist 'mime-preview-following-method-alist
6932            'gnus-original-article-mode #'gnus-following-method)
6933
6934 (set-alist 'mime-preview-over-to-previous-method-alist
6935            'gnus-original-article-mode
6936            (lambda ()
6937              (if (> (point-min) 1)
6938                  (gnus-article-prev-page)
6939                (gnus-article-read-summary-keys
6940                 nil (gnus-character-to-event ?P)))))
6941
6942 (set-alist 'mime-preview-over-to-next-method-alist
6943            'gnus-original-article-mode'
6944            (lambda ()
6945              (if (< (point-max) (buffer-size))
6946                  (gnus-article-next-page)
6947                (gnus-article-read-summary-keys
6948                 nil (gnus-character-to-event ?N)))))
6949
6950
6951 ;;; @ end
6952 ;;;
6953
6954 (gnus-ems-redefine)
6955
6956 (provide 'gnus-art)
6957
6958 (run-hooks 'gnus-art-load-hook)
6959
6960 ;;; gnus-art.el ends here