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