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