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