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