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