* gnus-art.el (gnus-request-article-this-buffer): Conditional
[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 "[ \t]\\|^" (gnus-point-at-bol) t)
4822     (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
4823     (if (re-search-forward "[^@ ]+@[^ \t>]+" (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       (error "No references around point"))))
4828
4829 (defun gnus-article-show-summary ()
4830   "Reconfigure windows to show summary buffer."
4831   (interactive)
4832   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4833       (error "There is no summary buffer for this article buffer")
4834     (gnus-article-set-globals)
4835     (gnus-configure-windows 'article)
4836     (gnus-summary-goto-subject gnus-current-article)
4837     (gnus-summary-position-point)))
4838
4839 (defun gnus-article-describe-briefly ()
4840   "Describe article mode commands briefly."
4841   (interactive)
4842   (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")))
4843
4844 (defun gnus-article-summary-command ()
4845   "Execute the last keystroke in the summary buffer."
4846   (interactive)
4847   (let ((obuf (current-buffer))
4848         (owin (current-window-configuration))
4849         func)
4850     (switch-to-buffer gnus-article-current-summary 'norecord)
4851     (setq func (lookup-key (current-local-map) (this-command-keys)))
4852     (call-interactively func)
4853     (set-buffer obuf)
4854     (set-window-configuration owin)
4855     (set-window-point (get-buffer-window (current-buffer)) (point))))
4856
4857 (defun gnus-article-summary-command-nosave ()
4858   "Execute the last keystroke in the summary buffer."
4859   (interactive)
4860   (let (func)
4861     (pop-to-buffer gnus-article-current-summary 'norecord)
4862     (setq func (lookup-key (current-local-map) (this-command-keys)))
4863     (call-interactively func)))
4864
4865 (defun gnus-article-check-buffer ()
4866   "Beep if not in an article buffer."
4867   (unless (equal major-mode 'gnus-article-mode)
4868     (error "Command invoked outside of a Gnus article buffer")))
4869
4870 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4871   "Read a summary buffer key sequence and execute it from the article buffer."
4872   (interactive "P")
4873   (gnus-article-check-buffer)
4874   (let ((nosaves
4875          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
4876            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4877            "=" "^" "\M-^" "|"))
4878         (nosave-but-article
4879          '("A\r"))
4880         (nosave-in-article
4881          '("\C-d"))
4882         (up-to-top
4883          '("n" "Gn" "p" "Gp"))
4884         keys new-sum-point)
4885     (save-excursion
4886       (set-buffer gnus-article-current-summary)
4887       (let (gnus-pick-mode)
4888         (push (or key last-command-event) unread-command-events)
4889         (setq keys (if (featurep 'xemacs)
4890                        (events-to-keys (read-key-sequence nil))
4891                      (read-key-sequence nil)))))
4892
4893     (message "")
4894
4895     (if (or (member keys nosaves)
4896             (member keys nosave-but-article)
4897             (member keys nosave-in-article))
4898         (let (func)
4899           (save-window-excursion
4900             (pop-to-buffer gnus-article-current-summary 'norecord)
4901             ;; We disable the pick minor mode commands.
4902             (let (gnus-pick-mode)
4903               (setq func (lookup-key (current-local-map) keys))))
4904           (if (or (not func)
4905                   (numberp func))
4906               (ding)
4907             (unless (member keys nosave-in-article)
4908               (set-buffer gnus-article-current-summary))
4909             (call-interactively func)
4910             (setq new-sum-point (point)))
4911           (when (member keys nosave-but-article)
4912             (pop-to-buffer gnus-article-buffer 'norecord)))
4913       ;; These commands should restore window configuration.
4914       (let ((obuf (current-buffer))
4915             (owin (current-window-configuration))
4916             (opoint (point))
4917             (summary gnus-article-current-summary)
4918             func in-buffer selected)
4919         (if not-restore-window
4920             (pop-to-buffer summary 'norecord)
4921           (switch-to-buffer summary 'norecord))
4922         (setq in-buffer (current-buffer))
4923         ;; We disable the pick minor mode commands.
4924         (if (and (setq func (let (gnus-pick-mode)
4925                               (lookup-key (current-local-map) keys)))
4926                  (functionp func))
4927             (progn
4928               (call-interactively func)
4929               (setq new-sum-point (point))
4930               (when (eq in-buffer (current-buffer))
4931                 (setq selected (gnus-summary-select-article))
4932                 (set-buffer obuf)
4933                 (unless not-restore-window
4934                   (set-window-configuration owin))
4935                 (when (eq selected 'old)
4936                   (article-goto-body)
4937                   (set-window-start (get-buffer-window (current-buffer))
4938                                     1)
4939                   (set-window-point (get-buffer-window (current-buffer))
4940                                     (point)))
4941                 (let ((win (get-buffer-window gnus-article-current-summary)))
4942                   (when win
4943                     (set-window-point win new-sum-point))))    )
4944           (switch-to-buffer gnus-article-buffer)
4945           (ding))))))
4946
4947 (defun gnus-article-describe-key (key)
4948   "Display documentation of the function invoked by KEY.  KEY is a string."
4949   (interactive "kDescribe key: ")
4950   (gnus-article-check-buffer)
4951   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4952       (save-excursion
4953         (set-buffer gnus-article-current-summary)
4954         (let (gnus-pick-mode)
4955           (if (featurep 'xemacs)
4956               (progn
4957                 (push (elt key 0) unread-command-events)
4958                 (setq key (events-to-keys
4959                            (read-key-sequence "Describe key: "))))
4960             (setq unread-command-events
4961                   (mapcar
4962                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4963                    (string-to-list key)))
4964             (setq key (read-key-sequence "Describe key: "))))
4965         (describe-key key))
4966     (describe-key key)))
4967
4968 (defun gnus-article-describe-key-briefly (key &optional insert)
4969   "Display documentation of the function invoked by KEY.  KEY is a string."
4970   (interactive "kDescribe key: \nP")
4971   (gnus-article-check-buffer)
4972   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4973       (save-excursion
4974         (set-buffer gnus-article-current-summary)
4975         (let (gnus-pick-mode)
4976           (if (featurep 'xemacs)
4977               (progn
4978                 (push (elt key 0) unread-command-events)
4979                 (setq key (events-to-keys
4980                            (read-key-sequence "Describe key: "))))
4981             (setq unread-command-events
4982                   (mapcar
4983                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4984                    (string-to-list key)))
4985             (setq key (read-key-sequence "Describe key: "))))
4986         (describe-key-briefly key insert))
4987     (describe-key-briefly key insert)))
4988
4989 (defun gnus-article-reply-with-original (&optional wide)
4990   "Start composing a reply mail to the current message.
4991 The text in the region will be yanked.  If the region isn't active,
4992 the entire article will be yanked."
4993   (interactive "P")
4994   (let ((article (cdr gnus-article-current))
4995         contents)
4996     (if (not (gnus-mark-active-p))
4997         (with-current-buffer gnus-summary-buffer
4998           (gnus-summary-reply (list (list article)) wide))
4999       (setq contents (buffer-substring (point) (mark t)))
5000       ;; Deactivate active regions.
5001       (when (and (boundp 'transient-mark-mode)
5002                  transient-mark-mode)
5003         (setq mark-active nil))
5004       (with-current-buffer gnus-summary-buffer
5005         (gnus-summary-reply
5006          (list (list article contents)) wide)))))
5007
5008 (defun gnus-article-followup-with-original ()
5009   "Compose a followup to the current article.
5010 The text in the region will be yanked.  If the region isn't active,
5011 the entire article will be yanked."
5012   (interactive)
5013   (let ((article (cdr gnus-article-current))
5014         contents)
5015       (if (not (gnus-mark-active-p))
5016           (with-current-buffer gnus-summary-buffer
5017             (gnus-summary-followup (list (list article))))
5018         (setq contents (buffer-substring (point) (mark t)))
5019         ;; Deactivate active regions.
5020         (when (and (boundp 'transient-mark-mode)
5021                    transient-mark-mode)
5022           (setq mark-active nil))
5023         (with-current-buffer gnus-summary-buffer
5024           (gnus-summary-followup
5025            (list (list article contents)))))))
5026
5027 (defun gnus-article-hide (&optional arg force)
5028   "Hide all the gruft in the current article.
5029 This means that signatures, cited text and (some) headers will be
5030 hidden.
5031 If given a prefix, show the hidden text instead."
5032   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5033   (gnus-article-hide-headers arg)
5034   (gnus-article-hide-list-identifiers arg)
5035   (gnus-article-hide-citation-maybe arg force)
5036   (gnus-article-hide-signature arg))
5037
5038 (defun gnus-article-maybe-highlight ()
5039   "Do some article highlighting if article highlighting is requested."
5040   (when (gnus-visual-p 'article-highlight 'highlight)
5041     (gnus-article-highlight-some)))
5042
5043 (defun gnus-check-group-server ()
5044   ;; Make sure the connection to the server is alive.
5045   (unless (gnus-server-opened
5046            (gnus-find-method-for-group gnus-newsgroup-name))
5047     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5048     (gnus-request-group gnus-newsgroup-name t)))
5049
5050 (eval-when-compile
5051   (autoload 'nneething-get-file-name "nneething"))
5052
5053 (defun gnus-request-article-this-buffer (article group)
5054   "Get an article and insert it into this buffer."
5055   (let (do-update-line sparse-header)
5056     (prog1
5057         (save-excursion
5058           (erase-buffer)
5059           (gnus-kill-all-overlays)
5060           (setq group (or group gnus-newsgroup-name))
5061
5062           ;; Using `gnus-request-article' directly will insert the article into
5063           ;; `nntp-server-buffer' - so we'll save some time by not having to
5064           ;; copy it from the server buffer into the article buffer.
5065
5066           ;; We only request an article by message-id when we do not have the
5067           ;; headers for it, so we'll have to get those.
5068           (when (stringp article)
5069             (gnus-read-header article))
5070
5071           ;; If the article number is negative, that means that this article
5072           ;; doesn't belong in this newsgroup (possibly), so we find its
5073           ;; message-id and request it by id instead of number.
5074           (when (and (numberp article)
5075                      gnus-summary-buffer
5076                      (get-buffer gnus-summary-buffer)
5077                      (gnus-buffer-exists-p gnus-summary-buffer))
5078             (save-excursion
5079               (set-buffer gnus-summary-buffer)
5080               (let ((header (gnus-summary-article-header article)))
5081                 (when (< article 0)
5082                   (cond
5083                    ((memq article gnus-newsgroup-sparse)
5084                     ;; This is a sparse gap article.
5085                     (setq do-update-line article)
5086                     (setq article (mail-header-id header))
5087                     (setq sparse-header (gnus-read-header article))
5088                     (setq gnus-newsgroup-sparse
5089                           (delq article gnus-newsgroup-sparse)))
5090                    ((vectorp header)
5091                     ;; It's a real article.
5092                     (setq article (mail-header-id header)))
5093                    (t
5094                     ;; It is an extracted pseudo-article.
5095                     (setq article 'pseudo)
5096                     (gnus-request-pseudo-article header))))
5097
5098                 (let ((method (gnus-find-method-for-group
5099                                gnus-newsgroup-name)))
5100                   (when (and (eq (car method) 'nneething)
5101                              (vectorp header))
5102                     (let ((dir (nneething-get-file-name
5103                                 (mail-header-id header))))
5104                       (when (and (stringp dir)
5105                                  (file-directory-p dir))
5106                         (setq article 'nneething)
5107                         (gnus-group-enter-directory dir))))))))
5108
5109           (cond
5110            ;; Refuse to select canceled articles.
5111            ((and (numberp article)
5112                  gnus-summary-buffer
5113                  (get-buffer gnus-summary-buffer)
5114                  (gnus-buffer-exists-p gnus-summary-buffer)
5115                  (eq (cdr (save-excursion
5116                             (set-buffer gnus-summary-buffer)
5117                             (assq article gnus-newsgroup-reads)))
5118                      gnus-canceled-mark))
5119             nil)
5120            ;; We first check `gnus-original-article-buffer'.
5121            ((and (get-buffer gnus-original-article-buffer)
5122                  (numberp article)
5123                  (save-excursion
5124                    (set-buffer gnus-original-article-buffer)
5125                    (and (equal (car gnus-original-article) group)
5126                         (eq (cdr gnus-original-article) article))))
5127             (insert-buffer-substring gnus-original-article-buffer)
5128             'article)
5129            ;; Check the backlog.
5130            ((and gnus-keep-backlog
5131                  (gnus-backlog-request-article group article (current-buffer)))
5132             'article)
5133            ;; Check asynchronous pre-fetch.
5134            ((gnus-async-request-fetched-article group article (current-buffer))
5135             (gnus-async-prefetch-next group article gnus-summary-buffer)
5136             (when (and (numberp article) gnus-keep-backlog)
5137               (gnus-backlog-enter-article group article (current-buffer)))
5138             'article)
5139            ;; Check the cache.
5140            ((and gnus-use-cache
5141                  (numberp article)
5142                  (gnus-cache-request-article article group))
5143             'article)
5144            ;; Check the agent cache.
5145            ((gnus-agent-request-article article group)
5146             'article)
5147            ;; Get the article and put into the article buffer.
5148            ((or (stringp article)
5149                 (numberp article))
5150             (let ((gnus-override-method gnus-override-method)
5151                   (methods (and (stringp article)
5152                                 gnus-refer-article-method))
5153                   (backend (car (gnus-find-method-for-group
5154                                  gnus-newsgroup-name)))
5155                   result
5156                   (buffer-read-only nil))
5157               (if (or (not (listp methods))
5158                       (and (symbolp (car methods))
5159                            (assq (car methods) nnoo-definition-alist)))
5160                   (setq methods (list methods)))
5161               (when (and (null gnus-override-method)
5162                          methods)
5163                 (setq gnus-override-method (pop methods)))
5164               (while (not result)
5165                 (when (eq gnus-override-method 'current)
5166                   (setq gnus-override-method
5167                         (with-current-buffer gnus-summary-buffer
5168                           gnus-current-select-method)))
5169                 (erase-buffer)
5170                 (gnus-kill-all-overlays)
5171                 (let ((gnus-newsgroup-name group))
5172                   (gnus-check-group-server))
5173                 (cond
5174                  ((gnus-request-article article group (current-buffer))
5175                   (when (numberp article)
5176                     (gnus-async-prefetch-next group article
5177                                               gnus-summary-buffer)
5178                     (when gnus-keep-backlog
5179                       (gnus-backlog-enter-article
5180                        group article (current-buffer))))
5181                   (setq result 'article))
5182                  (methods
5183                   (setq gnus-override-method (pop methods)))
5184                  ((not (string-match "^400 "
5185                                      (nnheader-get-report backend)))
5186                   ;; If we get 400 server disconnect, reconnect and
5187                   ;; retry; otherwise, assume the article has expired.
5188                   (setq result 'done))))
5189               (and (eq result 'article) 'article)))
5190            ;; It was a pseudo.
5191            (t article)))
5192
5193       ;; Associate this article with the current summary buffer.
5194       (setq gnus-article-current-summary gnus-summary-buffer)
5195
5196       ;; Take the article from the original article buffer
5197       ;; and place it in the buffer it's supposed to be in.
5198       (when (and (get-buffer gnus-article-buffer)
5199                  (equal (buffer-name (current-buffer))
5200                         (buffer-name (get-buffer gnus-article-buffer))))
5201         (save-excursion
5202           (if (get-buffer gnus-original-article-buffer)
5203               (set-buffer gnus-original-article-buffer)
5204             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5205             (buffer-disable-undo)
5206             (setq major-mode 'gnus-original-article-mode)
5207             (setq buffer-read-only t))
5208           (let (buffer-read-only)
5209             (erase-buffer)
5210             (insert-buffer-substring gnus-article-buffer))
5211           (setq gnus-original-article (cons group article)))
5212
5213         ;; Decode charsets.
5214         (run-hooks 'gnus-article-decode-hook)
5215         ;; Mark article as decoded or not.
5216         (setq gnus-article-decoded-p gnus-article-decode-hook))
5217
5218       ;; Update sparse articles.
5219       (when (and do-update-line
5220                  (or (numberp article)
5221                      (stringp article)))
5222         (let ((buf (current-buffer)))
5223           (set-buffer gnus-summary-buffer)
5224           (gnus-summary-update-article do-update-line sparse-header)
5225           (gnus-summary-goto-subject do-update-line nil t)
5226           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5227                             (point))
5228           (set-buffer buf))))))
5229
5230 ;;;
5231 ;;; Article editing
5232 ;;;
5233
5234 (defcustom gnus-article-edit-mode-hook nil
5235   "Hook run in article edit mode buffers."
5236   :group 'gnus-article-various
5237   :type 'hook)
5238
5239 (defvar gnus-article-edit-done-function nil)
5240
5241 (defvar gnus-article-edit-mode-map nil)
5242 (defvar gnus-article-edit-mode nil)
5243
5244 ;; Should we be using derived.el for this?
5245 (unless gnus-article-edit-mode-map
5246   (setq gnus-article-edit-mode-map (make-keymap))
5247   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5248
5249   (gnus-define-keys gnus-article-edit-mode-map
5250     "\C-c?"    describe-mode
5251     "\C-c\C-c" gnus-article-edit-done
5252     "\C-c\C-k" gnus-article-edit-exit
5253     "\C-c\C-f\C-t" message-goto-to
5254     "\C-c\C-f\C-o" message-goto-from
5255     "\C-c\C-f\C-b" message-goto-bcc
5256     ;;"\C-c\C-f\C-w" message-goto-fcc
5257     "\C-c\C-f\C-c" message-goto-cc
5258     "\C-c\C-f\C-s" message-goto-subject
5259     "\C-c\C-f\C-r" message-goto-reply-to
5260     "\C-c\C-f\C-n" message-goto-newsgroups
5261     "\C-c\C-f\C-d" message-goto-distribution
5262     "\C-c\C-f\C-f" message-goto-followup-to
5263     "\C-c\C-f\C-m" message-goto-mail-followup-to
5264     "\C-c\C-f\C-k" message-goto-keywords
5265     "\C-c\C-f\C-u" message-goto-summary
5266     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5267     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5268     "\C-c\C-b" message-goto-body
5269     "\C-c\C-i" message-goto-signature
5270
5271     "\C-c\C-t" message-insert-to
5272     "\C-c\C-n" message-insert-newsgroups
5273     "\C-c\C-o" message-sort-headers
5274     "\C-c\C-e" message-elide-region
5275     "\C-c\C-v" message-delete-not-region
5276     "\C-c\C-z" message-kill-to-signature
5277     "\M-\r" message-newline-and-reformat
5278     "\C-c\C-a" mml-attach-file
5279     "\C-a" message-beginning-of-line
5280     "\t" message-tab
5281     "\M-;" comment-region)
5282
5283   (gnus-define-keys (gnus-article-edit-wash-map
5284                      "\C-c\C-w" gnus-article-edit-mode-map)
5285     "f" gnus-article-edit-full-stops))
5286
5287 (easy-menu-define
5288   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5289   '("Field"
5290     ["Fetch To" message-insert-to t]
5291     ["Fetch Newsgroups" message-insert-newsgroups t]
5292     "----"
5293     ["To" message-goto-to t]
5294     ["From" message-goto-from t]
5295     ["Subject" message-goto-subject t]
5296     ["Cc" message-goto-cc t]
5297     ["Reply-To" message-goto-reply-to t]
5298     ["Summary" message-goto-summary t]
5299     ["Keywords" message-goto-keywords t]
5300     ["Newsgroups" message-goto-newsgroups t]
5301     ["Followup-To" message-goto-followup-to t]
5302     ["Mail-Followup-To" message-goto-mail-followup-to t]
5303     ["Distribution" message-goto-distribution t]
5304     ["Body" message-goto-body t]
5305     ["Signature" message-goto-signature t]))
5306
5307 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5308   "Major mode for editing articles.
5309 This is an extended text-mode.
5310
5311 \\{gnus-article-edit-mode-map}"
5312   (make-local-variable 'gnus-article-edit-done-function)
5313   (make-local-variable 'gnus-prev-winconf)
5314   (set (make-local-variable 'font-lock-defaults)
5315        '(message-font-lock-keywords t))
5316   (set (make-local-variable 'mail-header-separator) "")
5317   (set (make-local-variable 'gnus-article-edit-mode) t)
5318   (easy-menu-add message-mode-field-menu message-mode-map)
5319   (mml-mode)
5320   (setq buffer-read-only nil)
5321   (buffer-enable-undo)
5322   (widen))
5323
5324 (defun gnus-article-edit (&optional force)
5325   "Edit the current article.
5326 This will have permanent effect only in mail groups.
5327 If FORCE is non-nil, allow editing of articles even in read-only
5328 groups."
5329   (interactive "P")
5330   (when (and (not force)
5331              (gnus-group-read-only-p))
5332     (error "The current newsgroup does not support article editing"))
5333   (gnus-article-date-original)
5334   (gnus-article-edit-article
5335    'ignore
5336    `(lambda (no-highlight)
5337       'ignore
5338       (gnus-summary-edit-article-done
5339        ,(or (mail-header-references gnus-current-headers) "")
5340        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5341
5342 (defun gnus-article-edit-article (start-func exit-func)
5343   "Start editing the contents of the current article buffer."
5344   (let ((winconf (current-window-configuration)))
5345     (set-buffer gnus-article-buffer)
5346     (gnus-article-edit-mode)
5347     (funcall start-func)
5348     (set-buffer-modified-p nil)
5349     (gnus-configure-windows 'edit-article)
5350     (setq gnus-article-edit-done-function exit-func)
5351     (setq gnus-prev-winconf winconf)
5352     (gnus-message 6 "C-c C-c to end edits")))
5353
5354 (defun gnus-article-edit-done (&optional arg)
5355   "Update the article edits and exit."
5356   (interactive "P")
5357   (let ((func gnus-article-edit-done-function)
5358         (buf (current-buffer))
5359         (start (window-start))
5360         (p (point))
5361         (winconf gnus-prev-winconf))
5362     (widen) ;; Widen it in case that users narrowed the buffer.
5363     (funcall func arg)
5364     (set-buffer buf)
5365     ;; The cache and backlog have to be flushed somewhat.
5366     (when gnus-keep-backlog
5367       (gnus-backlog-remove-article
5368        (car gnus-article-current) (cdr gnus-article-current)))
5369     ;; Flush original article as well.
5370     (save-excursion
5371       (when (get-buffer gnus-original-article-buffer)
5372         (set-buffer gnus-original-article-buffer)
5373         (setq gnus-original-article nil)))
5374     (when gnus-use-cache
5375       (gnus-cache-update-article
5376        (car gnus-article-current) (cdr gnus-article-current)))
5377     ;; We remove all text props from the article buffer.
5378     (kill-all-local-variables)
5379     (gnus-set-text-properties (point-min) (point-max) nil)
5380     (gnus-article-mode)
5381     (set-window-configuration winconf)
5382     (set-buffer buf)
5383     (set-window-start (get-buffer-window buf) start)
5384     (set-window-point (get-buffer-window buf) (point))))
5385
5386 (defun gnus-article-edit-exit ()
5387   "Exit the article editing without updating."
5388   (interactive)
5389   (when (or (not (buffer-modified-p))
5390             (yes-or-no-p "Article modified; kill anyway? "))
5391     (let ((curbuf (current-buffer))
5392           (p (point))
5393           (window-start (window-start)))
5394       (erase-buffer)
5395       (if (gnus-buffer-live-p gnus-original-article-buffer)
5396           (insert-buffer gnus-original-article-buffer))
5397       (let ((winconf gnus-prev-winconf))
5398         (kill-all-local-variables)
5399         (gnus-article-mode)
5400         (set-window-configuration winconf)
5401         ;; Tippy-toe some to make sure that point remains where it was.
5402         (save-current-buffer
5403           (set-buffer curbuf)
5404           (set-window-start (get-buffer-window (current-buffer)) window-start)
5405           (goto-char p))))))
5406
5407 (defun gnus-article-edit-full-stops ()
5408   "Interactively repair spacing at end of sentences."
5409   (interactive)
5410   (save-excursion
5411     (goto-char (point-min))
5412     (search-forward-regexp "^$" nil t)
5413     (let ((case-fold-search nil))
5414       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5415
5416 ;;;
5417 ;;; Article highlights
5418 ;;;
5419
5420 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5421
5422 ;;; Internal Variables:
5423
5424 (defcustom gnus-button-url-regexp
5425   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5426       "\\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:]]\\)"
5427     "\\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\\)\\)")
5428   "Regular expression that matches URLs."
5429   :group 'gnus-article-buttons
5430   :type 'regexp)
5431
5432 (defcustom gnus-button-valid-fqdn-regexp
5433   (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
5434           ;; valid TLDs:
5435           "\\([a-z][a-z]" ;; two letter country TDLs
5436           "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
5437           "\\|aero\\|coop\\|info\\|name\\|museum"
5438           "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
5439           "\\)")
5440   "Regular expression that matches a valid FQDN."
5441   :group 'gnus-article-buttons
5442   :type 'regexp)
5443
5444 (defcustom gnus-button-man-handler 'manual-entry
5445   "Function to use for displaying man pages.
5446 The function must take at least one argument with a string naming the
5447 man page."
5448   :type '(choice (function-item :tag "Man" manual-entry)
5449                  (function-item :tag "Woman" woman)
5450                  (function :tag "Other"))
5451   :group 'gnus-article-buttons)
5452
5453 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5454   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5455 If the default site is too slow, try to find a CTAN mirror, see
5456 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
5457 the variable `gnus-button-handle-ctan'."
5458   :group 'gnus-article-buttons
5459   :link '(custom-manual "(gnus)Group Parameters")
5460   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5461                  (const "http://tug.ctan.org/tex-archive/")
5462                  (const "http://www.dante.de/CTAN/")
5463                  (string :tag "Other")))
5464
5465 (defcustom gnus-button-ctan-handler 'browse-url
5466   "Function to use for displaying CTAN links.
5467 The function must take one argument, the string naming the URL."
5468   :type '(choice (function-item :tag "Browse Url" browse-url)
5469                  (function :tag "Other"))
5470   :group 'gnus-article-buttons)
5471
5472 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5473   "Bogus strings removed from CTAN URLs."
5474   :group 'gnus-article-buttons
5475   :type '(choice (const "^/?tex-archive/\\|/")
5476                  (regexp :tag "Other")))
5477
5478 (defcustom gnus-button-mid-or-mail-regexp
5479   (concat "\\b\\(<?[a-z0-9][^<>\")!;:,{}\n\t ]*@"
5480           gnus-button-valid-fqdn-regexp
5481           ">?\\)\\b")
5482   "Regular expression that matches a message ID or a mail address."
5483   :group 'gnus-article-buttons
5484   :type 'regexp)
5485
5486 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5487   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5488 Strings like this can be either a message ID or a mail address.  If it is one
5489 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5490 message ID or a mail address, respectivly.  If this variable is set to the
5491 symbol `ask', always query the user what do do.  If it is a function, this
5492 function will be called with the string as it's only argument.  The function
5493 must return `mid', `mail', `invalid' or `ask'."
5494   :group 'gnus-article-buttons
5495   :type '(choice (function-item :tag "Heuristic function"
5496                                 gnus-button-mid-or-mail-heuristic)
5497                  (const ask)
5498                  (const mid)
5499                  (const mail)))
5500
5501 (defcustom gnus-button-mid-or-mail-heuristic-alist
5502   '((-10.0 . ".+\\$.+@")
5503     (-10.0 . "#")
5504     (-10.0 . "\\*")
5505     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
5506     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5507     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5508     (-1.0  . "^[^a-z]+@")
5509    
5510     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5511     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5512     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
5513     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5514    
5515     (-2.0  . "^[0-9]")
5516     (-1.0  . "^[0-9][0-9]")
5517     ;;
5518     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5519     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5520     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5521     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5522     ;;
5523     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5524     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5525     ;;       "[0-9]{8,}.*\@"
5526     (-3.0
5527      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5528     ;; "[0-9]{12,}.*\@"
5529     ;; compensation for TDMA dated mail addresses:
5530     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5531     ;;
5532     (-20.0 . "\\.fsf@") ;; Gnus
5533     (-20.0 . "^slrn")
5534     (-20.0 . "^Pine")
5535     (-20.0 . "_-_") ;; Subject change in thread
5536     ;;
5537     (-20.0 . "\\.ln@") ;; leafnode
5538     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5539     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5540     ;;
5541     ;; (5.0 . "") ;; $local_part_len <= 7
5542     (10.0  . "^[^0-9]+@")
5543     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5544     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5545     (3.0   . "\@stud")
5546     ;;
5547     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
5548     ;;
5549     (0.5   . "^[A-Z][a-z]")
5550     (0.5   . "^[A-Z][a-z][a-z]")
5551     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5552     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5553   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5554
5555 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5556 address.  The REGEXP is processed with `case-fold-search' set to `nil'."
5557   :group 'gnus-article-buttons
5558   :type '(repeat (cons (number :tag "Rate")
5559                        (regexp :tag "Regexp"))))
5560
5561 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5562   "Guess whether MID-OR-MAIL is a message ID or a mail address.
5563 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5564 address, `ask' if unsure and `invalid' if the string is invalid."
5565   (let ((case-fold-search nil)
5566         (list gnus-button-mid-or-mail-heuristic-alist)
5567         (result 0) rate regexp lpartlen elem)
5568     (setq lpartlen
5569           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5570     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5571     ;; Certain special cases...
5572     (when (string-match
5573            (concat
5574             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$" "\\|"
5575             "^[0-9]+\.[0-9]+\@compuserve")
5576            mid-or-mail)
5577       (gnus-message 8 "`%s' is a known mail address.")
5578       (setq result 'mail))
5579     (when (string-match "@.*@\\| " mid-or-mail)
5580       (gnus-message 8 "`%s' is invalid.")
5581       (setq result 'invalid))
5582     ;; Nothing more to do, if result is not a number here...
5583     (when (numberp result)
5584       (while list
5585         (setq elem (car list)
5586               rate (car elem)
5587               regexp (cdr elem)
5588               list (cdr list))
5589         (when (string-match regexp mid-or-mail)
5590           (setq result (+ result rate))
5591           (gnus-message
5592            9 "`%s' matched `%s', rate `%s', result `%s'."
5593            mid-or-mail regexp rate result)))
5594       (when (<= lpartlen 7)
5595         (setq result (+ result 5.0))
5596         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
5597                       mid-or-mail result))
5598       (when (>= lpartlen 12)
5599         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
5600         (cond
5601          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
5602           ;; Long local part should contain realname if e-mail address,
5603           ;; too many digits: message-id.
5604           ;; $score -= 5.0 + 0.1 * $local_part_len;
5605           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
5606           (setq result (+ result rate))
5607           (gnus-message
5608            9 "Many digits in `%s', rate `%s', result `%s'."
5609            mid-or-mail rate result))
5610          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
5611                         mid-or-mail)
5612           ;; Too few vowels [^aeiouy]{4,}.*\@
5613           (setq result (+ result -5.0))
5614           (gnus-message
5615            9 "Few vowels in `%s', rate `%s', result `%s'."
5616            mid-or-mail -5.0 result))
5617          (t
5618           (setq result (+ result 5.0))
5619           (gnus-message
5620            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
5621     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
5622     (cond
5623      ;; Maybe we should make this a customizable alist: (condition . 'result)
5624      ((< result -10.0) 'mid)
5625      ((> result  10.0) 'mail)
5626      (t 'ask))))
5627
5628 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5629   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
5630          (url-mid (concat "news" ":" mid-or-mail))
5631          (url-mailto (concat "mailto" ":" mid-or-mail)))
5632     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5633     (when (fboundp pref)
5634       (setq guessed
5635             ;; get rid of surrounding angles...
5636             (funcall pref
5637                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
5638       (if (or (eq 'mid guessed) (eq 'mail guessed))
5639           (setq pref guessed)
5640         (setq pref 'ask)))
5641     (if (eq pref 'ask)
5642         (save-window-excursion
5643           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
5644               (setq pref 'mail)
5645             (setq pref 'mid))))
5646     (cond ((eq pref 'mid)
5647            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
5648            (gnus-button-handle-news url-mid))
5649           ((eq pref 'mail)
5650            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
5651            (gnus-url-mailto url-mailto))
5652           (t (gnus-message 3 "Invalid string.")))))
5653
5654 (defun gnus-button-handle-custom (url)
5655   "Follow a Custom URL."
5656   (customize-apropos (gnus-url-unhex-string url)))
5657
5658 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
5659
5660 (defun gnus-button-handle-describe-function (url)
5661   "Call `describe-function' when pushing the corresponding URL button."
5662   (describe-function
5663    (intern
5664     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5665
5666 (defun gnus-button-handle-describe-variable (url)
5667   "Call `describe-variable' when pushing the corresponding URL button."
5668   (describe-variable
5669    (intern
5670     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5671
5672 (defun gnus-button-handle-describe-key (url)
5673   "Call `describe-key' when pushing the corresponding URL button."
5674   (let* ((key-string
5675           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
5676          (keys (ignore-errors (eval `(kbd ,key-string)))))
5677     (if keys
5678         (describe-key keys)
5679       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
5680
5681 (defun gnus-button-handle-apropos (url)
5682   "Call `apropos' when pushing the corresponding URL button."
5683   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5684
5685 (defun gnus-button-handle-apropos-command (url)
5686   "Call `apropos' when pushing the corresponding URL button."
5687   (apropos-command
5688    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5689
5690 (defun gnus-button-handle-apropos-variable (url)
5691   "Call `apropos' when pushing the corresponding URL button."
5692   (funcall
5693    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
5694    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5695
5696 (defun gnus-button-handle-apropos-documentation (url)
5697   "Call `apropos' when pushing the corresponding URL button."
5698   (funcall
5699    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
5700    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5701
5702 (defun gnus-button-handle-ctan (url)
5703   "Call `browse-url' when pushing a CTAN URL button."
5704   (funcall
5705    gnus-button-ctan-handler
5706    (concat
5707     gnus-ctan-url
5708     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
5709
5710 (defcustom gnus-button-tex-level 5
5711   "*Integer that says how many TeX-related buttons Gnus will show.
5712 The higher the number, the more buttons will appear and the more false
5713 positives are possible.  Note that you can set this variable local to
5714 specifific groups.  Setting it higher in TeX groups is probably a good idea.
5715 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5716 how to set variables in specific groups."
5717   :group 'gnus-article-buttons
5718   :link '(custom-manual "(gnus)Group Parameters")
5719   :type 'integer)
5720
5721 (defcustom gnus-button-man-level 5
5722   "*Integer that says how many man-related buttons Gnus will show.
5723 The higher the number, the more buttons will appear and the more false
5724 positives are possible.  Note that you can set this variable local to
5725 specifific groups.  Setting it higher in Unix groups is probably a good idea.
5726 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5727 how to set variables in specific groups."
5728   :group 'gnus-article-buttons
5729   :link '(custom-manual "(gnus)Group Parameters")
5730   :type 'integer)
5731
5732 (defcustom gnus-button-emacs-level 5
5733   "*Integer that says how many emacs-related buttons Gnus will show.
5734 The higher the number, the more buttons will appear and the more false
5735 positives are possible.  Note that you can set this variable local to
5736 specifific groups.  Setting it higher in Emacs or Gnus related groups is
5737 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
5738 `gnus-parameters' on how to set variables in specific groups."
5739   :group 'gnus-article-buttons
5740   :link '(custom-manual "(gnus)Group Parameters")
5741   :type 'integer)
5742
5743 (defcustom gnus-button-mail-level 5
5744   "*Integer that says how many buttons for message IDs or mail addresses will appear.
5745 The higher the number, the more buttons will appear and the more false
5746 positives are possible."
5747   :group 'gnus-article-buttons
5748   :type 'integer)
5749
5750 (defcustom gnus-button-alist
5751   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5752      0 t gnus-button-handle-news 3)
5753     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5754      gnus-button-handle-news 2)
5755     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5756      1 t
5757      gnus-button-fetch-group 4)
5758     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5759     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5760      t gnus-button-message-id 3)
5761     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5762     ("mailto:\\([-a-z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5763     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5764     ;; CTAN
5765     ("\\bCTAN:[ \t\n]*\\([^>)!;:,\n\t ]*\\)" 0 (>= gnus-button-tex-level 1)
5766      gnus-button-handle-ctan 1)
5767     ;; This is info
5768     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
5769      (>= gnus-button-emacs-level 1) gnus-button-handle-info 2)
5770     ;; This is custom
5771     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
5772      (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
5773     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5774      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
5775     ;; Emacs help commands
5776     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5777      ;; regexp doesn't match arguments containing ` '.
5778      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
5779     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5780      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
5781     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5782      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
5783     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5784      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
5785     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5786      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
5787     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5788      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
5789     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'" 1
5790      ;; Unlike the other regexps we really have to require quoting
5791      ;; here to determine where it ends.
5792      (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
5793     ;; This is how URLs _should_ be embedded in text...
5794     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5795     ;; Raw URLs.
5796     (gnus-button-url-regexp 0 t browse-url 0)
5797     ;; man pages
5798     ("\\b\\([a-z][a-z]+\\)([1-9])\\W" 0
5799      (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
5800      gnus-button-handle-man 1)
5801     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
5802     ("\\b\\([a-z][-_.a-z0-9]+\\)([1-9])\\W" 0
5803      (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
5804      gnus-button-handle-man 1)
5805     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
5806     ;; SoWWWAnchor(3iv), XSelectInput(3X11)
5807     ("\\b\\([a-z][-_.:a-z0-9]+\\)([1-9][X1a-z]*)\\W" 0
5808      (>= gnus-button-man-level 5) gnus-button-handle-man 1)
5809     ;; MID or mail: To avoid too many false positives we don't try to catch
5810     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
5811     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
5812     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
5813     ;; so that non-ambiguous entries (see above) match first.
5814     (gnus-button-mid-or-mail-regexp
5815      0 (>= gnus-button-mail-level 5) gnus-button-handle-mid-or-mail 1))
5816   "*Alist of regexps matching buttons in article bodies.
5817
5818 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5819 REGEXP: is the string (case insensitive) matching text around the button (can
5820 also be lisp expression evaluating to a string),
5821 BUTTON: is the number of the regexp grouping actually matching the button,
5822 FORM: is a lisp expression which must eval to true for the button to
5823 be added,
5824 CALLBACK: is the function to call when the user push this button, and each
5825 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5826
5827 CALLBACK can also be a variable, in that case the value of that
5828 variable it the real callback function."
5829   :group 'gnus-article-buttons
5830   :type '(repeat (list (choice regexp variable)
5831                        (integer :tag "Button")
5832                        (sexp :tag "Form")
5833                        (function :tag "Callback")
5834                        (repeat :tag "Par"
5835                                :inline t
5836                                (integer :tag "Regexp group")))))
5837
5838 (defcustom gnus-header-button-alist
5839   '(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5840      0 t gnus-button-message-id 0)
5841     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5842     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5843      0 t gnus-button-mailto 0)
5844     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp 0 t browse-url 0)
5845     ("^Subject:" gnus-button-url-regexp 0 t browse-url 0)
5846     ("^[^:]+:" gnus-button-url-regexp 0 t browse-url 0)
5847     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5848     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5849      gnus-button-message-id 3))
5850   "*Alist of headers and regexps to match buttons in article heads.
5851
5852 This alist is very similar to `gnus-button-alist', except that each
5853 alist has an additional HEADER element first in each entry:
5854
5855 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5856
5857 HEADER is a regexp to match a header.  For a fuller explanation, see
5858 `gnus-button-alist'."
5859   :group 'gnus-article-buttons
5860   :group 'gnus-article-headers
5861   :type '(repeat (list (regexp :tag "Header")
5862                        regexp
5863                        (integer :tag "Button")
5864                        (sexp :tag "Form")
5865                        (function :tag "Callback")
5866                        (repeat :tag "Par"
5867                                :inline t
5868                                (integer :tag "Regexp group")))))
5869
5870 (defvar gnus-button-regexp nil)
5871 (defvar gnus-button-marker-list nil)
5872 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5873
5874 (defvar gnus-button-last nil)
5875 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5876
5877 ;;; Commands:
5878
5879 (defun gnus-article-push-button (event)
5880   "Check text under the mouse pointer for a callback function.
5881 If the text under the mouse pointer has a `gnus-callback' property,
5882 call it with the value of the `gnus-data' text property."
5883   (interactive "e")
5884   (set-buffer (window-buffer (posn-window (event-start event))))
5885   (let* ((pos (posn-point (event-start event)))
5886          (data (get-text-property pos 'gnus-data))
5887          (fun (get-text-property pos 'gnus-callback)))
5888     (goto-char pos)
5889     (when fun
5890       (funcall fun data))))
5891
5892 (defun gnus-article-press-button ()
5893   "Check text at point for a callback function.
5894 If the text at point has a `gnus-callback' property,
5895 call it with the value of the `gnus-data' text property."
5896   (interactive)
5897   (let ((data (get-text-property (point) 'gnus-data))
5898         (fun (get-text-property (point) 'gnus-callback)))
5899     (when fun
5900       (funcall fun data))))
5901
5902 (defun gnus-article-highlight (&optional force)
5903   "Highlight current article.
5904 This function calls `gnus-article-highlight-headers',
5905 `gnus-article-highlight-citation',
5906 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5907 do the highlighting.  See the documentation for those functions."
5908   (interactive (list 'force))
5909   (gnus-article-highlight-headers)
5910   (gnus-article-highlight-citation force)
5911   (gnus-article-highlight-signature)
5912   (gnus-article-add-buttons force)
5913   (gnus-article-add-buttons-to-head))
5914
5915 (defun gnus-article-highlight-some (&optional force)
5916   "Highlight current article.
5917 This function calls `gnus-article-highlight-headers',
5918 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5919 do the highlighting.  See the documentation for those functions."
5920   (interactive (list 'force))
5921   (gnus-article-highlight-headers)
5922   (gnus-article-highlight-signature)
5923   (gnus-article-add-buttons))
5924
5925 (defun gnus-article-highlight-headers ()
5926   "Highlight article headers as specified by `gnus-header-face-alist'."
5927   (interactive)
5928   (save-excursion
5929     (set-buffer gnus-article-buffer)
5930     (save-restriction
5931       (let ((alist gnus-header-face-alist)
5932             (buffer-read-only nil)
5933             (case-fold-search t)
5934             (inhibit-point-motion-hooks t)
5935             entry regexp header-face field-face from hpoints fpoints)
5936         (article-narrow-to-head)
5937         (while (setq entry (pop alist))
5938           (goto-char (point-min))
5939           (setq regexp (concat "^\\("
5940                                (if (string-equal "" (nth 0 entry))
5941                                    "[^\t ]"
5942                                  (nth 0 entry))
5943                                "\\)")
5944                 header-face (nth 1 entry)
5945                 field-face (nth 2 entry))
5946           (while (and (re-search-forward regexp nil t)
5947                       (not (eobp)))
5948             (beginning-of-line)
5949             (setq from (point))
5950             (unless (search-forward ":" nil t)
5951               (forward-char 1))
5952             (when (and header-face
5953                        (not (memq (point) hpoints)))
5954               (push (point) hpoints)
5955               (gnus-put-text-property from (point) 'face header-face))
5956             (when (and field-face
5957                        (not (memq (setq from (point)) fpoints)))
5958               (push from fpoints)
5959               (if (re-search-forward "^[^ \t]" nil t)
5960                   (forward-char -2)
5961                 (goto-char (point-max)))
5962               (gnus-put-text-property from (point) 'face field-face))))))))
5963
5964 (defun gnus-article-highlight-signature ()
5965   "Highlight the signature in an article.
5966 It does this by highlighting everything after
5967 `gnus-signature-separator' using `gnus-signature-face'."
5968   (interactive)
5969   (save-excursion
5970     (set-buffer gnus-article-buffer)
5971     (let ((buffer-read-only nil)
5972           (inhibit-point-motion-hooks t))
5973       (save-restriction
5974         (when (and gnus-signature-face
5975                    (gnus-article-narrow-to-signature))
5976           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5977                             'face gnus-signature-face)
5978           (widen)
5979           (gnus-article-search-signature)
5980           (let ((start (match-beginning 0))
5981                 (end (set-marker (make-marker) (1+ (match-end 0)))))
5982             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5983                                      end)))))))
5984
5985 (defun gnus-button-in-region-p (b e prop)
5986   "Say whether PROP exists in the region."
5987   (text-property-not-all b e prop nil))
5988
5989 (defun gnus-article-add-buttons (&optional force)
5990   "Find external references in the article and make buttons of them.
5991 \"External references\" are things like Message-IDs and URLs, as
5992 specified by `gnus-button-alist'."
5993   (interactive (list 'force))
5994   (save-excursion
5995     (set-buffer gnus-article-buffer)
5996     (let ((buffer-read-only nil)
5997           (inhibit-point-motion-hooks t)
5998           (case-fold-search t)
5999           (alist gnus-button-alist)
6000           beg entry regexp)
6001       ;; Remove all old markers.
6002       (let (marker entry new-list)
6003         (while (setq marker (pop gnus-button-marker-list))
6004           (if (or (< marker (point-min)) (>= marker (point-max)))
6005               (push marker new-list)
6006             (goto-char marker)
6007             (when (setq entry (gnus-button-entry))
6008               (put-text-property (match-beginning (nth 1 entry))
6009                                  (match-end (nth 1 entry))
6010                                  'gnus-callback nil))
6011             (set-marker marker nil)))
6012         (setq gnus-button-marker-list new-list))
6013       ;; We skip the headers.
6014       (article-goto-body)
6015       (setq beg (point))
6016       (while (setq entry (pop alist))
6017         (setq regexp (eval (car entry)))
6018         (goto-char beg)
6019         (while (re-search-forward regexp nil t)
6020           (let* ((start (and entry (match-beginning (nth 1 entry))))
6021                  (end (and entry (match-end (nth 1 entry))))
6022                  (from (match-beginning 0)))
6023             (when (and (or (eq t (nth 2 entry))
6024                            (eval (nth 2 entry)))
6025                        (not (gnus-button-in-region-p
6026                              start end 'gnus-callback)))
6027               ;; That optional form returned non-nil, so we add the
6028               ;; button.
6029               (gnus-article-add-button
6030                start end 'gnus-button-push
6031                (car (push (set-marker (make-marker) from)
6032                           gnus-button-marker-list))))))))))
6033
6034 ;; Add buttons to the head of an article.
6035 (defun gnus-article-add-buttons-to-head ()
6036   "Add buttons to the head of the article."
6037   (interactive)
6038   (save-excursion
6039     (set-buffer gnus-article-buffer)
6040     (save-restriction
6041       (let ((buffer-read-only nil)
6042             (inhibit-point-motion-hooks t)
6043             (case-fold-search t)
6044             (alist gnus-header-button-alist)
6045             entry beg end)
6046         (article-narrow-to-head)
6047         (while alist
6048           ;; Each alist entry.
6049           (setq entry (car alist)
6050                 alist (cdr alist))
6051           (goto-char (point-min))
6052           (while (re-search-forward (car entry) nil t)
6053             ;; Each header matching the entry.
6054             (setq beg (match-beginning 0))
6055             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6056                                (match-beginning 0))
6057                           (point-max)))
6058             (goto-char beg)
6059             (while (re-search-forward (eval (nth 1 entry)) end t)
6060               ;; Each match within a header.
6061               (let* ((entry (cdr entry))
6062                      (start (match-beginning (nth 1 entry)))
6063                      (end (match-end (nth 1 entry)))
6064                      (form (nth 2 entry)))
6065                 (goto-char (match-end 0))
6066                 (when (eval form)
6067                   (gnus-article-add-button
6068                    start end (nth 3 entry)
6069                    (buffer-substring (match-beginning (nth 4 entry))
6070                                      (match-end (nth 4 entry)))))))
6071             (goto-char end)))))))
6072
6073 ;;; External functions:
6074
6075 (defun gnus-article-add-button (from to fun &optional data)
6076   "Create a button between FROM and TO with callback FUN and data DATA."
6077   (when gnus-article-button-face
6078     (gnus-overlay-put (gnus-make-overlay from to)
6079                       'face gnus-article-button-face))
6080   (gnus-add-text-properties
6081    from to
6082    (nconc (and gnus-article-mouse-face
6083                (list gnus-mouse-face-prop gnus-article-mouse-face))
6084           (list 'gnus-callback fun)
6085           (and data (list 'gnus-data data))))
6086   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6087                          :button-keymap gnus-widget-button-keymap))
6088
6089 ;;; Internal functions:
6090
6091 (defun gnus-article-set-globals ()
6092   (save-excursion
6093     (set-buffer gnus-summary-buffer)
6094     (gnus-set-global-variables)))
6095
6096 (defun gnus-signature-toggle (end)
6097   (save-excursion
6098     (set-buffer gnus-article-buffer)
6099     (let ((buffer-read-only nil)
6100           (inhibit-point-motion-hooks t))
6101       (if (text-property-any end (point-max) 'article-type 'signature)
6102           (progn
6103             (gnus-delete-wash-type 'signature)
6104             (gnus-remove-text-properties-when
6105              'article-type 'signature end (point-max)
6106              (cons 'article-type (cons 'signature
6107                                        gnus-hidden-properties))))
6108         (gnus-add-wash-type 'signature)
6109         (gnus-add-text-properties-when
6110          'article-type nil end (point-max)
6111          (cons 'article-type (cons 'signature
6112                                    gnus-hidden-properties)))))
6113     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6114       (gnus-set-mode-line 'article))))
6115
6116 (defun gnus-button-entry ()
6117   ;; Return the first entry in `gnus-button-alist' matching this place.
6118   (let ((alist gnus-button-alist)
6119         (entry nil))
6120     (while alist
6121       (setq entry (pop alist))
6122       (if (looking-at (eval (car entry)))
6123           (setq alist nil)
6124         (setq entry nil)))
6125     entry))
6126
6127 (defun gnus-button-push (marker)
6128   ;; Push button starting at MARKER.
6129   (save-excursion
6130     (goto-char marker)
6131     (let* ((entry (gnus-button-entry))
6132            (inhibit-point-motion-hooks t)
6133            (fun (nth 3 entry))
6134            (args (mapcar (lambda (group)
6135                            (let ((string (match-string group)))
6136                              (gnus-set-text-properties
6137                               0 (length string) nil string)
6138                              string))
6139                          (nthcdr 4 entry))))
6140       (cond
6141        ((fboundp fun)
6142         (apply fun args))
6143        ((and (boundp fun)
6144              (fboundp (symbol-value fun)))
6145         (apply (symbol-value fun) args))
6146        (t
6147         (gnus-message 1 "You must define `%S' to use this button"
6148                       (cons fun args)))))))
6149
6150 (defun gnus-parse-news-url (url)
6151   (let (scheme server group message-id articles)
6152     (with-temp-buffer
6153       (insert url)
6154       (goto-char (point-min))
6155       (when (looking-at "\\([A-Za-z]+\\):")
6156         (setq scheme (match-string 1))
6157         (goto-char (match-end 0)))
6158       (when (looking-at "//\\([^/]+\\)/")
6159         (setq server (match-string 1))
6160         (goto-char (match-end 0)))
6161
6162       (cond
6163        ((looking-at "\\(.*@.*\\)")
6164         (setq message-id (match-string 1)))
6165        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6166         (setq group (match-string 1)
6167               articles (split-string (match-string 2) "-")))
6168        ((looking-at "\\([^/]+\\)/?")
6169         (setq group (match-string 1)))
6170        (t
6171         (error "Unknown news URL syntax"))))
6172     (list scheme server group message-id articles)))
6173
6174 (defun gnus-button-handle-news (url)
6175   "Fetch a news URL."
6176   (destructuring-bind (scheme server group message-id articles)
6177       (gnus-parse-news-url url)
6178     (cond
6179      (message-id
6180       (save-excursion
6181         (set-buffer gnus-summary-buffer)
6182         (if server
6183             (let ((gnus-refer-article-method (list (list 'nntp server))))
6184               (gnus-summary-refer-article message-id))
6185           (gnus-summary-refer-article message-id))))
6186      (group
6187       (gnus-button-fetch-group url)))))
6188
6189 (defun gnus-button-handle-man (url)
6190   "Fetch a man page."
6191   (funcall gnus-button-man-handler url))
6192
6193 (defun gnus-button-handle-info (url)
6194   "Fetch an info URL."
6195   (if (string-match
6196        "^\\([^:/]+\\)?/\\(.*\\)"
6197        url)
6198       (gnus-info-find-node
6199        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6200                        "Gnus")
6201                ")"
6202                (gnus-url-unhex-string (match-string 2 url))))
6203     (error "Can't parse %s" url)))
6204
6205 (defun gnus-button-message-id (message-id)
6206   "Fetch MESSAGE-ID."
6207   (save-excursion
6208     (set-buffer gnus-summary-buffer)
6209     (gnus-summary-refer-article message-id)))
6210
6211 (defun gnus-button-fetch-group (address)
6212   "Fetch GROUP specified by ADDRESS."
6213   (if (not (string-match "[:/]" address))
6214       ;; This is just a simple group url.
6215       (gnus-group-read-ephemeral-group address gnus-select-method)
6216     (if (not
6217          (string-match
6218           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6219           address))
6220         (error "Can't parse %s" address)
6221       (gnus-group-read-ephemeral-group
6222        (match-string 4 address)
6223        `(nntp ,(match-string 1 address)
6224               (nntp-address ,(match-string 1 address))
6225               (nntp-port-number ,(if (match-end 3)
6226                                      (match-string 3 address)
6227                                    "nntp")))
6228        nil nil nil
6229        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6230
6231 (defun gnus-url-parse-query-string (query &optional downcase)
6232   (let (retval pairs cur key val)
6233     (setq pairs (split-string query "&"))
6234     (while pairs
6235       (setq cur (car pairs)
6236             pairs (cdr pairs))
6237       (if (not (string-match "=" cur))
6238           nil                           ; Grace
6239         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6240               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6241         (if downcase
6242             (setq key (downcase key)))
6243         (setq cur (assoc key retval))
6244         (if cur
6245             (setcdr cur (cons val (cdr cur)))
6246           (setq retval (cons (list key val) retval)))))
6247     retval))
6248
6249 (defun gnus-url-mailto (url)
6250   ;; Send mail to someone
6251   (when (string-match "mailto:/*\\(.*\\)" url)
6252     (setq url (substring url (match-beginning 1) nil)))
6253   (let (to args subject func)
6254     (if (string-match (regexp-quote "?") url)
6255         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6256               args (gnus-url-parse-query-string
6257                     (substring url (match-end 0) nil) t))
6258       (setq to (gnus-url-unhex-string url)))
6259     (setq args (cons (list "to" to) args)
6260           subject (cdr-safe (assoc "subject" args)))
6261     (gnus-msg-mail)
6262     (while args
6263       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6264       (if (fboundp func)
6265           (funcall func)
6266         (message-position-on-field (caar args)))
6267       (insert (mapconcat 'identity (cdar args) ", "))
6268       (setq args (cdr args)))
6269     (if subject
6270         (message-goto-body)
6271       (message-goto-subject))))
6272
6273 (defun gnus-button-embedded-url (address)
6274   "Activate ADDRESS with `browse-url'."
6275   (browse-url (gnus-strip-whitespace address)))
6276
6277 ;;; Next/prev buttons in the article buffer.
6278
6279 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6280 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6281
6282 (defvar gnus-prev-page-map
6283   (let ((map (make-sparse-keymap)))
6284     (unless (>= emacs-major-version 21)
6285       ;; XEmacs doesn't care.
6286       (set-keymap-parent map gnus-article-mode-map))
6287     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6288     (define-key map "\r" 'gnus-button-prev-page)
6289     map))
6290
6291 (defun gnus-insert-prev-page-button ()
6292   (let ((b (point))
6293         (buffer-read-only nil))
6294     (gnus-eval-format
6295      gnus-prev-page-line-format nil
6296      `(,@(gnus-local-map-property gnus-prev-page-map)
6297          gnus-prev t
6298          gnus-callback gnus-article-button-prev-page
6299          article-type annotation))
6300     (widget-convert-button
6301      'link b (point)
6302      :action 'gnus-button-prev-page
6303      :button-keymap gnus-prev-page-map)))
6304
6305 (defvar gnus-prev-page-map
6306   (let ((map (make-sparse-keymap)))
6307     (unless (>= emacs-major-version 21)
6308       ;; XEmacs doesn't care.
6309       (set-keymap-parent map gnus-article-mode-map))
6310     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6311     (define-key map "\r" 'gnus-button-prev-page)
6312     map))
6313
6314 (defvar gnus-next-page-map
6315   (let ((map (make-sparse-keymap)))
6316     (unless (>= emacs-major-version 21)
6317       ;; XEmacs doesn't care.
6318       (set-keymap-parent map gnus-article-mode-map))
6319     (define-key map gnus-mouse-2 'gnus-button-next-page)
6320     (define-key map "\r" 'gnus-button-next-page)
6321     map))
6322
6323 (defun gnus-button-next-page (&optional args more-args)
6324   "Go to the next page."
6325   (interactive)
6326   (let ((win (selected-window)))
6327     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6328     (gnus-article-next-page)
6329     (select-window win)))
6330
6331 (defun gnus-button-prev-page (&optional args more-args)
6332   "Go to the prev page."
6333   (interactive)
6334   (let ((win (selected-window)))
6335     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6336     (gnus-article-prev-page)
6337     (select-window win)))
6338
6339 (defun gnus-insert-next-page-button ()
6340   (let ((b (point))
6341         (buffer-read-only nil))
6342     (gnus-eval-format gnus-next-page-line-format nil
6343                       `(,@(gnus-local-map-property gnus-next-page-map)
6344                           gnus-next t
6345                           gnus-callback gnus-article-button-next-page
6346                           article-type annotation))
6347     (widget-convert-button
6348      'link b (point)
6349      :action 'gnus-button-next-page
6350      :button-keymap gnus-next-page-map)))
6351
6352 (defun gnus-article-button-next-page (arg)
6353   "Go to the next page."
6354   (interactive "P")
6355   (let ((win (selected-window)))
6356     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6357     (gnus-article-next-page)
6358     (select-window win)))
6359
6360 (defun gnus-article-button-prev-page (arg)
6361   "Go to the prev page."
6362   (interactive "P")
6363   (let ((win (selected-window)))
6364     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6365     (gnus-article-prev-page)
6366     (select-window win)))
6367
6368 (defvar gnus-decode-header-methods
6369   '(mail-decode-encoded-word-region)
6370   "List of methods used to decode headers.
6371
6372 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6373 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6374 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6375 whose names match REGEXP.
6376
6377 For example:
6378 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6379  mail-decode-encoded-word-region
6380  (\"chinese\" . rfc1843-decode-region))
6381 ")
6382
6383 (defvar gnus-decode-header-methods-cache nil)
6384
6385 (defun gnus-multi-decode-header (start end)
6386   "Apply the functions from `gnus-encoded-word-methods' that match."
6387   (unless (and gnus-decode-header-methods-cache
6388                (eq gnus-newsgroup-name
6389                    (car gnus-decode-header-methods-cache)))
6390     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6391     (mapcar (lambda (x)
6392               (if (symbolp x)
6393                   (nconc gnus-decode-header-methods-cache (list x))
6394                 (if (and gnus-newsgroup-name
6395                          (string-match (car x) gnus-newsgroup-name))
6396                     (nconc gnus-decode-header-methods-cache
6397                            (list (cdr x))))))
6398           gnus-decode-header-methods))
6399   (let ((xlist gnus-decode-header-methods-cache))
6400     (pop xlist)
6401     (save-restriction
6402       (narrow-to-region start end)
6403       (while xlist
6404         (funcall (pop xlist) (point-min) (point-max))))))
6405
6406 ;;;
6407 ;;; Treatment top-level handling.
6408 ;;;
6409
6410 (defun gnus-treat-article (condition &optional part-number total-parts type)
6411   (let ((length (- (point-max) (point-min)))
6412         (alist gnus-treatment-function-alist)
6413         (article-goto-body-goes-to-point-min-p t)
6414         (treated-type
6415          (or (not type)
6416              (catch 'found
6417                (let ((list gnus-article-treat-types))
6418                  (while list
6419                    (when (string-match (pop list) type)
6420                      (throw 'found t)))))))
6421         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6422         val elem)
6423     (gnus-run-hooks 'gnus-part-display-hook)
6424     (dolist (elem alist)
6425       (setq val
6426             (save-excursion
6427               (when (gnus-buffer-live-p gnus-summary-buffer)
6428                 (set-buffer gnus-summary-buffer))
6429               (symbol-value (car elem))))
6430       (when (and (or (consp val)
6431                      treated-type)
6432                  (gnus-treat-predicate val)
6433                  (or (not (get (car elem) 'highlight))
6434                      highlightp))
6435         (save-restriction
6436           (funcall (cadr elem)))))))
6437
6438 ;; Dynamic variables.
6439 (eval-when-compile
6440   (defvar part-number)
6441   (defvar total-parts)
6442   (defvar type)
6443   (defvar condition)
6444   (defvar length))
6445
6446 (defun gnus-treat-predicate (val)
6447   (cond
6448    ((null val)
6449     nil)
6450    (condition
6451     (eq condition val))
6452    ((and (listp val)
6453          (stringp (car val)))
6454     (apply 'gnus-or (mapcar `(lambda (s)
6455                                (string-match s ,(or gnus-newsgroup-name "")))
6456                             val)))
6457    ((listp val)
6458     (let ((pred (pop val)))
6459       (cond
6460        ((eq pred 'or)
6461         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6462        ((eq pred 'and)
6463         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6464        ((eq pred 'not)
6465         (not (gnus-treat-predicate (car val))))
6466        ((eq pred 'typep)
6467         (equal (car val) type))
6468        (t
6469         (error "%S is not a valid predicate" pred)))))
6470    ((eq val t)
6471     t)
6472    ((eq val 'head)
6473     nil)
6474    ((eq val 'last)
6475     (eq part-number total-parts))
6476    ((numberp val)
6477     (< length val))
6478    (t
6479     (error "%S is not a valid value" val))))
6480
6481 (defun gnus-article-encrypt-body (protocol &optional n)
6482   "Encrypt the article body."
6483   (interactive
6484    (list
6485     (or gnus-article-encrypt-protocol
6486         (completing-read "Encrypt protocol: "
6487                          gnus-article-encrypt-protocol-alist
6488                          nil t))
6489     current-prefix-arg))
6490   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6491     (unless func
6492       (error (format "Can't find the encrypt protocol %s" protocol)))
6493     (if (member gnus-newsgroup-name '("nndraft:delayed"
6494                                       "nndraft:drafts"
6495                                       "nndraft:queue"))
6496         (error "Can't encrypt the article in group %s"
6497                gnus-newsgroup-name))
6498     (gnus-summary-iterate n
6499       (save-excursion
6500         (set-buffer gnus-summary-buffer)
6501         (let ((mail-parse-charset gnus-newsgroup-charset)
6502               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6503               (summary-buffer gnus-summary-buffer)
6504               references point)
6505           (gnus-set-global-variables)
6506           (when (gnus-group-read-only-p)
6507             (error "The current newsgroup does not support article encrypt"))
6508           (gnus-summary-show-article t)
6509           (setq references
6510               (or (mail-header-references gnus-current-headers) ""))
6511           (set-buffer gnus-article-buffer)
6512           (let* ((buffer-read-only nil)
6513                  (headers
6514                   (mapcar (lambda (field)
6515                             (and (save-restriction
6516                                    (message-narrow-to-head)
6517                                    (goto-char (point-min))
6518                                    (search-forward field nil t))
6519                                  (prog2
6520                                      (message-narrow-to-field)
6521                                      (buffer-substring (point-min) (point-max))
6522                                    (delete-region (point-min) (point-max))
6523                                    (widen))))
6524                           '("Content-Type:" "Content-Transfer-Encoding:"
6525                             "Content-Disposition:"))))
6526             (message-narrow-to-head)
6527             (message-remove-header "MIME-Version")
6528             (goto-char (point-max))
6529             (setq point (point))
6530             (insert (apply 'concat headers))
6531             (widen)
6532             (narrow-to-region point (point-max))
6533             (let ((message-options message-options))
6534               (message-options-set 'message-sender user-mail-address)
6535               (message-options-set 'message-recipients user-mail-address)
6536               (message-options-set 'message-sign-encrypt 'not)
6537               (funcall func))
6538             (goto-char (point-min))
6539             (insert "MIME-Version: 1.0\n")
6540             (widen)
6541             (gnus-summary-edit-article-done
6542              references nil summary-buffer t))
6543           (when gnus-keep-backlog
6544             (gnus-backlog-remove-article
6545              (car gnus-article-current) (cdr gnus-article-current)))
6546           (save-excursion
6547             (when (get-buffer gnus-original-article-buffer)
6548               (set-buffer gnus-original-article-buffer)
6549               (setq gnus-original-article nil)))
6550           (when gnus-use-cache
6551             (gnus-cache-update-article
6552              (car gnus-article-current) (cdr gnus-article-current))))))))
6553
6554 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6555   "The following specs can be used:
6556 %t  The security MIME type
6557 %i  Additional info
6558 %d  Details
6559 %D  Details if button is pressed")
6560
6561 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6562   "The following specs can be used:
6563 %t  The security MIME type
6564 %i  Additional info
6565 %d  Details
6566 %D  Details if button is pressed")
6567
6568 (defvar gnus-mime-security-button-line-format-alist
6569   '((?t gnus-tmp-type ?s)
6570     (?i gnus-tmp-info ?s)
6571     (?d gnus-tmp-details ?s)
6572     (?D gnus-tmp-pressed-details ?s)))
6573
6574 (defvar gnus-mime-security-button-map
6575   (let ((map (make-sparse-keymap)))
6576     (unless (>= (string-to-number emacs-version) 21)
6577       (set-keymap-parent map gnus-article-mode-map))
6578     (define-key map gnus-mouse-2 'gnus-article-push-button)
6579     (define-key map "\r" 'gnus-article-press-button)
6580     map))
6581
6582 (defvar gnus-mime-security-details-buffer nil)
6583
6584 (defvar gnus-mime-security-button-pressed nil)
6585
6586 (defvar gnus-mime-security-show-details-inline t
6587   "If non-nil, show details in the article buffer.")
6588
6589 (defun gnus-mime-security-verify-or-decrypt (handle)
6590   (mm-remove-parts (cdr handle))
6591   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6592         point buffer-read-only)
6593     (if region
6594         (goto-char (car region)))
6595     (save-restriction
6596       (narrow-to-region (point) (point))
6597       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6598         (let* ((mm-verify-option 'known)
6599                (mm-decrypt-option 'known)
6600                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6601           (unless (eq nparts (cdr handle))
6602             (mm-destroy-parts (cdr handle))
6603             (setcdr handle nparts))))
6604       (setq point (point))
6605       (gnus-mime-display-security handle)
6606       (goto-char (point-max)))
6607     (when region
6608       (delete-region (point) (cdr region))
6609       (set-marker (car region) nil)
6610       (set-marker (cdr region) nil))
6611     (goto-char point)))
6612
6613 (defun gnus-mime-security-show-details (handle)
6614   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6615     (if (not details)
6616         (gnus-message 5 "No details.")
6617       (if gnus-mime-security-show-details-inline
6618           (let ((gnus-mime-security-button-pressed
6619                  (not (get-text-property (point) 'gnus-mime-details)))
6620                 (gnus-mime-security-button-line-format
6621                  (get-text-property (point) 'gnus-line-format))
6622                 buffer-read-only)
6623             (forward-char -1)
6624             (while (eq (get-text-property (point) 'gnus-line-format)
6625                        gnus-mime-security-button-line-format)
6626               (forward-char -1))
6627             (forward-char)
6628             (save-restriction
6629               (narrow-to-region (point) (point))
6630               (gnus-insert-mime-security-button handle))
6631             (delete-region (point)
6632                            (or (text-property-not-all
6633                                 (point) (point-max)
6634                                 'gnus-line-format
6635                                 gnus-mime-security-button-line-format)
6636                                (point-max))))
6637         ;; Not inlined.
6638         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6639             (with-current-buffer gnus-mime-security-details-buffer
6640               (erase-buffer)
6641               t)
6642           (setq gnus-mime-security-details-buffer
6643                 (gnus-get-buffer-create "*MIME Security Details*")))
6644         (with-current-buffer gnus-mime-security-details-buffer
6645           (insert details)
6646           (goto-char (point-min)))
6647         (pop-to-buffer gnus-mime-security-details-buffer)))))
6648
6649 (defun gnus-mime-security-press-button (handle)
6650   (save-excursion
6651     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6652         (gnus-mime-security-show-details handle)
6653       (gnus-mime-security-verify-or-decrypt handle))))
6654
6655 (defun gnus-insert-mime-security-button (handle &optional displayed)
6656   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6657          (gnus-tmp-type
6658           (concat
6659            (or (nth 2 (assoc protocol mm-verify-function-alist))
6660                (nth 2 (assoc protocol mm-decrypt-function-alist))
6661                "Unknown")
6662            (if (equal (car handle) "multipart/signed")
6663                " Signed" " Encrypted")
6664            " Part"))
6665          (gnus-tmp-info
6666           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6667               "Undecided"))
6668          (gnus-tmp-details
6669           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6670          gnus-tmp-pressed-details
6671          b e)
6672     (setq gnus-tmp-details
6673           (if gnus-tmp-details
6674               (concat "\n" gnus-tmp-details)
6675             ""))
6676     (setq gnus-tmp-pressed-details
6677           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6678     (unless (bolp)
6679       (insert "\n"))
6680     (setq b (point))
6681     (gnus-eval-format
6682      gnus-mime-security-button-line-format
6683      gnus-mime-security-button-line-format-alist
6684      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6685          gnus-callback gnus-mime-security-press-button
6686          gnus-line-format ,gnus-mime-security-button-line-format
6687          gnus-mime-details ,gnus-mime-security-button-pressed
6688          article-type annotation
6689          gnus-data ,handle))
6690     (setq e (point))
6691     (widget-convert-button
6692      'link b e
6693      :mime-handle handle
6694      :action 'gnus-widget-press-button
6695      :button-keymap gnus-mime-security-button-map
6696      :help-echo
6697      (lambda (widget/window &optional overlay pos)
6698        ;; Needed to properly clear the message due to a bug in
6699        ;; wid-edit (XEmacs only).
6700        (when (boundp 'help-echo-owns-message)
6701          (setq help-echo-owns-message t))
6702        (format
6703         "%S: show detail"
6704         (aref gnus-mouse-2 0))))))
6705
6706 (defun gnus-mime-display-security (handle)
6707   (save-restriction
6708     (narrow-to-region (point) (point))
6709     (unless (gnus-unbuttonized-mime-type-p (car handle))
6710       (gnus-insert-mime-security-button handle))
6711     (gnus-mime-display-mixed (cdr handle))
6712     (unless (bolp)
6713       (insert "\n"))
6714     (unless (gnus-unbuttonized-mime-type-p (car handle))
6715       (let ((gnus-mime-security-button-line-format
6716              gnus-mime-security-button-end-line-format))
6717         (gnus-insert-mime-security-button handle)))
6718     (mm-set-handle-multipart-parameter
6719      handle 'gnus-region
6720      (cons (set-marker (make-marker) (point-min))
6721            (set-marker (make-marker) (point-max))))))
6722
6723 (gnus-ems-redefine)
6724
6725 (provide 'gnus-art)
6726
6727 (run-hooks 'gnus-art-load-hook)
6728
6729 ;;; gnus-art.el ends here