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