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