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