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