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