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