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