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