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