5566b0ea324808aa6b09ca11ae30426912df7eda
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28   (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
32 (require 'gnus)
33 (require 'gnus-util)
34 (require 'gnus-sum)
35 (require 'gnus-spec)
36 (require 'gnus-int)
37 (require 'gnus-win)
38 (require 'mm-bodies)
39 (require 'mail-parse)
40 (require 'mm-decode)
41 (require 'mm-view)
42 (require 'wid-edit)
43 (require 'mm-uu)
44 (require 'message)
45 (require 'mouse)
46
47 (autoload 'gnus-msg-mail "gnus-msg" nil t)
48 (autoload 'gnus-button-mailto "gnus-msg")
49 (autoload 'gnus-button-reply "gnus-msg" nil t)
50 (autoload 'parse-time-string "parse-time" nil nil)
51 (autoload 'ansi-color-apply-on-region "ansi-color")
52 (autoload 'mm-url-insert-file-contents-external "mm-url")
53 (autoload 'mm-extern-cache-contents "mm-extern")
54
55 (defgroup gnus-article nil
56   "Article display."
57   :link '(custom-manual "(gnus)Article Buffer")
58   :group 'gnus)
59
60 (defgroup gnus-article-treat nil
61   "Treating article parts."
62   :link '(custom-manual "(gnus)Article Hiding")
63   :group 'gnus-article)
64
65 (defgroup gnus-article-hiding nil
66   "Hiding article parts."
67   :link '(custom-manual "(gnus)Article Hiding")
68   :group 'gnus-article)
69
70 (defgroup gnus-article-highlight nil
71   "Article highlighting."
72   :link '(custom-manual "(gnus)Article Highlighting")
73   :group 'gnus-article
74   :group 'gnus-visual)
75
76 (defgroup gnus-article-signature nil
77   "Article signatures."
78   :link '(custom-manual "(gnus)Article Signature")
79   :group 'gnus-article)
80
81 (defgroup gnus-article-headers nil
82   "Article headers."
83   :link '(custom-manual "(gnus)Hiding Headers")
84   :group 'gnus-article)
85
86 (defgroup gnus-article-washing nil
87   "Special commands on articles."
88   :link '(custom-manual "(gnus)Article Washing")
89   :group 'gnus-article)
90
91 (defgroup gnus-article-emphasis nil
92   "Fontisizing articles."
93   :link '(custom-manual "(gnus)Article Fontisizing")
94   :group 'gnus-article)
95
96 (defgroup gnus-article-saving nil
97   "Saving articles."
98   :link '(custom-manual "(gnus)Saving Articles")
99   :group 'gnus-article)
100
101 (defgroup gnus-article-mime nil
102   "Worshiping the MIME wonder."
103   :link '(custom-manual "(gnus)Using MIME")
104   :group 'gnus-article)
105
106 (defgroup gnus-article-buttons nil
107   "Pushable buttons in the article buffer."
108   :link '(custom-manual "(gnus)Article Buttons")
109   :group 'gnus-article)
110
111 (defgroup gnus-article-various nil
112   "Other article options."
113   :link '(custom-manual "(gnus)Misc Article")
114   :group 'gnus-article)
115
116 (defcustom gnus-ignored-headers
117   (mapcar
118    (lambda (header)
119      (concat "^" header ":"))
120    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126      "X-Attribution" "X-Originating-IP" "Delivered-To"
127      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143      "List-[A-Za-z]+" "X-Listprocessor-Version"
144      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146      "X-Received" "Content-length" "X-precedence"
147      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152      "X-Content-length" "X-Posting-Agent" "Original-Received"
153      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160      "Envelope-Sender" "Envelope-Recipients"))
161   "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164   :type '(choice 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:"
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 '(choice
174           (repeat :value-to-internal (lambda (widget value)
175                                        (custom-split-regexp-maybe value))
176                   :match (lambda (widget value)
177                            (or (stringp value)
178                                (widget-editable-list-match widget value)))
179                   regexp)
180           (const :tag "Use gnus-ignored-headers" nil)
181           regexp)
182   :group 'gnus-article-hiding)
183
184 (defcustom gnus-sorted-header-list
185   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187   "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191   :type '(repeat regexp)
192   :group 'gnus-article-hiding)
193
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195   "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
197
198   'empty       Headers with no content.
199   'newsgroups  Newsgroup identical to Gnus group.
200   'to-address  To identical to To-address.
201   'to-list     To identical to To-list.
202   'cc-list     CC identical to To-list.
203   'followup-to Followup-to identical to Newsgroups.
204   'reply-to    Reply-to identical to From.
205   'date        Date less than four days old.
206   'long-to     To and/or Cc longer than 1024 characters.
207   'many-to     Multiple To and/or Cc."
208   :type '(set (const :tag "Headers with no content." empty)
209               (const :tag "Newsgroups identical to Gnus group." newsgroups)
210               (const :tag "To identical to To-address." to-address)
211               (const :tag "To identical to To-list." to-list)
212               (const :tag "CC identical to To-list." cc-list)
213               (const :tag "Followup-to identical to Newsgroups." followup-to)
214               (const :tag "Reply-to identical to From." reply-to)
215               (const :tag "Date less than four days old." date)
216               (const :tag "To and/or Cc longer than 1024 characters." long-to)
217               (const :tag "Multiple To and/or Cc headers." many-to))
218   :group 'gnus-article-hiding)
219
220 (defcustom gnus-article-skip-boring nil
221   "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text.  Boring text is controlled by
225 `gnus-article-boring-faces'."
226   :version "22.1"
227   :type 'boolean
228   :group 'gnus-article-hiding)
229
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231   "Regexp matching signature separator.
232 This can also be a list of regexps.  In that case, it will be checked
233 from head to tail looking for a separator.  Searches will be done from
234 the end of the buffer."
235   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236                  (regexp)
237                  (repeat :tag "List of regexp" regexp))
238   :group 'gnus-article-signature)
239
240 (defcustom gnus-signature-limit nil
241   "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number.  If it is a floating point number, no signature may be
244 longer (in lines) than that number.  If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer.  If it is a string, it will be used as a
247 regexp.  If it matches, the text in question is not a signature.
248
249 This can also be a list of the above values."
250   :type '(choice (const nil)
251                  (integer :value 200)
252                  (number :value 4.0)
253                  function
254                  (regexp :value ".*"))
255   :group 'gnus-article-signature)
256
257 (defcustom gnus-hidden-properties '(invisible t intangible t)
258   "Property list to use for hiding text."
259   :type 'sexp
260   :group 'gnus-article-hiding)
261
262 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
263 ;; frames in a session.
264 (defcustom gnus-article-x-face-command
265   (if (featurep 'xemacs)
266       (if (or (gnus-image-type-available-p 'xface)
267               (gnus-image-type-available-p 'pbm))
268           'gnus-display-x-face-in-from
269         "{ echo \
270 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
271 ; uncompface; } | icontopbm | ee -")
272     (if (gnus-image-type-available-p 'pbm)
273         'gnus-display-x-face-in-from
274       "{ echo \
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | display -"))
277   "*String or function to be executed to display an X-Face header.
278 If it is a string, the command will be executed in a sub-shell
279 asynchronously.  The compressed face will be piped to this command."
280   :type `(choice string
281                  (function-item gnus-display-x-face-in-from)
282                  function)
283   :version "21.1"
284   :group 'gnus-picon
285   :group 'gnus-article-washing)
286
287 (defcustom gnus-article-x-face-too-ugly nil
288   "Regexp matching posters whose face shouldn't be shown automatically."
289   :type '(choice regexp (const nil))
290   :group 'gnus-article-washing)
291
292 (defcustom gnus-article-banner-alist nil
293   "Banner alist for stripping.
294 For example,
295      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
296   :version "21.1"
297   :type '(repeat (cons symbol regexp))
298   :group 'gnus-article-washing)
299
300 (gnus-define-group-parameter
301  banner
302  :variable-document
303  "Alist of regexps (to match group names) and banner."
304  :variable-group gnus-article-washing
305  :parameter-type
306  '(choice :tag "Banner"
307           :value nil
308           (const :tag "Remove signature" signature)
309           (symbol :tag "Item in `gnus-article-banner-alist'" none)
310           regexp
311           (const :tag "None" nil))
312  :parameter-document
313  "If non-nil, specify how to remove `banners' from articles.
314
315 Symbol `signature' means to remove signatures delimited by
316 `gnus-signature-separator'.  Any other symbol is used to look up a
317 regular expression to match the banner in `gnus-article-banner-alist'.
318 A string is used as a regular expression to match the banner
319 directly.")
320
321 (defcustom gnus-article-address-banner-alist nil
322   "Alist of mail addresses and banners.
323 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
324 to match a mail address in the From: header, BANNER is one of a symbol
325 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
326 If ADDRESS matches author's mail address, it will remove things like
327 advertisements.  For example:
328
329 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 "
331   :type '(repeat
332           (cons
333            (regexp :tag "Address")
334            (choice :tag "Banner" :value nil
335                    (const :tag "Remove signature" signature)
336                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
337                    regexp
338                    (const :tag "None" nil))))
339   :version "22.1"
340   :group 'gnus-article-washing)
341
342 (defmacro gnus-emphasis-custom-with-format (&rest body)
343   `(let ((format "\
344 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
345 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
346      ,@body))
347
348 (defun gnus-emphasis-custom-value-to-external (value)
349   (gnus-emphasis-custom-with-format
350    (if (consp (car value))
351        (list (format format (car (car value)) (cdr (car value)))
352              2
353              (if (nth 1 value) 2 3)
354              (nth 2 value))
355      value)))
356
357 (defun gnus-emphasis-custom-value-to-internal (value)
358   (gnus-emphasis-custom-with-format
359    (let ((regexp (concat "\\`"
360                          (format (regexp-quote format)
361                                  "\\([^()]+\\)" "\\([^()]+\\)")
362                          "\\'"))
363          pattern)
364      (if (string-match regexp (setq pattern (car value)))
365          (list (cons (match-string 1 pattern) (match-string 2 pattern))
366                (= (nth 2 value) 2)
367                (nth 3 value))
368        value))))
369
370 (defcustom gnus-emphasis-alist
371   (let ((types
372          '(("\\*" "\\*" bold nil 2)
373            ("_" "_" underline)
374            ("/" "/" italic)
375            ("_/" "/_" underline-italic)
376            ("_\\*" "\\*_" underline-bold)
377            ("\\*/" "/\\*" bold-italic)
378            ("_\\*/" "/\\*_" underline-bold-italic))))
379     (nconc
380      (gnus-emphasis-custom-with-format
381       (mapcar (lambda (spec)
382                 (list (format format (car spec) (cadr spec))
383                       (or (nth 3 spec) 2)
384                       (or (nth 4 spec) 3)
385                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386               types))
387      '(;; I've never seen anyone use this strikethru convention whereas I've
388        ;; several times seen it triggered by normal text.  --Stef
389        ;; Miles suggests that this form is sometimes used but for italics,
390        ;; so maybe we should map it to `italic'.
391        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
392        ;; 2 3 gnus-emphasis-strikethru)
393        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
394         2 3 gnus-emphasis-underline))))
395   "*Alist that says how to fontify certain phrases.
396 Each item looks like this:
397
398   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399
400 The first element is a regular expression to be matched.  The second
401 is a number that says what regular expression grouping used to find
402 the entire emphasized word.  The third is a number that says what
403 regexp grouping should be displayed and highlighted.  The fourth
404 is the face used for highlighting."
405   :type
406   '(repeat
407     (menu-choice
408      :format "%[Customizing Style%]\n%v"
409      :indent 2
410      (group :tag "Default"
411             :value ("" 0 0 default)
412             :value-create
413             (lambda (widget)
414               (let ((value (widget-get
415                             (cadr (widget-get (widget-get widget :parent)
416                                               :args))
417                             :value)))
418                 (if (not (eq (nth 2 value) 'default))
419                     (widget-put
420                      widget
421                      :value
422                      (gnus-emphasis-custom-value-to-external value))))
423               (widget-group-value-create widget))
424             regexp
425             (integer :format "Match group: %v")
426             (integer :format "Emphasize group: %v")
427             face)
428      (group :tag "Simple"
429             :value (("_" . "_") nil default)
430             (cons :format "%v"
431                   (regexp :format "Start regexp: %v")
432                   (regexp :format "End regexp: %v"))
433             (boolean :format "Show start and end patterns: %[%v%]\n"
434                      :on " On " :off " Off ")
435             face)))
436   :get (lambda (symbol)
437          (mapcar 'gnus-emphasis-custom-value-to-internal
438                  (default-value symbol)))
439   :set (lambda (symbol value)
440          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441                                      value)))
442   :group 'gnus-article-emphasis)
443
444 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
445   "A regexp to describe whitespace which should not be emphasized.
446 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
447 The former avoids underlining of leading and trailing whitespace,
448 and the latter avoids underlining any whitespace at all."
449   :version "21.1"
450   :group 'gnus-article-emphasis
451   :type 'regexp)
452
453 (defface gnus-emphasis-bold '((t (:bold t)))
454   "Face used for displaying strong emphasized text (*word*)."
455   :group 'gnus-article-emphasis)
456
457 (defface gnus-emphasis-italic '((t (:italic t)))
458   "Face used for displaying italic emphasized text (/word/)."
459   :group 'gnus-article-emphasis)
460
461 (defface gnus-emphasis-underline '((t (:underline t)))
462   "Face used for displaying underlined emphasized text (_word_)."
463   :group 'gnus-article-emphasis)
464
465 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
466   "Face used for displaying underlined bold emphasized text (_*word*_)."
467   :group 'gnus-article-emphasis)
468
469 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
470   "Face used for displaying underlined italic emphasized text (_/word/_)."
471   :group 'gnus-article-emphasis)
472
473 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
474   "Face used for displaying bold italic emphasized text (/*word*/)."
475   :group 'gnus-article-emphasis)
476
477 (defface gnus-emphasis-underline-bold-italic
478   '((t (:bold t :italic t :underline t)))
479   "Face used for displaying underlined bold italic emphasized text.
480 Example: (_/*word*/_)."
481   :group 'gnus-article-emphasis)
482
483 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
484                                       '((t (:strikethru t)))
485                                     '((t (:strike-through t))))
486   "Face used for displaying strike-through text (-word-)."
487   :group 'gnus-article-emphasis)
488
489 (defface gnus-emphasis-highlight-words
490   '((t (:background "black" :foreground "yellow")))
491   "Face used for displaying highlighted words."
492   :group 'gnus-article-emphasis)
493
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495   "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
497
498 The variable can also be function, which should return a complete Date
499 header.  The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501   :type '(choice string function)
502   :link '(custom-manual "(gnus)Article Date")
503   :group 'gnus-article-washing)
504
505 (defcustom gnus-save-all-headers t
506   "*If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
509 might have."
510   :group 'gnus-article-saving
511   :type 'boolean)
512
513 (defcustom gnus-prompt-before-saving 'always
514   "*This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files.  If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles.  If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521   :group 'gnus-article-saving
522   :type '(choice (item always)
523                  (item :tag "never" nil)
524                  (sexp :tag "once" :format "%t\n" :value t)))
525
526 (defcustom gnus-saved-headers gnus-visible-headers
527   "Headers to keep if `gnus-save-all-headers' is nil.
528 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
529 If that variable is nil, however, all headers that match this regexp
530 will be kept while the rest will be deleted before saving.  This and
531 `gnus-save-all-headers' will be overridden by the `:headers' property
532 that the symbol of the saver function, which is specified by
533 `gnus-default-article-saver', might have."
534   :group 'gnus-article-saving
535   :type 'regexp)
536
537 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
538 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
539   "A function to save articles in your favorite format.
540 The function will be called by way of the `gnus-summary-save-article'
541 command, and friends such as `gnus-summary-save-article-rmail'.
542
543 Gnus provides the following functions:
544
545 * gnus-summary-save-in-rmail (Rmail format)
546 * gnus-summary-save-in-mail (Unix mail format)
547 * gnus-summary-save-in-folder (MH folder)
548 * gnus-summary-save-in-file (article format)
549 * gnus-summary-save-body-in-file (article body)
550 * gnus-summary-save-in-vm (use VM's folder format)
551 * gnus-summary-write-to-file (article format -- overwrite)
552 * gnus-summary-write-body-to-file (article body -- overwrite)
553 * gnus-summary-save-in-pipe (article format)
554
555 The symbol of each function may have the following properties:
556
557 * :decode
558 The value non-nil means save decoded articles.  This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
561 `gnus-summary-save-in-pipe'.
562
563 * :function
564 The value specifies an alternative function which appends, not
565 overwrites, articles to a file.  This implies that when saving many
566 articles at a time, `gnus-prompt-before-saving' is bound to t and all
567 articles are saved in a single file.  This is meaningful only with
568 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569
570 * :headers
571 The value specifies the symbol of a variable of which the value
572 specifies headers to be saved.  If it is omitted,
573 `gnus-save-all-headers' and `gnus-saved-headers' control what
574 headers should be saved."
575   :group 'gnus-article-saving
576   :type '(radio (function-item gnus-summary-save-in-rmail)
577                 (function-item gnus-summary-save-in-mail)
578                 (function-item gnus-summary-save-in-folder)
579                 (function-item gnus-summary-save-in-file)
580                 (function-item gnus-summary-save-body-in-file)
581                 (function-item gnus-summary-save-in-vm)
582                 (function-item gnus-summary-write-to-file)
583                 (function-item gnus-summary-write-body-to-file)
584                 (function-item gnus-summary-save-in-pipe)
585                 (function)))
586
587 (defcustom gnus-article-save-coding-system
588   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
589       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
590       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
591       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
592   "Coding system used to save decoded articles to a file.
593
594 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
595 which can safely encode any characters in text.  This is used by the
596 commands including:
597
598 * gnus-summary-save-article-file
599 * gnus-summary-save-article-body-file
600 * gnus-summary-write-article-file
601 * gnus-summary-write-article-body-file
602
603 and the functions to which you may set `gnus-default-article-saver':
604
605 * gnus-summary-save-in-file
606 * gnus-summary-save-body-in-file
607 * gnus-summary-write-to-file
608 * gnus-summary-write-body-to-file
609
610 Those commands and functions save just text displayed in the article
611 buffer to a file if the value of this variable is non-nil.  Note that
612 buttonized MIME parts will be lost in a saved file in that case.
613 Otherwise, raw articles will be saved."
614   :group 'gnus-article-saving
615   :type `(choice
616           :format "%{%t%}:\n %[Value Menu%] %v"
617           (const :tag "Save raw articles" nil)
618           ,@(delq nil
619                   (mapcar
620                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
621                    '((const :tag "UTF-8" utf-8)
622                      (const :tag "iso-2022-7bit" iso-2022-7bit)
623                      (const :tag "Emacs internal" emacs-mule)
624                      (const :tag "escape-quoted" escape-quoted))))
625           (symbol :tag "Coding system")))
626
627 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
628   "A function generating a file name to save articles in Rmail format.
629 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
630   :group 'gnus-article-saving
631   :type 'function)
632
633 (defcustom gnus-mail-save-name 'gnus-plain-save-name
634   "A function generating a file name to save articles in Unix mail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636   :group 'gnus-article-saving
637   :type 'function)
638
639 (defcustom gnus-folder-save-name 'gnus-folder-save-name
640   "A function generating a file name to save articles in MH folder.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
642   :group 'gnus-article-saving
643   :type 'function)
644
645 (defcustom gnus-file-save-name 'gnus-numeric-save-name
646   "A function generating a file name to save articles in article format.
647 The function is called with NEWSGROUP, HEADERS, and optional
648 LAST-FILE."
649   :group 'gnus-article-saving
650   :type 'function)
651
652 (defcustom gnus-split-methods
653   '((gnus-article-archive-name)
654     (gnus-article-nndoc-name))
655   "*Variable used to suggest where articles are to be saved.
656 For instance, if you would like to save articles related to Gnus in
657 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
658 you could set this variable to something like:
659
660  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
661    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662
663 This variable is an alist where the key is the match and the
664 value is a list of possible files to save in if the match is
665 non-nil.
666
667 If the match is a string, it is used as a regexp match on the
668 article.  If the match is a symbol, that symbol will be funcalled
669 from the buffer of the article to be saved with the newsgroup as the
670 parameter.  If it is a list, it will be evalled in the same buffer.
671
672 If this form or function returns a string, this string will be used as a
673 possible file name; and if it returns a non-nil list, that list will be
674 used as possible file names."
675   :group 'gnus-article-saving
676   :type '(repeat (choice (list :value (fun) function)
677                          (cons :value ("" "") regexp (repeat string))
678                          (sexp :value nil))))
679
680 (defcustom gnus-page-delimiter "^\^L"
681   "*Regexp describing what to use as article page delimiters.
682 The default value is \"^\^L\", which is a form linefeed at the
683 beginning of a line."
684   :type 'regexp
685   :group 'gnus-article-various)
686
687 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
688   "*The format specification for the article mode line.
689 See `gnus-summary-mode-line-format' for a closer description.
690
691 The following additional specs are available:
692
693 %w  The article washing status.
694 %m  The number of MIME parts in the article."
695   :version "24.1"
696   :type 'string
697   :group 'gnus-article-various)
698
699 (defcustom gnus-article-mode-hook nil
700   "*A hook for Gnus article mode."
701   :type 'hook
702   :group 'gnus-article-various)
703
704 (when (featurep 'xemacs)
705   ;; Extracted from gnus-xmas-define in order to preserve user settings
706   (when (fboundp 'turn-off-scroll-in-place)
707     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
708   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
709   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710
711 (defcustom gnus-article-menu-hook nil
712   "*Hook run after the creation of the article mode menu."
713   :type 'hook
714   :group 'gnus-article-various)
715
716 (defcustom gnus-article-prepare-hook nil
717   "*A hook called after an article has been prepared in the article buffer."
718   :type 'hook
719   :group 'gnus-article-various)
720
721 (defcustom gnus-copy-article-ignored-headers nil
722   "List of headers to be removed when copying an article.
723 Each element is a regular expression."
724   :version "23.1" ;; No Gnus
725   :type '(repeat regexp)
726   :group 'gnus-article-various)
727
728 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
729                         "Gnus 5.10 (Emacs 22.1)")
730
731 (defface gnus-button
732   '((t (:weight bold)))
733   "Face used for highlighting a button in the article buffer."
734   :group 'gnus-article-buttons)
735
736 (defcustom gnus-article-button-face 'gnus-button
737   "Face used for highlighting buttons in the article buffer.
738
739 An article button is a piece of text that you can activate by pressing
740 `RET' or `mouse-2' above it."
741   :type 'face
742   :group 'gnus-article-buttons)
743
744 (defcustom gnus-article-mouse-face 'highlight
745   "Face used for mouse highlighting in the article buffer.
746
747 Article buttons will be displayed in this face when the cursor is
748 above them."
749   :type 'face
750   :group 'gnus-article-buttons)
751
752 (defcustom gnus-signature-face 'gnus-signature
753   "Face used for highlighting a signature in the article buffer.
754 Obsolete; use the face `gnus-signature' for customizations instead."
755   :type 'face
756   :group 'gnus-article-highlight
757   :group 'gnus-article-signature)
758
759 (defface gnus-signature
760   '((t
761      (:italic t)))
762   "Face used for highlighting a signature in the article buffer."
763   :group 'gnus-article-highlight
764   :group 'gnus-article-signature)
765 ;; backward-compatibility alias
766 (put 'gnus-signature-face 'face-alias 'gnus-signature)
767 (put 'gnus-signature-face 'obsolete-face "22.1")
768
769 (defface gnus-header-from
770   '((((class color)
771       (background dark))
772      (:foreground "PaleGreen1"))
773     (((class color)
774       (background light))
775      (:foreground "red3"))
776     (t
777      (:italic t)))
778   "Face used for displaying from headers."
779   :group 'gnus-article-headers
780   :group 'gnus-article-highlight)
781 ;; backward-compatibility alias
782 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
783 (put 'gnus-header-from-face 'obsolete-face "22.1")
784
785 (defface gnus-header-subject
786   '((((class color)
787       (background dark))
788      (:foreground "SeaGreen1"))
789     (((class color)
790       (background light))
791      (:foreground "red4"))
792     (t
793      (:bold t :italic t)))
794   "Face used for displaying subject headers."
795   :group 'gnus-article-headers
796   :group 'gnus-article-highlight)
797 ;; backward-compatibility alias
798 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
799 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800
801 (defface gnus-header-newsgroups
802   '((((class color)
803       (background dark))
804      (:foreground "yellow" :italic t))
805     (((class color)
806       (background light))
807      (:foreground "MidnightBlue" :italic t))
808     (t
809      (:italic t)))
810   "Face used for displaying newsgroups headers.
811 In the default setup this face is only used for crossposted
812 articles."
813   :group 'gnus-article-headers
814   :group 'gnus-article-highlight)
815 ;; backward-compatibility alias
816 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
817 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818
819 (defface gnus-header-name
820   '((((class color)
821       (background dark))
822      (:foreground "SpringGreen2"))
823     (((class color)
824       (background light))
825      (:foreground "maroon"))
826     (t
827      (:bold t)))
828   "Face used for displaying header names."
829   :group 'gnus-article-headers
830   :group 'gnus-article-highlight)
831 ;; backward-compatibility alias
832 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
833 (put 'gnus-header-name-face 'obsolete-face "22.1")
834
835 (defface gnus-header-content
836   '((((class color)
837       (background dark))
838      (:foreground "SpringGreen1" :italic t))
839     (((class color)
840       (background light))
841      (:foreground "indianred4" :italic t))
842     (t
843      (:italic t)))  "Face used for displaying header content."
844   :group 'gnus-article-headers
845   :group 'gnus-article-highlight)
846 ;; backward-compatibility alias
847 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
848 (put 'gnus-header-content-face 'obsolete-face "22.1")
849
850 (defcustom gnus-header-face-alist
851   '(("From" nil gnus-header-from)
852     ("Subject" nil gnus-header-subject)
853     ("Newsgroups:.*," nil gnus-header-newsgroups)
854     ("" gnus-header-name gnus-header-content))
855   "*Controls highlighting of article headers.
856
857 An alist of the form (HEADER NAME CONTENT).
858
859 HEADER is a regular expression which should match the name of a
860 header and NAME and CONTENT are either face names or nil.
861
862 The name of each header field will be displayed using the face
863 specified by the first element in the list where HEADER matches
864 the header name and NAME is non-nil.  Similarly, the content will
865 be displayed by the first non-nil matching CONTENT face."
866   :group 'gnus-article-headers
867   :group 'gnus-article-highlight
868   :type '(repeat (list (regexp :tag "Header")
869                        (choice :tag "Name"
870                                (item :tag "skip" nil)
871                                (face :value default))
872                        (choice :tag "Content"
873                                (item :tag "skip" nil)
874                                (face :value default)))))
875
876 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
877                                           '((xface . (:face gnus-x-face)))
878                                         '((pbm . (:face gnus-x-face))
879                                           (png . nil)))
880   "Alist of image types and properties applied to Face and X-Face images.
881 Here are examples:
882
883 ;; Specify the altitude of Face images in the From header.
884 \(setq gnus-face-properties-alist
885       '((pbm . (:face gnus-x-face :ascent 80))
886         (png . (:ascent 80))))
887
888 ;; Show Face images as pressed buttons.
889 \(setq gnus-face-properties-alist
890       '((pbm . (:face gnus-x-face :relief -2))
891         (png . (:relief -2))))
892
893 See the manual for the valid properties for various image types.
894 Currently, `pbm' is used for X-Face images and `png' is used for Face
895 images in Emacs.  Only the `:face' property is effective on the `xface'
896 image type in XEmacs if it is built with the libcompface library."
897   :version "23.1" ;; No Gnus
898   :group 'gnus-article-headers
899   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900
901 (defcustom gnus-article-decode-hook
902   '(article-decode-charset article-decode-encoded-words
903                            article-decode-group-name article-decode-idna-rhs)
904   "*Hook run to decode charsets in articles."
905   :group 'gnus-article-headers
906   :type 'hook)
907
908 (defcustom gnus-display-mime-function 'gnus-display-mime
909   "Function to display MIME articles."
910   :group 'gnus-article-mime
911   :type 'function)
912
913 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
914   "Function used to decode headers.")
915
916 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
917   "Function used to decode addresses.")
918
919 (defvar gnus-article-dumbquotes-map
920   '((?\200 "EUR")
921     (?\202 ",")
922     (?\203 "f")
923     (?\204 ",,")
924     (?\205 "...")
925     (?\213 "<")
926     (?\214 "OE")
927     (?\221 "`")
928     (?\222 "'")
929     (?\223 "``")
930     (?\224 "\"")
931     (?\225 "*")
932     (?\226 "-")
933     (?\227 "--")
934     (?\230 "~")
935     (?\231 "(TM)")
936     (?\233 ">")
937     (?\234 "oe")
938     (?\264 "'"))
939   "Table for MS-to-Latin1 translation.")
940
941 (defcustom gnus-ignored-mime-types nil
942   "List of MIME types that should be ignored by Gnus."
943   :version "21.1"
944   :group 'gnus-article-mime
945   :type '(repeat regexp))
946
947 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
948   "List of MIME types that should not be given buttons when rendered inline.
949 See also `gnus-buttonized-mime-types' which may override this variable.
950 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
951   :version "21.1"
952   :group 'gnus-article-mime
953   :type '(repeat regexp))
954
955 (defcustom gnus-buttonized-mime-types nil
956   "List of MIME types that should be given buttons when rendered inline.
957 If set, this variable overrides `gnus-unbuttonized-mime-types'.
958 To see e.g. security buttons you could set this to
959 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
960 this list to display radio buttons that allow you to choose one of two
961 media types those mails include.  See also `mm-discouraged-alternatives'.
962 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
963   :version "22.1"
964   :group 'gnus-article-mime
965   :type '(repeat regexp))
966
967 (defcustom gnus-inhibit-mime-unbuttonizing nil
968   "If non-nil, all MIME parts get buttons.
969 When nil (the default value), then some MIME parts do not get buttons,
970 as described by the variables `gnus-buttonized-mime-types' and
971 `gnus-unbuttonized-mime-types'."
972   :version "22.1"
973   :group 'gnus-article-mime
974   :type 'boolean)
975
976 (defcustom gnus-body-boundary-delimiter "_"
977   "String used to delimit header and body.
978 This variable is used by `gnus-article-treat-body-boundary' which can
979 be controlled by `gnus-treat-body-boundary'."
980   :version "22.1"
981   :group 'gnus-article-various
982   :type '(choice (item :tag "None" :value nil)
983                  string))
984
985 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
986                                   "/usr/share/picons")
987   "Defines the location of the faces database.
988 For information on obtaining this database of pretty pictures, please
989 see http://www.cs.indiana.edu/picons/ftp/index.html"
990   :version "22.1"
991   :type '(repeat directory)
992   :link '(url-link :tag "download"
993                    "http://www.cs.indiana.edu/picons/ftp/index.html")
994   :link '(custom-manual "(gnus)Picons")
995   :group 'gnus-picon)
996
997 (defun gnus-picons-installed-p ()
998   "Say whether picons are installed on your machine."
999   (let ((installed nil))
1000     (dolist (database gnus-picon-databases)
1001       (when (file-exists-p database)
1002         (setq installed t)))
1003     installed))
1004
1005 (defcustom gnus-article-mime-part-function nil
1006   "Function called with a MIME handle as the argument.
1007 This is meant for people who want to do something automatic based
1008 on parts -- for instance, adding Vcard info to a database."
1009   :group 'gnus-article-mime
1010   :type '(choice (const nil)
1011                  function))
1012
1013 (defcustom gnus-mime-multipart-functions nil
1014   "An alist of MIME types to functions to display them."
1015   :version "21.1"
1016   :group 'gnus-article-mime
1017   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018
1019 (defcustom gnus-article-date-headers '(combined-lapsed)
1020   "A list of Date header formats to display.
1021 Valid formats are `ut' (universal time), `local' (local time
1022 zone), `english' (readable English), `lapsed' (elapsed time),
1023 `combined-lapsed' (both the original date and the elapsed time),
1024 `original' (the original date header), `iso8601' (ISO8601
1025 format), and `user-defined' (a user-defined format defined by the
1026 `gnus-article-time-format' variable).
1027
1028 You have as many date headers as you want in the article buffer.
1029 Some of these headers are updated automatically.  See
1030 `gnus-article-update-date-headers' for details."
1031   :version "24.1"
1032   :group 'gnus-article-headers
1033   :type '(set
1034           (const :tag "Universal time (UT)" ut)
1035           (const :tag "Local time zone" local)
1036           (const :tag "Readable English" english)
1037           (const :tag "Elapsed time" lapsed)
1038           (const :tag "Original and elapsed time" combined-lapsed)
1039           (const :tag "Original date header" original)
1040           (const :tag "ISO8601 format" iso8601)
1041           (const :tag "User-defined" user-defined)))
1042
1043 (defcustom gnus-article-update-date-headers nil
1044   "A number that says how often to update the date header (in seconds).
1045 If nil, don't update it at all."
1046   :version "24.1"
1047   :group 'gnus-article-headers
1048   :type '(choice
1049           (item :tag "Don't update" :value nil)
1050           integer))
1051
1052 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1053   "Function called with a MIME handle as the argument.
1054 This is meant for people who want to view first matched part.
1055 For `undisplayed-alternative' (default), the first undisplayed
1056 part or alternative part is used.  For `undisplayed', the first
1057 undisplayed part is used.  For a function, the first part which
1058 the function return t is used.  For nil, the first part is
1059 used."
1060   :version "21.1"
1061   :group 'gnus-article-mime
1062   :type '(choice
1063           (item :tag "first" :value nil)
1064           (item :tag "undisplayed" :value undisplayed)
1065           (item :tag "undisplayed or alternative"
1066                 :value undisplayed-alternative)
1067           (function)))
1068
1069 (defcustom gnus-mime-action-alist
1070   '(("save to file" . gnus-mime-save-part)
1071     ("save and strip" . gnus-mime-save-part-and-strip)
1072     ("replace with file" . gnus-mime-replace-part)
1073     ("delete part" . gnus-mime-delete-part)
1074     ("display as text" . gnus-mime-inline-part)
1075     ("view the part" . gnus-mime-view-part)
1076     ("pipe to command" . gnus-mime-pipe-part)
1077     ("toggle display" . gnus-article-press-button)
1078     ("toggle display" . gnus-article-view-part-as-charset)
1079     ("view as type" . gnus-mime-view-part-as-type)
1080     ("view internally" . gnus-mime-view-part-internally)
1081     ("view externally" . gnus-mime-view-part-externally))
1082   "An alist of actions that run on the MIME attachment."
1083   :group 'gnus-article-mime
1084   :type '(repeat (cons (string :tag "name")
1085                        (function))))
1086
1087 (defcustom gnus-auto-select-part 1
1088   "Advance to next MIME part when deleting or stripping parts.
1089
1090 When 0, point will be placed on the same part as before.  When
1091 positive (negative), move point forward (backwards) this many
1092 parts.  When nil, redisplay article."
1093   :version "23.1" ;; No Gnus
1094   :group 'gnus-article-mime
1095   :type '(choice (const nil :tag "Redisplay article.")
1096                  (const 1 :tag "Next part.")
1097                  (const 0 :tag "Current part.")
1098                  integer))
1099
1100 ;;;
1101 ;;; The treatment variables
1102 ;;;
1103
1104 (defvar gnus-part-display-hook nil
1105   "Hook called on parts that are to receive treatment.")
1106
1107 (defvar gnus-article-treat-custom
1108   '(choice (const :tag "Off" nil)
1109            (const :tag "On" t)
1110            (const :tag "Header" head)
1111            (const :tag "First" first)
1112            (const :tag "Last" last)
1113            (integer :tag "Less")
1114            (repeat :tag "Groups" regexp)
1115            (sexp :tag "Predicate")))
1116
1117 (defvar gnus-article-treat-head-custom
1118   '(choice (const :tag "Off" nil)
1119            (const :tag "Header" head)))
1120
1121 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1122                                    "text/x-patch" "text/html")
1123   "Part types eligible for treatment.")
1124
1125 (defvar gnus-inhibit-treatment nil
1126   "Whether to inhibit treatment.")
1127
1128 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1129   "Highlight the signature.
1130 Valid values are nil, t, `head', `first', `last', an integer or a
1131 predicate.  See Info node `(gnus)Customizing Articles'."
1132   :group 'gnus-article-treat
1133   :link '(custom-manual "(gnus)Customizing Articles")
1134   :type gnus-article-treat-custom)
1135 (put 'gnus-treat-highlight-signature 'highlight t)
1136
1137 (defcustom gnus-treat-buttonize 100000
1138   "Add buttons.
1139 Valid values are nil, t, `head', `first', `last', an integer or a
1140 predicate.  See Info node `(gnus)Customizing Articles'."
1141   :group 'gnus-article-treat
1142   :link '(custom-manual "(gnus)Customizing Articles")
1143   :type gnus-article-treat-custom)
1144 (put 'gnus-treat-buttonize 'highlight t)
1145
1146 (defcustom gnus-treat-buttonize-head 'head
1147   "Add buttons to the head.
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate.  See Info node `(gnus)Customizing Articles'."
1150   :group 'gnus-article-treat
1151   :link '(custom-manual "(gnus)Customizing Articles")
1152   :type gnus-article-treat-head-custom)
1153 (put 'gnus-treat-buttonize-head 'highlight t)
1154
1155 (defcustom gnus-treat-date 'head
1156   "Display dates according to the `gnus-article-date-headers' variable.
1157 Valid values are nil, t, `head', `first', `last', an integer or a
1158 predicate.  See Info node `(gnus)Customizing Articles'."
1159   :version "24.1"
1160   :group 'gnus-article-treat
1161   :link '(custom-manual "(gnus)Customizing Articles")
1162   :type gnus-article-treat-head-custom)
1163
1164 (defcustom gnus-treat-emphasize 50000
1165   "Emphasize text.
1166 Valid values are nil, t, `head', `first', `last', an integer or a
1167 predicate.  See Info node `(gnus)Customizing Articles'."
1168   :group 'gnus-article-treat
1169   :link '(custom-manual "(gnus)Customizing Articles")
1170   :type gnus-article-treat-custom)
1171 (put 'gnus-treat-emphasize 'highlight t)
1172
1173 (defcustom gnus-treat-strip-cr nil
1174   "Remove carriage returns.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate.  See Info node `(gnus)Customizing Articles'."
1177   :version "22.1"
1178   :group 'gnus-article-treat
1179   :link '(custom-manual "(gnus)Customizing Articles")
1180   :type gnus-article-treat-custom)
1181
1182 (defcustom gnus-treat-unsplit-urls nil
1183   "Remove newlines from within URLs.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate.  See Info node `(gnus)Customizing Articles'."
1186   :version "22.1"
1187   :group 'gnus-article-treat
1188   :link '(custom-manual "(gnus)Customizing Articles")
1189   :type gnus-article-treat-custom)
1190
1191 (defcustom gnus-treat-leading-whitespace nil
1192   "Remove leading whitespace in headers.
1193 Valid values are nil, t, `head', `first', `last', an integer or a
1194 predicate.  See Info node `(gnus)Customizing Articles'."
1195   :version "22.1"
1196   :group 'gnus-article-treat
1197   :link '(custom-manual "(gnus)Customizing Articles")
1198   :type gnus-article-treat-custom)
1199
1200 (defcustom gnus-treat-hide-headers 'head
1201   "Hide headers.
1202 Valid values are nil, t, `head', `first', `last', an integer or a
1203 predicate.  See Info node `(gnus)Customizing Articles'."
1204   :group 'gnus-article-treat
1205   :link '(custom-manual "(gnus)Customizing Articles")
1206   :type gnus-article-treat-head-custom)
1207
1208 (defcustom gnus-treat-hide-boring-headers nil
1209   "Hide boring headers.
1210 Valid values are nil, t, `head', `first', `last', an integer or a
1211 predicate.  See Info node `(gnus)Customizing Articles'."
1212   :group 'gnus-article-treat
1213   :link '(custom-manual "(gnus)Customizing Articles")
1214   :type gnus-article-treat-head-custom)
1215
1216 (defcustom gnus-treat-hide-signature nil
1217   "Hide the signature.
1218 Valid values are nil, t, `head', `first', `last', an integer or a
1219 predicate.  See Info node `(gnus)Customizing Articles'."
1220   :group 'gnus-article-treat
1221   :link '(custom-manual "(gnus)Customizing Articles")
1222   :type gnus-article-treat-custom)
1223
1224 (defcustom gnus-treat-fill-article nil
1225   "Fill the article.
1226 Valid values are nil, t, `head', `first', `last', an integer or a
1227 predicate.  See Info node `(gnus)Customizing Articles'."
1228   :group 'gnus-article-treat
1229   :link '(custom-manual "(gnus)Customizing Articles")
1230   :type gnus-article-treat-custom)
1231
1232 (defcustom gnus-treat-hide-citation nil
1233   "Hide cited text.
1234 Valid values are nil, t, `head', `first', `last', an integer or a
1235 predicate.  See Info node `(gnus)Customizing Articles'.
1236
1237 See `gnus-article-highlight-citation' for variables used to
1238 control what it hides."
1239   :group 'gnus-article-treat
1240   :link '(custom-manual "(gnus)Customizing Articles")
1241   :type gnus-article-treat-custom)
1242
1243 (defcustom gnus-treat-hide-citation-maybe nil
1244   "Hide cited text according to certain conditions.
1245 Valid values are nil, t, `head', `first', `last', an integer or a
1246 predicate.  See Info node `(gnus)Customizing Articles'.
1247
1248 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1249 how to control what it hides."
1250   :group 'gnus-article-treat
1251   :link '(custom-manual "(gnus)Customizing Articles")
1252   :type gnus-article-treat-custom)
1253
1254 (defcustom gnus-treat-strip-list-identifiers 'head
1255   "Strip list identifiers from `gnus-list-identifiers`.
1256 Valid values are nil, t, `head', `first', `last', an integer or a
1257 predicate.  See Info node `(gnus)Customizing Articles'."
1258   :version "21.1"
1259   :group 'gnus-article-treat
1260   :link '(custom-manual "(gnus)Customizing Articles")
1261   :type gnus-article-treat-custom)
1262
1263 (gnus-define-group-parameter
1264  list-identifier
1265  :variable-document
1266  "Alist of regexps and correspondent identifiers."
1267  :variable-group gnus-article-washing
1268  :parameter-type
1269  '(choice :tag "Identifier"
1270           :value nil
1271           (symbol :tag "Item in `gnus-list-identifiers'" none)
1272           regexp
1273           (const :tag "None" nil))
1274  :parameter-document
1275  "If non-nil, specify how to remove `identifiers' from articles' subject.
1276
1277 Any symbol is used to look up a regular expression to match the
1278 banner in `gnus-list-identifiers'.  A string is used as a regular
1279 expression to match the identifier directly.")
1280
1281 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1282                         "Gnus 5.10 (Emacs 22.1)")
1283
1284 (defcustom gnus-treat-strip-pem nil
1285   "Strip PEM signatures.
1286 Valid values are nil, t, `head', `first', `last', an integer or a
1287 predicate.  See Info node `(gnus)Customizing Articles'."
1288   :group 'gnus-article-treat
1289   :link '(custom-manual "(gnus)Customizing Articles")
1290   :type gnus-article-treat-custom)
1291
1292 (defcustom gnus-treat-strip-banner t
1293   "Strip banners from articles.
1294 The banner to be stripped is specified in the `banner' group parameter.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate.  See Info node `(gnus)Customizing Articles'."
1297   :group 'gnus-article-treat
1298   :link '(custom-manual "(gnus)Customizing Articles")
1299   :type gnus-article-treat-custom)
1300
1301 (defcustom gnus-treat-highlight-headers 'head
1302   "Highlight the headers.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate.  See Info node `(gnus)Customizing Articles'."
1305   :group 'gnus-article-treat
1306   :link '(custom-manual "(gnus)Customizing Articles")
1307   :type gnus-article-treat-head-custom)
1308 (put 'gnus-treat-highlight-headers 'highlight t)
1309
1310 (defcustom gnus-treat-highlight-citation t
1311   "Highlight cited text.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate.  See Info node `(gnus)Customizing Articles'."
1314   :group 'gnus-article-treat
1315   :link '(custom-manual "(gnus)Customizing Articles")
1316   :type gnus-article-treat-custom)
1317 (put 'gnus-treat-highlight-citation 'highlight t)
1318
1319 (defcustom gnus-treat-strip-headers-in-body t
1320   "Strip the X-No-Archive header line from the beginning of the body.
1321 Valid values are nil, t, `head', `first', `last', an integer or a
1322 predicate.  See Info node `(gnus)Customizing Articles'."
1323   :version "21.1"
1324   :group 'gnus-article-treat
1325   :link '(custom-manual "(gnus)Customizing Articles")
1326   :type gnus-article-treat-custom)
1327
1328 (defcustom gnus-treat-strip-trailing-blank-lines nil
1329   "Strip trailing blank lines.
1330 Valid values are nil, t, `head', `first', `last', an integer or a
1331 predicate.  See Info node `(gnus)Customizing Articles'.
1332
1333 When set to t, it also strips trailing blanks in all MIME parts.
1334 Consider to use `last' instead."
1335   :group 'gnus-article-treat
1336   :link '(custom-manual "(gnus)Customizing Articles")
1337   :type gnus-article-treat-custom)
1338
1339 (defcustom gnus-treat-strip-leading-blank-lines nil
1340   "Strip leading blank lines.
1341 Valid values are nil, t, `head', `first', `last', an integer or a
1342 predicate.  See Info node `(gnus)Customizing Articles'.
1343
1344 When set to t, it also strips trailing blanks in all MIME parts."
1345   :group 'gnus-article-treat
1346   :link '(custom-manual "(gnus)Customizing Articles")
1347   :type gnus-article-treat-custom)
1348
1349 (defcustom gnus-treat-strip-multiple-blank-lines nil
1350   "Strip multiple blank lines.
1351 Valid values are nil, t, `head', `first', `last', an integer or a
1352 predicate.  See Info node `(gnus)Customizing Articles'."
1353   :group 'gnus-article-treat
1354   :link '(custom-manual "(gnus)Customizing Articles")
1355   :type gnus-article-treat-custom)
1356
1357 (defcustom gnus-treat-unfold-headers 'head
1358   "Unfold folded header lines.
1359 Valid values are nil, t, `head', `first', `last', an integer or a
1360 predicate.  See Info node `(gnus)Customizing Articles'."
1361   :version "22.1"
1362   :group 'gnus-article-treat
1363   :link '(custom-manual "(gnus)Customizing Articles")
1364   :type gnus-article-treat-custom)
1365
1366 (defcustom gnus-article-unfold-long-headers nil
1367   "If non-nil, allow unfolding headers even if the header is long.
1368 If it is a regexp, only long headers matching this regexp are unfolded.
1369 If it is t, all long headers are unfolded.
1370
1371 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1372   :version "23.1" ;; No Gnus
1373   :group 'gnus-article-treat
1374   :type '(choice (const nil)
1375                  (const :tag "all" t)
1376                  (regexp)))
1377
1378 (defcustom gnus-treat-fold-headers nil
1379   "Fold headers.
1380 Valid values are nil, t, `head', `first', `last', an integer or a
1381 predicate.  See Info node `(gnus)Customizing Articles'."
1382   :version "22.1"
1383   :group 'gnus-article-treat
1384   :link '(custom-manual "(gnus)Customizing Articles")
1385   :type gnus-article-treat-custom)
1386
1387 (defcustom gnus-treat-fold-newsgroups 'head
1388   "Fold the Newsgroups and Followup-To headers.
1389 Valid values are nil, t, `head', `first', `last', an integer or a
1390 predicate.  See Info node `(gnus)Customizing Articles'."
1391   :version "22.1"
1392   :group 'gnus-article-treat
1393   :link '(custom-manual "(gnus)Customizing Articles")
1394   :type gnus-article-treat-custom)
1395
1396 (defcustom gnus-treat-overstrike t
1397   "Treat overstrike highlighting.
1398 Valid values are nil, t, `head', `first', `last', an integer or a
1399 predicate.  See Info node `(gnus)Customizing Articles'."
1400   :group 'gnus-article-treat
1401   :link '(custom-manual "(gnus)Customizing Articles")
1402   :type gnus-article-treat-custom)
1403 (put 'gnus-treat-overstrike 'highlight t)
1404
1405 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1406   "Treat ANSI SGR control sequences.
1407 Valid values are nil, t, `head', `first', `last', an integer or a
1408 predicate.  See Info node `(gnus)Customizing Articles'."
1409   :group 'gnus-article-treat
1410   :link '(custom-manual "(gnus)Customizing Articles")
1411   :type gnus-article-treat-custom)
1412
1413 (make-obsolete-variable 'gnus-treat-display-xface
1414                         'gnus-treat-display-x-face "Emacs 22.1")
1415
1416 (defcustom gnus-treat-display-x-face
1417   (and (not noninteractive)
1418        (gnus-image-type-available-p 'xbm)
1419        (if (featurep 'xemacs)
1420            (featurep 'xface)
1421          (condition-case nil
1422              (and (string-match "^0x" (shell-command-to-string "uncompface"))
1423                   (executable-find "icontopbm"))
1424            ;; shell-command-to-string may signal an error, e.g. if
1425            ;; shell-file-name is not found.
1426            (error nil)))
1427        'head)
1428   "Display X-Face headers.
1429 Valid values are nil and `head'.
1430 See Info node `(gnus)Customizing Articles' and Info node
1431 `(gnus)X-Face' for details."
1432   :group 'gnus-article-treat
1433   :version "21.1"
1434   :link '(custom-manual "(gnus)Customizing Articles")
1435   :link '(custom-manual "(gnus)X-Face")
1436   :type gnus-article-treat-head-custom
1437   :set (lambda (symbol value)
1438          (set-default
1439           symbol
1440           (cond ((or (boundp symbol) (get symbol 'saved-value))
1441                  value)
1442                 ((boundp 'gnus-treat-display-xface)
1443                  (message "\
1444 ** gnus-treat-display-xface is an obsolete variable;\
1445  use gnus-treat-display-x-face instead")
1446                  (default-value 'gnus-treat-display-xface))
1447                 ((get 'gnus-treat-display-xface 'saved-value)
1448                  (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450  use gnus-treat-display-x-face instead")
1451                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1452                 (t
1453                  value)))))
1454 (put 'gnus-treat-display-x-face 'highlight t)
1455
1456 (defcustom gnus-treat-display-face
1457   (and (not noninteractive)
1458        (gnus-image-type-available-p 'png)
1459        'head)
1460   "Display Face headers.
1461 Valid values are nil, t, `head', `first', `last', an integer or a
1462 predicate.  See Info node `(gnus)Customizing Articles' and Info
1463 node `(gnus)Face' for details."
1464   :group 'gnus-article-treat
1465   :version "22.1"
1466   :link '(custom-manual "(gnus)Customizing Articles")
1467   :link '(custom-manual "(gnus)X-Face")
1468   :type gnus-article-treat-head-custom)
1469 (put 'gnus-treat-display-face 'highlight t)
1470
1471 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1472   "Display smileys.
1473 Valid values are nil, t, `head', `first', `last', an integer or a
1474 predicate.  See Info node `(gnus)Customizing Articles' and Info
1475 node `(gnus)Smileys' for details."
1476   :group 'gnus-article-treat
1477   :version "21.1"
1478   :link '(custom-manual "(gnus)Customizing Articles")
1479   :link '(custom-manual "(gnus)Smileys")
1480   :type gnus-article-treat-custom)
1481 (put 'gnus-treat-display-smileys 'highlight t)
1482
1483 (defcustom gnus-treat-from-picon
1484   (if (and (gnus-image-type-available-p 'xpm)
1485            (gnus-picons-installed-p))
1486       'head nil)
1487   "Display picons in the From header.
1488 Valid values are nil, t, `head', `first', `last', an integer or a
1489 predicate.  See Info node `(gnus)Customizing Articles' and Info
1490 node `(gnus)Picons' for details."
1491   :version "22.1"
1492   :group 'gnus-article-treat
1493   :group 'gnus-picon
1494   :link '(custom-manual "(gnus)Customizing Articles")
1495   :link '(custom-manual "(gnus)Picons")
1496   :type gnus-article-treat-head-custom)
1497 (put 'gnus-treat-from-picon 'highlight t)
1498
1499 (defcustom gnus-treat-mail-picon
1500   (if (and (gnus-image-type-available-p 'xpm)
1501            (gnus-picons-installed-p))
1502       'head nil)
1503   "Display picons in To and Cc headers.
1504 Valid values are nil, t, `head', `first', `last', an integer or a
1505 predicate.  See Info node `(gnus)Customizing Articles' and Info
1506 node `(gnus)Picons' for details."
1507   :version "22.1"
1508   :group 'gnus-article-treat
1509   :group 'gnus-picon
1510   :link '(custom-manual "(gnus)Customizing Articles")
1511   :link '(custom-manual "(gnus)Picons")
1512   :type gnus-article-treat-head-custom)
1513 (put 'gnus-treat-mail-picon 'highlight t)
1514
1515 (defcustom gnus-treat-newsgroups-picon
1516   (if (and (gnus-image-type-available-p 'xpm)
1517            (gnus-picons-installed-p))
1518       'head nil)
1519   "Display picons in the Newsgroups and Followup-To headers.
1520 Valid values are nil, t, `head', `first', `last', an integer or a
1521 predicate.  See Info node `(gnus)Customizing Articles' and Info
1522 node `(gnus)Picons' for details."
1523   :version "22.1"
1524   :group 'gnus-article-treat
1525   :group 'gnus-picon
1526   :link '(custom-manual "(gnus)Customizing Articles")
1527   :link '(custom-manual "(gnus)Picons")
1528   :type gnus-article-treat-head-custom)
1529 (put 'gnus-treat-newsgroups-picon 'highlight t)
1530
1531 (defcustom gnus-treat-from-gravatar nil
1532   "Display gravatars in the From header.
1533 Valid values are nil, t, `head', `first', `last', an integer or a
1534 predicate.  See Info node `(gnus)Customizing Articles' and Info
1535 node `(gnus)Gravatars' for details."
1536   :version "24.1"
1537   :group 'gnus-article-treat
1538   :group 'gnus-gravatar
1539   :link '(custom-manual "(gnus)Customizing Articles")
1540   :link '(custom-manual "(gnus)Gravatars")
1541   :type gnus-article-treat-head-custom)
1542 (put 'gnus-treat-from-gravatar 'highlight t)
1543
1544 (defcustom gnus-treat-mail-gravatar nil
1545   "Display gravatars in To and Cc headers.
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate.  See Info node `(gnus)Customizing Articles' and Info
1548 node `(gnus)Gravatars' for details."
1549   :version "24.1"
1550   :group 'gnus-article-treat
1551   :group 'gnus-gravatar
1552   :link '(custom-manual "(gnus)Customizing Articles")
1553   :link '(custom-manual "(gnus)Gravatars")
1554   :type gnus-article-treat-head-custom)
1555 (put 'gnus-treat-mail-gravatar 'highlight t)
1556
1557 (defcustom gnus-treat-body-boundary
1558   (if (or gnus-treat-newsgroups-picon
1559           gnus-treat-mail-picon
1560           gnus-treat-from-picon
1561           gnus-treat-from-gravatar
1562           gnus-treat-mail-gravatar)
1563       ;; If there's much decoration, the user might prefer a boundary.
1564       'head
1565     nil)
1566   "Draw a boundary at the end of the headers.
1567 Valid values are nil and `head'.
1568 See Info node `(gnus)Customizing Articles' for details."
1569   :version "22.1"
1570   :group 'gnus-article-treat
1571   :link '(custom-manual "(gnus)Customizing Articles")
1572   :type gnus-article-treat-head-custom)
1573
1574 (defcustom gnus-treat-capitalize-sentences nil
1575   "Capitalize sentence-starting words.
1576 Valid values are nil, t, `head', `first', `last', an integer or a
1577 predicate.  See Info node `(gnus)Customizing Articles'."
1578   :version "21.1"
1579   :group 'gnus-article-treat
1580   :link '(custom-manual "(gnus)Customizing Articles")
1581   :type gnus-article-treat-custom)
1582
1583 (defcustom gnus-treat-wash-html nil
1584   "Format as HTML.
1585 Valid values are nil, t, `head', `first', `last', an integer or a
1586 predicate.  See Info node `(gnus)Customizing Articles'."
1587   :version "22.1"
1588   :group 'gnus-article-treat
1589   :link '(custom-manual "(gnus)Customizing Articles")
1590   :type gnus-article-treat-custom)
1591
1592 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1593   "Fill long lines.
1594 Valid values are nil, t, `head', `first', `last', an integer or a
1595 predicate.  See Info node `(gnus)Customizing Articles'."
1596   :version "24.1"
1597   :group 'gnus-article-treat
1598   :link '(custom-manual "(gnus)Customizing Articles")
1599   :type gnus-article-treat-custom)
1600
1601 (defcustom gnus-treat-x-pgp-sig nil
1602   "Verify X-PGP-Sig.
1603 To automatically treat X-PGP-Sig, set it to head.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate.  See Info node `(gnus)Customizing Articles'."
1606   :version "22.1"
1607   :group 'gnus-article-treat
1608   :group 'mime-security
1609   :link '(custom-manual "(gnus)Customizing Articles")
1610   :type gnus-article-treat-custom)
1611
1612 (defvar gnus-article-encrypt-protocol-alist
1613   '(("PGP" . mml2015-self-encrypt)))
1614
1615 ;; Set to nil if more than one protocol added to
1616 ;; gnus-article-encrypt-protocol-alist.
1617 (defcustom gnus-article-encrypt-protocol "PGP"
1618   "The protocol used for encrypt articles.
1619 It is a string, such as \"PGP\". If nil, ask user."
1620   :version "22.1"
1621   :type 'string
1622   :group 'mime-security)
1623
1624 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1625                               (mm-coding-system-p 'utf-8)
1626                               (executable-find idna-program))
1627   "Whether IDNA decoding of headers is used when viewing messages.
1628 This requires GNU Libidn, and by default only enabled if it is found."
1629   :version "22.1"
1630   :group 'gnus-article-headers
1631   :type 'boolean)
1632
1633 (defcustom gnus-article-over-scroll nil
1634   "If non-nil, allow scrolling the article buffer even when there no more text."
1635   :version "22.1"
1636   :group 'gnus-article
1637   :type 'boolean)
1638
1639 (defcustom gnus-inhibit-images nil
1640   "Non-nil means inhibit displaying of images inline in the article body."
1641   :version "24.1"
1642   :group 'gnus-article
1643   :type 'boolean)
1644
1645 (defcustom gnus-blocked-images 'gnus-block-private-groups
1646   "Images that have URLs matching this regexp will be blocked.
1647 This can also be a function to be evaluated.  If so, it will be
1648 called with the group name as the parameter, and should return a
1649 regexp."
1650   :version "24.1"
1651   :group 'gnus-art
1652   :type '(choice regexp function))
1653
1654 ;;; Internal variables
1655
1656 (defvar gnus-english-month-names
1657   '("January" "February" "March" "April" "May" "June" "July" "August"
1658     "September" "October" "November" "December"))
1659
1660 (defvar article-goto-body-goes-to-point-min-p nil)
1661 (defvar gnus-article-wash-types nil)
1662 (defvar gnus-article-emphasis-alist nil)
1663 (defvar gnus-article-image-alist nil)
1664
1665 (defvar gnus-article-mime-handle-alist-1 nil)
1666 (defvar gnus-treatment-function-alist
1667   '((gnus-treat-strip-cr gnus-article-remove-cr)
1668     (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1669     (gnus-treat-strip-banner gnus-article-strip-banner)
1670     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1671     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1672     (gnus-treat-buttonize gnus-article-add-buttons)
1673     (gnus-treat-fill-article gnus-article-fill-cited-article)
1674     (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1675     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1676     (gnus-treat-display-x-face gnus-article-display-x-face)
1677     (gnus-treat-display-face gnus-article-display-face)
1678     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1679     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1680     (gnus-treat-hide-signature gnus-article-hide-signature)
1681     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1682     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1683     (gnus-treat-from-picon gnus-treat-from-picon)
1684     (gnus-treat-mail-picon gnus-treat-mail-picon)
1685     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1686     (gnus-treat-strip-pem gnus-article-hide-pem)
1687     (gnus-treat-date gnus-article-treat-date)
1688     (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1689     (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1690     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1691     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1692     (gnus-treat-strip-trailing-blank-lines
1693      gnus-article-remove-trailing-blank-lines)
1694     (gnus-treat-strip-leading-blank-lines
1695      gnus-article-strip-leading-blank-lines)
1696     (gnus-treat-strip-multiple-blank-lines
1697      gnus-article-strip-multiple-blank-lines)
1698     (gnus-treat-overstrike gnus-article-treat-overstrike)
1699     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1700     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1701     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1702     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1703     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1704     (gnus-treat-display-smileys gnus-treat-smiley)
1705     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1706     (gnus-treat-wash-html gnus-article-wash-html)
1707     (gnus-treat-emphasize gnus-article-emphasize)
1708     (gnus-treat-hide-citation gnus-article-hide-citation)
1709     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1710     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1711     (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1712
1713 (defvar gnus-article-mime-handle-alist nil)
1714 (defvar article-lapsed-timer nil)
1715 (defvar gnus-article-current-summary nil)
1716
1717 (defvar gnus-article-mode-syntax-table
1718   (let ((table (copy-syntax-table text-mode-syntax-table)))
1719     ;; This causes the citation match run O(2^n).
1720     ;; (modify-syntax-entry ?- "w" table)
1721     (modify-syntax-entry ?> ")<" table)
1722     (modify-syntax-entry ?< "(>" table)
1723     ;; make M-. in article buffers work for `foo' strings
1724     (modify-syntax-entry ?' " " table)
1725     (modify-syntax-entry ?` " " table)
1726     table)
1727   "Syntax table used in article mode buffers.
1728 Initialized from `text-mode-syntax-table.")
1729
1730 (defvar gnus-save-article-buffer nil)
1731
1732 (defvar gnus-number-of-articles-to-be-saved nil)
1733
1734 (defvar gnus-inhibit-hiding nil)
1735
1736 (defvar gnus-article-edit-mode nil)
1737
1738 ;;; Macros for dealing with the article buffer.
1739
1740 (defmacro gnus-with-article-headers (&rest forms)
1741   `(with-current-buffer gnus-article-buffer
1742      (save-restriction
1743        (let ((inhibit-read-only t)
1744              (inhibit-point-motion-hooks t)
1745              (case-fold-search t))
1746          (article-narrow-to-head)
1747          ,@forms))))
1748
1749 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1750 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1751
1752 (defmacro gnus-with-article-buffer (&rest forms)
1753   `(when (buffer-live-p (get-buffer gnus-article-buffer))
1754      (with-current-buffer gnus-article-buffer
1755        (let ((inhibit-read-only t))
1756          ,@forms))))
1757
1758 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1759 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1760
1761 (defun gnus-article-goto-header (header)
1762   "Go to HEADER, which is a regular expression."
1763   (re-search-forward (concat "^\\(" header "\\):") nil t))
1764
1765 (defsubst gnus-article-hide-text (b e props)
1766   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1767   (gnus-add-text-properties-when 'article-type nil b e props)
1768   (when (memq 'intangible props)
1769     (put-text-property
1770      (max (1- b) (point-min))
1771      b 'intangible (cddr (memq 'intangible props)))))
1772
1773 (defsubst gnus-article-unhide-text (b e)
1774   "Remove hidden text properties from region between B and E."
1775   (remove-text-properties b e gnus-hidden-properties)
1776   (when (memq 'intangible gnus-hidden-properties)
1777     (put-text-property (max (1- b) (point-min))
1778                        b 'intangible nil)))
1779
1780 (defun gnus-article-hide-text-type (b e type)
1781   "Hide text of TYPE between B and E."
1782   (gnus-add-wash-type type)
1783   (gnus-article-hide-text
1784    b e (cons 'article-type (cons type gnus-hidden-properties))))
1785
1786 (defun gnus-article-unhide-text-type (b e type)
1787   "Unhide text of TYPE between B and E."
1788   (gnus-delete-wash-type type)
1789   (remove-text-properties
1790    b e (cons 'article-type (cons type gnus-hidden-properties)))
1791   (when (memq 'intangible gnus-hidden-properties)
1792     (put-text-property (max (1- b) (point-min))
1793                        b 'intangible nil)))
1794
1795 (defun gnus-article-delete-text-of-type (type)
1796   "Delete text of TYPE in the current buffer."
1797   (save-excursion
1798     (let ((b (point-min)))
1799       (if (eq type 'multipart)
1800           ;; Remove MIME buttons associated with multipart/alternative parts.
1801           (progn
1802             (goto-char b)
1803             (while (if (get-text-property (point) 'gnus-part)
1804                        (setq b (point))
1805                      (when (setq b (next-single-property-change (point)
1806                                                                 'gnus-part))
1807                        (goto-char b)
1808                        t))
1809               (end-of-line)
1810               (skip-chars-forward "\n")
1811               (when (eq (get-text-property b 'article-type) 'multipart)
1812                 (delete-region b (point)))))
1813         (while (setq b (text-property-any b (point-max) 'article-type type))
1814           (delete-region
1815            b (or (text-property-not-all b (point-max) 'article-type type)
1816                  (point-max))))))))
1817
1818 (defun gnus-article-delete-invisible-text ()
1819   "Delete all invisible text in the current buffer."
1820   (save-excursion
1821     (let ((b (point-min)))
1822       (while (setq b (text-property-any b (point-max) 'invisible t))
1823         (delete-region
1824          b (or (text-property-not-all b (point-max) 'invisible t)
1825                (point-max)))))))
1826
1827 (defsubst gnus-article-header-rank ()
1828   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1829   (let ((list gnus-sorted-header-list)
1830         (i 1))
1831     (while list
1832       (if (looking-at (car list))
1833           (setq list nil)
1834         (setq list (cdr list))
1835         (incf i)))
1836       i))
1837
1838 (defun article-hide-headers (&optional arg delete)
1839   "Hide unwanted headers and possibly sort them as well."
1840   (interactive)
1841   ;; This function might be inhibited.
1842   (unless gnus-inhibit-hiding
1843     (let ((inhibit-read-only t)
1844           (case-fold-search t)
1845           (max (1+ (length gnus-sorted-header-list)))
1846           (inhibit-point-motion-hooks t)
1847           (cur (current-buffer))
1848           ignored visible beg)
1849       (save-excursion
1850         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1851         ;; group parameters, so we should go to the summary buffer.
1852         (when (prog1
1853                   (condition-case nil
1854                       (progn (set-buffer gnus-summary-buffer) t)
1855                     (error nil))
1856                 (setq ignored (when (not gnus-visible-headers)
1857                                 (cond ((stringp gnus-ignored-headers)
1858                                        gnus-ignored-headers)
1859                                       ((listp gnus-ignored-headers)
1860                                        (mapconcat 'identity
1861                                                   gnus-ignored-headers
1862                                                   "\\|"))))
1863                       visible (cond ((stringp gnus-visible-headers)
1864                                      gnus-visible-headers)
1865                                     ((and gnus-visible-headers
1866                                           (listp gnus-visible-headers))
1867                                      (mapconcat 'identity
1868                                                 gnus-visible-headers
1869                                                 "\\|")))))
1870           (set-buffer cur))
1871         (save-restriction
1872           ;; First we narrow to just the headers.
1873           (article-narrow-to-head)
1874           ;; Hide any "From " lines at the beginning of (mail) articles.
1875           (while (looking-at "From ")
1876             (forward-line 1))
1877           (unless (bobp)
1878             (delete-region (point-min) (point)))
1879           ;; Then treat the rest of the header lines.
1880           ;; Then we use the two regular expressions
1881           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1882           ;; select which header lines is to remain visible in the
1883           ;; article buffer.
1884           (while (re-search-forward "^[^ \t:]*:" nil t)
1885             (beginning-of-line)
1886             ;; Mark the rank of the header.
1887             (put-text-property
1888              (point) (1+ (point)) 'message-rank
1889              (if (or (and visible (looking-at visible))
1890                      (and ignored
1891                           (not (looking-at ignored))))
1892                  (gnus-article-header-rank)
1893                (+ 2 max)))
1894             (forward-line 1))
1895           (message-sort-headers-1)
1896           (when (setq beg (text-property-any
1897                            (point-min) (point-max) 'message-rank (+ 2 max)))
1898             ;; We delete the unwanted headers.
1899             (gnus-add-wash-type 'headers)
1900             (add-text-properties (point-min) (+ 5 (point-min))
1901                                  '(article-type headers dummy-invisible t))
1902             (delete-region beg (point-max))))))))
1903
1904 (defun article-hide-boring-headers (&optional arg)
1905   "Toggle hiding of headers that aren't very interesting.
1906 If given a negative prefix, always show; if given a positive prefix,
1907 always hide."
1908   (interactive (gnus-article-hidden-arg))
1909   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1910              (not gnus-show-all-headers))
1911     (save-excursion
1912       (save-restriction
1913         (let ((inhibit-read-only t)
1914               (inhibit-point-motion-hooks t))
1915           (article-narrow-to-head)
1916           (dolist (elem gnus-boring-article-headers)
1917             (goto-char (point-min))
1918             (cond
1919              ;; Hide empty headers.
1920              ((eq elem 'empty)
1921               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1922                 (forward-line -1)
1923                 (gnus-article-hide-text-type
1924                  (point-at-bol)
1925                  (progn
1926                    (end-of-line)
1927                    (if (re-search-forward "^[^ \t]" nil t)
1928                        (match-beginning 0)
1929                      (point-max)))
1930                  'boring-headers)))
1931              ;; Hide boring Newsgroups header.
1932              ((eq elem 'newsgroups)
1933               (when (gnus-string-equal
1934                      (gnus-fetch-field "newsgroups")
1935                      (gnus-group-real-name
1936                       (if (boundp 'gnus-newsgroup-name)
1937                           gnus-newsgroup-name
1938                         "")))
1939                 (gnus-article-hide-header "newsgroups")))
1940              ((eq elem 'to-address)
1941               (let ((to (message-fetch-field "to"))
1942                     (to-address
1943                      (gnus-parameter-to-address
1944                       (if (boundp 'gnus-newsgroup-name)
1945                           gnus-newsgroup-name ""))))
1946                 (when (and to to-address
1947                            (ignore-errors
1948                              (gnus-string-equal
1949                               ;; only one address in To
1950                               (nth 1 (mail-extract-address-components to))
1951                               to-address)))
1952                   (gnus-article-hide-header "to"))))
1953              ((eq elem 'to-list)
1954               (let ((to (message-fetch-field "to"))
1955                     (to-list
1956                      (gnus-parameter-to-list
1957                       (if (boundp 'gnus-newsgroup-name)
1958                           gnus-newsgroup-name ""))))
1959                 (when (and to to-list
1960                            (ignore-errors
1961                              (gnus-string-equal
1962                               ;; only one address in To
1963                               (nth 1 (mail-extract-address-components to))
1964                               to-list)))
1965                   (gnus-article-hide-header "to"))))
1966              ((eq elem 'cc-list)
1967               (let ((cc (message-fetch-field "cc"))
1968                     (to-list
1969                      (gnus-parameter-to-list
1970                       (if (boundp 'gnus-newsgroup-name)
1971                           gnus-newsgroup-name ""))))
1972                 (when (and cc to-list
1973                            (ignore-errors
1974                              (gnus-string-equal
1975                               ;; only one address in CC
1976                               (nth 1 (mail-extract-address-components cc))
1977                               to-list)))
1978                   (gnus-article-hide-header "cc"))))
1979              ((eq elem 'followup-to)
1980               (when (gnus-string-equal
1981                      (message-fetch-field "followup-to")
1982                      (message-fetch-field "newsgroups"))
1983                 (gnus-article-hide-header "followup-to")))
1984              ((eq elem 'reply-to)
1985               (if (gnus-group-find-parameter
1986                    gnus-newsgroup-name 'broken-reply-to)
1987                   (gnus-article-hide-header "reply-to")
1988                 (let ((from (message-fetch-field "from"))
1989                       (reply-to (message-fetch-field "reply-to")))
1990                   (when
1991                       (and
1992                        from reply-to
1993                        (ignore-errors
1994                          (equal
1995                           (sort (mapcar
1996                                  (lambda (x) (downcase (cadr x)))
1997                                  (mail-extract-address-components from t))
1998                                 'string<)
1999                           (sort (mapcar
2000                                  (lambda (x) (downcase (cadr x)))
2001                                  (mail-extract-address-components reply-to t))
2002                                 'string<))))
2003                     (gnus-article-hide-header "reply-to")))))
2004              ((eq elem 'date)
2005               (let ((date (with-current-buffer gnus-original-article-buffer
2006                             ;; If date in `gnus-article-buffer' is localized
2007                             ;; (`gnus-treat-date-user-defined'),
2008                             ;; `days-between' might fail.
2009                             (message-fetch-field "date"))))
2010                 (when (and date
2011                            (< (days-between (current-time-string) date)
2012                               4))
2013                   (gnus-article-hide-header "date"))))
2014              ((eq elem 'long-to)
2015               (let ((to (message-fetch-field "to"))
2016                     (cc (message-fetch-field "cc")))
2017                 (when (> (length to) 1024)
2018                   (gnus-article-hide-header "to"))
2019                 (when (> (length cc) 1024)
2020                   (gnus-article-hide-header "cc"))))
2021              ((eq elem 'many-to)
2022               (let ((to-count 0)
2023                     (cc-count 0))
2024                 (goto-char (point-min))
2025                 (while (re-search-forward "^to:" nil t)
2026                   (setq to-count (1+ to-count)))
2027                 (when (> to-count 1)
2028                   (while (> to-count 0)
2029                     (goto-char (point-min))
2030                     (save-restriction
2031                       (re-search-forward "^to:" nil nil to-count)
2032                       (forward-line -1)
2033                       (narrow-to-region (point) (point-max))
2034                       (gnus-article-hide-header "to"))
2035                     (setq to-count (1- to-count))))
2036                 (goto-char (point-min))
2037                 (while (re-search-forward "^cc:" nil t)
2038                   (setq cc-count (1+ cc-count)))
2039                 (when (> cc-count 1)
2040                   (while (> cc-count 0)
2041                     (goto-char (point-min))
2042                     (save-restriction
2043                       (re-search-forward "^cc:" nil nil cc-count)
2044                       (forward-line -1)
2045                       (narrow-to-region (point) (point-max))
2046                       (gnus-article-hide-header "cc"))
2047                     (setq cc-count (1- cc-count)))))))))))))
2048
2049 (defun gnus-article-hide-header (header)
2050   (save-excursion
2051     (goto-char (point-min))
2052     (when (re-search-forward (concat "^" header ":") nil t)
2053       (gnus-article-hide-text-type
2054        (point-at-bol)
2055        (progn
2056          (end-of-line)
2057          (if (re-search-forward "^[^ \t]" nil t)
2058              (match-beginning 0)
2059            (point-max)))
2060        'boring-headers))))
2061
2062 (defvar gnus-article-normalized-header-length 40
2063   "Length of normalized headers.")
2064
2065 (defun article-normalize-headers ()
2066   "Make all header lines 40 characters long."
2067   (interactive)
2068   (let ((inhibit-read-only t)
2069         column)
2070     (save-excursion
2071       (save-restriction
2072         (article-narrow-to-head)
2073         (while (not (eobp))
2074           (cond
2075            ((< (setq column (- (point-at-eol) (point)))
2076                gnus-article-normalized-header-length)
2077             (end-of-line)
2078             (insert (make-string
2079                      (- gnus-article-normalized-header-length column)
2080                      ? )))
2081            ((> column gnus-article-normalized-header-length)
2082             (gnus-put-text-property
2083              (progn
2084                (forward-char gnus-article-normalized-header-length)
2085                (point))
2086              (point-at-eol)
2087              'invisible t))
2088            (t
2089             ;; Do nothing.
2090             ))
2091           (forward-line 1))))))
2092
2093 (defun article-treat-dumbquotes ()
2094   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2095 Note that this function guesses whether a character is a sm*rtq**t* or
2096 not, so it should only be used interactively.
2097
2098 Sm*rtq**t*s are M****s***'s unilateral extension to the
2099 iso-8859-1 character map in an attempt to provide more quoting
2100 characters.  If you see something like \\222 or \\264 where
2101 you're expecting some kind of apostrophe or quotation mark, then
2102 try this wash."
2103   (interactive)
2104   (article-translate-strings gnus-article-dumbquotes-map))
2105
2106 (defvar org-entities)
2107
2108 (defun article-treat-non-ascii ()
2109   "Translate many Unicode characters into their ASCII equivalents."
2110   (interactive)
2111   (require 'org-entities)
2112   (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2113     (dolist (elem org-entities)
2114       (when (and (listp elem)
2115                  (= (length (nth 6 elem)) 1))
2116         (if (featurep 'xemacs)
2117             (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2118           (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2119     (save-excursion
2120       (when (article-goto-body)
2121         (let ((inhibit-read-only t)
2122               replace props)
2123           (while (not (eobp))
2124             (if (not (setq replace (if (featurep 'xemacs)
2125                                        (get-char-table (following-char) table)
2126                                      (aref table (following-char)))))
2127                 (forward-char 1)
2128               (if (prog1
2129                       (setq props (text-properties-at (point)))
2130                     (delete-char 1))
2131                   (add-text-properties (point) (progn (insert replace) (point))
2132                                        props)
2133                 (insert replace)))))))))
2134
2135 (defun article-translate-strings (map)
2136   "Translate all string in the body of the article according to MAP.
2137 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2138   (save-excursion
2139     (when (article-goto-body)
2140       (let ((inhibit-read-only t))
2141         (dolist (elem map)
2142           (let ((from (car elem))
2143                 (to (cadr elem)))
2144             (save-excursion
2145               (if (stringp from)
2146                   (while (search-forward from nil t)
2147                     (replace-match to))
2148                 (while (not (eobp))
2149                   (if (eq (following-char) from)
2150                       (progn
2151                         (delete-char 1)
2152                         (insert to))
2153                     (forward-char 1)))))))))))
2154
2155 (defun article-treat-overstrike ()
2156   "Translate overstrikes into bold text."
2157   (interactive)
2158   (save-excursion
2159     (when (article-goto-body)
2160       (let ((inhibit-read-only t))
2161         (while (search-forward "\b" nil t)
2162           (let ((next (char-after))
2163                 (previous (char-after (- (point) 2))))
2164             ;; We do the boldification/underlining by hiding the
2165             ;; overstrikes and putting the proper text property
2166             ;; on the letters.
2167             (cond
2168              ((eq next previous)
2169               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2170               (put-text-property (point) (1+ (point)) 'face 'bold))
2171              ((eq next ?_)
2172               (gnus-article-hide-text-type
2173                (1- (point)) (1+ (point)) 'overstrike)
2174               (put-text-property
2175                (- (point) 2) (1- (point)) 'face 'underline))
2176              ((eq previous ?_)
2177               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2178               (put-text-property
2179                (point) (1+ (point)) 'face 'underline)))))))))
2180
2181 (defun article-treat-ansi-sequences ()
2182   "Translate ANSI SGR control sequences into overlays or extents."
2183   (interactive)
2184   (save-excursion
2185     (when (article-goto-body)
2186       (let ((inhibit-read-only t))
2187         (ansi-color-apply-on-region (point) (point-max))))))
2188
2189 (defun gnus-article-treat-unfold-headers ()
2190   "Unfold folded message headers.
2191 Only the headers that fit into the current window width will be
2192 unfolded."
2193   (interactive)
2194   (gnus-with-article-headers
2195     (let (length)
2196       (while (not (eobp))
2197         (save-restriction
2198           (mail-header-narrow-to-field)
2199           (let* ((header (buffer-string))
2200                  (unfoldable
2201                   (or (equal gnus-article-unfold-long-headers t)
2202                       (and (stringp gnus-article-unfold-long-headers)
2203                            (string-match gnus-article-unfold-long-headers
2204                                          header)))))
2205             (with-temp-buffer
2206               (insert header)
2207               (goto-char (point-min))
2208               (while (re-search-forward "\n[\t ]" nil t)
2209                 (replace-match " " t t)))
2210             (setq length (- (point-max) (point-min) 1))
2211             (when (or unfoldable
2212                       (< length (window-width)))
2213               (while (re-search-forward "\n[\t ]" nil t)
2214                 (replace-match " " t t))))
2215           (goto-char (point-max)))))))
2216
2217 (defun gnus-article-treat-fold-headers ()
2218   "Fold message headers."
2219   (interactive)
2220   (gnus-with-article-headers
2221     (while (not (eobp))
2222       (save-restriction
2223         (mail-header-narrow-to-field)
2224         (mail-header-fold-field)
2225         (goto-char (point-max))))))
2226
2227 (defun gnus-treat-smiley ()
2228   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2229   (interactive)
2230   (gnus-with-article-buffer
2231     (if (memq 'smiley gnus-article-wash-types)
2232         (gnus-delete-images 'smiley)
2233       (article-goto-body)
2234       (let ((images (smiley-region (point) (point-max))))
2235         (when images
2236           (gnus-add-wash-type 'smiley)
2237           (dolist (image images)
2238             (gnus-add-image 'smiley image)))))))
2239
2240 (defun gnus-article-remove-images ()
2241   "Remove all images from the article buffer."
2242   (interactive)
2243   (gnus-with-article-buffer
2244     (save-restriction
2245       (widen)
2246       (dolist (elem gnus-article-image-alist)
2247         (gnus-delete-images (car elem))))))
2248
2249 (autoload 'w3m-toggle-inline-images "w3m")
2250
2251 (defun gnus-article-show-images ()
2252   "Show any images that are in the HTML-rendered article buffer.
2253 This only works if the article in question is HTML."
2254   (interactive)
2255   (gnus-with-article-buffer
2256     (save-restriction
2257       (widen)
2258       (if (eq mm-text-html-renderer 'w3m)
2259           (let ((mm-inline-text-html-with-images nil))
2260             (w3m-toggle-inline-images))
2261         (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2262                                                         'image-displayer))
2263           (destructuring-bind (start end function) region
2264             (funcall function (get-text-property start 'image-url)
2265                      start end)))))))
2266
2267 (defun gnus-article-treat-fold-newsgroups ()
2268   "Unfold folded message headers.
2269 Only the headers that fit into the current window width will be
2270 unfolded."
2271   (interactive)
2272   (gnus-with-article-headers
2273     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2274       (save-restriction
2275         (mail-header-narrow-to-field)
2276         (while (re-search-forward ", *" nil t)
2277           (replace-match ", " t t))
2278         (mail-header-fold-field)
2279         (goto-char (point-max))))))
2280
2281 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2282   "Value of `truncate-lines' in Gnus Article buffer.
2283 Valid values are nil, t, `head', `first', `last', an integer or a
2284 predicate.  See Info node `(gnus)Customizing Articles'."
2285   :version "23.1" ;; No Gnus
2286   :group 'gnus-article
2287   ;; :link '(custom-manual "(gnus)Customizing Articles")
2288   :type 'boolean)
2289
2290 (defun gnus-article-toggle-truncate-lines (&optional arg)
2291   "Toggle whether to fold or truncate long lines in article the buffer.
2292 If ARG is non-nil and not a number, toggle
2293 `gnus-article-truncate-lines' too.  If ARG is a number, truncate
2294 long lines if and only if arg is positive."
2295   (interactive "P")
2296   (cond
2297    ((and (numberp arg) (> arg 0))
2298     (setq gnus-article-truncate-lines t))
2299    ((numberp arg)
2300     (setq gnus-article-truncate-lines nil))
2301    (arg
2302     (setq gnus-article-truncate-lines
2303           (not gnus-article-truncate-lines))))
2304   (gnus-with-article-buffer
2305     (cond
2306      ((and (numberp arg) (> arg 0))
2307       (setq truncate-lines nil))
2308      ((numberp arg)
2309       (setq truncate-lines t)))
2310     ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2311     ;; `toggle-truncate-lines' needs an argument.
2312     (toggle-truncate-lines)))
2313
2314 (defun gnus-article-treat-body-boundary ()
2315   "Place a boundary line at the end of the headers."
2316   (interactive)
2317   (when (and gnus-body-boundary-delimiter
2318              (> (length gnus-body-boundary-delimiter) 0))
2319     (gnus-with-article-headers
2320       (goto-char (point-max))
2321       (let ((start (point)))
2322         (insert "X-Boundary: ")
2323         (gnus-add-text-properties start (point) '(invisible t intangible t))
2324        (insert (let (str (max (window-width)))
2325                  (if (featurep 'xemacs)
2326                      (setq max (1- max)))
2327                  (while (>= max (length str))
2328                     (setq str (concat str gnus-body-boundary-delimiter)))
2329                  (substring str 0 max))
2330                 "\n")
2331         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2332
2333 (defun article-fill-long-lines ()
2334   "Fill lines that are wider than the window width."
2335   (interactive)
2336   (save-excursion
2337     (let ((inhibit-read-only t)
2338           (width (window-width (get-buffer-window (current-buffer)))))
2339       (save-restriction
2340         (article-goto-body)
2341         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2342           (while (not (eobp))
2343             (end-of-line)
2344             (when (>= (current-column) (min fill-column width))
2345               (narrow-to-region (min (1+ (point)) (point-max))
2346                                 (point-at-bol))
2347               (let ((goback (point-marker)))
2348                 (fill-paragraph nil)
2349                 (goto-char (marker-position goback)))
2350               (widen))
2351             (forward-line 1)))))))
2352
2353 (defun article-capitalize-sentences ()
2354   "Capitalize the first word in each sentence."
2355   (interactive)
2356   (save-excursion
2357     (let ((inhibit-read-only t)
2358           (paragraph-start "^[\n\^L]"))
2359       (article-goto-body)
2360       (while (not (eobp))
2361         (capitalize-word 1)
2362         (forward-sentence)))))
2363
2364 (defun article-remove-cr ()
2365   "Remove trailing CRs and then translate remaining CRs into LFs."
2366   (interactive)
2367   (save-excursion
2368     (let ((inhibit-read-only t))
2369       (goto-char (point-min))
2370       (while (re-search-forward "\r+$" nil t)
2371         (replace-match "" t t))
2372       (goto-char (point-min))
2373       (while (search-forward "\r" nil t)
2374         (replace-match "\n" t t)))))
2375
2376 (defun article-remove-trailing-blank-lines ()
2377   "Remove all trailing blank lines from the article."
2378   (interactive)
2379   (save-excursion
2380     (let ((inhibit-read-only t))
2381       (goto-char (point-max))
2382       (delete-region
2383        (point)
2384        (progn
2385          (while (and (not (bobp))
2386                      (looking-at "^[ \t]*$")
2387                      (not (gnus-annotation-in-region-p
2388                            (point) (point-at-eol))))
2389            (forward-line -1))
2390          (forward-line 1)
2391          (point))))))
2392
2393 (defvar gnus-face-properties-alist)
2394
2395 (defun article-display-face (&optional force)
2396   "Display any Face headers in the header."
2397   (interactive (list 'force))
2398   (let ((wash-face-p buffer-read-only))
2399     (gnus-with-article-headers
2400       ;; When displaying parts, this function can be called several times on
2401       ;; the same article, without any intended toggle semantic (as typing `W
2402       ;; D d' would have). So face deletion must occur only when we come from
2403       ;; an interactive command, that is when the *Article* buffer is
2404       ;; read-only.
2405       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2406           (gnus-delete-images 'face)
2407         (let ((from (message-fetch-field "from"))
2408               face faces)
2409           (save-current-buffer
2410             (when (and wash-face-p
2411                        (gnus-buffer-live-p gnus-original-article-buffer)
2412                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2413               (set-buffer gnus-original-article-buffer))
2414             (save-restriction
2415               (mail-narrow-to-head)
2416               (when (or force
2417                         ;; Check whether this face is censored.
2418                         (not (and gnus-article-x-face-too-ugly
2419                                   (or from
2420                                       (setq from (message-fetch-field "from")))
2421                                   (string-match gnus-article-x-face-too-ugly
2422                                                 from))))
2423                 (while (gnus-article-goto-header "Face")
2424                   (push (mail-header-field-value) faces)))))
2425           (when faces
2426             (goto-char (point-min))
2427             (let (png image)
2428               (unless (setq from (gnus-article-goto-header "from"))
2429                 (insert "From:")
2430                 (setq from (point))
2431                 (insert " [no `from' set]\n"))
2432               (while faces
2433                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2434                   (setq image
2435                         (apply 'gnus-create-image png 'png t
2436                                (cdr (assq 'png gnus-face-properties-alist))))
2437                   (goto-char from)
2438                   (when image
2439                     (gnus-add-wash-type 'face)
2440                     (gnus-add-image 'face image)
2441                     (gnus-put-image image nil 'face)))))))))))
2442
2443 (defun article-display-x-face (&optional force)
2444   "Look for an X-Face header and display it if present."
2445   (interactive (list 'force))
2446   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2447     (gnus-with-article-headers
2448       ;; Delete the old process, if any.
2449       (when (process-status "article-x-face")
2450         (delete-process "article-x-face"))
2451       ;; See the comment in `article-display-face'.
2452       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2453           ;; We have already displayed X-Faces, so we remove them
2454           ;; instead.
2455           (gnus-delete-images 'xface)
2456         ;; Display X-Faces.
2457         (let ((from (message-fetch-field "from"))
2458               x-faces face)
2459           (save-current-buffer
2460             (when (and wash-face-p
2461                        (gnus-buffer-live-p gnus-original-article-buffer)
2462                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2463               ;; If type `W f', use gnus-original-article-buffer,
2464               ;; otherwise use the current buffer because displaying
2465               ;; RFC822 parts calls this function too.
2466               (set-buffer gnus-original-article-buffer))
2467             (save-restriction
2468               (mail-narrow-to-head)
2469               (and gnus-article-x-face-command
2470                    (or force
2471                        ;; Check whether this face is censored.
2472                        (not (and gnus-article-x-face-too-ugly
2473                                  (or from
2474                                      (setq from (message-fetch-field "from")))
2475                                  (string-match gnus-article-x-face-too-ugly
2476                                                from))))
2477                    (while (gnus-article-goto-header "X-Face")
2478                      (push (mail-header-field-value) x-faces)))))
2479           (when x-faces
2480             ;; We display the face.
2481             (cond ((functionp gnus-article-x-face-command)
2482                    ;; The command is a lisp function, so we call it.
2483                    (mapc gnus-article-x-face-command x-faces))
2484                   ((stringp gnus-article-x-face-command)
2485                    ;; The command is a string, so we interpret the command
2486                    ;; as a, well, command, and fork it off.
2487                    (let ((process-connection-type nil))
2488                      (gnus-set-process-query-on-exit-flag
2489                       (start-process
2490                        "article-x-face" nil shell-file-name
2491                        shell-command-switch gnus-article-x-face-command)
2492                       nil)
2493                      ;; Sending multiple EOFs to xv doesn't work,
2494                      ;; so we only do a single external face.
2495                      (with-temp-buffer
2496                        (insert (car x-faces))
2497                        (process-send-region "article-x-face"
2498                                             (point-min) (point-max)))
2499                      (process-send-eof "article-x-face")))
2500                   (t
2501                    (error "`%s' set to `%s' is not a function"
2502                           gnus-article-x-face-command
2503                           'gnus-article-x-face-command)))))))))
2504
2505 (defun article-decode-mime-words ()
2506   "Decode all MIME-encoded words in the article."
2507   (interactive)
2508   (gnus-with-article-buffer
2509     (let ((inhibit-point-motion-hooks t)
2510           (mail-parse-charset gnus-newsgroup-charset)
2511           (mail-parse-ignored-charsets
2512            (with-current-buffer gnus-summary-buffer
2513              gnus-newsgroup-ignored-charsets)))
2514       (mail-decode-encoded-word-region (point-min) (point-max)))))
2515
2516 (defun article-decode-charset (&optional prompt)
2517   "Decode charset-encoded text in the article.
2518 If PROMPT (the prefix), prompt for a coding system to use."
2519   (interactive "P")
2520   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2521         (inhibit-read-only t)
2522         (mail-parse-charset gnus-newsgroup-charset)
2523         (mail-parse-ignored-charsets
2524          (save-excursion (condition-case nil
2525                              (set-buffer gnus-summary-buffer)
2526                            (error))
2527                          gnus-newsgroup-ignored-charsets))
2528         ct cte ctl charset format)
2529     (save-excursion
2530       (save-restriction
2531         (article-narrow-to-head)
2532         (setq ct (message-fetch-field "Content-Type" t)
2533               cte (message-fetch-field "Content-Transfer-Encoding" t)
2534               ctl (and ct (mail-header-parse-content-type ct))
2535               charset (cond
2536                        (prompt
2537                         (mm-read-coding-system "Charset to decode: "))
2538                        (ctl
2539                         (mail-content-type-get ctl 'charset)))
2540               format (and ctl (mail-content-type-get ctl 'format)))
2541         (when cte
2542           (setq cte (mail-header-strip cte)))
2543         (if (and ctl (not (string-match "/" (car ctl))))
2544             (setq ctl nil))
2545         (goto-char (point-max)))
2546       (forward-line 1)
2547       (save-restriction
2548         (narrow-to-region (point) (point-max))
2549         (when (and (eq mail-parse-charset 'gnus-decoded)
2550                    (eq (mm-body-7-or-8) '8bit))
2551           ;; The text code could have been decoded.
2552           (setq charset mail-parse-charset))
2553         (when (and (or (not ctl)
2554                        (equal (car ctl) "text/plain"))
2555                    (not format)) ;; article with format will decode later.
2556           (mm-decode-body
2557            charset (and cte (intern (downcase
2558                                      (gnus-strip-whitespace cte))))
2559            (car ctl)))))))
2560
2561 (defun article-decode-encoded-words ()
2562   "Remove encoded-word encoding from headers."
2563   (let ((inhibit-point-motion-hooks t)
2564         (mail-parse-charset gnus-newsgroup-charset)
2565         (mail-parse-ignored-charsets
2566          (save-excursion (condition-case nil
2567                              (set-buffer gnus-summary-buffer)
2568                            (error))
2569                          gnus-newsgroup-ignored-charsets))
2570         (inhibit-read-only t)
2571         end start)
2572     (goto-char (point-min))
2573     (when (search-forward "\n\n" nil 'move)
2574       (forward-line -1))
2575     (setq end (point))
2576     (while (not (bobp))
2577       (while (progn
2578                (forward-line -1)
2579                (and (not (bobp))
2580                     (memq (char-after) '(?\t ? )))))
2581       (setq start (point))
2582       (if (looking-at "\
2583 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2584 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2585           (funcall gnus-decode-address-function start end)
2586         (funcall gnus-decode-header-function start end))
2587       (goto-char (setq end start)))))
2588
2589 (defun article-decode-group-name ()
2590   "Decode group names in Newsgroups, Followup-To and Xref headers."
2591   (let ((inhibit-point-motion-hooks t)
2592         (inhibit-read-only t)
2593         (method (gnus-find-method-for-group gnus-newsgroup-name))
2594         regexp)
2595     (when (and (or gnus-group-name-charset-method-alist
2596                    gnus-group-name-charset-group-alist)
2597                (gnus-buffer-live-p gnus-original-article-buffer))
2598       (save-restriction
2599         (article-narrow-to-head)
2600         (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2601           (with-current-buffer gnus-original-article-buffer
2602             (goto-char (point-min)))
2603           (setq regexp (concat "^" header
2604                                ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2605           (while (re-search-forward regexp nil t)
2606             (replace-match (save-match-data
2607                              (gnus-decode-newsgroups
2608                               ;; XXX how to use data in article buffer?
2609                               (with-current-buffer gnus-original-article-buffer
2610                                 (re-search-forward regexp nil t)
2611                                 (match-string 1))
2612                               gnus-newsgroup-name method))
2613                            t t nil 1))
2614           (goto-char (point-min)))))))
2615
2616 (autoload 'idna-to-unicode "idna")
2617
2618 (defun article-decode-idna-rhs ()
2619   "Decode IDNA strings in RHS in various headers in current buffer.
2620 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2621 Mail-Reply-To: and Mail-Followup-To:."
2622   (when gnus-use-idna
2623     (save-restriction
2624       (let ((inhibit-point-motion-hooks t)
2625             (inhibit-read-only t))
2626         (article-narrow-to-head)
2627         (goto-char (point-min))
2628         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2629           (let (ace unicode)
2630             (when (save-match-data
2631                     (and (setq ace (match-string 1))
2632                          (save-excursion
2633                            (and (re-search-backward "^[^ \t]" nil t)
2634                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2635                          (setq unicode (idna-to-unicode ace))))
2636               (unless (string= ace unicode)
2637                 (replace-match unicode nil nil nil 1)))))))))
2638
2639 (defun article-de-quoted-unreadable (&optional force read-charset)
2640   "Translate a quoted-printable-encoded article.
2641 If FORCE, decode the article whether it is marked as quoted-printable
2642 or not.
2643 If READ-CHARSET, ask for a coding system."
2644   (interactive (list 'force current-prefix-arg))
2645   (save-excursion
2646     (let ((inhibit-read-only t) type charset)
2647       (if (gnus-buffer-live-p gnus-original-article-buffer)
2648           (with-current-buffer gnus-original-article-buffer
2649             (setq type
2650                   (gnus-fetch-field "content-transfer-encoding"))
2651             (let* ((ct (gnus-fetch-field "content-type"))
2652                    (ctl (and ct (mail-header-parse-content-type ct))))
2653               (setq charset (and ctl
2654                                  (mail-content-type-get ctl 'charset)))
2655               (if (stringp charset)
2656                   (setq charset (intern (downcase charset)))))))
2657       (if read-charset
2658           (setq charset (mm-read-coding-system "Charset: " charset)))
2659       (unless charset
2660         (setq charset gnus-newsgroup-charset))
2661       (when (or force
2662                 (and type (let ((case-fold-search t))
2663                             (string-match "quoted-printable" type))))
2664         (article-goto-body)
2665         (quoted-printable-decode-region
2666          (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2667
2668 (defun article-de-base64-unreadable (&optional force read-charset)
2669   "Translate a base64 article.
2670 If FORCE, decode the article whether it is marked as base64 not.
2671 If READ-CHARSET, ask for a coding system."
2672   (interactive (list 'force current-prefix-arg))
2673   (save-excursion
2674     (let ((inhibit-read-only t) type charset)
2675       (if (gnus-buffer-live-p gnus-original-article-buffer)
2676           (with-current-buffer gnus-original-article-buffer
2677             (setq type
2678                   (gnus-fetch-field "content-transfer-encoding"))
2679             (let* ((ct (gnus-fetch-field "content-type"))
2680                    (ctl (and ct (mail-header-parse-content-type ct))))
2681               (setq charset (and ctl
2682                                  (mail-content-type-get ctl 'charset)))
2683               (if (stringp charset)
2684                   (setq charset (intern (downcase charset)))))))
2685       (if read-charset
2686           (setq charset (mm-read-coding-system "Charset: " charset)))
2687       (unless charset
2688         (setq charset gnus-newsgroup-charset))
2689       (when (or force
2690                 (and type (let ((case-fold-search t))
2691                             (string-match "base64" type))))
2692         (article-goto-body)
2693         (save-restriction
2694           (narrow-to-region (point) (point-max))
2695           (base64-decode-region (point-min) (point-max))
2696           (mm-decode-coding-region
2697            (point-min) (point-max)
2698            (mm-charset-to-coding-system charset nil t)))))))
2699
2700 (eval-when-compile
2701   (require 'rfc1843))
2702
2703 (defun article-decode-HZ ()
2704   "Translate a HZ-encoded article."
2705   (interactive)
2706   (require 'rfc1843)
2707   (save-excursion
2708     (let ((inhibit-read-only t))
2709       (rfc1843-decode-region (point-min) (point-max)))))
2710
2711 (defun article-unsplit-urls ()
2712   "Remove the newlines that some other mailers insert into URLs."
2713   (interactive)
2714   (save-excursion
2715     (let ((inhibit-read-only t))
2716       (goto-char (point-min))
2717       (while (re-search-forward
2718               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2719         (replace-match "\\1\\3" t)))
2720     (when (gmm-called-interactively-p 'any)
2721       (gnus-treat-article nil))))
2722
2723 (defun article-wash-html ()
2724   "Format an HTML article."
2725   (interactive)
2726   (let ((handles nil)
2727         (buffer-read-only nil))
2728     (when (gnus-buffer-live-p gnus-original-article-buffer)
2729       (with-current-buffer gnus-original-article-buffer
2730         (setq handles (mm-dissect-buffer t t))))
2731     (article-goto-body)
2732     (delete-region (point) (point-max))
2733     (mm-enable-multibyte)
2734     (mm-inline-text-html handles)))
2735
2736 (defvar gnus-article-browse-html-temp-list nil
2737   "List of temporary files created by `gnus-article-browse-html-parts'.
2738 Internal variable.")
2739
2740 (defcustom gnus-article-browse-delete-temp 'ask
2741   "What to do with temporary files from `gnus-article-browse-html-parts'.
2742 If nil, don't delete temporary files.  If it is t, delete them on
2743 exit from the summary buffer.  If it is the symbol `file', query
2744 on each file, if it is `ask' ask once when exiting from the
2745 summary buffer."
2746   :group 'gnus-article
2747   :version "23.1" ;; No Gnus
2748   :type '(choice (const :tag "Don't delete" nil)
2749                  (const :tag "Don't ask" t)
2750                  (const :tag "Ask" ask)
2751                  (const :tag "Ask for each file" file)))
2752
2753 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2754
2755 (defun gnus-article-browse-delete-temp-files (&optional how)
2756   "Delete temp-files created by `gnus-article-browse-html-parts'."
2757   (when (and gnus-article-browse-html-temp-list
2758              (progn
2759                (or how (setq how gnus-article-browse-delete-temp))
2760                (if (eq how 'ask)
2761                    (let ((files (length gnus-article-browse-html-temp-list)))
2762                      (or (gnus-y-or-n-p
2763                           (if (= files 1)
2764                               "Delete the temporary HTML file? "
2765                             (format "Delete all %s temporary HTML files? "
2766                                     files)))
2767                          (setq gnus-article-browse-html-temp-list nil)))
2768                  how)))
2769     (dolist (file gnus-article-browse-html-temp-list)
2770       (cond ((file-directory-p file)
2771              (when (or (not (eq how 'file))
2772                        (gnus-y-or-n-p
2773                         (format
2774                          "Delete temporary HTML file(s) in directory `%s'? "
2775                          (file-name-as-directory file))))
2776                (gnus-delete-directory file)))
2777             ((file-exists-p file)
2778              (when (or (not (eq how 'file))
2779                        (gnus-y-or-n-p
2780                         (format "Delete temporary HTML file `%s'? " file)))
2781                (delete-file file)))))
2782     ;; Also remove file from the list when not deleted or if file doesn't
2783     ;; exist anymore.
2784     (setq gnus-article-browse-html-temp-list nil))
2785   gnus-article-browse-html-temp-list)
2786
2787 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2788   "Find CID content in HANDLES and save it in a file in DIRECTORY.
2789 Return file name."
2790   (save-match-data
2791     (let (file type)
2792       (catch 'found
2793         (dolist (handle handles)
2794           (cond
2795            ((not (listp handle)))
2796            ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2797            ;; may create.
2798            ((not (or (bufferp (car handle)) (stringp (car handle)))))
2799            ((equal (mm-handle-media-supertype handle) "multipart")
2800             (when (setq file (gnus-article-browse-html-save-cid-content
2801                               cid handle directory))
2802               (throw 'found file)))
2803            ((equal (concat "<" cid ">") (mm-handle-id handle))
2804             (setq file
2805                   (expand-file-name
2806                    (or (mm-handle-filename handle)
2807                        (concat
2808                         (make-temp-name "cid")
2809                         (car (rassoc (car (mm-handle-type handle))
2810                                      mailcap-mime-extensions))))
2811                    directory))
2812             (mm-save-part-to-file handle file)
2813             (throw 'found file))))))))
2814
2815 (defun gnus-article-browse-html-parts (list &optional header)
2816   "View all \"text/html\" parts from LIST.
2817 Recurse into multiparts.  The optional HEADER that should be a decoded
2818 message header will be added to the bodies of the \"text/html\" parts."
2819   ;; Internal function used by `gnus-article-browse-html-article'.
2820   (let (type file charset content cid-dir tmp-file showed)
2821     ;; Find and show the html-parts.
2822     (dolist (handle list)
2823       ;; If HTML, show it:
2824       (cond ((not (listp handle)))
2825             ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2826                  (and (equal (car type) "message/external-body")
2827                       (or header
2828                           (setq file (mm-handle-filename handle)))
2829                       (or (mm-handle-cache handle)
2830                           (condition-case code
2831                               (progn (mm-extern-cache-contents handle) t)
2832                             (error
2833                              (gnus-message 3 "%s" (error-message-string code))
2834                              (when (>= gnus-verbose 3) (sit-for 2))
2835                              nil)))
2836                       (progn
2837                         (setq handle (mm-handle-cache handle)
2838                               type (mm-handle-type handle))
2839                         (equal (car type) "text/html"))))
2840              (setq charset (mail-content-type-get type 'charset)
2841                    content (mm-get-part handle))
2842              (with-temp-buffer
2843                (if (eq charset 'gnus-decoded)
2844                    (mm-enable-multibyte)
2845                  (mm-disable-multibyte))
2846                (insert content)
2847                ;; resolve cid contents
2848                (let ((case-fold-search t)
2849                      cid-file)
2850                  (goto-char (point-min))
2851                  (while (re-search-forward "\
2852 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2853                                            nil t)
2854                    (unless cid-dir
2855                      (setq cid-dir (mm-make-temp-file "cid" t))
2856                      (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2857                    (setq file nil
2858                          content nil)
2859                    (when (setq cid-file
2860                                (gnus-article-browse-html-save-cid-content
2861                                 (match-string 2)
2862                                 (with-current-buffer gnus-article-buffer
2863                                   gnus-article-mime-handles)
2864                                 cid-dir))
2865                      (when (eq system-type 'cygwin)
2866                        (setq cid-file
2867                              (concat "/" (substring
2868                                           (with-output-to-string
2869                                             (call-process "cygpath" nil
2870                                                           standard-output
2871                                                           nil "-m" cid-file))
2872                                           0 -1))))
2873                      (replace-match (concat "file://" cid-file)
2874                                     nil nil nil 1))))
2875                (unless content (setq content (buffer-string))))
2876              (when (or charset header (not file))
2877                (setq tmp-file (mm-make-temp-file
2878                                ;; Do we need to care for 8.3 filenames?
2879                                "mm-" nil ".html")))
2880              ;; Add a meta html tag to specify charset and a header.
2881              (cond
2882               (header
2883                (let (title eheader body hcharset coding)
2884                  (with-temp-buffer
2885                    (mm-enable-multibyte)
2886                    (setq case-fold-search t)
2887                    (insert header "\n")
2888                    (setq title (message-fetch-field "subject"))
2889                    (goto-char (point-min))
2890                    (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2891                                              nil t)
2892                      (replace-match (cond ((match-beginning 1) "&lt;")
2893                                           ((match-beginning 2) "&gt;")
2894                                           ((match-beginning 3) "&amp;")
2895                                           (t "<br>\n"))))
2896                    (goto-char (point-min))
2897                    (while (re-search-forward "^[\t ]+" nil t)
2898                      (dotimes (i (prog1
2899                                      (current-column)
2900                                    (delete-region (match-beginning 0)
2901                                                   (match-end 0))))
2902                        (insert "&nbsp;")))
2903                    (goto-char (point-min))
2904                    (insert "<div align=\"left\">\n")
2905                    (goto-char (point-max))
2906                    (insert "</div>\n<hr>\n")
2907                    ;; We have to examine charset one by one since
2908                    ;; charset specified in parts might be different.
2909                    (if (eq charset 'gnus-decoded)
2910                        (setq charset 'utf-8
2911                              eheader (mm-encode-coding-string (buffer-string)
2912                                                               charset)
2913                              title (when title
2914                                      (mm-encode-coding-string title charset))
2915                              body (mm-encode-coding-string content charset))
2916                      (setq hcharset (mm-find-mime-charset-region (point-min)
2917                                                                  (point-max)))
2918                      (cond ((= (length hcharset) 1)
2919                             (setq hcharset (car hcharset)
2920                                   coding (mm-charset-to-coding-system
2921                                           hcharset nil t)))
2922                            ((> (length hcharset) 1)
2923                             (setq hcharset 'utf-8
2924                                   coding hcharset)))
2925                      (if coding
2926                          (if charset
2927                              (progn
2928                                (setq body
2929                                      (mm-charset-to-coding-system charset
2930                                                                   nil t))
2931                                (if (eq coding body)
2932                                    (setq eheader (mm-encode-coding-string
2933                                                   (buffer-string) coding)
2934                                          title (when title
2935                                                  (mm-encode-coding-string
2936                                                   title coding))
2937                                          body content)
2938                                  (setq charset 'utf-8
2939                                        eheader (mm-encode-coding-string
2940                                                 (buffer-string) charset)
2941                                        title (when title
2942                                                (mm-encode-coding-string
2943                                                 title charset))
2944                                        body (mm-encode-coding-string
2945                                              (mm-decode-coding-string
2946                                               content body)
2947                                              charset))))
2948                            (setq charset hcharset
2949                                  eheader (mm-encode-coding-string
2950                                           (buffer-string) coding)
2951                                  title (when title
2952                                          (mm-encode-coding-string
2953                                           title coding))
2954                                  body content))
2955                        (setq eheader (mm-string-as-unibyte (buffer-string))
2956                              body content)))
2957                    (erase-buffer)
2958                    (mm-disable-multibyte)
2959                    (insert body)
2960                    (when charset
2961                      (mm-add-meta-html-tag handle charset t))
2962                    (when title
2963                      (goto-char (point-min))
2964                      (unless (search-forward "<title>" nil t)
2965                        (re-search-forward "<head>\\s-*" nil t)
2966                        (insert "<title>" title "</title>\n")))
2967                    (goto-char (point-min))
2968                    (or (re-search-forward
2969                         "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2970                        (re-search-forward
2971                         "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2972                    (insert eheader)
2973                    (mm-write-region (point-min) (point-max)
2974                                     tmp-file nil nil nil 'binary t))))
2975               (charset
2976                (mm-with-unibyte-buffer
2977                  (insert (if (eq charset 'gnus-decoded)
2978                              (mm-encode-coding-string content
2979                                                       (setq charset 'utf-8))
2980                            content))
2981                  (if (or (mm-add-meta-html-tag handle charset)
2982                          (not file))
2983                      (mm-write-region (point-min) (point-max)
2984                                       tmp-file nil nil nil 'binary t)
2985                    (setq tmp-file nil))))
2986               (tmp-file
2987                (mm-save-part-to-file handle tmp-file)))
2988              (when tmp-file
2989                (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2990              (add-hook 'gnus-summary-prepare-exit-hook
2991                        'gnus-article-browse-delete-temp-files)
2992              (add-hook 'gnus-exit-gnus-hook
2993                        (lambda  ()
2994                          (gnus-article-browse-delete-temp-files t)))
2995              ;; FIXME: Warn if there's an <img> tag?
2996              (browse-url-of-file (or tmp-file (expand-file-name file)))
2997              (setq showed t))
2998             ;; If multipart, recurse
2999             ((equal (mm-handle-media-supertype handle) "multipart")
3000              (when (gnus-article-browse-html-parts handle header)
3001                (setq showed t)))
3002             ((equal (mm-handle-media-type handle) "message/rfc822")
3003              (mm-with-multibyte-buffer
3004                (mm-insert-part handle)
3005                (setq handle (mm-dissect-buffer t t))
3006                (when (and (bufferp (car handle))
3007                           (stringp (car (mm-handle-type handle))))
3008                  (setq handle (list handle)))
3009                (when header
3010                  (article-decode-encoded-words)
3011                  (let ((gnus-visible-headers
3012                         (or (get 'gnus-visible-headers 'standard-value)
3013                             gnus-visible-headers)))
3014                    (article-hide-headers))
3015                  (goto-char (point-min))
3016                  (search-forward "\n\n" nil 'move)
3017                  (skip-chars-backward "\t\n ")
3018                  (setq header (buffer-substring (point-min) (point)))))
3019              (when (prog1
3020                        (gnus-article-browse-html-parts handle header)
3021                      (mm-destroy-parts handle))
3022                (setq showed t)))))
3023     showed))
3024
3025 (defun gnus-article-browse-html-article (&optional arg)
3026   "View \"text/html\" parts of the current article with a WWW browser.
3027 Inline images embedded in a message using the cid scheme, as they are
3028 generally considered to be safe, will be processed properly.
3029 The message header is added to the beginning of every html part unless
3030 the prefix argument ARG is given.
3031
3032 Warning: Spammers use links to images (using the http scheme) in HTML
3033 articles to verify whether you have read the message.  As
3034 `gnus-article-browse-html-article' passes the HTML content to the
3035 browser without eliminating these \"web bugs\" you should only
3036 use it for mails from trusted senders.
3037
3038 If you always want to display HTML parts in the browser, set
3039 `mm-text-html-renderer' to nil.
3040
3041 This command creates temporary files to pass HTML contents including
3042 images if any to the browser, and deletes them when exiting the group
3043 \(if you want)."
3044   ;; Cf. `mm-w3m-safe-url-regexp'
3045   (interactive "P")
3046   (if arg
3047       (gnus-summary-show-article)
3048     (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3049                                     gnus-visible-headers))
3050           ;; As we insert a <hr>, there's no need for the body boundary.
3051           (gnus-treat-body-boundary nil))
3052       (gnus-summary-show-article)))
3053   (with-current-buffer gnus-article-buffer
3054     (let ((header (unless arg
3055                     (save-restriction
3056                       (widen)
3057                       (buffer-substring-no-properties
3058                        (goto-char (point-min))
3059                        (if (search-forward "\n\n" nil t)
3060                            (match-beginning 0)
3061                          (goto-char (point-max))
3062                          (skip-chars-backward "\t\n ")
3063                          (point))))))
3064           parts)
3065       (set-buffer gnus-original-article-buffer)
3066       (setq parts (mm-dissect-buffer t t))
3067       ;; If singlepart, enforce a list.
3068       (when (and (bufferp (car parts))
3069                  (stringp (car (mm-handle-type parts))))
3070         (setq parts (list parts)))
3071       ;; Process the list
3072       (unless (gnus-article-browse-html-parts parts header)
3073         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3074       (mm-destroy-parts parts)
3075       (unless arg
3076         (gnus-summary-show-article)))))
3077
3078 (defun article-hide-list-identifiers ()
3079   "Remove list identifies from the Subject header.
3080 The `gnus-list-identifiers' variable specifies what to do."
3081   (interactive)
3082   (let ((inhibit-point-motion-hooks t)
3083         (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3084         (inhibit-read-only t))
3085     (when regexp
3086       (save-excursion
3087         (save-restriction
3088           (article-narrow-to-head)
3089           (goto-char (point-min))
3090           (while (re-search-forward
3091                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3092                   nil t)
3093             (delete-region (match-beginning 2) (match-end 0))
3094             (beginning-of-line))
3095           (when (re-search-forward
3096                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3097             (delete-region (match-beginning 1) (match-end 1))))))))
3098
3099 (defun article-hide-pem (&optional arg)
3100   "Toggle hiding of any PEM headers and signatures in the current article.
3101 If given a negative prefix, always show; if given a positive prefix,
3102 always hide."
3103   (interactive (gnus-article-hidden-arg))
3104   (unless (gnus-article-check-hidden-text 'pem arg)
3105     (save-excursion
3106       (let ((inhibit-read-only t) end)
3107         (goto-char (point-min))
3108         ;; Hide the horrendously ugly "header".
3109         (when (and (search-forward
3110                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3111                     nil t)
3112                    (setq end (1+ (match-beginning 0))))
3113           (gnus-add-wash-type 'pem)
3114           (gnus-article-hide-text-type
3115            end
3116            (if (search-forward "\n\n" nil t)
3117                (match-end 0)
3118              (point-max))
3119            'pem)
3120           ;; Hide the trailer as well
3121           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3122                                 nil t)
3123             (gnus-article-hide-text-type
3124              (match-beginning 0) (match-end 0) 'pem)))))))
3125
3126 (defun article-strip-banner ()
3127   "Strip the banners specified by the `banner' group parameter and by
3128 `gnus-article-address-banner-alist'."
3129   (interactive)
3130   (save-excursion
3131     (save-restriction
3132       (let ((inhibit-point-motion-hooks t))
3133         (when (gnus-parameter-banner gnus-newsgroup-name)
3134           (article-really-strip-banner
3135            (gnus-parameter-banner gnus-newsgroup-name)))
3136         (when gnus-article-address-banner-alist
3137           ;; Note that the From header is decoded here, so it is
3138           ;; required that the *-extract-address-components function
3139           ;; supports non-ASCII text.
3140           (let ((from (save-restriction
3141                         (widen)
3142                         (article-narrow-to-head)
3143                         (mail-fetch-field "from"))))
3144             (when (and from
3145                        (setq from
3146                              (cadr (funcall gnus-extract-address-components
3147                                             from))))
3148               (catch 'found
3149                 (dolist (pair gnus-article-address-banner-alist)
3150                   (when (string-match (car pair) from)
3151                     (throw 'found
3152                            (article-really-strip-banner (cdr pair)))))))))))))
3153
3154 (defun article-really-strip-banner (banner)
3155   "Strip the banner specified by the argument."
3156   (save-excursion
3157     (save-restriction
3158       (let ((inhibit-point-motion-hooks t)
3159             (gnus-signature-limit nil)
3160             (inhibit-read-only t))
3161         (article-goto-body)
3162         (cond
3163          ((eq banner 'signature)
3164           (when (gnus-article-narrow-to-signature)
3165             (widen)
3166             (forward-line -1)
3167             (delete-region (point) (point-max))))
3168          ((symbolp banner)
3169           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3170               (while (re-search-forward banner nil t)
3171                 (delete-region (match-beginning 0) (match-end 0)))))
3172          ((stringp banner)
3173           (while (re-search-forward banner nil t)
3174             (delete-region (match-beginning 0) (match-end 0)))))))))
3175
3176 (defun article-babel ()
3177   "Translate article using an online translation service."
3178   (interactive)
3179   (require 'babel)
3180   (gnus-with-article-buffer
3181     (when (article-goto-body)
3182       (let* ((start (point))
3183              (end (point-max))
3184              (orig (buffer-substring start end))
3185              (trans (babel-as-string orig)))
3186         (save-restriction
3187           (narrow-to-region start end)
3188           (delete-region start end)
3189           (insert trans))))))
3190
3191 (defun article-hide-signature (&optional arg)
3192   "Hide the signature in the current article.
3193 If given a negative prefix, always show; if given a positive prefix,
3194 always hide."
3195   (interactive (gnus-article-hidden-arg))
3196   (unless (gnus-article-check-hidden-text 'signature arg)
3197     (save-excursion
3198       (save-restriction
3199         (let ((inhibit-read-only t))
3200           (when (gnus-article-narrow-to-signature)
3201             (gnus-article-hide-text-type
3202              (point-min) (point-max) 'signature))))))
3203   (gnus-set-mode-line 'article))
3204
3205 (defun article-strip-headers-in-body ()
3206   "Strip offensive headers from bodies."
3207   (interactive)
3208   (save-excursion
3209     (article-goto-body)
3210     (let ((case-fold-search t))
3211       (when (looking-at "x-no-archive:")
3212         (gnus-delete-line)))))
3213
3214 (defun article-strip-leading-blank-lines ()
3215   "Remove all blank lines from the beginning of the article."
3216   (interactive)
3217   (save-excursion
3218     (let ((inhibit-point-motion-hooks t)
3219           (inhibit-read-only t))
3220       (when (article-goto-body)
3221         (while (and (not (eobp))
3222                     (looking-at "[ \t]*$"))
3223           (gnus-delete-line))))))
3224
3225 (defun article-narrow-to-head ()
3226   "Narrow the buffer to the head of the message.
3227 Point is left at the beginning of the narrowed-to region."
3228   (narrow-to-region
3229    (goto-char (point-min))
3230    (cond
3231     ;; Absolutely no headers displayed.
3232     ((looking-at "\n")
3233      (point))
3234     ;; Normal headers.
3235     ((search-forward "\n\n" nil 1)
3236      (1- (point)))
3237     ;; Nothing but headers.
3238     (t
3239      (point-max))))
3240   (goto-char (point-min)))
3241
3242 (defun article-goto-body ()
3243   "Place point at the start of the body."
3244   (goto-char (point-min))
3245   (cond
3246    ;; This variable is only bound when dealing with separate
3247    ;; MIME body parts.
3248    (article-goto-body-goes-to-point-min-p
3249     t)
3250    ((search-forward "\n\n" nil t)
3251     t)
3252    (t
3253     (goto-char (point-max))
3254     nil)))
3255
3256 (defun article-strip-multiple-blank-lines ()
3257   "Replace consecutive blank lines with one empty line."
3258   (interactive)
3259   (save-excursion
3260     (let ((inhibit-point-motion-hooks t)
3261           (inhibit-read-only t))
3262       ;; First make all blank lines empty.
3263       (article-goto-body)
3264       (while (re-search-forward "^[ \t]+$" nil t)
3265         (unless (gnus-annotation-in-region-p
3266                  (match-beginning 0) (match-end 0))
3267           (replace-match "" nil t)))
3268       ;; Then replace multiple empty lines with a single empty line.
3269       (article-goto-body)
3270       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3271         (unless (gnus-annotation-in-region-p
3272                  (match-beginning 0) (match-end 0))
3273           (delete-region (match-beginning 1) (match-end 1)))))))
3274
3275 (defun article-strip-leading-space ()
3276   "Remove all white space from the beginning of the lines in the article."
3277   (interactive)
3278   (save-excursion
3279     (let ((inhibit-point-motion-hooks t)
3280           (inhibit-read-only t))
3281       (article-goto-body)
3282       (while (re-search-forward "^[ \t]+" nil t)
3283         (replace-match "" t t)))))
3284
3285 (defun article-strip-trailing-space ()
3286   "Remove all white space from the end of the lines in the article."
3287   (interactive)
3288   (save-excursion
3289     (let ((inhibit-point-motion-hooks t)
3290           (inhibit-read-only t))
3291       (article-goto-body)
3292       (while (re-search-forward "[ \t]+$" nil t)
3293         (replace-match "" t t)))))
3294
3295 (defun article-strip-blank-lines ()
3296   "Strip leading, trailing and multiple blank lines."
3297   (interactive)
3298   (article-strip-leading-blank-lines)
3299   (article-remove-trailing-blank-lines)
3300   (article-strip-multiple-blank-lines))
3301
3302 (defun article-strip-all-blank-lines ()
3303   "Strip all blank lines."
3304   (interactive)
3305   (save-excursion
3306     (let ((inhibit-point-motion-hooks t)
3307           (inhibit-read-only t))
3308       (article-goto-body)
3309       (while (re-search-forward "^[ \t]*\n" nil t)
3310         (replace-match "" t t)))))
3311
3312 (defun gnus-article-narrow-to-signature ()
3313   "Narrow to the signature; return t if a signature is found, else nil."
3314   (let ((inhibit-point-motion-hooks t))
3315     (when (gnus-article-search-signature)
3316       (forward-line 1)
3317       ;; Check whether we have some limits to what we consider
3318       ;; to be a signature.
3319       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3320                       (list gnus-signature-limit)))
3321             limit limited)
3322         (while (setq limit (pop limits))
3323           (if (or (and (integerp limit)
3324                        (< (- (point-max) (point)) limit))
3325                   (and (floatp limit)
3326                        (< (count-lines (point) (point-max)) limit))
3327                   (and (functionp limit)
3328                        (funcall limit))
3329                   (and (stringp limit)
3330                        (not (re-search-forward limit nil t))))
3331               ()                        ; This limit did not succeed.
3332             (setq limited t
3333                   limits nil)))
3334         (unless limited
3335           (narrow-to-region (point) (point-max))
3336           t)))))
3337
3338 (defun gnus-article-search-signature ()
3339   "Search the current buffer for the signature separator.
3340 Put point at the beginning of the signature separator."
3341   (let ((cur (point)))
3342     (goto-char (point-max))
3343     (if (if (stringp gnus-signature-separator)
3344             (re-search-backward gnus-signature-separator nil t)
3345           (let ((seps gnus-signature-separator))
3346             (while (and seps
3347                         (not (re-search-backward (car seps) nil t)))
3348               (pop seps))
3349             seps))
3350         t
3351       (goto-char cur)
3352       nil)))
3353
3354 (defun gnus-article-hidden-arg ()
3355   "Return the current prefix arg as a number, or 0 if no prefix."
3356   (list (if current-prefix-arg
3357             (prefix-numeric-value current-prefix-arg)
3358           0)))
3359
3360 (defun gnus-article-check-hidden-text (type arg)
3361   "Return nil if hiding is necessary.
3362 Arg can be nil or a number.  nil and positive means hide, negative
3363 means show, 0 means toggle."
3364   (save-excursion
3365     (save-restriction
3366       (let ((hide (gnus-article-hidden-text-p type)))
3367         (cond
3368          ((or (null arg)
3369               (> arg 0))
3370           nil)
3371          ((< arg 0)
3372           (gnus-article-show-hidden-text type)
3373           t)
3374          (t
3375           (if (eq hide 'hidden)
3376               (progn
3377                 (gnus-article-show-hidden-text type)
3378                 t)
3379             nil)))))))
3380
3381 (defun gnus-article-hidden-text-p (type)
3382   "Say whether the current buffer contains hidden text of type TYPE."
3383   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3384     (while (and pos
3385                 (not (get-text-property pos 'invisible))
3386                 (not (get-text-property pos 'dummy-invisible)))
3387       (setq pos
3388             (text-property-any (1+ pos) (point-max) 'article-type type)))
3389     (if pos
3390         'hidden
3391       nil)))
3392
3393 (defun gnus-article-show-hidden-text (type &optional dummy)
3394   "Show all hidden text of type TYPE.
3395 Originally it is hide instead of DUMMY."
3396   (let ((inhibit-read-only t)
3397         (inhibit-point-motion-hooks t))
3398     (gnus-remove-text-properties-when
3399      'article-type type
3400      (point-min) (point-max)
3401      (cons 'article-type (cons type
3402                                gnus-hidden-properties)))
3403     (gnus-delete-wash-type type)))
3404
3405 (defconst article-time-units
3406   `((year . ,(* 365.25 24 60 60))
3407     (week . ,(* 7 24 60 60))
3408     (day . ,(* 24 60 60))
3409     (hour . ,(* 60 60))
3410     (minute . 60)
3411     (second . 1))
3412   "Mapping from time units to seconds.")
3413
3414 (defun gnus-article-forward-header ()
3415   "Move point to the start of the next header.
3416 If the current header is a continuation header, this can be several
3417 lines forward."
3418   (let ((ended nil))
3419     (while (not ended)
3420       (forward-line 1)
3421       (if (looking-at "[ \t]+[^ \t]")
3422           (forward-line 1)
3423         (setq ended t)))))
3424
3425 (defun article-treat-date ()
3426   (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3427                        (with-current-buffer gnus-summary-buffer
3428                          gnus-article-date-headers)
3429                      gnus-article-date-headers)
3430                    t))
3431
3432 (defun article-date-ut (&optional type highlight date-position)
3433   "Convert DATE date to TYPE in the current article.
3434 The default type is `ut'.  See `gnus-article-date-headers' for
3435 possible values."
3436   (interactive (list 'ut t))
3437   (let* ((case-fold-search t)
3438          (inhibit-read-only t)
3439          (inhibit-point-motion-hooks t)
3440          (first t)
3441          (visible-date (mail-fetch-field "Date"))
3442          pos date bface eface)
3443     (save-excursion
3444       (if date-position
3445           (progn
3446             (goto-char date-position)
3447             (setq date (get-text-property (point) 'original-date))
3448             (when (looking-at "[^:]+:[\t ]*")
3449               (setq bface (get-text-property (match-beginning 0) 'face)
3450                     eface (get-text-property (match-end 0) 'face)))
3451             (delete-region (point)
3452                            (progn
3453                              (gnus-article-forward-header)
3454                              (point)))
3455             (article-transform-date date type bface eface))
3456         (save-restriction
3457           (widen)
3458           (goto-char (point-min))
3459           (while (or (get-text-property (setq pos (point)) 'original-date)
3460                      (and (setq pos (next-single-property-change
3461                                      (point) 'original-date))
3462                           (goto-char pos)))
3463             (narrow-to-region pos (if (search-forward "\n\n" nil t)
3464                                       (1+ (match-beginning 0))
3465                                     (point-max)))
3466             (while (setq pos (text-property-not-all pos (point-max)
3467                                                     'gnus-date-type nil))
3468               (setq date (get-text-property pos 'original-date))
3469               (goto-char pos)
3470               (when (looking-at "[^:]+:[\t ]*")
3471                 (setq bface (get-text-property (match-beginning 0) 'face)
3472                       eface (get-text-property (match-end 0) 'face)))
3473               (delete-region pos (or (text-property-any pos (point-max)
3474                                                         'gnus-date-type nil)
3475                                      (point-max))))
3476             (unless date ;; the 1st time
3477               (goto-char (point-min))
3478               (while (re-search-forward "^Date:[\t ]*" nil t)
3479                 (setq date (get-text-property (match-beginning 0)
3480                                               'original-date)
3481                       bface (get-text-property (match-beginning 0) 'face)
3482                       eface (get-text-property (match-end 0) 'face))
3483                 (delete-region (point-at-bol) (progn
3484                                                 (gnus-article-forward-header)
3485                                                 (point)))))
3486             (when (and (not date)
3487                        visible-date)
3488               (setq date visible-date))
3489             (when date
3490               (article-transform-date date type bface eface))
3491             (goto-char (point-max))
3492             (widen)))))))
3493
3494 (defun article-transform-date (date type bface eface)
3495   (dolist (this-type (cond
3496                       ((null type)
3497                        (list 'ut))
3498                       ((atom type)
3499                        (list type))
3500                       (t
3501                        type)))
3502     (goto-char
3503      (prog1
3504          (point)
3505        (add-text-properties
3506         (point)
3507         (progn
3508           (insert (article-make-date-line date (or this-type 'ut)) "\n")
3509           (point))
3510         (list 'original-date date 'gnus-date-type this-type))))
3511     ;; Do highlighting.
3512     (when (looking-at
3513            "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3514       (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3515       (when (match-beginning 2)
3516         (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3517       (while (and (zerop (forward-line 1))
3518                   (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3519         (when (match-beginning 1)
3520           (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3521
3522 (defun article-make-date-line (date type)
3523   "Return a DATE line of TYPE."
3524   (unless (memq type '(local ut original user-defined iso8601 lapsed english
3525                              combined-lapsed))
3526     (error "Unknown conversion type: %s" type))
3527   (condition-case ()
3528       (let ((time (ignore-errors (date-to-time date))))
3529         (cond
3530          ;; Convert to the local timezone.
3531          ((eq type 'local)
3532           (concat "Date: " (message-make-date time)))
3533          ;; Convert to Universal Time.
3534          ((eq type 'ut)
3535           (concat "Date: "
3536                   (substring
3537                    (message-make-date
3538                     (let* ((e (parse-time-string date))
3539                            (tm (apply 'encode-time e))
3540                            (ms (car tm))
3541                            (ls (- (cadr tm) (car (current-time-zone time)))))
3542                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3543                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3544                             (t (list ms ls)))))
3545                    0 -5)
3546                   "UT"))
3547          ;; Get the original date from the article.
3548          ((eq type 'original)
3549           (concat "Date: " (if (string-match "\n+$" date)
3550                                (substring date 0 (match-beginning 0))
3551                              date)))
3552          ;; Let the user define the format.
3553          ((eq type 'user-defined)
3554           (let ((format (or (condition-case nil
3555                                 (with-current-buffer gnus-summary-buffer
3556                                   gnus-article-time-format)
3557                               (error nil))
3558                             gnus-article-time-format)))
3559             (if (functionp format)
3560                 (funcall format time)
3561               (concat "Date: " (format-time-string format time)))))
3562          ;; ISO 8601.
3563          ((eq type 'iso8601)
3564           (let ((tz (car (current-time-zone time))))
3565             (concat
3566              "Date: "
3567              (format-time-string "%Y%m%dT%H%M%S" time)
3568              (format "%s%02d%02d"
3569                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3570                      (/ (% (abs tz) 3600) 60)))))
3571          ;; Do a lapsed format.
3572          ((eq type 'lapsed)
3573           (concat "Date: " (article-lapsed-string time)))
3574          ;; A combined date/lapsed format.
3575          ((eq type 'combined-lapsed)
3576           (let ((date-string (article-make-date-line date 'original))
3577                 (segments 3)
3578                 lapsed-string)
3579             (while (and
3580                     time
3581                     (setq lapsed-string
3582                           (concat " (" (article-lapsed-string time segments) ")"))
3583                     (> (+ (length date-string)
3584                           (length lapsed-string))
3585                        (+ fill-column 6))
3586                     (> segments 0))
3587               (setq segments (1- segments)))
3588             (if (> segments 0)
3589                 (concat date-string lapsed-string)
3590               date-string)))
3591          ;; Display the date in proper English
3592          ((eq type 'english)
3593           (let ((dtime (decode-time time)))
3594             (concat
3595              "Date: the "
3596              (number-to-string (nth 3 dtime))
3597              (let ((digit (% (nth 3 dtime) 10)))
3598                (cond
3599                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3600                 ((= digit 1) "st")
3601                 ((= digit 2) "nd")
3602                 ((= digit 3) "rd")
3603                 (t "th")))
3604              " of "
3605              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3606              " "
3607              (number-to-string (nth 5 dtime))
3608              " at "
3609              (format "%02d" (nth 2 dtime))
3610              ":"
3611              (format "%02d" (nth 1 dtime)))))))
3612     (foo
3613      (format "Date: %s (from Gnus)" date))))
3614
3615 (defun article-lapsed-string (time &optional max-segments)
3616   ;; If the date is seriously mangled, the timezone functions are
3617   ;; liable to bug out, so we ignore all errors.
3618   (let* ((now (current-time))
3619          (real-time (subtract-time now time))
3620          (real-sec (and real-time
3621                         (+ (* (float (car real-time)) 65536)
3622                            (cadr real-time))))
3623          (sec (and real-time (abs real-sec)))
3624          (segments 0)
3625          num prev)
3626     (unless max-segments
3627       (setq max-segments (length article-time-units)))
3628     (cond
3629      ((null real-time)
3630       "Unknown")
3631      ((zerop sec)
3632       "Now")
3633      (t
3634       (concat
3635        ;; This is a bit convoluted, but basically we go
3636        ;; through the time units for years, weeks, etc,
3637        ;; and divide things to see whether that results
3638        ;; in positive answers.
3639        (mapconcat
3640         (lambda (unit)
3641           (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3642                   (>= segments max-segments))
3643               ;; The (remaining) seconds are too few to
3644               ;; be divided into this time unit.
3645               ""
3646             ;; It's big enough, so we output it.
3647             (setq sec (- sec (* num (cdr unit))))
3648             (prog1
3649                 (concat (if prev ", " "") (int-to-string
3650                                            (floor num))
3651                         " " (symbol-name (car unit))
3652                         (if (> num 1) "s" ""))
3653               (setq prev t
3654                     segments (1+ segments)))))
3655         article-time-units "")
3656        ;; If dates are odd, then it might appear like the
3657        ;; article was sent in the future.
3658        (if (> real-sec 0)
3659            " ago"
3660          " in the future"))))))
3661
3662 (defun article-date-local (&optional highlight)
3663   "Convert the current article date to the local timezone."
3664   (interactive (list t))
3665   (article-date-ut 'local highlight))
3666
3667 (defun article-date-english (&optional highlight)
3668   "Convert the current article date to something that is proper English."
3669   (interactive (list t))
3670   (article-date-ut 'english highlight))
3671
3672 (defun article-date-original (&optional highlight)
3673   "Convert the current article date to what it was originally.
3674 This is only useful if you have used some other date conversion
3675 function and want to see what the date was before converting."
3676   (interactive (list t))
3677   (article-date-ut 'original highlight))
3678
3679 (defun article-date-lapsed (&optional highlight)
3680   "Convert the current article date to time lapsed since it was sent."
3681   (interactive (list t))
3682   (article-date-ut 'lapsed highlight))
3683
3684 (defun article-date-combined-lapsed (&optional highlight)
3685   "Convert the current article date to time lapsed since it was sent."
3686   (interactive (list t))
3687   (article-date-ut 'combined-lapsed highlight))
3688
3689 (defun article-update-date-lapsed ()
3690   "Function to be run from a timer to update the lapsed time line."
3691   (save-match-data
3692     (let ((buffer (current-buffer)))
3693       (ignore-errors
3694         (walk-windows
3695          (lambda (w)
3696            (set-buffer (window-buffer w))
3697            (when (derived-mode-p 'gnus-article-mode)
3698              (let ((old-line (count-lines (point-min) (point)))
3699                    (old-column (- (point) (line-beginning-position)))
3700                    (window-start (window-start w))
3701                    (pos (point-min))
3702                    type next end)
3703                (while (setq pos (text-property-not-all pos (point-max)
3704                                                        'gnus-date-type nil))
3705                  (setq next (or (next-single-property-change pos
3706                                                              'gnus-date-type)
3707                                 (point-max)))
3708                  (setq type (get-text-property pos 'gnus-date-type))
3709                  (when (memq type '(lapsed combined-lapsed user-defined))
3710                    (article-date-ut type t pos)
3711                    (setq end (or (next-single-property-change pos
3712                                                               'gnus-date-type)
3713                                  (point-max)))
3714                    (when window-start
3715                      (if (/= window-start next)
3716                          (setq window-start nil)
3717                        (set-window-start w end)))
3718                    (setq next end))
3719                  (setq pos next))
3720                (goto-char (point-min))
3721                (when (> old-column 0)
3722                  (setq old-line (1- old-line)))
3723                (forward-line old-line)
3724                (end-of-line)
3725                (when (> (current-column) old-column)
3726                  (beginning-of-line)
3727                  (forward-char old-column)))))
3728          nil 'visible))
3729       (set-buffer buffer))))
3730
3731 (defun gnus-start-date-timer (&optional n)
3732   "Start a timer to update the Date headers in the article buffers.
3733 The numerical prefix says how frequently (in seconds) the function
3734 is to run."
3735   (interactive "p")
3736   (unless n
3737     (setq n 1))
3738   (gnus-stop-date-timer)
3739   (setq article-lapsed-timer
3740         (run-at-time 1 n 'article-update-date-lapsed)))
3741
3742 (defun gnus-stop-date-timer ()
3743   "Stop the Date timer."
3744   (interactive)
3745   (when article-lapsed-timer
3746     (nnheader-cancel-timer article-lapsed-timer)
3747     (setq article-lapsed-timer nil)))
3748
3749 (defun article-date-user (&optional highlight)
3750   "Convert the current article date to the user-defined format.
3751 This format is defined by the `gnus-article-time-format' variable."
3752   (interactive (list t))
3753   (article-date-ut 'user highlight))
3754
3755 (defun article-date-iso8601 (&optional highlight)
3756   "Convert the current article date to ISO8601."
3757   (interactive (list t))
3758   (article-date-ut 'iso8601 highlight))
3759
3760 (defmacro gnus-article-save-original-date (&rest forms)
3761   "Save the original date as a text property and evaluate FORMS."
3762   `(let* ((case-fold-search t)
3763           (start (progn
3764                    (goto-char (point-min))
3765                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3766                               (not (bolp)))
3767                      (match-end 0))))
3768           (date (when (and start
3769                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3770                                               nil t))
3771                   (buffer-substring-no-properties start
3772                                                   (match-beginning 0)))))
3773      (goto-char (point-max))
3774      (skip-chars-backward "\n")
3775      (put-text-property (point-min) (point) 'original-date date)
3776      ,@forms
3777      (goto-char (point-max))
3778      (skip-chars-backward "\n")
3779      (put-text-property (point-min) (point) 'original-date date)))
3780
3781 ;; (defun article-show-all ()
3782 ;;   "Show all hidden text in the article buffer."
3783 ;;   (interactive)
3784 ;;   (save-excursion
3785 ;;     (let ((inhibit-read-only t))
3786 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3787
3788 (defun article-remove-leading-whitespace ()
3789   "Remove excessive whitespace from all headers."
3790   (interactive)
3791   (save-excursion
3792     (save-restriction
3793       (let ((inhibit-read-only t))
3794         (article-narrow-to-head)
3795         (goto-char (point-min))
3796         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3797           (delete-region (match-beginning 1) (match-end 1)))))))
3798
3799 (defun article-emphasize (&optional arg)
3800   "Emphasize text according to `gnus-emphasis-alist'."
3801   (interactive (gnus-article-hidden-arg))
3802   (unless (gnus-article-check-hidden-text 'emphasis arg)
3803     (save-excursion
3804       (let ((alist (or
3805                     (condition-case nil
3806                         (with-current-buffer gnus-summary-buffer
3807                           gnus-article-emphasis-alist)
3808                       (error))
3809                     gnus-emphasis-alist))
3810             (inhibit-read-only t)
3811             (props (append '(article-type emphasis)
3812                            gnus-hidden-properties))
3813             regexp elem beg invisible visible face)
3814         (article-goto-body)
3815         (setq beg (point))
3816         (while (setq elem (pop alist))
3817           (goto-char beg)
3818           (setq regexp (car elem)
3819                 invisible (nth 1 elem)
3820                 visible (nth 2 elem)
3821                 face (nth 3 elem))
3822           (while (re-search-forward regexp nil t)
3823             (when (and (match-beginning visible) (match-beginning invisible))
3824               (gnus-article-hide-text
3825                (match-beginning invisible) (match-end invisible) props)
3826               (gnus-article-unhide-text-type
3827                (match-beginning visible) (match-end visible) 'emphasis)
3828               (gnus-put-overlay-excluding-newlines
3829                (match-beginning visible) (match-end visible) 'face face)
3830               (gnus-add-wash-type 'emphasis)
3831               (goto-char (match-end invisible)))))))))
3832
3833 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3834   "Setup newsgroup emphasis alist."
3835   (unless gnus-article-emphasis-alist
3836     (let ((name (and gnus-newsgroup-name
3837                      (gnus-group-real-name gnus-newsgroup-name))))
3838       (make-local-variable 'gnus-article-emphasis-alist)
3839       (setq gnus-article-emphasis-alist
3840             (nconc
3841              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3842                (while (setq elem (pop alist))
3843                  (when (and name (string-match (car elem) name))
3844                    (setq alist nil
3845                          highlight (copy-sequence (cdr elem)))))
3846                highlight)
3847              (copy-sequence highlight-words)
3848              (if gnus-newsgroup-name
3849                  (copy-sequence (gnus-group-find-parameter
3850                                  gnus-newsgroup-name 'highlight-words t)))
3851              gnus-emphasis-alist)))))
3852
3853 (defvar gnus-summary-article-menu)
3854 (defvar gnus-summary-post-menu)
3855
3856 ;;; Saving functions.
3857
3858 (defun gnus-article-save (save-buffer file &optional num)
3859   "Save the currently selected article."
3860   (when (or (get gnus-default-article-saver :headers)
3861             (not gnus-save-all-headers))
3862     ;; Remove headers according to `gnus-saved-headers' or the value
3863     ;; of the `:headers' property that the saver function might have.
3864     (let ((gnus-visible-headers
3865            (or (symbol-value (get gnus-default-article-saver :headers))
3866                gnus-saved-headers gnus-visible-headers))
3867           ;; Ignore group parameter.  See `article-hide-headers'.
3868           (gnus-summary-buffer nil))
3869       (with-current-buffer save-buffer
3870         (article-hide-headers 1 t))))
3871   (save-window-excursion
3872     (if (not gnus-default-article-saver)
3873         (error "No default saver is defined")
3874       ;; !!! Magic!  The saving functions all save
3875       ;; `gnus-save-article-buffer' (or so they think), but we
3876       ;; bind that variable to our save-buffer.
3877       (set-buffer gnus-article-buffer)
3878       (let* ((gnus-save-article-buffer save-buffer)
3879              (filename
3880               (cond
3881                ((not gnus-prompt-before-saving) 'default)
3882                ((eq gnus-prompt-before-saving 'always) nil)
3883                (t file)))
3884              (gnus-number-of-articles-to-be-saved
3885               (when (eq gnus-prompt-before-saving t)
3886                 num)))                  ; Magic
3887         (set-buffer gnus-article-current-summary)
3888         (funcall gnus-default-article-saver filename)))))
3889
3890 (defun gnus-read-save-file-name (prompt &optional filename
3891                                         function group headers variable
3892                                         dir-var)
3893   (let ((default-name
3894           (funcall function group headers (symbol-value variable)))
3895         result)
3896     (setq result
3897           (expand-file-name
3898            (cond
3899             ((eq filename 'default)
3900              default-name)
3901             ((eq filename t)
3902              default-name)
3903             (filename filename)
3904             (t
3905              (when (symbol-value dir-var)
3906                (setq default-name (expand-file-name
3907                                    (file-name-nondirectory default-name)
3908                                    (symbol-value dir-var))))
3909              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3910                     (prompt
3911                      (format prompt
3912                              (if (and gnus-number-of-articles-to-be-saved
3913                                       (> gnus-number-of-articles-to-be-saved 1))
3914                                  (format "these %d articles"
3915                                          gnus-number-of-articles-to-be-saved)
3916                                "this article")))
3917                     (file
3918                      ;; Let the split methods have their say.
3919                      (cond
3920                       ;; No split name was found.
3921                       ((null split-name)
3922                        (read-file-name
3923                         (concat prompt " (default "
3924                                 (file-name-nondirectory default-name) "): ")
3925                         (file-name-directory default-name)
3926                         default-name))
3927                       ;; A single group name is returned.
3928                       ((stringp split-name)
3929                        (setq default-name
3930                              (funcall function split-name headers
3931                                       (symbol-value variable)))
3932                        (read-file-name
3933                         (concat prompt " (default "
3934                                 (file-name-nondirectory default-name) "): ")
3935                         (file-name-directory default-name)
3936                         default-name))
3937                       ;; A single split name was found
3938                       ((= 1 (length split-name))
3939                        (let* ((name (expand-file-name
3940                                      (car split-name)
3941                                      gnus-article-save-directory))
3942                               (dir (cond ((file-directory-p name)
3943                                           (file-name-as-directory name))
3944                                          ((file-exists-p name) name)
3945                                          (t gnus-article-save-directory))))
3946                          (read-file-name
3947                           (concat prompt " (default " name "): ")
3948                           dir name)))
3949                       ;; A list of splits was found.
3950                       (t
3951                        (setq split-name (nreverse split-name))
3952                        (let (result)
3953                          (let ((file-name-history
3954                                 (nconc split-name file-name-history)))
3955                            (setq result
3956                                  (expand-file-name
3957                                   (read-file-name
3958                                    (concat prompt " (`M-p' for defaults): ")
3959                                    gnus-article-save-directory
3960                                    (car split-name))
3961                                   gnus-article-save-directory)))
3962                          (car (push result file-name-history)))))))
3963                ;; Create the directory.
3964                (gnus-make-directory (file-name-directory file))
3965                ;; If we have read a directory, we append the default file name.
3966                (when (file-directory-p file)
3967                  (setq file (expand-file-name (file-name-nondirectory
3968                                                default-name)
3969                                               (file-name-as-directory file))))
3970                ;; Possibly translate some characters.
3971                (nnheader-translate-file-chars file))))))
3972     (gnus-make-directory (file-name-directory result))
3973     (when variable
3974       (set variable result))
3975     (when dir-var
3976       (set dir-var (file-name-directory result)))
3977     result))
3978
3979 (defun gnus-article-archive-name (group)
3980   "Return the first instance of an \"Archive-name\" in the current buffer."
3981   (let ((case-fold-search t))
3982     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3983       (nnheader-concat gnus-article-save-directory
3984                        (match-string 1)))))
3985
3986 (defun gnus-article-nndoc-name (group)
3987   "If GROUP is an nndoc group, return the name of the parent group."
3988   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3989     (gnus-group-get-parameter group 'save-article-group)))
3990
3991 (defun gnus-summary-save-in-rmail (&optional filename)
3992   "Append this article to Rmail file.
3993 Optional argument FILENAME specifies file name.
3994 Directory to save to is default to `gnus-article-save-directory'."
3995   (setq filename (gnus-read-save-file-name
3996                   "Save %s in rmail file" filename
3997                   gnus-rmail-save-name gnus-newsgroup-name
3998                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3999   (with-current-buffer gnus-save-article-buffer
4000     (save-excursion
4001       (save-restriction
4002         (widen)
4003         ;; Note that unlike gnus-summary-save-in-mail, there is no
4004         ;; check to see if filename is Babyl.  Rmail in Emacs 23 does
4005         ;; not use Babyl.
4006         (gnus-output-to-rmail filename))))
4007   filename)
4008
4009 (defun gnus-summary-save-in-mail (&optional filename)
4010   "Append this article to Unix mail file.
4011 Optional argument FILENAME specifies file name.
4012 Directory to save to is default to `gnus-article-save-directory'."
4013   (setq filename (gnus-read-save-file-name
4014                   "Save %s in Unix mail file" filename
4015                   gnus-mail-save-name gnus-newsgroup-name
4016                   gnus-current-headers 'gnus-newsgroup-last-mail))
4017   (with-current-buffer gnus-save-article-buffer
4018     (save-excursion
4019       (save-restriction
4020         (widen)
4021         (if (and (file-readable-p filename)
4022                  (file-regular-p filename)
4023                  (mail-file-babyl-p filename))
4024             (gnus-output-to-rmail filename)
4025           (gnus-output-to-mail filename)))))
4026   filename)
4027
4028 (put 'gnus-summary-save-in-file :decode t)
4029 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4030 (defun gnus-summary-save-in-file (&optional filename overwrite)
4031   "Append this article to file.
4032 Optional argument FILENAME specifies file name.
4033 Directory to save to is default to `gnus-article-save-directory'."
4034   (setq filename (gnus-read-save-file-name
4035                   "Save %s in file" filename
4036                   gnus-file-save-name gnus-newsgroup-name
4037                   gnus-current-headers 'gnus-newsgroup-last-file))
4038   (with-current-buffer gnus-save-article-buffer
4039     (save-excursion
4040       (save-restriction
4041         (widen)
4042         (when (and overwrite
4043                    (file-exists-p filename))
4044           (delete-file filename))
4045         (gnus-output-to-file filename))))
4046   filename)
4047
4048 (put 'gnus-summary-write-to-file :decode t)
4049 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4050 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4051 (defun gnus-summary-write-to-file (&optional filename)
4052   "Write this article to a file, overwriting it if the file exists.
4053 Optional argument FILENAME specifies file name.
4054 The directory to save in defaults to `gnus-article-save-directory'."
4055   (setq filename (gnus-read-save-file-name
4056                   "Save %s in file" filename
4057                   gnus-file-save-name gnus-newsgroup-name
4058                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
4059   (gnus-summary-save-in-file filename t))
4060
4061 (put 'gnus-summary-save-body-in-file :decode t)
4062 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4063   "Append this article body to a file.
4064 Optional argument FILENAME specifies file name.
4065 The directory to save in defaults to `gnus-article-save-directory'."
4066   (setq filename (gnus-read-save-file-name
4067                   "Save %s body in file" filename
4068                   gnus-file-save-name gnus-newsgroup-name
4069                   gnus-current-headers 'gnus-newsgroup-last-file))
4070   (with-current-buffer gnus-save-article-buffer
4071     (save-excursion
4072       (save-restriction
4073         (widen)
4074         (when (article-goto-body)
4075           (narrow-to-region (point) (point-max)))
4076         (when (and overwrite
4077                    (file-exists-p filename))
4078           (delete-file filename))
4079         (gnus-output-to-file filename))))
4080   filename)
4081
4082 (put 'gnus-summary-write-body-to-file :decode t)
4083 (put 'gnus-summary-write-body-to-file
4084      :function 'gnus-summary-save-body-in-file)
4085 (defun gnus-summary-write-body-to-file (&optional filename)
4086   "Write this article body to a file, overwriting it if the file exists.
4087 Optional argument FILENAME specifies file name.
4088 The directory to save in defaults to `gnus-article-save-directory'."
4089   (setq filename (gnus-read-save-file-name
4090                   "Save %s body in file" filename
4091                   gnus-file-save-name gnus-newsgroup-name
4092                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
4093   (gnus-summary-save-body-in-file filename t))
4094
4095 (put 'gnus-summary-save-in-pipe :decode t)
4096 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4097 (defun gnus-summary-save-in-pipe (&optional command raw)
4098   "Pipe this article to subprocess COMMAND.
4099 Valid values for COMMAND include:
4100   a string
4101     The executable command name and possibly arguments.
4102   nil
4103     You will be prompted for the command in the minibuffer.
4104   the symbol `default'
4105     It will be replaced with the command which the variable
4106     `gnus-summary-pipe-output-default-command' holds or the command
4107     last used for saving.
4108 Non-nil value for RAW overrides `:decode' and `:headers' properties
4109 and the raw article including all headers will be piped."
4110   (let ((article (gnus-summary-article-number))
4111         (decode (unless raw
4112                   (get 'gnus-summary-save-in-pipe :decode)))
4113         save-buffer default)
4114     (if article
4115         (if (vectorp (gnus-summary-article-header article))
4116             (save-current-buffer
4117               (gnus-summary-select-article decode decode nil article)
4118               (insert-buffer-substring
4119                (prog1
4120                    (if decode
4121                        gnus-article-buffer
4122                      gnus-original-article-buffer)
4123                  (setq save-buffer
4124                        (nnheader-set-temp-buffer " *Gnus Save*"))))
4125               ;; Remove unwanted headers.
4126               (when (and (not raw)
4127                          (or (get 'gnus-summary-save-in-pipe :headers)
4128                              (not gnus-save-all-headers)))
4129                 (let ((gnus-visible-headers
4130                        (or (symbol-value (get 'gnus-summary-save-in-pipe
4131                                               :headers))
4132                            gnus-saved-headers gnus-visible-headers))
4133                       (gnus-summary-buffer nil))
4134                   (article-hide-headers 1 t))))
4135           (error "%d is not a real article" article))
4136       (error "No article to pipe"))
4137     (setq default (or gnus-summary-pipe-output-default-command
4138                       gnus-last-shell-command))
4139     (unless (stringp command)
4140       (setq command
4141             (if (and (eq command 'default) default)
4142                 default
4143               (gnus-read-shell-command "Shell command on this article: "
4144                                        default))))
4145     (when (string-equal command "")
4146       (if default
4147           (setq command default)
4148         (error "A command is required")))
4149     (with-current-buffer save-buffer
4150       (save-restriction
4151         (widen)
4152         (shell-command-on-region (point-min) (point-max) command nil)))
4153     (gnus-kill-buffer save-buffer))
4154   (setq gnus-summary-pipe-output-default-command command))
4155
4156 (defun gnus-summary-pipe-to-muttprint (&optional command)
4157   "Pipe this article to muttprint."
4158   (unless (stringp command)
4159     (setq command (read-string
4160                    "Print using command: " gnus-summary-muttprint-program
4161                    nil gnus-summary-muttprint-program)))
4162   (let ((gnus-summary-pipe-output-default-command
4163          gnus-summary-pipe-output-default-command))
4164     (gnus-summary-save-in-pipe command))
4165   (setq gnus-summary-muttprint-program command))
4166
4167 ;;; Article file names when saving.
4168
4169 (defun gnus-capitalize-newsgroup (newsgroup)
4170   "Capitalize NEWSGROUP name."
4171   (when (not (zerop (length newsgroup)))
4172     (concat (char-to-string (upcase (aref newsgroup 0)))
4173             (substring newsgroup 1))))
4174
4175 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4176   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4177 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4178 Otherwise, it is like ~/News/news/group/num."
4179   (let ((default
4180           (expand-file-name
4181            (concat (if (gnus-use-long-file-name 'not-save)
4182                        (gnus-capitalize-newsgroup newsgroup)
4183                      (gnus-newsgroup-directory-form newsgroup))
4184                    "/" (int-to-string (mail-header-number headers)))
4185            gnus-article-save-directory)))
4186     (if (and last-file
4187              (string-equal (file-name-directory default)
4188                            (file-name-directory last-file))
4189              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4190         default
4191       (or last-file default))))
4192
4193 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4194   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4195 If variable `gnus-use-long-file-name' is non-nil, it is
4196 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
4197   (let ((default
4198           (expand-file-name
4199            (concat (if (gnus-use-long-file-name 'not-save)
4200                        newsgroup
4201                      (gnus-newsgroup-directory-form newsgroup))
4202                    "/" (int-to-string (mail-header-number headers)))
4203            gnus-article-save-directory)))
4204     (if (and last-file
4205              (string-equal (file-name-directory default)
4206                            (file-name-directory last-file))
4207              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4208         default
4209       (or last-file default))))
4210
4211 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4212   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4213 If variable `gnus-use-long-file-name' is non-nil, it is
4214 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
4215   (or last-file
4216       (expand-file-name
4217        (if (gnus-use-long-file-name 'not-save)
4218            newsgroup
4219          (file-relative-name
4220           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4221           default-directory))
4222        gnus-article-save-directory)))
4223
4224 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4225   "Generate file name from sender."
4226   (let ((from (mail-header-from headers)))
4227     (expand-file-name
4228      (if (and from (string-match "\\([^ <]+\\)@" from))
4229          (match-string 1 from)
4230        "nobody")
4231      gnus-article-save-directory)))
4232
4233 (defun article-verify-x-pgp-sig ()
4234   "Verify X-PGP-Sig."
4235   ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4236   (interactive)
4237   (if (gnus-buffer-live-p gnus-original-article-buffer)
4238       (let ((sig (with-current-buffer gnus-original-article-buffer
4239                    (gnus-fetch-field "X-PGP-Sig")))
4240             items info headers)
4241         (when (and sig
4242                    mml2015-use
4243                    (mml2015-clear-verify-function))
4244           (with-temp-buffer
4245             (insert-buffer-substring gnus-original-article-buffer)
4246             (setq items (split-string sig))
4247             (message-narrow-to-head)
4248             (let ((inhibit-point-motion-hooks t)
4249                   (case-fold-search t))
4250               ;; Don't verify multiple headers.
4251               (setq headers (mapconcat (lambda (header)
4252                                          (concat header ": "
4253                                                  (mail-fetch-field header)
4254                                                  "\n"))
4255                                        (split-string (nth 1 items) ",") "")))
4256             (delete-region (point-min) (point-max))
4257             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4258             (insert "X-Signed-Headers: " (nth 1 items) "\n")
4259             (insert headers)
4260             (widen)
4261             (forward-line)
4262             (while (not (eobp))
4263               (if (looking-at "^-")
4264                   (insert "- "))
4265               (forward-line))
4266             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4267             (insert "Version: " (car items) "\n\n")
4268             (insert (mapconcat 'identity (cddr items) "\n"))
4269             (insert "\n-----END PGP SIGNATURE-----\n")
4270             (let ((mm-security-handle (list (format "multipart/signed"))))
4271               (mml2015-clean-buffer)
4272               (let ((coding-system-for-write (or gnus-newsgroup-charset
4273                                                  'iso-8859-1)))
4274                 (funcall (mml2015-clear-verify-function)))
4275               (setq info
4276                     (or (mm-handle-multipart-ctl-parameter
4277                          mm-security-handle 'gnus-details)
4278                         (mm-handle-multipart-ctl-parameter
4279                          mm-security-handle 'gnus-info)))))
4280           (when info
4281             (let ((inhibit-read-only t) bface eface)
4282               (save-restriction
4283                 (message-narrow-to-head)
4284                 (goto-char (point-max))
4285                 (forward-line -1)
4286                 (setq bface (get-text-property (point-at-bol) 'face)
4287                       eface (get-text-property (1- (point-at-eol)) 'face))
4288                 (message-remove-header "X-Gnus-PGP-Verify")
4289                 (if (re-search-forward "^X-PGP-Sig:" nil t)
4290                     (forward-line)
4291                   (goto-char (point-max)))
4292                 (narrow-to-region (point) (point))
4293                 (insert "X-Gnus-PGP-Verify: " info "\n")
4294                 (goto-char (point-min))
4295                 (forward-line)
4296                 (while (not (eobp))
4297                   (if (not (looking-at "^[ \t]"))
4298                       (insert " "))
4299                   (forward-line))
4300                 ;; Do highlighting.
4301                 (goto-char (point-min))
4302                 (when (looking-at "\\([^:]+\\): *")
4303                   (put-text-property (match-beginning 1) (1+ (match-end 1))
4304                                      'face bface)
4305                   (put-text-property (match-end 0) (point-max)
4306                                      'face eface)))))))))
4307
4308 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4309
4310 (defun article-verify-cancel-lock ()
4311   "Verify Cancel-Lock header."
4312   (interactive)
4313   (if (gnus-buffer-live-p gnus-original-article-buffer)
4314       (canlock-verify gnus-original-article-buffer)))
4315
4316 (eval-and-compile
4317   (mapc
4318    (lambda (func)
4319      (let (afunc gfunc)
4320        (if (consp func)
4321            (setq afunc (car func)
4322                  gfunc (cdr func))
4323          (setq afunc func
4324                gfunc (intern (format "gnus-%s" func))))
4325        (defalias gfunc
4326          (when (fboundp afunc)
4327            `(lambda (&optional interactive &rest args)
4328               ,(documentation afunc t)
4329               (interactive (list t))
4330               (with-current-buffer gnus-article-buffer
4331                 (if interactive
4332                     (call-interactively ',afunc)
4333                   (apply ',afunc args))))))))
4334    '(article-hide-headers
4335      article-verify-x-pgp-sig
4336      article-verify-cancel-lock
4337      article-hide-boring-headers
4338      article-treat-overstrike
4339      article-treat-ansi-sequences
4340      article-fill-long-lines
4341      article-capitalize-sentences
4342      article-remove-cr
4343      article-remove-leading-whitespace
4344      article-display-x-face
4345      article-display-face
4346      article-de-quoted-unreadable
4347      article-de-base64-unreadable
4348      article-decode-HZ
4349      article-wash-html
4350      article-unsplit-urls
4351      article-hide-list-identifiers
4352      article-strip-banner
4353      article-babel
4354      article-hide-pem
4355      article-hide-signature
4356      article-strip-headers-in-body
4357      article-remove-trailing-blank-lines
4358      article-strip-leading-blank-lines
4359      article-strip-multiple-blank-lines
4360      article-strip-leading-space
4361      article-strip-trailing-space
4362      article-strip-blank-lines
4363      article-strip-all-blank-lines
4364      article-date-local
4365      article-date-english
4366      article-date-iso8601
4367      article-date-original
4368      article-treat-date
4369      article-date-ut
4370      article-decode-mime-words
4371      article-decode-charset
4372      article-decode-encoded-words
4373      article-date-user
4374      article-date-lapsed
4375      article-date-combined-lapsed
4376      article-emphasize
4377      article-treat-dumbquotes
4378      article-treat-non-ascii
4379      article-normalize-headers
4380      ;;(article-show-all . gnus-article-show-all-headers)
4381      )))
4382 \f
4383 ;;;
4384 ;;; Gnus article mode
4385 ;;;
4386
4387 (put 'gnus-article-mode 'mode-class 'special)
4388
4389 (set-keymap-parent gnus-article-mode-map widget-keymap)
4390
4391 (gnus-define-keys gnus-article-mode-map
4392   " " gnus-article-goto-next-page
4393   [?\S-\ ] gnus-article-goto-prev-page
4394   "\177" gnus-article-goto-prev-page
4395   [delete] gnus-article-goto-prev-page
4396   "\C-c^" gnus-article-refer-article
4397   "h" gnus-article-show-summary
4398   "s" gnus-article-show-summary
4399   "\C-c\C-m" gnus-article-mail
4400   "?" gnus-article-describe-briefly
4401   "<" beginning-of-buffer
4402   ">" end-of-buffer
4403   "\C-c\C-i" gnus-info-find-node
4404   "\C-c\C-b" gnus-bug
4405   "R" gnus-article-reply-with-original
4406   "F" gnus-article-followup-with-original
4407   "\C-hk" gnus-article-describe-key
4408   "\C-hc" gnus-article-describe-key-briefly
4409   "\C-hb" gnus-article-describe-bindings
4410
4411   "e" gnus-article-read-summary-keys
4412   "\C-d" gnus-article-read-summary-keys
4413   "\M-*" gnus-article-read-summary-keys
4414   "\M-#" gnus-article-read-summary-keys
4415   "\M-^" gnus-article-read-summary-keys
4416   "\M-g" gnus-article-read-summary-keys)
4417
4418 (substitute-key-definition
4419  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4420
4421 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4422   "W" gnus-article-wide-reply-with-original)
4423 (if (featurep 'xemacs)
4424     (set-keymap-default-binding gnus-article-send-map
4425                                 'gnus-article-read-summary-send-keys)
4426   (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4427
4428 (defun gnus-article-make-menu-bar ()
4429   (unless (boundp 'gnus-article-commands-menu)
4430     (gnus-summary-make-menu-bar))
4431   (unless (boundp 'gnus-article-article-menu)
4432     (easy-menu-define
4433      gnus-article-article-menu gnus-article-mode-map ""
4434      '("Article"
4435        ["Scroll forwards" gnus-article-goto-next-page t]
4436        ["Scroll backwards" gnus-article-goto-prev-page t]
4437        ["Show summary" gnus-article-show-summary t]
4438        ["Fetch Message-ID at point" gnus-article-refer-article t]
4439        ["Mail to address at point" gnus-article-mail t]
4440        ["Send a bug report" gnus-bug t]))
4441
4442     (easy-menu-define
4443      gnus-article-treatment-menu gnus-article-mode-map ""
4444      ;; Fixme: this should use :active (and maybe :visible).
4445      '("Treatment"
4446        ["Hide headers" gnus-article-hide-headers t]
4447        ["Hide signature" gnus-article-hide-signature t]
4448        ["Hide citation" gnus-article-hide-citation t]
4449        ["Treat overstrike" gnus-article-treat-overstrike t]
4450        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4451        ["Remove carriage return" gnus-article-remove-cr t]
4452        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4453        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4454        ["Remove base64" gnus-article-de-base64-unreadable t]
4455        ["Treat html" gnus-article-wash-html t]
4456        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4457        ["Decode HZ" gnus-article-decode-HZ t]))
4458
4459     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4460
4461     ;; Note "Post" menu is defined in gnus-sum.el for consistency
4462
4463     (gnus-run-hooks 'gnus-article-menu-hook)))
4464
4465 (defvar bookmark-make-record-function)
4466 (defvar shr-put-image-function)
4467
4468 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4469   "Major mode for displaying an article.
4470
4471 All normal editing commands are switched off.
4472
4473 The following commands are available in addition to all summary mode
4474 commands:
4475 \\<gnus-article-mode-map>
4476 \\[gnus-article-next-page]\t Scroll the article one page forwards
4477 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4478 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4479 \\[gnus-article-show-summary]\t Display the summary buffer
4480 \\[gnus-article-mail]\t Send a reply to the address near point
4481 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4482 \\[gnus-info-find-node]\t Go to the Gnus info node"
4483   (gnus-simplify-mode-line)
4484   (make-local-variable 'minor-mode-alist)
4485   (when (gnus-visual-p 'article-menu 'menu)
4486     (gnus-article-make-menu-bar)
4487     (when gnus-summary-tool-bar-map
4488       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4489   (gnus-update-format-specifications nil 'article-mode)
4490   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4491   (set (make-local-variable 'gnus-page-broken) nil)
4492   (make-local-variable 'gnus-article-current-summary)
4493   (make-local-variable 'gnus-article-mime-handles)
4494   (make-local-variable 'gnus-article-decoded-p)
4495   (make-local-variable 'gnus-article-mime-handle-alist)
4496   (make-local-variable 'gnus-article-wash-types)
4497   (make-local-variable 'gnus-article-image-alist)
4498   (make-local-variable 'gnus-article-charset)
4499   (make-local-variable 'gnus-article-ignored-charsets)
4500   (set (make-local-variable 'bookmark-make-record-function)
4501        'gnus-summary-bookmark-make-record)
4502   ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4503   ;; face.
4504   (set (make-local-variable 'nobreak-char-display) nil)
4505   ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4506   (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4507   (setq cursor-in-non-selected-windows nil)
4508   (gnus-set-default-directory)
4509   (buffer-disable-undo)
4510   (setq buffer-read-only t
4511         show-trailing-whitespace nil)
4512   (mm-enable-multibyte))
4513
4514 (defun gnus-article-setup-buffer ()
4515   "Initialize the article buffer."
4516   (let* ((name (if gnus-single-article-buffer "*Article*"
4517                  (concat "*Article "
4518                          (gnus-group-decoded-name gnus-newsgroup-name)
4519                          "*")))
4520          (original
4521           (progn (string-match "\\*Article" name)
4522                  (concat " *Original Article"
4523                          (substring name (match-end 0))))))
4524     (setq gnus-article-buffer name)
4525     (setq gnus-original-article-buffer original)
4526     (setq gnus-article-mime-handle-alist nil)
4527     (with-current-buffer gnus-summary-buffer
4528       ;; This might be a variable local to the summary buffer.
4529       (unless gnus-single-article-buffer
4530         (setq gnus-article-buffer name)
4531         (setq gnus-original-article-buffer original)
4532         (gnus-set-global-variables)))
4533     (gnus-article-setup-highlight-words)
4534     ;; Init original article buffer.
4535     (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4536       (mm-enable-multibyte)
4537       (setq major-mode 'gnus-original-article-mode)
4538       (make-local-variable 'gnus-original-article))
4539     (if (and (get-buffer name)
4540              (with-current-buffer name
4541                (if gnus-article-edit-mode
4542                    (if (y-or-n-p "Article mode edit in progress; discard? ")
4543                        (progn
4544                          (set-buffer-modified-p nil)
4545                          (gnus-kill-buffer name)
4546                          (message "")
4547                          nil)
4548                      (error "Action aborted"))
4549                  t)))
4550         (let ((summary gnus-summary-buffer))
4551           (with-current-buffer name
4552             (set (make-local-variable 'gnus-article-edit-mode) nil)
4553             (gnus-article-stop-animations)
4554             (when gnus-article-mime-handles
4555               (mm-destroy-parts gnus-article-mime-handles)
4556               (setq gnus-article-mime-handles nil))
4557             ;; Set it to nil in article-buffer!
4558             (setq gnus-article-mime-handle-alist nil)
4559             (buffer-disable-undo)
4560             (setq buffer-read-only t)
4561             (unless (derived-mode-p 'gnus-article-mode)
4562               (gnus-article-mode))
4563             (set (make-local-variable 'gnus-summary-buffer) summary)
4564             (setq truncate-lines gnus-article-truncate-lines)
4565             (current-buffer)))
4566       (let ((summary gnus-summary-buffer))
4567         (with-current-buffer (gnus-get-buffer-create name)
4568           (gnus-article-mode)
4569           (setq truncate-lines gnus-article-truncate-lines)
4570           (set (make-local-variable 'gnus-summary-buffer) summary)
4571           (gnus-summary-set-local-parameters gnus-newsgroup-name)
4572           (when article-lapsed-timer
4573             (gnus-stop-date-timer))
4574           (when gnus-article-update-date-headers
4575             (gnus-start-date-timer gnus-article-update-date-headers))
4576           (current-buffer))))))
4577
4578 (defun gnus-article-stop-animations ()
4579   (dolist (timer (and (boundp 'timer-list)
4580                       timer-list))
4581     (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4582       (cancel-timer timer))))
4583
4584 (defun gnus-stop-downloads ()
4585   (when (boundp 'url-queue)
4586     (set (intern "url-queue" obarray) nil)))
4587
4588 ;; Set article window start at LINE, where LINE is the number of lines
4589 ;; from the head of the article.
4590 (defun gnus-article-set-window-start (&optional line)
4591   (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4592     (when article-window
4593       (set-window-start
4594        article-window
4595        (with-current-buffer gnus-article-buffer
4596          (goto-char (point-min))
4597          (if (not line)
4598              (point-min)
4599            (gnus-message 6 "Moved to bookmark")
4600            (search-forward "\n\n" nil t)
4601            (forward-line line)
4602            (point)))))))
4603
4604 (defun gnus-article-prepare (article &optional all-headers header)
4605   "Prepare ARTICLE in article mode buffer.
4606 ARTICLE should either be an article number or a Message-ID.
4607 If ARTICLE is an id, HEADER should be the article headers.
4608 If ALL-HEADERS is non-nil, no headers are hidden."
4609   (save-excursion
4610     ;; Make sure we start in a summary buffer.
4611     (unless (derived-mode-p 'gnus-summary-mode)
4612       (set-buffer gnus-summary-buffer))
4613     (setq gnus-summary-buffer (current-buffer))
4614     (let* ((gnus-article (if header (mail-header-number header) article))
4615            (summary-buffer (current-buffer))
4616            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4617            (group gnus-newsgroup-name)
4618            result)
4619       (save-excursion
4620         (gnus-article-setup-buffer)
4621         (set-buffer gnus-article-buffer)
4622         ;; Deactivate active regions.
4623         (when (and (boundp 'transient-mark-mode)
4624                    transient-mark-mode)
4625           (setq mark-active nil))
4626         (if (not (setq result (let ((inhibit-read-only t))
4627                                 (gnus-request-article-this-buffer
4628                                  article group))))
4629             ;; There is no such article.
4630             (save-excursion
4631               (when (and (numberp article)
4632                          (not (memq article gnus-newsgroup-sparse)))
4633                 (setq gnus-article-current
4634                       (cons gnus-newsgroup-name article))
4635                 (set-buffer gnus-summary-buffer)
4636                 (setq gnus-current-article article)
4637                 (if (and (memq article gnus-newsgroup-undownloaded)
4638                          (not (gnus-online (gnus-find-method-for-group
4639                                             gnus-newsgroup-name))))
4640                     (progn
4641                       (gnus-summary-set-agent-mark article)
4642                       (message "Message marked for downloading"))
4643                   (gnus-summary-mark-article article gnus-canceled-mark)
4644                   (unless (memq article gnus-newsgroup-sparse)
4645                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4646           (if (or (eq result 'pseudo)
4647                   (eq result 'nneething))
4648               (progn
4649                 (with-current-buffer summary-buffer
4650                   (push article gnus-newsgroup-history)
4651                   (setq gnus-last-article gnus-current-article
4652                         gnus-current-article 0
4653                         gnus-current-headers nil
4654                         gnus-article-current nil)
4655                   (if (eq result 'nneething)
4656                       (gnus-configure-windows 'summary)
4657                     (gnus-configure-windows 'article))
4658                   (gnus-set-global-variables))
4659                 (let ((gnus-article-mime-handle-alist-1
4660                        gnus-article-mime-handle-alist))
4661                   (gnus-set-mode-line 'article)))
4662             ;; The result from the `request' was an actual article -
4663             ;; or at least some text that is now displayed in the
4664             ;; article buffer.
4665             (when (and (numberp article)
4666                        (not (eq article gnus-current-article)))
4667               ;; Seems like a new article has been selected.
4668               ;; `gnus-current-article' must be an article number.
4669               (with-current-buffer summary-buffer
4670                 (push article gnus-newsgroup-history)
4671                 (setq gnus-last-article gnus-current-article
4672                       gnus-current-article article
4673                       gnus-current-headers
4674                       (gnus-summary-article-header gnus-current-article)
4675                       gnus-article-current
4676                       (cons gnus-newsgroup-name gnus-current-article))
4677                 (unless (vectorp gnus-current-headers)
4678                   (setq gnus-current-headers nil))
4679                 (gnus-summary-goto-subject gnus-current-article)
4680                 (when (gnus-summary-show-thread)
4681                   ;; If the summary buffer really was folded, the
4682                   ;; previous goto may not actually have gone to
4683                   ;; the right article, but the thread root instead.
4684                   ;; So we go again.
4685                   (gnus-summary-goto-subject gnus-current-article))
4686                 (gnus-run-hooks 'gnus-mark-article-hook)
4687                 (gnus-set-mode-line 'summary)
4688                 (when (gnus-visual-p 'article-highlight 'highlight)
4689                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4690                 ;; Set the global newsgroup variables here.
4691                 (gnus-set-global-variables)
4692                 (setq gnus-have-all-headers
4693                       (or all-headers gnus-show-all-headers))))
4694             (save-excursion
4695               (gnus-configure-windows 'article))
4696             (when (or (numberp article)
4697                       (stringp article))
4698               (gnus-article-prepare-display)
4699               ;; Do page break.
4700               (goto-char (point-min))
4701               (when gnus-break-pages
4702                 (gnus-narrow-to-page)))
4703             (let ((gnus-article-mime-handle-alist-1
4704                    gnus-article-mime-handle-alist))
4705               (gnus-set-mode-line 'article))
4706             (article-goto-body)
4707             (unless (bobp)
4708               (forward-line -1))
4709             (set-window-point (get-buffer-window (current-buffer)) (point))
4710             (gnus-configure-windows 'article)
4711             (gnus-run-hooks 'gnus-article-prepare-hook)
4712             t))))))
4713
4714 ;;;###autoload
4715 (defun gnus-article-prepare-display ()
4716   "Make the current buffer look like a nice article."
4717   ;; Hooks for getting information from the article.
4718   ;; This hook must be called before being narrowed.
4719   (let ((gnus-article-buffer (current-buffer))
4720         buffer-read-only
4721         (inhibit-read-only t))
4722     (unless (derived-mode-p 'gnus-article-mode)
4723       (gnus-article-mode))
4724     (setq buffer-read-only nil
4725           gnus-article-wash-types nil
4726           gnus-article-image-alist nil)
4727     (gnus-run-hooks 'gnus-tmp-internal-hook)
4728     (when gnus-display-mime-function
4729       (funcall gnus-display-mime-function))
4730     ;; Add attachment buttons to the header.
4731     (when gnus-mime-display-attachment-buttons-in-header
4732       (gnus-mime-buttonize-attachments-in-header))))
4733
4734 ;;;
4735 ;;; Gnus Sticky Article Mode
4736 ;;;
4737
4738 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4739   "Mode for sticky articles."
4740   ;; Release bindings that won't work.
4741   (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4742                              gnus-sticky-article-mode-map)
4743   (substitute-key-definition 'gnus-article-refer-article 'undefined
4744                              gnus-sticky-article-mode-map)
4745   (dolist (k '("e" "h" "s" "F" "R"))
4746     (define-key gnus-sticky-article-mode-map k nil))
4747   (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4748   (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4749   (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4750   (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4751
4752 (defun gnus-sticky-article (arg)
4753   "Make the current article sticky.
4754 If a prefix ARG is given, ask for a name for this sticky article buffer."
4755   (interactive "P")
4756   (gnus-summary-show-thread)
4757   (gnus-summary-select-article nil nil 'pseudo)
4758   (let (new-art-buf-name)
4759     (gnus-eval-in-buffer-window gnus-article-buffer
4760       (setq new-art-buf-name
4761             (concat
4762              "*Sticky Article: "
4763              (if arg
4764                  (read-from-minibuffer "Sticky article buffer name: ")
4765                (gnus-with-article-headers
4766                  (gnus-article-goto-header "subject")
4767                  (setq new-art-buf-name
4768                        (buffer-substring-no-properties
4769                         (line-beginning-position) (line-end-position)))
4770                  (goto-char (point-min))
4771                  (gnus-article-goto-header "from")
4772                  (setq new-art-buf-name
4773                        (concat
4774                         new-art-buf-name ", "
4775                         (buffer-substring-no-properties
4776                          (line-beginning-position) (line-end-position))))
4777                  (goto-char (point-min))
4778                  (gnus-article-goto-header "date")
4779                  (setq new-art-buf-name
4780                        (concat
4781                         new-art-buf-name ", "
4782                         (buffer-substring-no-properties
4783                          (line-beginning-position) (line-end-position))))))
4784              "*"))
4785       (if (and (gnus-buffer-live-p new-art-buf-name)
4786                (with-current-buffer new-art-buf-name
4787                  (derived-mode-p 'gnus-sticky-article-mode)))
4788           (switch-to-buffer new-art-buf-name)
4789         (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4790       (gnus-sticky-article-mode))
4791     (setq gnus-article-buffer new-art-buf-name))
4792   (gnus-summary-recenter)
4793   (gnus-summary-position-point))
4794
4795 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4796   "Kill the given sticky article BUFFER.
4797 If none is given, assume the current buffer and kill it if it has
4798 `gnus-sticky-article-mode'."
4799   (interactive)
4800   (unless buffer
4801     (setq buffer (current-buffer)))
4802   (with-current-buffer buffer
4803     (when (derived-mode-p 'gnus-sticky-article-mode)
4804       (gnus-kill-buffer buffer))))
4805
4806 (defun gnus-kill-sticky-article-buffers (arg)
4807   "Kill all sticky article buffers.
4808 If a prefix ARG is given, ask for confirmation."
4809   (interactive "P")
4810   (dolist (buf (gnus-buffers))
4811     (with-current-buffer buf
4812       (when (derived-mode-p 'gnus-sticky-article-mode)
4813         (if (not arg)
4814             (gnus-kill-buffer buf)
4815           (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4816             (gnus-kill-buffer buf)))))))
4817
4818 ;;;
4819 ;;; Gnus MIME viewing functions
4820 ;;;
4821
4822 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4823   "Format of the MIME buttons.
4824
4825 Valid specifiers include:
4826 %t  The MIME type
4827 %T  MIME type, along with additional info
4828 %n  The `name' parameter
4829 %d  The description, if any
4830 %l  The length of the encoded part
4831 %p  The part identifier number
4832 %e  Dots if the part isn't displayed
4833
4834 General format specifiers can also be used.  See Info node
4835 `(gnus)Formatting Variables'.")
4836
4837 (defvar gnus-mime-button-line-format-alist
4838   '((?t gnus-tmp-type ?s)
4839     (?T gnus-tmp-type-long ?s)
4840     (?n gnus-tmp-name ?s)
4841     (?d gnus-tmp-description ?s)
4842     (?p gnus-tmp-id ?s)
4843     (?l gnus-tmp-length ?d)
4844     (?e gnus-tmp-dots ?s)))
4845
4846 (defvar gnus-mime-button-commands
4847   '((gnus-article-press-button "\r" "Toggle Display")
4848     (gnus-mime-view-part "v" "View Interactively...")
4849     (gnus-mime-view-part-as-type "t" "View As Type...")
4850     (gnus-mime-view-part-as-charset "C" "View As charset...")
4851     (gnus-mime-save-part "o" "Save...")
4852     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4853     (gnus-mime-replace-part "r" "Replace part")
4854     (gnus-mime-delete-part "d" "Delete part")
4855     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4856     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4857     (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4858     (gnus-mime-view-part-externally "e" "View Externally")
4859     (gnus-mime-print-part "p" "Print")
4860     (gnus-mime-pipe-part "|" "Pipe To Command...")
4861     (gnus-mime-action-on-part "." "Take action on the part...")))
4862
4863 (defun gnus-article-mime-part-status ()
4864   (if gnus-article-mime-handle-alist-1
4865       (if (eq 1 (length gnus-article-mime-handle-alist-1))
4866           " (1 part)"
4867         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4868     ""))
4869
4870 (defvar gnus-mime-button-map
4871   (let ((map (make-sparse-keymap)))
4872     (define-key map gnus-mouse-2 'gnus-article-push-button)
4873     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4874     (dolist (c gnus-mime-button-commands)
4875       (define-key map (cadr c) (car c)))
4876     map))
4877
4878 (easy-menu-define
4879   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4880   `("MIME Part"
4881     ,@(mapcar (lambda (c)
4882                 (vector (caddr c) (car c) :active t))
4883               gnus-mime-button-commands)))
4884
4885 (defvar gnus-url-button-commands
4886   '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4887
4888 (defvar gnus-url-button-map
4889   (let ((map (make-sparse-keymap)))
4890     (dolist (c gnus-url-button-commands)
4891       (define-key map (cadr c) (car c)))
4892     map))
4893
4894 (easy-menu-define
4895   gnus-url-button-menu gnus-url-button-map "URL button menu."
4896   `("Url Button"
4897     ,@(mapcar (lambda (c)
4898                 (vector (caddr c) (car c) :active t))
4899               gnus-url-button-commands)))
4900
4901 (defmacro gnus-bind-safe-url-regexp (&rest body)
4902   "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4903   `(let ((mm-w3m-safe-url-regexp
4904           (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4905                                 (gnus-buffer-live-p
4906                                  gnus-article-current-summary))
4907                            (with-current-buffer gnus-article-current-summary
4908                              gnus-newsgroup-name)
4909                          gnus-newsgroup-name)))
4910             (if (cond ((not group)
4911                        ;; Maybe we're in a mml-preview buffer
4912                        ;; and no group is selected.
4913                        t)
4914                       ((stringp gnus-safe-html-newsgroups)
4915                        (string-match gnus-safe-html-newsgroups group))
4916                       ((consp gnus-safe-html-newsgroups)
4917                        (member group gnus-safe-html-newsgroups)))
4918                 nil
4919               mm-w3m-safe-url-regexp))))
4920      ,@body))
4921
4922 (defun gnus-mime-button-menu (event prefix)
4923  "Construct a context-sensitive menu of MIME commands."
4924  (interactive "e\nP")
4925  (save-window-excursion
4926    (let ((pos (event-start event)))
4927      (select-window (posn-window pos))
4928      (goto-char (posn-point pos))
4929      (gnus-article-check-buffer)
4930      (popup-menu gnus-mime-button-menu nil prefix))))
4931
4932 (defun gnus-mime-view-all-parts (&optional handles)
4933   "View all the MIME parts."
4934   (interactive)
4935   (with-current-buffer gnus-article-buffer
4936     (let ((handles (or handles gnus-article-mime-handles))
4937           (mail-parse-charset gnus-newsgroup-charset)
4938           (mail-parse-ignored-charsets
4939            (with-current-buffer gnus-summary-buffer
4940              gnus-newsgroup-ignored-charsets)))
4941       (when handles
4942         (mm-remove-parts handles)
4943         (goto-char (point-min))
4944         (or (search-forward "\n\n") (goto-char (point-max)))
4945         (let ((inhibit-read-only t))
4946           (delete-region (point) (point-max))
4947           (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4948
4949 (defun gnus-article-jump-to-part (n)
4950   "Jump to MIME part N."
4951   (interactive "P")
4952   (let ((parts (with-current-buffer gnus-article-buffer
4953                  (length gnus-article-mime-handle-alist))))
4954     (when (zerop parts)
4955       (error "No such part"))
4956     (pop-to-buffer gnus-article-buffer)
4957     (or n
4958         (setq n (if (= parts 1)
4959                     1
4960                   (read-number (format "Jump to part (1..%s): " parts)))))
4961     (unless (and (integerp n) (<= n parts) (>= n 1))
4962       (setq n
4963             (progn
4964               (gnus-message 7 "Invalid part `%s', using %s instead."
4965                             n parts)
4966               parts)))
4967     (gnus-message 9 "Jumping to part %s." n)
4968     (cond ((>= gnus-auto-select-part 1)
4969            (while (and (<= n parts)
4970                        (not (gnus-article-goto-part n)))
4971              (setq n (1+ n))))
4972           ((< gnus-auto-select-part 0)
4973            (while (and (>= n 1)
4974                        (not (gnus-article-goto-part n)))
4975              (setq n (1- n))))
4976           (t
4977            (gnus-article-goto-part n)))))
4978
4979 (defvar gnus-mime-buttonized-part-id nil
4980   "ID of a mime part that should be buttonized.
4981 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4982
4983 (eval-when-compile
4984   (defsubst gnus-article-edit-part (handles &optional current-id)
4985     "Edit an article in order to delete a mime part.
4986 This function is exclusively used by `gnus-mime-save-part-and-strip'
4987 and `gnus-mime-delete-part', and not provided at run-time normally."
4988     (gnus-article-edit-article
4989      `(lambda ()
4990         (buffer-disable-undo)
4991         (erase-buffer)
4992         (let ((mail-parse-charset (or gnus-article-charset
4993                                       ',gnus-newsgroup-charset))
4994               (mail-parse-ignored-charsets
4995                (or gnus-article-ignored-charsets
4996                    ',gnus-newsgroup-ignored-charsets))
4997               (mbl mml-buffer-list))
4998           (setq mml-buffer-list nil)
4999           (insert-buffer-substring gnus-original-article-buffer)
5000           (mime-to-mml ',handles)
5001           (setq gnus-article-mime-handles nil)
5002           (let ((mbl1 mml-buffer-list))
5003             (setq mml-buffer-list mbl)
5004             (set (make-local-variable 'mml-buffer-list) mbl1))
5005           (gnus-make-local-hook 'kill-buffer-hook)
5006           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5007      `(lambda (no-highlight)
5008         (let ((mail-parse-charset (or gnus-article-charset
5009                                       ',gnus-newsgroup-charset))
5010               (message-options message-options)
5011               (message-options-set-recipient)
5012               (mail-parse-ignored-charsets
5013                (or gnus-article-ignored-charsets
5014                    ',gnus-newsgroup-ignored-charsets)))
5015           (mml-to-mime)
5016           (mml-destroy-buffers)
5017           (remove-hook 'kill-buffer-hook
5018                        'mml-destroy-buffers t)
5019           (kill-local-variable 'mml-buffer-list))
5020         (gnus-summary-edit-article-done
5021          ,(or (mail-header-references gnus-current-headers) "")
5022          ,(gnus-group-read-only-p)
5023          ,gnus-summary-buffer no-highlight))
5024      t)
5025     ;; Force buttonizing this part.
5026     (let ((gnus-mime-buttonized-part-id current-id))
5027       (gnus-article-edit-done))
5028     (gnus-configure-windows 'article)
5029     (when (and current-id (integerp gnus-auto-select-part))
5030       (gnus-article-jump-to-part
5031        (min (max (+ current-id gnus-auto-select-part) 1)
5032             (with-current-buffer gnus-article-buffer
5033               (length gnus-article-mime-handle-alist)))))))
5034
5035 (defun gnus-mime-replace-part (file)
5036   "Replace MIME part under point with an external body."
5037   ;; Useful if file has already been saved to disk
5038   (interactive
5039    (list
5040     (read-file-name "Replace MIME part with file: "
5041                     (or mm-default-directory default-directory)
5042                     nil nil)))
5043   (gnus-mime-save-part-and-strip file))
5044
5045 (defun gnus-mime-save-part-and-strip (&optional file)
5046   "Save the MIME part under point then replace it with an external body.
5047 If FILE is given, use it for the external part."
5048   (interactive)
5049   (gnus-article-check-buffer)
5050   (when (gnus-group-read-only-p)
5051     (error "The current group does not support deleting of parts"))
5052   (when (mm-complicated-handles gnus-article-mime-handles)
5053     (error "\
5054 The current article has a complicated MIME structure, giving up..."))
5055   (let* ((data (get-text-property (point) 'gnus-data))
5056          (id (get-text-property (point) 'gnus-part))
5057          param
5058          (handles gnus-article-mime-handles))
5059     (unless file
5060       (setq file
5061             (and data (mm-save-part data "Delete MIME part and save to: "))))
5062     (when file
5063       (with-current-buffer (mm-handle-buffer data)
5064         (erase-buffer)
5065         (insert "Content-Type: " (mm-handle-media-type data))
5066         (mml-insert-parameter-string (cdr (mm-handle-type data))
5067                                      '(charset))
5068         ;; Add a filename for the sake of saving the part again.
5069         (mml-insert-parameter
5070          (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5071         (insert "\n")
5072         (insert "Content-ID: " (message-make-message-id) "\n")
5073         (insert "Content-Transfer-Encoding: binary\n")
5074         (insert "\n"))
5075       (setcdr data
5076               (cdr (mm-make-handle nil
5077                                    `("message/external-body"
5078                                      (access-type . "LOCAL-FILE")
5079                                      (name . ,file)))))
5080       ;; (set-buffer gnus-summary-buffer)
5081       (gnus-article-edit-part handles id))))
5082
5083 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5084 ;; parts...>') but with stripping would be nice.
5085
5086 (defun gnus-mime-delete-part ()
5087   "Delete the MIME part under point.
5088 Replace it with some information about the removed part."
5089   (interactive)
5090   (gnus-article-check-buffer)
5091   (when (gnus-group-read-only-p)
5092     (error "The current group does not support deleting of parts"))
5093   (when (mm-complicated-handles gnus-article-mime-handles)
5094     (error "\
5095 The current article has a complicated MIME structure, giving up..."))
5096   (when (or gnus-expert-user
5097             (gnus-yes-or-no-p "\
5098 Deleting parts may malfunction or destroy the article; continue? "))
5099     (let* ((data (get-text-property (point) 'gnus-data))
5100            (id (get-text-property (point) 'gnus-part))
5101            (handles gnus-article-mime-handles)
5102            (description
5103             (let ((desc (mm-handle-description data)))
5104               (when desc
5105                 (mail-decode-encoded-word-string desc))))
5106            (filename (or (mm-handle-filename data) "(none)"))
5107            (type (mm-handle-media-type data)))
5108       (unless data
5109         (error "No MIME part under point"))
5110       (with-current-buffer (mm-handle-buffer data)
5111         (let ((bsize (buffer-size)))
5112           (erase-buffer)
5113           (insert
5114            (concat
5115             ",----\n"
5116             "| The following attachment has been deleted:\n"
5117             "|\n"
5118             "| Type:           " type "\n"
5119             "| Filename:       " filename "\n"
5120             "| Size (encoded): " (format "%s byte%s\n"
5121                                          bsize (if (= bsize 1)
5122                                                    ""
5123                                                  "s"))
5124             (when description
5125               (concat    "| Description:    " description "\n"))
5126             "`----\n"))
5127           (setcdr data
5128                   (cdr (mm-make-handle
5129                         nil `("text/plain" (charset . gnus-decoded)) nil nil
5130                         (list "attachment")
5131                         (format "Deleted attachment (%s bytes)" bsize))))))
5132       ;; (set-buffer gnus-summary-buffer)
5133       (gnus-article-edit-part handles id))))
5134
5135 (defun gnus-mime-save-part ()
5136   "Save the MIME part under point."
5137   (interactive)
5138   (gnus-article-check-buffer)
5139   (let ((data (get-text-property (point) 'gnus-data)))
5140     (when data
5141       (mm-save-part data))))
5142
5143 (defun gnus-mime-pipe-part (&optional cmd)
5144   "Pipe the MIME part under point to a process.
5145 Use CMD as the process."
5146   (interactive)
5147   (gnus-article-check-buffer)
5148   (let ((data (get-text-property (point) 'gnus-data)))
5149     (when data
5150       (mm-pipe-part data cmd))))
5151
5152 (defun gnus-mime-view-part ()
5153   "Interactively choose a viewing method for the MIME part under point."
5154   (interactive)
5155   (gnus-article-check-buffer)
5156   (let ((data (get-text-property (point) 'gnus-data)))
5157     (when data
5158       (setq gnus-article-mime-handles
5159             (mm-merge-handles
5160              gnus-article-mime-handles (setq data (copy-sequence data))))
5161       (mm-interactively-view-part data))))
5162
5163 (defun gnus-mime-view-part-as-type-internal ()
5164   (gnus-article-check-buffer)
5165   (let* ((handle (get-text-property (point) 'gnus-data))
5166          (name (or
5167                 ;; Content-Type: foo/bar; name=...
5168                 (mail-content-type-get (mm-handle-type handle) 'name)
5169                 ;; Content-Disposition: attachment; filename=...
5170                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5171          (def-type (and name (mm-default-file-encoding name))))
5172     (or (and def-type (cons def-type 0))
5173         (and handle
5174              (equal (mm-handle-media-supertype handle) "text")
5175              '("text/plain" . 0))
5176         '("application/octet-stream" . 0))))
5177
5178 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5179   "Choose a MIME media type, and view the part as such.
5180 If non-nil, PRED is a predicate to use during completion to limit the
5181 available media-types."
5182   (interactive)
5183   (unless mime-type
5184     (setq mime-type
5185           (let ((default (gnus-mime-view-part-as-type-internal)))
5186             (gnus-completing-read
5187              "View as MIME type"
5188              (if pred
5189                  (gnus-remove-if-not pred (mailcap-mime-types))
5190                (mailcap-mime-types))
5191              nil nil nil
5192              (car default)))))
5193   (gnus-article-check-buffer)
5194   (let ((handle (get-text-property (point) 'gnus-data)))
5195     (when handle
5196       (when (equal (mm-handle-media-type handle) "message/external-body")
5197         (unless (mm-handle-cache handle)
5198           (mm-extern-cache-contents handle))
5199         (setq handle (mm-handle-cache handle)))
5200       (setq handle
5201             (mm-make-handle (mm-handle-buffer handle)
5202                             (cons mime-type (cdr (mm-handle-type handle)))
5203                             (mm-handle-encoding handle)
5204                             (mm-handle-undisplayer handle)
5205                             (mm-handle-disposition handle)
5206                             (mm-handle-description handle)
5207                             nil
5208                             (mm-handle-id handle)))
5209       (setq gnus-article-mime-handles
5210             (mm-merge-handles gnus-article-mime-handles handle))
5211       (when (mm-handle-displayed-p handle)
5212         (mm-remove-part handle))
5213       (gnus-mm-display-part handle))))
5214
5215 (defun gnus-mime-copy-part (&optional handle arg)
5216   "Put the MIME part under point into a new buffer.
5217 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5218 are decompressed."
5219   (interactive (list nil current-prefix-arg))
5220   (gnus-article-check-buffer)
5221   (unless handle
5222     (setq handle (get-text-property (point) 'gnus-data)))
5223   (when handle
5224     (let ((filename (mm-handle-filename handle))
5225           contents dont-decode charset coding-system)
5226       (mm-with-unibyte-buffer
5227         (mm-insert-part handle)
5228         (setq contents (or (condition-case nil
5229                                (mm-decompress-buffer filename nil 'sig)
5230                              (error
5231                               (setq dont-decode t)
5232                               nil))
5233                            (buffer-string))))
5234       (setq filename (cond (filename (file-name-nondirectory filename))
5235                            (dont-decode "*raw data*")
5236                            (t "*decoded*")))
5237       (cond
5238        (dont-decode)
5239        ((not arg)
5240         (unless (setq charset (mail-content-type-get
5241                                (mm-handle-type handle) 'charset))
5242           (unless (setq coding-system (mm-with-unibyte-buffer
5243                                         (insert contents)
5244                                         (mm-find-buffer-file-coding-system)))
5245             (setq charset gnus-newsgroup-charset))))
5246        ((numberp arg)
5247         (setq charset (or (cdr (assq arg
5248                                      gnus-summary-show-article-charset-alist))
5249                           (mm-read-coding-system "Charset: ")))))
5250       (switch-to-buffer (generate-new-buffer filename))
5251       (if (or coding-system
5252               (and charset
5253                    (setq coding-system (mm-charset-to-coding-system
5254                                         charset nil t))
5255                    (not (eq coding-system 'ascii))))
5256           (progn
5257             (mm-enable-multibyte)
5258             (insert (mm-decode-coding-string contents coding-system))
5259             (setq buffer-file-coding-system
5260                   (if (boundp 'last-coding-system-used)
5261                       (symbol-value 'last-coding-system-used)
5262                     coding-system)))
5263         (mm-disable-multibyte)
5264         (insert contents)
5265         (setq buffer-file-coding-system mm-binary-coding-system))
5266       ;; We do it this way to make `normal-mode' set the appropriate mode.
5267       (unwind-protect
5268           (progn
5269             (setq buffer-file-name (expand-file-name filename))
5270             (normal-mode))
5271         (setq buffer-file-name nil))
5272       (goto-char (point-min)))))
5273
5274 (defun gnus-mime-print-part (&optional handle filename)
5275   "Print the MIME part under point."
5276   (interactive (list nil (ps-print-preprint current-prefix-arg)))
5277   (gnus-article-check-buffer)
5278   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5279          (contents (and handle (mm-get-part handle)))
5280          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5281          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5282     (when contents
5283         (if printer
5284             (unwind-protect
5285                 (progn
5286                   (mm-save-part-to-file handle file)
5287                   (call-process shell-file-name nil
5288                                 (generate-new-buffer " *mm*")
5289                                 nil
5290                                 shell-command-switch
5291                                 (mm-mailcap-command
5292                                  printer file (mm-handle-type handle))))
5293               (delete-file file))
5294           (with-temp-buffer
5295             (insert contents)
5296             (gnus-print-buffer))
5297           (ps-despool filename)))))
5298
5299 (defun gnus-mime-inline-part (&optional handle arg)
5300   "Insert the MIME part under point into the current buffer.
5301 Compressed files like .gz and .bz2 are decompressed."
5302   (interactive (list nil current-prefix-arg))
5303   (gnus-article-check-buffer)
5304   (let* ((inhibit-read-only t)
5305          (b (point))
5306          (btn ;; position where the MIME button exists
5307           (if handle
5308               (if (eq handle (get-text-property b 'gnus-data))
5309                   b
5310                 (article-goto-body)
5311                 (or (text-property-any (point) (point-max) 'gnus-data handle)
5312                     (text-property-any (point-min) (point) 'gnus-data handle)))
5313             (setq handle (get-text-property b 'gnus-data))
5314             b))
5315          start contents charset coding-system)
5316     (when handle
5317       (when (= b (prog1
5318                      btn
5319                    (setq start (next-single-property-change btn 'gnus-data
5320                                                             nil (point-max))
5321                          btn (previous-single-property-change start
5322                                                               'gnus-data))))
5323         (setq b btn))
5324       (if (and (not arg) (mm-handle-undisplayer handle))
5325           (mm-remove-part handle)
5326         (mm-with-unibyte-buffer
5327           (mm-insert-part handle)
5328           (setq contents
5329                 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5330                     (buffer-string))))
5331         (cond
5332          ((not arg)
5333           (unless (setq charset (mail-content-type-get
5334                                  (mm-handle-type handle) 'charset))
5335             (unless (setq coding-system
5336                           (mm-with-unibyte-buffer
5337                             (insert contents)
5338                             (mm-find-buffer-file-coding-system)))
5339               (setq charset gnus-newsgroup-charset))))
5340          ((numberp arg)
5341           (if (mm-handle-undisplayer handle)
5342               (mm-remove-part handle))
5343           (setq charset
5344                 (or (cdr (assq arg
5345                                gnus-summary-show-article-charset-alist))
5346                     (mm-read-coding-system "Charset: "))))
5347          ((mm-handle-undisplayer handle)
5348           (mm-remove-part handle)))
5349         (goto-char start)
5350         (unless (bolp)
5351           ;; This is a header button.
5352           (forward-line 1))
5353         (mm-display-inline handle))
5354       ;; Toggle the button appearance between `[button]...' and `[button]'.
5355       (goto-char btn)
5356       (let ((displayed-p (mm-handle-displayed-p handle)))
5357         (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5358                                  (list displayed-p))
5359         (if (featurep 'emacs)
5360             (delete-region
5361              (point)
5362              (next-single-property-change (point) 'gnus-data nil (point-max)))
5363           (let* ((end (next-single-property-change (point) 'gnus-data))
5364                  (annots (annotations-at (or end (point-max)))))
5365             (delete-region (point)
5366                            (if end
5367                                (if annots (1+ end) end)
5368                              (point-max)))
5369             (dolist (annot annots)
5370               (set-extent-endpoints annot (point) (point)))))
5371         (setq start (point))
5372         (if (search-backward "\n\n" nil t)
5373             (progn
5374               (goto-char start)
5375               (unless (or displayed-p (eolp))
5376                 ;; Add extra newline.
5377                 (insert (propertize (buffer-substring (1- start) start)
5378                                     'gnus-undeletable t))))
5379           ;; We're in the article header.
5380           (delete-char -1)
5381           (dolist (ovl (gnus-overlays-in btn (point)))
5382             (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5383             (gnus-overlay-put ovl 'face nil))
5384           (save-restriction
5385             (message-narrow-to-field)
5386             (let ((gnus-treatment-function-alist
5387                    '((gnus-treat-highlight-headers
5388                       gnus-article-highlight-headers))))
5389               (gnus-treat-article 'head)))))
5390       (goto-char b))))
5391
5392 (defun gnus-mime-set-charset-parameters (handle charset)
5393   "Set CHARSET to parameters in HANDLE.
5394 CHARSET may either be a string or a symbol."
5395   (unless (stringp charset)
5396     (setq charset (symbol-name charset)))
5397   (if (stringp (car handle))
5398       (dolist (h (cdr handle))
5399         (gnus-mime-set-charset-parameters h charset))
5400     (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5401                                             "message/external-body")
5402                                      (progn
5403                                        (unless (mm-handle-cache handle)
5404                                          (mm-extern-cache-contents handle))
5405                                        (mm-handle-cache handle))
5406                                    handle)))
5407            (param (assq 'charset (cdr type))))
5408       (if param
5409           (setcdr param charset)
5410         (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5411
5412 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5413   "Insert the MIME part under point into the current buffer using the
5414 specified charset."
5415   (interactive (list nil current-prefix-arg))
5416   (gnus-article-check-buffer)
5417   (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5418         (fun (get-text-property (point) 'gnus-callback))
5419         (gnus-newsgroup-ignored-charsets 'gnus-all)
5420         charset form preferred parts)
5421     (when handle
5422       (when (prog1
5423                 (and fun
5424                      (setq charset
5425                            (or (cdr (assq
5426                                      arg
5427                                      gnus-summary-show-article-charset-alist))
5428                                (mm-read-coding-system "Charset: "))))
5429               (if (mm-handle-undisplayer handle)
5430                   (mm-remove-part handle)))
5431         (gnus-mime-set-charset-parameters handle charset)
5432         (when (and (consp (setq form (cdr-safe fun)))
5433                    (setq form (ignore-errors
5434                                 (assq 'gnus-mime-display-alternative form)))
5435                    (setq preferred (caddr form))
5436                    (progn
5437                      (when (eq (car preferred) 'quote)
5438                        (setq preferred (cadr preferred)))
5439                      (not (equal preferred
5440                                  (get-text-property (point) 'gnus-data))))
5441                    (setq parts (get-text-property (point) 'gnus-part))
5442                    (setq parts (cdr (assq parts
5443                                           gnus-article-mime-handle-alist)))
5444                    (equal (mm-handle-media-type parts) "multipart/alternative")
5445                    (setq parts (reverse (cdr parts))))
5446           (setcar (cddr form)
5447                   (list 'quote (or (cadr (member preferred parts))
5448                                    (car parts)))))
5449         (funcall fun handle)))))
5450
5451 (defun gnus-mime-view-part-externally (&optional handle)
5452   "View the MIME part under point with an external viewer."
5453   (interactive)
5454   (gnus-article-check-buffer)
5455   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5456          (mm-user-display-methods nil)
5457          (mm-inlined-types nil)
5458          (mail-parse-charset gnus-newsgroup-charset)
5459          (mail-parse-ignored-charsets
5460           (with-current-buffer gnus-summary-buffer
5461             gnus-newsgroup-ignored-charsets))
5462          (type (mm-handle-media-type handle))
5463          (method (mailcap-mime-info type))
5464          (mm-enable-external t))
5465     (if (not (stringp method))
5466         (gnus-mime-view-part-as-type
5467          nil (lambda (type) (stringp (mailcap-mime-info type))))
5468       (when handle
5469         (mm-display-part handle nil t)))))
5470
5471 (defun gnus-mime-view-part-internally (&optional handle)
5472   "View the MIME part under point with an internal viewer.
5473 If no internal viewer is available, use an external viewer."
5474   (interactive)
5475   (gnus-article-check-buffer)
5476   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5477          (mm-inlined-types '(".*"))
5478          (mm-inline-large-images t)
5479          (mail-parse-charset gnus-newsgroup-charset)
5480          (mail-parse-ignored-charsets
5481           (with-current-buffer gnus-summary-buffer
5482             gnus-newsgroup-ignored-charsets))
5483          (inhibit-read-only t))
5484     (if (not (mm-inlinable-p handle))
5485         (gnus-mime-view-part-as-type
5486          nil (lambda (type) (mm-inlinable-p handle type)))
5487       (when handle
5488         (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5489
5490 (defun gnus-mime-action-on-part (&optional action)
5491   "Do something with the MIME attachment at \(point\)."
5492   (interactive
5493    (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5494   (gnus-article-check-buffer)
5495   (let ((action-pair (assoc action gnus-mime-action-alist)))
5496     (if action-pair
5497         (funcall (cdr action-pair)))))
5498
5499 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5500   "Call FUNCTION on MIME part N.
5501 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5502 If INTERACTIVE, call FUNCTION interactively."
5503   (let (window frame)
5504     ;; Check whether the article is displayed.
5505     (unless (and (gnus-buffer-live-p gnus-article-buffer)
5506                  (setq window (get-buffer-window gnus-article-buffer t))
5507                  (frame-visible-p (setq frame (window-frame window))))
5508       (error "No article is displayed"))
5509     (with-current-buffer gnus-article-buffer
5510       ;; Check whether the article displays the right contents.
5511       (unless (with-current-buffer gnus-summary-buffer
5512                 (eq gnus-current-article (gnus-summary-article-number)))
5513         (error "You should select the right article first"))
5514       (if n
5515           (setq n (prefix-numeric-value n))
5516         (let ((pt (point)))
5517           (setq n (or (get-text-property pt 'gnus-part)
5518                       (and (not (bobp))
5519                            (get-text-property (1- pt) 'gnus-part))
5520                       (get-text-property (prog2
5521                                              (forward-line 1)
5522                                              (point)
5523                                            (goto-char pt))
5524                                          'gnus-part)
5525                       (get-text-property
5526                        (or (and (setq pt (previous-single-property-change
5527                                           pt 'gnus-part))
5528                                 (1- pt))
5529                            (next-single-property-change (point) 'gnus-part)
5530                            (point))
5531                        'gnus-part)
5532                       1))))
5533       ;; Check whether the specified part exists.
5534       (when (> n (length gnus-article-mime-handle-alist))
5535         (error "No such part")))
5536     (unless
5537         (progn
5538           ;; To select the window is needed so that the cursor
5539           ;; might be visible on the MIME button.
5540           (select-window (prog1
5541                              window
5542                            (setq window (selected-window))
5543                            ;; Article may be displayed in the other frame.
5544                            (gnus-select-frame-set-input-focus
5545                             (prog1
5546                                 frame
5547                               (setq frame (selected-frame))))))
5548           (when (gnus-article-goto-part n)
5549             ;; We point the cursor and the arrow at the MIME button
5550             ;; when the `function' prompt the user for something.
5551             (unless (and (pos-visible-in-window-p)
5552                          (> (count-lines (point) (window-end))
5553                             (/ (1- (window-height)) 3)))
5554               (recenter (/ (1- (window-height)) 3)))
5555             (let ((cursor-in-non-selected-windows t)
5556                   (overlay-arrow-string "=>")
5557                   (overlay-arrow-position (point-marker)))
5558               (unwind-protect
5559                   (cond
5560                    ((and no-handle interactive)
5561                     (call-interactively function))
5562                    (no-handle
5563                     (funcall function))
5564                    (interactive
5565                     (call-interactively
5566                      function (get-text-property (point) 'gnus-data)))
5567                    (t
5568                     (funcall function
5569                              (get-text-property (point) 'gnus-data))))
5570                 (set-marker overlay-arrow-position nil)
5571                 (unless gnus-auto-select-part
5572                   (gnus-select-frame-set-input-focus frame)
5573                   (select-window window))))
5574             t))
5575       (if gnus-inhibit-mime-unbuttonizing
5576           ;; This is the default though the program shouldn't reach here.
5577           (error "No such part")
5578         ;; The part which doesn't have the MIME button is selected.
5579         ;; So, we display all the buttons and redo it.
5580         (let ((gnus-inhibit-mime-unbuttonizing t))
5581           (gnus-summary-show-article)
5582           (gnus-article-part-wrapper n function no-handle))))))
5583
5584 (defun gnus-article-pipe-part (n)
5585   "Pipe MIME part N, which is the numerical prefix."
5586   (interactive "P")
5587   (gnus-article-part-wrapper n 'mm-pipe-part))
5588
5589 (defun gnus-article-save-part (n)
5590   "Save MIME part N, which is the numerical prefix."
5591   (interactive "P")
5592   (gnus-article-part-wrapper n 'mm-save-part))
5593
5594 (defun gnus-article-interactively-view-part (n)
5595   "View MIME part N interactively, which is the numerical prefix."
5596   (interactive "P")
5597   (gnus-article-part-wrapper n 'mm-interactively-view-part))
5598
5599 (defun gnus-article-copy-part (n)
5600   "Copy MIME part N, which is the numerical prefix."
5601   (interactive "P")
5602   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5603
5604 (defun gnus-article-view-part-as-charset (n)
5605   "View MIME part N using a specified charset.
5606 N is the numerical prefix."
5607   (interactive "P")
5608   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5609
5610 (defun gnus-article-view-part-externally (n)
5611   "View MIME part N externally, which is the numerical prefix."
5612   (interactive "P")
5613   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5614
5615 (defun gnus-article-inline-part (n)
5616   "Inline MIME part N, which is the numerical prefix."
5617   (interactive "P")
5618   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5619
5620 (defun gnus-article-save-part-and-strip (n)
5621   "Save MIME part N and replace it with an external body.
5622 N is the numerical prefix."
5623   (interactive "P")
5624   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5625
5626 (defun gnus-article-replace-part (n)
5627   "Replace MIME part N with an external body.
5628 N is the numerical prefix."
5629   (interactive "P")
5630   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5631
5632 (defun gnus-article-delete-part (n)
5633   "Delete MIME part N and add some information about the removed part.
5634 N is the numerical prefix."
5635   (interactive "P")
5636   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5637
5638 (defun gnus-article-view-part-as-type (n)
5639   "Choose a MIME media type, and view part N as such.
5640 N is the numerical prefix."
5641   (interactive "P")
5642   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5643
5644 (defun gnus-article-mime-match-handle-first (condition)
5645   (if condition
5646       (let (n)
5647         (dolist (ihandle gnus-article-mime-handle-alist)
5648           (if (and (cond
5649                     ((functionp condition)
5650                      (funcall condition (cdr ihandle)))
5651                     ((eq condition 'undisplayed)
5652                      (not (or (mm-handle-undisplayer (cdr ihandle))
5653                               (equal (mm-handle-media-type (cdr ihandle))
5654                                      "multipart/alternative"))))
5655                     ((eq condition 'undisplayed-alternative)
5656                      (not (mm-handle-undisplayer (cdr ihandle))))
5657                     (t t))
5658                    (gnus-article-goto-part (car ihandle))
5659                    (or (not n) (< (car ihandle) n)))
5660               (setq n (car ihandle))))
5661         (or n 1))
5662     1))
5663
5664 (defun gnus-article-view-part (&optional n)
5665   "View MIME part N, which is the numerical prefix.
5666 If the part is already shown, hide the part.  If N is nil, view
5667 all parts."
5668   (interactive "P")
5669   (with-current-buffer gnus-article-buffer
5670     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5671                              gnus-article-mime-match-handle-function)))
5672     (when (> n (length gnus-article-mime-handle-alist))
5673       (error "No such part"))
5674     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5675       (when (gnus-article-goto-part n)
5676         (if (equal (car handle) "multipart/alternative")
5677             (progn
5678               (beginning-of-line) ;; Make it toggle subparts
5679               (gnus-article-press-button))
5680           (when (eq (gnus-mm-display-part handle) 'internal)
5681             (gnus-set-window-start)))))))
5682
5683 (defsubst gnus-article-mime-total-parts ()
5684   (if (bufferp (car gnus-article-mime-handles))
5685       1 ;; single part
5686     (1- (length gnus-article-mime-handles))))
5687
5688 (defun gnus-mm-display-part (handle)
5689   "Display HANDLE and fix MIME button."
5690   (let ((id (get-text-property (point) 'gnus-part))
5691         (point (point))
5692         (inhibit-read-only t)
5693         (window (selected-window))
5694         (mail-parse-charset gnus-newsgroup-charset)
5695         (mail-parse-ignored-charsets
5696          (if (gnus-buffer-live-p gnus-summary-buffer)
5697              (with-current-buffer gnus-summary-buffer
5698                gnus-newsgroup-ignored-charsets)
5699            nil))
5700         start retval)
5701     (unwind-protect
5702         (progn
5703           (let ((win (gnus-get-buffer-window (current-buffer) t)))
5704             (when win
5705               (select-window win)
5706               (goto-char point)))
5707           (setq start (next-single-property-change point 'gnus-data
5708                                                    nil (point-max))
5709                 point (previous-single-property-change start 'gnus-data))
5710           (if (mm-handle-displayed-p handle)
5711               ;; This will remove the part.
5712               (setq retval (mm-display-part handle))
5713             (let ((part (or (and (mm-inlinable-p handle)
5714                                  (mm-inlined-p handle)
5715                                  t)
5716                             (with-temp-buffer
5717                               (gnus-bind-safe-url-regexp
5718                                (setq retval (mm-display-part handle)))
5719                               (unless (zerop (buffer-size))
5720                                 (buffer-string))))))
5721               (goto-char start)
5722               (unless (bolp)
5723                 ;; This is a header button.
5724                 (forward-line 1))
5725               (cond ((stringp part)
5726                      (save-restriction
5727                        (narrow-to-region (point)
5728                                          (progn
5729                                            (insert part)
5730                                            (unless (bolp) (insert "\n"))
5731                                            (point)))
5732                        (gnus-treat-article nil id
5733                                            (gnus-article-mime-total-parts)
5734                                            (mm-handle-media-type handle))
5735                        (mm-handle-set-undisplayer
5736                         handle
5737                         `(lambda ()
5738                            (let ((inhibit-read-only t))
5739                              (delete-region ,(copy-marker (point-min) t)
5740                                             ,(copy-marker (point-max) t)))))))
5741                     (part
5742                      (mm-display-inline handle))))))
5743       (goto-char point)
5744       ;; Toggle the button appearance between `[button]...' and `[button]'.
5745       (let ((displayed-p (mm-handle-displayed-p handle)))
5746         (gnus-insert-mime-button handle id (list displayed-p))
5747         (if (featurep 'emacs)
5748             (delete-region
5749              (point)
5750              (next-single-property-change (point) 'gnus-data nil (point-max)))
5751           (let* ((end (next-single-property-change (point) 'gnus-data))
5752                  (annots (annotations-at (or end (point-max)))))
5753             (delete-region (point)
5754                            (if end
5755                                (if annots (1+ end) end)
5756                              (point-max)))
5757             (dolist (annot annots)
5758               (set-extent-endpoints annot (point) (point)))))
5759         (setq start (point))
5760         (if (search-backward "\n\n" nil t)
5761             (progn
5762               (goto-char start)
5763               (unless (or displayed-p (eolp))
5764                 ;; Add extra newline.
5765                 (insert (propertize (buffer-substring (1- start) start)
5766                                     'gnus-undeletable t))))
5767           ;; We're in the article header.
5768           (delete-char -1)
5769           (dolist (ovl (gnus-overlays-in point (point)))
5770             (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5771             (gnus-overlay-put ovl 'face nil))
5772           (save-restriction
5773             (message-narrow-to-field)
5774             (let ((gnus-treatment-function-alist
5775                    '((gnus-treat-highlight-headers
5776                       gnus-article-highlight-headers))))
5777               (gnus-treat-article 'head)))))
5778       (goto-char point)
5779       (if (window-live-p window)
5780           (select-window window)))
5781     retval))
5782
5783 (defun gnus-article-goto-part (n)
5784   "Go to MIME part N."
5785   (when gnus-break-pages
5786     (widen))
5787   (article-goto-body)
5788   (prog1
5789       (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5790                        ;; There may be header buttons.
5791                        (text-property-any (point-min) (point) 'gnus-part n)))
5792             part handle end next handles)
5793         (when start
5794           (goto-char start)
5795           (if (setq handle (get-text-property start 'gnus-data))
5796               start
5797             ;; Go to the displayed subpart, assuming this is
5798             ;; multipart/alternative.
5799             (setq part start
5800                   end (point-at-eol))
5801             (while (and (not handle)
5802                         part
5803                         (< part end)
5804                         (setq next (text-property-not-all part end
5805                                                           'gnus-data nil)))
5806               (setq part next
5807                     handle (get-text-property part 'gnus-data))
5808               (push (cons handle part) handles)
5809               (unless (mm-handle-displayed-p handle)
5810                 (setq handle nil
5811                       part (text-property-any part end 'gnus-data nil))))
5812             (unless handle
5813               ;; No subpart is displayed, so we find preferred one.
5814               (setq part
5815                     (cdr (assq (mm-preferred-alternative
5816                                 (nreverse (mapcar 'car handles)))
5817                                handles))))
5818             (if part
5819                 (goto-char (1+ part))
5820               start))))
5821     (when gnus-break-pages
5822       (gnus-narrow-to-page))))
5823
5824 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5825   (let ((gnus-tmp-name
5826          (or (mm-handle-filename handle)
5827              (mail-content-type-get (mm-handle-type handle) 'url)
5828              ""))
5829         (gnus-tmp-type (mm-handle-media-type handle))
5830         (gnus-tmp-description (or (mm-handle-description handle) ""))
5831         (gnus-tmp-dots
5832          (if (if displayed (car displayed)
5833                (mm-handle-displayed-p handle))
5834              "" "..."))
5835         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5836                            (buffer-size)))
5837         gnus-tmp-type-long b e)
5838     (when (string-match ".*/" gnus-tmp-name)
5839       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5840     (setq gnus-tmp-type-long (concat gnus-tmp-type
5841                                      (and (not (equal gnus-tmp-name ""))
5842                                           (concat "; " gnus-tmp-name))))
5843     (unless (equal gnus-tmp-description "")
5844       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5845     (setq b (point))
5846     (gnus-eval-format
5847      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5848      `(keymap ,gnus-mime-button-map
5849               gnus-callback gnus-mm-display-part
5850               gnus-part ,gnus-tmp-id
5851               article-type annotation
5852               gnus-data ,handle
5853               rear-nonsticky t))
5854     (setq e (if (bolp)
5855                 ;; Exclude a newline.
5856                 (1- (point))
5857               (point)))
5858     (when gnus-article-button-face
5859       (gnus-overlay-put (gnus-make-overlay b e nil t)
5860                         'face gnus-article-button-face))
5861     (widget-convert-button
5862      'link b e
5863      :mime-handle handle
5864      :action 'gnus-widget-press-button
5865      :button-keymap gnus-mime-button-map
5866      :help-echo
5867      (lambda (widget)
5868        ;; Needed to properly clear the message due to a bug in
5869        ;; wid-edit (XEmacs only).
5870        (if (boundp 'help-echo-owns-message)
5871            (setq help-echo-owns-message t))
5872        (format
5873         "%S: %s the MIME part; %S: more options"
5874         (aref gnus-mouse-2 0)
5875         (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5876             "hide" "show")
5877         (aref gnus-down-mouse-3 0))))))
5878
5879 (defun gnus-widget-press-button (elems el)
5880   (goto-char (widget-get elems :from))
5881   (gnus-article-press-button))
5882
5883 (defvar gnus-displaying-mime nil)
5884
5885 (defun gnus-display-mime (&optional ihandles)
5886   "Display the MIME parts."
5887   (save-excursion
5888     (save-selected-window
5889       (let ((window (get-buffer-window gnus-article-buffer))
5890             (point (point)))
5891         (when window
5892           (select-window window)
5893           ;; We have to do this since selecting the window
5894           ;; may change the point.  So we set the window point.
5895           (set-window-point window point)))
5896       (let ((handles ihandles)
5897             (inhibit-read-only t)
5898             handle)
5899         (cond (handles)
5900               ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5901                (when gnus-article-emulate-mime
5902                  (mm-uu-dissect-text-parts handles)))
5903               (gnus-article-emulate-mime
5904                (setq handles (mm-uu-dissect))))
5905         (when (and (not ihandles)
5906                    (not gnus-displaying-mime))
5907           ;; Top-level call; we clean up.
5908           (when gnus-article-mime-handles
5909             (mm-destroy-parts gnus-article-mime-handles)
5910             (setq gnus-article-mime-handle-alist nil));; A trick.
5911           (setq gnus-article-mime-handles handles)
5912           ;; We allow users to glean info from the handles.
5913           (when gnus-article-mime-part-function
5914             (gnus-mime-part-function handles)))
5915         (if (and handles
5916                  (or (not (stringp (car handles)))
5917                      (cdr handles)))
5918             (progn
5919               (when (and (not ihandles)
5920                          (not gnus-displaying-mime))
5921                 ;; Clean up for mime parts.
5922                 (article-goto-body)
5923                 (delete-region (point) (point-max)))
5924               (let ((gnus-displaying-mime t))
5925                 (gnus-mime-display-part handles)))
5926           (save-restriction
5927             (article-goto-body)
5928             (narrow-to-region (point) (point-max))
5929             (gnus-treat-article nil 1 1 "text/plain")
5930             (widen)))
5931         (unless ihandles
5932           ;; Highlight the headers.
5933           (save-excursion
5934             (save-restriction
5935               (article-goto-body)
5936               (narrow-to-region (point-min) (point))
5937               (gnus-article-save-original-date
5938                (gnus-treat-article 'head)))))))
5939     ;; Cope with broken MIME messages.
5940     (goto-char (point-max))
5941     (unless (bolp)
5942       (insert "\n"))))
5943
5944 (defcustom gnus-mime-display-multipart-as-mixed nil
5945   "Display \"multipart\" parts as  \"multipart/mixed\".
5946
5947 If t, it overrides nil values of
5948 `gnus-mime-display-multipart-alternative-as-mixed' and
5949 `gnus-mime-display-multipart-related-as-mixed'."
5950   :group 'gnus-article-mime
5951   :type 'boolean)
5952
5953 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5954   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
5955   :version "22.1"
5956   :group 'gnus-article-mime
5957   :type 'boolean)
5958
5959 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5960   "Display \"multipart/related\" parts as  \"multipart/mixed\".
5961
5962 If displaying \"text/html\" is discouraged \(see
5963 `mm-discouraged-alternatives'\) images or other material inside a
5964 \"multipart/related\" part might be overlooked when this variable is nil."
5965   :version "22.1"
5966   :group 'gnus-article-mime
5967   :type 'boolean)
5968
5969 (defcustom gnus-mime-display-attachment-buttons-in-header t
5970   "Add attachment buttons in the end of the header of an article.
5971 Since MIME attachments tend to be put at the end of an article, we may
5972 overlook them if there is a huge body.  This option offers you a copy
5973 of all non-inlinable MIME parts as buttons shown in front of an article.
5974 If nil, don't show those extra buttons."
5975   :version "24.5"
5976   :group 'gnus-article-mime
5977   :type 'boolean)
5978
5979 (defun gnus-mime-display-part (handle)
5980   (cond
5981    ;; Maybe a broken MIME message.
5982    ((null handle))
5983    ;; Single part.
5984    ((not (stringp (car handle)))
5985     (gnus-mime-display-single handle))
5986    ;; User-defined multipart
5987    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5988     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5989              handle))
5990    ;; multipart/alternative
5991    ((and (equal (car handle) "multipart/alternative")
5992          (not (or gnus-mime-display-multipart-as-mixed
5993                   gnus-mime-display-multipart-alternative-as-mixed)))
5994     (let ((id (1+ (length gnus-article-mime-handle-alist))))
5995       (push (cons id handle) gnus-article-mime-handle-alist)
5996       (gnus-mime-display-alternative (cdr handle) nil nil id)))
5997    ;; multipart/related
5998    ((and (equal (car handle) "multipart/related")
5999          (not (or gnus-mime-display-multipart-as-mixed
6000                   gnus-mime-display-multipart-related-as-mixed)))
6001     (gnus-mime-display-part (cadr handle)))
6002    ((equal (car handle) "multipart/signed")
6003     (gnus-add-wash-type 'signed)
6004     (gnus-mime-display-security handle))
6005    ((equal (car handle) "multipart/encrypted")
6006     (gnus-add-wash-type 'encrypted)
6007     (gnus-mime-display-security handle))
6008    ;; Other multiparts are handled like multipart/mixed.
6009    (t
6010     (gnus-mime-display-mixed (cdr handle)))))
6011
6012 (defun gnus-mime-part-function (handles)
6013   (if (stringp (car handles))
6014       (mapcar 'gnus-mime-part-function (cdr handles))
6015     (funcall gnus-article-mime-part-function handles)))
6016
6017 (defun gnus-mime-display-mixed (handles)
6018   (mapcar 'gnus-mime-display-part handles))
6019
6020 (defun gnus-mime-display-single (handle)
6021   (let ((type (mm-handle-media-type handle))
6022         (ignored gnus-ignored-mime-types)
6023         (not-attachment t)
6024         display text)
6025     (catch 'ignored
6026       (progn
6027         (while ignored
6028           (when (string-match (pop ignored) type)
6029             (throw 'ignored nil)))
6030         (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6031                                (with-current-buffer gnus-summary-buffer
6032                                  gnus-inhibit-images)
6033                              gnus-inhibit-images)
6034                            (string-match "\\`image/" type)))
6035                  (setq not-attachment
6036                        (and (not (mm-inline-override-p handle))
6037                             (or (not (mm-handle-disposition handle))
6038                                 (equal (car (mm-handle-disposition handle))
6039                                        "inline")
6040                                 (mm-attachment-override-p handle))))
6041                  (mm-automatic-display-p handle)
6042                  (or (and
6043                       (mm-inlinable-p handle)
6044                       (mm-inlined-p handle))
6045                      (mm-automatic-external-display-p type)))
6046             (setq display t)
6047           (when (equal (mm-handle-media-supertype handle) "text")
6048             (setq text t)))
6049         (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6050               beg)
6051           (unless id
6052             (setq id (1+ (length gnus-article-mime-handle-alist)))
6053             (push (cons id handle) gnus-article-mime-handle-alist))
6054           (when (and display
6055                      (equal (mm-handle-media-supertype handle) "message"))
6056             (insert-char
6057              ?\n
6058              (cond ((not (bolp)) 2)
6059                    ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6060                    (t 1))))
6061           (when (or (not display)
6062                     (not (gnus-unbuttonized-mime-type-p type))
6063                     (eq id gnus-mime-buttonized-part-id))
6064             (gnus-insert-mime-button
6065              handle id (list (or display (and not-attachment text)))))
6066           (setq beg (point))
6067           (cond
6068            (display
6069             (let ((mail-parse-charset gnus-newsgroup-charset)
6070                   (mail-parse-ignored-charsets
6071                    (save-excursion (condition-case ()
6072                                        (set-buffer gnus-summary-buffer)
6073                                      (error))
6074                                    gnus-newsgroup-ignored-charsets)))
6075               (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6076            ((and text not-attachment)
6077             (mm-display-inline handle)))
6078           (goto-char (point-max))
6079           (if (string-match "\\`image/" type)
6080               (gnus-article-insert-newline)
6081             (if (prog1
6082                     (= (skip-chars-backward "\n") -1)
6083                   (forward-char 1))
6084                 (gnus-article-insert-newline)
6085               (put-text-property (point) (point-max) 'gnus-undeletable t))
6086             (goto-char (point-max)))
6087           ;; Do highlighting.
6088           (save-excursion
6089             (save-restriction
6090               (narrow-to-region beg (point))
6091               (if (eq handle gnus-article-mime-handles)
6092                   ;; The format=flowed case.
6093                   (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6094                 ;; Don't count signature parts that are never displayed.
6095                 ;; The part number should be re-calculated supposing this
6096                 ;; might be a message/rfc822 part.
6097                 (let (handles)
6098                   (dolist (part gnus-article-mime-handles)
6099                     (unless (or (stringp part)
6100                                 (equal (car (mm-handle-type part))
6101                                        "application/pgp-signature"))
6102                       (push part handles)))
6103                   (gnus-treat-article
6104                    nil (length (memq handle handles)) (length handles)
6105                    (mm-handle-media-type handle)))))))))))
6106
6107 (defun gnus-unbuttonized-mime-type-p (type)
6108   "Say whether TYPE is to be unbuttonized."
6109   (unless gnus-inhibit-mime-unbuttonizing
6110     (when (catch 'found
6111             (let ((types gnus-unbuttonized-mime-types))
6112               (while types
6113                 (when (string-match (pop types) type)
6114                   (throw 'found t)))))
6115       (not (catch 'found
6116              (let ((types gnus-buttonized-mime-types))
6117                (while types
6118                  (when (string-match (pop types) type)
6119                    (throw 'found t)))))))))
6120
6121 (defun gnus-article-insert-newline ()
6122   "Insert a newline, but mark it as undeletable."
6123   (gnus-put-text-property
6124    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6125
6126 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6127   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6128          (ihandles handles)
6129          (point (point))
6130          handle (inhibit-read-only t) from props begend not-pref)
6131     (save-window-excursion
6132       (save-restriction
6133         (when ibegend
6134           (narrow-to-region (car ibegend)
6135                             (or (cdr ibegend)
6136                                 (progn
6137                                   (goto-char (car ibegend))
6138                                   (forward-line 2)
6139                                   (point))))
6140           (delete-region (point-min) (point-max))
6141           (mm-remove-parts handles))
6142         (setq begend (list (point-marker)))
6143         ;; Do the toggle.
6144         (unless (setq not-pref (cadr (member preferred ihandles)))
6145           (setq not-pref (car ihandles)))
6146         (when (or ibegend
6147                   (not preferred)
6148                   (not (gnus-unbuttonized-mime-type-p
6149                         "multipart/alternative")))
6150           (gnus-add-text-properties
6151            (setq from (point))
6152            (progn
6153              (insert (format "%d.  " id))
6154              (point))
6155            `(gnus-callback
6156              (lambda (handles)
6157                (unless ,(not ibegend)
6158                  (setq gnus-article-mime-handle-alist
6159                        ',gnus-article-mime-handle-alist))
6160                (gnus-mime-display-alternative
6161                 ',ihandles ',not-pref ',begend ,id))
6162              keymap ,gnus-mime-button-map
6163              ,gnus-mouse-face-prop ,gnus-article-mouse-face
6164              face ,gnus-article-button-face
6165              gnus-part ,id
6166              article-type multipart
6167              rear-nonsticky t))
6168           (widget-convert-button 'link from (point)
6169                                  :action 'gnus-widget-press-button
6170                                  :button-keymap gnus-widget-button-keymap)
6171           ;; Do the handles
6172           (while (setq handle (pop handles))
6173             (gnus-add-text-properties
6174              (setq from (point))
6175              (progn
6176                (insert (format "(%c) %-18s"
6177                                (if (equal handle preferred) ?* ? )
6178                                (mm-handle-media-type handle)))
6179                (point))
6180              `(gnus-callback
6181                (lambda (handles)
6182                  (unless ,(not ibegend)
6183                    (setq gnus-article-mime-handle-alist
6184                          ',gnus-article-mime-handle-alist))
6185                  (gnus-mime-display-alternative
6186                   ',ihandles ',handle ',begend ,id))
6187                keymap ,gnus-mime-button-map
6188                ,gnus-mouse-face-prop ,gnus-article-mouse-face
6189                face ,gnus-article-button-face
6190                gnus-part ,id
6191                gnus-data ,handle
6192                rear-nonsticky t))
6193             (widget-convert-button 'link from (point)
6194                                    :action 'gnus-widget-press-button
6195                                    :button-keymap gnus-widget-button-keymap)
6196             (insert "  "))
6197           (insert "\n\n"))
6198         (when preferred
6199           (if (stringp (car preferred))
6200               (gnus-display-mime preferred)
6201             (let ((mail-parse-charset gnus-newsgroup-charset)
6202                   (mail-parse-ignored-charsets
6203                    (with-current-buffer gnus-summary-buffer
6204                      gnus-newsgroup-ignored-charsets)))
6205               (gnus-bind-safe-url-regexp (mm-display-part preferred))
6206               ;; Do highlighting.
6207               (save-excursion
6208                 (save-restriction
6209                   (narrow-to-region (car begend) (point-max))
6210                   (gnus-treat-article
6211                    nil (length gnus-article-mime-handle-alist)
6212                    (gnus-article-mime-total-parts)
6213                    (mm-handle-media-type preferred))))))
6214           (goto-char (point-max))
6215           (setcdr begend (point-marker)))))
6216     (when ibegend
6217       (goto-char point)))
6218   ;; Redraw attachment buttons in the header.
6219   (when gnus-mime-display-attachment-buttons-in-header
6220     (gnus-mime-buttonize-attachments-in-header)))
6221
6222 (defconst gnus-article-wash-status-strings
6223   (let ((alist '((cite "c" "Possible hidden citation text"
6224                        " " "All citation text visible")
6225                  (headers "h" "Hidden headers"
6226                           " " "All headers visible.")
6227                  (pgp "p" "Encrypted or signed message status hidden"
6228                       " " "No hidden encryption nor digital signature status")
6229                  (signature "s" "Signature has been hidden"
6230                             " " "Signature is visible")
6231                  (overstrike "o" "Overstrike (^H) characters applied"
6232                              " " "No overstrike characters applied")
6233                  (emphasis "e" "/*_Emphasis_*/ characters applied"
6234                            " " "No /*_emphasis_*/ characters applied")))
6235         result)
6236     (dolist (entry alist result)
6237       (let ((key (nth 0 entry))
6238             (on (copy-sequence (nth 1 entry)))
6239             (on-help (nth 2 entry))
6240             (off (copy-sequence (nth 3 entry)))
6241             (off-help (nth 4 entry)))
6242         (put-text-property 0 1 'help-echo on-help on)
6243         (put-text-property 0 1 'help-echo off-help off)
6244         (push (list key on off) result))))
6245   "Alist of strings describing wash status in the mode line.
6246 Each entry has the form (KEY ON OF), where the KEY is a symbol
6247 representing the particular washing function, ON is the string to use
6248 in the article mode line when the washing function is active, and OFF
6249 is the string to use when it is inactive.")
6250
6251 (defun gnus-article-wash-status-entry (key value)
6252   (let ((entry (assoc key gnus-article-wash-status-strings)))
6253     (if value (nth 1 entry) (nth 2 entry))))
6254
6255 (defun gnus-article-wash-status ()
6256   "Return a string which display status of article washing."
6257   (with-current-buffer gnus-article-buffer
6258     (let ((cite (memq 'cite gnus-article-wash-types))
6259           (headers (memq 'headers gnus-article-wash-types))
6260           (boring (memq 'boring-headers gnus-article-wash-types))
6261           (pgp (memq 'pgp gnus-article-wash-types))
6262           (pem (memq 'pem gnus-article-wash-types))
6263           (signed (memq 'signed gnus-article-wash-types))
6264           (encrypted (memq 'encrypted gnus-article-wash-types))
6265           (signature (memq 'signature gnus-article-wash-types))
6266           (overstrike (memq 'overstrike gnus-article-wash-types))
6267           (emphasis (memq 'emphasis gnus-article-wash-types)))
6268       (concat
6269        (gnus-article-wash-status-entry 'cite cite)
6270        (gnus-article-wash-status-entry 'headers (or headers boring))
6271        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6272        (gnus-article-wash-status-entry 'signature signature)
6273        (gnus-article-wash-status-entry 'overstrike overstrike)
6274        (gnus-article-wash-status-entry 'emphasis emphasis)))))
6275
6276 (defun gnus-add-wash-type (type)
6277   "Add a washing of TYPE to the current status."
6278   (add-to-list 'gnus-article-wash-types type))
6279
6280 (defun gnus-delete-wash-type (type)
6281   "Add a washing of TYPE to the current status."
6282   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6283
6284 (defun gnus-add-image (category image)
6285   "Add IMAGE of CATEGORY to the list of displayed images."
6286   (let ((entry (assq category gnus-article-image-alist)))
6287     (unless entry
6288       (setq entry (list category))
6289       (push entry gnus-article-image-alist))
6290     (nconc entry (list image))))
6291
6292 (defun gnus-delete-images (category)
6293   "Delete all images in CATEGORY."
6294   (let ((entry (assq category gnus-article-image-alist)))
6295     (dolist (image (cdr entry))
6296       (gnus-remove-image image category))
6297     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6298     (gnus-delete-wash-type category)))
6299
6300 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6301
6302 (defun gnus-article-maybe-hide-headers ()
6303   "Hide unwanted headers if `gnus-have-all-headers' is nil.
6304 Provided for backwards compatibility."
6305   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6306                  (not (with-current-buffer gnus-summary-buffer
6307                         gnus-have-all-headers)))
6308              (not gnus-inhibit-hiding))
6309     (gnus-article-hide-headers)))
6310
6311 (declare-function shr-put-image "shr" (data alt &optional flags))
6312
6313 (defun gnus-shr-put-image (data alt &optional flags)
6314   "Put image DATA with a string ALT.  Enable image to be deleted."
6315   (let ((image (if flags
6316                    (shr-put-image data (propertize (or alt "*")
6317                                                    'gnus-image-category 'shr)
6318                                   flags)
6319                  ;; Old `shr-put-image' doesn't take the optional `flags'
6320                  ;; argument.
6321                  (shr-put-image data (propertize (or alt "*")
6322                                                  'gnus-image-category 'shr)))))
6323     (when image
6324       (gnus-add-image 'shr image))))
6325
6326 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6327   "Show attachments as buttons in the end of the header of an article.
6328 This function toggles the display when called interactively.  Note that
6329 buttons to be added to the header are only the ones that aren't inlined
6330 in the body.  Use `gnus-header-face-alist' to highlight buttons."
6331   (interactive (list t))
6332   (gnus-with-article-buffer
6333     (gmm-labels
6334         ;; Function that returns a flattened version of
6335         ;; `gnus-article-mime-handle-alist'.
6336         ((flattened-alist
6337           (&optional alist id all)
6338           (if alist
6339               (let ((i 1) newid flat)
6340                 (dolist (handle alist flat)
6341                   (setq newid (append id (list i))
6342                         i (1+ i))
6343                   (if (stringp (car handle))
6344                       (setq flat (nconc flat (flattened-alist (cdr handle)
6345                                                               newid all)))
6346                     (delq (rassq handle all) all)
6347                     (setq flat (nconc flat (list (cons newid handle)))))))
6348             (let ((flat (list nil)))
6349               ;; Assume that elements of `gnus-article-mime-handle-alist'
6350               ;; are in the decreasing order, but unnumbered subsidiaries
6351               ;; in each element are in the increasing order.
6352               (dolist (handle (reverse gnus-article-mime-handle-alist))
6353                 (if (stringp (cadr handle))
6354                     (setq flat (nconc flat (flattened-alist (cddr handle)
6355                                                             (list (car handle))
6356                                                             flat)))
6357                   (delq (rassq (cdr handle) flat) flat)
6358                   (setq flat (nconc flat (list (cons (list (car handle))
6359                                                      (cdr handle)))))))
6360               (setq flat (cdr flat))
6361               (mapc (lambda (handle)
6362                       (if (cdar handle)
6363                           ;; This is a hidden (i.e. unnumbered) handle.
6364                           (progn
6365                             (setcar handle
6366                                     (1+ (caar gnus-article-mime-handle-alist)))
6367                             (push handle gnus-article-mime-handle-alist))
6368                         (setcar handle (caar handle))))
6369                     flat)
6370               flat))))
6371       (let ((case-fold-search t) buttons st handle)
6372         (save-excursion
6373           (save-restriction
6374             (widen)
6375             (article-narrow-to-head)
6376             ;; Header buttons exist?
6377             (while (and (not buttons)
6378                         (re-search-forward "^attachments?:[\n ]+" nil t))
6379               (when (get-char-property (match-end 0)
6380                                        'gnus-button-attachment-extra)
6381                 (setq buttons (match-beginning 0))))
6382             (widen)
6383             (when buttons
6384               ;; Delete header buttons.
6385               (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6386                                          (match-beginning 0)
6387                                        (point-max))))
6388             (unless (and interactive buttons)
6389               ;; Find buttons.
6390               (setq buttons nil)
6391               (dolist (handle (flattened-alist))
6392                 (when (and (not (stringp (cadr handle)))
6393                            (or (equal (car (mm-handle-disposition
6394                                             (cdr handle)))
6395                                       "attachment")
6396                                (not (and (mm-inlinable-p (cdr handle))
6397                                          (mm-inlined-p (cdr handle))))))
6398                   (push handle buttons)))
6399               (when buttons
6400                 ;; Add header buttons.
6401                 (article-goto-body)
6402                 (forward-line -1)
6403                 (narrow-to-region (point) (point))
6404                 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6405                 (dolist (button (nreverse buttons))
6406                   (setq st (point))
6407                   (insert " ")
6408                   (mm-handle-set-undisplayer
6409                    (setq handle (copy-sequence (cdr button))) nil)
6410                   (gnus-insert-mime-button handle (car button))
6411                   (skip-chars-backward "\t\n ")
6412                   (delete-region (point) (point-max))
6413                   (when (> (current-column) (window-width))
6414                     (goto-char st)
6415                     (insert "\n")
6416                     (end-of-line)))
6417                 (insert "\n")
6418                 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6419                   (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6420                   (gnus-overlay-put ovl 'face nil))
6421                 (let ((gnus-treatment-function-alist
6422                        '((gnus-treat-highlight-headers
6423                           gnus-article-highlight-headers))))
6424                   (gnus-treat-article 'head))))))))))
6425
6426 ;;; Article savers.
6427
6428 (defun gnus-output-to-file (file-name)
6429   "Append the current article to a file named FILE-NAME.
6430 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6431 text and used as the value of the coding cookie which is added to the
6432 top of a file.  Otherwise, this function saves a raw article without
6433 the coding cookie."
6434   (let* ((artbuf (current-buffer))
6435          (file-name-coding-system nnmail-pathname-coding-system)
6436          (coding gnus-article-save-coding-system)
6437          (coding-system-for-read (if coding
6438                                      nil ;; Rely on the coding cookie.
6439                                    mm-text-coding-system))
6440          (coding-system-for-write (or coding
6441                                       mm-text-coding-system-for-write
6442                                       mm-text-coding-system))
6443          (exists (file-exists-p file-name)))
6444     (with-temp-buffer
6445       (when exists
6446         (insert-file-contents file-name)
6447         (goto-char (point-min))
6448         ;; Remove the existing coding cookie.
6449         (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6450           (delete-region (match-beginning 0) (match-end 0))))
6451       (goto-char (point-max))
6452       (insert-buffer-substring artbuf)
6453       ;; Append newline at end of the buffer as separator, and then
6454       ;; save it to file.
6455       (goto-char (point-max))
6456       (insert "\n")
6457       (when coding
6458         ;; If the coding system is not suitable to encode the text,
6459         ;; ask a user for a proper one.
6460         (when (fboundp 'select-safe-coding-system)
6461           (setq coding (coding-system-base
6462                         (save-window-excursion
6463                           (select-safe-coding-system (point-min) (point-max)
6464                                                      coding))))
6465           (setq coding-system-for-write
6466                 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6467                     coding)))
6468         (goto-char (point-min))
6469         ;; Add the coding cookie.
6470         (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6471                         coding-system-for-write)))
6472       (if exists
6473           (progn
6474             (write-region (point-min) (point-max) file-name nil 'no-message)
6475             (message "Appended to %s" file-name))
6476         (write-region (point-min) (point-max) file-name))))
6477   t)
6478
6479 (defun gnus-narrow-to-page (&optional arg)
6480   "Narrow the article buffer to a page.
6481 If given a numerical ARG, move forward ARG pages."
6482   (interactive "P")
6483   (setq arg (if arg (prefix-numeric-value arg) 0))
6484   (with-current-buffer gnus-article-buffer
6485     (widen)
6486     ;; Remove any old next/prev buttons.
6487     (when (gnus-visual-p 'page-marker)
6488       (let ((inhibit-read-only t))
6489         (gnus-remove-text-with-property 'gnus-prev)
6490         (gnus-remove-text-with-property 'gnus-next)))
6491     (let (st nd pt)
6492       (when (save-excursion
6493               (cond ((< arg 0)
6494                      (if (re-search-backward page-delimiter nil 'move (abs arg))
6495                          (prog1
6496                              (setq nd (match-beginning 0)
6497                                    pt nd)
6498                            (when (re-search-backward page-delimiter nil t)
6499                              (setq st (match-end 0))))
6500                        (when (re-search-forward page-delimiter nil t)
6501                          (setq nd (match-beginning 0)
6502                                pt (point-min)))))
6503                     ((> arg 0)
6504                      (if (re-search-forward page-delimiter nil 'move arg)
6505                          (prog1
6506                              (setq st (match-end 0)
6507                                    pt st)
6508                            (when (re-search-forward page-delimiter nil t)
6509                              (setq nd (match-beginning 0))))
6510                        (when (re-search-backward page-delimiter nil t)
6511                          (setq st (match-end 0)
6512                                pt (point-max)))))
6513                     (t
6514                      (when (re-search-backward page-delimiter nil t)
6515                        (goto-char (setq st (match-end 0))))
6516                      (when (re-search-forward page-delimiter nil t)
6517                        (setq nd (match-beginning 0)))
6518                      (or st nd))))
6519         (setq gnus-page-broken t)
6520         (when pt (goto-char pt))
6521         (narrow-to-region (or st (point-min)) (or nd (point-max)))
6522         (when (gnus-visual-p 'page-marker)
6523           (save-excursion
6524             (when nd
6525               (goto-char nd)
6526               (gnus-insert-next-page-button))
6527             (when st
6528               (goto-char st)
6529               (gnus-insert-prev-page-button))))))))
6530
6531 ;; Article mode commands
6532
6533 (defun gnus-article-goto-next-page ()
6534   "Show the next page of the article."
6535   (interactive)
6536   (when (gnus-article-next-page)
6537     (goto-char (point-min))
6538     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6539
6540
6541 (defun gnus-article-goto-prev-page ()
6542   "Show the previous page of the article."
6543   (interactive)
6544   (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6545       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6546     (gnus-article-prev-page nil)))
6547
6548 ;; This is cleaner but currently breaks `gnus-pick-mode':
6549 ;;
6550 ;; (defun gnus-article-goto-next-page ()
6551 ;;   "Show the next page of the article."
6552 ;;   (interactive)
6553 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6554 ;;     (gnus-summary-next-page)))
6555 ;;
6556 ;; (defun gnus-article-goto-prev-page ()
6557 ;;   "Show the next page of the article."
6558 ;;   (interactive)
6559 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6560 ;;     (gnus-summary-prev-page)))
6561
6562 (defun gnus-article-next-page (&optional lines)
6563   "Show the next page of the current article.
6564 If end of article, return non-nil.  Otherwise return nil.
6565 Argument LINES specifies lines to be scrolled up."
6566   (interactive "p")
6567   (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6568   (if (and (not (and gnus-article-over-scroll
6569                      (> (count-lines (window-start) (point-max))
6570                         (if (featurep 'xemacs)
6571                             (or lines (1- (window-height)))
6572                           (+ (or lines (1- (window-height))) scroll-margin)))))
6573            (save-excursion
6574              (end-of-line)
6575              (and (pos-visible-in-window-p)     ;Not continuation line.
6576                   (>= (point) (point-max)))))
6577       ;; Nothing in this page.
6578       (if (or (not gnus-page-broken)
6579               (save-excursion
6580                 (save-restriction
6581                   (widen)
6582                   (forward-line)
6583                   (eobp)))) ;Real end-of-buffer?
6584           (progn
6585             (when gnus-article-over-scroll
6586               (gnus-article-next-page-1 lines))
6587             t)                  ;Nothing more.
6588         (gnus-narrow-to-page 1)         ;Go to next page.
6589         nil)
6590     ;; More in this page.
6591     (gnus-article-next-page-1 lines)
6592     nil))
6593
6594 (defun gnus-article-beginning-of-window ()
6595   "Move point to the beginning of the window.
6596 In Emacs, the point is placed at the line number which `scroll-margin'
6597 specifies."
6598   (if (featurep 'xemacs)
6599       (move-to-window-line 0)
6600     ;; There is an obscure bug in Emacs that makes it impossible to
6601     ;; scroll past big pictures in the article buffer.  Try to fix
6602     ;; this by adding a sanity check by counting the lines visible.
6603     (when (> (count-lines (window-start) (window-end)) 30)
6604       (move-to-window-line
6605        (min (max 0 scroll-margin)
6606             (max 1 (- (window-height)
6607                       (if mode-line-format 1 0)
6608                       (if header-line-format 1 0)
6609                       2)))))))
6610
6611 (defun gnus-article-next-page-1 (lines)
6612   (condition-case ()
6613       (let ((scroll-in-place nil)
6614             (auto-window-vscroll nil))
6615         (scroll-up lines))
6616     (end-of-buffer
6617      ;; Long lines may cause an end-of-buffer error.
6618      (goto-char (point-max))))
6619   (gnus-article-beginning-of-window))
6620
6621 (defun gnus-article-prev-page (&optional lines)
6622   "Show previous page of current article.
6623 Argument LINES specifies lines to be scrolled down."
6624   (interactive "p")
6625   (move-to-window-line 0)
6626   (if (and gnus-page-broken
6627            (bobp)
6628            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6629       (progn
6630         (gnus-narrow-to-page -1)        ;Go to previous page.
6631         (goto-char (point-max))
6632         (recenter (if gnus-article-over-scroll
6633                       (if lines
6634                           (max (if (featurep 'xemacs)
6635                                    lines
6636                                  (+ lines scroll-margin))
6637                                3)
6638                         (- (window-height) 2))
6639                     -1)))
6640     (prog1
6641         (condition-case ()
6642             (let ((scroll-in-place nil))
6643               (scroll-down lines))
6644           (beginning-of-buffer
6645            (goto-char (point-min))))
6646       (gnus-article-beginning-of-window))))
6647
6648 (defun gnus-article-only-boring-p ()
6649   "Decide whether there is only boring text remaining in the article.
6650 Something \"interesting\" is a word of at least two letters that does
6651 not have a face in `gnus-article-boring-faces'."
6652   (when (and gnus-article-skip-boring
6653              (boundp 'gnus-article-boring-faces)
6654              (symbol-value 'gnus-article-boring-faces))
6655     (save-excursion
6656       (let ((inhibit-point-motion-hooks t))
6657         (catch 'only-boring
6658           (while (re-search-forward "\\b\\w\\w" nil t)
6659             (forward-char -1)
6660             (when (not (gnus-intersection
6661                         (gnus-faces-at (point))
6662                         (symbol-value 'gnus-article-boring-faces)))
6663               (throw 'only-boring nil)))
6664           (throw 'only-boring t))))))
6665
6666 (defun gnus-article-refer-article ()
6667   "Read article specified by message-id around point."
6668   (interactive)
6669   (save-excursion
6670     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6671     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6672     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6673         (let ((msg-id (concat "<" (match-string 0) ">")))
6674           (set-buffer gnus-summary-buffer)
6675           (gnus-summary-refer-article msg-id))
6676       (error "No references around point"))))
6677
6678 (defun gnus-article-show-summary ()
6679   "Reconfigure windows to show summary buffer."
6680   (interactive)
6681   (if (not (gnus-buffer-live-p gnus-summary-buffer))
6682       (error "There is no summary buffer for this article buffer")
6683     (gnus-article-set-globals)
6684     (gnus-configure-windows 'article)
6685     (gnus-summary-goto-subject gnus-current-article)
6686     (gnus-summary-position-point)))
6687
6688 (defun gnus-article-describe-briefly ()
6689   "Describe article mode commands briefly."
6690   (interactive)
6691   (gnus-message 6 "%s" (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")))
6692
6693 (defun gnus-article-check-buffer ()
6694   "Beep if not in an article buffer."
6695   (unless (derived-mode-p 'gnus-article-mode)
6696     (error "Command invoked outside of a Gnus article buffer")))
6697
6698 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6699   "Read a summary buffer key sequence and execute it from the article buffer."
6700   (interactive "P")
6701   (gnus-article-check-buffer)
6702   (let ((nosaves
6703          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
6704            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6705            "=" "^" "\M-^" "|"))
6706         (nosave-but-article
6707          '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6708            "An" "Ap" [?A (meta return)] [?A delete]))
6709         (nosave-in-article
6710          '("AS" "\C-d"))
6711         (up-to-top
6712          '("n" "Gn" "p" "Gp"))
6713         keys new-sum-point)
6714     (with-current-buffer gnus-article-current-summary
6715       (let (gnus-pick-mode)
6716         (setq unread-command-events (nconc unread-command-events
6717                                            (list (or key last-command-event)))
6718               keys (if (featurep 'xemacs)
6719                        (events-to-keys (read-key-sequence nil t))
6720                      (read-key-sequence nil t)))))
6721
6722     (message "")
6723
6724     (cond
6725      ((eq (aref keys (1- (length keys))) ?\C-h)
6726       (gnus-article-describe-bindings (substring keys 0 -1)))
6727      ((or (member keys nosaves)
6728           (member keys nosave-but-article)
6729           (member keys nosave-in-article))
6730       (let (func)
6731         (save-window-excursion
6732           (pop-to-buffer gnus-article-current-summary)
6733           ;; We disable the pick minor mode commands.
6734           (let (gnus-pick-mode)
6735             (setq func (key-binding keys t))))
6736         (if (or (not func)
6737                 (numberp func))
6738             (ding)
6739           (unless (member keys nosave-in-article)
6740             (set-buffer gnus-article-current-summary))
6741           (when (and (symbolp func)
6742                      (get func 'disabled))
6743             (error "Function %s disabled" func))
6744           (call-interactively func)
6745           (setq new-sum-point (point)))
6746         (when (member keys nosave-but-article)
6747           (pop-to-buffer gnus-article-buffer))))
6748      (t
6749       ;; These commands should restore window configuration.
6750       (let ((obuf (current-buffer))
6751             (owin (current-window-configuration))
6752             win func in-buffer selected new-sum-start new-sum-hscroll err)
6753         (cond (not-restore-window
6754                (pop-to-buffer gnus-article-current-summary)
6755                (setq win (selected-window)))
6756               ((setq win (get-buffer-window gnus-article-current-summary))
6757                (select-window win))
6758               (t
6759                (let ((summary-buffer gnus-article-current-summary))
6760                  (gnus-configure-windows 'article)
6761                  (unless (setq win (get-buffer-window summary-buffer 'visible))
6762                    (let ((gnus-buffer-configuration
6763                           '((article ((vertical 1.0
6764                                                 (summary 0.25 point)
6765                                                 (article 1.0)))))))
6766                      (gnus-configure-windows 'article))
6767                    (setq win (get-buffer-window summary-buffer 'visible)))
6768                  (gnus-select-frame-set-input-focus (window-frame win))
6769                  (select-window win))))
6770         (setq in-buffer (current-buffer))
6771         ;; We disable the pick minor mode commands.
6772         (setq func (let (gnus-pick-mode)
6773                      (key-binding keys t)))
6774         (when (get func 'disabled)
6775           (error "Function %s disabled" func))
6776         (if (and func
6777                  (functionp func)
6778                  (condition-case code
6779                      (progn
6780                        (call-interactively func)
6781                        t)
6782                    (error
6783                     (setq err code)
6784                     nil)))
6785             (progn
6786               (when (eq win (selected-window))
6787                 (setq new-sum-point (point)
6788                       new-sum-start (window-start win)
6789                       new-sum-hscroll (window-hscroll win)))
6790               (when (or (eq in-buffer (current-buffer))
6791                         (when (eq obuf (current-buffer))
6792                           (set-buffer in-buffer)
6793                           t))
6794                 (setq selected (gnus-summary-select-article))
6795                 (set-buffer obuf)
6796                 (unless not-restore-window
6797                   (set-window-configuration owin))
6798                 (when (and (eq selected 'old)
6799                            new-sum-point)
6800                   (set-window-start (get-buffer-window (current-buffer))
6801                                     1)
6802                   (set-window-point (get-buffer-window (current-buffer))
6803                                     (if (article-goto-body)
6804                                         (1- (point))
6805                                       (point))))
6806                 (when (and (not not-restore-window)
6807                            new-sum-point
6808                            (window-live-p win)
6809                            (with-current-buffer (window-buffer win)
6810                              (derived-mode-p 'gnus-summary-mode)))
6811                   (set-window-point win new-sum-point)
6812                   (set-window-start win new-sum-start)
6813                   (set-window-hscroll win new-sum-hscroll))))
6814           (set-window-configuration owin)
6815           (if err
6816               (signal (car err) (cdr err))
6817             (ding))))))))
6818
6819 (defun gnus-article-read-summary-send-keys ()
6820   (interactive)
6821   (let ((unread-command-events (list (gnus-character-to-event ?S))))
6822     (gnus-article-read-summary-keys)))
6823
6824 (defun gnus-article-describe-key (key)
6825   "Display documentation of the function invoked by KEY.
6826 KEY is a string or a vector."
6827   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6828                        (read-key-sequence "Describe key: "))))
6829   (gnus-article-check-buffer)
6830   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6831                                   gnus-article-read-summary-send-keys))
6832       (with-current-buffer gnus-article-current-summary
6833         (setq unread-command-events
6834               (if (featurep 'xemacs)
6835                   (append key nil)
6836                 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6837                                         (list 'meta (- x 128))
6838                                       x))
6839                         key)))
6840         (let ((cursor-in-echo-area t)
6841               gnus-pick-mode)
6842           (describe-key (read-key-sequence nil t))))
6843     (describe-key key)))
6844
6845 (defun gnus-article-describe-key-briefly (key &optional insert)
6846   "Display documentation of the function invoked by KEY.
6847 KEY is a string or a vector."
6848   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6849                        (read-key-sequence "Describe key: "))
6850                      current-prefix-arg))
6851   (gnus-article-check-buffer)
6852   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6853                                   gnus-article-read-summary-send-keys))
6854       (with-current-buffer gnus-article-current-summary
6855         (setq unread-command-events
6856               (if (featurep 'xemacs)
6857                   (append key nil)
6858                 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6859                                         (list 'meta (- x 128))
6860                                       x))
6861                         key)))
6862         (let ((cursor-in-echo-area t)
6863               gnus-pick-mode)
6864           (describe-key-briefly (read-key-sequence nil t) insert)))
6865     (describe-key-briefly key insert)))
6866
6867 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6868 (defvar gnus-agent-summary-mode)
6869 (defvar gnus-draft-mode)
6870 (defvar help-xref-stack-item)
6871
6872 (defun gnus-article-describe-bindings (&optional prefix)
6873   "Show a list of all defined keys, and their definitions.
6874 The optional argument PREFIX, if non-nil, should be a key sequence;
6875 then we display only bindings that start with that prefix."
6876   (interactive)
6877   (gnus-article-check-buffer)
6878   (let ((keymap (copy-keymap gnus-article-mode-map))
6879         (map (copy-keymap gnus-article-send-map))
6880         (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6881         parent agent draft)
6882     (define-key keymap "S" map)
6883     (define-key map [t] nil)
6884     (with-current-buffer gnus-article-current-summary
6885       (set-keymap-parent
6886        keymap
6887        (if (setq parent (keymap-parent gnus-article-mode-map))
6888            (prog1
6889                (setq parent (copy-keymap parent))
6890              (set-keymap-parent parent (current-local-map)))
6891          (current-local-map)))
6892       (set-keymap-parent map (key-binding "S"))
6893       (let (key def gnus-pick-mode)
6894         (while sumkeys
6895           (setq key (pop sumkeys))
6896           (cond ((and (vectorp key) (= (length key) 1)
6897                       (consp (setq def (aref key 0)))
6898                       (numberp (car def)) (numberp (cdr def)))
6899                  (when (< (max (car def) (cdr def)) 128)
6900                    (setq sumkeys
6901                          (append (mapcar
6902                                   #'vector
6903                                   (nreverse (gnus-uncompress-range def)))
6904                                  sumkeys))))
6905                 ((setq def (key-binding key))
6906                  (unless (eq def 'undefined)
6907                    (define-key keymap key def))))))
6908       (when (boundp 'gnus-agent-summary-mode)
6909         (setq agent gnus-agent-summary-mode))
6910       (when (boundp 'gnus-draft-mode)
6911         (setq draft gnus-draft-mode)))
6912     (with-temp-buffer
6913       (use-local-map keymap)
6914       (set (make-local-variable 'gnus-agent-summary-mode) agent)
6915       (set (make-local-variable 'gnus-draft-mode) draft)
6916       (describe-bindings prefix))
6917     (let ((item `((lambda (prefix)
6918                     (with-current-buffer ,(current-buffer)
6919                       (gnus-article-describe-bindings prefix)))
6920                   ,prefix)))
6921       ;; Loading `help-mode' here is necessary if `describe-bindings'
6922       ;; is replaced with something, e.g. `helm-descbinds'.
6923       (require 'help-mode)
6924       (with-current-buffer (let (help-xref-following) (help-buffer))
6925         (setq help-xref-stack-item item)))))
6926
6927 (defun gnus-article-reply-with-original (&optional wide)
6928   "Start composing a reply mail to the current message.
6929 The text in the region will be yanked.  If the region isn't active,
6930 the entire article will be yanked."
6931   (interactive)
6932   (let ((article (cdr gnus-article-current))
6933         contents)
6934     (if (not (gnus-region-active-p))
6935         (with-current-buffer gnus-summary-buffer
6936           (gnus-summary-reply (list (list article)) wide))
6937       (setq contents (buffer-substring (point) (mark t)))
6938       ;; Deactivate active regions.
6939       (when (and (boundp 'transient-mark-mode)
6940                  transient-mark-mode)
6941         (setq mark-active nil))
6942       (with-current-buffer gnus-summary-buffer
6943         (gnus-summary-reply
6944          (list (list article contents)) wide)))))
6945
6946 (defun gnus-article-wide-reply-with-original ()
6947   "Start composing a wide reply mail to the current message.
6948 The text in the region will be yanked.  If the region isn't active,
6949 the entire article will be yanked."
6950   (interactive)
6951   (gnus-article-reply-with-original t))
6952
6953 (defun gnus-article-followup-with-original ()
6954   "Compose a followup to the current article.
6955 The text in the region will be yanked.  If the region isn't active,
6956 the entire article will be yanked."
6957   (interactive)
6958   (let ((article (cdr gnus-article-current))
6959         contents)
6960       (if (not (gnus-region-active-p))
6961           (with-current-buffer gnus-summary-buffer
6962             (gnus-summary-followup (list (list article))))
6963         (setq contents (buffer-substring (point) (mark t)))
6964         ;; Deactivate active regions.
6965         (when (and (boundp 'transient-mark-mode)
6966                    transient-mark-mode)
6967           (setq mark-active nil))
6968         (with-current-buffer gnus-summary-buffer
6969           (gnus-summary-followup
6970            (list (list article contents)))))))
6971
6972 (defun gnus-article-hide (&optional arg force)
6973   "Hide all the gruft in the current article.
6974 This means that signatures, cited text and (some) headers will be
6975 hidden.
6976 If given a prefix, show the hidden text instead."
6977   (interactive (append (gnus-article-hidden-arg) (list 'force)))
6978   (gnus-article-hide-headers arg)
6979   (gnus-article-hide-list-identifiers arg)
6980   (gnus-article-hide-citation-maybe arg force)
6981   (gnus-article-hide-signature arg))
6982
6983 (defun gnus-check-group-server ()
6984   ;; Make sure the connection to the server is alive.
6985   (unless (gnus-server-opened
6986            (gnus-find-method-for-group gnus-newsgroup-name))
6987     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6988     (gnus-request-group gnus-newsgroup-name t)))
6989
6990 (eval-when-compile
6991   (autoload 'nneething-get-file-name "nneething"))
6992
6993 (defun gnus-request-article-this-buffer (article group)
6994   "Get an article and insert it into this buffer."
6995   (let (do-update-line sparse-header)
6996     (prog1
6997         (save-excursion
6998           (erase-buffer)
6999           (gnus-kill-all-overlays)
7000           (setq group (or group gnus-newsgroup-name))
7001
7002           ;; Using `gnus-request-article' directly will insert the article into
7003           ;; `nntp-server-buffer' - so we'll save some time by not having to
7004           ;; copy it from the server buffer into the article buffer.
7005
7006           ;; We only request an article by message-id when we do not have the
7007           ;; headers for it, so we'll have to get those.
7008           (when (stringp article)
7009             (gnus-read-header article))
7010
7011           ;; If the article number is negative, that means that this article
7012           ;; doesn't belong in this newsgroup (possibly), so we find its
7013           ;; message-id and request it by id instead of number.
7014           (when (and (numberp article)
7015                      gnus-summary-buffer
7016                      (get-buffer gnus-summary-buffer)
7017                      (gnus-buffer-exists-p gnus-summary-buffer))
7018             (with-current-buffer gnus-summary-buffer
7019               (let ((header (gnus-summary-article-header article)))
7020                 (when (< article 0)
7021                   (cond
7022                    ((memq article gnus-newsgroup-sparse)
7023                     ;; This is a sparse gap article.
7024                     (setq do-update-line article)
7025                     (setq article (mail-header-id header))
7026                     (setq sparse-header (gnus-read-header article))
7027                     (setq gnus-newsgroup-sparse
7028                           (delq article gnus-newsgroup-sparse)))
7029                    ((vectorp header)
7030                     ;; It's a real article.
7031                     (setq article (mail-header-id header)))
7032                    (t
7033                     ;; It is an extracted pseudo-article.
7034                     (setq article 'pseudo)
7035                     (gnus-request-pseudo-article header))))
7036
7037                 (let ((method (gnus-find-method-for-group
7038                                gnus-newsgroup-name)))
7039                   (when (and (eq (car method) 'nneething)
7040                              (vectorp header))
7041                     (let ((dir (nneething-get-file-name
7042                                 (mail-header-id header))))
7043                       (when (and (stringp dir)
7044                                  (file-directory-p dir))
7045                         (setq article 'nneething)
7046                         (gnus-group-enter-directory dir))))))))
7047
7048           (cond
7049            ;; Refuse to select canceled articles.
7050            ((and (numberp article)
7051                  gnus-summary-buffer
7052                  (get-buffer gnus-summary-buffer)
7053                  (gnus-buffer-exists-p gnus-summary-buffer)
7054                  (eq (cdr (with-current-buffer gnus-summary-buffer
7055                             (assq article gnus-newsgroup-reads)))
7056                      gnus-canceled-mark))
7057             nil)
7058            ;; We first check `gnus-original-article-buffer'.
7059            ((and (get-buffer gnus-original-article-buffer)
7060                  (numberp article)
7061                  (with-current-buffer gnus-original-article-buffer
7062                    (and (equal (car gnus-original-article) group)
7063                         (eq (cdr gnus-original-article) article))))
7064             ;; `insert-buffer-substring' would incorrectly use the
7065             ;; equivalent of string-make-multibyte which amount to decoding
7066             ;; with locale-coding-system, causing failure of
7067             ;; subsequent decoding.
7068             (insert (mm-string-to-multibyte
7069                      (with-current-buffer gnus-original-article-buffer
7070                        (buffer-substring (point-min) (point-max)))))
7071             'article)
7072            ;; Check the backlog.
7073            ((and gnus-keep-backlog
7074                  (gnus-backlog-request-article group article (current-buffer)))
7075             'article)
7076            ;; Check asynchronous pre-fetch.
7077            ((gnus-async-request-fetched-article group article (current-buffer))
7078             (gnus-async-prefetch-next group article gnus-summary-buffer)
7079             (when (and (numberp article) gnus-keep-backlog)
7080               (gnus-backlog-enter-article group article (current-buffer)))
7081             'article)
7082            ;; Check the cache.
7083            ((and gnus-use-cache
7084                  (numberp article)
7085                  (gnus-cache-request-article article group))
7086             'article)
7087            ;; Check the agent cache.
7088            ((gnus-agent-request-article article group)
7089             'article)
7090            ;; Get the article and put into the article buffer.
7091            ((or (stringp article)
7092                 (numberp article))
7093             (let ((gnus-override-method gnus-override-method)
7094                   (methods (and (stringp article)
7095                                 (with-current-buffer gnus-summary-buffer
7096                                   (gnus-refer-article-methods))))
7097                   (backend (car (gnus-find-method-for-group
7098                                  gnus-newsgroup-name)))
7099                   result
7100                   (inhibit-read-only t))
7101               (when (and (null gnus-override-method)
7102                          methods)
7103                 (setq gnus-override-method (pop methods)))
7104               (while (not result)
7105                 (erase-buffer)
7106                 (gnus-kill-all-overlays)
7107                 (let ((gnus-newsgroup-name group))
7108                   (gnus-check-group-server))
7109                 (cond
7110                  ((gnus-request-article article group (current-buffer))
7111                   (when (numberp article)
7112                     (gnus-async-prefetch-next group article
7113                                               gnus-summary-buffer)
7114                     (when gnus-keep-backlog
7115                       (gnus-backlog-enter-article
7116                        group article (current-buffer)))
7117                     (when (and gnus-agent
7118                                (gnus-agent-group-covered-p group))
7119                       (gnus-agent-store-article article group)))
7120                   (setq result 'article))
7121                  (methods
7122                   (setq gnus-override-method (pop methods)))
7123                  ((not (string-match "^400 "
7124                                      (nnheader-get-report backend)))
7125                   ;; If we get 400 server disconnect, reconnect and
7126                   ;; retry; otherwise, assume the article has expired.
7127                   (setq result 'done))))
7128               (and (eq result 'article) 'article)))
7129            ;; It was a pseudo.
7130            (t article)))
7131
7132       ;; Associate this article with the current summary buffer.
7133       (setq gnus-article-current-summary gnus-summary-buffer)
7134
7135       ;; Take the article from the original article buffer
7136       ;; and place it in the buffer it's supposed to be in.
7137       (when (and (get-buffer gnus-article-buffer)
7138                  (equal (buffer-name (current-buffer))
7139                         (buffer-name (get-buffer gnus-article-buffer))))
7140         (save-excursion
7141           (if (get-buffer gnus-original-article-buffer)
7142               (set-buffer gnus-original-article-buffer)
7143             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7144             (buffer-disable-undo)
7145             (setq major-mode 'gnus-original-article-mode)
7146             (setq buffer-read-only t))
7147           (let ((inhibit-read-only t))
7148             (erase-buffer)
7149             (insert-buffer-substring gnus-article-buffer))
7150           (setq gnus-original-article (cons group article)))
7151
7152         ;; Decode charsets.
7153         (run-hooks 'gnus-article-decode-hook)
7154         ;; Mark article as decoded or not.
7155         (setq gnus-article-decoded-p gnus-article-decode-hook))
7156
7157       ;; Update sparse articles.
7158       (when (and do-update-line
7159                  (or (numberp article)
7160                      (stringp article)))
7161         (let ((buf (current-buffer)))
7162           (set-buffer gnus-summary-buffer)
7163           (gnus-summary-update-article do-update-line sparse-header)
7164           (gnus-summary-goto-subject do-update-line nil t)
7165           (set-window-point (gnus-get-buffer-window (current-buffer) t)
7166                             (point))
7167           (set-buffer buf))))))
7168
7169 (defun gnus-block-private-groups (group)
7170   (if (or (gnus-news-group-p group)
7171           (gnus-member-of-valid 'global group))
7172       ;; Block nothing in news groups.
7173       nil
7174     ;; Block everything anywhere else.
7175     "."))
7176
7177 (defun gnus-blocked-images ()
7178   (if (functionp gnus-blocked-images)
7179       (funcall gnus-blocked-images gnus-newsgroup-name)
7180     gnus-blocked-images))
7181
7182 ;;;
7183 ;;; Article editing
7184 ;;;
7185
7186 (defcustom gnus-article-edit-mode-hook nil
7187   "Hook run in article edit mode buffers."
7188   :group 'gnus-article-various
7189   :type 'hook)
7190
7191 (defvar gnus-article-edit-done-function nil)
7192
7193 (defvar gnus-article-edit-mode-map nil)
7194
7195 ;; Should we be using derived.el for this?
7196 (unless gnus-article-edit-mode-map
7197   (setq gnus-article-edit-mode-map (make-keymap))
7198   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7199
7200   (gnus-define-keys gnus-article-edit-mode-map
7201     "\C-c?"    describe-mode
7202     "\C-c\C-c" gnus-article-edit-done
7203     "\C-c\C-k" gnus-article-edit-exit
7204     "\C-c\C-f\C-t" message-goto-to
7205     "\C-c\C-f\C-o" message-goto-from
7206     "\C-c\C-f\C-b" message-goto-bcc
7207     ;;"\C-c\C-f\C-w" message-goto-fcc
7208     "\C-c\C-f\C-c" message-goto-cc
7209     "\C-c\C-f\C-s" message-goto-subject
7210     "\C-c\C-f\C-r" message-goto-reply-to
7211     "\C-c\C-f\C-n" message-goto-newsgroups
7212     "\C-c\C-f\C-d" message-goto-distribution
7213     "\C-c\C-f\C-f" message-goto-followup-to
7214     "\C-c\C-f\C-m" message-goto-mail-followup-to
7215     "\C-c\C-f\C-k" message-goto-keywords
7216     "\C-c\C-f\C-u" message-goto-summary
7217     "\C-c\C-f\C-i" message-insert-or-toggle-importance
7218     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7219     "\C-c\C-b" message-goto-body
7220     "\C-c\C-i" message-goto-signature
7221
7222     "\C-c\C-t" message-insert-to
7223     "\C-c\C-n" message-insert-newsgroups
7224     "\C-c\C-o" message-sort-headers
7225     "\C-c\C-e" message-elide-region
7226     "\C-c\C-v" message-delete-not-region
7227     "\C-c\C-z" message-kill-to-signature
7228     "\M-\r" message-newline-and-reformat
7229     "\C-c\C-a" mml-attach-file
7230     "\C-a" message-beginning-of-line
7231     "\t" message-tab
7232     "\M-;" comment-region)
7233
7234   (gnus-define-keys (gnus-article-edit-wash-map
7235                      "\C-c\C-w" gnus-article-edit-mode-map)
7236     "f" gnus-article-edit-full-stops))
7237
7238 (easy-menu-define
7239   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7240   '("Field"
7241     ["Fetch To" message-insert-to t]
7242     ["Fetch Newsgroups" message-insert-newsgroups t]
7243     "----"
7244     ["To" message-goto-to t]
7245     ["From" message-goto-from t]
7246     ["Subject" message-goto-subject t]
7247     ["Cc" message-goto-cc t]
7248     ["Reply-To" message-goto-reply-to t]
7249     ["Summary" message-goto-summary t]
7250     ["Keywords" message-goto-keywords t]
7251     ["Newsgroups" message-goto-newsgroups t]
7252     ["Followup-To" message-goto-followup-to t]
7253     ["Mail-Followup-To" message-goto-mail-followup-to t]
7254     ["Distribution" message-goto-distribution t]
7255     ["Body" message-goto-body t]
7256     ["Signature" message-goto-signature t]))
7257
7258 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7259   "Major mode for editing articles.
7260 This is an extended text-mode.
7261
7262 \\{gnus-article-edit-mode-map}"
7263   (make-local-variable 'gnus-article-edit-done-function)
7264   (make-local-variable 'gnus-prev-winconf)
7265   (set (make-local-variable 'font-lock-defaults)
7266        '(message-font-lock-keywords t))
7267   (set (make-local-variable 'mail-header-separator) "")
7268   (set (make-local-variable 'gnus-article-edit-mode) t)
7269   (easy-menu-add message-mode-field-menu message-mode-map)
7270   (mml-mode)
7271   (setq buffer-read-only nil)
7272   (buffer-enable-undo)
7273   (widen))
7274
7275 (defun gnus-article-edit (&optional force)
7276   "Edit the current article.
7277 This will have permanent effect only in mail groups.
7278 If FORCE is non-nil, allow editing of articles even in read-only
7279 groups."
7280   (interactive "P")
7281   (when (and (not force)
7282              (gnus-group-read-only-p))
7283     (error "The current newsgroup does not support article editing"))
7284   (gnus-article-date-original)
7285   (gnus-article-edit-article
7286    'ignore
7287    `(lambda (no-highlight)
7288       'ignore
7289       (gnus-summary-edit-article-done
7290        ,(or (mail-header-references gnus-current-headers) "")
7291        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7292
7293 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7294   "Start editing the contents of the current article buffer."
7295   (let ((winconf (current-window-configuration)))
7296     (set-buffer gnus-article-buffer)
7297     (let ((message-auto-save-directory
7298            ;; Don't associate the article buffer with a draft file.
7299            nil))
7300       (gnus-article-edit-mode))
7301     (funcall start-func)
7302     (set-buffer-modified-p nil)
7303     (gnus-configure-windows 'edit-article)
7304     (setq gnus-article-edit-done-function exit-func)
7305     (setq gnus-prev-winconf winconf)
7306     (unless quiet
7307       (gnus-message 6 "C-c C-c to end edits"))))
7308
7309 (defun gnus-article-edit-done (&optional arg)
7310   "Update the article edits and exit."
7311   (interactive "P")
7312   (let ((func gnus-article-edit-done-function)
7313         (buf (current-buffer))
7314         (start (window-start))
7315         (p (point))
7316         (winconf gnus-prev-winconf))
7317     (widen) ;; Widen it in case that users narrowed the buffer.
7318     (funcall func arg)
7319     (set-buffer buf)
7320     ;; The cache and backlog have to be flushed somewhat.
7321     (when gnus-keep-backlog
7322       (gnus-backlog-remove-article
7323        (car gnus-article-current) (cdr gnus-article-current)))
7324     ;; Flush original article as well.
7325     (gnus-flush-original-article-buffer)
7326     (when gnus-use-cache
7327       (gnus-cache-update-article
7328        (car gnus-article-current) (cdr gnus-article-current)))
7329     ;; We remove all text props from the article buffer.
7330     (kill-all-local-variables)
7331     (set-text-properties (point-min) (point-max) nil)
7332     (gnus-article-mode)
7333     (set-window-configuration winconf)
7334     (set-buffer buf)
7335     (set-window-start (get-buffer-window buf) start)
7336     (set-window-point (get-buffer-window buf) (point)))
7337   (gnus-summary-show-article))
7338
7339 (defun gnus-flush-original-article-buffer ()
7340   (when (get-buffer gnus-original-article-buffer)
7341     (with-current-buffer gnus-original-article-buffer
7342       (setq gnus-original-article nil))))
7343
7344 (defun gnus-article-edit-exit ()
7345   "Exit the article editing without updating."
7346   (interactive)
7347   (when (or (not (buffer-modified-p))
7348             (yes-or-no-p "Article modified; kill anyway? "))
7349     (let ((curbuf (current-buffer))
7350           (p (point))
7351           (window-start (window-start)))
7352       (erase-buffer)
7353       (if (gnus-buffer-live-p gnus-original-article-buffer)
7354           (insert-buffer-substring gnus-original-article-buffer))
7355       (let ((winconf gnus-prev-winconf))
7356         (kill-all-local-variables)
7357         (gnus-article-mode)
7358         (set-window-configuration winconf)
7359         ;; Tippy-toe some to make sure that point remains where it was.
7360         (save-current-buffer
7361           (set-buffer curbuf)
7362           (set-window-start (get-buffer-window (current-buffer)) window-start)
7363           (goto-char p))))
7364     (gnus-summary-show-article)))
7365
7366 (defun gnus-article-edit-full-stops ()
7367   "Interactively repair spacing at end of sentences."
7368   (interactive)
7369   (save-excursion
7370     (goto-char (point-min))
7371     (search-forward-regexp "^$" nil t)
7372     (let ((case-fold-search nil))
7373       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7374
7375 ;;;
7376 ;;; Article highlights
7377 ;;;
7378
7379 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7380
7381 ;;; Internal Variables:
7382
7383 (defcustom gnus-button-url-regexp
7384   (concat
7385    "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7386    "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7387    "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7388    (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7389        (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7390              (punct "!?:;.,"))
7391          (concat
7392           "\\(?:"
7393           ;; Match paired parentheses, e.g. in Wikipedia URLs:
7394           ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7395           "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7396           "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7397           "\\|"
7398           "[" chars punct "]+" "[" chars "]"
7399           "\\)"))
7400      (concat ;; XEmacs 21.4 doesn't support POSIX.
7401       "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7402       "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7403    "\\)")
7404   "Regular expression that matches URLs."
7405   :version "24.4"
7406   :group 'gnus-article-buttons
7407   :type 'regexp)
7408
7409 (defcustom gnus-button-valid-fqdn-regexp
7410   message-valid-fqdn-regexp
7411   "Regular expression that matches a valid FQDN."
7412   :version "22.1"
7413   :group 'gnus-article-buttons
7414   :type 'regexp)
7415
7416 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7417 (defcustom gnus-button-valid-localpart-regexp
7418   "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7419   "Regular expression that matches a localpart of mail addresses or MIDs."
7420   :version "22.1"
7421   :group 'gnus-article-buttons
7422   :type 'regexp)
7423
7424 (defcustom gnus-button-man-handler 'manual-entry
7425   "Function to use for displaying man pages.
7426 The function must take at least one argument with a string naming the
7427 man page."
7428   :version "22.1"
7429   :type '(choice (function-item :tag "Man" manual-entry)
7430                  (function-item :tag "Woman" woman)
7431                  (function :tag "Other"))
7432   :group 'gnus-article-buttons)
7433
7434 (defcustom gnus-button-mid-or-mail-regexp
7435   (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7436           gnus-button-valid-fqdn-regexp
7437           ">?\\)\\b")
7438   "Regular expression that matches a message ID or a mail address."
7439   :version "22.1"
7440   :group 'gnus-article-buttons
7441   :type 'regexp)
7442
7443 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7444   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7445 Strings like this can be either a message ID or a mail address.  If it is one
7446 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7447 message ID or a mail address, respectively.  If this variable is set to the
7448 symbol `ask', always query the user what do do.  If it is a function, this
7449 function will be called with the string as its only argument.  The function
7450 must return `mid', `mail', `invalid' or `ask'."
7451   :version "22.1"
7452   :group 'gnus-article-buttons
7453   :type '(choice (function-item :tag "Heuristic function"
7454                                 gnus-button-mid-or-mail-heuristic)
7455                  (const ask)
7456                  (const mid)
7457                  (const mail)))
7458
7459 (defcustom gnus-button-mid-or-mail-heuristic-alist
7460   '((-10.0 . ".+\\$.+@")
7461     (-10.0 . "#")
7462     (-10.0 . "\\*")
7463     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
7464     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7465     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7466     (-1.0  . "^[^a-z]+@")
7467     ;;
7468     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7469     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7470     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
7471     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7472     ;;
7473     (-2.0  . "^[0-9]")
7474     (-1.0  . "^[0-9][0-9]")
7475     ;;
7476     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7477     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7478     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7479     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7480     ;;
7481     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7482     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7483     ;;       "[0-9]{8,}.*\@"
7484     (-3.0
7485      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7486     ;; "[0-9]{12,}.*\@"
7487     ;; compensation for TDMA dated mail addresses:
7488     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7489     ;;
7490     (-20.0 . "\\.fsf@") ;; Gnus
7491     (-20.0 . "^slrn")
7492     (-20.0 . "^Pine")
7493     (-20.0 . "^alpine\\.")
7494     (-20.0 . "_-_") ;; Subject change in thread
7495     ;;
7496     (-20.0 . "\\.ln@") ;; leafnode
7497     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7498     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7499     ;;
7500     ;; (5.0 . "") ;; $local_part_len <= 7
7501     (10.0  . "^[^0-9]+@")
7502     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7503     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7504     (3.0   . "\@stud")
7505     ;;
7506     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
7507     ;;
7508     (0.5   . "^[A-Z][a-z]")
7509     (0.5   . "^[A-Z][a-z][a-z]")
7510     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7511     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7512   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7513
7514 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7515 address.  The REGEXP is processed with `case-fold-search' set to nil."
7516   :version "22.1"
7517   :group 'gnus-article-buttons
7518   :type '(repeat (cons (number :tag "Rate")
7519                        (regexp :tag "Regexp"))))
7520
7521 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7522   "Guess whether MID-OR-MAIL is a message ID or a mail address.
7523 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7524 address, `ask' if unsure and `invalid' if the string is invalid."
7525   (let ((case-fold-search nil)
7526         (list gnus-button-mid-or-mail-heuristic-alist)
7527         (result 0) rate regexp lpartlen elem)
7528     (setq lpartlen
7529           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7530     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7531     ;; Certain special cases...
7532     (when (string-match
7533            (concat
7534             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7535             "^[0-9]+\\.[0-9]+@compuserve\\|"
7536             "@public\\.gmane\\.org")
7537            mid-or-mail)
7538       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7539       (setq result 'mail))
7540     (when (string-match "@.*@\\| " mid-or-mail)
7541       (gnus-message 8 "`%s' is invalid." mid-or-mail)
7542       (setq result 'invalid))
7543     ;; Nothing more to do, if result is not a number here...
7544     (when (numberp result)
7545       (while list
7546         (setq elem (car list)
7547               rate (car elem)
7548               regexp (cdr elem)
7549               list (cdr list))
7550         (when (string-match regexp mid-or-mail)
7551           (setq result (+ result rate))
7552           (gnus-message
7553            9 "`%s' matched `%s', rate `%s', result `%s'."
7554            mid-or-mail regexp rate result)))
7555       (when (<= lpartlen 7)
7556         (setq result (+ result 5.0))
7557         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7558                       mid-or-mail result))
7559       (when (>= lpartlen 12)
7560         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7561         (cond
7562          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7563           ;; Long local part should contain realname if e-mail address,
7564           ;; too many digits: message-id.
7565           ;; $score -= 5.0 + 0.1 * $local_part_len;
7566           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7567           (setq result (+ result rate))
7568           (gnus-message
7569            9 "Many digits in `%s', rate `%s', result `%s'."
7570            mid-or-mail rate result))
7571          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7572                         mid-or-mail)
7573           ;; Too few vowels [^aeiouy]{4,}.*\@
7574           (setq result (+ result -5.0))
7575           (gnus-message
7576            9 "Few vowels in `%s', rate `%s', result `%s'."
7577            mid-or-mail -5.0 result))
7578          (t
7579           (setq result (+ result 5.0))
7580           (gnus-message
7581            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7582     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7583     ;; Maybe we should make this a customizable alist: (condition . 'result)
7584     (cond
7585      ((symbolp result) result)
7586      ;; Now convert number into proper results:
7587      ((< result -10.0) 'mid)
7588      ((> result  10.0) 'mail)
7589      (t 'ask))))
7590
7591 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7592   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7593          (url-mid (concat "news" ":" mid-or-mail))
7594          (url-mailto (concat "mailto" ":" mid-or-mail)))
7595     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7596     (when (fboundp pref)
7597       (setq guessed
7598             ;; get rid of surrounding angles...
7599             (funcall pref
7600                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7601       (if (or (eq 'mid guessed) (eq 'mail guessed))
7602           (setq pref guessed)
7603         (setq pref 'ask)))
7604     (if (eq pref 'ask)
7605         (save-window-excursion
7606           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7607               (setq pref 'mail)
7608             (setq pref 'mid))))
7609     (cond ((eq pref 'mid)
7610            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7611            (gnus-button-handle-news url-mid))
7612           ((eq pref 'mail)
7613            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
7614            (gnus-url-mailto url-mailto))
7615           (t (gnus-message 3 "Invalid string.")))))
7616
7617 (defun gnus-button-handle-custom (fun arg)
7618   "Call function FUN on argument ARG.
7619 Both FUN and ARG are supposed to be strings.  ARG will be passed
7620 as a symbol to FUN."
7621   (funcall (intern fun)
7622            (if (string-match "^customize-apropos" fun)
7623                arg
7624              (intern arg))))
7625
7626 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7627
7628 (defun gnus-button-handle-describe-function (url)
7629   "Call `describe-function' when pushing the corresponding URL button."
7630   (describe-function
7631    (intern
7632     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7633
7634 (defun gnus-button-handle-describe-variable (url)
7635   "Call `describe-variable' when pushing the corresponding URL button."
7636   (describe-variable
7637    (intern
7638     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7639
7640 (defun gnus-button-handle-symbol (url)
7641 "Display help on variable or function.
7642 Calls `describe-variable' or `describe-function'."
7643   (let ((sym (intern url)))
7644     (cond
7645      ((fboundp sym) (describe-function sym))
7646      ((boundp sym) (describe-variable sym))
7647      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7648
7649 (defun gnus-button-handle-describe-key (url)
7650   "Call `describe-key' when pushing the corresponding URL button."
7651   (let* ((key-string
7652           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7653          (keys (ignore-errors (eval `(kbd ,key-string)))))
7654     (if keys
7655         (describe-key keys)
7656       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7657
7658 (defun gnus-button-handle-apropos (url)
7659   "Call `apropos' when pushing the corresponding URL button."
7660   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7661
7662 (defun gnus-button-handle-apropos-command (url)
7663   "Call `apropos' when pushing the corresponding URL button."
7664   (apropos-command
7665    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7666
7667 (defun gnus-button-handle-apropos-variable (url)
7668   "Call `apropos' when pushing the corresponding URL button."
7669   (funcall
7670    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7671    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7672
7673 (defun gnus-button-handle-apropos-documentation (url)
7674   "Call `apropos' when pushing the corresponding URL button."
7675   (funcall
7676    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7677    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7678
7679 (defun gnus-button-handle-library (url)
7680   "Call `locate-library' when pushing the corresponding URL button."
7681   (gnus-message 9 "url=`%s'" url)
7682   (let* ((lib (locate-library url))
7683          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7684     (if (not lib)
7685         (gnus-message 1 "Cannot locale library `%s'." url)
7686       (find-file-read-only file))))
7687
7688 (defcustom gnus-button-man-level 5
7689   "*Integer that says how many man-related buttons Gnus will show.
7690 The higher the number, the more buttons will appear and the more false
7691 positives are possible.  Note that you can set this variable local to
7692 specific groups.  Setting it higher in Unix groups is probably a good idea.
7693 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7694 how to set variables in specific groups."
7695   :version "22.1"
7696   :group 'gnus-article-buttons
7697   :link '(custom-manual "(gnus)Group Parameters")
7698   :type 'integer)
7699
7700 (defcustom gnus-button-emacs-level 5
7701   "*Integer that says how many emacs-related buttons Gnus will show.
7702 The higher the number, the more buttons will appear and the more false
7703 positives are possible.  Note that you can set this variable local to
7704 specific groups.  Setting it higher in Emacs or Gnus related groups is
7705 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
7706 `gnus-parameters' on how to set variables in specific groups."
7707   :version "22.1"
7708   :group 'gnus-article-buttons
7709   :link '(custom-manual "(gnus)Group Parameters")
7710   :type 'integer)
7711
7712 (defcustom gnus-button-message-level 5
7713   "*Integer that says how many buttons for news or mail messages will appear.
7714 The higher the number, the more buttons will appear and the more false
7715 positives are possible."
7716   ;; mail addresses, MIDs, URLs for news, ...
7717   :version "22.1"
7718   :group 'gnus-article-buttons
7719   :type 'integer)
7720
7721 (defcustom gnus-button-browse-level 5
7722   "*Integer that says how many buttons for browsing will appear.
7723 The higher the number, the more buttons will appear and the more false
7724 positives are possible."
7725   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7726   :version "22.1"
7727   :group 'gnus-article-buttons
7728   :type 'integer)
7729
7730 (defcustom gnus-button-alist
7731   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7732      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7733     ((concat "\\b\\(nntp\\|news\\):\\("
7734              gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7735      0 t gnus-button-handle-news 2)
7736     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7737      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7738     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7739      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7740     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7741     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7742      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7743     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7744      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7745     ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7746      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7747     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7748      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7749     ;; RFC 2368 (The mailto URL scheme)
7750     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7751      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7752     ("\\bmailto:\\([^ \n\t]+\\)"
7753      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7754     ;; Info Konqueror style <info:/foo/bar baz>.
7755     ;; Must come before " Gnus home-grown style".
7756     ("\\binfo://?\\([^'\">\n\t]+\\)"
7757      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7758    ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7759     ("\\binfo://\\([^'\">\n\t ]+\\)"
7760      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7761     ;; Info GNOME style <info:foo#bar_baz>
7762     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7763      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7764     ;; Info KDE style <info:(foo)bar baz>
7765     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7766      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7767     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7768      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7769     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7770      ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7771      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7772     ;; This is custom
7773     ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7774      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7775     ;; Emacs help commands
7776     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7777      ;; regexp doesn't match arguments containing ` '.
7778      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7779     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7780      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7781     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7782      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7783     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7784      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7785     ;; The following entries may lead to many false positives so don't enable
7786     ;; them by default (use a high button level).
7787     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7788      ;; Exclude [.?] for URLs in gmane.emacs.cvs
7789      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7790     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7791      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7792     ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7793      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7794     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7795      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7796     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7797      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7798     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7799      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7800     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7801      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7802     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7803      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7804     ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7805      ;; Unlike the other regexps we really have to require quoting
7806      ;; here to determine where it ends.
7807      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7808     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7809     ("<URL: *\\([^\n<>]*\\)>"
7810      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7811     ;; RFC 2396 (2.4.3., delims) ...
7812     ("\"URL: *\\([^\n\"]*\\)\""
7813      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7814     ;; Raw URLs.
7815     (gnus-button-url-regexp
7816      0 (>= gnus-button-browse-level 0) browse-url 0)
7817     ;; man pages
7818     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7819      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7820      gnus-button-handle-man 1)
7821     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7822     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7823      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7824      gnus-button-handle-man 1)
7825     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7826     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7827     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7828      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7829     ;; Recognizing patches to .el files.  This is somewhat obscure,
7830     ;; but considering the percentage of Gnus users who hack Emacs
7831     ;; Lisp files...
7832     ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7833      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7834     ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7835      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7836     ;; MID or mail: To avoid too many false positives we don't try to catch
7837     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
7838     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
7839     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
7840     ;; so that non-ambiguous entries (see above) match first.
7841     (gnus-button-mid-or-mail-regexp
7842      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7843   "*Alist of regexps matching buttons in article bodies.
7844
7845 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7846 REGEXP: is the string (case insensitive) matching text around the button (can
7847 also be Lisp expression evaluating to a string),
7848 BUTTON: is the number of the regexp grouping actually matching the button,
7849 FORM: is a Lisp expression which must eval to true for the button to
7850 be added,
7851 CALLBACK: is the function to call when the user push this button, and each
7852 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7853
7854 CALLBACK can also be a variable, in that case the value of that
7855 variable it the real callback function."
7856   :group 'gnus-article-buttons
7857   :type '(repeat (list (choice regexp variable sexp)
7858                        (integer :tag "Button")
7859                        (sexp :tag "Form")
7860                        (function :tag "Callback")
7861                        (repeat :tag "Par"
7862                                :inline t
7863                                (integer :tag "Regexp group")))))
7864 (put 'gnus-button-alist 'risky-local-variable t)
7865
7866 (defcustom gnus-header-button-alist
7867   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7868      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7869     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7870      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7871     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7872      0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7873     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7874      0 (>= gnus-button-browse-level 0) browse-url 0)
7875     ("^Subject:" gnus-button-url-regexp
7876      0 (>= gnus-button-browse-level 0) browse-url 0)
7877     ("^[^:]+:" gnus-button-url-regexp
7878      0 (>= gnus-button-browse-level 0) browse-url 0)
7879     ("^OpenPGP:.*url=" gnus-button-url-regexp
7880      0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7881     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7882      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7883     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7884      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7885   "*Alist of headers and regexps to match buttons in article heads.
7886
7887 This alist is very similar to `gnus-button-alist', except that each
7888 alist has an additional HEADER element first in each entry:
7889
7890 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7891
7892 HEADER is a regexp to match a header.  For a fuller explanation, see
7893 `gnus-button-alist'."
7894   :group 'gnus-article-buttons
7895   :group 'gnus-article-headers
7896   :type '(repeat (list (regexp :tag "Header")
7897                        (choice regexp variable)
7898                        (integer :tag "Button")
7899                        (sexp :tag "Form")
7900                        (function :tag "Callback")
7901                        (repeat :tag "Par"
7902                                :inline t
7903                                (integer :tag "Regexp group")))))
7904 (put 'gnus-header-button-alist 'risky-local-variable t)
7905
7906 ;;; Commands:
7907
7908 (defun gnus-article-push-button (event)
7909   "Check text under the mouse pointer for a callback function.
7910 If the text under the mouse pointer has a `gnus-callback' property,
7911 call it with the value of the `gnus-data' text property."
7912   (interactive "e")
7913   (set-buffer (window-buffer (posn-window (event-start event))))
7914   (let* ((pos (posn-point (event-start event)))
7915          (data (get-text-property pos 'gnus-data))
7916          (fun (get-text-property pos 'gnus-callback)))
7917     (goto-char pos)
7918     (when fun
7919       (funcall fun data))))
7920
7921 (defun gnus-article-press-button ()
7922   "Check text at point for a callback function.
7923 If the text at point has a `gnus-callback' property,
7924 call it with the value of the `gnus-data' text property."
7925   (interactive)
7926   (let ((data (get-text-property (point) 'gnus-data))
7927         (fun (get-text-property (point) 'gnus-callback)))
7928     (when fun
7929       (funcall fun data))))
7930
7931 (defun gnus-article-highlight (&optional force)
7932   "Highlight current article.
7933 This function calls `gnus-article-highlight-headers',
7934 `gnus-article-highlight-citation',
7935 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7936 do the highlighting.  See the documentation for those functions."
7937   (interactive (list 'force))
7938   (gnus-article-highlight-headers)
7939   (gnus-article-highlight-citation force)
7940   (gnus-article-highlight-signature)
7941   (gnus-article-add-buttons)
7942   (gnus-article-add-buttons-to-head))
7943
7944 (defun gnus-article-highlight-some (&optional force)
7945   "Highlight current article.
7946 This function calls `gnus-article-highlight-headers',
7947 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7948 do the highlighting.  See the documentation for those functions."
7949   (interactive (list 'force))
7950   (gnus-article-highlight-headers)
7951   (gnus-article-highlight-signature)
7952   (gnus-article-add-buttons))
7953
7954 (defun gnus-article-highlight-headers ()
7955   "Highlight article headers as specified by `gnus-header-face-alist'."
7956   (interactive)
7957   (gnus-with-article-headers
7958     (let (regexp header-face field-face from hpoints fpoints)
7959       (dolist (entry gnus-header-face-alist)
7960         (goto-char (point-min))
7961         (setq regexp (concat "^\\("
7962                              (if (string-equal "" (nth 0 entry))
7963                                  "[^\t ]"
7964                                (nth 0 entry))
7965                              "\\)")
7966               header-face (nth 1 entry)
7967               field-face (nth 2 entry))
7968         (while (and (re-search-forward regexp nil t)
7969                     (not (eobp)))
7970           (beginning-of-line)
7971           (setq from (point))
7972           (unless (search-forward ":" nil t)
7973             (forward-char 1))
7974           (when (and header-face
7975                      (not (memq (point) hpoints)))
7976             (push (point) hpoints)
7977             (gnus-put-text-property from (point) 'face header-face))
7978           (when (and field-face
7979                      (not (memq (setq from (point)) fpoints)))
7980             (push from fpoints)
7981             (if (re-search-forward "^[^ \t]" nil t)
7982                 (forward-char -2)
7983               (goto-char (point-max)))
7984             (gnus-put-text-property from (point) 'face field-face)))))))
7985
7986 (defun gnus-article-highlight-signature ()
7987   "Highlight the signature in an article.
7988 It does this by highlighting everything after
7989 `gnus-signature-separator' using the face `gnus-signature'."
7990   (interactive)
7991   (gnus-with-article-buffer
7992     (let ((inhibit-point-motion-hooks t))
7993       (save-restriction
7994         (when (and gnus-signature-face
7995                    (gnus-article-narrow-to-signature))
7996           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7997                             'face gnus-signature-face)
7998           (widen)
7999           (gnus-article-search-signature)
8000           (let ((start (match-beginning 0))
8001                 (end (set-marker (make-marker) (1+ (match-end 0)))))
8002             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8003                                      end)))))))
8004
8005 (defun gnus-button-in-region-p (b e prop)
8006   "Say whether PROP exists in the region."
8007   (text-property-not-all b e prop nil))
8008
8009 (defun gnus-article-add-buttons ()
8010   "Find external references in the article and make buttons of them.
8011 \"External references\" are things like Message-IDs and URLs, as
8012 specified by `gnus-button-alist'."
8013   (interactive)
8014   (gnus-with-article-buffer
8015     (let ((inhibit-point-motion-hooks t)
8016           (case-fold-search t)
8017           (alist gnus-button-alist)
8018           beg entry regexp)
8019       ;; We skip the headers.
8020       (article-goto-body)
8021       (setq beg (point))
8022       (while (setq entry (pop alist))
8023         (setq regexp (eval (car entry)))
8024         (goto-char beg)
8025         (while (re-search-forward regexp nil t)
8026           (let ((start (match-beginning (nth 1 entry)))
8027                 (end (match-end (nth 1 entry)))
8028                 (from (match-beginning 0)))
8029             (when (and (eval (nth 2 entry))
8030                        (not (gnus-button-in-region-p
8031                              start end 'gnus-callback)))
8032               ;; That optional form returned non-nil, so we add the
8033               ;; button.
8034               (setq from (set-marker (make-marker) from))
8035               (unless (and (eq (car entry) 'gnus-button-url-regexp)
8036                            (gnus-article-extend-url-button from start end))
8037                 (gnus-article-add-button start end
8038                                          'gnus-button-push (list from entry))
8039                 (gnus-put-text-property
8040                  start end
8041                  'gnus-string (buffer-substring-no-properties
8042                                start end))))))))))
8043
8044 (defun gnus-article-extend-url-button (beg start end)
8045   "Extend url button if url is folded into two or more lines.
8046 Return non-nil if button is extended.  BEG is a marker that points to
8047 the beginning position of a text containing url.  START and END are
8048 the endpoints of a url button before it is extended.  The concatenated
8049 url is put as the `gnus-button-url' overlay property on the button."
8050   (let ((opoint (point))
8051         (points (list start end))
8052         url delim regexp)
8053     (prog1
8054         (when (and (progn
8055                      (goto-char end)
8056                      (not (looking-at "[\t ]*[\">]")))
8057                    (progn
8058                      (goto-char start)
8059                      (string-match
8060                       "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8061                       (buffer-substring (point-at-bol) start)))
8062                    (progn
8063                      (setq url (list (buffer-substring start end))
8064                            delim (if (match-beginning 1) ">" "\""))
8065                      (beginning-of-line)
8066                      (setq regexp (concat
8067                                    (when (and (looking-at
8068                                                message-cite-prefix-regexp)
8069                                               (< (match-end 0) start))
8070                                      (regexp-quote (match-string 0)))
8071                                    "\
8072 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8073                                    delim "\\)"))
8074                      (while (progn
8075                               (forward-line 1)
8076                               (and (looking-at regexp)
8077                                    (prog1
8078                                        (match-beginning 1)
8079                                      (push (or (match-string 2)
8080                                                (match-string 1))
8081                                            url)
8082                                      (push (setq end (or (match-end 2)
8083                                                          (match-end 1)))
8084                                            points)
8085                                      (push (or (match-beginning 2)
8086                                                (match-beginning 1))
8087                                            points)))))
8088                      (match-beginning 2)))
8089           (let (gnus-article-mouse-face widget-mouse-face)
8090             (while points
8091               (gnus-article-add-button (pop points) (pop points)
8092                                        'gnus-button-push
8093                                        (list beg (assq 'gnus-button-url-regexp
8094                                                        gnus-button-alist)))))
8095           (let ((overlay (gnus-make-overlay start end)))
8096             (gnus-overlay-put overlay 'evaporate t)
8097             (gnus-overlay-put overlay 'gnus-button-url
8098                               (list (mapconcat 'identity (nreverse url) "")))
8099             (when gnus-article-mouse-face
8100               (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8101           t)
8102       (goto-char opoint))))
8103
8104 ;; Add buttons to the head of an article.
8105 (defun gnus-article-add-buttons-to-head ()
8106   "Add buttons to the head of the article."
8107   (interactive)
8108   (gnus-with-article-headers
8109     (let (beg end)
8110       (dolist (entry gnus-header-button-alist)
8111         ;; Each alist entry.
8112         (goto-char (point-min))
8113         (while (re-search-forward (car entry) nil t)
8114           ;; Each header matching the entry.
8115           (setq beg (match-beginning 0))
8116           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8117                              (match-beginning 0))
8118                         (point-max)))
8119           (goto-char beg)
8120           (while (re-search-forward (eval (nth 1 entry)) end t)
8121             ;; Each match within a header.
8122             (let* ((entry (cdr entry))
8123                    (start (match-beginning (nth 1 entry)))
8124                    (end (match-end (nth 1 entry)))
8125                    (form (nth 2 entry)))
8126               (goto-char (match-end 0))
8127               (when (eval form)
8128                 (gnus-article-add-button
8129                  start end (nth 3 entry)
8130                  (buffer-substring (match-beginning (nth 4 entry))
8131                                    (match-end (nth 4 entry)))))))
8132           (goto-char end))))))
8133
8134 ;;; External functions:
8135
8136 (defun gnus-article-add-button (from to fun &optional data text)
8137   "Create a button between FROM and TO with callback FUN and data DATA."
8138   (when gnus-article-button-face
8139     (gnus-overlay-put (gnus-make-overlay from to nil t)
8140                       'face gnus-article-button-face))
8141   (gnus-add-text-properties
8142    from to
8143    (nconc (and gnus-article-mouse-face
8144                (list gnus-mouse-face-prop gnus-article-mouse-face))
8145           (list 'gnus-callback fun)
8146           (and data (list 'gnus-data data))))
8147   (widget-convert-button 'link from to :action 'gnus-widget-press-button
8148                          :help-echo (or text "Follow the link")
8149                          :keymap gnus-url-button-map
8150                          :button-keymap gnus-widget-button-keymap))
8151
8152 (defun gnus-article-copy-string ()
8153   "Copy the string in the button to the kill ring."
8154   (interactive)
8155   (gnus-article-check-buffer)
8156   (let ((data (get-text-property (point) 'gnus-string)))
8157     (when data
8158       (with-temp-buffer
8159         (insert data)
8160         (copy-region-as-kill (point-min) (point-max))
8161         (message "Copied %s" data)))))
8162
8163 ;;; Internal functions:
8164
8165 (defun gnus-article-set-globals ()
8166   (with-current-buffer gnus-summary-buffer
8167     (gnus-set-global-variables)))
8168
8169 (defun gnus-signature-toggle (end)
8170   (gnus-with-article-buffer
8171     (let ((inhibit-point-motion-hooks t))
8172       (if (text-property-any end (point-max) 'article-type 'signature)
8173           (progn
8174             (gnus-delete-wash-type 'signature)
8175             (gnus-remove-text-properties-when
8176              'article-type 'signature end (point-max)
8177              (cons 'article-type (cons 'signature
8178                                        gnus-hidden-properties))))
8179         (gnus-add-wash-type 'signature)
8180         (gnus-add-text-properties-when
8181          'article-type nil end (point-max)
8182          (cons 'article-type (cons 'signature
8183                                    gnus-hidden-properties)))))
8184     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8185       (gnus-set-mode-line 'article))))
8186
8187 (defun gnus-button-push (marker-and-entry)
8188   ;; Push button starting at MARKER.
8189   (save-excursion
8190     (let* ((marker (car marker-and-entry))
8191            (entry (cadr marker-and-entry))
8192            (regexp (car entry))
8193            (inhibit-point-motion-hooks t))
8194       (goto-char marker)
8195       ;; This is obviously true, or something bad is happening :)
8196       ;; But we need it to have the match-data
8197       (when (looking-at (or (if (symbolp regexp)
8198                                 (symbol-value regexp)
8199                               regexp)))
8200         (let ((fun (nth 3 entry))
8201               (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8202                              (get-char-property marker 'gnus-button-url))
8203                         (mapcar (lambda (group)
8204                                   (let ((string (match-string group)))
8205                                     (set-text-properties
8206                                      0 (length string) nil string)
8207                                     string))
8208                                 (nthcdr 4 entry)))))
8209
8210           (cond
8211            ((fboundp fun)
8212             (apply fun args))
8213            ((and (boundp fun)
8214                  (fboundp (symbol-value fun)))
8215             (apply (symbol-value fun) args))
8216            (t
8217             (gnus-message 1 "You must define `%S' to use this button"
8218                           (cons fun args)))))))))
8219
8220 (defun gnus-parse-news-url (url)
8221   (let (scheme server port group message-id articles)
8222     (with-temp-buffer
8223       (insert url)
8224       (goto-char (point-min))
8225       (when (looking-at "\\([A-Za-z]+\\):")
8226         (setq scheme (match-string 1))
8227         (goto-char (match-end 0)))
8228       (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8229         (setq server (match-string 1))
8230         (setq port (if (stringp (match-string 3))
8231                        (string-to-number (match-string 3))
8232                      (match-string 3)))
8233         (goto-char (match-end 0)))
8234
8235       (cond
8236        ((looking-at "\\(.*@.*\\)")
8237         (setq message-id (match-string 1)))
8238        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8239         (setq group (match-string 1)
8240               articles (split-string (match-string 2) "-")))
8241        ((looking-at "\\([^/]+\\)/?")
8242         (setq group (match-string 1)))
8243        (t
8244         (error "Unknown news URL syntax"))))
8245     (list scheme server port group message-id articles)))
8246
8247 (defun gnus-button-handle-news (url)
8248   "Fetch a news URL."
8249   (destructuring-bind (scheme server port group message-id articles)
8250       (gnus-parse-news-url url)
8251     (cond
8252      (message-id
8253       (with-current-buffer gnus-summary-buffer
8254         (if server
8255             (let ((gnus-refer-article-method
8256                    (nconc (list (list 'nntp server))
8257                           gnus-refer-article-method))
8258                   (nntp-port-number (or port "nntp")))
8259               (gnus-message 7 "Fetching %s with %s"
8260                             message-id gnus-refer-article-method)
8261               (gnus-summary-refer-article message-id))
8262           (gnus-summary-refer-article message-id))))
8263      (group
8264       (gnus-button-fetch-group url)))))
8265
8266 (defun gnus-button-patch (library line)
8267   "Visit an Emacs Lisp library LIBRARY on line LINE."
8268   (interactive)
8269   (let ((file (locate-library (file-name-nondirectory library))))
8270     (unless file
8271       (error "Couldn't find library %s" library))
8272     (find-file file)
8273     (goto-char (point-min))
8274     (forward-line (1- (string-to-number line)))))
8275
8276 (defun gnus-button-handle-man (url)
8277   "Fetch a man page."
8278   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8279   (when (eq gnus-button-man-handler 'woman)
8280     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8281   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8282   (funcall gnus-button-man-handler url))
8283
8284 (defun gnus-button-handle-info-url (url)
8285   "Fetch an info URL."
8286   (setq url (mm-subst-char-in-string ?+ ?\  url))
8287   (cond
8288    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8289     (gnus-info-find-node
8290      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8291                      "Gnus")
8292              ")" (gnus-url-unhex-string (match-string 2 url)))))
8293    ((string-match "([^)\"]+)[^\"]+" url)
8294     (setq url
8295           (gnus-replace-in-string
8296            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8297     (gnus-info-find-node url))
8298    (t (error "Can't parse %s" url))))
8299
8300 (defun gnus-button-handle-info-url-gnome (url)
8301   "Fetch GNOME style info URL."
8302   (setq url (mm-subst-char-in-string ?_ ?\  url))
8303   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8304       (gnus-info-find-node
8305        (concat "("
8306                (gnus-url-unhex-string
8307                  (match-string 1 url))
8308                ")"
8309                (or (gnus-url-unhex-string
8310                     (match-string 2 url))
8311                    "Top")))
8312     (error "Can't parse %s" url)))
8313
8314 (defun gnus-button-handle-info-url-kde (url)
8315   "Fetch KDE style info URL."
8316   (gnus-info-find-node (gnus-url-unhex-string url)))
8317
8318 ;; (info) will autoload info.el
8319 (declare-function Info-menu "info" (menu-item &optional fork))
8320 (declare-function Info-index-next "info" (num))
8321
8322 (defun gnus-button-handle-info-keystrokes (url)
8323   "Call `info' when pushing the corresponding URL button."
8324   ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8325   (let (node indx comma)
8326     (if (string-match
8327          (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8328                  "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8329                  "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8330                  "\\(?:[ \t\n,]*\\)\\)?")
8331          url)
8332         (setq node (match-string 2 url)
8333               indx (match-string 3 url))
8334       (error "Can't parse %s" url))
8335     (info)
8336     (Info-directory)
8337     (Info-menu node)
8338     (when (> (length indx) 0)
8339       (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8340                             "\\([ \t\n,]*\\)")
8341                     indx)
8342       (setq comma (match-string 2 indx))
8343       (setq indx  (match-string 1 indx))
8344       (Info-index indx)
8345       (when comma
8346         (dotimes (i (with-temp-buffer
8347                       (insert comma)
8348                       ;; Note: the XEmacs version of `how-many' takes
8349                       ;; no optional argument.
8350                       (goto-char (point-min))
8351                       (how-many ",")))
8352           (Info-index-next 1)))
8353       nil)))
8354
8355 (autoload 'pgg-snarf-keys-region "pgg")
8356 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8357 (declare-function pgg-display-output-buffer "pgg" (start end status))
8358
8359 (defun gnus-button-openpgp (url)
8360   "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8361   (with-temp-buffer
8362     (mm-url-insert-file-contents-external url)
8363     (pgg-snarf-keys-region (point-min) (point-max))
8364     (pgg-display-output-buffer nil nil nil)))
8365
8366 (defun gnus-button-message-id (message-id)
8367   "Fetch MESSAGE-ID."
8368   (with-current-buffer gnus-summary-buffer
8369     (gnus-summary-refer-article message-id)))
8370
8371 (defun gnus-button-fetch-group (address &rest ignore)
8372   "Fetch GROUP specified by ADDRESS."
8373   (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8374                       address)
8375     ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8376     ;; for nntp:// and news://
8377     (setq address (match-string 3 address)))
8378   (if (not (string-match "[:/]" address))
8379       ;; This is just a simple group url.
8380       (gnus-group-read-ephemeral-group address gnus-select-method)
8381     (if (not
8382          (string-match
8383           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8384           address))
8385         (error "Can't parse %s" address)
8386       (gnus-group-read-ephemeral-group
8387        (match-string 4 address)
8388        `(nntp ,(match-string 1 address)
8389               (nntp-address ,(match-string 1 address))
8390               (nntp-port-number ,(if (match-end 3)
8391                                      (match-string 3 address)
8392                                    "nntp")))
8393        nil nil nil
8394        (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8395
8396 (defun gnus-url-parse-query-string (query &optional downcase)
8397   (let (retval pairs cur key val)
8398     (setq pairs (split-string query "&"))
8399     (while pairs
8400       (setq cur (car pairs)
8401             pairs (cdr pairs))
8402       (if (not (string-match "=" cur))
8403           nil                           ; Grace
8404         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8405               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8406         (if downcase
8407             (setq key (downcase key)))
8408         (setq cur (assoc key retval))
8409         (if cur
8410             (setcdr cur (cons val (cdr cur)))
8411           (setq retval (cons (list key val) retval)))))
8412     retval))
8413
8414 (defun gnus-url-mailto (url)
8415   ;; Send mail to someone
8416   (setq url (replace-regexp-in-string "\n" " " url))
8417   (when (string-match "mailto:/*\\(.*\\)" url)
8418     (setq url (substring url (match-beginning 1) nil)))
8419   (let (to args subject func)
8420     (setq args (gnus-url-parse-query-string
8421                 (if (string-match "^\\?" url)
8422                     (substring url 1)
8423                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8424                       (concat "to=" (match-string 1 url) "&"
8425                               (match-string 2 url))
8426                     (concat "to=" url))))
8427           subject (cdr-safe (assoc "subject" args)))
8428     (gnus-msg-mail)
8429     (while args
8430       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8431       (if (fboundp func)
8432           (funcall func)
8433         (message-position-on-field (caar args)))
8434       (insert (gnus-replace-in-string
8435                (mapconcat 'identity (reverse (cdar args)) ", ")
8436                "\r\n" "\n" t))
8437       (setq args (cdr args)))
8438     (if subject
8439         (message-goto-body)
8440       (message-goto-subject))))
8441
8442 (defun gnus-button-embedded-url (address)
8443   "Activate ADDRESS with `browse-url'."
8444   (browse-url (gnus-strip-whitespace address)))
8445
8446 ;;; Next/prev buttons in the article buffer.
8447
8448 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8449 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8450
8451 (defvar gnus-prev-page-map
8452   (let ((map (make-sparse-keymap)))
8453     (define-key map gnus-mouse-2 'gnus-button-prev-page)
8454     (define-key map "\r" 'gnus-button-prev-page)
8455     map))
8456
8457 (defvar gnus-next-page-map
8458   (let ((map (make-sparse-keymap)))
8459     (define-key map gnus-mouse-2 'gnus-button-next-page)
8460     (define-key map "\r" 'gnus-button-next-page)
8461     map))
8462
8463 (defun gnus-insert-prev-page-button ()
8464   (let ((b (point)) e
8465         (inhibit-read-only t))
8466     (gnus-eval-format
8467      gnus-prev-page-line-format nil
8468      `(keymap ,gnus-prev-page-map
8469               gnus-prev t
8470               gnus-callback gnus-article-button-prev-page
8471               article-type annotation))
8472     (setq e (if (bolp)
8473                 ;; Exclude a newline.
8474                 (1- (point))
8475               (point)))
8476     (when gnus-article-button-face
8477       (gnus-overlay-put (gnus-make-overlay b e nil t)
8478                         'face gnus-article-button-face))
8479     (widget-convert-button
8480      'link b e
8481      :action 'gnus-button-prev-page
8482      :button-keymap gnus-prev-page-map)))
8483
8484 (defun gnus-button-next-page (&optional args more-args)
8485   "Go to the next page."
8486   (interactive)
8487   (let ((win (selected-window)))
8488     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8489     (gnus-article-next-page)
8490     (select-window win)))
8491
8492 (defun gnus-button-prev-page (&optional args more-args)
8493   "Go to the prev page."
8494   (interactive)
8495   (let ((win (selected-window)))
8496     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8497     (gnus-article-prev-page)
8498     (select-window win)))
8499
8500 (defun gnus-insert-next-page-button ()
8501   (let ((b (point)) e
8502         (inhibit-read-only t))
8503     (gnus-eval-format gnus-next-page-line-format nil
8504                       `(keymap ,gnus-next-page-map
8505                                gnus-next t
8506                                gnus-callback gnus-article-button-next-page
8507                                article-type annotation))
8508     (setq e (if (bolp)
8509                 ;; Exclude a newline.
8510                 (1- (point))
8511               (point)))
8512     (when gnus-article-button-face
8513       (gnus-overlay-put (gnus-make-overlay b e nil t)
8514                         'face gnus-article-button-face))
8515     (widget-convert-button
8516      'link b e
8517      :action 'gnus-button-next-page
8518      :button-keymap gnus-next-page-map)))
8519
8520 (defun gnus-article-button-next-page (arg)
8521   "Go to the next page."
8522   (interactive "P")
8523   (let ((win (selected-window)))
8524     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8525     (gnus-article-next-page)
8526     (select-window win)))
8527
8528 (defun gnus-article-button-prev-page (arg)
8529   "Go to the prev page."
8530   (interactive "P")
8531   (let ((win (selected-window)))
8532     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8533     (gnus-article-prev-page)
8534     (select-window win)))
8535
8536 (defvar gnus-decode-header-methods
8537   '(mail-decode-encoded-word-region)
8538   "List of methods used to decode headers.
8539
8540 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
8541 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
8542 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8543 whose names match REGEXP.
8544
8545 For example:
8546 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8547  mail-decode-encoded-word-region
8548  (\"chinese\" . rfc1843-decode-region))
8549 ")
8550
8551 (defvar gnus-decode-header-methods-cache nil)
8552
8553 (defun gnus-multi-decode-header (start end)
8554   "Apply the functions from `gnus-encoded-word-methods' that match."
8555   (unless (and gnus-decode-header-methods-cache
8556                (eq gnus-newsgroup-name
8557                    (car gnus-decode-header-methods-cache)))
8558     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8559     (dolist (x gnus-decode-header-methods)
8560       (if (symbolp x)
8561           (nconc gnus-decode-header-methods-cache (list x))
8562         (if (and gnus-newsgroup-name
8563                  (string-match (car x) gnus-newsgroup-name))
8564             (nconc gnus-decode-header-methods-cache
8565                    (list (cdr x)))))))
8566   (let ((xlist gnus-decode-header-methods-cache))
8567     (pop xlist)
8568     (save-restriction
8569       (narrow-to-region start end)
8570       (while xlist
8571         (funcall (pop xlist) (point-min) (point-max))))))
8572
8573 ;;;
8574 ;;; Treatment top-level handling.
8575 ;;;
8576
8577 (defvar gnus-inhibit-article-treatments nil)
8578
8579 (defun gnus-treat-article (gnus-treat-condition
8580                            &optional part-number total-parts gnus-treat-type)
8581   (let ((gnus-treat-length (- (point-max) (point-min)))
8582         (alist gnus-treatment-function-alist)
8583         (article-goto-body-goes-to-point-min-p t)
8584         (treated-type
8585          (or (not gnus-treat-type)
8586              (catch 'found
8587                (let ((list gnus-article-treat-types))
8588                  (while list
8589                    (when (string-match (pop list) gnus-treat-type)
8590                      (throw 'found t)))))))
8591         (highlightp (gnus-visual-p 'article-highlight 'highlight))
8592         val elem)
8593     (gnus-run-hooks 'gnus-part-display-hook)
8594     (dolist (elem alist)
8595       (setq val
8596             (save-excursion
8597               (when (gnus-buffer-live-p gnus-summary-buffer)
8598                 (set-buffer gnus-summary-buffer))
8599               (symbol-value (car elem))))
8600       (when (and (or (consp val)
8601                      treated-type)
8602                  (or (not gnus-inhibit-article-treatments)
8603                      (eq gnus-treat-condition 'head))
8604                  (gnus-treat-predicate val)
8605                  (or (not (get (car elem) 'highlight))
8606                      highlightp))
8607         (save-restriction
8608           (funcall (cadr elem)))))))
8609
8610 ;; Dynamic variables.
8611 (defvar part-number)
8612 (defvar total-parts)
8613 (defvar gnus-treat-type)
8614 (defvar gnus-treat-condition)
8615 (defvar gnus-treat-length)
8616
8617 (defun gnus-treat-predicate (val)
8618   (cond
8619    ((null val)
8620     nil)
8621    (gnus-treat-condition
8622     (eq gnus-treat-condition val))
8623    ((and (listp val)
8624          (stringp (car val)))
8625     (apply 'gnus-or (mapcar `(lambda (s)
8626                                (string-match s ,(or gnus-newsgroup-name "")))
8627                             val)))
8628    ((listp val)
8629     (let ((pred (pop val)))
8630       (cond
8631        ((eq pred 'or)
8632         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8633        ((eq pred 'and)
8634         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8635        ((eq pred 'not)
8636         (not (gnus-treat-predicate (car val))))
8637        ((eq pred 'typep)
8638         (equal (car val) gnus-treat-type))
8639        ((functionp pred)
8640         (funcall pred))
8641        (t
8642         (error "%S is not a valid predicate" pred)))))
8643    ((eq val t)
8644     t)
8645    ((eq val 'head)
8646     nil)
8647    ((eq val 'first)
8648     (eq part-number 1))
8649    ((eq val 'last)
8650     (eq part-number total-parts))
8651    ((numberp val)
8652     (< gnus-treat-length val))
8653    (t
8654     (error "%S is not a valid value" val))))
8655
8656 (defun gnus-article-encrypt-body (protocol &optional n)
8657   "Encrypt the article body."
8658   (interactive
8659    (list
8660     (or gnus-article-encrypt-protocol
8661         (gnus-completing-read "Encrypt protocol"
8662                               (mapcar 'car gnus-article-encrypt-protocol-alist)
8663                               t))
8664     current-prefix-arg))
8665   ;; User might hit `K E' instead of `K e', so prompt once.
8666   (when (and gnus-article-encrypt-protocol
8667              gnus-novice-user)
8668     (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8669       (error "Encrypt aborted")))
8670   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8671     (unless func
8672       (error "Can't find the encrypt protocol %s" protocol))
8673     (if (member gnus-newsgroup-name '("nndraft:delayed"
8674                                       "nndraft:drafts"
8675                                       "nndraft:queue"))
8676         (error "Can't encrypt the article in group %s"
8677                gnus-newsgroup-name))
8678     (gnus-summary-iterate n
8679       (with-current-buffer gnus-summary-buffer
8680         (let ((mail-parse-charset gnus-newsgroup-charset)
8681               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8682               (summary-buffer gnus-summary-buffer)
8683               references point)
8684           (gnus-set-global-variables)
8685           (when (gnus-group-read-only-p)
8686             (error "The current newsgroup does not support article encrypt"))
8687           (gnus-summary-show-article t)
8688           (setq references
8689               (or (mail-header-references gnus-current-headers) ""))
8690           (set-buffer gnus-article-buffer)
8691           (let* ((inhibit-read-only t)
8692                  (headers
8693                   (mapcar (lambda (field)
8694                             (and (save-restriction
8695                                    (message-narrow-to-head)
8696                                    (goto-char (point-min))
8697                                    (search-forward field nil t))
8698                                  (prog2
8699                                      (message-narrow-to-field)
8700                                      (buffer-string)
8701                                    (delete-region (point-min) (point-max))
8702                                    (widen))))
8703                           '("Content-Type:" "Content-Transfer-Encoding:"
8704                             "Content-Disposition:"))))
8705             (message-narrow-to-head)
8706             (message-remove-header "MIME-Version")
8707             (goto-char (point-max))
8708             (setq point (point))
8709             (insert (apply 'concat headers))
8710             (widen)
8711             (narrow-to-region point (point-max))
8712             (let ((message-options message-options))
8713               (message-options-set 'message-sender user-mail-address)
8714               (message-options-set 'message-recipients user-mail-address)
8715               (message-options-set 'message-sign-encrypt 'not)
8716               (funcall func))
8717             (goto-char (point-min))
8718             (insert "MIME-Version: 1.0\n")
8719             (widen)
8720             (gnus-summary-edit-article-done
8721              references nil summary-buffer t))
8722           (when gnus-keep-backlog
8723             (gnus-backlog-remove-article
8724              (car gnus-article-current) (cdr gnus-article-current)))
8725           (gnus-flush-original-article-buffer)
8726           (when gnus-use-cache
8727             (gnus-cache-update-article
8728              (car gnus-article-current) (cdr gnus-article-current))))))))
8729
8730 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8731   "The following specs can be used:
8732 %t  The security MIME type
8733 %i  Additional info
8734 %d  Details
8735 %D  Details if button is pressed")
8736
8737 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8738   "The following specs can be used:
8739 %t  The security MIME type
8740 %i  Additional info
8741 %d  Details
8742 %D  Details if button is pressed")
8743
8744 (defvar gnus-mime-security-button-line-format-alist
8745   '((?t gnus-tmp-type ?s)
8746     (?i gnus-tmp-info ?s)
8747     (?d gnus-tmp-details ?s)
8748     (?D gnus-tmp-pressed-details ?s)))
8749
8750 (defvar gnus-mime-security-button-commands
8751   '((gnus-article-press-button "\r" "Show Detail")
8752     (undefined "v")
8753     (undefined "t")
8754     (undefined "C")
8755     (gnus-mime-security-save-part "o" "Save...")
8756     (undefined "\C-o")
8757     (undefined "r")
8758     (undefined "d")
8759     (undefined "c")
8760     (undefined "i")
8761     (undefined "E")
8762     (undefined "e")
8763     (undefined "p")
8764     (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8765     (undefined ".")))
8766
8767 (defvar gnus-mime-security-button-map
8768   (let ((map (make-sparse-keymap)))
8769     (define-key map gnus-mouse-2 'gnus-article-push-button)
8770     (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8771     (dolist (c gnus-mime-security-button-commands)
8772       (define-key map (cadr c) (car c)))
8773     map))
8774
8775 (easy-menu-define
8776   gnus-mime-security-button-menu gnus-mime-security-button-map
8777   "Security button menu."
8778   `("Security Part"
8779     ,@(delq nil
8780             (mapcar (lambda (c)
8781                       (unless (eq (car c) 'undefined)
8782                         (vector (caddr c) (car c) :active t)))
8783                     gnus-mime-security-button-commands))))
8784
8785 (defun gnus-mime-security-button-menu (event prefix)
8786   "Construct a context-sensitive menu of security commands."
8787   (interactive "e\nP")
8788   (save-window-excursion
8789     (let ((pos (event-start event)))
8790       (select-window (posn-window pos))
8791       (goto-char (posn-point pos))
8792       (gnus-article-check-buffer)
8793       (popup-menu gnus-mime-security-button-menu nil prefix))))
8794
8795 (defvar gnus-mime-security-details-buffer nil)
8796
8797 (defvar gnus-mime-security-button-pressed nil)
8798
8799 (defvar gnus-mime-security-show-details-inline t
8800   "If non-nil, show details in the article buffer.")
8801
8802 (defun gnus-mime-security-verify-or-decrypt (handle)
8803   (mm-remove-parts (cdr handle))
8804   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8805         point (inhibit-read-only t))
8806     (if region
8807         (goto-char (car region)))
8808     (setq point (point))
8809     (with-current-buffer (mm-handle-multipart-original-buffer handle)
8810       (let* ((mm-verify-option 'known)
8811              (mm-decrypt-option 'known)
8812              (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8813         (unless (eq nparts (cdr handle))
8814           (mm-destroy-parts (cdr handle))
8815           (setcdr handle nparts))))
8816     (gnus-mime-display-security handle)
8817     (when region
8818       (delete-region (point) (cdr region))
8819       (set-marker (car region) nil)
8820       (set-marker (cdr region) nil))
8821     (goto-char point)))
8822
8823 (defun gnus-mime-security-show-details (handle)
8824   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8825     (if (not details)
8826         (gnus-message 5 "No details.")
8827       (if gnus-mime-security-show-details-inline
8828           (let ((gnus-mime-security-button-pressed
8829                  (not (get-text-property (point) 'gnus-mime-details)))
8830                 (gnus-mime-security-button-line-format
8831                  (get-text-property (point) 'gnus-line-format))
8832                 (inhibit-read-only t))
8833             (forward-char -1)
8834             (while (eq (get-text-property (point) 'gnus-line-format)
8835                        gnus-mime-security-button-line-format)
8836               (forward-char -1))
8837             (forward-char)
8838             (save-restriction
8839               (narrow-to-region (point) (point))
8840               (gnus-insert-mime-security-button handle))
8841             (delete-region (point)
8842                            (or (text-property-not-all
8843                                 (point) (point-max)
8844                                 'gnus-line-format
8845                                 gnus-mime-security-button-line-format)
8846                                (point-max))))
8847         ;; Not inlined.
8848         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8849             (with-current-buffer gnus-mime-security-details-buffer
8850               (erase-buffer)
8851               t)
8852           (setq gnus-mime-security-details-buffer
8853                 (gnus-get-buffer-create "*MIME Security Details*")))
8854         (with-current-buffer gnus-mime-security-details-buffer
8855           (insert details)
8856           (goto-char (point-min)))
8857         (pop-to-buffer gnus-mime-security-details-buffer)))))
8858
8859 (defun gnus-mime-security-press-button (handle)
8860   (save-excursion
8861     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8862         (gnus-mime-security-show-details handle)
8863       (gnus-mime-security-verify-or-decrypt handle))))
8864
8865 (defun gnus-insert-mime-security-button (handle &optional displayed)
8866   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8867          (gnus-tmp-type
8868           (concat
8869            (or (nth 2 (assoc protocol mm-verify-function-alist))
8870                (nth 2 (assoc protocol mm-decrypt-function-alist))
8871                "Unknown")
8872            (if (equal (car handle) "multipart/signed")
8873                " Signed" " Encrypted")
8874            " Part"))
8875          (gnus-tmp-info
8876           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8877               "Undecided"))
8878          (gnus-tmp-details
8879           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8880          gnus-tmp-pressed-details
8881          b e)
8882     (setq gnus-tmp-details
8883           (if gnus-tmp-details
8884               (concat "\n" gnus-tmp-details)
8885             ""))
8886     (setq gnus-tmp-pressed-details
8887           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8888     (unless (bolp)
8889       (insert "\n"))
8890     (setq b (point))
8891     (gnus-eval-format
8892      gnus-mime-security-button-line-format
8893      gnus-mime-security-button-line-format-alist
8894      `(keymap ,gnus-mime-security-button-map
8895          gnus-callback gnus-mime-security-press-button
8896          gnus-line-format ,gnus-mime-security-button-line-format
8897          gnus-mime-details ,gnus-mime-security-button-pressed
8898          article-type annotation
8899          gnus-data ,handle))
8900     (setq e (if (bolp)
8901                 ;; Exclude a newline.
8902                 (1- (point))
8903               (point)))
8904     (when gnus-article-button-face
8905       (gnus-overlay-put (gnus-make-overlay b e nil t)
8906                         'face gnus-article-button-face))
8907     (widget-convert-button
8908      'link b e
8909      :mime-handle handle
8910      :action 'gnus-widget-press-button
8911      :button-keymap gnus-mime-security-button-map
8912      :help-echo
8913      (lambda (widget)
8914        ;; Needed to properly clear the message due to a bug in
8915        ;; wid-edit (XEmacs only).
8916        (when (boundp 'help-echo-owns-message)
8917          (setq help-echo-owns-message t))
8918        (format
8919         "%S: show detail; %S: more options"
8920         (aref gnus-mouse-2 0)
8921         (aref gnus-down-mouse-3 0))))))
8922
8923 (defun gnus-mime-display-security (handle)
8924   (save-restriction
8925     (narrow-to-region (point) (point))
8926     (unless (gnus-unbuttonized-mime-type-p (car handle))
8927       (gnus-insert-mime-security-button handle))
8928     (gnus-mime-display-part (cadr handle))
8929     (unless (bolp)
8930       (insert "\n"))
8931     (unless (gnus-unbuttonized-mime-type-p (car handle))
8932       (let ((gnus-mime-security-button-line-format
8933              gnus-mime-security-button-end-line-format))
8934         (gnus-insert-mime-security-button handle)))
8935     (mm-set-handle-multipart-parameter
8936      handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8937     (goto-char (point-max))))
8938
8939 (defun gnus-mime-security-run-function (function)
8940   "Run FUNCTION with the security part under point."
8941   (gnus-article-check-buffer)
8942   (let ((data (get-text-property (point) 'gnus-data))
8943         buffer handle)
8944     (when (and (stringp (car-safe data))
8945                (setq buffer (mm-handle-multipart-original-buffer data))
8946                (setq handle (cadr data)))
8947       (if (bufferp (mm-handle-buffer handle))
8948           (progn
8949             (setq handle (cons buffer (copy-sequence (cdr handle))))
8950             (mm-handle-set-undisplayer handle nil))
8951         (setq handle (mm-make-handle
8952                       buffer
8953                       (mm-handle-multipart-ctl-parameter handle 'protocol)
8954                       nil nil nil nil nil nil)))
8955       (funcall function handle))))
8956
8957 (defun gnus-mime-security-save-part ()
8958   "Save the security part under point."
8959   (interactive)
8960   (gnus-mime-security-run-function 'mm-save-part))
8961
8962 (defun gnus-mime-security-pipe-part ()
8963   "Pipe the security part under point to a process."
8964   (interactive)
8965   (gnus-mime-security-run-function 'mm-pipe-part))
8966
8967 (gnus-ems-redefine)
8968
8969 (provide 'gnus-art)
8970
8971 (run-hooks 'gnus-art-load-hook)
8972
8973 ;;; gnus-art.el ends here