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