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