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