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