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