(gnus-article-mode): Use summary tool bar.
[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 (defun gnus-article-mode ()
3457   "Major mode for displaying an article.
3458
3459 All normal editing commands are switched off.
3460
3461 The following commands are available in addition to all summary mode
3462 commands:
3463 \\<gnus-article-mode-map>
3464 \\[gnus-article-next-page]\t Scroll the article one page forwards
3465 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3466 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3467 \\[gnus-article-show-summary]\t Display the summary buffer
3468 \\[gnus-article-mail]\t Send a reply to the address near point
3469 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3470 \\[gnus-info-find-node]\t Go to the Gnus info node"
3471   (interactive)
3472   (gnus-simplify-mode-line)
3473   (setq mode-name "Article")
3474   (setq major-mode 'gnus-article-mode)
3475   (make-local-variable 'minor-mode-alist)
3476   (use-local-map gnus-article-mode-map)
3477   (when (gnus-visual-p 'article-menu 'menu)
3478     (gnus-article-make-menu-bar)
3479     (when gnus-summary-tool-bar-map
3480       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3481   (gnus-update-format-specifications nil 'article-mode)
3482   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3483   (make-local-variable 'gnus-page-broken)
3484   (make-local-variable 'gnus-button-marker-list)
3485   (make-local-variable 'gnus-article-current-summary)
3486   (make-local-variable 'gnus-article-mime-handles)
3487   (make-local-variable 'gnus-article-decoded-p)
3488   (make-local-variable 'gnus-article-mime-handle-alist)
3489   (make-local-variable 'gnus-article-wash-types)
3490   (make-local-variable 'gnus-article-image-alist)
3491   (make-local-variable 'gnus-article-charset)
3492   (make-local-variable 'gnus-article-ignored-charsets)
3493   (gnus-set-default-directory)
3494   (buffer-disable-undo)
3495   (setq buffer-read-only t)
3496   (set-syntax-table gnus-article-mode-syntax-table)
3497   (mm-enable-multibyte)
3498   (gnus-run-hooks 'gnus-article-mode-hook))
3499
3500 (defun gnus-article-setup-buffer ()
3501   "Initialize the article buffer."
3502   (let* ((name (if gnus-single-article-buffer "*Article*"
3503                  (concat "*Article " gnus-newsgroup-name "*")))
3504          (original
3505           (progn (string-match "\\*Article" name)
3506                  (concat " *Original Article"
3507                          (substring name (match-end 0))))))
3508     (setq gnus-article-buffer name)
3509     (setq gnus-original-article-buffer original)
3510     (setq gnus-article-mime-handle-alist nil)
3511     ;; This might be a variable local to the summary buffer.
3512     (unless gnus-single-article-buffer
3513       (save-excursion
3514         (set-buffer gnus-summary-buffer)
3515         (setq gnus-article-buffer name)
3516         (setq gnus-original-article-buffer original)
3517         (gnus-set-global-variables)))
3518     (gnus-article-setup-highlight-words)
3519     ;; Init original article buffer.
3520     (save-excursion
3521       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3522       (mm-enable-multibyte)
3523       (setq major-mode 'gnus-original-article-mode)
3524       (make-local-variable 'gnus-original-article))
3525     (if (get-buffer name)
3526         (save-excursion
3527           (set-buffer name)
3528           (when (and gnus-article-edit-mode
3529                      (buffer-modified-p)
3530                      (not
3531                       (y-or-n-p "Article mode edit in progress; discard? ")))
3532             (error "Action aborted"))
3533           (set (make-local-variable 'gnus-article-edit-mode) nil)
3534           (when gnus-article-mime-handles
3535             (mm-destroy-parts gnus-article-mime-handles)
3536             (setq gnus-article-mime-handles nil))
3537           ;; Set it to nil in article-buffer!
3538           (setq gnus-article-mime-handle-alist nil)
3539           (buffer-disable-undo)
3540           (setq buffer-read-only t)
3541           ;; This list just keeps growing if we don't reset it.
3542           (setq gnus-button-marker-list nil)
3543           (unless (eq major-mode 'gnus-article-mode)
3544             (gnus-article-mode))
3545           (current-buffer))
3546       (save-excursion
3547         (set-buffer (gnus-get-buffer-create name))
3548         (gnus-article-mode)
3549         (make-local-variable 'gnus-summary-buffer)
3550         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3551         (current-buffer)))))
3552
3553 ;; Set article window start at LINE, where LINE is the number of lines
3554 ;; from the head of the article.
3555 (defun gnus-article-set-window-start (&optional line)
3556   (set-window-start
3557    (gnus-get-buffer-window gnus-article-buffer t)
3558    (save-excursion
3559      (set-buffer gnus-article-buffer)
3560      (goto-char (point-min))
3561      (if (not line)
3562          (point-min)
3563        (gnus-message 6 "Moved to bookmark")
3564        (search-forward "\n\n" nil t)
3565        (forward-line line)
3566        (point)))))
3567
3568 (defun gnus-article-prepare (article &optional all-headers header)
3569   "Prepare ARTICLE in article mode buffer.
3570 ARTICLE should either be an article number or a Message-ID.
3571 If ARTICLE is an id, HEADER should be the article headers.
3572 If ALL-HEADERS is non-nil, no headers are hidden."
3573   (save-excursion
3574     ;; Make sure we start in a summary buffer.
3575     (unless (eq major-mode 'gnus-summary-mode)
3576       (set-buffer gnus-summary-buffer))
3577     (setq gnus-summary-buffer (current-buffer))
3578     (let* ((gnus-article (if header (mail-header-number header) article))
3579            (summary-buffer (current-buffer))
3580            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3581            (group gnus-newsgroup-name)
3582            result)
3583       (save-excursion
3584         (gnus-article-setup-buffer)
3585         (set-buffer gnus-article-buffer)
3586         ;; Deactivate active regions.
3587         (when (and (boundp 'transient-mark-mode)
3588                    transient-mark-mode)
3589           (setq mark-active nil))
3590         (if (not (setq result (let ((buffer-read-only nil))
3591                                 (gnus-request-article-this-buffer
3592                                  article group))))
3593             ;; There is no such article.
3594             (save-excursion
3595               (when (and (numberp article)
3596                          (not (memq article gnus-newsgroup-sparse)))
3597                 (setq gnus-article-current
3598                       (cons gnus-newsgroup-name article))
3599                 (set-buffer gnus-summary-buffer)
3600                 (setq gnus-current-article article)
3601                 (if (memq article gnus-newsgroup-undownloaded)
3602                     (progn
3603                       (gnus-summary-set-agent-mark article)
3604                       (message "Message marked for downloading"))
3605                   (gnus-summary-mark-article article gnus-canceled-mark)
3606                   (unless (memq article gnus-newsgroup-sparse)
3607                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3608           (if (or (eq result 'pseudo)
3609                   (eq result 'nneething))
3610               (progn
3611                 (save-excursion
3612                   (set-buffer summary-buffer)
3613                   (push article gnus-newsgroup-history)
3614                   (setq gnus-last-article gnus-current-article
3615                         gnus-current-article 0
3616                         gnus-current-headers nil
3617                         gnus-article-current nil)
3618                   (if (eq result 'nneething)
3619                       (gnus-configure-windows 'summary)
3620                     (gnus-configure-windows 'article))
3621                   (gnus-set-global-variables))
3622                 (let ((gnus-article-mime-handle-alist-1
3623                        gnus-article-mime-handle-alist))
3624                   (gnus-set-mode-line 'article)))
3625             ;; The result from the `request' was an actual article -
3626             ;; or at least some text that is now displayed in the
3627             ;; article buffer.
3628             (when (and (numberp article)
3629                        (not (eq article gnus-current-article)))
3630               ;; Seems like a new article has been selected.
3631               ;; `gnus-current-article' must be an article number.
3632               (save-excursion
3633                 (set-buffer summary-buffer)
3634                 (push article gnus-newsgroup-history)
3635                 (setq gnus-last-article gnus-current-article
3636                       gnus-current-article article
3637                       gnus-current-headers
3638                       (gnus-summary-article-header gnus-current-article)
3639                       gnus-article-current
3640                       (cons gnus-newsgroup-name gnus-current-article))
3641                 (unless (vectorp gnus-current-headers)
3642                   (setq gnus-current-headers nil))
3643                 (gnus-summary-goto-subject gnus-current-article)
3644                 (when (gnus-summary-show-thread)
3645                   ;; If the summary buffer really was folded, the
3646                   ;; previous goto may not actually have gone to
3647                   ;; the right article, but the thread root instead.
3648                   ;; So we go again.
3649                   (gnus-summary-goto-subject gnus-current-article))
3650                 (gnus-run-hooks 'gnus-mark-article-hook)
3651                 (gnus-set-mode-line 'summary)
3652                 (when (gnus-visual-p 'article-highlight 'highlight)
3653                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3654                 ;; Set the global newsgroup variables here.
3655                 (gnus-set-global-variables)
3656                 (setq gnus-have-all-headers
3657                       (or all-headers gnus-show-all-headers))))
3658             (save-excursion
3659               (gnus-configure-windows 'article))
3660             (when (or (numberp article)
3661                       (stringp article))
3662               (gnus-article-prepare-display)
3663               ;; Do page break.
3664               (goto-char (point-min))
3665               (setq gnus-page-broken
3666                     (when gnus-break-pages
3667                       (gnus-narrow-to-page)
3668                       t)))
3669             (let ((gnus-article-mime-handle-alist-1
3670                    gnus-article-mime-handle-alist))
3671               (gnus-set-mode-line 'article))
3672             (article-goto-body)
3673             (unless (bobp)
3674               (forward-line -1))
3675             (set-window-point (get-buffer-window (current-buffer)) (point))
3676             (gnus-configure-windows 'article)
3677             t))))))
3678
3679 ;;;###autoload
3680 (defun gnus-article-prepare-display ()
3681   "Make the current buffer look like a nice article."
3682   ;; Hooks for getting information from the article.
3683   ;; This hook must be called before being narrowed.
3684   (let ((gnus-article-buffer (current-buffer))
3685         buffer-read-only)
3686     (unless (eq major-mode 'gnus-article-mode)
3687       (gnus-article-mode))
3688     (setq buffer-read-only nil
3689           gnus-article-wash-types nil
3690           gnus-article-image-alist nil)
3691     (gnus-run-hooks 'gnus-tmp-internal-hook)
3692     (when gnus-display-mime-function
3693       (funcall gnus-display-mime-function))
3694     (gnus-run-hooks 'gnus-article-prepare-hook)))
3695
3696 ;;;
3697 ;;; Gnus MIME viewing functions
3698 ;;;
3699
3700 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3701   "Format of the MIME buttons.
3702
3703 Valid specifiers include:
3704 %t  The MIME type
3705 %T  MIME type, along with additional info
3706 %n  The `name' parameter
3707 %d  The description, if any
3708 %l  The length of the encoded part
3709 %p  The part identifier number
3710 %e  Dots if the part isn't displayed
3711
3712 General format specifiers can also be used.  See Info node
3713 `(gnus)Formatting Variables'.")
3714
3715 (defvar gnus-mime-button-line-format-alist
3716   '((?t gnus-tmp-type ?s)
3717     (?T gnus-tmp-type-long ?s)
3718     (?n gnus-tmp-name ?s)
3719     (?d gnus-tmp-description ?s)
3720     (?p gnus-tmp-id ?s)
3721     (?l gnus-tmp-length ?d)
3722     (?e gnus-tmp-dots ?s)))
3723
3724 (defvar gnus-mime-button-commands
3725   '((gnus-article-press-button "\r" "Toggle Display")
3726     (gnus-mime-view-part "v" "View Interactively...")
3727     (gnus-mime-view-part-as-type "t" "View As Type...")
3728     (gnus-mime-view-part-as-charset "C" "View As charset...")
3729     (gnus-mime-save-part "o" "Save...")
3730     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3731     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3732     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3733     (gnus-mime-view-part-internally "E" "View Internally")
3734     (gnus-mime-view-part-externally "e" "View Externally")
3735     (gnus-mime-print-part "p" "Print")
3736     (gnus-mime-pipe-part "|" "Pipe To Command...")
3737     (gnus-mime-action-on-part "." "Take action on the part")))
3738
3739 (defun gnus-article-mime-part-status ()
3740   (if gnus-article-mime-handle-alist-1
3741       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3742           " (1 part)"
3743         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3744     ""))
3745
3746 (defvar gnus-mime-button-map
3747   (let ((map (make-sparse-keymap)))
3748     (unless (>= (string-to-number emacs-version) 21)
3749       ;; XEmacs doesn't care.
3750       (set-keymap-parent map gnus-article-mode-map))
3751     (define-key map gnus-mouse-2 'gnus-article-push-button)
3752     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3753     (dolist (c gnus-mime-button-commands)
3754       (define-key map (cadr c) (car c)))
3755     map))
3756
3757 (defun gnus-mime-button-menu (event)
3758   "Construct a context-sensitive menu of MIME commands."
3759   (interactive "e")
3760   (save-window-excursion
3761     (let ((pos (event-start event)))
3762       (select-window (posn-window pos))
3763       (goto-char (posn-point pos))
3764       (gnus-article-check-buffer)
3765       (let ((response (x-popup-menu
3766                        t `("MIME Part"
3767                            ("" ,@(mapcar (lambda (c)
3768                                            (cons (caddr c) (car c)))
3769                                          gnus-mime-button-commands))))))
3770         (if response
3771             (call-interactively response))))))
3772
3773 (defun gnus-mime-view-all-parts (&optional handles)
3774   "View all the MIME parts."
3775   (interactive)
3776   (save-current-buffer
3777     (set-buffer gnus-article-buffer)
3778     (let ((handles (or handles gnus-article-mime-handles))
3779           (mail-parse-charset gnus-newsgroup-charset)
3780           (mail-parse-ignored-charsets
3781            (with-current-buffer gnus-summary-buffer
3782              gnus-newsgroup-ignored-charsets)))
3783       (when handles
3784         (mm-remove-parts handles)
3785         (goto-char (point-min))
3786         (or (search-forward "\n\n") (goto-char (point-max)))
3787         (let (buffer-read-only)
3788           (delete-region (point) (point-max))
3789           (mm-display-parts handles))))))
3790
3791 (defun gnus-mime-save-part-and-strip ()
3792   "Save the MIME part under point then replace it with an external body."
3793   (interactive)
3794   (gnus-article-check-buffer)
3795   (let* ((data (get-text-property (point) 'gnus-data))
3796          file param
3797          (handles gnus-article-mime-handles))
3798     (if (mm-multiple-handles gnus-article-mime-handles)
3799         (error "This function is not implemented"))
3800     (setq file (and data (mm-save-part data)))
3801     (when file
3802       (with-current-buffer (mm-handle-buffer data)
3803         (erase-buffer)
3804         (insert "Content-Type: " (mm-handle-media-type data))
3805         (mml-insert-parameter-string (cdr (mm-handle-type data))
3806                                      '(charset))
3807         (insert "\n")
3808         (insert "Content-ID: " (message-make-message-id) "\n")
3809         (insert "Content-Transfer-Encoding: binary\n")
3810         (insert "\n"))
3811       (setcdr data
3812               (cdr (mm-make-handle nil
3813                                    `("message/external-body"
3814                                      (access-type . "LOCAL-FILE")
3815                                      (name . ,file)))))
3816       (set-buffer gnus-summary-buffer)
3817       (gnus-article-edit-article
3818        `(lambda ()
3819            (erase-buffer)
3820            (let ((mail-parse-charset (or gnus-article-charset
3821                                          ',gnus-newsgroup-charset))
3822                  (mail-parse-ignored-charsets
3823                   (or gnus-article-ignored-charsets
3824                       ',gnus-newsgroup-ignored-charsets))
3825                  (mbl mml-buffer-list))
3826              (setq mml-buffer-list nil)
3827              (insert-buffer gnus-original-article-buffer)
3828              (mime-to-mml ',handles)
3829              (setq gnus-article-mime-handles nil)
3830              (let ((mbl1 mml-buffer-list))
3831                (setq mml-buffer-list mbl)
3832                (set (make-local-variable 'mml-buffer-list) mbl1))
3833              ;; LOCAL argument of add-hook differs between GNU Emacs
3834              ;; and XEmacs. make-local-hook makes sure they are local.
3835              (make-local-hook 'kill-buffer-hook)
3836              (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3837        `(lambda (no-highlight)
3838           (let ((mail-parse-charset (or gnus-article-charset
3839                                         ',gnus-newsgroup-charset))
3840                 (message-options message-options)
3841                 (message-options-set-recipient)
3842                 (mail-parse-ignored-charsets
3843                  (or gnus-article-ignored-charsets
3844                      ',gnus-newsgroup-ignored-charsets)))
3845            (mml-to-mime)
3846            (mml-destroy-buffers)
3847            (remove-hook 'kill-buffer-hook
3848                         'mml-destroy-buffers t)
3849            (kill-local-variable 'mml-buffer-list))
3850           (gnus-summary-edit-article-done
3851            ,(or (mail-header-references gnus-current-headers) "")
3852            ,(gnus-group-read-only-p)
3853            ,gnus-summary-buffer no-highlight))))))
3854
3855 (defun gnus-mime-save-part ()
3856   "Save the MIME part under point."
3857   (interactive)
3858   (gnus-article-check-buffer)
3859   (let ((data (get-text-property (point) 'gnus-data)))
3860     (when data
3861       (mm-save-part data))))
3862
3863 (defun gnus-mime-pipe-part ()
3864   "Pipe the MIME part under point to a process."
3865   (interactive)
3866   (gnus-article-check-buffer)
3867   (let ((data (get-text-property (point) 'gnus-data)))
3868     (when data
3869       (mm-pipe-part data))))
3870
3871 (defun gnus-mime-view-part ()
3872   "Interactively choose a viewing method for the MIME part under point."
3873   (interactive)
3874   (gnus-article-check-buffer)
3875   (let ((data (get-text-property (point) 'gnus-data)))
3876     (when data
3877       (setq gnus-article-mime-handles
3878             (mm-merge-handles
3879              gnus-article-mime-handles (setq data (copy-sequence data))))
3880       (mm-interactively-view-part data))))
3881
3882 (defun gnus-mime-view-part-as-type-internal ()
3883   (gnus-article-check-buffer)
3884   (let* ((name (mail-content-type-get
3885                 (mm-handle-type (get-text-property (point) 'gnus-data))
3886                 'name))
3887          (def-type (and name (mm-default-file-encoding name))))
3888     (and def-type (cons def-type 0))))
3889
3890 (defun gnus-mime-view-part-as-type (&optional mime-type)
3891   "Choose a MIME media type, and view the part as such."
3892   (interactive)
3893   (unless mime-type
3894     (setq mime-type (completing-read
3895                      "View as MIME type: "
3896                      (mapcar #'list (mailcap-mime-types))
3897                      nil nil
3898                      (gnus-mime-view-part-as-type-internal))))
3899   (gnus-article-check-buffer)
3900   (let ((handle (get-text-property (point) 'gnus-data)))
3901     (when handle
3902       (setq handle
3903             (mm-make-handle (mm-handle-buffer handle)
3904                             (cons mime-type (cdr (mm-handle-type handle)))
3905                             (mm-handle-encoding handle)
3906                             (mm-handle-undisplayer handle)
3907                             (mm-handle-disposition handle)
3908                             (mm-handle-description handle)
3909                             nil
3910                             (mm-handle-id handle)))
3911       (setq gnus-article-mime-handles
3912             (mm-merge-handles gnus-article-mime-handles handle))
3913       (gnus-mm-display-part handle))))
3914
3915 (eval-when-compile
3916   (require 'jka-compr))
3917
3918 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
3919 ;; emacs can do that itself.
3920 ;;
3921 (defun gnus-mime-jka-compr-maybe-uncompress ()
3922   "Uncompress the current buffer if `auto-compression-mode' is enabled.
3923 The uncompress method used is derived from `buffer-file-name'."
3924   (when (and (fboundp 'jka-compr-installed-p)
3925              (jka-compr-installed-p))
3926     (let ((info (jka-compr-get-compression-info buffer-file-name)))
3927       (when info
3928         (let ((basename (file-name-nondirectory buffer-file-name))
3929               (args     (jka-compr-info-uncompress-args    info))
3930               (prog     (jka-compr-info-uncompress-program info))
3931               (message  (jka-compr-info-uncompress-message info))
3932               (err-file (jka-compr-make-temp-name)))
3933           (if message
3934               (message "%s %s..." message basename))
3935           (unwind-protect
3936               (unless (memq (apply 'call-process-region
3937                                    (point-min) (point-max) 
3938                                    prog
3939                                    t (list t err-file) nil
3940                                    args)
3941                             jka-compr-acceptable-retval-list)
3942                 (jka-compr-error prog args basename message err-file))
3943             (jka-compr-delete-temp-file err-file)))))))
3944
3945 (defun gnus-mime-copy-part (&optional handle)
3946   "Put the MIME part under point into a new buffer.
3947 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
3948 are decompressed."
3949   (interactive)
3950   (gnus-article-check-buffer)
3951   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3952          (contents (and handle (mm-get-part handle)))
3953          (base (and handle
3954                     (file-name-nondirectory
3955                      (or
3956                       (mail-content-type-get (mm-handle-type handle) 'name)
3957                       (mail-content-type-get (mm-handle-disposition handle)
3958                                              'filename)
3959                       "*decoded*"))))
3960          (buffer (and base (generate-new-buffer base))))
3961     (when contents
3962       (switch-to-buffer buffer)
3963       (insert contents)
3964       ;; We do it this way to make `normal-mode' set the appropriate mode.
3965       (unwind-protect
3966           (progn
3967             (setq buffer-file-name (expand-file-name base))
3968             (gnus-mime-jka-compr-maybe-uncompress)
3969             (normal-mode))
3970         (setq buffer-file-name nil))
3971       (goto-char (point-min)))))
3972
3973 (defun gnus-mime-print-part (&optional handle filename)
3974   "Print the MIME part under point."
3975   (interactive (list nil (ps-print-preprint current-prefix-arg)))
3976   (gnus-article-check-buffer)
3977   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3978          (contents (and handle (mm-get-part handle)))
3979          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
3980          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
3981     (when contents
3982         (if printer
3983             (unwind-protect
3984                 (progn
3985                   (mm-save-part-to-file handle file)
3986                   (call-process shell-file-name nil
3987                                 (generate-new-buffer " *mm*")
3988                                 nil
3989                                 shell-command-switch
3990                                 (mm-mailcap-command
3991                                  printer file (mm-handle-type handle))))
3992               (delete-file file))
3993           (with-temp-buffer
3994             (insert contents)
3995             (gnus-print-buffer))
3996           (ps-despool filename)))))
3997
3998 (defun gnus-mime-inline-part (&optional handle arg)
3999   "Insert the MIME part under point into the current buffer."
4000   (interactive (list nil current-prefix-arg))
4001   (gnus-article-check-buffer)
4002   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4003          contents charset
4004          (b (point))
4005          buffer-read-only)
4006     (when handle
4007       (if (and (not arg) (mm-handle-undisplayer handle))
4008           (mm-remove-part handle)
4009         (setq contents (mm-get-part handle))
4010         (cond
4011          ((not arg)
4012           (setq charset (or (mail-content-type-get
4013                              (mm-handle-type handle) 'charset)
4014                             gnus-newsgroup-charset)))
4015          ((numberp arg)
4016           (if (mm-handle-undisplayer handle)
4017               (mm-remove-part handle))
4018           (setq charset
4019                 (or (cdr (assq arg
4020                                gnus-summary-show-article-charset-alist))
4021                     (mm-read-coding-system "Charset: ")))))
4022         (forward-line 2)
4023         (mm-insert-inline handle
4024                           (if (and charset
4025                                    (setq charset (mm-charset-to-coding-system
4026                                                   charset))
4027                                    (not (eq charset 'ascii)))
4028                               (mm-decode-coding-string contents charset)
4029                             contents))
4030         (goto-char b)))))
4031
4032 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4033   "Insert the MIME part under point into the current buffer using the
4034 specified charset."
4035   (interactive (list nil current-prefix-arg))
4036   (gnus-article-check-buffer)
4037   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4038          contents charset
4039          (b (point))
4040          buffer-read-only)
4041     (when handle
4042       (if (mm-handle-undisplayer handle)
4043           (mm-remove-part handle))
4044       (let ((gnus-newsgroup-charset
4045              (or (cdr (assq arg
4046                             gnus-summary-show-article-charset-alist))
4047                  (mm-read-coding-system "Charset: ")))
4048           (gnus-newsgroup-ignored-charsets 'gnus-all))
4049         (gnus-article-press-button)))))
4050
4051 (defun gnus-mime-view-part-externally (&optional handle)
4052   "View the MIME part under point with an external viewer."
4053   (interactive)
4054   (gnus-article-check-buffer)
4055   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4056          (mm-user-display-methods nil)
4057          (mm-inlined-types nil)
4058          (mail-parse-charset gnus-newsgroup-charset)
4059          (mail-parse-ignored-charsets
4060           (save-excursion (set-buffer gnus-summary-buffer)
4061                           gnus-newsgroup-ignored-charsets)))
4062     (when handle
4063       (if (mm-handle-undisplayer handle)
4064           (mm-remove-part handle)
4065         (mm-display-part handle)))))
4066
4067 (defun gnus-mime-view-part-internally (&optional handle)
4068   "View the MIME part under point with an internal viewer.
4069 If no internal viewer is available, use an external viewer."
4070   (interactive)
4071   (gnus-article-check-buffer)
4072   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4073          (mm-inlined-types '(".*"))
4074          (mm-inline-large-images t)
4075          (mail-parse-charset gnus-newsgroup-charset)
4076          (mail-parse-ignored-charsets
4077           (save-excursion (set-buffer gnus-summary-buffer)
4078                           gnus-newsgroup-ignored-charsets)))
4079     (when handle
4080       (if (mm-handle-undisplayer handle)
4081           (mm-remove-part handle)
4082         (mm-display-part handle)))))
4083
4084 (defun gnus-mime-action-on-part (&optional action)
4085   "Do something with the MIME attachment at \(point\)."
4086   (interactive
4087    (list (completing-read "Action: " gnus-mime-action-alist)))
4088   (gnus-article-check-buffer)
4089   (let ((action-pair (assoc action gnus-mime-action-alist)))
4090     (if action-pair
4091         (funcall (cdr action-pair)))))
4092
4093 (defun gnus-article-part-wrapper (n function)
4094   (save-current-buffer
4095     (set-buffer gnus-article-buffer)
4096     (when (> n (length gnus-article-mime-handle-alist))
4097       (error "No such part"))
4098     (gnus-article-goto-part n)
4099     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4100       (funcall function handle))))
4101
4102 (defun gnus-article-pipe-part (n)
4103   "Pipe MIME part N, which is the numerical prefix."
4104   (interactive "p")
4105   (gnus-article-part-wrapper n 'mm-pipe-part))
4106
4107 (defun gnus-article-save-part (n)
4108   "Save MIME part N, which is the numerical prefix."
4109   (interactive "p")
4110   (gnus-article-part-wrapper n 'mm-save-part))
4111
4112 (defun gnus-article-interactively-view-part (n)
4113   "View MIME part N interactively, which is the numerical prefix."
4114   (interactive "p")
4115   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4116
4117 (defun gnus-article-copy-part (n)
4118   "Copy MIME part N, which is the numerical prefix."
4119   (interactive "p")
4120   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4121
4122 (defun gnus-article-view-part-as-charset (n)
4123   "Copy MIME part N, which is the numerical prefix."
4124   (interactive "p")
4125   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4126
4127 (defun gnus-article-view-part-externally (n)
4128   "View MIME part N externally, which is the numerical prefix."
4129   (interactive "p")
4130   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4131
4132 (defun gnus-article-inline-part (n)
4133   "Inline MIME part N, which is the numerical prefix."
4134   (interactive "p")
4135   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4136
4137 (defun gnus-article-mime-match-handle-first (condition)
4138   (if condition
4139       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4140         (while (setq ihandle (pop alist))
4141           (if (and (cond
4142                     ((functionp condition)
4143                      (funcall condition (cdr ihandle)))
4144                     ((eq condition 'undisplayed)
4145                      (not (or (mm-handle-undisplayer (cdr ihandle))
4146                               (equal (mm-handle-media-type (cdr ihandle))
4147                                      "multipart/alternative"))))
4148                     ((eq condition 'undisplayed-alternative)
4149                      (not (mm-handle-undisplayer (cdr ihandle))))
4150                     (t t))
4151                    (gnus-article-goto-part (car ihandle))
4152                    (or (not n) (< (car ihandle) n)))
4153               (setq n (car ihandle))))
4154         (or n 1))
4155     1))
4156
4157 (defun gnus-article-view-part (&optional n)
4158   "View MIME part N, which is the numerical prefix."
4159   (interactive "P")
4160   (save-current-buffer
4161     (set-buffer gnus-article-buffer)
4162     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4163                              gnus-article-mime-match-handle-function)))
4164     (when (> n (length gnus-article-mime-handle-alist))
4165       (error "No such part"))
4166     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4167       (when (gnus-article-goto-part n)
4168         (if (equal (car handle) "multipart/alternative")
4169             (gnus-article-press-button)
4170           (when (eq (gnus-mm-display-part handle) 'internal)
4171             (gnus-set-window-start)))))))
4172
4173 (defsubst gnus-article-mime-total-parts ()
4174   (if (bufferp (car gnus-article-mime-handles))
4175       1 ;; single part
4176     (1- (length gnus-article-mime-handles))))
4177
4178 (defun gnus-mm-display-part (handle)
4179   "Display HANDLE and fix MIME button."
4180   (let ((id (get-text-property (point) 'gnus-part))
4181         (point (point))
4182         buffer-read-only)
4183     (forward-line 1)
4184     (prog1
4185         (let ((window (selected-window))
4186               (mail-parse-charset gnus-newsgroup-charset)
4187               (mail-parse-ignored-charsets
4188                (if (gnus-buffer-live-p gnus-summary-buffer)
4189                    (save-excursion
4190                      (set-buffer gnus-summary-buffer)
4191                      gnus-newsgroup-ignored-charsets)
4192                  nil)))
4193           (save-excursion
4194             (unwind-protect
4195                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4196                       (beg (point)))
4197                   (when win
4198                     (select-window win))
4199                   (goto-char point)
4200                   (forward-line)
4201                   (if (mm-handle-displayed-p handle)
4202                       ;; This will remove the part.
4203                       (mm-display-part handle)
4204                     (save-restriction
4205                       (narrow-to-region (point)
4206                                         (if (eobp) (point) (1+ (point))))
4207                       (mm-display-part handle)
4208                       ;; We narrow to the part itself and
4209                       ;; then call the treatment functions.
4210                       (goto-char (point-min))
4211                       (forward-line 1)
4212                       (narrow-to-region (point) (point-max))
4213                       (gnus-treat-article
4214                        nil id
4215                        (gnus-article-mime-total-parts)
4216                        (mm-handle-media-type handle)))))
4217               (if (window-live-p window)
4218                   (select-window window)))))
4219       (goto-char point)
4220       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4221       (gnus-insert-mime-button
4222        handle id (list (mm-handle-displayed-p handle)))
4223       (goto-char point))))
4224
4225 (defun gnus-article-goto-part (n)
4226   "Go to MIME part N."
4227   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4228     (when point
4229       (goto-char point))))
4230
4231 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4232   (let ((gnus-tmp-name
4233          (or (mail-content-type-get (mm-handle-type handle) 'name)
4234              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4235              (mail-content-type-get (mm-handle-type handle) 'url)
4236              ""))
4237         (gnus-tmp-type (mm-handle-media-type handle))
4238         (gnus-tmp-description
4239          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4240                                               "")))
4241         (gnus-tmp-dots
4242          (if (if displayed (car displayed)
4243                (mm-handle-displayed-p handle))
4244              "" "..."))
4245         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4246                            (buffer-size)))
4247         gnus-tmp-type-long b e)
4248     (when (string-match ".*/" gnus-tmp-name)
4249       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4250     (setq gnus-tmp-type-long (concat gnus-tmp-type
4251                                      (and (not (equal gnus-tmp-name ""))
4252                                           (concat "; " gnus-tmp-name))))
4253     (unless (equal gnus-tmp-description "")
4254       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4255     (unless (bolp)
4256       (insert "\n"))
4257     (setq b (point))
4258     (gnus-eval-format
4259      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4260      `(,@(gnus-local-map-property gnus-mime-button-map)
4261          gnus-callback gnus-mm-display-part
4262          gnus-part ,gnus-tmp-id
4263          article-type annotation
4264          gnus-data ,handle))
4265     (setq e (point))
4266     (widget-convert-button
4267      'link b e
4268      :mime-handle handle
4269      :action 'gnus-widget-press-button
4270      :button-keymap gnus-mime-button-map
4271      :help-echo
4272      (lambda (widget/window &optional overlay pos)
4273        ;; Needed to properly clear the message due to a bug in
4274        ;; wid-edit (XEmacs only).
4275        (if (boundp 'help-echo-owns-message)
4276            (setq help-echo-owns-message t))
4277        (format
4278         "%S: %s the MIME part; %S: more options"
4279         (aref gnus-mouse-2 0)
4280         ;; XEmacs will get a single widget arg; Emacs 21 will get
4281         ;; window, overlay, position.
4282         (if (mm-handle-displayed-p
4283              (if overlay
4284                  (with-current-buffer (gnus-overlay-buffer overlay)
4285                    (widget-get (widget-at (gnus-overlay-start overlay))
4286                                :mime-handle))
4287                (widget-get widget/window :mime-handle)))
4288             "hide" "show")
4289         (aref gnus-down-mouse-3 0))))))
4290
4291 (defun gnus-widget-press-button (elems el)
4292   (goto-char (widget-get elems :from))
4293   (gnus-article-press-button))
4294
4295 (defvar gnus-displaying-mime nil)
4296
4297 (defun gnus-display-mime (&optional ihandles)
4298   "Display the MIME parts."
4299   (save-excursion
4300     (save-selected-window
4301       (let ((window (get-buffer-window gnus-article-buffer))
4302             (point (point)))
4303         (when window
4304           (select-window window)
4305           ;; We have to do this since selecting the window
4306           ;; may change the point.  So we set the window point.
4307           (set-window-point window point)))
4308       (let* ((handles (or ihandles
4309                           (mm-dissect-buffer nil gnus-article-loose-mime)
4310                           (and gnus-article-emulate-mime
4311                                (mm-uu-dissect))))
4312              buffer-read-only handle name type b e display)
4313         (when (and (not ihandles)
4314                    (not gnus-displaying-mime))
4315           ;; Top-level call; we clean up.
4316           (when gnus-article-mime-handles
4317             (mm-destroy-parts gnus-article-mime-handles)
4318             (setq gnus-article-mime-handle-alist nil));; A trick.
4319           (setq gnus-article-mime-handles handles)
4320           ;; We allow users to glean info from the handles.
4321           (when gnus-article-mime-part-function
4322             (gnus-mime-part-function handles)))
4323         (if (and handles
4324                  (or (not (stringp (car handles)))
4325                      (cdr handles)))
4326             (progn
4327               (when (and (not ihandles)
4328                          (not gnus-displaying-mime))
4329                 ;; Clean up for mime parts.
4330                 (article-goto-body)
4331                 (delete-region (point) (point-max)))
4332               (let ((gnus-displaying-mime t))
4333                 (gnus-mime-display-part handles)))
4334           (save-restriction
4335             (article-goto-body)
4336             (narrow-to-region (point) (point-max))
4337             (gnus-treat-article nil 1 1)
4338             (widen)))
4339         (unless ihandles
4340           ;; Highlight the headers.
4341           (save-excursion
4342             (save-restriction
4343               (article-goto-body)
4344               (narrow-to-region (point-min) (point))
4345               (gnus-treat-article 'head))))))))
4346
4347 (defvar gnus-mime-display-multipart-as-mixed nil)
4348 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4349 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4350
4351 (defun gnus-mime-display-part (handle)
4352   (cond
4353    ;; Single part.
4354    ((not (stringp (car handle)))
4355     (gnus-mime-display-single handle))
4356    ;; User-defined multipart
4357    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4358     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4359              handle))
4360    ;; multipart/alternative
4361    ((and (equal (car handle) "multipart/alternative")
4362          (not (or gnus-mime-display-multipart-as-mixed
4363                   gnus-mime-display-multipart-alternative-as-mixed)))
4364     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4365       (push (cons id handle) gnus-article-mime-handle-alist)
4366       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4367    ;; multipart/related
4368    ((and (equal (car handle) "multipart/related")
4369          (not (or gnus-mime-display-multipart-as-mixed
4370                   gnus-mime-display-multipart-related-as-mixed)))
4371     ;;;!!!We should find the start part, but we just default
4372     ;;;!!!to the first part.
4373     ;;(gnus-mime-display-part (cadr handle))
4374     ;;;!!! Most multipart/related is an HTML message plus images.
4375     ;;;!!! Unfortunately we are unable to let W3 display those
4376     ;;;!!! included images, so we just display it as a mixed multipart.
4377     ;;(gnus-mime-display-mixed (cdr handle))
4378     ;;;!!! No, w3 can display everything just fine.
4379     (gnus-mime-display-part (cadr handle)))
4380    ((equal (car handle) "multipart/signed")
4381     (gnus-add-wash-type 'signed)
4382     (gnus-mime-display-security handle))
4383    ((equal (car handle) "multipart/encrypted")
4384     (gnus-add-wash-type 'encrypted)
4385     (gnus-mime-display-security handle))
4386    ;; Other multiparts are handled like multipart/mixed.
4387    (t
4388     (gnus-mime-display-mixed (cdr handle)))))
4389
4390 (defun gnus-mime-part-function (handles)
4391   (if (stringp (car handles))
4392       (mapcar 'gnus-mime-part-function (cdr handles))
4393     (funcall gnus-article-mime-part-function handles)))
4394
4395 (defun gnus-mime-display-mixed (handles)
4396   (mapcar 'gnus-mime-display-part handles))
4397
4398 (defun gnus-mime-display-single (handle)
4399   (let ((type (mm-handle-media-type handle))
4400         (ignored gnus-ignored-mime-types)
4401         (not-attachment t)
4402         (move nil)
4403         display text)
4404     (catch 'ignored
4405       (progn
4406         (while ignored
4407           (when (string-match (pop ignored) type)
4408             (throw 'ignored nil)))
4409         (if (and (setq not-attachment
4410                        (and (not (mm-inline-override-p handle))
4411                             (or (not (mm-handle-disposition handle))
4412                                 (equal (car (mm-handle-disposition handle))
4413                                        "inline")
4414                                 (mm-attachment-override-p handle))))
4415                  (mm-automatic-display-p handle)
4416                  (or (and
4417                       (mm-inlinable-p handle)
4418                       (mm-inlined-p handle))
4419                      (mm-automatic-external-display-p type)))
4420             (setq display t)
4421           (when (equal (mm-handle-media-supertype handle) "text")
4422             (setq text t)))
4423         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4424               beg)
4425           (push (cons id handle) gnus-article-mime-handle-alist)
4426           (when (or (not display)
4427                     (not (gnus-unbuttonized-mime-type-p type)))
4428             ;(gnus-article-insert-newline)
4429             (gnus-insert-mime-button
4430              handle id (list (or display (and not-attachment text))))
4431             (gnus-article-insert-newline)
4432             ;(gnus-article-insert-newline)
4433             ;; Remember modify the number of forward lines.
4434             (setq move t))
4435           (setq beg (point))
4436           (cond
4437            (display
4438             (when move
4439               (forward-line -1)
4440               (setq beg (point)))
4441             (let ((mail-parse-charset gnus-newsgroup-charset)
4442                   (mail-parse-ignored-charsets
4443                    (save-excursion (condition-case ()
4444                                        (set-buffer gnus-summary-buffer)
4445                                      (error))
4446                                    gnus-newsgroup-ignored-charsets)))
4447               (mm-display-part handle t))
4448             (goto-char (point-max)))
4449            ((and text not-attachment)
4450             (when move
4451               (forward-line -1)
4452               (setq beg (point)))
4453             (gnus-article-insert-newline)
4454             (mm-insert-inline handle (mm-get-part handle))
4455             (goto-char (point-max))))
4456           ;; Do highlighting.
4457           (save-excursion
4458             (save-restriction
4459               (narrow-to-region beg (point))
4460               (gnus-treat-article
4461                nil id
4462                (gnus-article-mime-total-parts)
4463                (mm-handle-media-type handle)))))))))
4464
4465 (defun gnus-unbuttonized-mime-type-p (type)
4466   "Say whether TYPE is to be unbuttonized."
4467   (unless gnus-inhibit-mime-unbuttonizing
4468     (when (catch 'found
4469             (let ((types gnus-unbuttonized-mime-types))
4470               (while types
4471                 (when (string-match (pop types) type)
4472                   (throw 'found t)))))
4473       (not (catch 'found
4474              (let ((types gnus-buttonized-mime-types))
4475                (while types
4476                  (when (string-match (pop types) type)
4477                    (throw 'found t)))))))))
4478
4479 (defun gnus-article-insert-newline ()
4480   "Insert a newline, but mark it as undeletable."
4481   (gnus-put-text-property
4482    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4483
4484 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4485   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4486          (ihandles handles)
4487          (point (point))
4488          handle buffer-read-only from props begend not-pref)
4489     (save-window-excursion
4490       (save-restriction
4491         (when ibegend
4492           (narrow-to-region (car ibegend)
4493                             (or (cdr ibegend)
4494                                 (progn
4495                                   (goto-char (car ibegend))
4496                                   (forward-line 2)
4497                                   (point))))
4498           (delete-region (point-min) (point-max))
4499           (mm-remove-parts handles))
4500         (setq begend (list (point-marker)))
4501         ;; Do the toggle.
4502         (unless (setq not-pref (cadr (member preferred ihandles)))
4503           (setq not-pref (car ihandles)))
4504         (when (or ibegend
4505                   (not preferred)
4506                   (not (gnus-unbuttonized-mime-type-p
4507                         "multipart/alternative")))
4508           (gnus-add-text-properties
4509            (setq from (point))
4510            (progn
4511              (insert (format "%d.  " id))
4512              (point))
4513            `(gnus-callback
4514              (lambda (handles)
4515                (unless ,(not ibegend)
4516                  (setq gnus-article-mime-handle-alist
4517                        ',gnus-article-mime-handle-alist))
4518                (gnus-mime-display-alternative
4519                 ',ihandles ',not-pref ',begend ,id))
4520              ,@(gnus-local-map-property gnus-mime-button-map)
4521              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4522              face ,gnus-article-button-face
4523              gnus-part ,id
4524              gnus-data ,handle))
4525           (widget-convert-button 'link from (point)
4526                                  :action 'gnus-widget-press-button
4527                                  :button-keymap gnus-widget-button-keymap)
4528           ;; Do the handles
4529           (while (setq handle (pop handles))
4530             (gnus-add-text-properties
4531              (setq from (point))
4532              (progn
4533                (insert (format "(%c) %-18s"
4534                                (if (equal handle preferred) ?* ? )
4535                                (mm-handle-media-type handle)))
4536                (point))
4537              `(gnus-callback
4538                (lambda (handles)
4539                  (unless ,(not ibegend)
4540                    (setq gnus-article-mime-handle-alist
4541                          ',gnus-article-mime-handle-alist))
4542                  (gnus-mime-display-alternative
4543                   ',ihandles ',handle ',begend ,id))
4544                ,@(gnus-local-map-property gnus-mime-button-map)
4545                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4546                face ,gnus-article-button-face
4547                gnus-part ,id
4548                gnus-data ,handle))
4549             (widget-convert-button 'link from (point)
4550                                    :action 'gnus-widget-press-button
4551                                    :button-keymap gnus-widget-button-keymap)
4552             (insert "  "))
4553           (insert "\n\n"))
4554         (when preferred
4555           (if (stringp (car preferred))
4556               (gnus-display-mime preferred)
4557             (let ((mail-parse-charset gnus-newsgroup-charset)
4558                   (mail-parse-ignored-charsets
4559                    (save-excursion (set-buffer gnus-summary-buffer)
4560                                    gnus-newsgroup-ignored-charsets)))
4561               (mm-display-part preferred)
4562               ;; Do highlighting.
4563               (save-excursion
4564                 (save-restriction
4565                   (narrow-to-region (car begend) (point-max))
4566                   (gnus-treat-article
4567                    nil (length gnus-article-mime-handle-alist)
4568                    (gnus-article-mime-total-parts)
4569                    (mm-handle-media-type handle))))))
4570           (goto-char (point-max))
4571           (setcdr begend (point-marker)))))
4572     (when ibegend
4573       (goto-char point))))
4574
4575 (defconst gnus-article-wash-status-strings
4576   (let ((alist '((cite "c" "Possible hidden citation text"
4577                        " " "All citation text visible")
4578                  (headers "h" "Hidden headers"
4579                           " " "All headers visible.")
4580                  (pgp "p" "Encrypted or signed message status hidden"
4581                       " " "No hidden encryption nor digital signature status")
4582                  (signature "s" "Signature has been hidden"
4583                             " " "Signature is visible")
4584                  (overstrike "o" "Overstrike (^H) characters applied"
4585                              " " "No overstrike characters applied")
4586                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4587                            " " "No /*_emphasis_*/ characters applied")))
4588         result)
4589     (dolist (entry alist result)
4590       (let ((key (nth 0 entry))
4591             (on (copy-sequence (nth 1 entry)))
4592             (on-help (nth 2 entry))
4593             (off (copy-sequence (nth 3 entry)))
4594             (off-help (nth 4 entry)))
4595         (put-text-property 0 1 'help-echo on-help on)
4596         (put-text-property 0 1 'help-echo off-help off)
4597         (push (list key on off) result))))
4598   "Alist of strings describing wash status in the mode line.
4599 Each entry has the form (KEY ON OF), where the KEY is a symbol
4600 representing the particular washing function, ON is the string to use
4601 in the article mode line when the washing function is active, and OFF
4602 is the string to use when it is inactive.")
4603
4604 (defun gnus-article-wash-status-entry (key value)
4605   (let ((entry (assoc key gnus-article-wash-status-strings)))
4606     (if value (nth 1 entry) (nth 2 entry))))
4607
4608 (defun gnus-article-wash-status ()
4609   "Return a string which display status of article washing."
4610   (save-excursion
4611     (set-buffer gnus-article-buffer)
4612     (let ((cite (memq 'cite gnus-article-wash-types))
4613           (headers (memq 'headers gnus-article-wash-types))
4614           (boring (memq 'boring-headers gnus-article-wash-types))
4615           (pgp (memq 'pgp gnus-article-wash-types))
4616           (pem (memq 'pem gnus-article-wash-types))
4617           (signed (memq 'signed gnus-article-wash-types))
4618           (encrypted (memq 'encrypted gnus-article-wash-types))
4619           (signature (memq 'signature gnus-article-wash-types))
4620           (overstrike (memq 'overstrike gnus-article-wash-types))
4621           (emphasis (memq 'emphasis gnus-article-wash-types)))
4622       (concat
4623        (gnus-article-wash-status-entry 'cite cite)
4624        (gnus-article-wash-status-entry 'headers (or headers boring))
4625        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4626        (gnus-article-wash-status-entry 'signature signature)
4627        (gnus-article-wash-status-entry 'overstrike overstrike)
4628        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4629
4630 (defun gnus-add-wash-type (type)
4631   "Add a washing of TYPE to the current status."
4632   (add-to-list 'gnus-article-wash-types type))
4633
4634 (defun gnus-delete-wash-type (type)
4635   "Add a washing of TYPE to the current status."
4636   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4637
4638 (defun gnus-add-image (category image)
4639   "Add IMAGE of CATEGORY to the list of displayed images."
4640   (let ((entry (assq category gnus-article-image-alist)))
4641     (unless entry
4642       (setq entry (list category))
4643       (push entry gnus-article-image-alist))
4644     (nconc entry (list image))))
4645
4646 (defun gnus-delete-images (category)
4647   "Delete all images in CATEGORY."
4648   (let ((entry (assq category gnus-article-image-alist)))
4649     (dolist (image (cdr entry))
4650       (gnus-remove-image image))
4651     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4652     (gnus-delete-wash-type category)))
4653
4654 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4655
4656 (defun gnus-article-maybe-hide-headers ()
4657   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4658 Provided for backwards compatibility."
4659   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4660                  (not (save-excursion (set-buffer gnus-summary-buffer)
4661                                       gnus-have-all-headers)))
4662              (not gnus-inhibit-hiding))
4663     (gnus-article-hide-headers)))
4664
4665 ;;; Article savers.
4666
4667 (defun gnus-output-to-file (file-name)
4668   "Append the current article to a file named FILE-NAME."
4669   (let ((artbuf (current-buffer)))
4670     (with-temp-buffer
4671       (insert-buffer-substring artbuf)
4672       ;; Append newline at end of the buffer as separator, and then
4673       ;; save it to file.
4674       (goto-char (point-max))
4675       (insert "\n")
4676       (let ((file-name-coding-system nnmail-pathname-coding-system))
4677         (mm-append-to-file (point-min) (point-max) file-name))
4678       t)))
4679
4680 (defun gnus-narrow-to-page (&optional arg)
4681   "Narrow the article buffer to a page.
4682 If given a numerical ARG, move forward ARG pages."
4683   (interactive "P")
4684   (setq arg (if arg (prefix-numeric-value arg) 0))
4685   (save-excursion
4686     (set-buffer gnus-article-buffer)
4687     (goto-char (point-min))
4688     (widen)
4689     ;; Remove any old next/prev buttons.
4690     (when (gnus-visual-p 'page-marker)
4691       (let ((buffer-read-only nil))
4692         (gnus-remove-text-with-property 'gnus-prev)
4693         (gnus-remove-text-with-property 'gnus-next)))
4694     (when
4695         (cond ((< arg 0)
4696                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4697               ((> arg 0)
4698                (re-search-forward page-delimiter nil 'move arg)))
4699       (goto-char (match-end 0)))
4700     (narrow-to-region
4701      (point)
4702      (if (re-search-forward page-delimiter nil 'move)
4703          (match-beginning 0)
4704        (point)))
4705     (when (and (gnus-visual-p 'page-marker)
4706                (not (= (point-min) 1)))
4707       (save-excursion
4708         (goto-char (point-min))
4709         (gnus-insert-prev-page-button)))
4710     (when (and (gnus-visual-p 'page-marker)
4711                (< (+ (point-max) 2) (buffer-size)))
4712       (save-excursion
4713         (goto-char (point-max))
4714         (gnus-insert-next-page-button)))))
4715
4716 ;; Article mode commands
4717
4718 (defun gnus-article-goto-next-page ()
4719   "Show the next page of the article."
4720   (interactive)
4721   (when (gnus-article-next-page)
4722     (goto-char (point-min))
4723     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4724
4725 (defun gnus-article-goto-prev-page ()
4726   "Show the next page of the article."
4727   (interactive)
4728   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4729     (gnus-article-prev-page nil)))
4730
4731 (defun gnus-article-next-page (&optional lines)
4732   "Show the next page of the current article.
4733 If end of article, return non-nil.  Otherwise return nil.
4734 Argument LINES specifies lines to be scrolled up."
4735   (interactive "p")
4736   (move-to-window-line -1)
4737   (if (save-excursion
4738         (end-of-line)
4739         (and (pos-visible-in-window-p)  ;Not continuation line.
4740              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
4741       ;; Nothing in this page.
4742       (if (or (not gnus-page-broken)
4743               (save-excursion
4744                 (save-restriction
4745                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4746           t                             ;Nothing more.
4747         (gnus-narrow-to-page 1)         ;Go to next page.
4748         nil)
4749     ;; More in this page.
4750     (let ((scroll-in-place nil))
4751       (condition-case ()
4752           (scroll-up lines)
4753         (end-of-buffer
4754          ;; Long lines may cause an end-of-buffer error.
4755          (goto-char (point-max)))))
4756     (move-to-window-line 0)
4757     nil))
4758
4759 (defun gnus-article-prev-page (&optional lines)
4760   "Show previous page of current article.
4761 Argument LINES specifies lines to be scrolled down."
4762   (interactive "p")
4763   (move-to-window-line 0)
4764   (if (and gnus-page-broken
4765            (bobp)
4766            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4767       (progn
4768         (gnus-narrow-to-page -1)        ;Go to previous page.
4769         (goto-char (point-max))
4770         (recenter -1))
4771     (let ((scroll-in-place nil))
4772       (prog1
4773           (condition-case ()
4774               (scroll-down lines)
4775             (beginning-of-buffer
4776              (goto-char (point-min))))
4777         (move-to-window-line 0)))))
4778
4779 (defun gnus-article-refer-article ()
4780   "Read article specified by message-id around point."
4781   (interactive)
4782   (let ((point (point)))
4783     (search-forward ">" nil t)          ;Move point to end of "<....>".
4784     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4785         (let ((message-id (match-string 1)))
4786           (goto-char point)
4787           (set-buffer gnus-summary-buffer)
4788           (gnus-summary-refer-article message-id))
4789       (goto-char (point))
4790       (error "No references around point"))))
4791
4792 (defun gnus-article-show-summary ()
4793   "Reconfigure windows to show summary buffer."
4794   (interactive)
4795   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4796       (error "There is no summary buffer for this article buffer")
4797     (gnus-article-set-globals)
4798     (gnus-configure-windows 'article)
4799     (gnus-summary-goto-subject gnus-current-article)
4800     (gnus-summary-position-point)))
4801
4802 (defun gnus-article-describe-briefly ()
4803   "Describe article mode commands briefly."
4804   (interactive)
4805   (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")))
4806
4807 (defun gnus-article-summary-command ()
4808   "Execute the last keystroke in the summary buffer."
4809   (interactive)
4810   (let ((obuf (current-buffer))
4811         (owin (current-window-configuration))
4812         func)
4813     (switch-to-buffer gnus-article-current-summary 'norecord)
4814     (setq func (lookup-key (current-local-map) (this-command-keys)))
4815     (call-interactively func)
4816     (set-buffer obuf)
4817     (set-window-configuration owin)
4818     (set-window-point (get-buffer-window (current-buffer)) (point))))
4819
4820 (defun gnus-article-summary-command-nosave ()
4821   "Execute the last keystroke in the summary buffer."
4822   (interactive)
4823   (let (func)
4824     (pop-to-buffer gnus-article-current-summary 'norecord)
4825     (setq func (lookup-key (current-local-map) (this-command-keys)))
4826     (call-interactively func)))
4827
4828 (defun gnus-article-check-buffer ()
4829   "Beep if not in an article buffer."
4830   (unless (equal major-mode 'gnus-article-mode)
4831     (error "Command invoked outside of a Gnus article buffer")))
4832
4833 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4834   "Read a summary buffer key sequence and execute it from the article buffer."
4835   (interactive "P")
4836   (gnus-article-check-buffer)
4837   (let ((nosaves
4838          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
4839            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4840            "=" "^" "\M-^" "|"))
4841         (nosave-but-article
4842          '("A\r"))
4843         (nosave-in-article
4844          '("\C-d"))
4845         (up-to-top
4846          '("n" "Gn" "p" "Gp"))
4847         keys new-sum-point)
4848     (save-excursion
4849       (set-buffer gnus-article-current-summary)
4850       (let (gnus-pick-mode)
4851         (push (or key last-command-event) unread-command-events)
4852         (setq keys (if (featurep 'xemacs)
4853                        (events-to-keys (read-key-sequence nil))
4854                      (read-key-sequence nil)))))
4855
4856     (message "")
4857
4858     (if (or (member keys nosaves)
4859             (member keys nosave-but-article)
4860             (member keys nosave-in-article))
4861         (let (func)
4862           (save-window-excursion
4863             (pop-to-buffer gnus-article-current-summary 'norecord)
4864             ;; We disable the pick minor mode commands.
4865             (let (gnus-pick-mode)
4866               (setq func (lookup-key (current-local-map) keys))))
4867           (if (or (not func)
4868                   (numberp func))
4869               (ding)
4870             (unless (member keys nosave-in-article)
4871               (set-buffer gnus-article-current-summary))
4872             (call-interactively func)
4873             (setq new-sum-point (point)))
4874           (when (member keys nosave-but-article)
4875             (pop-to-buffer gnus-article-buffer 'norecord)))
4876       ;; These commands should restore window configuration.
4877       (let ((obuf (current-buffer))
4878             (owin (current-window-configuration))
4879             (opoint (point))
4880             (summary gnus-article-current-summary)
4881             func in-buffer selected)
4882         (if not-restore-window
4883             (pop-to-buffer summary 'norecord)
4884           (switch-to-buffer summary 'norecord))
4885         (setq in-buffer (current-buffer))
4886         ;; We disable the pick minor mode commands.
4887         (if (and (setq func (let (gnus-pick-mode)
4888                               (lookup-key (current-local-map) keys)))
4889                  (functionp func))
4890             (progn
4891               (call-interactively func)
4892               (setq new-sum-point (point))
4893               (when (eq in-buffer (current-buffer))
4894                 (setq selected (gnus-summary-select-article))
4895                 (set-buffer obuf)
4896                 (unless not-restore-window
4897                   (set-window-configuration owin))
4898                 (when (eq selected 'old)
4899                   (article-goto-body)
4900                   (set-window-start (get-buffer-window (current-buffer))
4901                                     1)
4902                   (set-window-point (get-buffer-window (current-buffer))
4903                                     (point)))
4904                 (let ((win (get-buffer-window gnus-article-current-summary)))
4905                   (when win
4906                     (set-window-point win new-sum-point))))    )
4907           (switch-to-buffer gnus-article-buffer)
4908           (ding))))))
4909
4910 (defun gnus-article-describe-key (key)
4911   "Display documentation of the function invoked by KEY.  KEY is a string."
4912   (interactive "kDescribe key: ")
4913   (gnus-article-check-buffer)
4914   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4915       (save-excursion
4916         (set-buffer gnus-article-current-summary)
4917         (let (gnus-pick-mode)
4918           (if (featurep 'xemacs)
4919               (progn
4920                 (push (elt key 0) unread-command-events)
4921                 (setq key (events-to-keys
4922                            (read-key-sequence "Describe key: "))))
4923             (setq unread-command-events
4924                   (mapcar
4925                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4926                    (string-to-list key)))
4927             (setq key (read-key-sequence "Describe key: "))))
4928         (describe-key key))
4929     (describe-key key)))
4930
4931 (defun gnus-article-describe-key-briefly (key &optional insert)
4932   "Display documentation of the function invoked by KEY.  KEY is a string."
4933   (interactive "kDescribe key: \nP")
4934   (gnus-article-check-buffer)
4935   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4936       (save-excursion
4937         (set-buffer gnus-article-current-summary)
4938         (let (gnus-pick-mode)
4939           (if (featurep 'xemacs)
4940               (progn
4941                 (push (elt key 0) unread-command-events)
4942                 (setq key (events-to-keys
4943                            (read-key-sequence "Describe key: "))))
4944             (setq unread-command-events
4945                   (mapcar
4946                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4947                    (string-to-list key)))
4948             (setq key (read-key-sequence "Describe key: "))))
4949         (describe-key-briefly key insert))
4950     (describe-key-briefly key insert)))
4951
4952 (defun gnus-article-reply-with-original (&optional wide)
4953   "Start composing a reply mail to the current message.
4954 The text in the region will be yanked.  If the region isn't active,
4955 the entire article will be yanked."
4956   (interactive "P")
4957   (let ((article (cdr gnus-article-current))
4958         contents)
4959     (if (not (gnus-mark-active-p))
4960         (with-current-buffer gnus-summary-buffer
4961           (gnus-summary-reply (list (list article)) wide))
4962       (setq contents (buffer-substring (point) (mark t)))
4963       ;; Deactivate active regions.
4964       (when (and (boundp 'transient-mark-mode)
4965                  transient-mark-mode)
4966         (setq mark-active nil))
4967       (with-current-buffer gnus-summary-buffer
4968         (gnus-summary-reply
4969          (list (list article contents)) wide)))))
4970
4971 (defun gnus-article-followup-with-original ()
4972   "Compose a followup to the current article.
4973 The text in the region will be yanked.  If the region isn't active,
4974 the entire article will be yanked."
4975   (interactive)
4976   (let ((article (cdr gnus-article-current))
4977         contents)
4978       (if (not (gnus-mark-active-p))
4979           (with-current-buffer gnus-summary-buffer
4980             (gnus-summary-followup (list (list article))))
4981         (setq contents (buffer-substring (point) (mark t)))
4982         ;; Deactivate active regions.
4983         (when (and (boundp 'transient-mark-mode)
4984                    transient-mark-mode)
4985           (setq mark-active nil))
4986         (with-current-buffer gnus-summary-buffer
4987           (gnus-summary-followup
4988            (list (list article contents)))))))
4989
4990 (defun gnus-article-hide (&optional arg force)
4991   "Hide all the gruft in the current article.
4992 This means that signatures, cited text and (some) headers will be
4993 hidden.
4994 If given a prefix, show the hidden text instead."
4995   (interactive (append (gnus-article-hidden-arg) (list 'force)))
4996   (gnus-article-hide-headers arg)
4997   (gnus-article-hide-list-identifiers arg)
4998   (gnus-article-hide-citation-maybe arg force)
4999   (gnus-article-hide-signature arg))
5000
5001 (defun gnus-article-maybe-highlight ()
5002   "Do some article highlighting if article highlighting is requested."
5003   (when (gnus-visual-p 'article-highlight 'highlight)
5004     (gnus-article-highlight-some)))
5005
5006 (defun gnus-check-group-server ()
5007   ;; Make sure the connection to the server is alive.
5008   (unless (gnus-server-opened
5009            (gnus-find-method-for-group gnus-newsgroup-name))
5010     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5011     (gnus-request-group gnus-newsgroup-name t)))
5012
5013 (eval-when-compile
5014   (autoload 'nneething-get-file-name "nneething"))
5015
5016 (defun gnus-request-article-this-buffer (article group)
5017   "Get an article and insert it into this buffer."
5018   (let (do-update-line sparse-header)
5019     (prog1
5020         (save-excursion
5021           (erase-buffer)
5022           (gnus-kill-all-overlays)
5023           (setq group (or group gnus-newsgroup-name))
5024
5025           ;; Using `gnus-request-article' directly will insert the article into
5026           ;; `nntp-server-buffer' - so we'll save some time by not having to
5027           ;; copy it from the server buffer into the article buffer.
5028
5029           ;; We only request an article by message-id when we do not have the
5030           ;; headers for it, so we'll have to get those.
5031           (when (stringp article)
5032             (gnus-read-header article))
5033
5034           ;; If the article number is negative, that means that this article
5035           ;; doesn't belong in this newsgroup (possibly), so we find its
5036           ;; message-id and request it by id instead of number.
5037           (when (and (numberp article)
5038                      gnus-summary-buffer
5039                      (get-buffer gnus-summary-buffer)
5040                      (gnus-buffer-exists-p gnus-summary-buffer))
5041             (save-excursion
5042               (set-buffer gnus-summary-buffer)
5043               (let ((header (gnus-summary-article-header article)))
5044                 (when (< article 0)
5045                   (cond
5046                    ((memq article gnus-newsgroup-sparse)
5047                     ;; This is a sparse gap article.
5048                     (setq do-update-line article)
5049                     (setq article (mail-header-id header))
5050                     (setq sparse-header (gnus-read-header article))
5051                     (setq gnus-newsgroup-sparse
5052                           (delq article gnus-newsgroup-sparse)))
5053                    ((vectorp header)
5054                     ;; It's a real article.
5055                     (setq article (mail-header-id header)))
5056                    (t
5057                     ;; It is an extracted pseudo-article.
5058                     (setq article 'pseudo)
5059                     (gnus-request-pseudo-article header))))
5060
5061                 (let ((method (gnus-find-method-for-group
5062                                gnus-newsgroup-name)))
5063                   (when (and (eq (car method) 'nneething)
5064                              (vectorp header))
5065                     (let ((dir (nneething-get-file-name
5066                                 (mail-header-id header))))
5067                       (when (and (stringp dir)
5068                                  (file-directory-p dir))
5069                         (setq article 'nneething)
5070                         (gnus-group-enter-directory dir))))))))
5071
5072           (cond
5073            ;; Refuse to select canceled articles.
5074            ((and (numberp article)
5075                  gnus-summary-buffer
5076                  (get-buffer gnus-summary-buffer)
5077                  (gnus-buffer-exists-p gnus-summary-buffer)
5078                  (eq (cdr (save-excursion
5079                             (set-buffer gnus-summary-buffer)
5080                             (assq article gnus-newsgroup-reads)))
5081                      gnus-canceled-mark))
5082             nil)
5083            ;; We first check `gnus-original-article-buffer'.
5084            ((and (get-buffer gnus-original-article-buffer)
5085                  (numberp article)
5086                  (save-excursion
5087                    (set-buffer gnus-original-article-buffer)
5088                    (and (equal (car gnus-original-article) group)
5089                         (eq (cdr gnus-original-article) article))))
5090             (insert-buffer-substring gnus-original-article-buffer)
5091             'article)
5092            ;; Check the backlog.
5093            ((and gnus-keep-backlog
5094                  (gnus-backlog-request-article group article (current-buffer)))
5095             'article)
5096            ;; Check asynchronous pre-fetch.
5097            ((gnus-async-request-fetched-article group article (current-buffer))
5098             (gnus-async-prefetch-next group article gnus-summary-buffer)
5099             (when (and (numberp article) gnus-keep-backlog)
5100               (gnus-backlog-enter-article group article (current-buffer)))
5101             'article)
5102            ;; Check the cache.
5103            ((and gnus-use-cache
5104                  (numberp article)
5105                  (gnus-cache-request-article article group))
5106             'article)
5107            ;; Check the agent cache.
5108            ((and gnus-agent gnus-agent-cache gnus-plugged
5109                  (numberp article)
5110                  (gnus-agent-request-article article group))
5111             'article)
5112            ;; Get the article and put into the article buffer.
5113            ((or (stringp article)
5114                 (numberp article))
5115             (let ((gnus-override-method gnus-override-method)
5116                   (methods (and (stringp article)
5117                                 gnus-refer-article-method))
5118                   (backend (car (gnus-find-method-for-group
5119                                  gnus-newsgroup-name)))
5120                   result
5121                   (buffer-read-only nil))
5122               (if (or (not (listp methods))
5123                       (and (symbolp (car methods))
5124                            (assq (car methods) nnoo-definition-alist)))
5125                   (setq methods (list methods)))
5126               (when (and (null gnus-override-method)
5127                          methods)
5128                 (setq gnus-override-method (pop methods)))
5129               (while (not result)
5130                 (when (eq gnus-override-method 'current)
5131                   (setq gnus-override-method
5132                         (with-current-buffer gnus-summary-buffer
5133                           gnus-current-select-method)))
5134                 (erase-buffer)
5135                 (gnus-kill-all-overlays)
5136                 (let ((gnus-newsgroup-name group))
5137                   (gnus-check-group-server))
5138                 (cond
5139                  ((gnus-request-article article group (current-buffer))
5140                   (when (numberp article)
5141                     (gnus-async-prefetch-next group article
5142                                               gnus-summary-buffer)
5143                     (when gnus-keep-backlog
5144                       (gnus-backlog-enter-article
5145                        group article (current-buffer))))
5146                   (setq result 'article))
5147                  (methods
5148                   (setq gnus-override-method (pop methods)))
5149                  ((not (string-match "^400 "
5150                                      (nnheader-get-report backend)))
5151                   ;; If we get 400 server disconnect, reconnect and
5152                   ;; retry; otherwise, assume the article has expired.
5153                   (setq result 'done))))
5154               (and (eq result 'article) 'article)))
5155            ;; It was a pseudo.
5156            (t article)))
5157
5158       ;; Associate this article with the current summary buffer.
5159       (setq gnus-article-current-summary gnus-summary-buffer)
5160
5161       ;; Take the article from the original article buffer
5162       ;; and place it in the buffer it's supposed to be in.
5163       (when (and (get-buffer gnus-article-buffer)
5164                  (equal (buffer-name (current-buffer))
5165                         (buffer-name (get-buffer gnus-article-buffer))))
5166         (save-excursion
5167           (if (get-buffer gnus-original-article-buffer)
5168               (set-buffer gnus-original-article-buffer)
5169             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5170             (buffer-disable-undo)
5171             (setq major-mode 'gnus-original-article-mode)
5172             (setq buffer-read-only t))
5173           (let (buffer-read-only)
5174             (erase-buffer)
5175             (insert-buffer-substring gnus-article-buffer))
5176           (setq gnus-original-article (cons group article)))
5177
5178         ;; Decode charsets.
5179         (run-hooks 'gnus-article-decode-hook)
5180         ;; Mark article as decoded or not.
5181         (setq gnus-article-decoded-p gnus-article-decode-hook))
5182
5183       ;; Update sparse articles.
5184       (when (and do-update-line
5185                  (or (numberp article)
5186                      (stringp article)))
5187         (let ((buf (current-buffer)))
5188           (set-buffer gnus-summary-buffer)
5189           (gnus-summary-update-article do-update-line sparse-header)
5190           (gnus-summary-goto-subject do-update-line nil t)
5191           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5192                             (point))
5193           (set-buffer buf))))))
5194
5195 ;;;
5196 ;;; Article editing
5197 ;;;
5198
5199 (defcustom gnus-article-edit-mode-hook nil
5200   "Hook run in article edit mode buffers."
5201   :group 'gnus-article-various
5202   :type 'hook)
5203
5204 (defvar gnus-article-edit-done-function nil)
5205
5206 (defvar gnus-article-edit-mode-map nil)
5207 (defvar gnus-article-edit-mode nil)
5208
5209 ;; Should we be using derived.el for this?
5210 (unless gnus-article-edit-mode-map
5211   (setq gnus-article-edit-mode-map (make-keymap))
5212   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5213
5214   (gnus-define-keys gnus-article-edit-mode-map
5215     "\C-c?"    describe-mode
5216     "\C-c\C-c" gnus-article-edit-done
5217     "\C-c\C-k" gnus-article-edit-exit
5218     "\C-c\C-f\C-t" message-goto-to
5219     "\C-c\C-f\C-o" message-goto-from
5220     "\C-c\C-f\C-b" message-goto-bcc
5221     ;;"\C-c\C-f\C-w" message-goto-fcc
5222     "\C-c\C-f\C-c" message-goto-cc
5223     "\C-c\C-f\C-s" message-goto-subject
5224     "\C-c\C-f\C-r" message-goto-reply-to
5225     "\C-c\C-f\C-n" message-goto-newsgroups
5226     "\C-c\C-f\C-d" message-goto-distribution
5227     "\C-c\C-f\C-f" message-goto-followup-to
5228     "\C-c\C-f\C-m" message-goto-mail-followup-to
5229     "\C-c\C-f\C-k" message-goto-keywords
5230     "\C-c\C-f\C-u" message-goto-summary
5231     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5232     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5233     "\C-c\C-b" message-goto-body
5234     "\C-c\C-i" message-goto-signature
5235
5236     "\C-c\C-t" message-insert-to
5237     "\C-c\C-n" message-insert-newsgroups
5238     "\C-c\C-o" message-sort-headers
5239     "\C-c\C-e" message-elide-region
5240     "\C-c\C-v" message-delete-not-region
5241     "\C-c\C-z" message-kill-to-signature
5242     "\M-\r" message-newline-and-reformat
5243     "\C-c\C-a" mml-attach-file
5244     "\C-a" message-beginning-of-line
5245     "\t" message-tab
5246     "\M-;" comment-region)
5247
5248   (gnus-define-keys (gnus-article-edit-wash-map
5249                      "\C-c\C-w" gnus-article-edit-mode-map)
5250     "f" gnus-article-edit-full-stops))
5251
5252 (easy-menu-define
5253   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5254   '("Field"
5255     ["Fetch To" message-insert-to t]
5256     ["Fetch Newsgroups" message-insert-newsgroups t]
5257     "----"
5258     ["To" message-goto-to t]
5259     ["From" message-goto-from t]
5260     ["Subject" message-goto-subject t]
5261     ["Cc" message-goto-cc t]
5262     ["Reply-To" message-goto-reply-to t]
5263     ["Summary" message-goto-summary t]
5264     ["Keywords" message-goto-keywords t]
5265     ["Newsgroups" message-goto-newsgroups t]
5266     ["Followup-To" message-goto-followup-to t]
5267     ["Mail-Followup-To" message-goto-mail-followup-to t]
5268     ["Distribution" message-goto-distribution t]
5269     ["Body" message-goto-body t]
5270     ["Signature" message-goto-signature t]))
5271
5272 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5273   "Major mode for editing articles.
5274 This is an extended text-mode.
5275
5276 \\{gnus-article-edit-mode-map}"
5277   (make-local-variable 'gnus-article-edit-done-function)
5278   (make-local-variable 'gnus-prev-winconf)
5279   (set (make-local-variable 'font-lock-defaults)
5280        '(message-font-lock-keywords t))
5281   (set (make-local-variable 'mail-header-separator) "")
5282   (set (make-local-variable 'gnus-article-edit-mode) t)
5283   (easy-menu-add message-mode-field-menu message-mode-map)
5284   (mml-mode)
5285   (setq buffer-read-only nil)
5286   (buffer-enable-undo)
5287   (widen))
5288
5289 (defun gnus-article-edit (&optional force)
5290   "Edit the current article.
5291 This will have permanent effect only in mail groups.
5292 If FORCE is non-nil, allow editing of articles even in read-only
5293 groups."
5294   (interactive "P")
5295   (when (and (not force)
5296              (gnus-group-read-only-p))
5297     (error "The current newsgroup does not support article editing"))
5298   (gnus-article-date-original)
5299   (gnus-article-edit-article
5300    'ignore
5301    `(lambda (no-highlight)
5302       'ignore
5303       (gnus-summary-edit-article-done
5304        ,(or (mail-header-references gnus-current-headers) "")
5305        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5306
5307 (defun gnus-article-edit-article (start-func exit-func)
5308   "Start editing the contents of the current article buffer."
5309   (let ((winconf (current-window-configuration)))
5310     (set-buffer gnus-article-buffer)
5311     (gnus-article-edit-mode)
5312     (funcall start-func)
5313     (set-buffer-modified-p nil)
5314     (gnus-configure-windows 'edit-article)
5315     (setq gnus-article-edit-done-function exit-func)
5316     (setq gnus-prev-winconf winconf)
5317     (gnus-message 6 "C-c C-c to end edits")))
5318
5319 (defun gnus-article-edit-done (&optional arg)
5320   "Update the article edits and exit."
5321   (interactive "P")
5322   (let ((func gnus-article-edit-done-function)
5323         (buf (current-buffer))
5324         (start (window-start))
5325         (p (point))
5326         (winconf gnus-prev-winconf))
5327     (widen) ;; Widen it in case that users narrowed the buffer.
5328     (funcall func arg)
5329     (set-buffer buf)
5330     ;; The cache and backlog have to be flushed somewhat.
5331     (when gnus-keep-backlog
5332       (gnus-backlog-remove-article
5333        (car gnus-article-current) (cdr gnus-article-current)))
5334     ;; Flush original article as well.
5335     (save-excursion
5336       (when (get-buffer gnus-original-article-buffer)
5337         (set-buffer gnus-original-article-buffer)
5338         (setq gnus-original-article nil)))
5339     (when gnus-use-cache
5340       (gnus-cache-update-article
5341        (car gnus-article-current) (cdr gnus-article-current)))
5342     ;; We remove all text props from the article buffer.
5343     (kill-all-local-variables)
5344     (gnus-set-text-properties (point-min) (point-max) nil)
5345     (gnus-article-mode)
5346     (set-window-configuration winconf)
5347     (set-buffer buf)
5348     (set-window-start (get-buffer-window buf) start)
5349     (set-window-point (get-buffer-window buf) (point))))
5350
5351 (defun gnus-article-edit-exit ()
5352   "Exit the article editing without updating."
5353   (interactive)
5354   (when (or (not (buffer-modified-p))
5355             (yes-or-no-p "Article modified; kill anyway? "))
5356     (let ((curbuf (current-buffer))
5357           (p (point))
5358           (window-start (window-start)))
5359       (erase-buffer)
5360       (if (gnus-buffer-live-p gnus-original-article-buffer)
5361           (insert-buffer gnus-original-article-buffer))
5362       (let ((winconf gnus-prev-winconf))
5363         (kill-all-local-variables)
5364         (gnus-article-mode)
5365         (set-window-configuration winconf)
5366         ;; Tippy-toe some to make sure that point remains where it was.
5367         (save-current-buffer
5368           (set-buffer curbuf)
5369           (set-window-start (get-buffer-window (current-buffer)) window-start)
5370           (goto-char p))))))
5371
5372 (defun gnus-article-edit-full-stops ()
5373   "Interactively repair spacing at end of sentences."
5374   (interactive)
5375   (save-excursion
5376     (goto-char (point-min))
5377     (search-forward-regexp "^$" nil t)
5378     (let ((case-fold-search nil))
5379       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5380
5381 ;;;
5382 ;;; Article highlights
5383 ;;;
5384
5385 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5386
5387 ;;; Internal Variables:
5388
5389 (defcustom gnus-button-url-regexp
5390   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5391       "\\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:]]\\)"
5392     "\\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\\)\\)")
5393   "Regular expression that matches URLs."
5394   :group 'gnus-article-buttons
5395   :type 'regexp)
5396
5397 (defcustom gnus-button-valid-fqdn-regexp
5398   (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
5399           ;; valid TLDs:
5400           "\\([a-z][a-z]" ;; two letter country TDLs
5401           "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
5402           "\\|aero\\|coop\\|info\\|name\\|museum"
5403           "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
5404           "\\)")
5405   "Regular expression that matches a valid FQDN."
5406   :group 'gnus-article-buttons
5407   :type 'regexp)
5408
5409 (defcustom gnus-button-man-handler 'manual-entry
5410   "Function to use for displaying man pages.
5411 The function must take at least one argument with a string naming the
5412 man page."
5413   :type '(choice (function-item :tag "Man" manual-entry)
5414                  (function-item :tag "Woman" woman)
5415                  (function :tag "Other"))
5416   :group 'gnus-article-buttons)
5417
5418 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5419   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5420 If the default site is too slow, try to find a CTAN mirror, see
5421 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
5422 the variable `gnus-button-handle-ctan'."
5423   :group 'gnus-article-buttons
5424   :link '(custom-manual "(gnus)Group Parameters")
5425   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5426                  (const "http://tug.ctan.org/tex-archive/")
5427                  (const "http://www.dante.de/CTAN/")
5428                  (string :tag "Other")))
5429
5430 (defcustom gnus-button-ctan-handler 'browse-url
5431   "Function to use for displaying CTAN links.
5432 The function must take one argument, the string naming the URL."
5433   :type '(choice (function-item :tag "Browse Url" browse-url)
5434                  (function :tag "Other"))
5435   :group 'gnus-article-buttons)
5436
5437 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5438   "Bogus strings removed from CTAN URLs."
5439   :group 'gnus-article-buttons
5440   :type '(choice (const "^/?tex-archive/\\|/")
5441                  (regexp :tag "Other")))
5442
5443 (defcustom gnus-button-mid-or-mail-regexp
5444   (concat "\\b\\(<?[a-z0-9][^<>\")!;:,{}\n\t ]*@"
5445           gnus-button-valid-fqdn-regexp
5446           ">?\\)\\b")
5447   "Regular expression that matches a message ID or a mail address."
5448   :group 'gnus-article-buttons
5449   :type 'regexp)
5450
5451 (defcustom gnus-button-prefer-mid-or-mail 'guess
5452   "What to do when the button on a string as \"foo123@bar.com\" is pushed.
5453 Strings like this can be either a message ID or a mail address.  If the
5454 variable is set to the symbol `ask', query the user what do do.  If it is the
5455 symbol `guess', Gnus will do a guess and query the user what do do if it is
5456 ambiguous.  See the variable `gnus-button-guessed-mid-regexp' for details
5457 concerning the guessing.  If it is one of the sybols `mid' or `mail', Gnus
5458 will always assume that the string is a message ID or a mail address,
5459 respectivly."
5460   ;; FIXME: doc-string could/should be improved.
5461   :group 'gnus-article-buttons
5462   :type '(choice (const ask)
5463                  (const guess)
5464                  (const mid)
5465                  (const mail)))
5466
5467 (defcustom gnus-button-guessed-mid-regexp
5468   (concat
5469    "^<?\\(slrn\\|Pine\\.\\)"
5470    "\\|\\.fsf@\\|\\.fsf_-_@\\|\\.ln@"
5471    "\\|@4ax\\.com\\|@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de"
5472           "\\|^<?.*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*@")
5473   "Regular expression that matches message IDs and not mail addresses."
5474   ;; TODO: Incorporate more matches from
5475   ;; <URL:http://piology.org/perl/id-or-mail.pl.html>. I.e. translate the
5476   ;; Perl-REs to Elisp-REs.
5477   :group 'gnus-article-buttons
5478   :type 'regexp)
5479
5480 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5481   (let* ((pref gnus-button-prefer-mid-or-mail)
5482          (url-mid (concat "news" ":" mid-or-mail))
5483          (url-mailto (concat "mailto" ":" mid-or-mail)))
5484     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5485     ;; If it looks like a MID (well known readers or servers) use 'mid,
5486     ;; otherwise 'ask the user.
5487     (if (eq pref 'guess)
5488         (if (string-match gnus-button-guessed-mid-regexp mid-or-mail)
5489             (setq pref 'mid)
5490           (setq pref 'ask)))
5491     (if (eq pref 'ask)
5492         (save-window-excursion
5493           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
5494               (setq pref 'mail)
5495             (setq pref 'mid))))
5496     (cond ((eq pref 'mid)
5497            (gnus-message 9 "calling `gnus-button-handle-news' %s" url-mid)
5498            (gnus-button-handle-news url-mid))
5499           ((eq pref 'mail)
5500            (gnus-message 9 "calling `gnus-url-mailto'  %s" url-mailto)
5501            (gnus-url-mailto url-mailto)))))
5502
5503 (defun gnus-button-handle-custom (url)
5504   "Follow a Custom URL."
5505   (customize-apropos (gnus-url-unhex-string url)))
5506
5507 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
5508
5509 (defun gnus-button-handle-describe-function (url)
5510   "Call describe-function when pushing the corresponding URL button."
5511   (describe-function
5512    (intern
5513     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5514
5515 (defun gnus-button-handle-describe-variable (url)
5516   "Call describe-variable when pushing the corresponding URL button."
5517   (describe-variable
5518    (intern
5519     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5520
5521 ;; FIXME: Is is possible to implement this?  Else it should be removed here
5522 ;; and in `gnus-button-alist'.
5523 (defun gnus-button-handle-describe-key (url)
5524   "Call describe-key when pushing the corresponding URL button."
5525   (error "not implemented"))
5526
5527 (defun gnus-button-handle-apropos (url)
5528   "Call apropos when pushing the corresponding URL button."
5529   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5530
5531 (defun gnus-button-handle-apropos-command (url)
5532   "Call apropos when pushing the corresponding URL button."
5533   (apropos-command
5534    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5535
5536 (defun gnus-button-handle-apropos-variable (url)
5537   "Call apropos when pushing the corresponding URL button."
5538   (funcall
5539    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
5540    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5541
5542 (defun gnus-button-handle-apropos-documentation (url)
5543   "Call apropos when pushing the corresponding URL button."
5544   (funcall
5545    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
5546    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5547
5548 (defun gnus-button-handle-ctan (url)
5549   "Call `browse-url' when pushing a CTAN URL button."
5550   (funcall
5551    gnus-button-ctan-handler
5552    (concat
5553     gnus-ctan-url
5554     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
5555
5556 (defcustom gnus-button-tex-level 5
5557   "*Integer that says how many TeX-related buttons Gnus will show.
5558 The higher the number, the more buttons will appear and the more false
5559 positives are possible.  Note that you can set this variable local to
5560 specifific groups.  Setting it higher in TeX groups is probably a good idea.
5561 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5562 how to set variables in specific groups."
5563   :group 'gnus-article-buttons
5564   :link '(custom-manual "(gnus)Group Parameters")
5565   :type 'integer)
5566
5567 (defcustom gnus-button-man-level 5
5568   "*Integer that says how many man-related buttons Gnus will show.
5569 The higher the number, the more buttons will appear and the more false
5570 positives are possible.  Note that you can set this variable local to
5571 specifific groups.  Setting it higher in Unix groups is probably a good idea.
5572 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5573 how to set variables in specific groups."
5574   :group 'gnus-article-buttons
5575   :link '(custom-manual "(gnus)Group Parameters")
5576   :type 'integer)
5577
5578 (defcustom gnus-button-emacs-level 5
5579   "*Integer that says how many emacs-related buttons Gnus will show.
5580 The higher the number, the more buttons will appear and the more false
5581 positives are possible.  Note that you can set this variable local to
5582 specifific groups.  Setting it higher in Emacs or Gnus related groups is
5583 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
5584 `gnus-parameters' on how to set variables in specific groups."
5585   :group 'gnus-article-buttons
5586   :link '(custom-manual "(gnus)Group Parameters")
5587   :type 'integer)
5588
5589 (defcustom gnus-button-mail-level 5
5590   "*Integer that says how many buttons for message IDs or mail addresses will appear.
5591 The higher the number, the more buttons will appear and the more false
5592 positives are possible."
5593   :group 'gnus-article-buttons
5594   :type 'integer)
5595
5596 (defcustom gnus-button-alist
5597   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5598      0 t gnus-button-handle-news 3)
5599     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5600      gnus-button-handle-news 2)
5601     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5602      1 t
5603      gnus-button-fetch-group 4)
5604     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5605     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5606      t gnus-button-message-id 3)
5607     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5608     ("mailto:\\([-a-z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5609     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5610     ;; CTAN
5611     ("\\bCTAN:[ \t\n]*\\([^>)!;:,\n\t ]*\\)" 0 (>= gnus-button-tex-level 1)
5612      gnus-button-handle-ctan 1)
5613     ;; This is info
5614     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
5615      (>= gnus-button-emacs-level 1) gnus-button-handle-info 2)
5616     ;; This is custom
5617     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
5618      (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
5619     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
5620      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
5621     ;; Emacs help commands
5622     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5623      ;; regexp doesn't match arguments containing ` '.
5624      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
5625     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5626      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
5627     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5628      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
5629     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5630      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
5631     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5632      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
5633     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
5634      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
5635     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+" 0
5636      ;; this regexp needs to be fixed!
5637      (>= gnus-button-emacs-level 9) gnus-button-handle-describe-key 2)
5638     ;; This is how URLs _should_ be embedded in text...
5639     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5640     ;; Raw URLs.
5641     (gnus-button-url-regexp 0 t browse-url 0)
5642     ;; man pages
5643     ("\\b\\([a-z][a-z]+\\)([1-9])\\W" 0
5644      (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
5645      gnus-button-handle-man 1)
5646     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
5647     ("\\b\\([a-z][-_.a-z0-9]+\\)([1-9])\\W" 0
5648      (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
5649      gnus-button-handle-man 1)
5650     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
5651     ;; SoWWWAnchor(3iv), XSelectInput(3X11)
5652     ("\\b\\([a-z][-_.:a-z0-9]+\\)([1-9][X1a-z]*)\\W" 0
5653      (>= gnus-button-man-level 5) gnus-button-handle-man 1)
5654     ;; MID or mail: To avoid too many false positives we don't try to catch
5655     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
5656     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
5657     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
5658     ;; so that non-ambiguous entries (see above) match first.
5659     (gnus-button-mid-or-mail-regexp
5660      0 (>= gnus-button-mail-level 5) gnus-button-handle-mid-or-mail 1))
5661   "*Alist of regexps matching buttons in article bodies.
5662
5663 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5664 REGEXP: is the string (case insensitive) matching text around the button (can
5665 also be lisp expression evaluating to a string),
5666 BUTTON: is the number of the regexp grouping actually matching the button,
5667 FORM: is a lisp expression which must eval to true for the button to
5668 be added,
5669 CALLBACK: is the function to call when the user push this button, and each
5670 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5671
5672 CALLBACK can also be a variable, in that case the value of that
5673 variable it the real callback function."
5674   :group 'gnus-article-buttons
5675   :type '(repeat (list (choice regexp variable)
5676                        (integer :tag "Button")
5677                        (sexp :tag "Form")
5678                        (function :tag "Callback")
5679                        (repeat :tag "Par"
5680                                :inline t
5681                                (integer :tag "Regexp group")))))
5682
5683 (defcustom gnus-header-button-alist
5684   '(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5685      0 t gnus-button-message-id 0)
5686     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5687     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5688      0 t gnus-button-mailto 0)
5689     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp 0 t browse-url 0)
5690     ("^Subject:" gnus-button-url-regexp 0 t browse-url 0)
5691     ("^[^:]+:" gnus-button-url-regexp 0 t browse-url 0)
5692     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5693     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5694      gnus-button-message-id 3))
5695   "*Alist of headers and regexps to match buttons in article heads.
5696
5697 This alist is very similar to `gnus-button-alist', except that each
5698 alist has an additional HEADER element first in each entry:
5699
5700 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5701
5702 HEADER is a regexp to match a header.  For a fuller explanation, see
5703 `gnus-button-alist'."
5704   :group 'gnus-article-buttons
5705   :group 'gnus-article-headers
5706   :type '(repeat (list (regexp :tag "Header")
5707                        regexp
5708                        (integer :tag "Button")
5709                        (sexp :tag "Form")
5710                        (function :tag "Callback")
5711                        (repeat :tag "Par"
5712                                :inline t
5713                                (integer :tag "Regexp group")))))
5714
5715 (defvar gnus-button-regexp nil)
5716 (defvar gnus-button-marker-list nil)
5717 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5718
5719 (defvar gnus-button-last nil)
5720 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5721
5722 ;;; Commands:
5723
5724 (defun gnus-article-push-button (event)
5725   "Check text under the mouse pointer for a callback function.
5726 If the text under the mouse pointer has a `gnus-callback' property,
5727 call it with the value of the `gnus-data' text property."
5728   (interactive "e")
5729   (set-buffer (window-buffer (posn-window (event-start event))))
5730   (let* ((pos (posn-point (event-start event)))
5731          (data (get-text-property pos 'gnus-data))
5732          (fun (get-text-property pos 'gnus-callback)))
5733     (goto-char pos)
5734     (when fun
5735       (funcall fun data))))
5736
5737 (defun gnus-article-press-button ()
5738   "Check text at point for a callback function.
5739 If the text at point has a `gnus-callback' property,
5740 call it with the value of the `gnus-data' text property."
5741   (interactive)
5742   (let ((data (get-text-property (point) 'gnus-data))
5743         (fun (get-text-property (point) 'gnus-callback)))
5744     (when fun
5745       (funcall fun data))))
5746
5747 (defun gnus-article-highlight (&optional force)
5748   "Highlight current article.
5749 This function calls `gnus-article-highlight-headers',
5750 `gnus-article-highlight-citation',
5751 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5752 do the highlighting.  See the documentation for those functions."
5753   (interactive (list 'force))
5754   (gnus-article-highlight-headers)
5755   (gnus-article-highlight-citation force)
5756   (gnus-article-highlight-signature)
5757   (gnus-article-add-buttons force)
5758   (gnus-article-add-buttons-to-head))
5759
5760 (defun gnus-article-highlight-some (&optional force)
5761   "Highlight current article.
5762 This function calls `gnus-article-highlight-headers',
5763 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5764 do the highlighting.  See the documentation for those functions."
5765   (interactive (list 'force))
5766   (gnus-article-highlight-headers)
5767   (gnus-article-highlight-signature)
5768   (gnus-article-add-buttons))
5769
5770 (defun gnus-article-highlight-headers ()
5771   "Highlight article headers as specified by `gnus-header-face-alist'."
5772   (interactive)
5773   (save-excursion
5774     (set-buffer gnus-article-buffer)
5775     (save-restriction
5776       (let ((alist gnus-header-face-alist)
5777             (buffer-read-only nil)
5778             (case-fold-search t)
5779             (inhibit-point-motion-hooks t)
5780             entry regexp header-face field-face from hpoints fpoints)
5781         (article-narrow-to-head)
5782         (while (setq entry (pop alist))
5783           (goto-char (point-min))
5784           (setq regexp (concat "^\\("
5785                                (if (string-equal "" (nth 0 entry))
5786                                    "[^\t ]"
5787                                  (nth 0 entry))
5788                                "\\)")
5789                 header-face (nth 1 entry)
5790                 field-face (nth 2 entry))
5791           (while (and (re-search-forward regexp nil t)
5792                       (not (eobp)))
5793             (beginning-of-line)
5794             (setq from (point))
5795             (unless (search-forward ":" nil t)
5796               (forward-char 1))
5797             (when (and header-face
5798                        (not (memq (point) hpoints)))
5799               (push (point) hpoints)
5800               (gnus-put-text-property from (point) 'face header-face))
5801             (when (and field-face
5802                        (not (memq (setq from (point)) fpoints)))
5803               (push from fpoints)
5804               (if (re-search-forward "^[^ \t]" nil t)
5805                   (forward-char -2)
5806                 (goto-char (point-max)))
5807               (gnus-put-text-property from (point) 'face field-face))))))))
5808
5809 (defun gnus-article-highlight-signature ()
5810   "Highlight the signature in an article.
5811 It does this by highlighting everything after
5812 `gnus-signature-separator' using `gnus-signature-face'."
5813   (interactive)
5814   (save-excursion
5815     (set-buffer gnus-article-buffer)
5816     (let ((buffer-read-only nil)
5817           (inhibit-point-motion-hooks t))
5818       (save-restriction
5819         (when (and gnus-signature-face
5820                    (gnus-article-narrow-to-signature))
5821           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5822                             'face gnus-signature-face)
5823           (widen)
5824           (gnus-article-search-signature)
5825           (let ((start (match-beginning 0))
5826                 (end (set-marker (make-marker) (1+ (match-end 0)))))
5827             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5828                                      end)))))))
5829
5830 (defun gnus-button-in-region-p (b e prop)
5831   "Say whether PROP exists in the region."
5832   (text-property-not-all b e prop nil))
5833
5834 (defun gnus-article-add-buttons (&optional force)
5835   "Find external references in the article and make buttons of them.
5836 \"External references\" are things like Message-IDs and URLs, as
5837 specified by `gnus-button-alist'."
5838   (interactive (list 'force))
5839   (save-excursion
5840     (set-buffer gnus-article-buffer)
5841     (let ((buffer-read-only nil)
5842           (inhibit-point-motion-hooks t)
5843           (case-fold-search t)
5844           (alist gnus-button-alist)
5845           beg entry regexp)
5846       ;; Remove all old markers.
5847       (let (marker entry new-list)
5848         (while (setq marker (pop gnus-button-marker-list))
5849           (if (or (< marker (point-min)) (>= marker (point-max)))
5850               (push marker new-list)
5851             (goto-char marker)
5852             (when (setq entry (gnus-button-entry))
5853               (put-text-property (match-beginning (nth 1 entry))
5854                                  (match-end (nth 1 entry))
5855                                  'gnus-callback nil))
5856             (set-marker marker nil)))
5857         (setq gnus-button-marker-list new-list))
5858       ;; We skip the headers.
5859       (article-goto-body)
5860       (setq beg (point))
5861       (while (setq entry (pop alist))
5862         (setq regexp (eval (car entry)))
5863         (goto-char beg)
5864         (while (re-search-forward regexp nil t)
5865           (let* ((start (and entry (match-beginning (nth 1 entry))))
5866                  (end (and entry (match-end (nth 1 entry))))
5867                  (from (match-beginning 0)))
5868             (when (and (or (eq t (nth 2 entry))
5869                            (eval (nth 2 entry)))
5870                        (not (gnus-button-in-region-p
5871                              start end 'gnus-callback)))
5872               ;; That optional form returned non-nil, so we add the
5873               ;; button.
5874               (gnus-article-add-button
5875                start end 'gnus-button-push
5876                (car (push (set-marker (make-marker) from)
5877                           gnus-button-marker-list))))))))))
5878
5879 ;; Add buttons to the head of an article.
5880 (defun gnus-article-add-buttons-to-head ()
5881   "Add buttons to the head of the article."
5882   (interactive)
5883   (save-excursion
5884     (set-buffer gnus-article-buffer)
5885     (save-restriction
5886       (let ((buffer-read-only nil)
5887             (inhibit-point-motion-hooks t)
5888             (case-fold-search t)
5889             (alist gnus-header-button-alist)
5890             entry beg end)
5891         (article-narrow-to-head)
5892         (while alist
5893           ;; Each alist entry.
5894           (setq entry (car alist)
5895                 alist (cdr alist))
5896           (goto-char (point-min))
5897           (while (re-search-forward (car entry) nil t)
5898             ;; Each header matching the entry.
5899             (setq beg (match-beginning 0))
5900             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5901                                (match-beginning 0))
5902                           (point-max)))
5903             (goto-char beg)
5904             (while (re-search-forward (eval (nth 1 entry)) end t)
5905               ;; Each match within a header.
5906               (let* ((entry (cdr entry))
5907                      (start (match-beginning (nth 1 entry)))
5908                      (end (match-end (nth 1 entry)))
5909                      (form (nth 2 entry)))
5910                 (goto-char (match-end 0))
5911                 (when (eval form)
5912                   (gnus-article-add-button
5913                    start end (nth 3 entry)
5914                    (buffer-substring (match-beginning (nth 4 entry))
5915                                      (match-end (nth 4 entry)))))))
5916             (goto-char end)))))))
5917
5918 ;;; External functions:
5919
5920 (defun gnus-article-add-button (from to fun &optional data)
5921   "Create a button between FROM and TO with callback FUN and data DATA."
5922   (when gnus-article-button-face
5923     (gnus-overlay-put (gnus-make-overlay from to)
5924                       'face gnus-article-button-face))
5925   (gnus-add-text-properties
5926    from to
5927    (nconc (and gnus-article-mouse-face
5928                (list gnus-mouse-face-prop gnus-article-mouse-face))
5929           (list 'gnus-callback fun)
5930           (and data (list 'gnus-data data))))
5931   (widget-convert-button 'link from to :action 'gnus-widget-press-button
5932                          :button-keymap gnus-widget-button-keymap))
5933
5934 ;;; Internal functions:
5935
5936 (defun gnus-article-set-globals ()
5937   (save-excursion
5938     (set-buffer gnus-summary-buffer)
5939     (gnus-set-global-variables)))
5940
5941 (defun gnus-signature-toggle (end)
5942   (save-excursion
5943     (set-buffer gnus-article-buffer)
5944     (let ((buffer-read-only nil)
5945           (inhibit-point-motion-hooks t))
5946       (if (text-property-any end (point-max) 'article-type 'signature)
5947           (progn
5948             (gnus-delete-wash-type 'signature)
5949             (gnus-remove-text-properties-when
5950              'article-type 'signature end (point-max)
5951              (cons 'article-type (cons 'signature
5952                                        gnus-hidden-properties))))
5953         (gnus-add-wash-type 'signature)
5954         (gnus-add-text-properties-when
5955          'article-type nil end (point-max)
5956          (cons 'article-type (cons 'signature
5957                                    gnus-hidden-properties)))))
5958     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5959       (gnus-set-mode-line 'article))))
5960
5961 (defun gnus-button-entry ()
5962   ;; Return the first entry in `gnus-button-alist' matching this place.
5963   (let ((alist gnus-button-alist)
5964         (entry nil))
5965     (while alist
5966       (setq entry (pop alist))
5967       (if (looking-at (eval (car entry)))
5968           (setq alist nil)
5969         (setq entry nil)))
5970     entry))
5971
5972 (defun gnus-button-push (marker)
5973   ;; Push button starting at MARKER.
5974   (save-excursion
5975     (goto-char marker)
5976     (let* ((entry (gnus-button-entry))
5977            (inhibit-point-motion-hooks t)
5978            (fun (nth 3 entry))
5979            (args (mapcar (lambda (group)
5980                            (let ((string (match-string group)))
5981                              (gnus-set-text-properties
5982                               0 (length string) nil string)
5983                              string))
5984                          (nthcdr 4 entry))))
5985       (cond
5986        ((fboundp fun)
5987         (apply fun args))
5988        ((and (boundp fun)
5989              (fboundp (symbol-value fun)))
5990         (apply (symbol-value fun) args))
5991        (t
5992         (gnus-message 1 "You must define `%S' to use this button"
5993                       (cons fun args)))))))
5994
5995 (defun gnus-parse-news-url (url)
5996   (let (scheme server group message-id articles)
5997     (with-temp-buffer
5998       (insert url)
5999       (goto-char (point-min))
6000       (when (looking-at "\\([A-Za-z]+\\):")
6001         (setq scheme (match-string 1))
6002         (goto-char (match-end 0)))
6003       (when (looking-at "//\\([^/]+\\)/")
6004         (setq server (match-string 1))
6005         (goto-char (match-end 0)))
6006
6007       (cond
6008        ((looking-at "\\(.*@.*\\)")
6009         (setq message-id (match-string 1)))
6010        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6011         (setq group (match-string 1)
6012               articles (split-string (match-string 2) "-")))
6013        ((looking-at "\\([^/]+\\)/?")
6014         (setq group (match-string 1)))
6015        (t
6016         (error "Unknown news URL syntax"))))
6017     (list scheme server group message-id articles)))
6018
6019 (defun gnus-button-handle-news (url)
6020   "Fetch a news URL."
6021   (destructuring-bind (scheme server group message-id articles)
6022       (gnus-parse-news-url url)
6023     (cond
6024      (message-id
6025       (save-excursion
6026         (set-buffer gnus-summary-buffer)
6027         (if server
6028             (let ((gnus-refer-article-method (list (list 'nntp server))))
6029               (gnus-summary-refer-article message-id))
6030           (gnus-summary-refer-article message-id))))
6031      (group
6032       (gnus-button-fetch-group url)))))
6033
6034 (defun gnus-button-handle-man (url)
6035   "Fetch a man page."
6036   (funcall gnus-button-man-handler url))
6037
6038 (defun gnus-button-handle-info (url)
6039   "Fetch an info URL."
6040   (if (string-match
6041        "^\\([^:/]+\\)?/\\(.*\\)"
6042        url)
6043       (gnus-info-find-node
6044        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6045                        "Gnus")
6046                ")"
6047                (gnus-url-unhex-string (match-string 2 url))))
6048     (error "Can't parse %s" url)))
6049
6050 (defun gnus-button-message-id (message-id)
6051   "Fetch MESSAGE-ID."
6052   (save-excursion
6053     (set-buffer gnus-summary-buffer)
6054     (gnus-summary-refer-article message-id)))
6055
6056 (defun gnus-button-fetch-group (address)
6057   "Fetch GROUP specified by ADDRESS."
6058   (if (not (string-match "[:/]" address))
6059       ;; This is just a simple group url.
6060       (gnus-group-read-ephemeral-group address gnus-select-method)
6061     (if (not
6062          (string-match
6063           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6064           address))
6065         (error "Can't parse %s" address)
6066       (gnus-group-read-ephemeral-group
6067        (match-string 4 address)
6068        `(nntp ,(match-string 1 address)
6069               (nntp-address ,(match-string 1 address))
6070               (nntp-port-number ,(if (match-end 3)
6071                                      (match-string 3 address)
6072                                    "nntp")))
6073        nil nil nil
6074        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6075
6076 (defun gnus-url-parse-query-string (query &optional downcase)
6077   (let (retval pairs cur key val)
6078     (setq pairs (split-string query "&"))
6079     (while pairs
6080       (setq cur (car pairs)
6081             pairs (cdr pairs))
6082       (if (not (string-match "=" cur))
6083           nil                           ; Grace
6084         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6085               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6086         (if downcase
6087             (setq key (downcase key)))
6088         (setq cur (assoc key retval))
6089         (if cur
6090             (setcdr cur (cons val (cdr cur)))
6091           (setq retval (cons (list key val) retval)))))
6092     retval))
6093
6094 (defun gnus-url-mailto (url)
6095   ;; Send mail to someone
6096   (when (string-match "mailto:/*\\(.*\\)" url)
6097     (setq url (substring url (match-beginning 1) nil)))
6098   (let (to args subject func)
6099     (if (string-match (regexp-quote "?") url)
6100         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6101               args (gnus-url-parse-query-string
6102                     (substring url (match-end 0) nil) t))
6103       (setq to (gnus-url-unhex-string url)))
6104     (setq args (cons (list "to" to) args)
6105           subject (cdr-safe (assoc "subject" args)))
6106     (gnus-msg-mail)
6107     (while args
6108       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6109       (if (fboundp func)
6110           (funcall func)
6111         (message-position-on-field (caar args)))
6112       (insert (mapconcat 'identity (cdar args) ", "))
6113       (setq args (cdr args)))
6114     (if subject
6115         (message-goto-body)
6116       (message-goto-subject))))
6117
6118 (defun gnus-button-embedded-url (address)
6119   "Activate ADDRESS with `browse-url'."
6120   (browse-url (gnus-strip-whitespace address)))
6121
6122 ;;; Next/prev buttons in the article buffer.
6123
6124 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6125 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6126
6127 (defvar gnus-prev-page-map
6128   (let ((map (make-sparse-keymap)))
6129     (unless (>= emacs-major-version 21)
6130       ;; XEmacs doesn't care.
6131       (set-keymap-parent map gnus-article-mode-map))
6132     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6133     (define-key map "\r" 'gnus-button-prev-page)
6134     map))
6135
6136 (defun gnus-insert-prev-page-button ()
6137   (let ((b (point))
6138         (buffer-read-only nil))
6139     (gnus-eval-format
6140      gnus-prev-page-line-format nil
6141      `(,@(gnus-local-map-property gnus-prev-page-map)
6142          gnus-prev t
6143          gnus-callback gnus-article-button-prev-page
6144          article-type annotation))
6145     (widget-convert-button
6146      'link b (point)
6147      :action 'gnus-button-prev-page
6148      :button-keymap gnus-prev-page-map)))
6149
6150 (defvar gnus-prev-page-map
6151   (let ((map (make-sparse-keymap)))
6152     (unless (>= emacs-major-version 21)
6153       ;; XEmacs doesn't care.
6154       (set-keymap-parent map gnus-article-mode-map))
6155     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6156     (define-key map "\r" 'gnus-button-prev-page)
6157     map))
6158
6159 (defvar gnus-next-page-map
6160   (let ((map (make-sparse-keymap)))
6161     (unless (>= emacs-major-version 21)
6162       ;; XEmacs doesn't care.
6163       (set-keymap-parent map gnus-article-mode-map))
6164     (define-key map gnus-mouse-2 'gnus-button-next-page)
6165     (define-key map "\r" 'gnus-button-next-page)
6166     map))
6167
6168 (defun gnus-button-next-page (&optional args more-args)
6169   "Go to the next page."
6170   (interactive)
6171   (let ((win (selected-window)))
6172     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6173     (gnus-article-next-page)
6174     (select-window win)))
6175
6176 (defun gnus-button-prev-page (&optional args more-args)
6177   "Go to the prev page."
6178   (interactive)
6179   (let ((win (selected-window)))
6180     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6181     (gnus-article-prev-page)
6182     (select-window win)))
6183
6184 (defun gnus-insert-next-page-button ()
6185   (let ((b (point))
6186         (buffer-read-only nil))
6187     (gnus-eval-format gnus-next-page-line-format nil
6188                       `(,@(gnus-local-map-property gnus-next-page-map)
6189                           gnus-next t
6190                           gnus-callback gnus-article-button-next-page
6191                           article-type annotation))
6192     (widget-convert-button
6193      'link b (point)
6194      :action 'gnus-button-next-page
6195      :button-keymap gnus-next-page-map)))
6196
6197 (defun gnus-article-button-next-page (arg)
6198   "Go to the next page."
6199   (interactive "P")
6200   (let ((win (selected-window)))
6201     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6202     (gnus-article-next-page)
6203     (select-window win)))
6204
6205 (defun gnus-article-button-prev-page (arg)
6206   "Go to the prev page."
6207   (interactive "P")
6208   (let ((win (selected-window)))
6209     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6210     (gnus-article-prev-page)
6211     (select-window win)))
6212
6213 (defvar gnus-decode-header-methods
6214   '(mail-decode-encoded-word-region)
6215   "List of methods used to decode headers.
6216
6217 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6218 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6219 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6220 whose names match REGEXP.
6221
6222 For example:
6223 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6224  mail-decode-encoded-word-region
6225  (\"chinese\" . rfc1843-decode-region))
6226 ")
6227
6228 (defvar gnus-decode-header-methods-cache nil)
6229
6230 (defun gnus-multi-decode-header (start end)
6231   "Apply the functions from `gnus-encoded-word-methods' that match."
6232   (unless (and gnus-decode-header-methods-cache
6233                (eq gnus-newsgroup-name
6234                    (car gnus-decode-header-methods-cache)))
6235     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6236     (mapcar (lambda (x)
6237               (if (symbolp x)
6238                   (nconc gnus-decode-header-methods-cache (list x))
6239                 (if (and gnus-newsgroup-name
6240                          (string-match (car x) gnus-newsgroup-name))
6241                     (nconc gnus-decode-header-methods-cache
6242                            (list (cdr x))))))
6243           gnus-decode-header-methods))
6244   (let ((xlist gnus-decode-header-methods-cache))
6245     (pop xlist)
6246     (save-restriction
6247       (narrow-to-region start end)
6248       (while xlist
6249         (funcall (pop xlist) (point-min) (point-max))))))
6250
6251 ;;;
6252 ;;; Treatment top-level handling.
6253 ;;;
6254
6255 (defun gnus-treat-article (condition &optional part-number total-parts type)
6256   (let ((length (- (point-max) (point-min)))
6257         (alist gnus-treatment-function-alist)
6258         (article-goto-body-goes-to-point-min-p t)
6259         (treated-type
6260          (or (not type)
6261              (catch 'found
6262                (let ((list gnus-article-treat-types))
6263                  (while list
6264                    (when (string-match (pop list) type)
6265                      (throw 'found t)))))))
6266         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6267         val elem)
6268     (gnus-run-hooks 'gnus-part-display-hook)
6269     (dolist (elem alist)
6270       (setq val
6271             (save-excursion
6272               (when (gnus-buffer-live-p gnus-summary-buffer)
6273                 (set-buffer gnus-summary-buffer))
6274               (symbol-value (car elem))))
6275       (when (and (or (consp val)
6276                      treated-type)
6277                  (gnus-treat-predicate val)
6278                  (or (not (get (car elem) 'highlight))
6279                      highlightp))
6280         (save-restriction
6281           (funcall (cadr elem)))))))
6282
6283 ;; Dynamic variables.
6284 (eval-when-compile
6285   (defvar part-number)
6286   (defvar total-parts)
6287   (defvar type)
6288   (defvar condition)
6289   (defvar length))
6290
6291 (defun gnus-treat-predicate (val)
6292   (cond
6293    ((null val)
6294     nil)
6295    (condition
6296     (eq condition val))
6297    ((and (listp val)
6298          (stringp (car val)))
6299     (apply 'gnus-or (mapcar `(lambda (s)
6300                                (string-match s ,(or gnus-newsgroup-name "")))
6301                             val)))
6302    ((listp val)
6303     (let ((pred (pop val)))
6304       (cond
6305        ((eq pred 'or)
6306         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6307        ((eq pred 'and)
6308         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6309        ((eq pred 'not)
6310         (not (gnus-treat-predicate (car val))))
6311        ((eq pred 'typep)
6312         (equal (car val) type))
6313        (t
6314         (error "%S is not a valid predicate" pred)))))
6315    ((eq val t)
6316     t)
6317    ((eq val 'head)
6318     nil)
6319    ((eq val 'last)
6320     (eq part-number total-parts))
6321    ((numberp val)
6322     (< length val))
6323    (t
6324     (error "%S is not a valid value" val))))
6325
6326 (defun gnus-article-encrypt-body (protocol &optional n)
6327   "Encrypt the article body."
6328   (interactive
6329    (list
6330     (or gnus-article-encrypt-protocol
6331         (completing-read "Encrypt protocol: "
6332                          gnus-article-encrypt-protocol-alist
6333                          nil t))
6334     current-prefix-arg))
6335   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6336     (unless func
6337       (error (format "Can't find the encrypt protocol %s" protocol)))
6338     (if (member gnus-newsgroup-name '("nndraft:delayed"
6339                                       "nndraft:drafts"
6340                                       "nndraft:queue"))
6341         (error "Can't encrypt the article in group %s"
6342                gnus-newsgroup-name))
6343     (gnus-summary-iterate n
6344       (save-excursion
6345         (set-buffer gnus-summary-buffer)
6346         (let ((mail-parse-charset gnus-newsgroup-charset)
6347               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6348               (summary-buffer gnus-summary-buffer)
6349               references point)
6350           (gnus-set-global-variables)
6351           (when (gnus-group-read-only-p)
6352             (error "The current newsgroup does not support article encrypt"))
6353           (gnus-summary-show-article t)
6354           (setq references
6355               (or (mail-header-references gnus-current-headers) ""))
6356           (set-buffer gnus-article-buffer)
6357           (let* ((buffer-read-only nil)
6358                  (headers
6359                   (mapcar (lambda (field)
6360                             (and (save-restriction
6361                                    (message-narrow-to-head)
6362                                    (goto-char (point-min))
6363                                    (search-forward field nil t))
6364                                  (prog2
6365                                      (message-narrow-to-field)
6366                                      (buffer-substring (point-min) (point-max))
6367                                    (delete-region (point-min) (point-max))
6368                                    (widen))))
6369                           '("Content-Type:" "Content-Transfer-Encoding:"
6370                             "Content-Disposition:"))))
6371             (message-narrow-to-head)
6372             (message-remove-header "MIME-Version")
6373             (goto-char (point-max))
6374             (setq point (point))
6375             (insert (apply 'concat headers))
6376             (widen)
6377             (narrow-to-region point (point-max))
6378             (let ((message-options message-options))
6379               (message-options-set 'message-sender user-mail-address)
6380               (message-options-set 'message-recipients user-mail-address)
6381               (message-options-set 'message-sign-encrypt 'not)
6382               (funcall func))
6383             (goto-char (point-min))
6384             (insert "MIME-Version: 1.0\n")
6385             (widen)
6386             (gnus-summary-edit-article-done
6387              references nil summary-buffer t))
6388           (when gnus-keep-backlog
6389             (gnus-backlog-remove-article
6390              (car gnus-article-current) (cdr gnus-article-current)))
6391           (save-excursion
6392             (when (get-buffer gnus-original-article-buffer)
6393               (set-buffer gnus-original-article-buffer)
6394               (setq gnus-original-article nil)))
6395           (when gnus-use-cache
6396             (gnus-cache-update-article
6397              (car gnus-article-current) (cdr gnus-article-current))))))))
6398
6399 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6400   "The following specs can be used:
6401 %t  The security MIME type
6402 %i  Additional info
6403 %d  Details
6404 %D  Details if button is pressed")
6405
6406 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6407   "The following specs can be used:
6408 %t  The security MIME type
6409 %i  Additional info
6410 %d  Details
6411 %D  Details if button is pressed")
6412
6413 (defvar gnus-mime-security-button-line-format-alist
6414   '((?t gnus-tmp-type ?s)
6415     (?i gnus-tmp-info ?s)
6416     (?d gnus-tmp-details ?s)
6417     (?D gnus-tmp-pressed-details ?s)))
6418
6419 (defvar gnus-mime-security-button-map
6420   (let ((map (make-sparse-keymap)))
6421     (unless (>= (string-to-number emacs-version) 21)
6422       (set-keymap-parent map gnus-article-mode-map))
6423     (define-key map gnus-mouse-2 'gnus-article-push-button)
6424     (define-key map "\r" 'gnus-article-press-button)
6425     map))
6426
6427 (defvar gnus-mime-security-details-buffer nil)
6428
6429 (defvar gnus-mime-security-button-pressed nil)
6430
6431 (defvar gnus-mime-security-show-details-inline t
6432   "If non-nil, show details in the article buffer.")
6433
6434 (defun gnus-mime-security-verify-or-decrypt (handle)
6435   (mm-remove-parts (cdr handle))
6436   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6437         point buffer-read-only)
6438     (if region
6439         (goto-char (car region)))
6440     (save-restriction
6441       (narrow-to-region (point) (point))
6442       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6443         (let* ((mm-verify-option 'known)
6444                (mm-decrypt-option 'known)
6445                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6446           (unless (eq nparts (cdr handle))
6447             (mm-destroy-parts (cdr handle))
6448             (setcdr handle nparts))))
6449       (setq point (point))
6450       (gnus-mime-display-security handle)
6451       (goto-char (point-max)))
6452     (when region
6453       (delete-region (point) (cdr region))
6454       (set-marker (car region) nil)
6455       (set-marker (cdr region) nil))
6456     (goto-char point)))
6457
6458 (defun gnus-mime-security-show-details (handle)
6459   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6460     (if (not details)
6461         (gnus-message 5 "No details.")
6462       (if gnus-mime-security-show-details-inline
6463           (let ((gnus-mime-security-button-pressed
6464                  (not (get-text-property (point) 'gnus-mime-details)))
6465                 (gnus-mime-security-button-line-format
6466                  (get-text-property (point) 'gnus-line-format))
6467                 buffer-read-only)
6468             (forward-char -1)
6469             (while (eq (get-text-property (point) 'gnus-line-format)
6470                        gnus-mime-security-button-line-format)
6471               (forward-char -1))
6472             (forward-char)
6473             (save-restriction
6474               (narrow-to-region (point) (point))
6475               (gnus-insert-mime-security-button handle))
6476             (delete-region (point)
6477                            (or (text-property-not-all
6478                                 (point) (point-max)
6479                                 'gnus-line-format
6480                                 gnus-mime-security-button-line-format)
6481                                (point-max))))
6482         ;; Not inlined.
6483         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6484             (with-current-buffer gnus-mime-security-details-buffer
6485               (erase-buffer)
6486               t)
6487           (setq gnus-mime-security-details-buffer
6488                 (gnus-get-buffer-create "*MIME Security Details*")))
6489         (with-current-buffer gnus-mime-security-details-buffer
6490           (insert details)
6491           (goto-char (point-min)))
6492         (pop-to-buffer gnus-mime-security-details-buffer)))))
6493
6494 (defun gnus-mime-security-press-button (handle)
6495   (save-excursion
6496     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6497         (gnus-mime-security-show-details handle)
6498       (gnus-mime-security-verify-or-decrypt handle))))
6499
6500 (defun gnus-insert-mime-security-button (handle &optional displayed)
6501   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6502          (gnus-tmp-type
6503           (concat
6504            (or (nth 2 (assoc protocol mm-verify-function-alist))
6505                (nth 2 (assoc protocol mm-decrypt-function-alist))
6506                "Unknown")
6507            (if (equal (car handle) "multipart/signed")
6508                " Signed" " Encrypted")
6509            " Part"))
6510          (gnus-tmp-info
6511           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6512               "Undecided"))
6513          (gnus-tmp-details
6514           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6515          gnus-tmp-pressed-details
6516          b e)
6517     (setq gnus-tmp-details
6518           (if gnus-tmp-details
6519               (concat "\n" gnus-tmp-details)
6520             ""))
6521     (setq gnus-tmp-pressed-details
6522           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6523     (unless (bolp)
6524       (insert "\n"))
6525     (setq b (point))
6526     (gnus-eval-format
6527      gnus-mime-security-button-line-format
6528      gnus-mime-security-button-line-format-alist
6529      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6530          gnus-callback gnus-mime-security-press-button
6531          gnus-line-format ,gnus-mime-security-button-line-format
6532          gnus-mime-details ,gnus-mime-security-button-pressed
6533          article-type annotation
6534          gnus-data ,handle))
6535     (setq e (point))
6536     (widget-convert-button
6537      'link b e
6538      :mime-handle handle
6539      :action 'gnus-widget-press-button
6540      :button-keymap gnus-mime-security-button-map
6541      :help-echo
6542      (lambda (widget/window &optional overlay pos)
6543        ;; Needed to properly clear the message due to a bug in
6544        ;; wid-edit (XEmacs only).
6545        (when (boundp 'help-echo-owns-message)
6546          (setq help-echo-owns-message t))
6547        (format
6548         "%S: show detail"
6549         (aref gnus-mouse-2 0))))))
6550
6551 (defun gnus-mime-display-security (handle)
6552   (save-restriction
6553     (narrow-to-region (point) (point))
6554     (unless (gnus-unbuttonized-mime-type-p (car handle))
6555       (gnus-insert-mime-security-button handle))
6556     (gnus-mime-display-mixed (cdr handle))
6557     (unless (bolp)
6558       (insert "\n"))
6559     (unless (gnus-unbuttonized-mime-type-p (car handle))
6560       (let ((gnus-mime-security-button-line-format
6561              gnus-mime-security-button-end-line-format))
6562         (gnus-insert-mime-security-button handle)))
6563     (mm-set-handle-multipart-parameter
6564      handle 'gnus-region
6565      (cons (set-marker (make-marker) (point-min))
6566            (set-marker (make-marker) (point-max))))))
6567
6568 (gnus-ems-redefine)
6569
6570 (provide 'gnus-art)
6571
6572 (run-hooks 'gnus-art-load-hook)
6573
6574 ;;; gnus-art.el ends here