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