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