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