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