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