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