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