0b723bcddd1b0640c887be43b0a38235ea8feb12
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-map)
33   (defvar w3m-minor-mode-map))
34
35 (require 'gnus)
36 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
37 (eval-and-compile
38   (let ((recursive-load-depth-limit 100))
39     (require 'gnus-sum)))
40 (require 'gnus-spec)
41 (require 'gnus-int)
42 (require 'gnus-win)
43 (require 'mm-bodies)
44 (require 'mail-parse)
45 (require 'mm-decode)
46 (require 'mm-view)
47 (require 'wid-edit)
48 (require 'mm-uu)
49 (require 'message)
50
51 (autoload 'gnus-msg-mail "gnus-msg" nil t)
52 (autoload 'gnus-button-mailto "gnus-msg")
53 (autoload 'gnus-button-reply "gnus-msg" nil t)
54 (autoload 'parse-time-string "parse-time" nil nil)
55 (autoload 'ansi-color-apply-on-region "ansi-color")
56 (autoload 'mm-url-insert-file-contents-external "mm-url")
57 (autoload 'mm-extern-cache-contents "mm-extern")
58
59 (defgroup gnus-article nil
60   "Article display."
61   :link '(custom-manual "(gnus)Article Buffer")
62   :group 'gnus)
63
64 (defgroup gnus-article-treat nil
65   "Treating article parts."
66   :link '(custom-manual "(gnus)Article Hiding")
67   :group 'gnus-article)
68
69 (defgroup gnus-article-hiding nil
70   "Hiding article parts."
71   :link '(custom-manual "(gnus)Article Hiding")
72   :group 'gnus-article)
73
74 (defgroup gnus-article-highlight nil
75   "Article highlighting."
76   :link '(custom-manual "(gnus)Article Highlighting")
77   :group 'gnus-article
78   :group 'gnus-visual)
79
80 (defgroup gnus-article-signature nil
81   "Article signatures."
82   :link '(custom-manual "(gnus)Article Signature")
83   :group 'gnus-article)
84
85 (defgroup gnus-article-headers nil
86   "Article headers."
87   :link '(custom-manual "(gnus)Hiding Headers")
88   :group 'gnus-article)
89
90 (defgroup gnus-article-washing nil
91   "Special commands on articles."
92   :link '(custom-manual "(gnus)Article Washing")
93   :group 'gnus-article)
94
95 (defgroup gnus-article-emphasis nil
96   "Fontisizing articles."
97   :link '(custom-manual "(gnus)Article Fontisizing")
98   :group 'gnus-article)
99
100 (defgroup gnus-article-saving nil
101   "Saving articles."
102   :link '(custom-manual "(gnus)Saving Articles")
103   :group 'gnus-article)
104
105 (defgroup gnus-article-mime nil
106   "Worshiping the MIME wonder."
107   :link '(custom-manual "(gnus)Using MIME")
108   :group 'gnus-article)
109
110 (defgroup gnus-article-buttons nil
111   "Pushable buttons in the article buffer."
112   :link '(custom-manual "(gnus)Article Buttons")
113   :group 'gnus-article)
114
115 (defgroup gnus-article-various nil
116   "Other article options."
117   :link '(custom-manual "(gnus)Misc Article")
118   :group 'gnus-article)
119
120 (defcustom gnus-ignored-headers
121   (mapcar
122    (lambda (header)
123      (concat "^" header ":"))
124    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
125      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
126      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
127      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
128      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
129      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
130      "X-Attribution" "X-Originating-IP" "Delivered-To"
131      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
132      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
133      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
134      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
135      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
136      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
137      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
138      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
139      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
140      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
141      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
142      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
143      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
144      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
145      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
146      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
147      "List-[A-Za-z]+" "X-Listprocessor-Version"
148      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
149      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
150      "X-Received" "Content-length" "X-precedence"
151      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
152      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
153      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
154      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
155      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
156      "X-Content-length" "X-Posting-Agent" "Original-Received"
157      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
158      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
159      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
160      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
161      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
162      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
163      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
164      "Envelope-Sender" "Envelope-Recipients"))
165   "*All headers that start with this regexp will be hidden.
166 This variable can also be a list of regexps of headers to be ignored.
167 If `gnus-visible-headers' is non-nil, this variable will be ignored."
168   :type '(choice :custom-show nil
169                  regexp
170                  (repeat regexp))
171   :group 'gnus-article-hiding)
172
173 (defcustom gnus-visible-headers
174   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
175   "*All headers that do not match this regexp will be hidden.
176 This variable can also be a list of regexp of headers to remain visible.
177 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
178   :type '(repeat :value-to-internal (lambda (widget value)
179                                       (custom-split-regexp-maybe value))
180                  :match (lambda (widget value)
181                           (or (stringp value)
182                               (widget-editable-list-match widget value)))
183                  regexp)
184   :group 'gnus-article-hiding)
185
186 (defcustom gnus-sorted-header-list
187   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189   "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193   :type '(repeat regexp)
194   :group 'gnus-article-hiding)
195
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197   "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
199
200   'empty       Headers with no content.
201   'newsgroups  Newsgroup identical to Gnus group.
202   'to-address  To identical to To-address.
203   'to-list     To identical to To-list.
204   'cc-list     CC identical to To-list.
205   'followup-to Followup-to identical to Newsgroups.
206   'reply-to    Reply-to identical to From.
207   'date        Date less than four days old.
208   'long-to     To and/or Cc longer than 1024 characters.
209   'many-to     Multiple To and/or Cc."
210   :type '(set (const :tag "Headers with no content." empty)
211               (const :tag "Newsgroups identical to Gnus group." newsgroups)
212               (const :tag "To identical to To-address." to-address)
213               (const :tag "To identical to To-list." to-list)
214               (const :tag "CC identical to To-list." cc-list)
215               (const :tag "Followup-to identical to Newsgroups." followup-to)
216               (const :tag "Reply-to identical to From." reply-to)
217               (const :tag "Date less than four days old." date)
218               (const :tag "To and/or Cc longer than 1024 characters." long-to)
219               (const :tag "Multiple To and/or Cc headers." many-to))
220   :group 'gnus-article-hiding)
221
222 (defcustom gnus-article-skip-boring nil
223   "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text.  Boring text is controlled by
227 `gnus-article-boring-faces'."
228   :version "22.1"
229   :type 'boolean
230   :group 'gnus-article-hiding)
231
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233   "Regexp matching signature separator.
234 This can also be a list of regexps.  In that case, it will be checked
235 from head to tail looking for a separator.  Searches will be done from
236 the end of the buffer."
237   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238                  (regexp)
239                  (repeat :tag "List of regexp" regexp))
240   :group 'gnus-article-signature)
241
242 (defcustom gnus-signature-limit nil
243   "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number.  If it is a floating point number, no signature may be
246 longer (in lines) than that number.  If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer.  If it is a string, it will be used as a
249 regexp.  If it matches, the text in question is not a signature.
250
251 This can also be a list of the above values."
252   :type '(choice (const nil)
253                  (integer :value 200)
254                  (number :value 4.0)
255                  (function :value fun)
256                  (regexp :value ".*"))
257   :group 'gnus-article-signature)
258
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260   "Property list to use for hiding text."
261   :type 'sexp
262   :group 'gnus-article-hiding)
263
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267   (if (featurep 'xemacs)
268       (if (or (gnus-image-type-available-p 'xface)
269               (gnus-image-type-available-p 'pbm))
270           'gnus-display-x-face-in-from
271         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272     (if (gnus-image-type-available-p 'pbm)
273         'gnus-display-x-face-in-from
274       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
275 display -"))
276   "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously.  The compressed face will be piped to this command."
279   :type `(choice string
280                  (function-item gnus-display-x-face-in-from)
281                  function)
282   :version "21.1"
283   :group 'gnus-picon
284   :group 'gnus-article-washing)
285
286 (defcustom gnus-article-x-face-too-ugly nil
287   "Regexp matching posters whose face shouldn't be shown automatically."
288   :type '(choice regexp (const nil))
289   :group 'gnus-article-washing)
290
291 (defcustom gnus-article-banner-alist nil
292   "Banner alist for stripping.
293 For example,
294      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295   :version "21.1"
296   :type '(repeat (cons symbol regexp))
297   :group 'gnus-article-washing)
298
299 (gnus-define-group-parameter
300  banner
301  :variable-document
302  "Alist of regexps (to match group names) and banner."
303  :variable-group gnus-article-washing
304  :parameter-type
305  '(choice :tag "Banner"
306           :value nil
307           (const :tag "Remove signature" signature)
308           (symbol :tag "Item in `gnus-article-banner-alist'" none)
309           regexp
310           (const :tag "None" nil))
311  :parameter-document
312  "If non-nil, specify how to remove `banners' from articles.
313
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'.  Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
319
320 (defcustom gnus-article-address-banner-alist nil
321   "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements.  For example:
327
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
329 "
330   :type '(repeat
331           (cons
332            (regexp :tag "Address")
333            (choice :tag "Banner" :value nil
334                    (const :tag "Remove signature" signature)
335                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
336                    regexp
337                    (const :tag "None" nil))))
338   :version "22.1"
339   :group 'gnus-article-washing)
340
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342   `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345      ,@body))
346
347 (defun gnus-emphasis-custom-value-to-external (value)
348   (gnus-emphasis-custom-with-format
349    (if (consp (car value))
350        (list (format format (car (car value)) (cdr (car value)))
351              2
352              (if (nth 1 value) 2 3)
353              (nth 2 value))
354      value)))
355
356 (defun gnus-emphasis-custom-value-to-internal (value)
357   (gnus-emphasis-custom-with-format
358    (let ((regexp (concat "\\`"
359                          (format (regexp-quote format)
360                                  "\\([^()]+\\)" "\\([^()]+\\)")
361                          "\\'"))
362          pattern)
363      (if (string-match regexp (setq pattern (car value)))
364          (list (cons (match-string 1 pattern) (match-string 2 pattern))
365                (= (nth 2 value) 2)
366                (nth 3 value))
367        value))))
368
369 (defcustom gnus-emphasis-alist
370   (let ((types
371          '(("\\*" "\\*" bold nil 2)
372            ("_" "_" underline)
373            ("/" "/" italic)
374            ("_/" "/_" underline-italic)
375            ("_\\*" "\\*_" underline-bold)
376            ("\\*/" "/\\*" bold-italic)
377            ("_\\*/" "/\\*_" underline-bold-italic))))
378     (nconc
379      (gnus-emphasis-custom-with-format
380       (mapcar (lambda (spec)
381                 (list (format format (car spec) (cadr spec))
382                       (or (nth 3 spec) 2)
383                       (or (nth 4 spec) 3)
384                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385               types))
386      '(;; I've never seen anyone use this strikethru convention whereas I've
387        ;; several times seen it triggered by normal text.  --Stef
388        ;; Miles suggests that this form is sometimes used but for italics,
389        ;; so maybe we should map it to `italic'.
390        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391        ;; 2 3 gnus-emphasis-strikethru)
392        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393         2 3 gnus-emphasis-underline))))
394   "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
396
397   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
398
399 The first element is a regular expression to be matched.  The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word.  The third is a number that says what
402 regexp grouping should be displayed and highlighted.  The fourth
403 is the face used for highlighting."
404   :type
405   '(repeat
406     (menu-choice
407      :format "%[Customizing Style%]\n%v"
408      :indent 2
409      (group :tag "Default"
410             :value ("" 0 0 default)
411             :value-create
412             (lambda (widget)
413               (let ((value (widget-get
414                             (cadr (widget-get (widget-get widget :parent)
415                                               :args))
416                             :value)))
417                 (if (not (eq (nth 2 value) 'default))
418                     (widget-put
419                      widget
420                      :value
421                      (gnus-emphasis-custom-value-to-external value))))
422               (widget-group-value-create widget))
423             regexp
424             (integer :format "Match group: %v")
425             (integer :format "Emphasize group: %v")
426             face)
427      (group :tag "Simple"
428             :value (("_" . "_") nil default)
429             (cons :format "%v"
430                   (regexp :format "Start regexp: %v")
431                   (regexp :format "End regexp: %v"))
432             (boolean :format "Show start and end patterns: %[%v%]\n"
433                      :on " On " :off " Off ")
434             face)))
435   :get (lambda (symbol)
436          (mapcar 'gnus-emphasis-custom-value-to-internal
437                  (default-value symbol)))
438   :set (lambda (symbol value)
439          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440                                      value)))
441   :group 'gnus-article-emphasis)
442
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444   "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448   :version "21.1"
449   :group 'gnus-article-emphasis
450   :type 'regexp)
451
452 (defface gnus-emphasis-bold '((t (:bold t)))
453   "Face used for displaying strong emphasized text (*word*)."
454   :group 'gnus-article-emphasis)
455
456 (defface gnus-emphasis-italic '((t (:italic t)))
457   "Face used for displaying italic emphasized text (/word/)."
458   :group 'gnus-article-emphasis)
459
460 (defface gnus-emphasis-underline '((t (:underline t)))
461   "Face used for displaying underlined emphasized text (_word_)."
462   :group 'gnus-article-emphasis)
463
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465   "Face used for displaying underlined bold emphasized text (_*word*_)."
466   :group 'gnus-article-emphasis)
467
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469   "Face used for displaying underlined italic emphasized text (_/word/_)."
470   :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473   "Face used for displaying bold italic emphasized text (/*word*/)."
474   :group 'gnus-article-emphasis)
475
476 (defface gnus-emphasis-underline-bold-italic
477   '((t (:bold t :italic t :underline t)))
478   "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480   :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483                                       '((t (:strikethru t)))
484                                     '((t (:strike-through t))))
485   "Face used for displaying strike-through text (-word-)."
486   :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-highlight-words
489   '((t (:background "black" :foreground "yellow")))
490   "Face used for displaying highlighted words."
491   :group 'gnus-article-emphasis)
492
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494   "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
496
497 The variable can also be function, which should return a complete Date
498 header.  The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500   :type '(choice string function)
501   :link '(custom-manual "(gnus)Article Date")
502   :group 'gnus-article-washing)
503
504 (defcustom gnus-save-all-headers t
505   "*If non-nil, don't remove any headers before saving.
506 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                  (browse-url-of-file tmp-file)
2825                  (setq showed t)))
2826               ;; If multipart, recurse
2827               ((and (stringp (car handle))
2828                     (string-match "^multipart/" (car handle))
2829                     (setq showed
2830                           (or showed
2831                               (gnus-article-browse-html-parts handle))))))))
2832     showed))
2833
2834 (defun gnus-article-browse-html-article ()
2835   "View \"text/html\" parts of the current article with a WWW browser."
2836   (interactive)
2837   (save-window-excursion
2838     ;; Open raw article and select the buffer
2839     (gnus-summary-show-article t)
2840     (gnus-summary-select-article-buffer)
2841     (let ((parts (mm-dissect-buffer t t)))
2842       ;; If singlepart, enforce a list.
2843       (when (and (bufferp (car parts))
2844                  (stringp (car (mm-handle-type parts))))
2845         (setq parts (list parts)))
2846       ;; Process the list
2847       (unless (gnus-article-browse-html-parts parts)
2848         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2849       (gnus-summary-show-article))))
2850
2851 (defun article-hide-list-identifiers ()
2852   "Remove list identifies from the Subject header.
2853 The `gnus-list-identifiers' variable specifies what to do."
2854   (interactive)
2855   (let ((inhibit-point-motion-hooks t)
2856         (regexp (if (consp gnus-list-identifiers)
2857                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2858                   gnus-list-identifiers))
2859         (inhibit-read-only t))
2860     (when regexp
2861       (save-excursion
2862         (save-restriction
2863           (article-narrow-to-head)
2864           (goto-char (point-min))
2865           (while (re-search-forward
2866                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2867                   nil t)
2868             (delete-region (match-beginning 2) (match-end 0))
2869             (beginning-of-line))
2870           (when (re-search-forward
2871                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2872             (delete-region (match-beginning 1) (match-end 1))))))))
2873
2874 (defun article-hide-pem (&optional arg)
2875   "Toggle hiding of any PEM headers and signatures in the current article.
2876 If given a negative prefix, always show; if given a positive prefix,
2877 always hide."
2878   (interactive (gnus-article-hidden-arg))
2879   (unless (gnus-article-check-hidden-text 'pem arg)
2880     (save-excursion
2881       (let ((inhibit-read-only t) end)
2882         (goto-char (point-min))
2883         ;; Hide the horrendously ugly "header".
2884         (when (and (search-forward
2885                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2886                     nil t)
2887                    (setq end (1+ (match-beginning 0))))
2888           (gnus-add-wash-type 'pem)
2889           (gnus-article-hide-text-type
2890            end
2891            (if (search-forward "\n\n" nil t)
2892                (match-end 0)
2893              (point-max))
2894            'pem)
2895           ;; Hide the trailer as well
2896           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2897                                 nil t)
2898             (gnus-article-hide-text-type
2899              (match-beginning 0) (match-end 0) 'pem)))))))
2900
2901 (defun article-strip-banner ()
2902   "Strip the banners specified by the `banner' group parameter and by
2903 `gnus-article-address-banner-alist'."
2904   (interactive)
2905   (save-excursion
2906     (save-restriction
2907       (let ((inhibit-point-motion-hooks t))
2908         (when (gnus-parameter-banner gnus-newsgroup-name)
2909           (article-really-strip-banner
2910            (gnus-parameter-banner gnus-newsgroup-name)))
2911         (when gnus-article-address-banner-alist
2912           ;; Note that the From header is decoded here, so it is
2913           ;; required that the *-extract-address-components function
2914           ;; supports non-ASCII text.
2915           (let ((from (save-restriction
2916                         (widen)
2917                         (article-narrow-to-head)
2918                         (mail-fetch-field "from"))))
2919             (when (and from
2920                        (setq from
2921                              (cadr (funcall gnus-extract-address-components
2922                                             from))))
2923               (catch 'found
2924                 (dolist (pair gnus-article-address-banner-alist)
2925                   (when (string-match (car pair) from)
2926                     (throw 'found
2927                            (article-really-strip-banner (cdr pair)))))))))))))
2928
2929 (defun article-really-strip-banner (banner)
2930   "Strip the banner specified by the argument."
2931   (save-excursion
2932     (save-restriction
2933       (let ((inhibit-point-motion-hooks t)
2934             (gnus-signature-limit nil)
2935             (inhibit-read-only t))
2936         (article-goto-body)
2937         (cond
2938          ((eq banner 'signature)
2939           (when (gnus-article-narrow-to-signature)
2940             (widen)
2941             (forward-line -1)
2942             (delete-region (point) (point-max))))
2943          ((symbolp banner)
2944           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2945               (while (re-search-forward banner nil t)
2946                 (delete-region (match-beginning 0) (match-end 0)))))
2947          ((stringp banner)
2948           (while (re-search-forward banner nil t)
2949             (delete-region (match-beginning 0) (match-end 0)))))))))
2950
2951 (defun article-babel ()
2952   "Translate article using an online translation service."
2953   (interactive)
2954   (require 'babel)
2955   (gnus-with-article-buffer
2956     (when (article-goto-body)
2957       (let* ((start (point))
2958              (end (point-max))
2959              (orig (buffer-substring start end))
2960              (trans (babel-as-string orig)))
2961         (save-restriction
2962           (narrow-to-region start end)
2963           (delete-region start end)
2964           (insert trans))))))
2965
2966 (defun article-hide-signature (&optional arg)
2967   "Hide the signature in the current article.
2968 If given a negative prefix, always show; if given a positive prefix,
2969 always hide."
2970   (interactive (gnus-article-hidden-arg))
2971   (unless (gnus-article-check-hidden-text 'signature arg)
2972     (save-excursion
2973       (save-restriction
2974         (let ((inhibit-read-only t))
2975           (when (gnus-article-narrow-to-signature)
2976             (gnus-article-hide-text-type
2977              (point-min) (point-max) 'signature))))))
2978   (gnus-set-mode-line 'article))
2979
2980 (defun article-strip-headers-in-body ()
2981   "Strip offensive headers from bodies."
2982   (interactive)
2983   (save-excursion
2984     (article-goto-body)
2985     (let ((case-fold-search t))
2986       (when (looking-at "x-no-archive:")
2987         (gnus-delete-line)))))
2988
2989 (defun article-strip-leading-blank-lines ()
2990   "Remove all blank lines from the beginning of the article."
2991   (interactive)
2992   (save-excursion
2993     (let ((inhibit-point-motion-hooks t)
2994           (inhibit-read-only t))
2995       (when (article-goto-body)
2996         (while (and (not (eobp))
2997                     (looking-at "[ \t]*$"))
2998           (gnus-delete-line))))))
2999
3000 (defun article-narrow-to-head ()
3001   "Narrow the buffer to the head of the message.
3002 Point is left at the beginning of the narrowed-to region."
3003   (narrow-to-region
3004    (goto-char (point-min))
3005    (if (search-forward "\n\n" nil 1)
3006        (1- (point))
3007      (point-max)))
3008   (goto-char (point-min)))
3009
3010 (defun article-goto-body ()
3011   "Place point at the start of the body."
3012   (goto-char (point-min))
3013   (cond
3014    ;; This variable is only bound when dealing with separate
3015    ;; MIME body parts.
3016    (article-goto-body-goes-to-point-min-p
3017     t)
3018    ((search-forward "\n\n" nil t)
3019     t)
3020    (t
3021     (goto-char (point-max))
3022     nil)))
3023
3024 (defun article-strip-multiple-blank-lines ()
3025   "Replace consecutive blank lines with one empty line."
3026   (interactive)
3027   (save-excursion
3028     (let ((inhibit-point-motion-hooks t)
3029           (inhibit-read-only t))
3030       ;; First make all blank lines empty.
3031       (article-goto-body)
3032       (while (re-search-forward "^[ \t]+$" nil t)
3033         (unless (gnus-annotation-in-region-p
3034                  (match-beginning 0) (match-end 0))
3035           (replace-match "" nil t)))
3036       ;; Then replace multiple empty lines with a single empty line.
3037       (article-goto-body)
3038       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3039         (unless (gnus-annotation-in-region-p
3040                  (match-beginning 0) (match-end 0))
3041           (delete-region (match-beginning 1) (match-end 1)))))))
3042
3043 (defun article-strip-leading-space ()
3044   "Remove all white space from the beginning of the lines in the article."
3045   (interactive)
3046   (save-excursion
3047     (let ((inhibit-point-motion-hooks t)
3048           (inhibit-read-only t))
3049       (article-goto-body)
3050       (while (re-search-forward "^[ \t]+" nil t)
3051         (replace-match "" t t)))))
3052
3053 (defun article-strip-trailing-space ()
3054   "Remove all white space from the end of the lines in the article."
3055   (interactive)
3056   (save-excursion
3057     (let ((inhibit-point-motion-hooks t)
3058           (inhibit-read-only t))
3059       (article-goto-body)
3060       (while (re-search-forward "[ \t]+$" nil t)
3061         (replace-match "" t t)))))
3062
3063 (defun article-strip-blank-lines ()
3064   "Strip leading, trailing and multiple blank lines."
3065   (interactive)
3066   (article-strip-leading-blank-lines)
3067   (article-remove-trailing-blank-lines)
3068   (article-strip-multiple-blank-lines))
3069
3070 (defun article-strip-all-blank-lines ()
3071   "Strip all blank lines."
3072   (interactive)
3073   (save-excursion
3074     (let ((inhibit-point-motion-hooks t)
3075           (inhibit-read-only t))
3076       (article-goto-body)
3077       (while (re-search-forward "^[ \t]*\n" nil t)
3078         (replace-match "" t t)))))
3079
3080 (defun gnus-article-narrow-to-signature ()
3081   "Narrow to the signature; return t if a signature is found, else nil."
3082   (let ((inhibit-point-motion-hooks t))
3083     (when (gnus-article-search-signature)
3084       (forward-line 1)
3085       ;; Check whether we have some limits to what we consider
3086       ;; to be a signature.
3087       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3088                       (list gnus-signature-limit)))
3089             limit limited)
3090         (while (setq limit (pop limits))
3091           (if (or (and (integerp limit)
3092                        (< (- (point-max) (point)) limit))
3093                   (and (floatp limit)
3094                        (< (count-lines (point) (point-max)) limit))
3095                   (and (functionp limit)
3096                        (funcall limit))
3097                   (and (stringp limit)
3098                        (not (re-search-forward limit nil t))))
3099               ()                        ; This limit did not succeed.
3100             (setq limited t
3101                   limits nil)))
3102         (unless limited
3103           (narrow-to-region (point) (point-max))
3104           t)))))
3105
3106 (defun gnus-article-search-signature ()
3107   "Search the current buffer for the signature separator.
3108 Put point at the beginning of the signature separator."
3109   (let ((cur (point)))
3110     (goto-char (point-max))
3111     (if (if (stringp gnus-signature-separator)
3112             (re-search-backward gnus-signature-separator nil t)
3113           (let ((seps gnus-signature-separator))
3114             (while (and seps
3115                         (not (re-search-backward (car seps) nil t)))
3116               (pop seps))
3117             seps))
3118         t
3119       (goto-char cur)
3120       nil)))
3121
3122 (defun gnus-article-hidden-arg ()
3123   "Return the current prefix arg as a number, or 0 if no prefix."
3124   (list (if current-prefix-arg
3125             (prefix-numeric-value current-prefix-arg)
3126           0)))
3127
3128 (defun gnus-article-check-hidden-text (type arg)
3129   "Return nil if hiding is necessary.
3130 Arg can be nil or a number.  nil and positive means hide, negative
3131 means show, 0 means toggle."
3132   (save-excursion
3133     (save-restriction
3134       (let ((hide (gnus-article-hidden-text-p type)))
3135         (cond
3136          ((or (null arg)
3137               (> arg 0))
3138           nil)
3139          ((< arg 0)
3140           (gnus-article-show-hidden-text type)
3141           t)
3142          (t
3143           (if (eq hide 'hidden)
3144               (progn
3145                 (gnus-article-show-hidden-text type)
3146                 t)
3147             nil)))))))
3148
3149 (defun gnus-article-hidden-text-p (type)
3150   "Say whether the current buffer contains hidden text of type TYPE."
3151   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3152     (while (and pos
3153                 (not (get-text-property pos 'invisible))
3154                 (not (get-text-property pos 'dummy-invisible)))
3155       (setq pos
3156             (text-property-any (1+ pos) (point-max) 'article-type type)))
3157     (if pos
3158         'hidden
3159       nil)))
3160
3161 (defun gnus-article-show-hidden-text (type &optional dummy)
3162   "Show all hidden text of type TYPE.
3163 Originally it is hide instead of DUMMY."
3164   (let ((inhibit-read-only t)
3165         (inhibit-point-motion-hooks t))
3166     (gnus-remove-text-properties-when
3167      'article-type type
3168      (point-min) (point-max)
3169      (cons 'article-type (cons type
3170                                gnus-hidden-properties)))
3171     (gnus-delete-wash-type type)))
3172
3173 (defconst article-time-units
3174   `((year . ,(* 365.25 24 60 60))
3175     (week . ,(* 7 24 60 60))
3176     (day . ,(* 24 60 60))
3177     (hour . ,(* 60 60))
3178     (minute . 60)
3179     (second . 1))
3180   "Mapping from time units to seconds.")
3181
3182 (defun gnus-article-forward-header ()
3183   "Move point to the start of the next header.
3184 If the current header is a continuation header, this can be several
3185 lines forward."
3186   (let ((ended nil))
3187     (while (not ended)
3188       (forward-line 1)
3189       (if (looking-at "[ \t]+[^ \t]")
3190           (forward-line 1)
3191         (setq ended t)))))
3192
3193 (defun article-date-ut (&optional type highlight)
3194   "Convert DATE date to universal time in the current article.
3195 If TYPE is `local', convert to local time; if it is `lapsed', output
3196 how much time has lapsed since DATE.  For `lapsed', the value of
3197 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3198 should replace the \"Date:\" one, or should be added below it."
3199   (interactive (list 'ut t))
3200   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3201          (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3202                              tdate-regexp)
3203                             ((eq type 'lapsed)
3204                              "^X-Sent:[ \t]")
3205                             (article-lapsed-timer
3206                              "^Date:[ \t]")
3207                             (t
3208                              tdate-regexp)))
3209          (case-fold-search t)
3210          (inhibit-read-only t)
3211          (inhibit-point-motion-hooks t)
3212          pos date bface eface)
3213     (save-excursion
3214       (save-restriction
3215         (widen)
3216         (goto-char (point-min))
3217         (while (or (setq date (get-text-property (setq pos (point))
3218                                                  'original-date))
3219                    (when (setq pos (next-single-property-change
3220                                     (point) 'original-date))
3221                      (setq date (get-text-property pos 'original-date))
3222                      t))
3223           (narrow-to-region pos (or (text-property-any pos (point-max)
3224                                                        'original-date nil)
3225                                     (point-max)))
3226           (goto-char (point-min))
3227           (when (re-search-forward tdate-regexp nil t)
3228             (setq bface (get-text-property (point-at-bol) 'face)
3229                   eface (get-text-property (1- (point-at-eol)) 'face)))
3230           (goto-char (point-min))
3231           (setq pos nil)
3232           ;; Delete any old Date headers.
3233           (while (re-search-forward date-regexp nil t)
3234             (if pos
3235                 (delete-region (point-at-bol) (progn
3236                                                 (gnus-article-forward-header)
3237                                                 (point)))
3238               (delete-region (point-at-bol) (progn
3239                                               (gnus-article-forward-header)
3240                                               (forward-char -1)
3241                                               (point)))
3242               (setq pos (point))))
3243           (when (and (not pos)
3244                      (re-search-forward tdate-regexp nil t))
3245             (forward-line 1))
3246           (gnus-goto-char pos)
3247           (insert (article-make-date-line date (or type 'ut)))
3248           (unless pos
3249             (insert "\n")
3250             (forward-line -1))
3251           ;; Do highlighting.
3252           (beginning-of-line)
3253           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3254             (put-text-property (match-beginning 1) (1+ (match-end 1))
3255                                'face bface)
3256             (put-text-property (match-beginning 2) (match-end 2)
3257                                'face eface))
3258           (put-text-property (point-min) (1- (point-max)) 'original-date date)
3259           (goto-char (point-max))
3260           (widen))))))
3261
3262 (defun article-make-date-line (date type)
3263   "Return a DATE line of TYPE."
3264   (unless (memq type '(local ut original user iso8601 lapsed english))
3265     (error "Unknown conversion type: %s" type))
3266   (condition-case ()
3267       (let ((time (date-to-time date)))
3268         (cond
3269          ;; Convert to the local timezone.
3270          ((eq type 'local)
3271           (concat "Date: " (message-make-date time)))
3272          ;; Convert to Universal Time.
3273          ((eq type 'ut)
3274           (concat "Date: "
3275                   (substring
3276                    (message-make-date
3277                     (let* ((e (parse-time-string date))
3278                            (tm (apply 'encode-time e))
3279                            (ms (car tm))
3280                            (ls (- (cadr tm) (car (current-time-zone time)))))
3281                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3282                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3283                             (t (list ms ls)))))
3284                    0 -5)
3285                   "UT"))
3286          ;; Get the original date from the article.
3287          ((eq type 'original)
3288           (concat "Date: " (if (string-match "\n+$" date)
3289                                (substring date 0 (match-beginning 0))
3290                              date)))
3291          ;; Let the user define the format.
3292          ((eq type 'user)
3293           (let ((format (or (condition-case nil
3294                                 (with-current-buffer gnus-summary-buffer
3295                                   gnus-article-time-format)
3296                               (error nil))
3297                             gnus-article-time-format)))
3298             (if (functionp format)
3299                 (funcall format time)
3300               (concat "Date: " (format-time-string format time)))))
3301          ;; ISO 8601.
3302          ((eq type 'iso8601)
3303           (let ((tz (car (current-time-zone time))))
3304             (concat
3305              "Date: "
3306              (format-time-string "%Y%m%dT%H%M%S" time)
3307              (format "%s%02d%02d"
3308                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3309                      (/ (% (abs tz) 3600) 60)))))
3310          ;; Do an X-Sent lapsed format.
3311          ((eq type 'lapsed)
3312           ;; If the date is seriously mangled, the timezone functions are
3313           ;; liable to bug out, so we ignore all errors.
3314           (let* ((now (current-time))
3315                  (real-time (subtract-time now time))
3316                  (real-sec (and real-time
3317                                 (+ (* (float (car real-time)) 65536)
3318                                    (cadr real-time))))
3319                  (sec (and real-time (abs real-sec)))
3320                  num prev)
3321             (cond
3322              ((null real-time)
3323               "X-Sent: Unknown")
3324              ((zerop sec)
3325               "X-Sent: Now")
3326              (t
3327               (concat
3328                "X-Sent: "
3329                ;; This is a bit convoluted, but basically we go
3330                ;; through the time units for years, weeks, etc,
3331                ;; and divide things to see whether that results
3332                ;; in positive answers.
3333                (mapconcat
3334                 (lambda (unit)
3335                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3336                       ;; The (remaining) seconds are too few to
3337                       ;; be divided into this time unit.
3338                       ""
3339                     ;; It's big enough, so we output it.
3340                     (setq sec (- sec (* num (cdr unit))))
3341                     (prog1
3342                         (concat (if prev ", " "") (int-to-string
3343                                                    (floor num))
3344                                 " " (symbol-name (car unit))
3345                                 (if (> num 1) "s" ""))
3346                       (setq prev t))))
3347                 article-time-units "")
3348                ;; If dates are odd, then it might appear like the
3349                ;; article was sent in the future.
3350                (if (> real-sec 0)
3351                    " ago"
3352                  " in the future"))))))
3353          ;; Display the date in proper English
3354          ((eq type 'english)
3355           (let ((dtime (decode-time time)))
3356             (concat
3357              "Date: the "
3358              (number-to-string (nth 3 dtime))
3359              (let ((digit (% (nth 3 dtime) 10)))
3360                (cond
3361                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3362                 ((= digit 1) "st")
3363                 ((= digit 2) "nd")
3364                 ((= digit 3) "rd")
3365                 (t "th")))
3366              " of "
3367              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3368              " "
3369              (number-to-string (nth 5 dtime))
3370              " at "
3371              (format "%02d" (nth 2 dtime))
3372              ":"
3373              (format "%02d" (nth 1 dtime)))))))
3374     (error
3375      (format "Date: %s (from Gnus)" date))))
3376
3377 (defun article-date-local (&optional highlight)
3378   "Convert the current article date to the local timezone."
3379   (interactive (list t))
3380   (article-date-ut 'local highlight))
3381
3382 (defun article-date-english (&optional highlight)
3383   "Convert the current article date to something that is proper English."
3384   (interactive (list t))
3385   (article-date-ut 'english highlight))
3386
3387 (defun article-date-original (&optional highlight)
3388   "Convert the current article date to what it was originally.
3389 This is only useful if you have used some other date conversion
3390 function and want to see what the date was before converting."
3391   (interactive (list t))
3392   (article-date-ut 'original highlight))
3393
3394 (defun article-date-lapsed (&optional highlight)
3395   "Convert the current article date to time lapsed since it was sent."
3396   (interactive (list t))
3397   (article-date-ut 'lapsed highlight))
3398
3399 (defun article-update-date-lapsed ()
3400   "Function to be run from a timer to update the lapsed time line."
3401   (save-match-data
3402     (let (deactivate-mark)
3403       (save-excursion
3404         (ignore-errors
3405          (walk-windows
3406           (lambda (w)
3407             (set-buffer (window-buffer w))
3408             (when (eq major-mode 'gnus-article-mode)
3409               (let ((mark (point-marker)))
3410                 (goto-char (point-min))
3411                 (when (re-search-forward "^X-Sent:" nil t)
3412                   (article-date-lapsed t))
3413                 (goto-char (marker-position mark))
3414                 (move-marker mark nil))))
3415           nil 'visible))))))
3416
3417 (defun gnus-start-date-timer (&optional n)
3418   "Start a timer to update the X-Sent header in the article buffers.
3419 The numerical prefix says how frequently (in seconds) the function
3420 is to run."
3421   (interactive "p")
3422   (unless n
3423     (setq n 1))
3424   (gnus-stop-date-timer)
3425   (setq article-lapsed-timer
3426         (run-at-time 1 n 'article-update-date-lapsed)))
3427
3428 (defun gnus-stop-date-timer ()
3429   "Stop the X-Sent timer."
3430   (interactive)
3431   (when article-lapsed-timer
3432     (nnheader-cancel-timer article-lapsed-timer)
3433     (setq article-lapsed-timer nil)))
3434
3435 (defun article-date-user (&optional highlight)
3436   "Convert the current article date to the user-defined format.
3437 This format is defined by the `gnus-article-time-format' variable."
3438   (interactive (list t))
3439   (article-date-ut 'user highlight))
3440
3441 (defun article-date-iso8601 (&optional highlight)
3442   "Convert the current article date to ISO8601."
3443   (interactive (list t))
3444   (article-date-ut 'iso8601 highlight))
3445
3446 (defmacro gnus-article-save-original-date (&rest forms)
3447   "Save the original date as a text property and evaluate FORMS."
3448   `(let* ((case-fold-search t)
3449           (start (progn
3450                    (goto-char (point-min))
3451                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3452                               (not (bolp)))
3453                      (match-end 0))))
3454           (date (when (and start
3455                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3456                                               nil t))
3457                   (buffer-substring-no-properties start
3458                                                   (match-beginning 0)))))
3459      (goto-char (point-max))
3460      (skip-chars-backward "\n")
3461      (put-text-property (point-min) (point) 'original-date date)
3462      ,@forms
3463      (goto-char (point-max))
3464      (skip-chars-backward "\n")
3465      (put-text-property (point-min) (point) 'original-date date)))
3466
3467 ;; (defun article-show-all ()
3468 ;;   "Show all hidden text in the article buffer."
3469 ;;   (interactive)
3470 ;;   (save-excursion
3471 ;;     (let ((inhibit-read-only t))
3472 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3473
3474 (defun article-remove-leading-whitespace ()
3475   "Remove excessive whitespace from all headers."
3476   (interactive)
3477   (save-excursion
3478     (save-restriction
3479       (let ((inhibit-read-only t))
3480         (article-narrow-to-head)
3481         (goto-char (point-min))
3482         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3483           (delete-region (match-beginning 1) (match-end 1)))))))
3484
3485 (defun article-emphasize (&optional arg)
3486   "Emphasize text according to `gnus-emphasis-alist'."
3487   (interactive (gnus-article-hidden-arg))
3488   (unless (gnus-article-check-hidden-text 'emphasis arg)
3489     (save-excursion
3490       (let ((alist (or
3491                     (condition-case nil
3492                         (with-current-buffer gnus-summary-buffer
3493                           gnus-article-emphasis-alist)
3494                       (error))
3495                     gnus-emphasis-alist))
3496             (inhibit-read-only t)
3497             (props (append '(article-type emphasis)
3498                            gnus-hidden-properties))
3499             regexp elem beg invisible visible face)
3500         (article-goto-body)
3501         (setq beg (point))
3502         (while (setq elem (pop alist))
3503           (goto-char beg)
3504           (setq regexp (car elem)
3505                 invisible (nth 1 elem)
3506                 visible (nth 2 elem)
3507                 face (nth 3 elem))
3508           (while (re-search-forward regexp nil t)
3509             (when (and (match-beginning visible) (match-beginning invisible))
3510               (gnus-article-hide-text
3511                (match-beginning invisible) (match-end invisible) props)
3512               (gnus-article-unhide-text-type
3513                (match-beginning visible) (match-end visible) 'emphasis)
3514               (gnus-put-overlay-excluding-newlines
3515                (match-beginning visible) (match-end visible) 'face face)
3516               (gnus-add-wash-type 'emphasis)
3517               (goto-char (match-end invisible)))))))))
3518
3519 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3520   "Setup newsgroup emphasis alist."
3521   (unless gnus-article-emphasis-alist
3522     (let ((name (and gnus-newsgroup-name
3523                      (gnus-group-real-name gnus-newsgroup-name))))
3524       (make-local-variable 'gnus-article-emphasis-alist)
3525       (setq gnus-article-emphasis-alist
3526             (nconc
3527              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3528                (while (setq elem (pop alist))
3529                  (when (and name (string-match (car elem) name))
3530                    (setq alist nil
3531                          highlight (copy-sequence (cdr elem)))))
3532                highlight)
3533              (copy-sequence highlight-words)
3534              (if gnus-newsgroup-name
3535                  (copy-sequence (gnus-group-find-parameter
3536                                  gnus-newsgroup-name 'highlight-words t)))
3537              gnus-emphasis-alist)))))
3538
3539 (eval-when-compile
3540   (defvar gnus-summary-article-menu)
3541   (defvar gnus-summary-post-menu))
3542
3543 ;;; Saving functions.
3544
3545 (defun gnus-article-save (save-buffer file &optional num)
3546   "Save the currently selected article."
3547   (when (or (get gnus-default-article-saver :headers)
3548             (not gnus-save-all-headers))
3549     ;; Remove headers according to `gnus-saved-headers' or the value
3550     ;; of the `:headers' property that the saver function might have.
3551     (let ((gnus-visible-headers
3552            (or (symbol-value (get gnus-default-article-saver :headers))
3553                gnus-saved-headers gnus-visible-headers))
3554           (gnus-article-buffer save-buffer))
3555       (save-excursion
3556         (set-buffer save-buffer)
3557         (article-hide-headers 1 t))))
3558   (save-window-excursion
3559     (if (not gnus-default-article-saver)
3560         (error "No default saver is defined")
3561       ;; !!! Magic!  The saving functions all save
3562       ;; `gnus-save-article-buffer' (or so they think), but we
3563       ;; bind that variable to our save-buffer.
3564       (set-buffer gnus-article-buffer)
3565       (let* ((gnus-save-article-buffer save-buffer)
3566              (filename
3567               (cond
3568                ((not gnus-prompt-before-saving) 'default)
3569                ((eq gnus-prompt-before-saving 'always) nil)
3570                (t file)))
3571              (gnus-number-of-articles-to-be-saved
3572               (when (eq gnus-prompt-before-saving t)
3573                 num)))                  ; Magic
3574         (set-buffer gnus-article-current-summary)
3575         (funcall gnus-default-article-saver filename)))))
3576
3577 (defun gnus-read-save-file-name (prompt &optional filename
3578                                         function group headers variable
3579                                         dir-var)
3580   (let ((default-name
3581           (funcall function group headers (symbol-value variable)))
3582         result)
3583     (setq result
3584           (expand-file-name
3585            (cond
3586             ((eq filename 'default)
3587              default-name)
3588             ((eq filename t)
3589              default-name)
3590             (filename filename)
3591             (t
3592              (when (symbol-value dir-var)
3593                (setq default-name (expand-file-name
3594                                    (file-name-nondirectory default-name)
3595                                    (symbol-value dir-var))))
3596              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3597                     (prompt
3598                      (format prompt
3599                              (if (and gnus-number-of-articles-to-be-saved
3600                                       (> gnus-number-of-articles-to-be-saved 1))
3601                                  (format "these %d articles"
3602                                          gnus-number-of-articles-to-be-saved)
3603                                "this article")))
3604                     (file
3605                      ;; Let the split methods have their say.
3606                      (cond
3607                       ;; No split name was found.
3608                       ((null split-name)
3609                        (read-file-name
3610                         (concat prompt " (default "
3611                                 (file-name-nondirectory default-name) "): ")
3612                         (file-name-directory default-name)
3613                         default-name))
3614                       ;; A single group name is returned.
3615                       ((stringp split-name)
3616                        (setq default-name
3617                              (funcall function split-name headers
3618                                       (symbol-value variable)))
3619                        (read-file-name
3620                         (concat prompt " (default "
3621                                 (file-name-nondirectory default-name) "): ")
3622                         (file-name-directory default-name)
3623                         default-name))
3624                       ;; A single split name was found
3625                       ((= 1 (length split-name))
3626                        (let* ((name (expand-file-name
3627                                      (car split-name)
3628                                      gnus-article-save-directory))
3629                               (dir (cond ((file-directory-p name)
3630                                           (file-name-as-directory name))
3631                                          ((file-exists-p name) name)
3632                                          (t gnus-article-save-directory))))
3633                          (read-file-name
3634                           (concat prompt " (default " name "): ")
3635                           dir name)))
3636                       ;; A list of splits was found.
3637                       (t
3638                        (setq split-name (nreverse split-name))
3639                        (let (result)
3640                          (let ((file-name-history
3641                                 (nconc split-name file-name-history)))
3642                            (setq result
3643                                  (expand-file-name
3644                                   (read-file-name
3645                                    (concat prompt " (`M-p' for defaults): ")
3646                                    gnus-article-save-directory
3647                                    (car split-name))
3648                                   gnus-article-save-directory)))
3649                          (car (push result file-name-history)))))))
3650                ;; Create the directory.
3651                (gnus-make-directory (file-name-directory file))
3652                ;; If we have read a directory, we append the default file name.
3653                (when (file-directory-p file)
3654                  (setq file (expand-file-name (file-name-nondirectory
3655                                                default-name)
3656                                               (file-name-as-directory file))))
3657                ;; Possibly translate some characters.
3658                (nnheader-translate-file-chars file))))))
3659     (gnus-make-directory (file-name-directory result))
3660     (when variable
3661       (set variable result))
3662     (when dir-var
3663       (set dir-var (file-name-directory result)))
3664     result))
3665
3666 (defun gnus-article-archive-name (group)
3667   "Return the first instance of an \"Archive-name\" in the current buffer."
3668   (let ((case-fold-search t))
3669     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3670       (nnheader-concat gnus-article-save-directory
3671                        (match-string 1)))))
3672
3673 (defun gnus-article-nndoc-name (group)
3674   "If GROUP is an nndoc group, return the name of the parent group."
3675   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3676     (gnus-group-get-parameter group 'save-article-group)))
3677
3678 (defun gnus-summary-save-in-rmail (&optional filename)
3679   "Append this article to Rmail file.
3680 Optional argument FILENAME specifies file name.
3681 Directory to save to is default to `gnus-article-save-directory'."
3682   (setq filename (gnus-read-save-file-name
3683                   "Save %s in rmail file" filename
3684                   gnus-rmail-save-name gnus-newsgroup-name
3685                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3686   (gnus-eval-in-buffer-window gnus-save-article-buffer
3687     (save-excursion
3688       (save-restriction
3689         (widen)
3690         (gnus-output-to-rmail filename))))
3691   filename)
3692
3693 (defun gnus-summary-save-in-mail (&optional filename)
3694   "Append this article to Unix mail file.
3695 Optional argument FILENAME specifies file name.
3696 Directory to save to is default to `gnus-article-save-directory'."
3697   (setq filename (gnus-read-save-file-name
3698                   "Save %s in Unix mail file" filename
3699                   gnus-mail-save-name gnus-newsgroup-name
3700                   gnus-current-headers 'gnus-newsgroup-last-mail))
3701   (gnus-eval-in-buffer-window gnus-save-article-buffer
3702     (save-excursion
3703       (save-restriction
3704         (widen)
3705         (if (and (file-readable-p filename)
3706                  (file-regular-p filename)
3707                  (mail-file-babyl-p filename))
3708             (rmail-output-to-rmail-file filename t)
3709           (gnus-output-to-mail filename)))))
3710   filename)
3711
3712 (put 'gnus-summary-save-in-file :decode t)
3713 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3714 (defun gnus-summary-save-in-file (&optional filename overwrite)
3715   "Append this article to file.
3716 Optional argument FILENAME specifies file name.
3717 Directory to save to is default to `gnus-article-save-directory'."
3718   (setq filename (gnus-read-save-file-name
3719                   "Save %s in file" filename
3720                   gnus-file-save-name gnus-newsgroup-name
3721                   gnus-current-headers 'gnus-newsgroup-last-file))
3722   (gnus-eval-in-buffer-window gnus-save-article-buffer
3723     (save-excursion
3724       (save-restriction
3725         (widen)
3726         (when (and overwrite
3727                    (file-exists-p filename))
3728           (delete-file filename))
3729         (gnus-output-to-file filename))))
3730   filename)
3731
3732 (put 'gnus-summary-write-to-file :decode t)
3733 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3734 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3735 (defun gnus-summary-write-to-file (&optional filename)
3736   "Write this article to a file, overwriting it if the file exists.
3737 Optional argument FILENAME specifies file name.
3738 The directory to save in defaults to `gnus-article-save-directory'."
3739   (setq filename (gnus-read-save-file-name
3740                   "Save %s in file" filename
3741                   gnus-file-save-name gnus-newsgroup-name
3742                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3743   (gnus-summary-save-in-file filename t))
3744
3745 (put 'gnus-summary-save-body-in-file :decode t)
3746 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3747   "Append this article body to a file.
3748 Optional argument FILENAME specifies file name.
3749 The directory to save in defaults to `gnus-article-save-directory'."
3750   (setq filename (gnus-read-save-file-name
3751                   "Save %s body in file" filename
3752                   gnus-file-save-name gnus-newsgroup-name
3753                   gnus-current-headers 'gnus-newsgroup-last-file))
3754   (gnus-eval-in-buffer-window gnus-save-article-buffer
3755     (save-excursion
3756       (save-restriction
3757         (widen)
3758         (when (article-goto-body)
3759           (narrow-to-region (point) (point-max)))
3760         (when (and overwrite
3761                    (file-exists-p filename))
3762           (delete-file filename))
3763         (gnus-output-to-file filename))))
3764   filename)
3765
3766 (put 'gnus-summary-write-body-to-file :decode t)
3767 (put 'gnus-summary-write-body-to-file
3768      :function 'gnus-summary-save-body-in-file)
3769 (defun gnus-summary-write-body-to-file (&optional filename)
3770   "Write this article body to a file, overwriting it if the file exists.
3771 Optional argument FILENAME specifies file name.
3772 The directory to save in defaults to `gnus-article-save-directory'."
3773   (setq filename (gnus-read-save-file-name
3774                   "Save %s body in file" filename
3775                   gnus-file-save-name gnus-newsgroup-name
3776                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3777   (gnus-summary-save-body-in-file filename t))
3778
3779 (defun gnus-summary-save-in-pipe (&optional command)
3780   "Pipe this article to subprocess."
3781   (setq command
3782         (cond ((and (eq command 'default)
3783                     gnus-last-shell-command)
3784                gnus-last-shell-command)
3785               ((stringp command)
3786                command)
3787               (t (read-string
3788                   (format
3789                    "Shell command on %s: "
3790                    (if (and gnus-number-of-articles-to-be-saved
3791                             (> gnus-number-of-articles-to-be-saved 1))
3792                        (format "these %d articles"
3793                                gnus-number-of-articles-to-be-saved)
3794                      "this article"))
3795                   gnus-last-shell-command))))
3796   (when (string-equal command "")
3797     (if gnus-last-shell-command
3798         (setq command gnus-last-shell-command)
3799       (error "A command is required")))
3800   (gnus-eval-in-buffer-window gnus-article-buffer
3801     (save-restriction
3802       (widen)
3803       (shell-command-on-region (point-min) (point-max) command nil)))
3804   (setq gnus-last-shell-command command))
3805
3806 (defun gnus-summary-pipe-to-muttprint (&optional command)
3807   "Pipe this article to muttprint."
3808   (setq command (read-string
3809                  "Print using command: " gnus-summary-muttprint-program
3810                  nil gnus-summary-muttprint-program))
3811   (gnus-summary-save-in-pipe command))
3812
3813 ;;; Article file names when saving.
3814
3815 (defun gnus-capitalize-newsgroup (newsgroup)
3816   "Capitalize NEWSGROUP name."
3817   (when (not (zerop (length newsgroup)))
3818     (concat (char-to-string (upcase (aref newsgroup 0)))
3819             (substring newsgroup 1))))
3820
3821 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3822   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3823 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3824 Otherwise, it is like ~/News/news/group/num."
3825   (let ((default
3826           (expand-file-name
3827            (concat (if (gnus-use-long-file-name 'not-save)
3828                        (gnus-capitalize-newsgroup newsgroup)
3829                      (gnus-newsgroup-directory-form newsgroup))
3830                    "/" (int-to-string (mail-header-number headers)))
3831            gnus-article-save-directory)))
3832     (if (and last-file
3833              (string-equal (file-name-directory default)
3834                            (file-name-directory last-file))
3835              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3836         default
3837       (or last-file default))))
3838
3839 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3840   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3841 If variable `gnus-use-long-file-name' is non-nil, it is
3842 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3843   (let ((default
3844           (expand-file-name
3845            (concat (if (gnus-use-long-file-name 'not-save)
3846                        newsgroup
3847                      (gnus-newsgroup-directory-form newsgroup))
3848                    "/" (int-to-string (mail-header-number headers)))
3849            gnus-article-save-directory)))
3850     (if (and last-file
3851              (string-equal (file-name-directory default)
3852                            (file-name-directory last-file))
3853              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3854         default
3855       (or last-file default))))
3856
3857 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3858   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3859 If variable `gnus-use-long-file-name' is non-nil, it is
3860 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3861   (or last-file
3862       (expand-file-name
3863        (if (gnus-use-long-file-name 'not-save)
3864            newsgroup
3865          (file-relative-name
3866           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3867           default-directory))
3868        gnus-article-save-directory)))
3869
3870 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3871   "Generate file name from sender."
3872   (let ((from (mail-header-from headers)))
3873     (expand-file-name
3874      (if (and from (string-match "\\([^ <]+\\)@" from))
3875          (match-string 1 from)
3876        "nobody")
3877      gnus-article-save-directory)))
3878
3879 (defun article-verify-x-pgp-sig ()
3880   "Verify X-PGP-Sig."
3881   (interactive)
3882   (if (gnus-buffer-live-p gnus-original-article-buffer)
3883       (let ((sig (with-current-buffer gnus-original-article-buffer
3884                    (gnus-fetch-field "X-PGP-Sig")))
3885             items info headers)
3886         (when (and sig
3887                    mml2015-use
3888                    (mml2015-clear-verify-function))
3889           (with-temp-buffer
3890             (insert-buffer-substring gnus-original-article-buffer)
3891             (setq items (split-string sig))
3892             (message-narrow-to-head)
3893             (let ((inhibit-point-motion-hooks t)
3894                   (case-fold-search t))
3895               ;; Don't verify multiple headers.
3896               (setq headers (mapconcat (lambda (header)
3897                                          (concat header ": "
3898                                                  (mail-fetch-field header)
3899                                                  "\n"))
3900                                        (split-string (nth 1 items) ",") "")))
3901             (delete-region (point-min) (point-max))
3902             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3903             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3904             (insert headers)
3905             (widen)
3906             (forward-line)
3907             (while (not (eobp))
3908               (if (looking-at "^-")
3909                   (insert "- "))
3910               (forward-line))
3911             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3912             (insert "Version: " (car items) "\n\n")
3913             (insert (mapconcat 'identity (cddr items) "\n"))
3914             (insert "\n-----END PGP SIGNATURE-----\n")
3915             (let ((mm-security-handle (list (format "multipart/signed"))))
3916               (mml2015-clean-buffer)
3917               (let ((coding-system-for-write (or gnus-newsgroup-charset
3918                                                  'iso-8859-1)))
3919                 (funcall (mml2015-clear-verify-function)))
3920               (setq info
3921                     (or (mm-handle-multipart-ctl-parameter
3922                          mm-security-handle 'gnus-details)
3923                         (mm-handle-multipart-ctl-parameter
3924                          mm-security-handle 'gnus-info)))))
3925           (when info
3926             (let ((inhibit-read-only t) bface eface)
3927               (save-restriction
3928                 (message-narrow-to-head)
3929                 (goto-char (point-max))
3930                 (forward-line -1)
3931                 (setq bface (get-text-property (point-at-bol) 'face)
3932                       eface (get-text-property (1- (point-at-eol)) 'face))
3933                 (message-remove-header "X-Gnus-PGP-Verify")
3934                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3935                     (forward-line)
3936                   (goto-char (point-max)))
3937                 (narrow-to-region (point) (point))
3938                 (insert "X-Gnus-PGP-Verify: " info "\n")
3939                 (goto-char (point-min))
3940                 (forward-line)
3941                 (while (not (eobp))
3942                   (if (not (looking-at "^[ \t]"))
3943                       (insert " "))
3944                   (forward-line))
3945                 ;; Do highlighting.
3946                 (goto-char (point-min))
3947                 (when (looking-at "\\([^:]+\\): *")
3948                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3949                                      'face bface)
3950                   (put-text-property (match-end 0) (point-max)
3951                                      'face eface)))))))))
3952
3953 (defun article-verify-cancel-lock ()
3954   "Verify Cancel-Lock header."
3955   (interactive)
3956   (if (gnus-buffer-live-p gnus-original-article-buffer)
3957       (canlock-verify gnus-original-article-buffer)))
3958
3959 (eval-and-compile
3960   (mapcar
3961    (lambda (func)
3962      (let (afunc gfunc)
3963        (if (consp func)
3964            (setq afunc (car func)
3965                  gfunc (cdr func))
3966          (setq afunc func
3967                gfunc (intern (format "gnus-%s" func))))
3968        (defalias gfunc
3969          (when (fboundp afunc)
3970            `(lambda (&optional interactive &rest args)
3971               ,(documentation afunc t)
3972               (interactive (list t))
3973               (save-excursion
3974                 (set-buffer gnus-article-buffer)
3975                 (if interactive
3976                     (call-interactively ',afunc)
3977                   (apply ',afunc args))))))))
3978    '(article-hide-headers
3979      article-verify-x-pgp-sig
3980      article-verify-cancel-lock
3981      article-hide-boring-headers
3982      article-treat-overstrike
3983      article-treat-ansi-sequences
3984      article-fill-long-lines
3985      article-capitalize-sentences
3986      article-remove-cr
3987      article-remove-leading-whitespace
3988      article-display-x-face
3989      article-display-face
3990      article-de-quoted-unreadable
3991      article-de-base64-unreadable
3992      article-decode-HZ
3993      article-wash-html
3994      article-unsplit-urls
3995      article-hide-list-identifiers
3996      article-strip-banner
3997      article-babel
3998      article-hide-pem
3999      article-hide-signature
4000      article-strip-headers-in-body
4001      article-remove-trailing-blank-lines
4002      article-strip-leading-blank-lines
4003      article-strip-multiple-blank-lines
4004      article-strip-leading-space
4005      article-strip-trailing-space
4006      article-strip-blank-lines
4007      article-strip-all-blank-lines
4008      article-date-local
4009      article-date-english
4010      article-date-iso8601
4011      article-date-original
4012      article-date-ut
4013      article-decode-mime-words
4014      article-decode-charset
4015      article-decode-encoded-words
4016      article-date-user
4017      article-date-lapsed
4018      article-emphasize
4019      article-treat-dumbquotes
4020      article-normalize-headers
4021 ;;     (article-show-all . gnus-article-show-all-headers)
4022      )))
4023 \f
4024 ;;;
4025 ;;; Gnus article mode
4026 ;;;
4027
4028 (put 'gnus-article-mode 'mode-class 'special)
4029
4030 (set-keymap-parent gnus-article-mode-map widget-keymap)
4031
4032 (gnus-define-keys gnus-article-mode-map
4033   " " gnus-article-goto-next-page
4034   "\177" gnus-article-goto-prev-page
4035   [delete] gnus-article-goto-prev-page
4036   [backspace] gnus-article-goto-prev-page
4037   "\C-c^" gnus-article-refer-article
4038   "h" gnus-article-show-summary
4039   "s" gnus-article-show-summary
4040   "\C-c\C-m" gnus-article-mail
4041   "?" gnus-article-describe-briefly
4042   "e" gnus-summary-edit-article
4043   "<" beginning-of-buffer
4044   ">" end-of-buffer
4045   "\C-c\C-i" gnus-info-find-node
4046   "\C-c\C-b" gnus-bug
4047   "R" gnus-article-reply-with-original
4048   "F" gnus-article-followup-with-original
4049   "\C-hk" gnus-article-describe-key
4050   "\C-hc" gnus-article-describe-key-briefly
4051
4052   "\C-d" gnus-article-read-summary-keys
4053   "\M-*" gnus-article-read-summary-keys
4054   "\M-#" gnus-article-read-summary-keys
4055   "\M-^" gnus-article-read-summary-keys
4056   "\M-g" gnus-article-read-summary-keys)
4057
4058 (substitute-key-definition
4059  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4060
4061 (defun gnus-article-make-menu-bar ()
4062   (unless (boundp 'gnus-article-commands-menu)
4063     (gnus-summary-make-menu-bar))
4064   (gnus-turn-off-edit-menu 'article)
4065   (unless (boundp 'gnus-article-article-menu)
4066     (easy-menu-define
4067      gnus-article-article-menu gnus-article-mode-map ""
4068      '("Article"
4069        ["Scroll forwards" gnus-article-goto-next-page t]
4070        ["Scroll backwards" gnus-article-goto-prev-page t]
4071        ["Show summary" gnus-article-show-summary t]
4072        ["Fetch Message-ID at point" gnus-article-refer-article t]
4073        ["Mail to address at point" gnus-article-mail t]
4074        ["Send a bug report" gnus-bug t]))
4075
4076     (easy-menu-define
4077      gnus-article-treatment-menu gnus-article-mode-map ""
4078      ;; Fixme: this should use :active (and maybe :visible).
4079      '("Treatment"
4080        ["Hide headers" gnus-article-hide-headers t]
4081        ["Hide signature" gnus-article-hide-signature t]
4082        ["Hide citation" gnus-article-hide-citation t]
4083        ["Treat overstrike" gnus-article-treat-overstrike t]
4084        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4085        ["Remove carriage return" gnus-article-remove-cr t]
4086        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4087        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4088        ["Remove base64" gnus-article-de-base64-unreadable t]
4089        ["Treat html" gnus-article-wash-html t]
4090        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4091        ["Decode HZ" gnus-article-decode-HZ t]))
4092
4093     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4094
4095     ;; Note "Post" menu is defined in gnus-sum.el for consistency
4096
4097     (gnus-run-hooks 'gnus-article-menu-hook)))
4098
4099 (defun gnus-article-mode ()
4100   "Major mode for displaying an article.
4101
4102 All normal editing commands are switched off.
4103
4104 The following commands are available in addition to all summary mode
4105 commands:
4106 \\<gnus-article-mode-map>
4107 \\[gnus-article-next-page]\t Scroll the article one page forwards
4108 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4109 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4110 \\[gnus-article-show-summary]\t Display the summary buffer
4111 \\[gnus-article-mail]\t Send a reply to the address near point
4112 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4113 \\[gnus-info-find-node]\t Go to the Gnus info node"
4114   (interactive)
4115   (kill-all-local-variables)
4116   (gnus-simplify-mode-line)
4117   (setq mode-name "Article")
4118   (setq major-mode 'gnus-article-mode)
4119   (make-local-variable 'minor-mode-alist)
4120   (use-local-map gnus-article-mode-map)
4121   (when (gnus-visual-p 'article-menu 'menu)
4122     (gnus-article-make-menu-bar)
4123     (when gnus-summary-tool-bar-map
4124       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4125   (gnus-update-format-specifications nil 'article-mode)
4126   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4127   (set (make-local-variable 'gnus-page-broken) nil)
4128   (make-local-variable 'gnus-button-marker-list)
4129   (make-local-variable 'gnus-article-current-summary)
4130   (make-local-variable 'gnus-article-mime-handles)
4131   (make-local-variable 'gnus-article-decoded-p)
4132   (make-local-variable 'gnus-article-mime-handle-alist)
4133   (make-local-variable 'gnus-article-wash-types)
4134   (make-local-variable 'gnus-article-image-alist)
4135   (make-local-variable 'gnus-article-charset)
4136   (make-local-variable 'gnus-article-ignored-charsets)
4137   ;; Prevent recent Emacsen from displaying non-break space as "\ ".
4138   (set (make-local-variable 'nobreak-char-display) nil)
4139   (setq cursor-in-non-selected-windows nil)
4140   (setq truncate-lines gnus-article-truncate-lines)
4141   (gnus-set-default-directory)
4142   (buffer-disable-undo)
4143   (setq buffer-read-only t
4144         show-trailing-whitespace nil)
4145   (set-syntax-table gnus-article-mode-syntax-table)
4146   (mm-enable-multibyte)
4147   (gnus-run-mode-hooks 'gnus-article-mode-hook))
4148
4149 (defvar gnus-button-marker-list nil
4150   "Regexp matching any of the regexps from `gnus-button-alist'.
4151 Internal variable.")
4152
4153 (defun gnus-article-setup-buffer ()
4154   "Initialize the article buffer."
4155   (let* ((name (if gnus-single-article-buffer "*Article*"
4156                  (concat "*Article " gnus-newsgroup-name "*")))
4157          (original
4158           (progn (string-match "\\*Article" name)
4159                  (concat " *Original Article"
4160                          (substring name (match-end 0))))))
4161     (setq gnus-article-buffer name)
4162     (setq gnus-original-article-buffer original)
4163     (setq gnus-article-mime-handle-alist nil)
4164     (with-current-buffer gnus-summary-buffer
4165       ;; This might be a variable local to the summary buffer.
4166       (unless gnus-single-article-buffer
4167         (setq gnus-article-buffer name)
4168         (setq gnus-original-article-buffer original)
4169         (gnus-set-global-variables)))
4170     (gnus-article-setup-highlight-words)
4171     ;; Init original article buffer.
4172     (save-excursion
4173       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4174       (mm-enable-multibyte)
4175       (setq major-mode 'gnus-original-article-mode)
4176       (make-local-variable 'gnus-original-article))
4177     (if (and (get-buffer name)
4178              (with-current-buffer name
4179                (if gnus-article-edit-mode
4180                    (if (y-or-n-p "Article mode edit in progress; discard? ")
4181                        (progn
4182                          (set-buffer-modified-p nil)
4183                          (gnus-kill-buffer name)
4184                          (message "")
4185                          nil)
4186                      (error "Action aborted"))
4187                  t)))
4188         (save-excursion
4189           (set-buffer name)
4190           (set (make-local-variable 'gnus-article-edit-mode) nil)
4191           (when gnus-article-mime-handles
4192             (mm-destroy-parts gnus-article-mime-handles)
4193             (setq gnus-article-mime-handles nil))
4194           ;; Set it to nil in article-buffer!
4195           (setq gnus-article-mime-handle-alist nil)
4196           (buffer-disable-undo)
4197           (setq buffer-read-only t)
4198           ;; This list just keeps growing if we don't reset it.
4199           (setq gnus-button-marker-list nil)
4200           (unless (eq major-mode 'gnus-article-mode)
4201             (gnus-article-mode))
4202           (current-buffer))
4203       (save-excursion
4204         (set-buffer (gnus-get-buffer-create name))
4205         (gnus-article-mode)
4206         (make-local-variable 'gnus-summary-buffer)
4207         (setq gnus-summary-buffer
4208               (gnus-summary-buffer-name gnus-newsgroup-name))
4209         (gnus-summary-set-local-parameters gnus-newsgroup-name)
4210         (current-buffer)))))
4211
4212 ;; Set article window start at LINE, where LINE is the number of lines
4213 ;; from the head of the article.
4214 (defun gnus-article-set-window-start (&optional line)
4215   (set-window-start
4216    (gnus-get-buffer-window gnus-article-buffer t)
4217    (save-excursion
4218      (set-buffer gnus-article-buffer)
4219      (goto-char (point-min))
4220      (if (not line)
4221          (point-min)
4222        (gnus-message 6 "Moved to bookmark")
4223        (search-forward "\n\n" nil t)
4224        (forward-line line)
4225        (point)))))
4226
4227 (defun gnus-article-prepare (article &optional all-headers header)
4228   "Prepare ARTICLE in article mode buffer.
4229 ARTICLE should either be an article number or a Message-ID.
4230 If ARTICLE is an id, HEADER should be the article headers.
4231 If ALL-HEADERS is non-nil, no headers are hidden."
4232   (save-excursion
4233     ;; Make sure we start in a summary buffer.
4234     (unless (eq major-mode 'gnus-summary-mode)
4235       (set-buffer gnus-summary-buffer))
4236     (setq gnus-summary-buffer (current-buffer))
4237     (let* ((gnus-article (if header (mail-header-number header) article))
4238            (summary-buffer (current-buffer))
4239            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4240            (group gnus-newsgroup-name)
4241            result)
4242       (save-excursion
4243         (gnus-article-setup-buffer)
4244         (set-buffer gnus-article-buffer)
4245         ;; Deactivate active regions.
4246         (when (and (boundp 'transient-mark-mode)
4247                    transient-mark-mode)
4248           (setq mark-active nil))
4249         (if (not (setq result (let ((inhibit-read-only t))
4250                                 (gnus-request-article-this-buffer
4251                                  article group))))
4252             ;; There is no such article.
4253             (save-excursion
4254               (when (and (numberp article)
4255                          (not (memq article gnus-newsgroup-sparse)))
4256                 (setq gnus-article-current
4257                       (cons gnus-newsgroup-name article))
4258                 (set-buffer gnus-summary-buffer)
4259                 (setq gnus-current-article article)
4260                 (if (and (memq article gnus-newsgroup-undownloaded)
4261                          (not (gnus-online (gnus-find-method-for-group
4262                                             gnus-newsgroup-name))))
4263                     (progn
4264                       (gnus-summary-set-agent-mark article)
4265                       (message "Message marked for downloading"))
4266                   (gnus-summary-mark-article article gnus-canceled-mark)
4267                   (unless (memq article gnus-newsgroup-sparse)
4268                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4269           (if (or (eq result 'pseudo)
4270                   (eq result 'nneething))
4271               (progn
4272                 (save-excursion
4273                   (set-buffer summary-buffer)
4274                   (push article gnus-newsgroup-history)
4275                   (setq gnus-last-article gnus-current-article
4276                         gnus-current-article 0
4277                         gnus-current-headers nil
4278                         gnus-article-current nil)
4279                   (if (eq result 'nneething)
4280                       (gnus-configure-windows 'summary)
4281                     (gnus-configure-windows 'article))
4282                   (gnus-set-global-variables))
4283                 (let ((gnus-article-mime-handle-alist-1
4284                        gnus-article-mime-handle-alist))
4285                   (gnus-set-mode-line 'article)))
4286             ;; The result from the `request' was an actual article -
4287             ;; or at least some text that is now displayed in the
4288             ;; article buffer.
4289             (when (and (numberp article)
4290                        (not (eq article gnus-current-article)))
4291               ;; Seems like a new article has been selected.
4292               ;; `gnus-current-article' must be an article number.
4293               (save-excursion
4294                 (set-buffer summary-buffer)
4295                 (push article gnus-newsgroup-history)
4296                 (setq gnus-last-article gnus-current-article
4297                       gnus-current-article article
4298                       gnus-current-headers
4299                       (gnus-summary-article-header gnus-current-article)
4300                       gnus-article-current
4301                       (cons gnus-newsgroup-name gnus-current-article))
4302                 (unless (vectorp gnus-current-headers)
4303                   (setq gnus-current-headers nil))
4304                 (gnus-summary-goto-subject gnus-current-article)
4305                 (when (gnus-summary-show-thread)
4306                   ;; If the summary buffer really was folded, the
4307                   ;; previous goto may not actually have gone to
4308                   ;; the right article, but the thread root instead.
4309                   ;; So we go again.
4310                   (gnus-summary-goto-subject gnus-current-article))
4311                 (gnus-run-hooks 'gnus-mark-article-hook)
4312                 (gnus-set-mode-line 'summary)
4313                 (when (gnus-visual-p 'article-highlight 'highlight)
4314                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4315                 ;; Set the global newsgroup variables here.
4316                 (gnus-set-global-variables)
4317                 (setq gnus-have-all-headers
4318                       (or all-headers gnus-show-all-headers))))
4319             (save-excursion
4320               (gnus-configure-windows 'article))
4321             (when (or (numberp article)
4322                       (stringp article))
4323               (gnus-article-prepare-display)
4324               ;; Do page break.
4325               (goto-char (point-min))
4326               (when gnus-break-pages
4327                 (gnus-narrow-to-page)))
4328             (let ((gnus-article-mime-handle-alist-1
4329                    gnus-article-mime-handle-alist))
4330               (gnus-set-mode-line 'article))
4331             (article-goto-body)
4332             (unless (bobp)
4333               (forward-line -1))
4334             (set-window-point (get-buffer-window (current-buffer)) (point))
4335             (gnus-configure-windows 'article)
4336             t))))))
4337
4338 ;;;###autoload
4339 (defun gnus-article-prepare-display ()
4340   "Make the current buffer look like a nice article."
4341   ;; Hooks for getting information from the article.
4342   ;; This hook must be called before being narrowed.
4343   (let ((gnus-article-buffer (current-buffer))
4344         buffer-read-only
4345         (inhibit-read-only t))
4346     (unless (eq major-mode 'gnus-article-mode)
4347       (gnus-article-mode))
4348     (setq buffer-read-only nil
4349           gnus-article-wash-types nil
4350           gnus-article-image-alist nil)
4351     (gnus-run-hooks 'gnus-tmp-internal-hook)
4352     (when gnus-display-mime-function
4353       (funcall gnus-display-mime-function))
4354     (gnus-run-hooks 'gnus-article-prepare-hook)))
4355
4356 ;;;
4357 ;;; Gnus MIME viewing functions
4358 ;;;
4359
4360 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4361   "Format of the MIME buttons.
4362
4363 Valid specifiers include:
4364 %t  The MIME type
4365 %T  MIME type, along with additional info
4366 %n  The `name' parameter
4367 %d  The description, if any
4368 %l  The length of the encoded part
4369 %p  The part identifier number
4370 %e  Dots if the part isn't displayed
4371
4372 General format specifiers can also be used.  See Info node
4373 `(gnus)Formatting Variables'.")
4374
4375 (defvar gnus-mime-button-line-format-alist
4376   '((?t gnus-tmp-type ?s)
4377     (?T gnus-tmp-type-long ?s)
4378     (?n gnus-tmp-name ?s)
4379     (?d gnus-tmp-description ?s)
4380     (?p gnus-tmp-id ?s)
4381     (?l gnus-tmp-length ?d)
4382     (?e gnus-tmp-dots ?s)))
4383
4384 (defvar gnus-mime-button-commands
4385   '((gnus-article-press-button "\r" "Toggle Display")
4386     (gnus-mime-view-part "v" "View Interactively...")
4387     (gnus-mime-view-part-as-type "t" "View As Type...")
4388     (gnus-mime-view-part-as-charset "C" "View As charset...")
4389     (gnus-mime-save-part "o" "Save...")
4390     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4391     (gnus-mime-replace-part "r" "Replace part")
4392     (gnus-mime-delete-part "d" "Delete part")
4393     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4394     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4395     (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4396     (gnus-mime-view-part-externally "e" "View Externally")
4397     (gnus-mime-print-part "p" "Print")
4398     (gnus-mime-pipe-part "|" "Pipe To Command...")
4399     (gnus-mime-action-on-part "." "Take action on the part...")))
4400
4401 (defun gnus-article-mime-part-status ()
4402   (if gnus-article-mime-handle-alist-1
4403       (if (eq 1 (length gnus-article-mime-handle-alist-1))
4404           " (1 part)"
4405         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4406     ""))
4407
4408 (defvar gnus-mime-button-map
4409   (let ((map (make-sparse-keymap)))
4410     (define-key map gnus-mouse-2 'gnus-article-push-button)
4411     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4412     (dolist (c gnus-mime-button-commands)
4413       (define-key map (cadr c) (car c)))
4414     map))
4415
4416 (easy-menu-define
4417   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4418   `("MIME Part"
4419     ,@(mapcar (lambda (c)
4420                 (vector (caddr c) (car c) :active t))
4421               gnus-mime-button-commands)))
4422
4423 (defun gnus-mime-button-menu (event prefix)
4424  "Construct a context-sensitive menu of MIME commands."
4425  (interactive "e\nP")
4426  (save-window-excursion
4427    (let ((pos (event-start event)))
4428      (select-window (posn-window pos))
4429      (goto-char (posn-point pos))
4430      (gnus-article-check-buffer)
4431      (popup-menu gnus-mime-button-menu nil prefix))))
4432
4433 (defun gnus-mime-view-all-parts (&optional handles)
4434   "View all the MIME parts."
4435   (interactive)
4436   (with-current-buffer gnus-article-buffer
4437     (let ((handles (or handles gnus-article-mime-handles))
4438           (mail-parse-charset gnus-newsgroup-charset)
4439           (mail-parse-ignored-charsets
4440            (with-current-buffer gnus-summary-buffer
4441              gnus-newsgroup-ignored-charsets)))
4442       (when handles
4443         (mm-remove-parts handles)
4444         (goto-char (point-min))
4445         (or (search-forward "\n\n") (goto-char (point-max)))
4446         (let ((inhibit-read-only t))
4447           (delete-region (point) (point-max))
4448           (mm-display-parts handles))))))
4449
4450 (defun gnus-article-jump-to-part (n)
4451   "Jump to MIME part N."
4452   (interactive "P")
4453   (pop-to-buffer gnus-article-buffer)
4454   ;; FIXME: why is it necessary?
4455   (sit-for 0)
4456   (let ((parts (length gnus-article-mime-handle-alist)))
4457     (or n (setq n
4458                 (string-to-number
4459                  (read-string ;; Emacs 21 doesn't have `read-number'.
4460                   (format "Jump to part (2..%s): " parts)))))
4461     (unless (and (integerp n) (<= n parts) (>= n 1))
4462       (setq n
4463             (progn
4464               (gnus-message 7 "Invalid part `%s', using %s instead."
4465                             n parts)
4466               parts)))
4467     (gnus-message 9 "Jumping to part %s." n)
4468     (cond ((>= gnus-auto-select-part 1)
4469            (while (and (<= n parts)
4470                        (not (gnus-article-goto-part n)))
4471              (setq n (1+ n))))
4472           ((< gnus-auto-select-part 0)
4473            (while (and (>= n 1)
4474                        (not (gnus-article-goto-part n)))
4475              (setq n (1- n))))
4476           (t
4477            (gnus-article-goto-part n)))))
4478
4479 (eval-when-compile
4480   (defsubst gnus-article-edit-part (handles &optional current-id)
4481     "Edit an article in order to delete a mime part.
4482 This function is exclusively used by `gnus-mime-save-part-and-strip'
4483 and `gnus-mime-delete-part', and not provided at run-time normally."
4484     (gnus-article-edit-article
4485      `(lambda ()
4486         (buffer-disable-undo)
4487         (erase-buffer)
4488         (let ((mail-parse-charset (or gnus-article-charset
4489                                       ',gnus-newsgroup-charset))
4490               (mail-parse-ignored-charsets
4491                (or gnus-article-ignored-charsets
4492                    ',gnus-newsgroup-ignored-charsets))
4493               (mbl mml-buffer-list))
4494           (setq mml-buffer-list nil)
4495           (insert-buffer-substring gnus-original-article-buffer)
4496           (mime-to-mml ',handles)
4497           (setq gnus-article-mime-handles nil)
4498           (let ((mbl1 mml-buffer-list))
4499             (setq mml-buffer-list mbl)
4500             (set (make-local-variable 'mml-buffer-list) mbl1))
4501           (gnus-make-local-hook 'kill-buffer-hook)
4502           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4503      `(lambda (no-highlight)
4504         (let ((mail-parse-charset (or gnus-article-charset
4505                                       ',gnus-newsgroup-charset))
4506               (message-options message-options)
4507               (message-options-set-recipient)
4508               (mail-parse-ignored-charsets
4509                (or gnus-article-ignored-charsets
4510                    ',gnus-newsgroup-ignored-charsets)))
4511           (mml-to-mime)
4512           (mml-destroy-buffers)
4513           (remove-hook 'kill-buffer-hook
4514                        'mml-destroy-buffers t)
4515           (kill-local-variable 'mml-buffer-list))
4516         (gnus-summary-edit-article-done
4517          ,(or (mail-header-references gnus-current-headers) "")
4518          ,(gnus-group-read-only-p)
4519          ,gnus-summary-buffer no-highlight))
4520      t)
4521     (gnus-article-edit-done)
4522     (gnus-summary-expand-window)
4523     (gnus-summary-show-article)
4524     (when (and current-id (integerp gnus-auto-select-part))
4525       (gnus-article-jump-to-part
4526        (+ current-id gnus-auto-select-part)))))
4527
4528 (defun gnus-mime-replace-part (file)
4529   "Replace MIME part under point with an external body."
4530   ;; Useful if file has already been saved to disk
4531   (interactive
4532    (list
4533     (mm-with-multibyte
4534       (read-file-name "Replace MIME part with file: "
4535                       (or mm-default-directory default-directory)
4536                       nil nil))))
4537   (gnus-mime-save-part-and-strip file))
4538
4539 (defun gnus-mime-save-part-and-strip (&optional file)
4540   "Save the MIME part under point then replace it with an external body.
4541 If FILE is given, use it for the external part."
4542   (interactive)
4543   (gnus-article-check-buffer)
4544   (when (gnus-group-read-only-p)
4545     (error "The current group does not support deleting of parts"))
4546   (when (mm-complicated-handles gnus-article-mime-handles)
4547     (error "\
4548 The current article has a complicated MIME structure, giving up..."))
4549   (let* ((data (get-text-property (point) 'gnus-data))
4550          (id (get-text-property (point) 'gnus-part))
4551          param
4552          (handles gnus-article-mime-handles))
4553     (unless file
4554       (setq file
4555             (and data (mm-save-part data "Delete MIME part and save to: "))))
4556     (when file
4557       (with-current-buffer (mm-handle-buffer data)
4558         (erase-buffer)
4559         (insert "Content-Type: " (mm-handle-media-type data))
4560         (mml-insert-parameter-string (cdr (mm-handle-type data))
4561                                      '(charset))
4562         ;; Add a filename for the sake of saving the part again.
4563         (mml-insert-parameter
4564          (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4565         (insert "\n")
4566         (insert "Content-ID: " (message-make-message-id) "\n")
4567         (insert "Content-Transfer-Encoding: binary\n")
4568         (insert "\n"))
4569       (setcdr data
4570               (cdr (mm-make-handle nil
4571                                    `("message/external-body"
4572                                      (access-type . "LOCAL-FILE")
4573                                      (name . ,file)))))
4574       ;; (set-buffer gnus-summary-buffer)
4575       (gnus-article-edit-part handles id))))
4576
4577 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4578 ;; parts...>') but with stripping would be nice.
4579
4580 (defun gnus-mime-delete-part ()
4581   "Delete the MIME part under point.
4582 Replace it with some information about the removed part."
4583   (interactive)
4584   (gnus-article-check-buffer)
4585   (when (gnus-group-read-only-p)
4586     (error "The current group does not support deleting of parts"))
4587   (when (mm-complicated-handles gnus-article-mime-handles)
4588     (error "\
4589 The current article has a complicated MIME structure, giving up..."))
4590   (when (or gnus-expert-user
4591             (gnus-yes-or-no-p "\
4592 Deleting parts may malfunction or destroy the article; continue? "))
4593     (let* ((data (get-text-property (point) 'gnus-data))
4594            (id (get-text-property (point) 'gnus-part))
4595            (handles gnus-article-mime-handles)
4596            (none "(none)")
4597            (description
4598             (mail-decode-encoded-word-string (or (mm-handle-description data)
4599                                                  none)))
4600            (filename
4601             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4602                 none))
4603            (type (mm-handle-media-type data)))
4604       (unless data
4605         (error "No MIME part under point"))
4606       (with-current-buffer (mm-handle-buffer data)
4607         (let ((bsize (format "%s" (buffer-size))))
4608           (erase-buffer)
4609           (insert
4610            (concat
4611             ",----\n"
4612             "| The following attachment has been deleted:\n"
4613             "|\n"
4614             "| Type:           " type "\n"
4615             "| Filename:       " filename "\n"
4616             "| Size (encoded): " bsize " Byte\n"
4617             "| Description:    " description "\n"
4618             "`----\n"))
4619           (setcdr data
4620                   (cdr (mm-make-handle
4621                         nil `("text/plain") nil nil
4622                         (list "attachment")
4623                         (format "Deleted attachment (%s bytes)" bsize))))))
4624       ;; (set-buffer gnus-summary-buffer)
4625       (gnus-article-edit-part handles id))))
4626
4627 (defun gnus-mime-save-part ()
4628   "Save the MIME part under point."
4629   (interactive)
4630   (gnus-article-check-buffer)
4631   (let ((data (get-text-property (point) 'gnus-data)))
4632     (when data
4633       (mm-save-part data))))
4634
4635 (defun gnus-mime-pipe-part ()
4636   "Pipe the MIME part under point to a process."
4637   (interactive)
4638   (gnus-article-check-buffer)
4639   (let ((data (get-text-property (point) 'gnus-data)))
4640     (when data
4641       (mm-pipe-part data))))
4642
4643 (defun gnus-mime-view-part ()
4644   "Interactively choose a viewing method for the MIME part under point."
4645   (interactive)
4646   (gnus-article-check-buffer)
4647   (let ((data (get-text-property (point) 'gnus-data)))
4648     (when data
4649       (setq gnus-article-mime-handles
4650             (mm-merge-handles
4651              gnus-article-mime-handles (setq data (copy-sequence data))))
4652       (mm-interactively-view-part data))))
4653
4654 (defun gnus-mime-view-part-as-type-internal ()
4655   (gnus-article-check-buffer)
4656   (let* ((handle (get-text-property (point) 'gnus-data))
4657          (name (or
4658                 ;; Content-Type: foo/bar; name=...
4659                 (mail-content-type-get (mm-handle-type handle) 'name)
4660                 ;; Content-Disposition: attachment; filename=...
4661                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4662          (def-type (and name (mm-default-file-encoding name))))
4663     (and def-type (cons def-type 0))))
4664
4665 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4666   "Choose a MIME media type, and view the part as such.
4667 If non-nil, PRED is a predicate to use during completion to limit the
4668 available media-types."
4669   (interactive)
4670   (unless mime-type
4671     (setq mime-type
4672           (let ((default (gnus-mime-view-part-as-type-internal)))
4673             (completing-read
4674              (format "View as MIME type (default %s): "
4675                      (car default))
4676              (mapcar #'list (mailcap-mime-types))
4677              pred nil nil nil
4678              (car default)))))
4679   (gnus-article-check-buffer)
4680   (let ((handle (get-text-property (point) 'gnus-data)))
4681     (when handle
4682       (when (equal (mm-handle-media-type handle) "message/external-body")
4683         (unless (mm-handle-cache handle)
4684           (mm-extern-cache-contents handle))
4685         (setq handle (mm-handle-cache handle)))
4686       (setq handle
4687             (mm-make-handle (mm-handle-buffer handle)
4688                             (cons mime-type (cdr (mm-handle-type handle)))
4689                             (mm-handle-encoding handle)
4690                             (mm-handle-undisplayer handle)
4691                             (mm-handle-disposition handle)
4692                             (mm-handle-description handle)
4693                             nil
4694                             (mm-handle-id handle)))
4695       (setq gnus-article-mime-handles
4696             (mm-merge-handles gnus-article-mime-handles handle))
4697       (gnus-mm-display-part handle))))
4698
4699 (defun gnus-mime-copy-part (&optional handle arg)
4700   "Put the MIME part under point into a new buffer.
4701 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4702 are decompressed."
4703   (interactive (list nil current-prefix-arg))
4704   (gnus-article-check-buffer)
4705   (unless handle
4706     (setq handle (get-text-property (point) 'gnus-data)))
4707   (when handle
4708     (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4709                                                'name)
4710                         (mail-content-type-get (mm-handle-disposition handle)
4711                                                'filename)))
4712           contents dont-decode charset coding-system)
4713       (mm-with-unibyte-buffer
4714         (mm-insert-part handle)
4715         (setq contents (or (condition-case nil
4716                                (mm-decompress-buffer filename nil 'sig)
4717                              (error
4718                               (setq dont-decode t)
4719                               nil))
4720                            (buffer-string))))
4721       (setq filename (cond (filename (file-name-nondirectory filename))
4722                            (dont-decode "*raw data*")
4723                            (t "*decoded*")))
4724       (cond
4725        (dont-decode)
4726        ((not arg)
4727         (unless (setq charset (mail-content-type-get
4728                                (mm-handle-type handle) 'charset))
4729           (unless (setq coding-system (mm-with-unibyte-buffer
4730                                         (insert contents)
4731                                         (mm-find-buffer-file-coding-system)))
4732             (setq charset gnus-newsgroup-charset))))
4733        ((numberp arg)
4734         (setq charset (or (cdr (assq arg
4735                                      gnus-summary-show-article-charset-alist))
4736                           (mm-read-coding-system "Charset: ")))))
4737       (switch-to-buffer (generate-new-buffer filename))
4738       (if (or coding-system
4739               (and charset
4740                    (setq coding-system (mm-charset-to-coding-system charset))
4741                    (not (eq charset 'ascii))))
4742           (progn
4743             (mm-enable-multibyte)
4744             (insert (mm-decode-coding-string contents coding-system))
4745             (setq buffer-file-coding-system
4746                   (if (boundp 'last-coding-system-used)
4747                       (symbol-value 'last-coding-system-used)
4748                     coding-system)))
4749         (mm-disable-multibyte)
4750         (insert contents)
4751         (setq buffer-file-coding-system mm-binary-coding-system))
4752       ;; We do it this way to make `normal-mode' set the appropriate mode.
4753       (unwind-protect
4754           (progn
4755             (setq buffer-file-name (expand-file-name filename))
4756             (normal-mode))
4757         (setq buffer-file-name nil))
4758       (goto-char (point-min)))))
4759
4760 (defun gnus-mime-print-part (&optional handle filename)
4761   "Print the MIME part under point."
4762   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4763   (gnus-article-check-buffer)
4764   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4765          (contents (and handle (mm-get-part handle)))
4766          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4767          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4768     (when contents
4769         (if printer
4770             (unwind-protect
4771                 (progn
4772                   (mm-save-part-to-file handle file)
4773                   (call-process shell-file-name nil
4774                                 (generate-new-buffer " *mm*")
4775                                 nil
4776                                 shell-command-switch
4777                                 (mm-mailcap-command
4778                                  printer file (mm-handle-type handle))))
4779               (delete-file file))
4780           (with-temp-buffer
4781             (insert contents)
4782             (gnus-print-buffer))
4783           (ps-despool filename)))))
4784
4785 (defun gnus-mime-inline-part (&optional handle arg)
4786   "Insert the MIME part under point into the current buffer.
4787 Compressed files like .gz and .bz2 are decompressed."
4788   (interactive (list nil current-prefix-arg))
4789   (gnus-article-check-buffer)
4790   (unless handle
4791     (setq handle (get-text-property (point) 'gnus-data)))
4792   (when handle
4793     (let ((b (point))
4794           (inhibit-read-only t)
4795           contents charset coding-system)
4796       (if (and (not arg) (mm-handle-undisplayer handle))
4797           (mm-remove-part handle)
4798         (mm-with-unibyte-buffer
4799           (mm-insert-part handle)
4800           (setq contents
4801                 (or (mm-decompress-buffer
4802                      (or (mail-content-type-get (mm-handle-type handle)
4803                                                 'name)
4804                          (mail-content-type-get (mm-handle-disposition handle)
4805                                                 'filename))
4806                      nil t)
4807                     (buffer-string))))
4808         (cond
4809          ((not arg)
4810           (unless (setq charset (mail-content-type-get
4811                                  (mm-handle-type handle) 'charset))
4812             (unless (setq coding-system
4813                           (mm-with-unibyte-buffer
4814                             (insert contents)
4815                             (mm-find-buffer-file-coding-system)))
4816               (setq charset gnus-newsgroup-charset))))
4817          ((numberp arg)
4818           (if (mm-handle-undisplayer handle)
4819               (mm-remove-part handle))
4820           (setq charset
4821                 (or (cdr (assq arg
4822                                gnus-summary-show-article-charset-alist))
4823                     (mm-read-coding-system "Charset: "))))
4824          (t
4825           (if (mm-handle-undisplayer handle)
4826               (mm-remove-part handle))))
4827         (forward-line 2)
4828         (mm-insert-inline
4829          handle
4830          (if (or coding-system
4831                  (and charset
4832                       (setq coding-system
4833                             (mm-charset-to-coding-system charset))
4834                       (not (eq coding-system 'ascii))))
4835              (mm-decode-coding-string contents coding-system)
4836            (mm-string-to-multibyte contents)))
4837         (goto-char b)))))
4838
4839 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4840   "Insert the MIME part under point into the current buffer using the
4841 specified charset."
4842   (interactive (list nil current-prefix-arg))
4843   (gnus-article-check-buffer)
4844   (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4845         (fun (get-text-property (point) 'gnus-callback))
4846         (gnus-newsgroup-ignored-charsets 'gnus-all)
4847         gnus-newsgroup-charset type charset)
4848     (when handle
4849       (if (mm-handle-undisplayer handle)
4850           (mm-remove-part handle))
4851       (when fun
4852         (setq gnus-newsgroup-charset
4853               (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4854                   (mm-read-coding-system "Charset: ")))
4855         ;; Strip the charset parameter from `handle'.
4856         (setq type (mm-handle-type
4857                     (if (equal (mm-handle-media-type handle)
4858                                "message/external-body")
4859                         (progn
4860                           (unless (mm-handle-cache handle)
4861                             (mm-extern-cache-contents handle))
4862                           (mm-handle-cache handle))
4863                       handle))
4864               charset (assq 'charset (cdr type)))
4865         (delq charset type)
4866         (funcall fun handle)))))
4867
4868 (defun gnus-mime-view-part-externally (&optional handle)
4869   "View the MIME part under point with an external viewer."
4870   (interactive)
4871   (gnus-article-check-buffer)
4872   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4873          (mm-user-display-methods nil)
4874          (mm-inlined-types nil)
4875          (mail-parse-charset gnus-newsgroup-charset)
4876          (mail-parse-ignored-charsets
4877           (with-current-buffer gnus-summary-buffer
4878             gnus-newsgroup-ignored-charsets))
4879          (type (mm-handle-media-type handle))
4880          (method (mailcap-mime-info type))
4881          (mm-enable-external t))
4882     (if (not (stringp method))
4883         (gnus-mime-view-part-as-type
4884          nil (lambda (type) (stringp (mailcap-mime-info type))))
4885       (when handle
4886         (if (mm-handle-undisplayer handle)
4887             (mm-remove-part handle)
4888           (mm-display-part handle))))))
4889
4890 (defun gnus-mime-view-part-internally (&optional handle)
4891   "View the MIME part under point with an internal viewer.
4892 If no internal viewer is available, use an external viewer."
4893   (interactive)
4894   (gnus-article-check-buffer)
4895   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4896          (mm-inlined-types '(".*"))
4897          (mm-inline-large-images t)
4898          (mail-parse-charset gnus-newsgroup-charset)
4899          (mail-parse-ignored-charsets
4900           (with-current-buffer gnus-summary-buffer
4901             gnus-newsgroup-ignored-charsets))
4902          (inhibit-read-only t))
4903     (if (not (mm-inlinable-p handle))
4904         (gnus-mime-view-part-as-type
4905          nil (lambda (type) (mm-inlinable-p handle type)))
4906       (when handle
4907         (if (mm-handle-undisplayer handle)
4908             (mm-remove-part handle)
4909           (mm-display-part handle))))))
4910
4911 (defun gnus-mime-action-on-part (&optional action)
4912   "Do something with the MIME attachment at \(point\)."
4913   (interactive
4914    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4915   (gnus-article-check-buffer)
4916   (let ((action-pair (assoc action gnus-mime-action-alist)))
4917     (if action-pair
4918         (funcall (cdr action-pair)))))
4919
4920 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4921   "Call FUNCTION on MIME part N.
4922 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4923 If INTERACTIVE, call FUNCTION interactivly."
4924   (let (window frame)
4925     ;; Check whether the article is displayed.
4926     (unless (and (gnus-buffer-live-p gnus-article-buffer)
4927                  (setq window (get-buffer-window gnus-article-buffer t))
4928                  (frame-visible-p (setq frame (window-frame window))))
4929       (error "No article is displayed"))
4930     (with-current-buffer gnus-article-buffer
4931       ;; Check whether the article displays the right contents.
4932       (unless (with-current-buffer gnus-summary-buffer
4933                 (eq gnus-current-article (gnus-summary-article-number)))
4934         (error "You should select the right article first"))
4935       ;; Check whether the specified part exists.
4936       (when (> n (length gnus-article-mime-handle-alist))
4937         (error "No such part")))
4938     (unless
4939         (progn
4940           ;; To select the window is needed so that the cursor
4941           ;; might be visible on the MIME button.
4942           (select-window (prog1
4943                              window
4944                            (setq window (selected-window))
4945                            ;; Article may be displayed in the other frame.
4946                            (gnus-select-frame-set-input-focus
4947                             (prog1
4948                                 frame
4949                               (setq frame (selected-frame))))))
4950           (when (gnus-article-goto-part n)
4951             ;; We point the cursor and the arrow at the MIME button
4952             ;; when the `function' prompt the user for something.
4953             (let ((cursor-in-non-selected-windows t)
4954                   (overlay-arrow-string "=>")
4955                   (overlay-arrow-position (point-marker)))
4956               (unwind-protect
4957                   (cond
4958                    ((and no-handle interactive)
4959                     (call-interactively function))
4960                    (no-handle
4961                     (funcall function))
4962                    (interactive
4963                     (call-interactively
4964                      function
4965                      (cdr (assq n gnus-article-mime-handle-alist))))
4966                    (t
4967                     (funcall function
4968                              (cdr (assq n gnus-article-mime-handle-alist)))))
4969                 (set-marker overlay-arrow-position nil)
4970                 (unless gnus-auto-select-part
4971                   (gnus-select-frame-set-input-focus frame)
4972                   (select-window window))))
4973             t))
4974       (if gnus-inhibit-mime-unbuttonizing
4975           ;; This is the default though the program shouldn't reach here.
4976           (error "No such part")
4977         ;; The part which doesn't have the MIME button is selected.
4978         ;; So, we display all the buttons and redo it.
4979         (let ((gnus-inhibit-mime-unbuttonizing t))
4980           (gnus-summary-show-article)
4981           (gnus-article-part-wrapper n function no-handle))))))
4982
4983 (defun gnus-article-pipe-part (n)
4984   "Pipe MIME part N, which is the numerical prefix."
4985   (interactive "p")
4986   (gnus-article-part-wrapper n 'mm-pipe-part))
4987
4988 (defun gnus-article-save-part (n)
4989   "Save MIME part N, which is the numerical prefix."
4990   (interactive "p")
4991   (gnus-article-part-wrapper n 'mm-save-part))
4992
4993 (defun gnus-article-interactively-view-part (n)
4994   "View MIME part N interactively, which is the numerical prefix."
4995   (interactive "p")
4996   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4997
4998 (defun gnus-article-copy-part (n)
4999   "Copy MIME part N, which is the numerical prefix."
5000   (interactive "p")
5001   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5002
5003 (defun gnus-article-view-part-as-charset (n)
5004   "View MIME part N using a specified charset.
5005 N is the numerical prefix."
5006   (interactive "p")
5007   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5008
5009 (defun gnus-article-view-part-externally (n)
5010   "View MIME part N externally, which is the numerical prefix."
5011   (interactive "p")
5012   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5013
5014 (defun gnus-article-inline-part (n)
5015   "Inline MIME part N, which is the numerical prefix."
5016   (interactive "p")
5017   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5018
5019 (defun gnus-article-save-part-and-strip (n)
5020   "Save MIME part N and replace it with an external body.
5021 N is the numerical prefix."
5022   (interactive "p")
5023   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5024
5025 (defun gnus-article-replace-part (n)
5026   "Replace MIME part N with an external body.
5027 N is the numerical prefix."
5028   (interactive "p")
5029   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5030
5031 (defun gnus-article-delete-part (n)
5032   "Delete MIME part N and add some information about the removed part.
5033 N is the numerical prefix."
5034   (interactive "p")
5035   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5036
5037 (defun gnus-article-view-part-as-type (n)
5038   "Choose a MIME media type, and view part N as such.
5039 N is the numerical prefix."
5040   (interactive "p")
5041   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5042
5043 (defun gnus-article-mime-match-handle-first (condition)
5044   (if condition
5045       (let (n)
5046         (dolist (ihandle gnus-article-mime-handle-alist)
5047           (if (and (cond
5048                     ((functionp condition)
5049                      (funcall condition (cdr ihandle)))
5050                     ((eq condition 'undisplayed)
5051                      (not (or (mm-handle-undisplayer (cdr ihandle))
5052                               (equal (mm-handle-media-type (cdr ihandle))
5053                                      "multipart/alternative"))))
5054                     ((eq condition 'undisplayed-alternative)
5055                      (not (mm-handle-undisplayer (cdr ihandle))))
5056                     (t t))
5057                    (gnus-article-goto-part (car ihandle))
5058                    (or (not n) (< (car ihandle) n)))
5059               (setq n (car ihandle))))
5060         (or n 1))
5061     1))
5062
5063 (defun gnus-article-view-part (&optional n)
5064   "View MIME part N, which is the numerical prefix."
5065   (interactive "P")
5066   (with-current-buffer gnus-article-buffer
5067     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5068                              gnus-article-mime-match-handle-function)))
5069     (when (> n (length gnus-article-mime-handle-alist))
5070       (error "No such part"))
5071     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5072       (when (gnus-article-goto-part n)
5073         (if (equal (car handle) "multipart/alternative")
5074             (gnus-article-press-button)
5075           (when (eq (gnus-mm-display-part handle) 'internal)
5076             (gnus-set-window-start)))))))
5077
5078 (defsubst gnus-article-mime-total-parts ()
5079   (if (bufferp (car gnus-article-mime-handles))
5080       1 ;; single part
5081     (1- (length gnus-article-mime-handles))))
5082
5083 (defun gnus-mm-display-part (handle)
5084   "Display HANDLE and fix MIME button."
5085   (let ((id (get-text-property (point) 'gnus-part))
5086         (point (point))
5087         (inhibit-read-only t))
5088     (forward-line 1)
5089     (prog1
5090         (let ((window (selected-window))
5091               (mail-parse-charset gnus-newsgroup-charset)
5092               (mail-parse-ignored-charsets
5093                (if (gnus-buffer-live-p gnus-summary-buffer)
5094                    (with-current-buffer gnus-summary-buffer
5095                      gnus-newsgroup-ignored-charsets)
5096                  nil)))
5097           (save-excursion
5098             (unwind-protect
5099                 (let ((win (gnus-get-buffer-window (current-buffer) t))
5100                       (beg (point)))
5101                   (when win
5102                     (select-window win))
5103                   (goto-char point)
5104                   (forward-line)
5105                   (if (mm-handle-displayed-p handle)
5106                       ;; This will remove the part.
5107                       (mm-display-part handle)
5108                     (save-restriction
5109                       (narrow-to-region (point)
5110                                         (if (eobp) (point) (1+ (point))))
5111                       (mm-display-part handle)
5112                       ;; We narrow to the part itself and
5113                       ;; then call the treatment functions.
5114                       (goto-char (point-min))
5115                       (forward-line 1)
5116                       (narrow-to-region (point) (point-max))
5117                       (gnus-treat-article
5118                        nil id
5119                        (gnus-article-mime-total-parts)
5120                        (mm-handle-media-type handle)))))
5121               (if (window-live-p window)
5122                   (select-window window)))))
5123       (goto-char point)
5124       (gnus-delete-line)
5125       (gnus-insert-mime-button
5126        handle id (list (mm-handle-displayed-p handle)))
5127       (goto-char point))))
5128
5129 (defun gnus-article-goto-part (n)
5130   "Go to MIME part N."
5131   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5132
5133 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5134   (let ((gnus-tmp-name
5135          (or (mail-content-type-get (mm-handle-type handle) 'name)
5136              (mail-content-type-get (mm-handle-disposition handle) 'filename)
5137              (mail-content-type-get (mm-handle-type handle) 'url)
5138              ""))
5139         (gnus-tmp-type (mm-handle-media-type handle))
5140         (gnus-tmp-description
5141          (mail-decode-encoded-word-string (or (mm-handle-description handle)
5142                                               "")))
5143         (gnus-tmp-dots
5144          (if (if displayed (car displayed)
5145                (mm-handle-displayed-p handle))
5146              "" "..."))
5147         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5148                            (buffer-size)))
5149         gnus-tmp-type-long b e)
5150     (when (string-match ".*/" gnus-tmp-name)
5151       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5152     (setq gnus-tmp-type-long (concat gnus-tmp-type
5153                                      (and (not (equal gnus-tmp-name ""))
5154                                           (concat "; " gnus-tmp-name))))
5155     (unless (equal gnus-tmp-description "")
5156       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5157     (unless (bolp)
5158       (insert "\n"))
5159     (setq b (point))
5160     (gnus-eval-format
5161      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5162      `(keymap ,gnus-mime-button-map
5163               gnus-callback gnus-mm-display-part
5164               gnus-part ,gnus-tmp-id
5165               article-type annotation
5166               gnus-data ,handle))
5167     (setq e (if (bolp)
5168                 ;; Exclude a newline.
5169                 (1- (point))
5170               (point)))
5171     (when gnus-article-button-face
5172       (gnus-overlay-put (gnus-make-overlay b e)
5173                         'face gnus-article-button-face))
5174     (widget-convert-button
5175      'link b e
5176      :mime-handle handle
5177      :action 'gnus-widget-press-button
5178      :button-keymap gnus-mime-button-map
5179      :help-echo
5180      (lambda (widget/window &optional overlay pos)
5181        ;; Needed to properly clear the message due to a bug in
5182        ;; wid-edit (XEmacs only).
5183        (if (boundp 'help-echo-owns-message)
5184            (setq help-echo-owns-message t))
5185        (format
5186         "%S: %s the MIME part; %S: more options"
5187         (aref gnus-mouse-2 0)
5188         ;; XEmacs will get a single widget arg; Emacs 21 will get
5189         ;; window, overlay, position.
5190         (if (mm-handle-displayed-p
5191              (if overlay
5192                  (with-current-buffer (gnus-overlay-buffer overlay)
5193                    (widget-get (widget-at (gnus-overlay-start overlay))
5194                                :mime-handle))
5195                (widget-get widget/window :mime-handle)))
5196             "hide" "show")
5197         (aref gnus-down-mouse-3 0))))))
5198
5199 (defun gnus-widget-press-button (elems el)
5200   (goto-char (widget-get elems :from))
5201   (gnus-article-press-button))
5202
5203 (defvar gnus-displaying-mime nil)
5204
5205 (defun gnus-display-mime (&optional ihandles)
5206   "Display the MIME parts."
5207   (save-excursion
5208     (save-selected-window
5209       (let ((window (get-buffer-window gnus-article-buffer))
5210             (point (point)))
5211         (when window
5212           (select-window window)
5213           ;; We have to do this since selecting the window
5214           ;; may change the point.  So we set the window point.
5215           (set-window-point window point)))
5216       (let ((handles ihandles)
5217             (inhibit-read-only t)
5218             handle)
5219         (cond (handles)
5220               ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5221                (when gnus-article-emulate-mime
5222                  (mm-uu-dissect-text-parts handles)))
5223               (gnus-article-emulate-mime
5224                (setq handles (mm-uu-dissect))))
5225         (when (and (not ihandles)
5226                    (not gnus-displaying-mime))
5227           ;; Top-level call; we clean up.
5228           (when gnus-article-mime-handles
5229             (mm-destroy-parts gnus-article-mime-handles)
5230             (setq gnus-article-mime-handle-alist nil));; A trick.
5231           (setq gnus-article-mime-handles handles)
5232           ;; We allow users to glean info from the handles.
5233           (when gnus-article-mime-part-function
5234             (gnus-mime-part-function handles)))
5235         (if (and handles
5236                  (or (not (stringp (car handles)))
5237                      (cdr handles)))
5238             (progn
5239               (when (and (not ihandles)
5240                          (not gnus-displaying-mime))
5241                 ;; Clean up for mime parts.
5242                 (article-goto-body)
5243                 (delete-region (point) (point-max)))
5244               (let ((gnus-displaying-mime t))
5245                 (gnus-mime-display-part handles)))
5246           (save-restriction
5247             (article-goto-body)
5248             (narrow-to-region (point) (point-max))
5249             (gnus-treat-article nil 1 1)
5250             (widen)))
5251         (unless ihandles
5252           ;; Highlight the headers.
5253           (save-excursion
5254             (save-restriction
5255               (article-goto-body)
5256               (narrow-to-region (point-min) (point))
5257               (gnus-article-save-original-date
5258                (gnus-treat-article 'head)))))))
5259     ;; Cope with broken MIME messages.
5260     (goto-char (point-max))
5261     (unless (bolp)
5262       (insert "\n"))))
5263
5264 (defcustom gnus-mime-display-multipart-as-mixed nil
5265   "Display \"multipart\" parts as  \"multipart/mixed\".
5266
5267 If t, it overrides nil values of
5268 `gnus-mime-display-multipart-alternative-as-mixed' and
5269 `gnus-mime-display-multipart-related-as-mixed'."
5270   :group 'gnus-article-mime
5271   :type 'boolean)
5272
5273 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5274   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
5275   :version "22.1"
5276   :group 'gnus-article-mime
5277   :type 'boolean)
5278
5279 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5280   "Display \"multipart/related\" parts as  \"multipart/mixed\".
5281
5282 If displaying \"text/html\" is discouraged \(see
5283 `mm-discouraged-alternatives'\) images or other material inside a
5284 \"multipart/related\" part might be overlooked when this variable is nil."
5285   :version "22.1"
5286   :group 'gnus-article-mime
5287   :type 'boolean)
5288
5289 (defun gnus-mime-display-part (handle)
5290   (cond
5291    ;; Maybe a broken MIME message.
5292    ((null handle))
5293    ;; Single part.
5294    ((not (stringp (car handle)))
5295     (gnus-mime-display-single handle))
5296    ;; User-defined multipart
5297    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5298     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5299              handle))
5300    ;; multipart/alternative
5301    ((and (equal (car handle) "multipart/alternative")
5302          (not (or gnus-mime-display-multipart-as-mixed
5303                   gnus-mime-display-multipart-alternative-as-mixed)))
5304     (let ((id (1+ (length gnus-article-mime-handle-alist))))
5305       (push (cons id handle) gnus-article-mime-handle-alist)
5306       (gnus-mime-display-alternative (cdr handle) nil nil id)))
5307    ;; multipart/related
5308    ((and (equal (car handle) "multipart/related")
5309          (not (or gnus-mime-display-multipart-as-mixed
5310                   gnus-mime-display-multipart-related-as-mixed)))
5311     ;;;!!!We should find the start part, but we just default
5312     ;;;!!!to the first part.
5313     ;;(gnus-mime-display-part (cadr handle))
5314     ;;;!!! Most multipart/related is an HTML message plus images.
5315     ;;;!!! Unfortunately we are unable to let W3 display those
5316     ;;;!!! included images, so we just display it as a mixed multipart.
5317     ;;(gnus-mime-display-mixed (cdr handle))
5318     ;;;!!! No, w3 can display everything just fine.
5319     (gnus-mime-display-part (cadr handle)))
5320    ((equal (car handle) "multipart/signed")
5321     (gnus-add-wash-type 'signed)
5322     (gnus-mime-display-security handle))
5323    ((equal (car handle) "multipart/encrypted")
5324     (gnus-add-wash-type 'encrypted)
5325     (gnus-mime-display-security handle))
5326    ;; Other multiparts are handled like multipart/mixed.
5327    (t
5328     (gnus-mime-display-mixed (cdr handle)))))
5329
5330 (defun gnus-mime-part-function (handles)
5331   (if (stringp (car handles))
5332       (mapcar 'gnus-mime-part-function (cdr handles))
5333     (funcall gnus-article-mime-part-function handles)))
5334
5335 (defun gnus-mime-display-mixed (handles)
5336   (mapcar 'gnus-mime-display-part handles))
5337
5338 (defun gnus-mime-display-single (handle)
5339   (let ((type (mm-handle-media-type handle))
5340         (ignored gnus-ignored-mime-types)
5341         (not-attachment t)
5342         (move nil)
5343         display text)
5344     (catch 'ignored
5345       (progn
5346         (while ignored
5347           (when (string-match (pop ignored) type)
5348             (throw 'ignored nil)))
5349         (if (and (setq not-attachment
5350                        (and (not (mm-inline-override-p handle))
5351                             (or (not (mm-handle-disposition handle))
5352                                 (equal (car (mm-handle-disposition handle))
5353                                        "inline")
5354                                 (mm-attachment-override-p handle))))
5355                  (mm-automatic-display-p handle)
5356                  (or (and
5357                       (mm-inlinable-p handle)
5358                       (mm-inlined-p handle))
5359                      (mm-automatic-external-display-p type)))
5360             (setq display t)
5361           (when (equal (mm-handle-media-supertype handle) "text")
5362             (setq text t)))
5363         (let ((id (1+ (length gnus-article-mime-handle-alist)))
5364               beg)
5365           (push (cons id handle) gnus-article-mime-handle-alist)
5366           (when (and display
5367                      (equal (mm-handle-media-supertype handle) "message"))
5368             (insert-char
5369              ?\n
5370              (cond ((not (bolp)) 2)
5371                    ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5372                    (t 1))))
5373           (when (or (not display)
5374                     (not (gnus-unbuttonized-mime-type-p type)))
5375             (gnus-insert-mime-button
5376              handle id (list (or display (and not-attachment text))))
5377             (gnus-article-insert-newline)
5378             ;; Remember modify the number of forward lines.
5379             (setq move t))
5380           (setq beg (point))
5381           (cond
5382            (display
5383             (when move
5384               (forward-line -1)
5385               (setq beg (point)))
5386             (let ((mail-parse-charset gnus-newsgroup-charset)
5387                   (mail-parse-ignored-charsets
5388                    (save-excursion (condition-case ()
5389                                        (set-buffer gnus-summary-buffer)
5390                                      (error))
5391                                    gnus-newsgroup-ignored-charsets)))
5392               (mm-display-part handle t))
5393             (goto-char (point-max)))
5394            ((and text not-attachment)
5395             (when move
5396               (forward-line -1)
5397               (setq beg (point)))
5398             (gnus-article-insert-newline)
5399             (mm-insert-inline
5400              handle
5401              (let ((charset (mail-content-type-get (mm-handle-type handle)
5402                                                    'charset)))
5403                (cond ((not charset)
5404                       (mm-string-as-multibyte (mm-get-part handle)))
5405                      ((eq charset 'gnus-decoded)
5406                       (with-current-buffer (mm-handle-buffer handle)
5407                         (buffer-string)))
5408                      (t
5409                       (mm-decode-string (mm-get-part handle) charset)))))
5410             (goto-char (point-max))))
5411           ;; Do highlighting.
5412           (save-excursion
5413             (save-restriction
5414               (narrow-to-region beg (point))
5415               (gnus-treat-article
5416                nil id
5417                (gnus-article-mime-total-parts)
5418                (mm-handle-media-type handle)))))))))
5419
5420 (defun gnus-unbuttonized-mime-type-p (type)
5421   "Say whether TYPE is to be unbuttonized."
5422   (unless gnus-inhibit-mime-unbuttonizing
5423     (when (catch 'found
5424             (let ((types gnus-unbuttonized-mime-types))
5425               (while types
5426                 (when (string-match (pop types) type)
5427                   (throw 'found t)))))
5428       (not (catch 'found
5429              (let ((types gnus-buttonized-mime-types))
5430                (while types
5431                  (when (string-match (pop types) type)
5432                    (throw 'found t)))))))))
5433
5434 (defun gnus-article-insert-newline ()
5435   "Insert a newline, but mark it as undeletable."
5436   (gnus-put-text-property
5437    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5438
5439 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5440   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5441          (ihandles handles)
5442          (point (point))
5443          handle (inhibit-read-only t) from props begend not-pref)
5444     (save-window-excursion
5445       (save-restriction
5446         (when ibegend
5447           (narrow-to-region (car ibegend)
5448                             (or (cdr ibegend)
5449                                 (progn
5450                                   (goto-char (car ibegend))
5451                                   (forward-line 2)
5452                                   (point))))
5453           (delete-region (point-min) (point-max))
5454           (mm-remove-parts handles))
5455         (setq begend (list (point-marker)))
5456         ;; Do the toggle.
5457         (unless (setq not-pref (cadr (member preferred ihandles)))
5458           (setq not-pref (car ihandles)))
5459         (when (or ibegend
5460                   (not preferred)
5461                   (not (gnus-unbuttonized-mime-type-p
5462                         "multipart/alternative")))
5463           (gnus-add-text-properties
5464            (setq from (point))
5465            (progn
5466              (insert (format "%d.  " id))
5467              (point))
5468            `(gnus-callback
5469              (lambda (handles)
5470                (unless ,(not ibegend)
5471                  (setq gnus-article-mime-handle-alist
5472                        ',gnus-article-mime-handle-alist))
5473                (gnus-mime-display-alternative
5474                 ',ihandles ',not-pref ',begend ,id))
5475              keymap ,gnus-mime-button-map
5476              ,gnus-mouse-face-prop ,gnus-article-mouse-face
5477              face ,gnus-article-button-face
5478              gnus-part ,id
5479              article-type multipart))
5480           (widget-convert-button 'link from (point)
5481                                  :action 'gnus-widget-press-button
5482                                  :button-keymap gnus-widget-button-keymap)
5483           ;; Do the handles
5484           (while (setq handle (pop handles))
5485             (gnus-add-text-properties
5486              (setq from (point))
5487              (progn
5488                (insert (format "(%c) %-18s"
5489                                (if (equal handle preferred) ?* ? )
5490                                (mm-handle-media-type handle)))
5491                (point))
5492              `(gnus-callback
5493                (lambda (handles)
5494                  (unless ,(not ibegend)
5495                    (setq gnus-article-mime-handle-alist
5496                          ',gnus-article-mime-handle-alist))
5497                  (gnus-mime-display-alternative
5498                   ',ihandles ',handle ',begend ,id))
5499                keymap ,gnus-mime-button-map
5500                ,gnus-mouse-face-prop ,gnus-article-mouse-face
5501                face ,gnus-article-button-face
5502                gnus-part ,id
5503                gnus-data ,handle))
5504             (widget-convert-button 'link from (point)
5505                                    :action 'gnus-widget-press-button
5506                                    :button-keymap gnus-widget-button-keymap)
5507             (insert "  "))
5508           (insert "\n\n"))
5509         (when preferred
5510           (if (stringp (car preferred))
5511               (gnus-display-mime preferred)
5512             (let ((mail-parse-charset gnus-newsgroup-charset)
5513                   (mail-parse-ignored-charsets
5514                    (with-current-buffer gnus-summary-buffer
5515                      gnus-newsgroup-ignored-charsets)))
5516               (mm-display-part preferred)
5517               ;; Do highlighting.
5518               (save-excursion
5519                 (save-restriction
5520                   (narrow-to-region (car begend) (point-max))
5521                   (gnus-treat-article
5522                    nil (length gnus-article-mime-handle-alist)
5523                    (gnus-article-mime-total-parts)
5524                    (mm-handle-media-type handle))))))
5525           (goto-char (point-max))
5526           (setcdr begend (point-marker)))))
5527     (when ibegend
5528       (goto-char point))))
5529
5530 (defconst gnus-article-wash-status-strings
5531   (let ((alist '((cite "c" "Possible hidden citation text"
5532                        " " "All citation text visible")
5533                  (headers "h" "Hidden headers"
5534                           " " "All headers visible.")
5535                  (pgp "p" "Encrypted or signed message status hidden"
5536                       " " "No hidden encryption nor digital signature status")
5537                  (signature "s" "Signature has been hidden"
5538                             " " "Signature is visible")
5539                  (overstrike "o" "Overstrike (^H) characters applied"
5540                              " " "No overstrike characters applied")
5541                  (emphasis "e" "/*_Emphasis_*/ characters applied"
5542                            " " "No /*_emphasis_*/ characters applied")))
5543         result)
5544     (dolist (entry alist result)
5545       (let ((key (nth 0 entry))
5546             (on (copy-sequence (nth 1 entry)))
5547             (on-help (nth 2 entry))
5548             (off (copy-sequence (nth 3 entry)))
5549             (off-help (nth 4 entry)))
5550         (put-text-property 0 1 'help-echo on-help on)
5551         (put-text-property 0 1 'help-echo off-help off)
5552         (push (list key on off) result))))
5553   "Alist of strings describing wash status in the mode line.
5554 Each entry has the form (KEY ON OF), where the KEY is a symbol
5555 representing the particular washing function, ON is the string to use
5556 in the article mode line when the washing function is active, and OFF
5557 is the string to use when it is inactive.")
5558
5559 (defun gnus-article-wash-status-entry (key value)
5560   (let ((entry (assoc key gnus-article-wash-status-strings)))
5561     (if value (nth 1 entry) (nth 2 entry))))
5562
5563 (defun gnus-article-wash-status ()
5564   "Return a string which display status of article washing."
5565   (with-current-buffer gnus-article-buffer
5566     (let ((cite (memq 'cite gnus-article-wash-types))
5567           (headers (memq 'headers gnus-article-wash-types))
5568           (boring (memq 'boring-headers gnus-article-wash-types))
5569           (pgp (memq 'pgp gnus-article-wash-types))
5570           (pem (memq 'pem gnus-article-wash-types))
5571           (signed (memq 'signed gnus-article-wash-types))
5572           (encrypted (memq 'encrypted gnus-article-wash-types))
5573           (signature (memq 'signature gnus-article-wash-types))
5574           (overstrike (memq 'overstrike gnus-article-wash-types))
5575           (emphasis (memq 'emphasis gnus-article-wash-types)))
5576       (concat
5577        (gnus-article-wash-status-entry 'cite cite)
5578        (gnus-article-wash-status-entry 'headers (or headers boring))
5579        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5580        (gnus-article-wash-status-entry 'signature signature)
5581        (gnus-article-wash-status-entry 'overstrike overstrike)
5582        (gnus-article-wash-status-entry 'emphasis emphasis)))))
5583
5584 (defun gnus-add-wash-type (type)
5585   "Add a washing of TYPE to the current status."
5586   (add-to-list 'gnus-article-wash-types type))
5587
5588 (defun gnus-delete-wash-type (type)
5589   "Add a washing of TYPE to the current status."
5590   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5591
5592 (defun gnus-add-image (category image)
5593   "Add IMAGE of CATEGORY to the list of displayed images."
5594   (let ((entry (assq category gnus-article-image-alist)))
5595     (unless entry
5596       (setq entry (list category))
5597       (push entry gnus-article-image-alist))
5598     (nconc entry (list image))))
5599
5600 (defun gnus-delete-images (category)
5601   "Delete all images in CATEGORY."
5602   (let ((entry (assq category gnus-article-image-alist)))
5603     (dolist (image (cdr entry))
5604       (gnus-remove-image image category))
5605     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5606     (gnus-delete-wash-type category)))
5607
5608 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5609
5610 (defun gnus-article-maybe-hide-headers ()
5611   "Hide unwanted headers if `gnus-have-all-headers' is nil.
5612 Provided for backwards compatibility."
5613   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5614                  (not (with-current-buffer gnus-summary-buffer
5615                         gnus-have-all-headers)))
5616              (not gnus-inhibit-hiding))
5617     (gnus-article-hide-headers)))
5618
5619 ;;; Article savers.
5620
5621 (defun gnus-output-to-file (file-name)
5622   "Append the current article to a file named FILE-NAME.
5623 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5624 text and used as the value of the coding cookie which is added to the
5625 top of a file.  Otherwise, this function saves a raw article without
5626 the coding cookie."
5627   (let* ((artbuf (current-buffer))
5628          (file-name-coding-system nnmail-pathname-coding-system)
5629          (coding gnus-article-save-coding-system)
5630          (coding-system-for-read (if coding
5631                                      nil ;; Rely on the coding cookie.
5632                                    mm-text-coding-system))
5633          (coding-system-for-write (or coding
5634                                       mm-text-coding-system-for-write
5635                                       mm-text-coding-system))
5636          (exists (file-exists-p file-name)))
5637     (with-temp-buffer
5638       (when exists
5639         (insert-file-contents file-name)
5640         (goto-char (point-min))
5641         ;; Remove the existing coding cookie.
5642         (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5643           (delete-region (match-beginning 0) (match-end 0))))
5644       (goto-char (point-max))
5645       (insert-buffer-substring artbuf)
5646       ;; Append newline at end of the buffer as separator, and then
5647       ;; save it to file.
5648       (goto-char (point-max))
5649       (insert "\n")
5650       (when coding
5651         ;; If the coding system is not suitable to encode the text,
5652         ;; ask a user for a proper one.
5653         (when (fboundp 'select-safe-coding-system)
5654           (setq coding (coding-system-base
5655                         (save-window-excursion
5656                           (select-safe-coding-system (point-min) (point-max)
5657                                                      coding))))
5658           (setq coding-system-for-write
5659                 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5660                     coding)))
5661         (goto-char (point-min))
5662         ;; Add the coding cookie.
5663         (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5664                         coding-system-for-write)))
5665       (if exists
5666           (progn
5667             (write-region (point-min) (point-max) file-name nil 'no-message)
5668             (message "Appended to %s" file-name))
5669         (write-region (point-min) (point-max) file-name))))
5670   t)
5671
5672 (defun gnus-narrow-to-page (&optional arg)
5673   "Narrow the article buffer to a page.
5674 If given a numerical ARG, move forward ARG pages."
5675   (interactive "P")
5676   (setq arg (if arg (prefix-numeric-value arg) 0))
5677   (save-excursion
5678     (set-buffer gnus-article-buffer)
5679     (goto-char (point-min))
5680     (widen)
5681     ;; Remove any old next/prev buttons.
5682     (when (gnus-visual-p 'page-marker)
5683       (let ((inhibit-read-only t))
5684         (gnus-remove-text-with-property 'gnus-prev)
5685         (gnus-remove-text-with-property 'gnus-next)))
5686     (if
5687         (cond ((< arg 0)
5688                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5689               ((> arg 0)
5690                (re-search-forward page-delimiter nil 'move arg)))
5691         (goto-char (match-end 0))
5692       (save-excursion
5693         (goto-char (point-min))
5694         (setq gnus-page-broken
5695               (and (re-search-forward page-delimiter nil t) t))))
5696     (when gnus-page-broken
5697       (narrow-to-region
5698        (point)
5699        (if (re-search-forward page-delimiter nil 'move)
5700            (match-beginning 0)
5701          (point)))
5702       (when (and (gnus-visual-p 'page-marker)
5703                  (> (point-min) (save-restriction (widen) (point-min))))
5704         (save-excursion
5705           (goto-char (point-min))
5706           (gnus-insert-prev-page-button)))
5707       (when (and (gnus-visual-p 'page-marker)
5708                  (< (point-max) (save-restriction (widen) (point-max))))
5709         (save-excursion
5710           (goto-char (point-max))
5711           (gnus-insert-next-page-button))))))
5712
5713 ;; Article mode commands
5714
5715 (defun gnus-article-goto-next-page ()
5716   "Show the next page of the article."
5717   (interactive)
5718   (when (gnus-article-next-page)
5719     (goto-char (point-min))
5720     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5721
5722
5723 (defun gnus-article-goto-prev-page ()
5724   "Show the previous page of the article."
5725   (interactive)
5726   (if (bobp)
5727       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5728     (gnus-article-prev-page nil)))
5729
5730 ;; This is cleaner but currently breaks `gnus-pick-mode':
5731 ;;
5732 ;; (defun gnus-article-goto-next-page ()
5733 ;;   "Show the next page of the article."
5734 ;;   (interactive)
5735 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5736 ;;     (gnus-summary-next-page)))
5737 ;;
5738 ;; (defun gnus-article-goto-prev-page ()
5739 ;;   "Show the next page of the article."
5740 ;;   (interactive)
5741 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5742 ;;     (gnus-summary-prev-page)))
5743
5744 (defun gnus-article-next-page (&optional lines)
5745   "Show the next page of the current article.
5746 If end of article, return non-nil.  Otherwise return nil.
5747 Argument LINES specifies lines to be scrolled up."
5748   (interactive "p")
5749   (move-to-window-line -1)
5750   (if (save-excursion
5751         (end-of-line)
5752         (and (pos-visible-in-window-p)  ;Not continuation line.
5753              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5754       ;; Nothing in this page.
5755       (if (or (not gnus-page-broken)
5756               (save-excursion
5757                 (save-restriction
5758                   (widen)
5759                   (forward-line)
5760                   (eobp)))) ;Real end-of-buffer?
5761           (progn
5762             (when gnus-article-over-scroll
5763               (gnus-article-next-page-1 lines))
5764             t)                  ;Nothing more.
5765         (gnus-narrow-to-page 1)         ;Go to next page.
5766         nil)
5767     ;; More in this page.
5768     (gnus-article-next-page-1 lines)
5769     nil))
5770
5771 (defmacro gnus-article-beginning-of-window ()
5772   "Move point to the beginning of the window.
5773 In Emacs, the point is placed at the line number which `scroll-margin'
5774 specifies."
5775   (if (featurep 'xemacs)
5776       '(move-to-window-line 0)
5777     '(move-to-window-line
5778       (min (max 0 scroll-margin)
5779            (max 1 (- (window-height)
5780                      (if mode-line-format 1 0)
5781                      (if header-line-format 1 0)))))))
5782
5783 (defun gnus-article-next-page-1 (lines)
5784   (when (and (not (featurep 'xemacs))
5785              (numberp lines)
5786              (> lines 0)
5787              (numberp (symbol-value 'scroll-margin))
5788              (> (symbol-value 'scroll-margin) 0))
5789     ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5790     ;; too many number of lines if `scroll-margin' is set as two or greater.
5791     (setq lines (min lines
5792                      (max 0 (- (count-lines (window-start) (point-max))
5793                                (symbol-value 'scroll-margin))))))
5794   (condition-case ()
5795       (let ((scroll-in-place nil))
5796         (scroll-up lines))
5797     (end-of-buffer
5798      ;; Long lines may cause an end-of-buffer error.
5799      (goto-char (point-max))))
5800   (gnus-article-beginning-of-window))
5801
5802 (defun gnus-article-prev-page (&optional lines)
5803   "Show previous page of current article.
5804 Argument LINES specifies lines to be scrolled down."
5805   (interactive "p")
5806   (move-to-window-line 0)
5807   (if (and gnus-page-broken
5808            (bobp)
5809            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5810       (progn
5811         (gnus-narrow-to-page -1)        ;Go to previous page.
5812         (goto-char (point-max))
5813         (recenter -1))
5814     (prog1
5815         (condition-case ()
5816             (let ((scroll-in-place nil))
5817               (scroll-down lines))
5818           (beginning-of-buffer
5819            (goto-char (point-min))))
5820       (gnus-article-beginning-of-window))))
5821
5822 (defun gnus-article-only-boring-p ()
5823   "Decide whether there is only boring text remaining in the article.
5824 Something \"interesting\" is a word of at least two letters that does
5825 not have a face in `gnus-article-boring-faces'."
5826   (when (and gnus-article-skip-boring
5827              (boundp 'gnus-article-boring-faces)
5828              (symbol-value 'gnus-article-boring-faces))
5829     (save-excursion
5830       (let ((inhibit-point-motion-hooks t))
5831         (catch 'only-boring
5832           (while (re-search-forward "\\b\\w\\w" nil t)
5833             (forward-char -1)
5834             (when (not (gnus-intersection
5835                         (gnus-faces-at (point))
5836                         (symbol-value 'gnus-article-boring-faces)))
5837               (throw 'only-boring nil)))
5838           (throw 'only-boring t))))))
5839
5840 (defun gnus-article-refer-article ()
5841   "Read article specified by message-id around point."
5842   (interactive)
5843   (save-excursion
5844     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5845     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5846     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5847         (let ((msg-id (concat "<" (match-string 0) ">")))
5848           (set-buffer gnus-summary-buffer)
5849           (gnus-summary-refer-article msg-id))
5850       (error "No references around point"))))
5851
5852 (defun gnus-article-show-summary ()
5853   "Reconfigure windows to show summary buffer."
5854   (interactive)
5855   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5856       (error "There is no summary buffer for this article buffer")
5857     (gnus-article-set-globals)
5858     (gnus-configure-windows 'article)
5859     (gnus-summary-goto-subject gnus-current-article)
5860     (gnus-summary-position-point)))
5861
5862 (defun gnus-article-describe-briefly ()
5863   "Describe article mode commands briefly."
5864   (interactive)
5865   (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")))
5866
5867 (defun gnus-article-summary-command ()
5868   "Execute the last keystroke in the summary buffer."
5869   (interactive)
5870   (let ((obuf (current-buffer))
5871         (owin (current-window-configuration))
5872         func)
5873     (switch-to-buffer gnus-article-current-summary 'norecord)
5874     (setq func (lookup-key (current-local-map) (this-command-keys)))
5875     (call-interactively func)
5876     (set-buffer obuf)
5877     (set-window-configuration owin)
5878     (set-window-point (get-buffer-window (current-buffer)) (point))))
5879
5880 (defun gnus-article-summary-command-nosave ()
5881   "Execute the last keystroke in the summary buffer."
5882   (interactive)
5883   (let (func)
5884     (pop-to-buffer gnus-article-current-summary 'norecord)
5885     (setq func (lookup-key (current-local-map) (this-command-keys)))
5886     (call-interactively func)))
5887
5888 (defun gnus-article-check-buffer ()
5889   "Beep if not in an article buffer."
5890   (unless (equal major-mode 'gnus-article-mode)
5891     (error "Command invoked outside of a Gnus article buffer")))
5892
5893 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5894   "Read a summary buffer key sequence and execute it from the article buffer."
5895   (interactive "P")
5896   (gnus-article-check-buffer)
5897   (let ((nosaves
5898          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5899            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5900            "=" "^" "\M-^" "|"))
5901         (nosave-but-article
5902          '("A\r"))
5903         (nosave-in-article
5904          '("\C-d"))
5905         (up-to-top
5906          '("n" "Gn" "p" "Gp"))
5907         keys new-sum-point)
5908     (save-excursion
5909       (set-buffer gnus-article-current-summary)
5910       (let (gnus-pick-mode)
5911         (push (or key last-command-event) unread-command-events)
5912         (setq keys (if (featurep 'xemacs)
5913                        (events-to-keys (read-key-sequence nil))
5914                      (read-key-sequence nil)))))
5915
5916     (message "")
5917
5918     (if (or (member keys nosaves)
5919             (member keys nosave-but-article)
5920             (member keys nosave-in-article))
5921         (let (func)
5922           (save-window-excursion
5923             (pop-to-buffer gnus-article-current-summary 'norecord)
5924             ;; We disable the pick minor mode commands.
5925             (let (gnus-pick-mode)
5926               (setq func (lookup-key (current-local-map) keys))))
5927           (if (or (not func)
5928                   (numberp func))
5929               (ding)
5930             (unless (member keys nosave-in-article)
5931               (set-buffer gnus-article-current-summary))
5932             (call-interactively func)
5933             (setq new-sum-point (point)))
5934           (when (member keys nosave-but-article)
5935             (pop-to-buffer gnus-article-buffer 'norecord)))
5936       ;; These commands should restore window configuration.
5937       (let ((obuf (current-buffer))
5938             (owin (current-window-configuration))
5939             (opoint (point))
5940             win func in-buffer selected new-sum-start new-sum-hscroll)
5941         (cond (not-restore-window
5942                (pop-to-buffer gnus-article-current-summary 'norecord))
5943               ((setq win (get-buffer-window gnus-article-current-summary))
5944                (select-window win))
5945               (t
5946                (switch-to-buffer gnus-article-current-summary 'norecord)))
5947         (setq in-buffer (current-buffer))
5948         ;; We disable the pick minor mode commands.
5949         (if (and (setq func (let (gnus-pick-mode)
5950                               (lookup-key (current-local-map) keys)))
5951                  (functionp func))
5952             (progn
5953               (call-interactively func)
5954               (when (eq win (selected-window))
5955                 (setq new-sum-point (point)
5956                       new-sum-start (window-start win)
5957                       new-sum-hscroll (window-hscroll win)))
5958               (when (eq in-buffer (current-buffer))
5959                 (setq selected (gnus-summary-select-article))
5960                 (set-buffer obuf)
5961                 (unless not-restore-window
5962                   (set-window-configuration owin))
5963                 (when (eq selected 'old)
5964                   (article-goto-body)
5965                   (set-window-start (get-buffer-window (current-buffer))
5966                                     1)
5967                   (set-window-point (get-buffer-window (current-buffer))
5968                                     (point)))
5969                 (when (and (not not-restore-window)
5970                            new-sum-point)
5971                   (set-window-point win new-sum-point)
5972                   (set-window-start win new-sum-start)
5973                   (set-window-hscroll win new-sum-hscroll))))
5974           (set-window-configuration owin)
5975           (ding))))))
5976
5977 (defun gnus-article-describe-key (key)
5978   "Display documentation of the function invoked by KEY.  KEY is a string."
5979   (interactive "kDescribe key: ")
5980   (gnus-article-check-buffer)
5981   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5982       (save-excursion
5983         (set-buffer gnus-article-current-summary)
5984         (let (gnus-pick-mode)
5985           (if (featurep 'xemacs)
5986               (progn
5987                 (push (elt key 0) unread-command-events)
5988                 (setq key (events-to-keys
5989                            (read-key-sequence "Describe key: "))))
5990             (setq unread-command-events
5991                   (mapcar
5992                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5993                    (string-to-list key)))
5994             (setq key (read-key-sequence "Describe key: "))))
5995         (describe-key key))
5996     (describe-key key)))
5997
5998 (defun gnus-article-describe-key-briefly (key &optional insert)
5999   "Display documentation of the function invoked by KEY.  KEY is a string."
6000   (interactive "kDescribe key: \nP")
6001   (gnus-article-check-buffer)
6002   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6003       (save-excursion
6004         (set-buffer gnus-article-current-summary)
6005         (let (gnus-pick-mode)
6006           (if (featurep 'xemacs)
6007               (progn
6008                 (push (elt key 0) unread-command-events)
6009                 (setq key (events-to-keys
6010                            (read-key-sequence "Describe key: "))))
6011             (setq unread-command-events
6012                   (mapcar
6013                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6014                    (string-to-list key)))
6015             (setq key (read-key-sequence "Describe key: "))))
6016         (describe-key-briefly key insert))
6017     (describe-key-briefly key insert)))
6018
6019 (defun gnus-article-reply-with-original (&optional wide)
6020   "Start composing a reply mail to the current message.
6021 The text in the region will be yanked.  If the region isn't active,
6022 the entire article will be yanked."
6023   (interactive "P")
6024   (let ((article (cdr gnus-article-current))
6025         contents)
6026     (if (not (gnus-region-active-p))
6027         (with-current-buffer gnus-summary-buffer
6028           (gnus-summary-reply (list (list article)) wide))
6029       (setq contents (buffer-substring (point) (mark t)))
6030       ;; Deactivate active regions.
6031       (when (and (boundp 'transient-mark-mode)
6032                  transient-mark-mode)
6033         (setq mark-active nil))
6034       (with-current-buffer gnus-summary-buffer
6035         (gnus-summary-reply
6036          (list (list article contents)) wide)))))
6037
6038 (defun gnus-article-followup-with-original ()
6039   "Compose a followup to the current article.
6040 The text in the region will be yanked.  If the region isn't active,
6041 the entire article will be yanked."
6042   (interactive)
6043   (let ((article (cdr gnus-article-current))
6044         contents)
6045       (if (not (gnus-region-active-p))
6046           (with-current-buffer gnus-summary-buffer
6047             (gnus-summary-followup (list (list article))))
6048         (setq contents (buffer-substring (point) (mark t)))
6049         ;; Deactivate active regions.
6050         (when (and (boundp 'transient-mark-mode)
6051                    transient-mark-mode)
6052           (setq mark-active nil))
6053         (with-current-buffer gnus-summary-buffer
6054           (gnus-summary-followup
6055            (list (list article contents)))))))
6056
6057 (defun gnus-article-hide (&optional arg force)
6058   "Hide all the gruft in the current article.
6059 This means that signatures, cited text and (some) headers will be
6060 hidden.
6061 If given a prefix, show the hidden text instead."
6062   (interactive (append (gnus-article-hidden-arg) (list 'force)))
6063   (gnus-article-hide-headers arg)
6064   (gnus-article-hide-list-identifiers arg)
6065   (gnus-article-hide-citation-maybe arg force)
6066   (gnus-article-hide-signature arg))
6067
6068 (defun gnus-article-maybe-highlight ()
6069   "Do some article highlighting if article highlighting is requested."
6070   (when (gnus-visual-p 'article-highlight 'highlight)
6071     (gnus-article-highlight-some)))
6072
6073 (defun gnus-check-group-server ()
6074   ;; Make sure the connection to the server is alive.
6075   (unless (gnus-server-opened
6076            (gnus-find-method-for-group gnus-newsgroup-name))
6077     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6078     (gnus-request-group gnus-newsgroup-name t)))
6079
6080 (eval-when-compile
6081   (autoload 'nneething-get-file-name "nneething"))
6082
6083 (defun gnus-request-article-this-buffer (article group)
6084   "Get an article and insert it into this buffer."
6085   (let (do-update-line sparse-header)
6086     (prog1
6087         (save-excursion
6088           (erase-buffer)
6089           (gnus-kill-all-overlays)
6090           (setq group (or group gnus-newsgroup-name))
6091
6092           ;; Using `gnus-request-article' directly will insert the article into
6093           ;; `nntp-server-buffer' - so we'll save some time by not having to
6094           ;; copy it from the server buffer into the article buffer.
6095
6096           ;; We only request an article by message-id when we do not have the
6097           ;; headers for it, so we'll have to get those.
6098           (when (stringp article)
6099             (gnus-read-header article))
6100
6101           ;; If the article number is negative, that means that this article
6102           ;; doesn't belong in this newsgroup (possibly), so we find its
6103           ;; message-id and request it by id instead of number.
6104           (when (and (numberp article)
6105                      gnus-summary-buffer
6106                      (get-buffer gnus-summary-buffer)
6107                      (gnus-buffer-exists-p gnus-summary-buffer))
6108             (save-excursion
6109               (set-buffer gnus-summary-buffer)
6110               (let ((header (gnus-summary-article-header article)))
6111                 (when (< article 0)
6112                   (cond
6113                    ((memq article gnus-newsgroup-sparse)
6114                     ;; This is a sparse gap article.
6115                     (setq do-update-line article)
6116                     (setq article (mail-header-id header))
6117                     (setq sparse-header (gnus-read-header article))
6118                     (setq gnus-newsgroup-sparse
6119                           (delq article gnus-newsgroup-sparse)))
6120                    ((vectorp header)
6121                     ;; It's a real article.
6122                     (setq article (mail-header-id header)))
6123                    (t
6124                     ;; It is an extracted pseudo-article.
6125                     (setq article 'pseudo)
6126                     (gnus-request-pseudo-article header))))
6127
6128                 (let ((method (gnus-find-method-for-group
6129                                gnus-newsgroup-name)))
6130                   (when (and (eq (car method) 'nneething)
6131                              (vectorp header))
6132                     (let ((dir (nneething-get-file-name
6133                                 (mail-header-id header))))
6134                       (when (and (stringp dir)
6135                                  (file-directory-p dir))
6136                         (setq article 'nneething)
6137                         (gnus-group-enter-directory dir))))))))
6138
6139           (cond
6140            ;; Refuse to select canceled articles.
6141            ((and (numberp article)
6142                  gnus-summary-buffer
6143                  (get-buffer gnus-summary-buffer)
6144                  (gnus-buffer-exists-p gnus-summary-buffer)
6145                  (eq (cdr (with-current-buffer gnus-summary-buffer
6146                             (assq article gnus-newsgroup-reads)))
6147                      gnus-canceled-mark))
6148             nil)
6149            ;; We first check `gnus-original-article-buffer'.
6150            ((and (get-buffer gnus-original-article-buffer)
6151                  (numberp article)
6152                  (with-current-buffer gnus-original-article-buffer
6153                    (and (equal (car gnus-original-article) group)
6154                         (eq (cdr gnus-original-article) article))))
6155             (insert-buffer-substring gnus-original-article-buffer)
6156             'article)
6157            ;; Check the backlog.
6158            ((and gnus-keep-backlog
6159                  (gnus-backlog-request-article group article (current-buffer)))
6160             'article)
6161            ;; Check asynchronous pre-fetch.
6162            ((gnus-async-request-fetched-article group article (current-buffer))
6163             (gnus-async-prefetch-next group article gnus-summary-buffer)
6164             (when (and (numberp article) gnus-keep-backlog)
6165               (gnus-backlog-enter-article group article (current-buffer)))
6166             'article)
6167            ;; Check the cache.
6168            ((and gnus-use-cache
6169                  (numberp article)
6170                  (gnus-cache-request-article article group))
6171             'article)
6172            ;; Check the agent cache.
6173            ((gnus-agent-request-article article group)
6174             'article)
6175            ;; Get the article and put into the article buffer.
6176            ((or (stringp article)
6177                 (numberp article))
6178             (let ((gnus-override-method gnus-override-method)
6179                   (methods (and (stringp article)
6180                                 gnus-refer-article-method))
6181                   (backend (car (gnus-find-method-for-group
6182                                  gnus-newsgroup-name)))
6183                   result
6184                   (inhibit-read-only t))
6185               (if (or (not (listp methods))
6186                       (and (symbolp (car methods))
6187                            (assq (car methods) nnoo-definition-alist)))
6188                   (setq methods (list methods)))
6189               (when (and (null gnus-override-method)
6190                          methods)
6191                 (setq gnus-override-method (pop methods)))
6192               (while (not result)
6193                 (when (eq gnus-override-method 'current)
6194                   (setq gnus-override-method
6195                         (with-current-buffer gnus-summary-buffer
6196                           gnus-current-select-method)))
6197                 (erase-buffer)
6198                 (gnus-kill-all-overlays)
6199                 (let ((gnus-newsgroup-name group))
6200                   (gnus-check-group-server))
6201                 (cond
6202                  ((gnus-request-article article group (current-buffer))
6203                   (when (numberp article)
6204                     (gnus-async-prefetch-next group article
6205                                               gnus-summary-buffer)
6206                     (when gnus-keep-backlog
6207                       (gnus-backlog-enter-article
6208                        group article (current-buffer))))
6209                   (setq result 'article))
6210                  (methods
6211                   (setq gnus-override-method (pop methods)))
6212                  ((not (string-match "^400 "
6213                                      (nnheader-get-report backend)))
6214                   ;; If we get 400 server disconnect, reconnect and
6215                   ;; retry; otherwise, assume the article has expired.
6216                   (setq result 'done))))
6217               (and (eq result 'article) 'article)))
6218            ;; It was a pseudo.
6219            (t article)))
6220
6221       ;; Associate this article with the current summary buffer.
6222       (setq gnus-article-current-summary gnus-summary-buffer)
6223
6224       ;; Take the article from the original article buffer
6225       ;; and place it in the buffer it's supposed to be in.
6226       (when (and (get-buffer gnus-article-buffer)
6227                  (equal (buffer-name (current-buffer))
6228                         (buffer-name (get-buffer gnus-article-buffer))))
6229         (save-excursion
6230           (if (get-buffer gnus-original-article-buffer)
6231               (set-buffer gnus-original-article-buffer)
6232             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6233             (buffer-disable-undo)
6234             (setq major-mode 'gnus-original-article-mode)
6235             (setq buffer-read-only t))
6236           (let ((inhibit-read-only t))
6237             (erase-buffer)
6238             (insert-buffer-substring gnus-article-buffer))
6239           (setq gnus-original-article (cons group article)))
6240
6241         ;; Decode charsets.
6242         (run-hooks 'gnus-article-decode-hook)
6243         ;; Mark article as decoded or not.
6244         (setq gnus-article-decoded-p gnus-article-decode-hook))
6245
6246       ;; Update sparse articles.
6247       (when (and do-update-line
6248                  (or (numberp article)
6249                      (stringp article)))
6250         (let ((buf (current-buffer)))
6251           (set-buffer gnus-summary-buffer)
6252           (gnus-summary-update-article do-update-line sparse-header)
6253           (gnus-summary-goto-subject do-update-line nil t)
6254           (set-window-point (gnus-get-buffer-window (current-buffer) t)
6255                             (point))
6256           (set-buffer buf))))))
6257
6258 ;;;
6259 ;;; Article editing
6260 ;;;
6261
6262 (defcustom gnus-article-edit-mode-hook nil
6263   "Hook run in article edit mode buffers."
6264   :group 'gnus-article-various
6265   :type 'hook)
6266
6267 (defvar gnus-article-edit-done-function nil)
6268
6269 (defvar gnus-article-edit-mode-map nil)
6270
6271 ;; Should we be using derived.el for this?
6272 (unless gnus-article-edit-mode-map
6273   (setq gnus-article-edit-mode-map (make-keymap))
6274   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6275
6276   (gnus-define-keys gnus-article-edit-mode-map
6277     "\C-c?"    describe-mode
6278     "\C-c\C-c" gnus-article-edit-done
6279     "\C-c\C-k" gnus-article-edit-exit
6280     "\C-c\C-f\C-t" message-goto-to
6281     "\C-c\C-f\C-o" message-goto-from
6282     "\C-c\C-f\C-b" message-goto-bcc
6283     ;;"\C-c\C-f\C-w" message-goto-fcc
6284     "\C-c\C-f\C-c" message-goto-cc
6285     "\C-c\C-f\C-s" message-goto-subject
6286     "\C-c\C-f\C-r" message-goto-reply-to
6287     "\C-c\C-f\C-n" message-goto-newsgroups
6288     "\C-c\C-f\C-d" message-goto-distribution
6289     "\C-c\C-f\C-f" message-goto-followup-to
6290     "\C-c\C-f\C-m" message-goto-mail-followup-to
6291     "\C-c\C-f\C-k" message-goto-keywords
6292     "\C-c\C-f\C-u" message-goto-summary
6293     "\C-c\C-f\C-i" message-insert-or-toggle-importance
6294     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6295     "\C-c\C-b" message-goto-body
6296     "\C-c\C-i" message-goto-signature
6297
6298     "\C-c\C-t" message-insert-to
6299     "\C-c\C-n" message-insert-newsgroups
6300     "\C-c\C-o" message-sort-headers
6301     "\C-c\C-e" message-elide-region
6302     "\C-c\C-v" message-delete-not-region
6303     "\C-c\C-z" message-kill-to-signature
6304     "\M-\r" message-newline-and-reformat
6305     "\C-c\C-a" mml-attach-file
6306     "\C-a" message-beginning-of-line
6307     "\t" message-tab
6308     "\M-;" comment-region)
6309
6310   (gnus-define-keys (gnus-article-edit-wash-map
6311                      "\C-c\C-w" gnus-article-edit-mode-map)
6312     "f" gnus-article-edit-full-stops))
6313
6314 (easy-menu-define
6315   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6316   '("Field"
6317     ["Fetch To" message-insert-to t]
6318     ["Fetch Newsgroups" message-insert-newsgroups t]
6319     "----"
6320     ["To" message-goto-to t]
6321     ["From" message-goto-from t]
6322     ["Subject" message-goto-subject t]
6323     ["Cc" message-goto-cc t]
6324     ["Reply-To" message-goto-reply-to t]
6325     ["Summary" message-goto-summary t]
6326     ["Keywords" message-goto-keywords t]
6327     ["Newsgroups" message-goto-newsgroups t]
6328     ["Followup-To" message-goto-followup-to t]
6329     ["Mail-Followup-To" message-goto-mail-followup-to t]
6330     ["Distribution" message-goto-distribution t]
6331     ["Body" message-goto-body t]
6332     ["Signature" message-goto-signature t]))
6333
6334 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6335   "Major mode for editing articles.
6336 This is an extended text-mode.
6337
6338 \\{gnus-article-edit-mode-map}"
6339   (make-local-variable 'gnus-article-edit-done-function)
6340   (make-local-variable 'gnus-prev-winconf)
6341   (set (make-local-variable 'font-lock-defaults)
6342        '(message-font-lock-keywords t))
6343   (set (make-local-variable 'mail-header-separator) "")
6344   (set (make-local-variable 'gnus-article-edit-mode) t)
6345   (easy-menu-add message-mode-field-menu message-mode-map)
6346   (mml-mode)
6347   (setq buffer-read-only nil)
6348   (buffer-enable-undo)
6349   (widen))
6350
6351 (defun gnus-article-edit (&optional force)
6352   "Edit the current article.
6353 This will have permanent effect only in mail groups.
6354 If FORCE is non-nil, allow editing of articles even in read-only
6355 groups."
6356   (interactive "P")
6357   (when (and (not force)
6358              (gnus-group-read-only-p))
6359     (error "The current newsgroup does not support article editing"))
6360   (gnus-article-date-original)
6361   (gnus-article-edit-article
6362    'ignore
6363    `(lambda (no-highlight)
6364       'ignore
6365       (gnus-summary-edit-article-done
6366        ,(or (mail-header-references gnus-current-headers) "")
6367        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6368
6369 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6370   "Start editing the contents of the current article buffer."
6371   (let ((winconf (current-window-configuration)))
6372     (set-buffer gnus-article-buffer)
6373     (let ((message-auto-save-directory
6374            ;; Don't associate the article buffer with a draft file.
6375            nil))
6376       (gnus-article-edit-mode))
6377     (funcall start-func)
6378     (set-buffer-modified-p nil)
6379     (gnus-configure-windows 'edit-article)
6380     (setq gnus-article-edit-done-function exit-func)
6381     (setq gnus-prev-winconf winconf)
6382     (unless quiet
6383       (gnus-message 6 "C-c C-c to end edits"))))
6384
6385 (defun gnus-article-edit-done (&optional arg)
6386   "Update the article edits and exit."
6387   (interactive "P")
6388   (let ((func gnus-article-edit-done-function)
6389         (buf (current-buffer))
6390         (start (window-start))
6391         (p (point))
6392         (winconf gnus-prev-winconf))
6393     (widen) ;; Widen it in case that users narrowed the buffer.
6394     (funcall func arg)
6395     (set-buffer buf)
6396     ;; The cache and backlog have to be flushed somewhat.
6397     (when gnus-keep-backlog
6398       (gnus-backlog-remove-article
6399        (car gnus-article-current) (cdr gnus-article-current)))
6400     ;; Flush original article as well.
6401     (save-excursion
6402       (when (get-buffer gnus-original-article-buffer)
6403         (set-buffer gnus-original-article-buffer)
6404         (setq gnus-original-article nil)))
6405     (when gnus-use-cache
6406       (gnus-cache-update-article
6407        (car gnus-article-current) (cdr gnus-article-current)))
6408     ;; We remove all text props from the article buffer.
6409     (kill-all-local-variables)
6410     (set-text-properties (point-min) (point-max) nil)
6411     (gnus-article-mode)
6412     (set-window-configuration winconf)
6413     (set-buffer buf)
6414     (set-window-start (get-buffer-window buf) start)
6415     (set-window-point (get-buffer-window buf) (point)))
6416   (gnus-summary-show-article))
6417
6418 (defun gnus-article-edit-exit ()
6419   "Exit the article editing without updating."
6420   (interactive)
6421   (when (or (not (buffer-modified-p))
6422             (yes-or-no-p "Article modified; kill anyway? "))
6423     (let ((curbuf (current-buffer))
6424           (p (point))
6425           (window-start (window-start)))
6426       (erase-buffer)
6427       (if (gnus-buffer-live-p gnus-original-article-buffer)
6428           (insert-buffer-substring gnus-original-article-buffer))
6429       (let ((winconf gnus-prev-winconf))
6430         (kill-all-local-variables)
6431         (gnus-article-mode)
6432         (set-window-configuration winconf)
6433         ;; Tippy-toe some to make sure that point remains where it was.
6434         (save-current-buffer
6435           (set-buffer curbuf)
6436           (set-window-start (get-buffer-window (current-buffer)) window-start)
6437           (goto-char p))))
6438     (gnus-summary-show-article)))
6439
6440 (defun gnus-article-edit-full-stops ()
6441   "Interactively repair spacing at end of sentences."
6442   (interactive)
6443   (save-excursion
6444     (goto-char (point-min))
6445     (search-forward-regexp "^$" nil t)
6446     (let ((case-fold-search nil))
6447       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6448
6449 ;;;
6450 ;;; Article highlights
6451 ;;;
6452
6453 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6454
6455 ;;; Internal Variables:
6456
6457 (defcustom gnus-button-url-regexp
6458   (concat
6459    "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6460    "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6461    "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6462    (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6463        "[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]"
6464      (concat ;; XEmacs 21.4 doesn't support POSIX.
6465       "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6466       "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6467    "\\)")
6468   "Regular expression that matches URLs."
6469   :group 'gnus-article-buttons
6470   :type 'regexp)
6471
6472 (defcustom gnus-button-valid-fqdn-regexp
6473   message-valid-fqdn-regexp
6474   "Regular expression that matches a valid FQDN."
6475   :version "22.1"
6476   :group 'gnus-article-buttons
6477   :type 'regexp)
6478
6479 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6480 (defcustom gnus-button-valid-localpart-regexp
6481   "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6482   "Regular expression that matches a localpart of mail addresses or MIDs."
6483   :version "22.1"
6484   :group 'gnus-article-buttons
6485   :type 'regexp)
6486
6487 (defcustom gnus-button-man-handler 'manual-entry
6488   "Function to use for displaying man pages.
6489 The function must take at least one argument with a string naming the
6490 man page."
6491   :version "22.1"
6492   :type '(choice (function-item :tag "Man" manual-entry)
6493                  (function-item :tag "Woman" woman)
6494                  (function :tag "Other"))
6495   :group 'gnus-article-buttons)
6496
6497 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6498   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6499 If the default site is too slow, try to find a CTAN mirror, see
6500 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
6501 the variable `gnus-button-handle-ctan'."
6502   :version "22.1"
6503   :group 'gnus-article-buttons
6504   :link '(custom-manual "(gnus)Group Parameters")
6505   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6506                  (const "http://tug.ctan.org/tex-archive/")
6507                  (const "http://www.dante.de/CTAN/")
6508                  (string :tag "Other")))
6509
6510 (defcustom gnus-button-ctan-handler 'browse-url
6511   "Function to use for displaying CTAN links.
6512 The function must take one argument, the string naming the URL."
6513   :version "22.1"
6514   :type '(choice (function-item :tag "Browse Url" browse-url)
6515                  (function :tag "Other"))
6516   :group 'gnus-article-buttons)
6517
6518 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6519   "Bogus strings removed from CTAN URLs."
6520   :version "22.1"
6521   :group 'gnus-article-buttons
6522   :type '(choice (const "^/?tex-archive/\\|/")
6523                  (regexp :tag "Other")))
6524
6525 (defcustom gnus-button-ctan-directory-regexp
6526   (regexp-opt
6527    (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6528          "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6529          "languages" "macros" "nonfree" "obsolete" "support" "systems"
6530          "tds" "tools" "usergrps" "web") t)
6531   "Regular expression for ctan directories.
6532 It should match all directories in the top level of `gnus-ctan-url'."
6533   :version "22.1"
6534   :group 'gnus-article-buttons
6535   :type 'regexp)
6536
6537 (defcustom gnus-button-mid-or-mail-regexp
6538   (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6539           gnus-button-valid-fqdn-regexp
6540           ">?\\)\\b")
6541   "Regular expression that matches a message ID or a mail address."
6542   :version "22.1"
6543   :group 'gnus-article-buttons
6544   :type 'regexp)
6545
6546 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6547   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6548 Strings like this can be either a message ID or a mail address.  If it is one
6549 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6550 message ID or a mail address, respectively.  If this variable is set to the
6551 symbol `ask', always query the user what do do.  If it is a function, this
6552 function will be called with the string as it's only argument.  The function
6553 must return `mid', `mail', `invalid' or `ask'."
6554   :version "22.1"
6555   :group 'gnus-article-buttons
6556   :type '(choice (function-item :tag "Heuristic function"
6557                                 gnus-button-mid-or-mail-heuristic)
6558                  (const ask)
6559                  (const mid)
6560                  (const mail)))
6561
6562 (defcustom gnus-button-mid-or-mail-heuristic-alist
6563   '((-10.0 . ".+\\$.+@")
6564     (-10.0 . "#")
6565     (-10.0 . "\\*")
6566     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
6567     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6568     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6569     (-1.0  . "^[^a-z]+@")
6570     ;;
6571     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6572     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6573     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
6574     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6575     ;;
6576     (-2.0  . "^[0-9]")
6577     (-1.0  . "^[0-9][0-9]")
6578     ;;
6579     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6580     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6581     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6582     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6583     ;;
6584     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6585     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6586     ;;       "[0-9]{8,}.*\@"
6587     (-3.0
6588      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6589     ;; "[0-9]{12,}.*\@"
6590     ;; compensation for TDMA dated mail addresses:
6591     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6592     ;;
6593     (-20.0 . "\\.fsf@") ;; Gnus
6594     (-20.0 . "^slrn")
6595     (-20.0 . "^Pine")
6596     (-20.0 . "_-_") ;; Subject change in thread
6597     ;;
6598     (-20.0 . "\\.ln@") ;; leafnode
6599     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6600     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6601     ;;
6602     ;; (5.0 . "") ;; $local_part_len <= 7
6603     (10.0  . "^[^0-9]+@")
6604     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6605     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6606     (3.0   . "\@stud")
6607     ;;
6608     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
6609     ;;
6610     (0.5   . "^[A-Z][a-z]")
6611     (0.5   . "^[A-Z][a-z][a-z]")
6612     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6613     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6614   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6615
6616 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6617 address.  The REGEXP is processed with `case-fold-search' set to nil."
6618   :version "22.1"
6619   :group 'gnus-article-buttons
6620   :type '(repeat (cons (number :tag "Rate")
6621                        (regexp :tag "Regexp"))))
6622
6623 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6624   "Guess whether MID-OR-MAIL is a message ID or a mail address.
6625 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6626 address, `ask' if unsure and `invalid' if the string is invalid."
6627   (let ((case-fold-search nil)
6628         (list gnus-button-mid-or-mail-heuristic-alist)
6629         (result 0) rate regexp lpartlen elem)
6630     (setq lpartlen
6631           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6632     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6633     ;; Certain special cases...
6634     (when (string-match
6635            (concat
6636             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6637             "^[0-9]+\\.[0-9]+@compuserve\\|"
6638             "@public\\.gmane\\.org")
6639            mid-or-mail)
6640       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6641       (setq result 'mail))
6642     (when (string-match "@.*@\\| " mid-or-mail)
6643       (gnus-message 8 "`%s' is invalid." mid-or-mail)
6644       (setq result 'invalid))
6645     ;; Nothing more to do, if result is not a number here...
6646     (when (numberp result)
6647       (while list
6648         (setq elem (car list)
6649               rate (car elem)
6650               regexp (cdr elem)
6651               list (cdr list))
6652         (when (string-match regexp mid-or-mail)
6653           (setq result (+ result rate))
6654           (gnus-message
6655            9 "`%s' matched `%s', rate `%s', result `%s'."
6656            mid-or-mail regexp rate result)))
6657       (when (<= lpartlen 7)
6658         (setq result (+ result 5.0))
6659         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6660                       mid-or-mail result))
6661       (when (>= lpartlen 12)
6662         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6663         (cond
6664          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6665           ;; Long local part should contain realname if e-mail address,
6666           ;; too many digits: message-id.
6667           ;; $score -= 5.0 + 0.1 * $local_part_len;
6668           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6669           (setq result (+ result rate))
6670           (gnus-message
6671            9 "Many digits in `%s', rate `%s', result `%s'."
6672            mid-or-mail rate result))
6673          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6674                         mid-or-mail)
6675           ;; Too few vowels [^aeiouy]{4,}.*\@
6676           (setq result (+ result -5.0))
6677           (gnus-message
6678            9 "Few vowels in `%s', rate `%s', result `%s'."
6679            mid-or-mail -5.0 result))
6680          (t
6681           (setq result (+ result 5.0))
6682           (gnus-message
6683            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6684     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6685     ;; Maybe we should make this a customizable alist: (condition . 'result)
6686     (cond
6687      ((symbolp result) result)
6688      ;; Now convert number into proper results:
6689      ((< result -10.0) 'mid)
6690      ((> result  10.0) 'mail)
6691      (t 'ask))))
6692
6693 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6694   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6695          (url-mid (concat "news" ":" mid-or-mail))
6696          (url-mailto (concat "mailto" ":" mid-or-mail)))
6697     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6698     (when (fboundp pref)
6699       (setq guessed
6700             ;; get rid of surrounding angles...
6701             (funcall pref
6702                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6703       (if (or (eq 'mid guessed) (eq 'mail guessed))
6704           (setq pref guessed)
6705         (setq pref 'ask)))
6706     (if (eq pref 'ask)
6707         (save-window-excursion
6708           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6709               (setq pref 'mail)
6710             (setq pref 'mid))))
6711     (cond ((eq pref 'mid)
6712            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6713            (gnus-button-handle-news url-mid))
6714           ((eq pref 'mail)
6715            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
6716            (gnus-url-mailto url-mailto))
6717           (t (gnus-message 3 "Invalid string.")))))
6718
6719 (defun gnus-button-handle-custom (fun arg)
6720   "Call function FUN on argument ARG.
6721 Both FUN and ARG are supposed to be strings.  ARG will be passed
6722 as a symbol to FUN."
6723   (funcall (intern fun)
6724            (if (string-match "^customize-apropos" fun)
6725                arg
6726              (intern arg))))
6727
6728 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6729
6730 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6731 ;; stuff?
6732
6733 (defun gnus-button-handle-describe-function (url)
6734   "Call `describe-function' when pushing the corresponding URL button."
6735   (describe-function
6736    (intern
6737     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6738
6739 (defun gnus-button-handle-describe-variable (url)
6740   "Call `describe-variable' when pushing the corresponding URL button."
6741   (describe-variable
6742    (intern
6743     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6744
6745 (defun gnus-button-handle-symbol (url)
6746 "Display help on variable or function.
6747 Calls `describe-variable' or `describe-function'."
6748   (let ((sym (intern url)))
6749     (cond
6750      ((fboundp sym) (describe-function sym))
6751      ((boundp sym) (describe-variable sym))
6752      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6753
6754 (defun gnus-button-handle-describe-key (url)
6755   "Call `describe-key' when pushing the corresponding URL button."
6756   (let* ((key-string
6757           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6758          (keys (ignore-errors (eval `(kbd ,key-string)))))
6759     (if keys
6760         (describe-key keys)
6761       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6762
6763 (defun gnus-button-handle-apropos (url)
6764   "Call `apropos' when pushing the corresponding URL button."
6765   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6766
6767 (defun gnus-button-handle-apropos-command (url)
6768   "Call `apropos' when pushing the corresponding URL button."
6769   (apropos-command
6770    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6771
6772 (defun gnus-button-handle-apropos-variable (url)
6773   "Call `apropos' when pushing the corresponding URL button."
6774   (funcall
6775    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6776    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6777
6778 (defun gnus-button-handle-apropos-documentation (url)
6779   "Call `apropos' when pushing the corresponding URL button."
6780   (funcall
6781    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6782    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6783
6784 (defun gnus-button-handle-library (url)
6785   "Call `locate-library' when pushing the corresponding URL button."
6786   (gnus-message 9 "url=`%s'" url)
6787   (let* ((lib (locate-library url))
6788          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6789     (if (not lib)
6790         (gnus-message 1 "Cannot locale library `%s'." url)
6791       (find-file-read-only file))))
6792
6793 (defun gnus-button-handle-ctan (url)
6794   "Call `browse-url' when pushing a CTAN URL button."
6795   (funcall
6796    gnus-button-ctan-handler
6797    (concat
6798     gnus-ctan-url
6799     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6800
6801 (defcustom gnus-button-tex-level 5
6802   "*Integer that says how many TeX-related buttons Gnus will show.
6803 The higher the number, the more buttons will appear and the more false
6804 positives are possible.  Note that you can set this variable local to
6805 specific groups.  Setting it higher in TeX groups is probably a good idea.
6806 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6807 how to set variables in specific groups."
6808   :version "22.1"
6809   :group 'gnus-article-buttons
6810   :link '(custom-manual "(gnus)Group Parameters")
6811   :type 'integer)
6812
6813 (defcustom gnus-button-man-level 5
6814   "*Integer that says how many man-related buttons Gnus will show.
6815 The higher the number, the more buttons will appear and the more false
6816 positives are possible.  Note that you can set this variable local to
6817 specific groups.  Setting it higher in Unix groups is probably a good idea.
6818 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6819 how to set variables in specific groups."
6820   :version "22.1"
6821   :group 'gnus-article-buttons
6822   :link '(custom-manual "(gnus)Group Parameters")
6823   :type 'integer)
6824
6825 (defcustom gnus-button-emacs-level 5
6826   "*Integer that says how many emacs-related buttons Gnus will show.
6827 The higher the number, the more buttons will appear and the more false
6828 positives are possible.  Note that you can set this variable local to
6829 specific groups.  Setting it higher in Emacs or Gnus related groups is
6830 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
6831 `gnus-parameters' on how to set variables in specific groups."
6832   :version "22.1"
6833   :group 'gnus-article-buttons
6834   :link '(custom-manual "(gnus)Group Parameters")
6835   :type 'integer)
6836
6837 (defcustom gnus-button-message-level 5
6838   "*Integer that says how many buttons for news or mail messages will appear.
6839 The higher the number, the more buttons will appear and the more false
6840 positives are possible."
6841   ;; mail addresses, MIDs, URLs for news, ...
6842   :version "22.1"
6843   :group 'gnus-article-buttons
6844   :type 'integer)
6845
6846 (defcustom gnus-button-browse-level 5
6847   "*Integer that says how many buttons for browsing will appear.
6848 The higher the number, the more buttons will appear and the more false
6849 positives are possible."
6850   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6851   :version "22.1"
6852   :group 'gnus-article-buttons
6853   :type 'integer)
6854
6855 (defcustom gnus-button-alist
6856   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6857      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6858     ((concat "\\b\\(nntp\\|news\\):\\("
6859              gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6860      0 t gnus-button-handle-news 2)
6861     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6862      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6863     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6864      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6865     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6866     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6867      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6868     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6869      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6870     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6871      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6872     ;; RFC 2368 (The mailto URL scheme)
6873     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6874      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6875     ("\\bmailto:\\([^ \n\t]+\\)"
6876      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6877     ;; CTAN
6878     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6879              gnus-button-ctan-directory-regexp
6880              "[^][>)!;:,'\n\t ]+\\)")
6881      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6882     ((concat "\\btex-archive/\\("
6883              gnus-button-ctan-directory-regexp
6884              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6885      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6886     ((concat
6887       "\\b\\("
6888       gnus-button-ctan-directory-regexp
6889       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6890      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6891     ;; This is info (home-grown style) <info://foo/bar+baz>
6892     ("\\binfo://\\([^'\">\n\t ]+\\)"
6893      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6894     ;; Info GNOME style <info:foo#bar_baz>
6895     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6896      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6897     ;; Info KDE style <info:(foo)bar baz>
6898     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6899      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6900     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6901      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6902     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6903      ;; Info links like `C-h i d m CC Mode RET'
6904      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6905     ;; This is custom
6906     ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6907      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
6908     ;; Emacs help commands
6909     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6910      ;; regexp doesn't match arguments containing ` '.
6911      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6912     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6913      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6914     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6915      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6916     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6917      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6918     ;; The following entries may lead to many false positives so don't enable
6919     ;; them by default (use a high button level).
6920     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6921      ;; Exclude [.?] for URLs in gmane.emacs.cvs
6922      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6923     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6924      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6925     ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6926      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6927     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6928      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6929     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6930      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6931     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6932      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6933     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6934      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6935     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6936      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6937     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6938      ;; Unlike the other regexps we really have to require quoting
6939      ;; here to determine where it ends.
6940      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6941     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6942     ("<URL: *\\([^<>]*\\)>"
6943      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6944     ;; RFC 2396 (2.4.3., delims) ...
6945     ("\"URL: *\\([^\"]*\\)\""
6946      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6947     ;; RFC 2396 (2.4.3., delims) ...
6948     ("\"URL: *\\([^\"]*\\)\""
6949      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6950     ;; Raw URLs.
6951     (gnus-button-url-regexp
6952      0 (>= gnus-button-browse-level 0) browse-url 0)
6953     ;; man pages
6954     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6955      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6956      gnus-button-handle-man 1)
6957     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6958     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6959      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6960      gnus-button-handle-man 1)
6961     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6962     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6963     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6964      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6965     ;; Recognizing patches to .el files.  This is somewhat obscure,
6966     ;; but considering the percentage of Gnus users who hack Emacs
6967     ;; Lisp files...
6968     ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
6969      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
6970     ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
6971      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
6972     ;; MID or mail: To avoid too many false positives we don't try to catch
6973     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
6974     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
6975     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
6976     ;; so that non-ambiguous entries (see above) match first.
6977     (gnus-button-mid-or-mail-regexp
6978      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6979   "*Alist of regexps matching buttons in article bodies.
6980
6981 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6982 REGEXP: is the string (case insensitive) matching text around the button (can
6983 also be Lisp expression evaluating to a string),
6984 BUTTON: is the number of the regexp grouping actually matching the button,
6985 FORM: is a Lisp expression which must eval to true for the button to
6986 be added,
6987 CALLBACK: is the function to call when the user push this button, and each
6988 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6989
6990 CALLBACK can also be a variable, in that case the value of that
6991 variable it the real callback function."
6992   :group 'gnus-article-buttons
6993   :type '(repeat (list (choice regexp variable sexp)
6994                        (integer :tag "Button")
6995                        (sexp :tag "Form")
6996                        (function :tag "Callback")
6997                        (repeat :tag "Par"
6998                                :inline t
6999                                (integer :tag "Regexp group")))))
7000
7001 (defcustom gnus-header-button-alist
7002   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7003      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7004     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7005      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7006     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7007      0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7008     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7009      0 (>= gnus-button-browse-level 0) browse-url 0)
7010     ("^Subject:" gnus-button-url-regexp
7011      0 (>= gnus-button-browse-level 0) browse-url 0)
7012     ("^[^:]+:" gnus-button-url-regexp
7013      0 (>= gnus-button-browse-level 0) browse-url 0)
7014     ("^OpenPGP:.*url=" gnus-button-url-regexp
7015      0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7016     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7017      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7018     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7019      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7020   "*Alist of headers and regexps to match buttons in article heads.
7021
7022 This alist is very similar to `gnus-button-alist', except that each
7023 alist has an additional HEADER element first in each entry:
7024
7025 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7026
7027 HEADER is a regexp to match a header.  For a fuller explanation, see
7028 `gnus-button-alist'."
7029   :group 'gnus-article-buttons
7030   :group 'gnus-article-headers
7031   :type '(repeat (list (regexp :tag "Header")
7032                        (choice regexp variable)
7033                        (integer :tag "Button")
7034                        (sexp :tag "Form")
7035                        (function :tag "Callback")
7036                        (repeat :tag "Par"
7037                                :inline t
7038                                (integer :tag "Regexp group")))))
7039
7040 ;;; Commands:
7041
7042 (defun gnus-article-push-button (event)
7043   "Check text under the mouse pointer for a callback function.
7044 If the text under the mouse pointer has a `gnus-callback' property,
7045 call it with the value of the `gnus-data' text property."
7046   (interactive "e")
7047   (set-buffer (window-buffer (posn-window (event-start event))))
7048   (let* ((pos (posn-point (event-start event)))
7049          (data (get-text-property pos 'gnus-data))
7050          (fun (get-text-property pos 'gnus-callback)))
7051     (goto-char pos)
7052     (when fun
7053       (funcall fun data))))
7054
7055 (defun gnus-article-press-button ()
7056   "Check text at point for a callback function.
7057 If the text at point has a `gnus-callback' property,
7058 call it with the value of the `gnus-data' text property."
7059   (interactive)
7060   (let ((data (get-text-property (point) 'gnus-data))
7061         (fun (get-text-property (point) 'gnus-callback)))
7062     (when fun
7063       (funcall fun data))))
7064
7065 (defun gnus-article-highlight (&optional force)
7066   "Highlight current article.
7067 This function calls `gnus-article-highlight-headers',
7068 `gnus-article-highlight-citation',
7069 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7070 do the highlighting.  See the documentation for those functions."
7071   (interactive (list 'force))
7072   (gnus-article-highlight-headers)
7073   (gnus-article-highlight-citation force)
7074   (gnus-article-highlight-signature)
7075   (gnus-article-add-buttons force)
7076   (gnus-article-add-buttons-to-head))
7077
7078 (defun gnus-article-highlight-some (&optional force)
7079   "Highlight current article.
7080 This function calls `gnus-article-highlight-headers',
7081 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7082 do the highlighting.  See the documentation for those functions."
7083   (interactive (list 'force))
7084   (gnus-article-highlight-headers)
7085   (gnus-article-highlight-signature)
7086   (gnus-article-add-buttons))
7087
7088 (defun gnus-article-highlight-headers ()
7089   "Highlight article headers as specified by `gnus-header-face-alist'."
7090   (interactive)
7091   (gnus-with-article-headers
7092     (let (regexp header-face field-face from hpoints fpoints)
7093       (dolist (entry gnus-header-face-alist)
7094         (goto-char (point-min))
7095         (setq regexp (concat "^\\("
7096                              (if (string-equal "" (nth 0 entry))
7097                                  "[^\t ]"
7098                                (nth 0 entry))
7099                              "\\)")
7100               header-face (nth 1 entry)
7101               field-face (nth 2 entry))
7102         (while (and (re-search-forward regexp nil t)
7103                     (not (eobp)))
7104           (beginning-of-line)
7105           (setq from (point))
7106           (unless (search-forward ":" nil t)
7107             (forward-char 1))
7108           (when (and header-face
7109                      (not (memq (point) hpoints)))
7110             (push (point) hpoints)
7111             (gnus-put-text-property from (point) 'face header-face))
7112           (when (and field-face
7113                      (not (memq (setq from (point)) fpoints)))
7114             (push from fpoints)
7115             (if (re-search-forward "^[^ \t]" nil t)
7116                 (forward-char -2)
7117               (goto-char (point-max)))
7118             (gnus-put-text-property from (point) 'face field-face)))))))
7119
7120 (defun gnus-article-highlight-signature ()
7121   "Highlight the signature in an article.
7122 It does this by highlighting everything after
7123 `gnus-signature-separator' using the face `gnus-signature'."
7124   (interactive)
7125   (gnus-with-article-buffer
7126     (let ((inhibit-point-motion-hooks t))
7127       (save-restriction
7128         (when (and gnus-signature-face
7129                    (gnus-article-narrow-to-signature))
7130           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
7131                             'face gnus-signature-face)
7132           (widen)
7133           (gnus-article-search-signature)
7134           (let ((start (match-beginning 0))
7135                 (end (set-marker (make-marker) (1+ (match-end 0)))))
7136             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7137                                      end)))))))
7138
7139 (defun gnus-button-in-region-p (b e prop)
7140   "Say whether PROP exists in the region."
7141   (text-property-not-all b e prop nil))
7142
7143 (defun gnus-article-add-buttons (&optional force)
7144   "Find external references in the article and make buttons of them.
7145 \"External references\" are things like Message-IDs and URLs, as
7146 specified by `gnus-button-alist'."
7147   (interactive (list 'force))
7148   (gnus-with-article-buffer
7149     (let ((inhibit-point-motion-hooks t)
7150           (case-fold-search t)
7151           (alist gnus-button-alist)
7152           beg entry regexp)
7153       ;; Remove all old markers.
7154       (let (marker entry new-list)
7155         (while (setq marker (pop gnus-button-marker-list))
7156           (if (or (< marker (point-min)) (>= marker (point-max)))
7157               (push marker new-list)
7158             (goto-char marker)
7159             (when (setq entry (gnus-button-entry))
7160               (put-text-property (match-beginning (nth 1 entry))
7161                                  (match-end (nth 1 entry))
7162                                  'gnus-callback nil))
7163             (set-marker marker nil)))
7164         (setq gnus-button-marker-list new-list))
7165       ;; We skip the headers.
7166       (article-goto-body)
7167       (setq beg (point))
7168       (while (setq entry (pop alist))
7169         (setq regexp (eval (car entry)))
7170         (goto-char beg)
7171         (while (re-search-forward regexp nil t)
7172           (let* ((start (and entry (match-beginning (nth 1 entry))))
7173                  (end (and entry (match-end (nth 1 entry))))
7174                  (from (match-beginning 0)))
7175             (when (and (or (eq t (nth 2 entry))
7176                            (eval (nth 2 entry)))
7177                        (not (gnus-button-in-region-p
7178                              start end 'gnus-callback)))
7179               ;; That optional form returned non-nil, so we add the
7180               ;; button.
7181               (gnus-article-add-button
7182                start end 'gnus-button-push
7183                (car (push (set-marker (make-marker) from)
7184                           gnus-button-marker-list))))))))))
7185
7186 ;; Add buttons to the head of an article.
7187 (defun gnus-article-add-buttons-to-head ()
7188   "Add buttons to the head of the article."
7189   (interactive)
7190   (gnus-with-article-headers
7191     (let (beg end)
7192       (dolist (entry gnus-header-button-alist)
7193         ;; Each alist entry.
7194         (goto-char (point-min))
7195         (while (re-search-forward (car entry) nil t)
7196           ;; Each header matching the entry.
7197           (setq beg (match-beginning 0))
7198           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7199                              (match-beginning 0))
7200                         (point-max)))
7201           (goto-char beg)
7202           (while (re-search-forward (eval (nth 1 entry)) end t)
7203             ;; Each match within a header.
7204             (let* ((entry (cdr entry))
7205                    (start (match-beginning (nth 1 entry)))
7206                    (end (match-end (nth 1 entry)))
7207                    (form (nth 2 entry)))
7208               (goto-char (match-end 0))
7209               (when (eval form)
7210                 (gnus-article-add-button
7211                  start end (nth 3 entry)
7212                  (buffer-substring (match-beginning (nth 4 entry))
7213                                    (match-end (nth 4 entry)))))))
7214           (goto-char end))))))
7215
7216 ;;; External functions:
7217
7218 (defun gnus-article-add-button (from to fun &optional data)
7219   "Create a button between FROM and TO with callback FUN and data DATA."
7220   (when gnus-article-button-face
7221     (gnus-overlay-put (gnus-make-overlay from to)
7222                       'face gnus-article-button-face))
7223   (gnus-add-text-properties
7224    from to
7225    (nconc (and gnus-article-mouse-face
7226                (list gnus-mouse-face-prop gnus-article-mouse-face))
7227           (list 'gnus-callback fun)
7228           (and data (list 'gnus-data data))))
7229   (widget-convert-button 'link from to :action 'gnus-widget-press-button
7230                          :button-keymap gnus-widget-button-keymap))
7231
7232 ;;; Internal functions:
7233
7234 (defun gnus-article-set-globals ()
7235   (with-current-buffer gnus-summary-buffer
7236     (gnus-set-global-variables)))
7237
7238 (defun gnus-signature-toggle (end)
7239   (gnus-with-article-buffer
7240     (let ((inhibit-point-motion-hooks t))
7241       (if (text-property-any end (point-max) 'article-type 'signature)
7242           (progn
7243             (gnus-delete-wash-type 'signature)
7244             (gnus-remove-text-properties-when
7245              'article-type 'signature end (point-max)
7246              (cons 'article-type (cons 'signature
7247                                        gnus-hidden-properties))))
7248         (gnus-add-wash-type 'signature)
7249         (gnus-add-text-properties-when
7250          'article-type nil end (point-max)
7251          (cons 'article-type (cons 'signature
7252                                    gnus-hidden-properties)))))
7253     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7254       (gnus-set-mode-line 'article))))
7255
7256 (defun gnus-button-entry ()
7257   ;; Return the first entry in `gnus-button-alist' matching this place.
7258   (let ((alist gnus-button-alist)
7259         (entry nil))
7260     (while alist
7261       (setq entry (pop alist))
7262       (if (looking-at (eval (car entry)))
7263           (setq alist nil)
7264         (setq entry nil)))
7265     entry))
7266
7267 (defun gnus-button-push (marker)
7268   ;; Push button starting at MARKER.
7269   (save-excursion
7270     (goto-char marker)
7271     (let* ((entry (gnus-button-entry))
7272            (inhibit-point-motion-hooks t)
7273            (fun (nth 3 entry))
7274            (args (mapcar (lambda (group)
7275                            (let ((string (match-string group)))
7276                              (set-text-properties
7277                               0 (length string) nil string)
7278                              string))
7279                          (nthcdr 4 entry))))
7280       (cond
7281        ((fboundp fun)
7282         (apply fun args))
7283        ((and (boundp fun)
7284              (fboundp (symbol-value fun)))
7285         (apply (symbol-value fun) args))
7286        (t
7287         (gnus-message 1 "You must define `%S' to use this button"
7288                       (cons fun args)))))))
7289
7290 (defun gnus-parse-news-url (url)
7291   (let (scheme server port group message-id articles)
7292     (with-temp-buffer
7293       (insert url)
7294       (goto-char (point-min))
7295       (when (looking-at "\\([A-Za-z]+\\):")
7296         (setq scheme (match-string 1))
7297         (goto-char (match-end 0)))
7298       (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7299         (setq server (match-string 1))
7300         (setq port (if (stringp (match-string 3))
7301                        (string-to-number (match-string 3))
7302                      (match-string 3)))
7303         (goto-char (match-end 0)))
7304
7305       (cond
7306        ((looking-at "\\(.*@.*\\)")
7307         (setq message-id (match-string 1)))
7308        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7309         (setq group (match-string 1)
7310               articles (split-string (match-string 2) "-")))
7311        ((looking-at "\\([^/]+\\)/?")
7312         (setq group (match-string 1)))
7313        (t
7314         (error "Unknown news URL syntax"))))
7315     (list scheme server port group message-id articles)))
7316
7317 (defun gnus-button-handle-news (url)
7318   "Fetch a news URL."
7319   (destructuring-bind (scheme server port group message-id articles)
7320       (gnus-parse-news-url url)
7321     (cond
7322      (message-id
7323       (save-excursion
7324         (set-buffer gnus-summary-buffer)
7325         (if server
7326             (let ((gnus-refer-article-method
7327                    (nconc (list (list 'nntp server))
7328                           gnus-refer-article-method))
7329                   (nntp-port-number (or port "nntp")))
7330               (gnus-message 7 "Fetching %s with %s"
7331                             message-id gnus-refer-article-method)
7332               (gnus-summary-refer-article message-id))
7333           (gnus-summary-refer-article message-id))))
7334      (group
7335       (gnus-button-fetch-group url)))))
7336
7337 (defun gnus-button-patch (library line)
7338   "Visit an Emacs Lisp library LIBRARY on line LINE."
7339   (interactive)
7340   (let ((file (locate-library (file-name-nondirectory library))))
7341     (unless file
7342       (error "Couldn't find library %s" library))
7343     (find-file file)
7344     (goto-line (string-to-number line))))
7345
7346 (defun gnus-button-handle-man (url)
7347   "Fetch a man page."
7348   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7349   (when (eq gnus-button-man-handler 'woman)
7350     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7351   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7352   (funcall gnus-button-man-handler url))
7353
7354 (defun gnus-button-handle-info-url (url)
7355   "Fetch an info URL."
7356   (setq url (mm-subst-char-in-string ?+ ?\  url))
7357   (cond
7358    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7359     (gnus-info-find-node
7360      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7361                      "Gnus")
7362              ")" (gnus-url-unhex-string (match-string 2 url)))))
7363    ((string-match "([^)\"]+)[^\"]+" url)
7364     (setq url
7365           (gnus-replace-in-string
7366            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7367     (gnus-info-find-node url))
7368    (t (error "Can't parse %s" url))))
7369
7370 (defun gnus-button-handle-info-url-gnome (url)
7371   "Fetch GNOME style info URL."
7372   (setq url (mm-subst-char-in-string ?_ ?\  url))
7373   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7374       (gnus-info-find-node
7375        (concat "("
7376                (gnus-url-unhex-string
7377                  (match-string 1 url))
7378                ")"
7379                (or (gnus-url-unhex-string
7380                     (match-string 2 url))
7381                    "Top")))
7382     (error "Can't parse %s" url)))
7383
7384 (defun gnus-button-handle-info-url-kde (url)
7385   "Fetch KDE style info URL."
7386   (gnus-info-find-node (gnus-url-unhex-string url)))
7387
7388 (defun gnus-button-handle-info-keystrokes (url)
7389   "Call `info' when pushing the corresponding URL button."
7390   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7391   (info)
7392   (Info-directory)
7393   (Info-menu url))
7394
7395 (defun gnus-button-openpgp (url)
7396   "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7397   (with-temp-buffer
7398     (mm-url-insert-file-contents-external url)
7399     (pgg-snarf-keys-region (point-min) (point-max))
7400     (pgg-display-output-buffer nil nil nil)))
7401
7402 (defun gnus-button-message-id (message-id)
7403   "Fetch MESSAGE-ID."
7404   (with-current-buffer gnus-summary-buffer
7405     (gnus-summary-refer-article message-id)))
7406
7407 (defun gnus-button-fetch-group (address)
7408   "Fetch GROUP specified by ADDRESS."
7409   (if (not (string-match "[:/]" address))
7410       ;; This is just a simple group url.
7411       (gnus-group-read-ephemeral-group address gnus-select-method)
7412     (if (not
7413          (string-match
7414           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7415           address))
7416         (error "Can't parse %s" address)
7417       (gnus-group-read-ephemeral-group
7418        (match-string 4 address)
7419        `(nntp ,(match-string 1 address)
7420               (nntp-address ,(match-string 1 address))
7421               (nntp-port-number ,(if (match-end 3)
7422                                      (match-string 3 address)
7423                                    "nntp")))
7424        nil nil nil
7425        (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7426
7427 (defun gnus-url-parse-query-string (query &optional downcase)
7428   (let (retval pairs cur key val)
7429     (setq pairs (split-string query "&"))
7430     (while pairs
7431       (setq cur (car pairs)
7432             pairs (cdr pairs))
7433       (if (not (string-match "=" cur))
7434           nil                           ; Grace
7435         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7436               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7437         (if downcase
7438             (setq key (downcase key)))
7439         (setq cur (assoc key retval))
7440         (if cur
7441             (setcdr cur (cons val (cdr cur)))
7442           (setq retval (cons (list key val) retval)))))
7443     retval))
7444
7445 (defun gnus-url-mailto (url)
7446   ;; Send mail to someone
7447   (when (string-match "mailto:/*\\(.*\\)" url)
7448     (setq url (substring url (match-beginning 1) nil)))
7449   (let (to args subject func)
7450     (setq args (gnus-url-parse-query-string
7451                 (if (string-match "^\\?" url)
7452                     (substring url 1)
7453                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7454                       (concat "to=" (match-string 1 url) "&"
7455                               (match-string 2 url))
7456                     (concat "to=" url)))
7457                 t)
7458           subject (cdr-safe (assoc "subject" args)))
7459     (gnus-msg-mail)
7460     (while args
7461       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7462       (if (fboundp func)
7463           (funcall func)
7464         (message-position-on-field (caar args)))
7465       (insert (gnus-replace-in-string
7466                (mapconcat 'identity (reverse (cdar args)) ", ")
7467                "\r\n" "\n" t))
7468       (setq args (cdr args)))
7469     (if subject
7470         (message-goto-body)
7471       (message-goto-subject))))
7472
7473 (defun gnus-button-embedded-url (address)
7474   "Activate ADDRESS with `browse-url'."
7475   (browse-url (gnus-strip-whitespace address)))
7476
7477 ;;; Next/prev buttons in the article buffer.
7478
7479 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7480 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7481
7482 (defvar gnus-prev-page-map
7483   (let ((map (make-sparse-keymap)))
7484     (define-key map gnus-mouse-2 'gnus-button-prev-page)
7485     (define-key map "\r" 'gnus-button-prev-page)
7486     map))
7487
7488 (defvar gnus-next-page-map
7489   (let ((map (make-sparse-keymap)))
7490     (unless (>= emacs-major-version 21)
7491       ;; XEmacs doesn't care.
7492       (set-keymap-parent map gnus-article-mode-map))
7493     (define-key map gnus-mouse-2 'gnus-button-next-page)
7494     (define-key map "\r" 'gnus-button-next-page)
7495     map))
7496
7497 (defun gnus-insert-prev-page-button ()
7498   (let ((b (point)) e
7499         (inhibit-read-only t))
7500     (gnus-eval-format
7501      gnus-prev-page-line-format nil
7502      `(keymap ,gnus-prev-page-map
7503               gnus-prev t
7504               gnus-callback gnus-article-button-prev-page
7505               article-type annotation))
7506     (setq e (if (bolp)
7507                 ;; Exclude a newline.
7508                 (1- (point))
7509               (point)))
7510     (when gnus-article-button-face
7511       (gnus-overlay-put (gnus-make-overlay b e)
7512                         'face gnus-article-button-face))
7513     (widget-convert-button
7514      'link b e
7515      :action 'gnus-button-prev-page
7516      :button-keymap gnus-prev-page-map)))
7517
7518 (defun gnus-button-next-page (&optional args more-args)
7519   "Go to the next page."
7520   (interactive)
7521   (let ((win (selected-window)))
7522     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7523     (gnus-article-next-page)
7524     (select-window win)))
7525
7526 (defun gnus-button-prev-page (&optional args more-args)
7527   "Go to the prev page."
7528   (interactive)
7529   (let ((win (selected-window)))
7530     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7531     (gnus-article-prev-page)
7532     (select-window win)))
7533
7534 (defun gnus-insert-next-page-button ()
7535   (let ((b (point)) e
7536         (inhibit-read-only t))
7537     (gnus-eval-format gnus-next-page-line-format nil
7538                       `(keymap ,gnus-next-page-map
7539                                gnus-next t
7540                                gnus-callback gnus-article-button-next-page
7541                                article-type annotation))
7542     (setq e (if (bolp)
7543                 ;; Exclude a newline.
7544                 (1- (point))
7545               (point)))
7546     (when gnus-article-button-face
7547       (gnus-overlay-put (gnus-make-overlay b e)
7548                         'face gnus-article-button-face))
7549     (widget-convert-button
7550      'link b e
7551      :action 'gnus-button-next-page
7552      :button-keymap gnus-next-page-map)))
7553
7554 (defun gnus-article-button-next-page (arg)
7555   "Go to the next page."
7556   (interactive "P")
7557   (let ((win (selected-window)))
7558     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7559     (gnus-article-next-page)
7560     (select-window win)))
7561
7562 (defun gnus-article-button-prev-page (arg)
7563   "Go to the prev page."
7564   (interactive "P")
7565   (let ((win (selected-window)))
7566     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7567     (gnus-article-prev-page)
7568     (select-window win)))
7569
7570 (defvar gnus-decode-header-methods
7571   '(mail-decode-encoded-word-region)
7572   "List of methods used to decode headers.
7573
7574 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
7575 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
7576 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7577 whose names match REGEXP.
7578
7579 For example:
7580 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7581  mail-decode-encoded-word-region
7582  (\"chinese\" . rfc1843-decode-region))
7583 ")
7584
7585 (defvar gnus-decode-header-methods-cache nil)
7586
7587 (defun gnus-multi-decode-header (start end)
7588   "Apply the functions from `gnus-encoded-word-methods' that match."
7589   (unless (and gnus-decode-header-methods-cache
7590                (eq gnus-newsgroup-name
7591                    (car gnus-decode-header-methods-cache)))
7592     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7593     (mapcar (lambda (x)
7594               (if (symbolp x)
7595                   (nconc gnus-decode-header-methods-cache (list x))
7596                 (if (and gnus-newsgroup-name
7597                          (string-match (car x) gnus-newsgroup-name))
7598                     (nconc gnus-decode-header-methods-cache
7599                            (list (cdr x))))))
7600           gnus-decode-header-methods))
7601   (let ((xlist gnus-decode-header-methods-cache))
7602     (pop xlist)
7603     (save-restriction
7604       (narrow-to-region start end)
7605       (while xlist
7606         (funcall (pop xlist) (point-min) (point-max))))))
7607
7608 ;;;
7609 ;;; Treatment top-level handling.
7610 ;;;
7611
7612 (defun gnus-treat-article (condition &optional part-number total-parts type)
7613   (let ((length (- (point-max) (point-min)))
7614         (alist gnus-treatment-function-alist)
7615         (article-goto-body-goes-to-point-min-p t)
7616         (treated-type
7617          (or (not type)
7618              (catch 'found
7619                (let ((list gnus-article-treat-types))
7620                  (while list
7621                    (when (string-match (pop list) type)
7622                      (throw 'found t)))))))
7623         (highlightp (gnus-visual-p 'article-highlight 'highlight))
7624         val elem)
7625     (gnus-run-hooks 'gnus-part-display-hook)
7626     (dolist (elem alist)
7627       (setq val
7628             (save-excursion
7629               (when (gnus-buffer-live-p gnus-summary-buffer)
7630                 (set-buffer gnus-summary-buffer))
7631               (symbol-value (car elem))))
7632       (when (and (or (consp val)
7633                      treated-type)
7634                  (gnus-treat-predicate val)
7635                  (or (not (get (car elem) 'highlight))
7636                      highlightp))
7637         (save-restriction
7638           (funcall (cadr elem)))))))
7639
7640 ;; Dynamic variables.
7641 (eval-when-compile
7642   (defvar part-number)
7643   (defvar total-parts)
7644   (defvar type)
7645   (defvar condition)
7646   (defvar length))
7647
7648 (defun gnus-treat-predicate (val)
7649   (cond
7650    ((null val)
7651     nil)
7652    (condition
7653     (eq condition val))
7654    ((and (listp val)
7655          (stringp (car val)))
7656     (apply 'gnus-or (mapcar `(lambda (s)
7657                                (string-match s ,(or gnus-newsgroup-name "")))
7658                             val)))
7659    ((listp val)
7660     (let ((pred (pop val)))
7661       (cond
7662        ((eq pred 'or)
7663         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7664        ((eq pred 'and)
7665         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7666        ((eq pred 'not)
7667         (not (gnus-treat-predicate (car val))))
7668        ((eq pred 'typep)
7669         (equal (car val) type))
7670        (t
7671         (error "%S is not a valid predicate" pred)))))
7672    ((eq val t)
7673     t)
7674    ((eq val 'head)
7675     nil)
7676    ((eq val 'first)
7677     (eq part-number 1))
7678    ((eq val 'last)
7679     (eq part-number total-parts))
7680    ((numberp val)
7681     (< length val))
7682    (t
7683     (error "%S is not a valid value" val))))
7684
7685 (defun gnus-article-encrypt-body (protocol &optional n)
7686   "Encrypt the article body."
7687   (interactive
7688    (list
7689     (or gnus-article-encrypt-protocol
7690         (completing-read "Encrypt protocol: "
7691                          gnus-article-encrypt-protocol-alist
7692                          nil t))
7693     current-prefix-arg))
7694   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7695     (unless func
7696       (error "Can't find the encrypt protocol %s" protocol))
7697     (if (member gnus-newsgroup-name '("nndraft:delayed"
7698                                       "nndraft:drafts"
7699                                       "nndraft:queue"))
7700         (error "Can't encrypt the article in group %s"
7701                gnus-newsgroup-name))
7702     (gnus-summary-iterate n
7703       (save-excursion
7704         (set-buffer gnus-summary-buffer)
7705         (let ((mail-parse-charset gnus-newsgroup-charset)
7706               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7707               (summary-buffer gnus-summary-buffer)
7708               references point)
7709           (gnus-set-global-variables)
7710           (when (gnus-group-read-only-p)
7711             (error "The current newsgroup does not support article encrypt"))
7712           (gnus-summary-show-article t)
7713           (setq references
7714               (or (mail-header-references gnus-current-headers) ""))
7715           (set-buffer gnus-article-buffer)
7716           (let* ((inhibit-read-only t)
7717                  (headers
7718                   (mapcar (lambda (field)
7719                             (and (save-restriction
7720                                    (message-narrow-to-head)
7721                                    (goto-char (point-min))
7722                                    (search-forward field nil t))
7723                                  (prog2
7724                                      (message-narrow-to-field)
7725                                      (buffer-string)
7726                                    (delete-region (point-min) (point-max))
7727                                    (widen))))
7728                           '("Content-Type:" "Content-Transfer-Encoding:"
7729                             "Content-Disposition:"))))
7730             (message-narrow-to-head)
7731             (message-remove-header "MIME-Version")
7732             (goto-char (point-max))
7733             (setq point (point))
7734             (insert (apply 'concat headers))
7735             (widen)
7736             (narrow-to-region point (point-max))
7737             (let ((message-options message-options))
7738               (message-options-set 'message-sender user-mail-address)
7739               (message-options-set 'message-recipients user-mail-address)
7740               (message-options-set 'message-sign-encrypt 'not)
7741               (funcall func))
7742             (goto-char (point-min))
7743             (insert "MIME-Version: 1.0\n")
7744             (widen)
7745             (gnus-summary-edit-article-done
7746              references nil summary-buffer t))
7747           (when gnus-keep-backlog
7748             (gnus-backlog-remove-article
7749              (car gnus-article-current) (cdr gnus-article-current)))
7750           (save-excursion
7751             (when (get-buffer gnus-original-article-buffer)
7752               (set-buffer gnus-original-article-buffer)
7753               (setq gnus-original-article nil)))
7754           (when gnus-use-cache
7755             (gnus-cache-update-article
7756              (car gnus-article-current) (cdr gnus-article-current))))))))
7757
7758 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7759   "The following specs can be used:
7760 %t  The security MIME type
7761 %i  Additional info
7762 %d  Details
7763 %D  Details if button is pressed")
7764
7765 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7766   "The following specs can be used:
7767 %t  The security MIME type
7768 %i  Additional info
7769 %d  Details
7770 %D  Details if button is pressed")
7771
7772 (defvar gnus-mime-security-button-line-format-alist
7773   '((?t gnus-tmp-type ?s)
7774     (?i gnus-tmp-info ?s)
7775     (?d gnus-tmp-details ?s)
7776     (?D gnus-tmp-pressed-details ?s)))
7777
7778 (defvar gnus-mime-security-button-commands
7779   '((gnus-article-press-button "\r" "Show Detail")
7780     (undefined "v")
7781     (undefined "t")
7782     (undefined "C")
7783     (gnus-mime-security-save-part "o" "Save...")
7784     (undefined "\C-o")
7785     (undefined "r")
7786     (undefined "d")
7787     (undefined "c")
7788     (undefined "i")
7789     (undefined "E")
7790     (undefined "e")
7791     (undefined "p")
7792     (gnus-mime-security-pipe-part "|" "Pipe To Command...")
7793     (undefined ".")))
7794
7795 (defvar gnus-mime-security-button-map
7796   (let ((map (make-sparse-keymap)))
7797     (define-key map gnus-mouse-2 'gnus-article-push-button)
7798     (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
7799     (dolist (c gnus-mime-security-button-commands)
7800       (define-key map (cadr c) (car c)))
7801     map))
7802
7803 (easy-menu-define
7804   gnus-mime-security-button-menu gnus-mime-security-button-map
7805   "Security button menu."
7806   `("Security Part"
7807     ,@(delq nil
7808             (mapcar (lambda (c)
7809                       (unless (eq (car c) 'undefined)
7810                         (vector (caddr c) (car c) :active t)))
7811                     gnus-mime-security-button-commands))))
7812
7813 (defun gnus-mime-security-button-menu (event prefix)
7814   "Construct a context-sensitive menu of security commands."
7815   (interactive "e\nP")
7816   (save-window-excursion
7817     (let ((pos (event-start event)))
7818       (select-window (posn-window pos))
7819       (goto-char (posn-point pos))
7820       (gnus-article-check-buffer)
7821       (popup-menu gnus-mime-security-button-menu nil prefix))))
7822
7823 (defvar gnus-mime-security-details-buffer nil)
7824
7825 (defvar gnus-mime-security-button-pressed nil)
7826
7827 (defvar gnus-mime-security-show-details-inline t
7828   "If non-nil, show details in the article buffer.")
7829
7830 (defun gnus-mime-security-verify-or-decrypt (handle)
7831   (mm-remove-parts (cdr handle))
7832   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7833         point (inhibit-read-only t))
7834     (if region
7835         (goto-char (car region)))
7836     (save-restriction
7837       (narrow-to-region (point) (point))
7838       (with-current-buffer (mm-handle-multipart-original-buffer handle)
7839         (let* ((mm-verify-option 'known)
7840                (mm-decrypt-option 'known)
7841                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7842           (unless (eq nparts (cdr handle))
7843             (mm-destroy-parts (cdr handle))
7844             (setcdr handle nparts))))
7845       (setq point (point))
7846       (gnus-mime-display-security handle)
7847       (goto-char (point-max)))
7848     (when region
7849       (delete-region (point) (cdr region))
7850       (set-marker (car region) nil)
7851       (set-marker (cdr region) nil))
7852     (goto-char point)))
7853
7854 (defun gnus-mime-security-show-details (handle)
7855   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7856     (if (not details)
7857         (gnus-message 5 "No details.")
7858       (if gnus-mime-security-show-details-inline
7859           (let ((gnus-mime-security-button-pressed
7860                  (not (get-text-property (point) 'gnus-mime-details)))
7861                 (gnus-mime-security-button-line-format
7862                  (get-text-property (point) 'gnus-line-format))
7863                 (inhibit-read-only t))
7864             (forward-char -1)
7865             (while (eq (get-text-property (point) 'gnus-line-format)
7866                        gnus-mime-security-button-line-format)
7867               (forward-char -1))
7868             (forward-char)
7869             (save-restriction
7870               (narrow-to-region (point) (point))
7871               (gnus-insert-mime-security-button handle))
7872             (delete-region (point)
7873                            (or (text-property-not-all
7874                                 (point) (point-max)
7875                                 'gnus-line-format
7876                                 gnus-mime-security-button-line-format)
7877                                (point-max))))
7878         ;; Not inlined.
7879         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7880             (with-current-buffer gnus-mime-security-details-buffer
7881               (erase-buffer)
7882               t)
7883           (setq gnus-mime-security-details-buffer
7884                 (gnus-get-buffer-create "*MIME Security Details*")))
7885         (with-current-buffer gnus-mime-security-details-buffer
7886           (insert details)
7887           (goto-char (point-min)))
7888         (pop-to-buffer gnus-mime-security-details-buffer)))))
7889
7890 (defun gnus-mime-security-press-button (handle)
7891   (save-excursion
7892     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7893         (gnus-mime-security-show-details handle)
7894       (gnus-mime-security-verify-or-decrypt handle))))
7895
7896 (defun gnus-insert-mime-security-button (handle &optional displayed)
7897   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7898          (gnus-tmp-type
7899           (concat
7900            (or (nth 2 (assoc protocol mm-verify-function-alist))
7901                (nth 2 (assoc protocol mm-decrypt-function-alist))
7902                "Unknown")
7903            (if (equal (car handle) "multipart/signed")
7904                " Signed" " Encrypted")
7905            " Part"))
7906          (gnus-tmp-info
7907           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7908               "Undecided"))
7909          (gnus-tmp-details
7910           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7911          gnus-tmp-pressed-details
7912          b e)
7913     (setq gnus-tmp-details
7914           (if gnus-tmp-details
7915               (concat "\n" gnus-tmp-details)
7916             ""))
7917     (setq gnus-tmp-pressed-details
7918           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7919     (unless (bolp)
7920       (insert "\n"))
7921     (setq b (point))
7922     (gnus-eval-format
7923      gnus-mime-security-button-line-format
7924      gnus-mime-security-button-line-format-alist
7925      `(keymap ,gnus-mime-security-button-map
7926          gnus-callback gnus-mime-security-press-button
7927          gnus-line-format ,gnus-mime-security-button-line-format
7928          gnus-mime-details ,gnus-mime-security-button-pressed
7929          article-type annotation
7930          gnus-data ,handle))
7931     (setq e (if (bolp)
7932                 ;; Exclude a newline.
7933                 (1- (point))
7934               (point)))
7935     (when gnus-article-button-face
7936       (gnus-overlay-put (gnus-make-overlay b e)
7937                         'face gnus-article-button-face))
7938     (widget-convert-button
7939      'link b e
7940      :mime-handle handle
7941      :action 'gnus-widget-press-button
7942      :button-keymap gnus-mime-security-button-map
7943      :help-echo
7944      (lambda (widget/window &optional overlay pos)
7945        ;; Needed to properly clear the message due to a bug in
7946        ;; wid-edit (XEmacs only).
7947        (when (boundp 'help-echo-owns-message)
7948          (setq help-echo-owns-message t))
7949        (format
7950         "%S: show detail; %S: more options"
7951         (aref gnus-mouse-2 0)
7952         (aref gnus-down-mouse-3 0))))))
7953
7954 (defun gnus-mime-display-security (handle)
7955   (save-restriction
7956     (narrow-to-region (point) (point))
7957     (unless (gnus-unbuttonized-mime-type-p (car handle))
7958       (gnus-insert-mime-security-button handle))
7959     (gnus-mime-display-part (cadr handle))
7960     (unless (bolp)
7961       (insert "\n"))
7962     (unless (gnus-unbuttonized-mime-type-p (car handle))
7963       (let ((gnus-mime-security-button-line-format
7964              gnus-mime-security-button-end-line-format))
7965         (gnus-insert-mime-security-button handle)))
7966     (mm-set-handle-multipart-parameter
7967      handle 'gnus-region
7968      (cons (set-marker (make-marker) (point-min))
7969            (set-marker (make-marker) (point-max))))))
7970
7971 (defun gnus-mime-security-run-function (function)
7972   "Run FUNCTION with the security part under point."
7973   (gnus-article-check-buffer)
7974   (let ((data (get-text-property (point) 'gnus-data))
7975         buffer handle)
7976     (when (and (stringp (car-safe data))
7977                (setq buffer (mm-handle-multipart-original-buffer data))
7978                (setq handle (cadr data)))
7979       (if (bufferp (mm-handle-buffer handle))
7980           (progn
7981             (setq handle (cons buffer (copy-sequence (cdr handle))))
7982             (mm-handle-set-undisplayer handle nil))
7983         (setq handle (mm-make-handle
7984                       buffer
7985                       (mm-handle-multipart-ctl-parameter handle 'protocol)
7986                       nil nil nil nil nil nil)))
7987       (funcall function handle))))
7988
7989 (defun gnus-mime-security-save-part ()
7990   "Save the security part under point."
7991   (interactive)
7992   (gnus-mime-security-run-function 'mm-save-part))
7993
7994 (defun gnus-mime-security-pipe-part ()
7995   "Pipe the security part under point to a process."
7996   (interactive)
7997   (gnus-mime-security-run-function 'mm-pipe-part))
7998
7999 (gnus-ems-redefine)
8000
8001 (provide 'gnus-art)
8002
8003 (run-hooks 'gnus-art-load-hook)
8004
8005 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8006 ;;; gnus-art.el ends here