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