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