lpath.el: Fbind cursor-sensor-mode for XEmacs
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2015 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 (autoload 'url-expand-file-name "url-expand")
55
56 (defgroup gnus-article nil
57   "Article display."
58   :link '(custom-manual "(gnus)Article Buffer")
59   :group 'gnus)
60
61 (defgroup gnus-article-treat nil
62   "Treating article parts."
63   :link '(custom-manual "(gnus)Article Hiding")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-hiding nil
67   "Hiding article parts."
68   :link '(custom-manual "(gnus)Article Hiding")
69   :group 'gnus-article)
70
71 (defgroup gnus-article-highlight nil
72   "Article highlighting."
73   :link '(custom-manual "(gnus)Article Highlighting")
74   :group 'gnus-article
75   :group 'gnus-visual)
76
77 (defgroup gnus-article-signature nil
78   "Article signatures."
79   :link '(custom-manual "(gnus)Article Signature")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-headers nil
83   "Article headers."
84   :link '(custom-manual "(gnus)Hiding Headers")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-washing nil
88   "Special commands on articles."
89   :link '(custom-manual "(gnus)Article Washing")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-emphasis nil
93   "Fontisizing articles."
94   :link '(custom-manual "(gnus)Article Fontisizing")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-saving nil
98   "Saving articles."
99   :link '(custom-manual "(gnus)Saving Articles")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-mime nil
103   "Worshiping the MIME wonder."
104   :link '(custom-manual "(gnus)Using MIME")
105   :group 'gnus-article)
106
107 (defgroup gnus-article-buttons nil
108   "Pushable buttons in the article buffer."
109   :link '(custom-manual "(gnus)Article Buttons")
110   :group 'gnus-article)
111
112 (defgroup gnus-article-various nil
113   "Other article options."
114   :link '(custom-manual "(gnus)Misc Article")
115   :group 'gnus-article)
116
117 (defcustom gnus-ignored-headers
118   (mapcar
119    (lambda (header)
120      (concat "^" header ":"))
121    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127      "X-Attribution" "X-Originating-IP" "Delivered-To"
128      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144      "List-[A-Za-z]+" "X-Listprocessor-Version"
145      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147      "X-Received" "Content-length" "X-precedence"
148      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153      "X-Content-length" "X-Posting-Agent" "Original-Received"
154      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
158      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161      "Envelope-Sender" "Envelope-Recipients"))
162   "*All headers that start with this regexp will be hidden.
163 This variable can also be a list of regexps of headers to be ignored.
164 If `gnus-visible-headers' is non-nil, this variable will be ignored."
165   :type '(choice regexp
166                  (repeat regexp))
167   :group 'gnus-article-hiding)
168
169 (defcustom gnus-visible-headers
170   "^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:"
171   "*All headers that do not match this regexp will be hidden.
172 This variable can also be a list of regexp of headers to remain visible.
173 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174   :type '(choice
175           (repeat :value-to-internal (lambda (widget value)
176                                        (custom-split-regexp-maybe value))
177                   :match (lambda (widget value)
178                            (or (stringp value)
179                                (widget-editable-list-match widget value)))
180                   regexp)
181           (const :tag "Use gnus-ignored-headers" nil)
182           regexp)
183   :group 'gnus-article-hiding)
184
185 (defcustom gnus-sorted-header-list
186   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
187     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
188   "*This variable is a list of regular expressions.
189 If it is non-nil, headers that match the regular expressions will
190 be placed first in the article buffer in the sequence specified by
191 this list."
192   :type '(repeat regexp)
193   :group 'gnus-article-hiding)
194
195 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
196   "Headers that are only to be displayed if they have interesting data.
197 Possible values in this list are:
198
199   'empty       Headers with no content.
200   'newsgroups  Newsgroup identical to Gnus group.
201   'to-address  To identical to To-address.
202   'to-list     To identical to To-list.
203   'cc-list     CC identical to To-list.
204   'followup-to Followup-to identical to Newsgroups.
205   'reply-to    Reply-to identical to From.
206   'date        Date less than four days old.
207   'long-to     To and/or Cc longer than 1024 characters.
208   'many-to     Multiple To and/or Cc."
209   :type '(set (const :tag "Headers with no content." empty)
210               (const :tag "Newsgroups identical to Gnus group." newsgroups)
211               (const :tag "To identical to To-address." to-address)
212               (const :tag "To identical to To-list." to-list)
213               (const :tag "CC identical to To-list." cc-list)
214               (const :tag "Followup-to identical to Newsgroups." followup-to)
215               (const :tag "Reply-to identical to From." reply-to)
216               (const :tag "Date less than four days old." date)
217               (const :tag "To and/or Cc longer than 1024 characters." long-to)
218               (const :tag "Multiple To and/or Cc headers." many-to))
219   :group 'gnus-article-hiding)
220
221 (defcustom gnus-article-skip-boring nil
222   "Skip over text that is not worth reading.
223 By default, if you set this t, then Gnus will display citations and
224 signatures, but will never scroll down to show you a page consisting
225 only of boring text.  Boring text is controlled by
226 `gnus-article-boring-faces'."
227   :version "22.1"
228   :type 'boolean
229   :group 'gnus-article-hiding)
230
231 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
232   "Regexp matching signature separator.
233 This can also be a list of regexps.  In that case, it will be checked
234 from head to tail looking for a separator.  Searches will be done from
235 the end of the buffer."
236   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
237                  (regexp)
238                  (repeat :tag "List of regexp" regexp))
239   :group 'gnus-article-signature)
240
241 (defcustom gnus-signature-limit nil
242   "Provide a limit to what is considered a signature.
243 If it is a number, no signature may not be longer (in characters) than
244 that number.  If it is a floating point number, no signature may be
245 longer (in lines) than that number.  If it is a function, the function
246 will be called without any parameters, and if it returns nil, there is
247 no signature in the buffer.  If it is a string, it will be used as a
248 regexp.  If it matches, the text in question is not a signature.
249
250 This can also be a list of the above values."
251   :type '(choice (const nil)
252                  (integer :value 200)
253                  (number :value 4.0)
254                  function
255                  (regexp :value ".*"))
256   :group 'gnus-article-signature)
257
258 (defcustom gnus-hidden-properties
259   ;; We use to have `intangible' here as well, but Emacs's command loop moves
260   ;; point out of invisible text anyway, so `intangible' is clearly not
261   ;; needed there.  And XEmacs doesn't handle `intangible' anyway.
262   '(invisible t)
263   "Property list to use for hiding text."
264   :type 'sexp
265   :group 'gnus-article-hiding)
266
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270   (if (featurep 'xemacs)
271       (if (or (gnus-image-type-available-p 'xface)
272               (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 | ee -")
277     (if (gnus-image-type-available-p 'pbm)
278         'gnus-display-x-face-in-from
279       "{ echo \
280 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
281 ; uncompface; } | icontopbm | display -"))
282   "*String or function to be executed to display an X-Face header.
283 If it is a string, the command will be executed in a sub-shell
284 asynchronously.  The compressed face will be piped to this command."
285   :type `(choice string
286                  (function-item gnus-display-x-face-in-from)
287                  function)
288   :version "21.1"
289   :group 'gnus-picon
290   :group 'gnus-article-washing)
291
292 (defcustom gnus-article-x-face-too-ugly nil
293   "Regexp matching posters whose face shouldn't be shown automatically."
294   :type '(choice regexp (const nil))
295   :group 'gnus-article-washing)
296
297 (defcustom gnus-article-banner-alist nil
298   "Banner alist for stripping.
299 For example,
300      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301   :version "21.1"
302   :type '(repeat (cons symbol regexp))
303   :group 'gnus-article-washing)
304
305 (gnus-define-group-parameter
306  banner
307  :variable-document
308  "Alist of regexps (to match group names) and banner."
309  :variable-group gnus-article-washing
310  :parameter-type
311  '(choice :tag "Banner"
312           :value nil
313           (const :tag "Remove signature" signature)
314           (symbol :tag "Item in `gnus-article-banner-alist'" none)
315           regexp
316           (const :tag "None" nil))
317  :parameter-document
318  "If non-nil, specify how to remove `banners' from articles.
319
320 Symbol `signature' means to remove signatures delimited by
321 `gnus-signature-separator'.  Any other symbol is used to look up a
322 regular expression to match the banner in `gnus-article-banner-alist'.
323 A string is used as a regular expression to match the banner
324 directly.")
325
326 (defcustom gnus-article-address-banner-alist nil
327   "Alist of mail addresses and banners.
328 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
329 to match a mail address in the From: header, BANNER is one of a symbol
330 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
331 If ADDRESS matches author's mail address, it will remove things like
332 advertisements.  For example:
333
334 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 "
336   :type '(repeat
337           (cons
338            (regexp :tag "Address")
339            (choice :tag "Banner" :value nil
340                    (const :tag "Remove signature" signature)
341                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
342                    regexp
343                    (const :tag "None" nil))))
344   :version "22.1"
345   :group 'gnus-article-washing)
346
347 (defmacro gnus-emphasis-custom-with-format (&rest body)
348   `(let ((format "\
349 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
350 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351      ,@body))
352
353 (defun gnus-emphasis-custom-value-to-external (value)
354   (gnus-emphasis-custom-with-format
355    (if (consp (car value))
356        (list (format format (car (car value)) (cdr (car value)))
357              2
358              (if (nth 1 value) 2 3)
359              (nth 2 value))
360      value)))
361
362 (defun gnus-emphasis-custom-value-to-internal (value)
363   (gnus-emphasis-custom-with-format
364    (let ((regexp (concat "\\`"
365                          (format (regexp-quote format)
366                                  "\\([^()]+\\)" "\\([^()]+\\)")
367                          "\\'"))
368          pattern)
369      (if (string-match regexp (setq pattern (car value)))
370          (list (cons (match-string 1 pattern) (match-string 2 pattern))
371                (= (nth 2 value) 2)
372                (nth 3 value))
373        value))))
374
375 (defcustom gnus-emphasis-alist
376   (let ((types
377          '(("\\*" "\\*" bold nil 2)
378            ("_" "_" underline)
379            ("/" "/" italic)
380            ("_/" "/_" underline-italic)
381            ("_\\*" "\\*_" underline-bold)
382            ("\\*/" "/\\*" bold-italic)
383            ("_\\*/" "/\\*_" underline-bold-italic))))
384     (nconc
385      (gnus-emphasis-custom-with-format
386       (mapcar (lambda (spec)
387                 (list (format format (car spec) (cadr spec))
388                       (or (nth 3 spec) 2)
389                       (or (nth 4 spec) 3)
390                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391               types))
392      '(;; I've never seen anyone use this strikethru convention whereas I've
393        ;; several times seen it triggered by normal text.  --Stef
394        ;; Miles suggests that this form is sometimes used but for italics,
395        ;; so maybe we should map it to `italic'.
396        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
397        ;; 2 3 gnus-emphasis-strikethru)
398        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
399         2 3 gnus-emphasis-underline))))
400   "*Alist that says how to fontify certain phrases.
401 Each item looks like this:
402
403   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
404
405 The first element is a regular expression to be matched.  The second
406 is a number that says what regular expression grouping used to find
407 the entire emphasized word.  The third is a number that says what
408 regexp grouping should be displayed and highlighted.  The fourth
409 is the face used for highlighting."
410   :type
411   '(repeat
412     (menu-choice
413      :format "%[Customizing Style%]\n%v"
414      :indent 2
415      (group :tag "Default"
416             :value ("" 0 0 default)
417             :value-create
418             (lambda (widget)
419               (let ((value (widget-get
420                             (cadr (widget-get (widget-get widget :parent)
421                                               :args))
422                             :value)))
423                 (if (not (eq (nth 2 value) 'default))
424                     (widget-put
425                      widget
426                      :value
427                      (gnus-emphasis-custom-value-to-external value))))
428               (widget-group-value-create widget))
429             regexp
430             (integer :format "Match group: %v")
431             (integer :format "Emphasize group: %v")
432             face)
433      (group :tag "Simple"
434             :value (("_" . "_") nil default)
435             (cons :format "%v"
436                   (regexp :format "Start regexp: %v")
437                   (regexp :format "End regexp: %v"))
438             (boolean :format "Show start and end patterns: %[%v%]\n"
439                      :on " On " :off " Off ")
440             face)))
441   :get (lambda (symbol)
442          (mapcar 'gnus-emphasis-custom-value-to-internal
443                  (default-value symbol)))
444   :set (lambda (symbol value)
445          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446                                      value)))
447   :group 'gnus-article-emphasis)
448
449 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
450   "A regexp to describe whitespace which should not be emphasized.
451 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
452 The former avoids underlining of leading and trailing whitespace,
453 and the latter avoids underlining any whitespace at all."
454   :version "21.1"
455   :group 'gnus-article-emphasis
456   :type 'regexp)
457
458 (defface gnus-emphasis-bold '((t (:bold t)))
459   "Face used for displaying strong emphasized text (*word*)."
460   :group 'gnus-article-emphasis)
461
462 (defface gnus-emphasis-italic '((t (:italic t)))
463   "Face used for displaying italic emphasized text (/word/)."
464   :group 'gnus-article-emphasis)
465
466 (defface gnus-emphasis-underline '((t (:underline t)))
467   "Face used for displaying underlined emphasized text (_word_)."
468   :group 'gnus-article-emphasis)
469
470 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
471   "Face used for displaying underlined bold emphasized text (_*word*_)."
472   :group 'gnus-article-emphasis)
473
474 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
475   "Face used for displaying underlined italic emphasized text (_/word/_)."
476   :group 'gnus-article-emphasis)
477
478 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
479   "Face used for displaying bold italic emphasized text (/*word*/)."
480   :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-underline-bold-italic
483   '((t (:bold t :italic t :underline t)))
484   "Face used for displaying underlined bold italic emphasized text.
485 Example: (_/*word*/_)."
486   :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
489                                       '((t (:strikethru t)))
490                                     '((t (:strike-through t))))
491   "Face used for displaying strike-through text (-word-)."
492   :group 'gnus-article-emphasis)
493
494 (defface gnus-emphasis-highlight-words
495   '((t (:background "black" :foreground "yellow")))
496   "Face used for displaying highlighted words."
497   :group 'gnus-article-emphasis)
498
499 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
500   "Format for display of Date headers in article bodies.
501 See `format-time-string' for the possible values.
502
503 The variable can also be function, which should return a complete Date
504 header.  The function is called with one argument, the time, which can
505 be fed to `format-time-string'."
506   :type '(choice string function)
507   :link '(custom-manual "(gnus)Article Date")
508   :group 'gnus-article-washing)
509
510 (defcustom gnus-save-all-headers t
511   "*If non-nil, don't remove any headers before saving.
512 This will be overridden by the `:headers' property that the symbol of
513 the saver function, which is specified by `gnus-default-article-saver',
514 might have."
515   :group 'gnus-article-saving
516   :type 'boolean)
517
518 (defcustom gnus-prompt-before-saving 'always
519   "*This variable says how much prompting is to be done when saving articles.
520 If it is nil, no prompting will be done, and the articles will be
521 saved to the default files.  If this variable is `always', each and
522 every article that is saved will be preceded by a prompt, even when
523 saving large batches of articles.  If this variable is neither nil not
524 `always', there the user will be prompted once for a file name for
525 each invocation of the saving commands."
526   :group 'gnus-article-saving
527   :type '(choice (item always)
528                  (item :tag "never" nil)
529                  (sexp :tag "once" :format "%t\n" :value t)))
530
531 (defcustom gnus-saved-headers gnus-visible-headers
532   "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving.  This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539   :group 'gnus-article-saving
540   :type 'regexp)
541
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544   "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
547
548 Gnus provides the following functions:
549
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
559
560 The symbol of each function may have the following properties:
561
562 * :decode
563 The value non-nil means save decoded articles.  This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
567
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file.  This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file.  This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
574
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved.  If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580   :group 'gnus-article-saving
581   :type '(radio (function-item gnus-summary-save-in-rmail)
582                 (function-item gnus-summary-save-in-mail)
583                 (function-item gnus-summary-save-in-folder)
584                 (function-item gnus-summary-save-in-file)
585                 (function-item gnus-summary-save-body-in-file)
586                 (function-item gnus-summary-save-in-vm)
587                 (function-item gnus-summary-write-to-file)
588                 (function-item gnus-summary-write-body-to-file)
589                 (function-item gnus-summary-save-in-pipe)
590                 (function)))
591
592 (defcustom gnus-article-save-coding-system
593   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597   "Coding system used to save decoded articles to a file.
598
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text.  This is used by the
601 commands including:
602
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
607
608 and the functions to which you may set `gnus-default-article-saver':
609
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
614
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil.  Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619   :group 'gnus-article-saving
620   :type `(choice
621           :format "%{%t%}:\n %[Value Menu%] %v"
622           (const :tag "Save raw articles" nil)
623           ,@(delq nil
624                   (mapcar
625                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626                    '((const :tag "UTF-8" utf-8)
627                      (const :tag "iso-2022-7bit" iso-2022-7bit)
628                      (const :tag "Emacs internal" emacs-mule)
629                      (const :tag "escape-quoted" escape-quoted))))
630           (symbol :tag "Coding system")))
631
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633   "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635   :group 'gnus-article-saving
636   :type 'function)
637
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639   "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641   :group 'gnus-article-saving
642   :type 'function)
643
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645   "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647   :group 'gnus-article-saving
648   :type 'function)
649
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651   "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654   :group 'gnus-article-saving
655   :type 'function)
656
657 (defcustom gnus-split-methods
658   '((gnus-article-archive-name)
659     (gnus-article-nndoc-name))
660   "*Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
664
665  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
667
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
671
672 If the match is a string, it is used as a regexp match on the
673 article.  If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter.  If it is a list, it will be evalled in the same buffer.
676
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680   :group 'gnus-article-saving
681   :type '(repeat (choice (list :value (fun) function)
682                          (cons :value ("" "") regexp (repeat string))
683                          (sexp :value nil))))
684
685 (defcustom gnus-page-delimiter "^\^L"
686   "*Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689   :type 'regexp
690   :group 'gnus-article-various)
691
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693   "*The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
695
696 The following additional specs are available:
697
698 %w  The article washing status.
699 %m  The number of MIME parts in the article."
700   :version "24.1"
701   :type 'string
702   :group 'gnus-article-various)
703
704 (defcustom gnus-article-mode-hook nil
705   "*A hook for Gnus article mode."
706   :type 'hook
707   :group 'gnus-article-various)
708
709 (when (featurep 'xemacs)
710   ;; Extracted from gnus-xmas-define in order to preserve user settings
711   (when (fboundp 'turn-off-scroll-in-place)
712     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
713   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
714   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
715
716 (defcustom gnus-article-menu-hook nil
717   "*Hook run after the creation of the article mode menu."
718   :type 'hook
719   :group 'gnus-article-various)
720
721 (defcustom gnus-article-prepare-hook nil
722   "*A hook called after an article has been prepared in the article buffer."
723   :type 'hook
724   :group 'gnus-article-various)
725
726 (defcustom gnus-copy-article-ignored-headers nil
727   "List of headers to be removed when copying an article.
728 Each element is a regular expression."
729   :version "23.1" ;; No Gnus
730   :type '(repeat regexp)
731   :group 'gnus-article-various)
732
733 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
734                         "Gnus 5.10 (Emacs 22.1)")
735
736 (defface gnus-button
737   '((t (:weight bold)))
738   "Face used for highlighting a button in the article buffer."
739   :group 'gnus-article-buttons)
740
741 (defcustom gnus-article-button-face 'gnus-button
742   "Face used for highlighting buttons in the article buffer.
743
744 An article button is a piece of text that you can activate by pressing
745 `RET' or `mouse-2' above it."
746   :type 'face
747   :group 'gnus-article-buttons)
748
749 (defcustom gnus-article-mouse-face 'highlight
750   "Face used for mouse highlighting in the article buffer.
751
752 Article buttons will be displayed in this face when the cursor is
753 above them."
754   :type 'face
755   :group 'gnus-article-buttons)
756
757 (defcustom gnus-signature-face 'gnus-signature
758   "Face used for highlighting a signature in the article buffer.
759 Obsolete; use the face `gnus-signature' for customizations instead."
760   :type 'face
761   :group 'gnus-article-highlight
762   :group 'gnus-article-signature)
763
764 (defface gnus-signature
765   '((t
766      (:italic t)))
767   "Face used for highlighting a signature in the article buffer."
768   :group 'gnus-article-highlight
769   :group 'gnus-article-signature)
770 ;; backward-compatibility alias
771 (put 'gnus-signature-face 'face-alias 'gnus-signature)
772 (put 'gnus-signature-face 'obsolete-face "22.1")
773
774 (defface gnus-header-from
775   '((((class color)
776       (background dark))
777      (:foreground "PaleGreen1"))
778     (((class color)
779       (background light))
780      (:foreground "red3"))
781     (t
782      (:italic t)))
783   "Face used for displaying from headers."
784   :group 'gnus-article-headers
785   :group 'gnus-article-highlight)
786 ;; backward-compatibility alias
787 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
788 (put 'gnus-header-from-face 'obsolete-face "22.1")
789
790 (defface gnus-header-subject
791   '((((class color)
792       (background dark))
793      (:foreground "SeaGreen1"))
794     (((class color)
795       (background light))
796      (:foreground "red4"))
797     (t
798      (:bold t :italic t)))
799   "Face used for displaying subject headers."
800   :group 'gnus-article-headers
801   :group 'gnus-article-highlight)
802 ;; backward-compatibility alias
803 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
804 (put 'gnus-header-subject-face 'obsolete-face "22.1")
805
806 (defface gnus-header-newsgroups
807   '((((class color)
808       (background dark))
809      (:foreground "yellow" :italic t))
810     (((class color)
811       (background light))
812      (:foreground "MidnightBlue" :italic t))
813     (t
814      (:italic t)))
815   "Face used for displaying newsgroups headers.
816 In the default setup this face is only used for crossposted
817 articles."
818   :group 'gnus-article-headers
819   :group 'gnus-article-highlight)
820 ;; backward-compatibility alias
821 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
822 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
823
824 (defface gnus-header-name
825   '((((class color)
826       (background dark))
827      (:foreground "SpringGreen2"))
828     (((class color)
829       (background light))
830      (:foreground "maroon"))
831     (t
832      (:bold t)))
833   "Face used for displaying header names."
834   :group 'gnus-article-headers
835   :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
838 (put 'gnus-header-name-face 'obsolete-face "22.1")
839
840 (defface gnus-header-content
841   '((((class color)
842       (background dark))
843      (:foreground "SpringGreen1" :italic t))
844     (((class color)
845       (background light))
846      (:foreground "indianred4" :italic t))
847     (t
848      (:italic t)))  "Face used for displaying header content."
849   :group 'gnus-article-headers
850   :group 'gnus-article-highlight)
851 ;; backward-compatibility alias
852 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
853 (put 'gnus-header-content-face 'obsolete-face "22.1")
854
855 (defcustom gnus-header-face-alist
856   '(("From" nil gnus-header-from)
857     ("Subject" nil gnus-header-subject)
858     ("Newsgroups:.*," nil gnus-header-newsgroups)
859     ("" gnus-header-name gnus-header-content))
860   "*Controls highlighting of article headers.
861
862 An alist of the form (HEADER NAME CONTENT).
863
864 HEADER is a regular expression which should match the name of a
865 header and NAME and CONTENT are either face names or nil.
866
867 The name of each header field will be displayed using the face
868 specified by the first element in the list where HEADER matches
869 the header name and NAME is non-nil.  Similarly, the content will
870 be displayed by the first non-nil matching CONTENT face."
871   :group 'gnus-article-headers
872   :group 'gnus-article-highlight
873   :type '(repeat (list (regexp :tag "Header")
874                        (choice :tag "Name"
875                                (item :tag "skip" nil)
876                                (face :value default))
877                        (choice :tag "Content"
878                                (item :tag "skip" nil)
879                                (face :value default)))))
880
881 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
882                                           '((xface . (:face gnus-x-face)))
883                                         '((pbm . (:face gnus-x-face))
884                                           (png . nil)))
885   "Alist of image types and properties applied to Face and X-Face images.
886 Here are examples:
887
888 ;; Specify the altitude of Face images in the From header.
889 \(setq gnus-face-properties-alist
890       '((pbm . (:face gnus-x-face :ascent 80))
891         (png . (:ascent 80))))
892
893 ;; Show Face images as pressed buttons.
894 \(setq gnus-face-properties-alist
895       '((pbm . (:face gnus-x-face :relief -2))
896         (png . (:relief -2))))
897
898 See the manual for the valid properties for various image types.
899 Currently, `pbm' is used for X-Face images and `png' is used for Face
900 images in Emacs.  Only the `:face' property is effective on the `xface'
901 image type in XEmacs if it is built with the libcompface library."
902   :version "23.1" ;; No Gnus
903   :group 'gnus-article-headers
904   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
905
906 (defcustom gnus-article-decode-hook
907   '(article-decode-charset article-decode-encoded-words
908                            article-decode-group-name article-decode-idna-rhs)
909   "*Hook run to decode charsets in articles."
910   :group 'gnus-article-headers
911   :type 'hook)
912
913 (defcustom gnus-display-mime-function 'gnus-display-mime
914   "Function to display MIME articles."
915   :group 'gnus-article-mime
916   :type 'function)
917
918 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
919   "Function used to decode headers.")
920
921 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
922   "Function used to decode addresses.")
923
924 (defvar gnus-article-dumbquotes-map
925   '((?\200 "EUR")
926     (?\202 ",")
927     (?\203 "f")
928     (?\204 ",,")
929     (?\205 "...")
930     (?\213 "<")
931     (?\214 "OE")
932     (?\221 "`")
933     (?\222 "'")
934     (?\223 "``")
935     (?\224 "\"")
936     (?\225 "*")
937     (?\226 "-")
938     (?\227 "--")
939     (?\230 "~")
940     (?\231 "(TM)")
941     (?\233 ">")
942     (?\234 "oe")
943     (?\264 "'"))
944   "Table for MS-to-Latin1 translation.")
945
946 (defcustom gnus-ignored-mime-types nil
947   "List of MIME types that should be ignored by Gnus."
948   :version "21.1"
949   :group 'gnus-article-mime
950   :type '(repeat regexp))
951
952 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
953   "List of MIME types that should not be given buttons when rendered inline.
954 See also `gnus-buttonized-mime-types' which may override this variable.
955 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956   :version "21.1"
957   :group 'gnus-article-mime
958   :type '(repeat regexp))
959
960 (defcustom gnus-buttonized-mime-types nil
961   "List of MIME types that should be given buttons when rendered inline.
962 If set, this variable overrides `gnus-unbuttonized-mime-types'.
963 To see e.g. security buttons you could set this to
964 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
965 this list to display radio buttons that allow you to choose one of two
966 media types those mails include.  See also `mm-discouraged-alternatives'.
967 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968   :version "22.1"
969   :group 'gnus-article-mime
970   :type '(repeat regexp))
971
972 (defcustom gnus-inhibit-mime-unbuttonizing nil
973   "If non-nil, all MIME parts get buttons.
974 When nil (the default value), then some MIME parts do not get buttons,
975 as described by the variables `gnus-buttonized-mime-types' and
976 `gnus-unbuttonized-mime-types'."
977   :version "22.1"
978   :group 'gnus-article-mime
979   :type 'boolean)
980
981 (defcustom gnus-body-boundary-delimiter "_"
982   "String used to delimit header and body.
983 This variable is used by `gnus-article-treat-body-boundary' which can
984 be controlled by `gnus-treat-body-boundary'."
985   :version "22.1"
986   :group 'gnus-article-various
987   :type '(choice (item :tag "None" :value nil)
988                  string))
989
990 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991                                   "/usr/share/picons")
992   "Defines the location of the faces database.
993 For information on obtaining this database of pretty pictures, please
994 see http://www.cs.indiana.edu/picons/ftp/index.html"
995   :version "22.1"
996   :type '(repeat directory)
997   :link '(url-link :tag "download"
998                    "http://www.cs.indiana.edu/picons/ftp/index.html")
999   :link '(custom-manual "(gnus)Picons")
1000   :group 'gnus-picon)
1001
1002 (defun gnus-picons-installed-p ()
1003   "Say whether picons are installed on your machine."
1004   (let ((installed nil))
1005     (dolist (database gnus-picon-databases)
1006       (when (file-exists-p database)
1007         (setq installed t)))
1008     installed))
1009
1010 (defcustom gnus-article-mime-part-function nil
1011   "Function called with a MIME handle as the argument.
1012 This is meant for people who want to do something automatic based
1013 on parts -- for instance, adding Vcard info to a database."
1014   :group 'gnus-article-mime
1015   :type '(choice (const nil)
1016                  function))
1017
1018 (defcustom gnus-mime-multipart-functions nil
1019   "An alist of MIME types to functions to display them."
1020   :version "21.1"
1021   :group 'gnus-article-mime
1022   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1023
1024 (defcustom gnus-article-date-headers '(combined-lapsed)
1025   "A list of Date header formats to display.
1026 Valid formats are `ut' (universal time), `local' (local time
1027 zone), `english' (readable English), `lapsed' (elapsed time),
1028 `combined-lapsed' (both the original date and the elapsed time),
1029 `original' (the original date header), `iso8601' (ISO8601
1030 format), and `user-defined' (a user-defined format defined by the
1031 `gnus-article-time-format' variable).
1032
1033 You have as many date headers as you want in the article buffer.
1034 Some of these headers are updated automatically.  See
1035 `gnus-article-update-date-headers' for details."
1036   :version "24.1"
1037   :group 'gnus-article-headers
1038   :type '(set
1039           (const :tag "Universal time (UT)" ut)
1040           (const :tag "Local time zone" local)
1041           (const :tag "Readable English" english)
1042           (const :tag "Elapsed time" lapsed)
1043           (const :tag "Original and elapsed time" combined-lapsed)
1044           (const :tag "Original date header" original)
1045           (const :tag "ISO8601 format" iso8601)
1046           (const :tag "User-defined" user-defined)))
1047
1048 (defcustom gnus-article-update-date-headers nil
1049   "A number that says how often to update the date header (in seconds).
1050 If nil, don't update it at all."
1051   :version "24.1"
1052   :group 'gnus-article-headers
1053   :type '(choice
1054           (item :tag "Don't update" :value nil)
1055           integer))
1056
1057 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1058   "Function called with a MIME handle as the argument.
1059 This is meant for people who want to view first matched part.
1060 For `undisplayed-alternative' (default), the first undisplayed
1061 part or alternative part is used.  For `undisplayed', the first
1062 undisplayed part is used.  For a function, the first part which
1063 the function return t is used.  For nil, the first part is
1064 used."
1065   :version "21.1"
1066   :group 'gnus-article-mime
1067   :type '(choice
1068           (item :tag "first" :value nil)
1069           (item :tag "undisplayed" :value undisplayed)
1070           (item :tag "undisplayed or alternative"
1071                 :value undisplayed-alternative)
1072           (function)))
1073
1074 (defcustom gnus-mime-action-alist
1075   '(("save to file" . gnus-mime-save-part)
1076     ("save and strip" . gnus-mime-save-part-and-strip)
1077     ("replace with file" . gnus-mime-replace-part)
1078     ("delete part" . gnus-mime-delete-part)
1079     ("display as text" . gnus-mime-inline-part)
1080     ("view the part" . gnus-mime-view-part)
1081     ("pipe to command" . gnus-mime-pipe-part)
1082     ("toggle display" . gnus-article-press-button)
1083     ("toggle display" . gnus-article-view-part-as-charset)
1084     ("view as type" . gnus-mime-view-part-as-type)
1085     ("view internally" . gnus-mime-view-part-internally)
1086     ("view externally" . gnus-mime-view-part-externally))
1087   "An alist of actions that run on the MIME attachment."
1088   :group 'gnus-article-mime
1089   :type '(repeat (cons (string :tag "name")
1090                        (function))))
1091
1092 (defcustom gnus-auto-select-part 1
1093   "Advance to next MIME part when deleting or stripping parts.
1094
1095 When 0, point will be placed on the same part as before.  When
1096 positive (negative), move point forward (backwards) this many
1097 parts.  When nil, redisplay article."
1098   :version "23.1" ;; No Gnus
1099   :group 'gnus-article-mime
1100   :type '(choice (const nil :tag "Redisplay article.")
1101                  (const 1 :tag "Next part.")
1102                  (const 0 :tag "Current part.")
1103                  integer))
1104
1105 ;;;
1106 ;;; The treatment variables
1107 ;;;
1108
1109 (defvar gnus-part-display-hook nil
1110   "Hook called on parts that are to receive treatment.")
1111
1112 (defvar gnus-article-treat-custom
1113   '(choice (const :tag "Off" nil)
1114            (const :tag "On" t)
1115            (const :tag "Header" head)
1116            (const :tag "First" first)
1117            (const :tag "Last" last)
1118            (integer :tag "Less")
1119            (repeat :tag "Groups" regexp)
1120            (sexp :tag "Predicate")))
1121
1122 (defvar gnus-article-treat-head-custom
1123   '(choice (const :tag "Off" nil)
1124            (const :tag "Header" head)))
1125
1126 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127                                    "text/x-patch" "text/html")
1128   "Part types eligible for treatment.")
1129
1130 (defvar gnus-inhibit-treatment nil
1131   "Whether to inhibit treatment.")
1132
1133 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1134   "Highlight the signature.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate.  See Info node `(gnus)Customizing Articles'."
1137   :group 'gnus-article-treat
1138   :link '(custom-manual "(gnus)Customizing Articles")
1139   :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-signature 'highlight t)
1141
1142 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1143   "Add buttons.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate.  See Info node `(gnus)Customizing Articles'."
1146   :group 'gnus-article-treat
1147   :link '(custom-manual "(gnus)Customizing Articles")
1148   :type gnus-article-treat-custom)
1149 (put 'gnus-treat-buttonize 'highlight t)
1150
1151 (defcustom gnus-treat-buttonize-head 'head
1152   "Add buttons to the head.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate.  See Info node `(gnus)Customizing Articles'."
1155   :group 'gnus-article-treat
1156   :link '(custom-manual "(gnus)Customizing Articles")
1157   :type gnus-article-treat-head-custom)
1158 (put 'gnus-treat-buttonize-head 'highlight t)
1159
1160 (defcustom gnus-treat-date 'head
1161   "Display dates according to the `gnus-article-date-headers' variable.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate.  See Info node `(gnus)Customizing Articles'."
1164   :version "24.1"
1165   :group 'gnus-article-treat
1166   :link '(custom-manual "(gnus)Customizing Articles")
1167   :type gnus-article-treat-head-custom)
1168
1169 (defcustom gnus-treat-emphasize 50000
1170   "Emphasize text.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate.  See Info node `(gnus)Customizing Articles'."
1173   :group 'gnus-article-treat
1174   :link '(custom-manual "(gnus)Customizing Articles")
1175   :type gnus-article-treat-custom)
1176 (put 'gnus-treat-emphasize 'highlight t)
1177
1178 (defcustom gnus-treat-strip-cr nil
1179   "Remove carriage returns.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate.  See Info node `(gnus)Customizing Articles'."
1182   :version "22.1"
1183   :group 'gnus-article-treat
1184   :link '(custom-manual "(gnus)Customizing Articles")
1185   :type gnus-article-treat-custom)
1186
1187 (defcustom gnus-treat-unsplit-urls nil
1188   "Remove newlines from within URLs.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate.  See Info node `(gnus)Customizing Articles'."
1191   :version "22.1"
1192   :group 'gnus-article-treat
1193   :link '(custom-manual "(gnus)Customizing Articles")
1194   :type gnus-article-treat-custom)
1195
1196 (defcustom gnus-treat-leading-whitespace nil
1197   "Remove leading whitespace in headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate.  See Info node `(gnus)Customizing Articles'."
1200   :version "22.1"
1201   :group 'gnus-article-treat
1202   :link '(custom-manual "(gnus)Customizing Articles")
1203   :type gnus-article-treat-custom)
1204
1205 (defcustom gnus-treat-hide-headers 'head
1206   "Hide headers.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate.  See Info node `(gnus)Customizing Articles'."
1209   :group 'gnus-article-treat
1210   :link '(custom-manual "(gnus)Customizing Articles")
1211   :type gnus-article-treat-head-custom)
1212
1213 (defcustom gnus-treat-hide-boring-headers nil
1214   "Hide boring headers.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate.  See Info node `(gnus)Customizing Articles'."
1217   :group 'gnus-article-treat
1218   :link '(custom-manual "(gnus)Customizing Articles")
1219   :type gnus-article-treat-head-custom)
1220
1221 (defcustom gnus-treat-hide-signature nil
1222   "Hide the signature.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate.  See Info node `(gnus)Customizing Articles'."
1225   :group 'gnus-article-treat
1226   :link '(custom-manual "(gnus)Customizing Articles")
1227   :type gnus-article-treat-custom)
1228
1229 (defcustom gnus-treat-fill-article nil
1230   "Fill the article.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate.  See Info node `(gnus)Customizing Articles'."
1233   :group 'gnus-article-treat
1234   :link '(custom-manual "(gnus)Customizing Articles")
1235   :type gnus-article-treat-custom)
1236
1237 (defcustom gnus-treat-hide-citation nil
1238   "Hide cited text.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate.  See Info node `(gnus)Customizing Articles'.
1241
1242 See `gnus-article-highlight-citation' for variables used to
1243 control what it hides."
1244   :group 'gnus-article-treat
1245   :link '(custom-manual "(gnus)Customizing Articles")
1246   :type gnus-article-treat-custom)
1247
1248 (defcustom gnus-treat-hide-citation-maybe nil
1249   "Hide cited text according to certain conditions.
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate.  See Info node `(gnus)Customizing Articles'.
1252
1253 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1254 how to control what it hides."
1255   :group 'gnus-article-treat
1256   :link '(custom-manual "(gnus)Customizing Articles")
1257   :type gnus-article-treat-custom)
1258
1259 (defcustom gnus-treat-strip-list-identifiers 'head
1260   "Strip list identifiers from `gnus-list-identifiers`.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate.  See Info node `(gnus)Customizing Articles'."
1263   :version "21.1"
1264   :group 'gnus-article-treat
1265   :link '(custom-manual "(gnus)Customizing Articles")
1266   :type gnus-article-treat-custom)
1267
1268 (gnus-define-group-parameter
1269  list-identifier
1270  :variable-document
1271  "Alist of regexps and correspondent identifiers."
1272  :variable-group gnus-article-washing
1273  :parameter-type
1274  '(choice :tag "Identifier"
1275           :value nil
1276           (symbol :tag "Item in `gnus-list-identifiers'" none)
1277           regexp
1278           (const :tag "None" nil))
1279  :parameter-document
1280  "If non-nil, specify how to remove `identifiers' from articles' subject.
1281
1282 Any symbol is used to look up a regular expression to match the
1283 banner in `gnus-list-identifiers'.  A string is used as a regular
1284 expression to match the identifier directly.")
1285
1286 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1287                         "Gnus 5.10 (Emacs 22.1)")
1288
1289 (defcustom gnus-treat-strip-pem nil
1290   "Strip PEM signatures.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate.  See Info node `(gnus)Customizing Articles'."
1293   :group 'gnus-article-treat
1294   :link '(custom-manual "(gnus)Customizing Articles")
1295   :type gnus-article-treat-custom)
1296
1297 (defcustom gnus-treat-strip-banner t
1298   "Strip banners from articles.
1299 The banner to be stripped is specified in the `banner' group parameter.
1300 Valid values are nil, t, `head', `first', `last', an integer or a
1301 predicate.  See Info node `(gnus)Customizing Articles'."
1302   :group 'gnus-article-treat
1303   :link '(custom-manual "(gnus)Customizing Articles")
1304   :type gnus-article-treat-custom)
1305
1306 (defcustom gnus-treat-highlight-headers 'head
1307   "Highlight the headers.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate.  See Info node `(gnus)Customizing Articles'."
1310   :group 'gnus-article-treat
1311   :link '(custom-manual "(gnus)Customizing Articles")
1312   :type gnus-article-treat-head-custom)
1313 (put 'gnus-treat-highlight-headers 'highlight t)
1314
1315 (defcustom gnus-treat-highlight-citation t
1316   "Highlight cited text.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate.  See Info node `(gnus)Customizing Articles'."
1319   :group 'gnus-article-treat
1320   :link '(custom-manual "(gnus)Customizing Articles")
1321   :type gnus-article-treat-custom)
1322 (put 'gnus-treat-highlight-citation 'highlight t)
1323
1324 (defcustom gnus-treat-strip-headers-in-body t
1325   "Strip the X-No-Archive header line from the beginning of the body.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate.  See Info node `(gnus)Customizing Articles'."
1328   :version "21.1"
1329   :group 'gnus-article-treat
1330   :link '(custom-manual "(gnus)Customizing Articles")
1331   :type gnus-article-treat-custom)
1332
1333 (defcustom gnus-treat-strip-trailing-blank-lines nil
1334   "Strip trailing blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate.  See Info node `(gnus)Customizing Articles'.
1337
1338 When set to t, it also strips trailing blanks in all MIME parts.
1339 Consider to use `last' instead."
1340   :group 'gnus-article-treat
1341   :link '(custom-manual "(gnus)Customizing Articles")
1342   :type gnus-article-treat-custom)
1343
1344 (defcustom gnus-treat-strip-leading-blank-lines nil
1345   "Strip leading blank lines.
1346 Valid values are nil, t, `head', `first', `last', an integer or a
1347 predicate.  See Info node `(gnus)Customizing Articles'.
1348
1349 When set to t, it also strips trailing blanks in all MIME parts."
1350   :group 'gnus-article-treat
1351   :link '(custom-manual "(gnus)Customizing Articles")
1352   :type gnus-article-treat-custom)
1353
1354 (defcustom gnus-treat-strip-multiple-blank-lines nil
1355   "Strip multiple blank lines.
1356 Valid values are nil, t, `head', `first', `last', an integer or a
1357 predicate.  See Info node `(gnus)Customizing Articles'."
1358   :group 'gnus-article-treat
1359   :link '(custom-manual "(gnus)Customizing Articles")
1360   :type gnus-article-treat-custom)
1361
1362 (defcustom gnus-treat-unfold-headers 'head
1363   "Unfold folded header lines.
1364 Valid values are nil, t, `head', `first', `last', an integer or a
1365 predicate.  See Info node `(gnus)Customizing Articles'."
1366   :version "22.1"
1367   :group 'gnus-article-treat
1368   :link '(custom-manual "(gnus)Customizing Articles")
1369   :type gnus-article-treat-custom)
1370
1371 (defcustom gnus-article-unfold-long-headers nil
1372   "If non-nil, allow unfolding headers even if the header is long.
1373 If it is a regexp, only long headers matching this regexp are unfolded.
1374 If it is t, all long headers are unfolded.
1375
1376 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1377   :version "23.1" ;; No Gnus
1378   :group 'gnus-article-treat
1379   :type '(choice (const nil)
1380                  (const :tag "all" t)
1381                  (regexp)))
1382
1383 (defcustom gnus-treat-fold-headers nil
1384   "Fold headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate.  See Info node `(gnus)Customizing Articles'."
1387   :version "22.1"
1388   :group 'gnus-article-treat
1389   :link '(custom-manual "(gnus)Customizing Articles")
1390   :type gnus-article-treat-custom)
1391
1392 (defcustom gnus-treat-fold-newsgroups 'head
1393   "Fold the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate.  See Info node `(gnus)Customizing Articles'."
1396   :version "22.1"
1397   :group 'gnus-article-treat
1398   :link '(custom-manual "(gnus)Customizing Articles")
1399   :type gnus-article-treat-custom)
1400
1401 (defcustom gnus-treat-overstrike t
1402   "Treat overstrike highlighting.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate.  See Info node `(gnus)Customizing Articles'."
1405   :group 'gnus-article-treat
1406   :link '(custom-manual "(gnus)Customizing Articles")
1407   :type gnus-article-treat-custom)
1408 (put 'gnus-treat-overstrike 'highlight t)
1409
1410 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1411   "Treat ANSI SGR control sequences.
1412 Valid values are nil, t, `head', `first', `last', an integer or a
1413 predicate.  See Info node `(gnus)Customizing Articles'."
1414   :group 'gnus-article-treat
1415   :link '(custom-manual "(gnus)Customizing Articles")
1416   :type gnus-article-treat-custom)
1417
1418 (make-obsolete-variable 'gnus-treat-display-xface
1419                         'gnus-treat-display-x-face "Emacs 22.1")
1420
1421 (defcustom gnus-treat-display-x-face
1422   (and (not noninteractive)
1423        (gnus-image-type-available-p 'xbm)
1424        (if (featurep 'xemacs)
1425            (featurep 'xface)
1426          (condition-case nil
1427              (and (string-match "^0x" (shell-command-to-string "uncompface"))
1428                   (executable-find "icontopbm"))
1429            ;; shell-command-to-string may signal an error, e.g. if
1430            ;; shell-file-name is not found.
1431            (error nil)))
1432        'head)
1433   "Display X-Face headers.
1434 Valid values are nil and `head'.
1435 See Info node `(gnus)Customizing Articles' and Info node
1436 `(gnus)X-Face' for details."
1437   :group 'gnus-article-treat
1438   :version "21.1"
1439   :link '(custom-manual "(gnus)Customizing Articles")
1440   :link '(custom-manual "(gnus)X-Face")
1441   :type gnus-article-treat-head-custom
1442   :set (lambda (symbol value)
1443          (set-default
1444           symbol
1445           (cond ((or (boundp symbol) (get symbol 'saved-value))
1446                  value)
1447                 ((boundp 'gnus-treat-display-xface)
1448                  (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450  use gnus-treat-display-x-face instead")
1451                  (default-value 'gnus-treat-display-xface))
1452                 ((get 'gnus-treat-display-xface 'saved-value)
1453                  (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455  use gnus-treat-display-x-face instead")
1456                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1457                 (t
1458                  value)))))
1459 (put 'gnus-treat-display-x-face 'highlight t)
1460
1461 (defcustom gnus-treat-display-face
1462   (and (not noninteractive)
1463        (gnus-image-type-available-p 'png)
1464        'head)
1465   "Display Face headers.
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate.  See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Face' for details."
1469   :group 'gnus-article-treat
1470   :version "22.1"
1471   :link '(custom-manual "(gnus)Customizing Articles")
1472   :link '(custom-manual "(gnus)X-Face")
1473   :type gnus-article-treat-head-custom)
1474 (put 'gnus-treat-display-face 'highlight t)
1475
1476 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477   "Display smileys.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate.  See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Smileys' for details."
1481   :group 'gnus-article-treat
1482   :version "21.1"
1483   :link '(custom-manual "(gnus)Customizing Articles")
1484   :link '(custom-manual "(gnus)Smileys")
1485   :type gnus-article-treat-custom)
1486 (put 'gnus-treat-display-smileys 'highlight t)
1487
1488 (defcustom gnus-treat-from-picon
1489   (if (and (gnus-image-type-available-p 'xpm)
1490            (gnus-picons-installed-p))
1491       'head nil)
1492   "Display picons in the From header.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate.  See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496   :version "22.1"
1497   :group 'gnus-article-treat
1498   :group 'gnus-picon
1499   :link '(custom-manual "(gnus)Customizing Articles")
1500   :link '(custom-manual "(gnus)Picons")
1501   :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-from-picon 'highlight t)
1503
1504 (defcustom gnus-treat-mail-picon
1505   (if (and (gnus-image-type-available-p 'xpm)
1506            (gnus-picons-installed-p))
1507       'head nil)
1508   "Display picons in To and Cc headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate.  See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512   :version "22.1"
1513   :group 'gnus-article-treat
1514   :group 'gnus-picon
1515   :link '(custom-manual "(gnus)Customizing Articles")
1516   :link '(custom-manual "(gnus)Picons")
1517   :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-mail-picon 'highlight t)
1519
1520 (defcustom gnus-treat-newsgroups-picon
1521   (if (and (gnus-image-type-available-p 'xpm)
1522            (gnus-picons-installed-p))
1523       'head nil)
1524   "Display picons in the Newsgroups and Followup-To headers.
1525 Valid values are nil, t, `head', `first', `last', an integer or a
1526 predicate.  See Info node `(gnus)Customizing Articles' and Info
1527 node `(gnus)Picons' for details."
1528   :version "22.1"
1529   :group 'gnus-article-treat
1530   :group 'gnus-picon
1531   :link '(custom-manual "(gnus)Customizing Articles")
1532   :link '(custom-manual "(gnus)Picons")
1533   :type gnus-article-treat-head-custom)
1534 (put 'gnus-treat-newsgroups-picon 'highlight t)
1535
1536 (defcustom gnus-treat-from-gravatar nil
1537   "Display gravatars in the From header.
1538 Valid values are nil, t, `head', `first', `last', an integer or a
1539 predicate.  See Info node `(gnus)Customizing Articles' and Info
1540 node `(gnus)Gravatars' for details."
1541   :version "24.1"
1542   :group 'gnus-article-treat
1543   :group 'gnus-gravatar
1544   :link '(custom-manual "(gnus)Customizing Articles")
1545   :link '(custom-manual "(gnus)Gravatars")
1546   :type gnus-article-treat-head-custom)
1547 (put 'gnus-treat-from-gravatar 'highlight t)
1548
1549 (defcustom gnus-treat-mail-gravatar nil
1550   "Display gravatars in To and Cc headers.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate.  See Info node `(gnus)Customizing Articles' and Info
1553 node `(gnus)Gravatars' for details."
1554   :version "24.1"
1555   :group 'gnus-article-treat
1556   :group 'gnus-gravatar
1557   :link '(custom-manual "(gnus)Customizing Articles")
1558   :link '(custom-manual "(gnus)Gravatars")
1559   :type gnus-article-treat-head-custom)
1560 (put 'gnus-treat-mail-gravatar 'highlight t)
1561
1562 (defcustom gnus-treat-body-boundary
1563   (if (or gnus-treat-newsgroups-picon
1564           gnus-treat-mail-picon
1565           gnus-treat-from-picon
1566           gnus-treat-from-gravatar
1567           gnus-treat-mail-gravatar)
1568       ;; If there's much decoration, the user might prefer a boundary.
1569       'head
1570     nil)
1571   "Draw a boundary at the end of the headers.
1572 Valid values are nil and `head'.
1573 See Info node `(gnus)Customizing Articles' for details."
1574   :version "22.1"
1575   :group 'gnus-article-treat
1576   :link '(custom-manual "(gnus)Customizing Articles")
1577   :type gnus-article-treat-head-custom)
1578
1579 (defcustom gnus-treat-capitalize-sentences nil
1580   "Capitalize sentence-starting words.
1581 Valid values are nil, t, `head', `first', `last', an integer or a
1582 predicate.  See Info node `(gnus)Customizing Articles'."
1583   :version "21.1"
1584   :group 'gnus-article-treat
1585   :link '(custom-manual "(gnus)Customizing Articles")
1586   :type gnus-article-treat-custom)
1587
1588 (defcustom gnus-treat-wash-html nil
1589   "Format as HTML.
1590 Valid values are nil, t, `head', `first', `last', an integer or a
1591 predicate.  See Info node `(gnus)Customizing Articles'."
1592   :version "22.1"
1593   :group 'gnus-article-treat
1594   :link '(custom-manual "(gnus)Customizing Articles")
1595   :type gnus-article-treat-custom)
1596
1597 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598   "Fill long lines.
1599 Valid values are nil, t, `head', `first', `last', an integer or a
1600 predicate.  See Info node `(gnus)Customizing Articles'."
1601   :version "24.1"
1602   :group 'gnus-article-treat
1603   :link '(custom-manual "(gnus)Customizing Articles")
1604   :type gnus-article-treat-custom)
1605
1606 (defcustom gnus-treat-x-pgp-sig nil
1607   "Verify X-PGP-Sig.
1608 To automatically treat X-PGP-Sig, set it to head.
1609 Valid values are nil, t, `head', `first', `last', an integer or a
1610 predicate.  See Info node `(gnus)Customizing Articles'."
1611   :version "22.1"
1612   :group 'gnus-article-treat
1613   :group 'mime-security
1614   :link '(custom-manual "(gnus)Customizing Articles")
1615   :type gnus-article-treat-custom)
1616
1617 (defvar gnus-article-encrypt-protocol-alist
1618   '(("PGP" . mml2015-self-encrypt)))
1619
1620 ;; Set to nil if more than one protocol added to
1621 ;; gnus-article-encrypt-protocol-alist.
1622 (defcustom gnus-article-encrypt-protocol "PGP"
1623   "The protocol used for encrypt articles.
1624 It is a string, such as \"PGP\". If nil, ask user."
1625   :version "22.1"
1626   :type 'string
1627   :group 'mime-security)
1628
1629 (defvar idna-program)
1630
1631 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1632                               (mm-coding-system-p 'utf-8)
1633                               idna-program
1634                               (executable-find idna-program))
1635   "Whether IDNA decoding of headers is used when viewing messages.
1636 This requires GNU Libidn, and by default only enabled if it is found."
1637   :version "22.1"
1638   :group 'gnus-article-headers
1639   :type 'boolean)
1640
1641 (defcustom gnus-article-over-scroll nil
1642   "If non-nil, allow scrolling the article buffer even when there no more text."
1643   :version "22.1"
1644   :group 'gnus-article
1645   :type 'boolean)
1646
1647 (defcustom gnus-inhibit-images nil
1648   "Non-nil means inhibit displaying of images inline in the article body."
1649   :version "24.1"
1650   :group 'gnus-article
1651   :type 'boolean)
1652
1653 (defcustom gnus-blocked-images 'gnus-block-private-groups
1654   "Images that have URLs matching this regexp will be blocked.
1655 This can also be a function to be evaluated.  If so, it will be
1656 called with the group name as the parameter, and should return a
1657 regexp."
1658   :version "24.1"
1659   :group 'gnus-art
1660   :type '(choice regexp function))
1661
1662 ;;; Internal variables
1663
1664 (defvar gnus-english-month-names
1665   '("January" "February" "March" "April" "May" "June" "July" "August"
1666     "September" "October" "November" "December"))
1667
1668 (defvar article-goto-body-goes-to-point-min-p nil)
1669 (defvar gnus-article-wash-types nil)
1670 (defvar gnus-article-emphasis-alist nil)
1671 (defvar gnus-article-image-alist nil)
1672
1673 (defvar gnus-article-mime-handle-alist-1 nil)
1674 (defvar gnus-treatment-function-alist
1675   '((gnus-treat-strip-cr gnus-article-remove-cr)
1676     (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1677     (gnus-treat-strip-banner gnus-article-strip-banner)
1678     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1679     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1680     (gnus-treat-buttonize gnus-article-add-buttons)
1681     (gnus-treat-fill-article gnus-article-fill-cited-article)
1682     (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1683     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1684     (gnus-treat-display-x-face gnus-article-display-x-face)
1685     (gnus-treat-display-face gnus-article-display-face)
1686     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1687     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1688     (gnus-treat-hide-signature gnus-article-hide-signature)
1689     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1690     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1691     (gnus-treat-from-picon gnus-treat-from-picon)
1692     (gnus-treat-mail-picon gnus-treat-mail-picon)
1693     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1694     (gnus-treat-strip-pem gnus-article-hide-pem)
1695     (gnus-treat-date gnus-article-treat-date)
1696     (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1697     (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1698     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1699     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1700     (gnus-treat-strip-trailing-blank-lines
1701      gnus-article-remove-trailing-blank-lines)
1702     (gnus-treat-strip-leading-blank-lines
1703      gnus-article-strip-leading-blank-lines)
1704     (gnus-treat-strip-multiple-blank-lines
1705      gnus-article-strip-multiple-blank-lines)
1706     (gnus-treat-overstrike gnus-article-treat-overstrike)
1707     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1708     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1709     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1710     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1711     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1712     (gnus-treat-display-smileys gnus-treat-smiley)
1713     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1714     (gnus-treat-wash-html gnus-article-wash-html)
1715     (gnus-treat-emphasize gnus-article-emphasize)
1716     (gnus-treat-hide-citation gnus-article-hide-citation)
1717     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1718     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1719     (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1720
1721 (defvar gnus-article-mime-handle-alist nil)
1722 (defvar article-lapsed-timer nil)
1723 (defvar gnus-article-current-summary nil)
1724
1725 (defvar gnus-article-mode-syntax-table
1726   (let ((table (copy-syntax-table text-mode-syntax-table)))
1727     ;; This causes the citation match run O(2^n).
1728     ;; (modify-syntax-entry ?- "w" table)
1729     (modify-syntax-entry ?> ")<" table)
1730     (modify-syntax-entry ?< "(>" table)
1731     ;; make M-. in article buffers work for `foo' strings
1732     (modify-syntax-entry ?' " " table)
1733     (modify-syntax-entry ?` " " table)
1734     table)
1735   "Syntax table used in article mode buffers.
1736 Initialized from `text-mode-syntax-table.")
1737
1738 (defvar gnus-save-article-buffer nil)
1739
1740 (defvar gnus-number-of-articles-to-be-saved nil)
1741
1742 (defvar gnus-inhibit-hiding nil)
1743
1744 (defvar gnus-article-edit-mode nil)
1745
1746 ;;; Macros for dealing with the article buffer.
1747
1748 (defmacro gnus-with-article-headers (&rest forms)
1749   `(with-current-buffer gnus-article-buffer
1750      (save-restriction
1751        (let ((inhibit-read-only t)
1752              (inhibit-point-motion-hooks t)
1753              (case-fold-search t))
1754          (article-narrow-to-head)
1755          ,@forms))))
1756
1757 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1758 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1759
1760 (defmacro gnus-with-article-buffer (&rest forms)
1761   `(when (buffer-live-p (get-buffer gnus-article-buffer))
1762      (with-current-buffer gnus-article-buffer
1763        (let ((inhibit-read-only t))
1764          ,@forms))))
1765
1766 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1767 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1768
1769 (defun gnus-article-goto-header (header)
1770   "Go to HEADER, which is a regular expression."
1771   (re-search-forward (concat "^\\(" header "\\):") nil t))
1772
1773 (defsubst gnus-article-hide-text (b e props)
1774   "Set text PROPS on the B to E region."
1775   (gnus-add-text-properties-when 'article-type nil b e props))
1776
1777 (defsubst gnus-article-unhide-text (b e)
1778   "Remove hidden text properties from region between B and E."
1779   (remove-text-properties b e gnus-hidden-properties))
1780
1781 (defun gnus-article-hide-text-type (b e type)
1782   "Hide text of TYPE between B and E."
1783   (gnus-add-wash-type type)
1784   (gnus-article-hide-text
1785    b e (cons 'article-type (cons type gnus-hidden-properties))))
1786
1787 (defun gnus-article-unhide-text-type (b e type)
1788   "Unhide text of TYPE between B and E."
1789   (gnus-delete-wash-type type)
1790   (remove-text-properties
1791    b e (cons 'article-type (cons type gnus-hidden-properties))))
1792
1793 (defun gnus-article-delete-text-of-type (type)
1794   "Delete text of TYPE in the current buffer."
1795   (save-excursion
1796     (let ((b (point-min)))
1797       (if (eq type 'multipart)
1798           ;; Remove MIME buttons associated with multipart/alternative parts.
1799           (progn
1800             (goto-char b)
1801             (while (if (get-text-property (point) 'gnus-part)
1802                        (setq b (point))
1803                      (when (setq b (next-single-property-change (point)
1804                                                                 'gnus-part))
1805                        (goto-char b)
1806                        t))
1807               (end-of-line)
1808               (skip-chars-forward "\n")
1809               (when (eq (get-text-property b 'article-type) 'multipart)
1810                 (delete-region b (point)))))
1811         (while (setq b (text-property-any b (point-max) 'article-type type))
1812           (delete-region
1813            b (or (text-property-not-all b (point-max) 'article-type type)
1814                  (point-max))))))))
1815
1816 (defun gnus-article-delete-invisible-text ()
1817   "Delete all invisible text in the current buffer."
1818   (save-excursion
1819     (let ((b (point-min)))
1820       (while (setq b (text-property-any b (point-max) 'invisible t))
1821         (delete-region
1822          b (or (text-property-not-all b (point-max) 'invisible t)
1823                (point-max)))))))
1824
1825 (defsubst gnus-article-header-rank ()
1826   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1827   (let ((list gnus-sorted-header-list)
1828         (i 1))
1829     (while list
1830       (if (looking-at (car list))
1831           (setq list nil)
1832         (setq list (cdr list))
1833         (incf i)))
1834       i))
1835
1836 (defun article-hide-headers (&optional _arg _delete)
1837   "Hide unwanted headers and possibly sort them as well."
1838   (interactive)
1839   ;; This function might be inhibited.
1840   (unless gnus-inhibit-hiding
1841     (let ((inhibit-read-only t)
1842           (case-fold-search t)
1843           (max (1+ (length gnus-sorted-header-list)))
1844           (inhibit-point-motion-hooks t)
1845           (cur (current-buffer))
1846           ignored visible beg)
1847       (save-excursion
1848         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1849         ;; group parameters, so we should go to the summary buffer.
1850         (when (prog1
1851                   (condition-case nil
1852                       (progn (set-buffer gnus-summary-buffer) t)
1853                     (error nil))
1854                 (setq ignored (when (not gnus-visible-headers)
1855                                 (cond ((stringp gnus-ignored-headers)
1856                                        gnus-ignored-headers)
1857                                       ((listp gnus-ignored-headers)
1858                                        (mapconcat 'identity
1859                                                   gnus-ignored-headers
1860                                                   "\\|"))))
1861                       visible (cond ((stringp gnus-visible-headers)
1862                                      gnus-visible-headers)
1863                                     ((and gnus-visible-headers
1864                                           (listp gnus-visible-headers))
1865                                      (mapconcat 'identity
1866                                                 gnus-visible-headers
1867                                                 "\\|")))))
1868           (set-buffer cur))
1869         (save-restriction
1870           ;; First we narrow to just the headers.
1871           (article-narrow-to-head)
1872           ;; Hide any "From " lines at the beginning of (mail) articles.
1873           (while (looking-at "From ")
1874             (forward-line 1))
1875           (unless (bobp)
1876             (delete-region (point-min) (point)))
1877           ;; Then treat the rest of the header lines.
1878           ;; Then we use the two regular expressions
1879           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1880           ;; select which header lines is to remain visible in the
1881           ;; article buffer.
1882           (while (re-search-forward "^[^ \t:]*:" nil t)
1883             (beginning-of-line)
1884             ;; Mark the rank of the header.
1885             (put-text-property
1886              (point) (1+ (point)) 'message-rank
1887              (if (or (and visible (looking-at visible))
1888                      (and ignored
1889                           (not (looking-at ignored))))
1890                  (gnus-article-header-rank)
1891                (+ 2 max)))
1892             (forward-line 1))
1893           (message-sort-headers-1)
1894           (when (setq beg (text-property-any
1895                            (point-min) (point-max) 'message-rank (+ 2 max)))
1896             ;; We delete the unwanted headers.
1897             (gnus-add-wash-type 'headers)
1898             (add-text-properties (point-min) (+ 5 (point-min))
1899                                  '(article-type headers dummy-invisible t))
1900             (delete-region beg (point-max))))))))
1901
1902 (defun article-hide-boring-headers (&optional arg)
1903   "Toggle hiding of headers that aren't very interesting.
1904 If given a negative prefix, always show; if given a positive prefix,
1905 always hide."
1906   (interactive (gnus-article-hidden-arg))
1907   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1908              (not gnus-show-all-headers))
1909     (save-excursion
1910       (save-restriction
1911         (let ((inhibit-read-only t)
1912               (inhibit-point-motion-hooks t))
1913           (article-narrow-to-head)
1914           (dolist (elem gnus-boring-article-headers)
1915             (goto-char (point-min))
1916             (cond
1917              ;; Hide empty headers.
1918              ((eq elem 'empty)
1919               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1920                 (forward-line -1)
1921                 (gnus-article-hide-text-type
1922                  (point-at-bol)
1923                  (progn
1924                    (end-of-line)
1925                    (if (re-search-forward "^[^ \t]" nil t)
1926                        (match-beginning 0)
1927                      (point-max)))
1928                  'boring-headers)))
1929              ;; Hide boring Newsgroups header.
1930              ((eq elem 'newsgroups)
1931               (when (gnus-string-equal
1932                      (gnus-fetch-field "newsgroups")
1933                      (gnus-group-real-name
1934                       (if (boundp 'gnus-newsgroup-name)
1935                           gnus-newsgroup-name
1936                         "")))
1937                 (gnus-article-hide-header "newsgroups")))
1938              ((eq elem 'to-address)
1939               (let ((to (message-fetch-field "to"))
1940                     (to-address
1941                      (gnus-parameter-to-address
1942                       (if (boundp 'gnus-newsgroup-name)
1943                           gnus-newsgroup-name ""))))
1944                 (when (and to to-address
1945                            (ignore-errors
1946                              (gnus-string-equal
1947                               ;; only one address in To
1948                               (nth 1 (mail-extract-address-components to))
1949                               to-address)))
1950                   (gnus-article-hide-header "to"))))
1951              ((eq elem 'to-list)
1952               (let ((to (message-fetch-field "to"))
1953                     (to-list
1954                      (gnus-parameter-to-list
1955                       (if (boundp 'gnus-newsgroup-name)
1956                           gnus-newsgroup-name ""))))
1957                 (when (and to to-list
1958                            (ignore-errors
1959                              (gnus-string-equal
1960                               ;; only one address in To
1961                               (nth 1 (mail-extract-address-components to))
1962                               to-list)))
1963                   (gnus-article-hide-header "to"))))
1964              ((eq elem 'cc-list)
1965               (let ((cc (message-fetch-field "cc"))
1966                     (to-list
1967                      (gnus-parameter-to-list
1968                       (if (boundp 'gnus-newsgroup-name)
1969                           gnus-newsgroup-name ""))))
1970                 (when (and cc to-list
1971                            (ignore-errors
1972                              (gnus-string-equal
1973                               ;; only one address in CC
1974                               (nth 1 (mail-extract-address-components cc))
1975                               to-list)))
1976                   (gnus-article-hide-header "cc"))))
1977              ((eq elem 'followup-to)
1978               (when (gnus-string-equal
1979                      (message-fetch-field "followup-to")
1980                      (message-fetch-field "newsgroups"))
1981                 (gnus-article-hide-header "followup-to")))
1982              ((eq elem 'reply-to)
1983               (if (gnus-group-find-parameter
1984                    gnus-newsgroup-name 'broken-reply-to)
1985                   (gnus-article-hide-header "reply-to")
1986                 (let ((from (message-fetch-field "from"))
1987                       (reply-to (message-fetch-field "reply-to")))
1988                   (when
1989                       (and
1990                        from reply-to
1991                        (ignore-errors
1992                          (equal
1993                           (sort (mapcar
1994                                  (lambda (x) (downcase (cadr x)))
1995                                  (mail-extract-address-components from t))
1996                                 'string<)
1997                           (sort (mapcar
1998                                  (lambda (x) (downcase (cadr x)))
1999                                  (mail-extract-address-components reply-to t))
2000                                 'string<))))
2001                     (gnus-article-hide-header "reply-to")))))
2002              ((eq elem 'date)
2003               (let ((date (with-current-buffer gnus-original-article-buffer
2004                             ;; If date in `gnus-article-buffer' is localized
2005                             ;; (`gnus-treat-date-user-defined'),
2006                             ;; `days-between' might fail.
2007                             (message-fetch-field "date"))))
2008                 (when (and date
2009                            (< (days-between (current-time-string) date)
2010                               4))
2011                   (gnus-article-hide-header "date"))))
2012              ((eq elem 'long-to)
2013               (let ((to (message-fetch-field "to"))
2014                     (cc (message-fetch-field "cc")))
2015                 (when (> (length to) 1024)
2016                   (gnus-article-hide-header "to"))
2017                 (when (> (length cc) 1024)
2018                   (gnus-article-hide-header "cc"))))
2019              ((eq elem 'many-to)
2020               (let ((to-count 0)
2021                     (cc-count 0))
2022                 (goto-char (point-min))
2023                 (while (re-search-forward "^to:" nil t)
2024                   (setq to-count (1+ to-count)))
2025                 (when (> to-count 1)
2026                   (while (> to-count 0)
2027                     (goto-char (point-min))
2028                     (save-restriction
2029                       (re-search-forward "^to:" nil nil to-count)
2030                       (forward-line -1)
2031                       (narrow-to-region (point) (point-max))
2032                       (gnus-article-hide-header "to"))
2033                     (setq to-count (1- to-count))))
2034                 (goto-char (point-min))
2035                 (while (re-search-forward "^cc:" nil t)
2036                   (setq cc-count (1+ cc-count)))
2037                 (when (> cc-count 1)
2038                   (while (> cc-count 0)
2039                     (goto-char (point-min))
2040                     (save-restriction
2041                       (re-search-forward "^cc:" nil nil cc-count)
2042                       (forward-line -1)
2043                       (narrow-to-region (point) (point-max))
2044                       (gnus-article-hide-header "cc"))
2045                     (setq cc-count (1- cc-count)))))))))))))
2046
2047 (defun gnus-article-hide-header (header)
2048   (save-excursion
2049     (goto-char (point-min))
2050     (when (re-search-forward (concat "^" header ":") nil t)
2051       (gnus-article-hide-text-type
2052        (point-at-bol)
2053        (progn
2054          (end-of-line)
2055          (if (re-search-forward "^[^ \t]" nil t)
2056              (match-beginning 0)
2057            (point-max)))
2058        'boring-headers))))
2059
2060 (defvar gnus-article-normalized-header-length 40
2061   "Length of normalized headers.")
2062
2063 (defun article-normalize-headers ()
2064   "Make all header lines 40 characters long."
2065   (interactive)
2066   (let ((inhibit-read-only t)
2067         column)
2068     (save-excursion
2069       (save-restriction
2070         (article-narrow-to-head)
2071         (while (not (eobp))
2072           (cond
2073            ((< (setq column (- (point-at-eol) (point)))
2074                gnus-article-normalized-header-length)
2075             (end-of-line)
2076             (insert (make-string
2077                      (- gnus-article-normalized-header-length column)
2078                      ? )))
2079            ((> column gnus-article-normalized-header-length)
2080             (gnus-put-text-property
2081              (progn
2082                (forward-char gnus-article-normalized-header-length)
2083                (point))
2084              (point-at-eol)
2085              'invisible t))
2086            (t
2087             ;; Do nothing.
2088             ))
2089           (forward-line 1))))))
2090
2091 (defun article-treat-dumbquotes ()
2092   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2093 Note that this function guesses whether a character is a sm*rtq**t* or
2094 not, so it should only be used interactively.
2095
2096 Sm*rtq**t*s are M****s***'s unilateral extension to the
2097 iso-8859-1 character map in an attempt to provide more quoting
2098 characters.  If you see something like \\222 or \\264 where
2099 you're expecting some kind of apostrophe or quotation mark, then
2100 try this wash."
2101   (interactive)
2102   (article-translate-strings gnus-article-dumbquotes-map))
2103
2104 (defvar org-entities)
2105
2106 (defun article-treat-non-ascii ()
2107   "Translate many Unicode characters into their ASCII equivalents."
2108   (interactive)
2109   (require 'org-entities)
2110   (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2111     (dolist (elem org-entities)
2112       (when (and (listp elem)
2113                  (= (length (nth 6 elem)) 1))
2114         (if (featurep 'xemacs)
2115             (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2116           (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2117     (save-excursion
2118       (when (article-goto-body)
2119         (let ((inhibit-read-only t)
2120               replace props)
2121           (while (not (eobp))
2122             (if (not (setq replace (if (featurep 'xemacs)
2123                                        (get-char-table (following-char) table)
2124                                      (aref table (following-char)))))
2125                 (forward-char 1)
2126               (if (prog1
2127                       (setq props (text-properties-at (point)))
2128                     (delete-char 1))
2129                   (add-text-properties (point) (progn (insert replace) (point))
2130                                        props)
2131                 (insert replace)))))))))
2132
2133 (defun article-translate-strings (map)
2134   "Translate all string in the body of the article according to MAP.
2135 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2136   (save-excursion
2137     (when (article-goto-body)
2138       (let ((inhibit-read-only t))
2139         (dolist (elem map)
2140           (let ((from (car elem))
2141                 (to (cadr elem)))
2142             (save-excursion
2143               (if (stringp from)
2144                   (while (search-forward from nil t)
2145                     (replace-match to))
2146                 (while (not (eobp))
2147                   (if (eq (following-char) from)
2148                       (progn
2149                         (delete-char 1)
2150                         (insert to))
2151                     (forward-char 1)))))))))))
2152
2153 (defun article-treat-overstrike ()
2154   "Translate overstrikes into bold text."
2155   (interactive)
2156   (save-excursion
2157     (when (article-goto-body)
2158       (let ((inhibit-read-only t))
2159         (while (search-forward "\b" nil t)
2160           (let ((next (char-after))
2161                 (previous (char-after (- (point) 2))))
2162             ;; We do the boldification/underlining by hiding the
2163             ;; overstrikes and putting the proper text property
2164             ;; on the letters.
2165             (cond
2166              ((eq next previous)
2167               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2168               (put-text-property (point) (1+ (point)) 'face 'bold))
2169              ((eq next ?_)
2170               (gnus-article-hide-text-type
2171                (1- (point)) (1+ (point)) 'overstrike)
2172               (put-text-property
2173                (- (point) 2) (1- (point)) 'face 'underline))
2174              ((eq previous ?_)
2175               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2176               (put-text-property
2177                (point) (1+ (point)) 'face 'underline)))))))))
2178
2179 (defun article-treat-ansi-sequences ()
2180   "Translate ANSI SGR control sequences into overlays or extents."
2181   (interactive)
2182   (save-excursion
2183     (when (article-goto-body)
2184       (let ((inhibit-read-only t))
2185         (ansi-color-apply-on-region (point) (point-max))))))
2186
2187 (defun gnus-article-treat-unfold-headers ()
2188   "Unfold folded message headers.
2189 Only the headers that fit into the current window width will be
2190 unfolded."
2191   (interactive)
2192   (gnus-with-article-headers
2193     (let (length)
2194       (while (not (eobp))
2195         (save-restriction
2196           (mail-header-narrow-to-field)
2197           (let* ((header (buffer-string))
2198                  (unfoldable
2199                   (or (equal gnus-article-unfold-long-headers t)
2200                       (and (stringp gnus-article-unfold-long-headers)
2201                            (string-match gnus-article-unfold-long-headers
2202                                          header)))))
2203             (with-temp-buffer
2204               (insert header)
2205               (goto-char (point-min))
2206               (while (re-search-forward "\n[\t ]" nil t)
2207                 (replace-match " " t t)))
2208             (setq length (- (point-max) (point-min) 1))
2209             (when (or unfoldable
2210                       (< length (window-width)))
2211               (while (re-search-forward "\n[\t ]" nil t)
2212                 (replace-match " " t t))))
2213           (goto-char (point-max)))))))
2214
2215 (defun gnus-article-treat-fold-headers ()
2216   "Fold message headers."
2217   (interactive)
2218   (gnus-with-article-headers
2219     (while (not (eobp))
2220       (save-restriction
2221         (mail-header-narrow-to-field)
2222         (mail-header-fold-field)
2223         (goto-char (point-max))))))
2224
2225 (defun gnus-treat-smiley ()
2226   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2227   (interactive)
2228   (gnus-with-article-buffer
2229     (if (memq 'smiley gnus-article-wash-types)
2230         (gnus-delete-images 'smiley)
2231       (article-goto-body)
2232       (let ((images (smiley-region (point) (point-max))))
2233         (when images
2234           (gnus-add-wash-type 'smiley)
2235           (dolist (image images)
2236             (gnus-add-image 'smiley image)))))))
2237
2238 (defun gnus-article-remove-images ()
2239   "Remove all images from the article buffer."
2240   (interactive)
2241   (gnus-with-article-buffer
2242     (save-restriction
2243       (widen)
2244       (dolist (elem gnus-article-image-alist)
2245         (gnus-delete-images (car elem))))))
2246
2247 (autoload 'w3m-toggle-inline-images "w3m")
2248
2249 (defun gnus-article-show-images ()
2250   "Show any images that are in the HTML-rendered article buffer.
2251 This only works if the article in question is HTML."
2252   (interactive)
2253   (gnus-with-article-buffer
2254     (save-restriction
2255       (widen)
2256       (if (eq mm-text-html-renderer 'w3m)
2257           (let ((mm-inline-text-html-with-images nil))
2258             (w3m-toggle-inline-images))
2259         (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2260                                                         'image-displayer))
2261           (destructuring-bind (start end function) region
2262             (funcall function (get-text-property start 'image-url)
2263                      start end)))))))
2264
2265 (defun gnus-article-treat-fold-newsgroups ()
2266   "Unfold folded message headers.
2267 Only the headers that fit into the current window width will be
2268 unfolded."
2269   (interactive)
2270   (gnus-with-article-headers
2271     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2272       (save-restriction
2273         (mail-header-narrow-to-field)
2274         (while (re-search-forward ", *" nil t)
2275           (replace-match ", " t t))
2276         (mail-header-fold-field)
2277         (goto-char (point-max))))))
2278
2279 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2280   "Value of `truncate-lines' in Gnus Article buffer.
2281 Valid values are nil, t, `head', `first', `last', an integer or a
2282 predicate.  See Info node `(gnus)Customizing Articles'."
2283   :version "23.1" ;; No Gnus
2284   :group 'gnus-article
2285   ;; :link '(custom-manual "(gnus)Customizing Articles")
2286   :type 'boolean)
2287
2288 (defun gnus-article-toggle-truncate-lines (&optional arg)
2289   "Toggle whether to fold or truncate long lines in article the buffer.
2290 If ARG is non-nil and not a number, toggle
2291 `gnus-article-truncate-lines' too.  If ARG is a number, truncate
2292 long lines if and only if arg is positive."
2293   (interactive "P")
2294   (cond
2295    ((and (numberp arg) (> arg 0))
2296     (setq gnus-article-truncate-lines t))
2297    ((numberp arg)
2298     (setq gnus-article-truncate-lines nil))
2299    (arg
2300     (setq gnus-article-truncate-lines
2301           (not gnus-article-truncate-lines))))
2302   (gnus-with-article-buffer
2303     (cond
2304      ((and (numberp arg) (> arg 0))
2305       (setq truncate-lines nil))
2306      ((numberp arg)
2307       (setq truncate-lines t)))
2308     ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2309     ;; `toggle-truncate-lines' needs an argument.
2310     (toggle-truncate-lines)))
2311
2312 (defun gnus-article-treat-body-boundary ()
2313   "Place a boundary line at the end of the headers."
2314   (interactive)
2315   (when (and gnus-body-boundary-delimiter
2316              (> (length gnus-body-boundary-delimiter) 0))
2317     (gnus-with-article-headers
2318       (goto-char (point-max))
2319       (let ((start (point)))
2320         (insert "X-Boundary: ")
2321         (gnus-add-text-properties start (point) gnus-hidden-properties)
2322        (insert (let (str (max (window-width)))
2323                  (if (featurep 'xemacs)
2324                      (setq max (1- max)))
2325                  (while (>= max (length str))
2326                     (setq str (concat str gnus-body-boundary-delimiter)))
2327                  (substring str 0 max))
2328                 "\n")
2329         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2330
2331 (defun article-fill-long-lines ()
2332   "Fill lines that are wider than the window width."
2333   (interactive)
2334   (save-excursion
2335     (let ((inhibit-read-only t)
2336           (width (window-width (get-buffer-window (current-buffer)))))
2337       (save-restriction
2338         (article-goto-body)
2339         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2340           (while (not (eobp))
2341             (end-of-line)
2342             (when (>= (current-column) (min fill-column width))
2343               (narrow-to-region (min (1+ (point)) (point-max))
2344                                 (point-at-bol))
2345               (let ((goback (point-marker)))
2346                 (fill-paragraph nil)
2347                 (goto-char (marker-position goback)))
2348               (widen))
2349             (forward-line 1)))))))
2350
2351 (defun article-capitalize-sentences ()
2352   "Capitalize the first word in each sentence."
2353   (interactive)
2354   (save-excursion
2355     (let ((inhibit-read-only t)
2356           (paragraph-start "^[\n\^L]"))
2357       (article-goto-body)
2358       (while (not (eobp))
2359         (capitalize-word 1)
2360         (forward-sentence)))))
2361
2362 (defun article-remove-cr ()
2363   "Remove trailing CRs and then translate remaining CRs into LFs."
2364   (interactive)
2365   (save-excursion
2366     (let ((inhibit-read-only t))
2367       (goto-char (point-min))
2368       (while (re-search-forward "\r+$" nil t)
2369         (replace-match "" t t))
2370       (goto-char (point-min))
2371       (while (search-forward "\r" nil t)
2372         (replace-match "\n" t t)))))
2373
2374 (defun article-remove-trailing-blank-lines ()
2375   "Remove all trailing blank lines from the article."
2376   (interactive)
2377   (save-excursion
2378     (let ((inhibit-read-only t))
2379       (goto-char (point-max))
2380       (delete-region
2381        (point)
2382        (progn
2383          (while (and (not (bobp))
2384                      (looking-at "^[ \t]*$")
2385                      (not (gnus-annotation-in-region-p
2386                            (point) (point-at-eol))))
2387            (forward-line -1))
2388          (forward-line 1)
2389          (point))))))
2390
2391 (defvar gnus-face-properties-alist)
2392
2393 (defun article-display-face (&optional force)
2394   "Display any Face headers in the header."
2395   (interactive (list 'force))
2396   (let ((wash-face-p buffer-read-only))
2397     (gnus-with-article-headers
2398       ;; When displaying parts, this function can be called several times on
2399       ;; the same article, without any intended toggle semantic (as typing `W
2400       ;; D d' would have). So face deletion must occur only when we come from
2401       ;; an interactive command, that is when the *Article* buffer is
2402       ;; read-only.
2403       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2404           (gnus-delete-images 'face)
2405         (let ((from (message-fetch-field "from"))
2406               faces)
2407           (save-current-buffer
2408             (when (and wash-face-p
2409                        (gnus-buffer-live-p gnus-original-article-buffer)
2410                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2411               (set-buffer gnus-original-article-buffer))
2412             (save-restriction
2413               (mail-narrow-to-head)
2414               (when (or force
2415                         ;; Check whether this face is censored.
2416                         (not (and gnus-article-x-face-too-ugly
2417                                   (or from
2418                                       (setq from (message-fetch-field "from")))
2419                                   (string-match gnus-article-x-face-too-ugly
2420                                                 from))))
2421                 (while (gnus-article-goto-header "Face")
2422                   (push (mail-header-field-value) faces)))))
2423           (when faces
2424             (goto-char (point-min))
2425             (let (png image)
2426               (unless (setq from (gnus-article-goto-header "from"))
2427                 (insert "From:")
2428                 (setq from (point))
2429                 (insert " [no `from' set]\n"))
2430               (while faces
2431                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2432                   (setq image
2433                         (apply 'gnus-create-image png 'png t
2434                                (cdr (assq 'png gnus-face-properties-alist))))
2435                   (goto-char from)
2436                   (when image
2437                     (gnus-add-wash-type 'face)
2438                     (gnus-add-image 'face image)
2439                     (gnus-put-image image nil 'face)))))))))))
2440
2441 (defun article-display-x-face (&optional force)
2442   "Look for an X-Face header and display it if present."
2443   (interactive (list 'force))
2444   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2445     (gnus-with-article-headers
2446       ;; Delete the old process, if any.
2447       (when (process-status "article-x-face")
2448         (delete-process "article-x-face"))
2449       ;; See the comment in `article-display-face'.
2450       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2451           ;; We have already displayed X-Faces, so we remove them
2452           ;; instead.
2453           (gnus-delete-images 'xface)
2454         ;; Display X-Faces.
2455         (let ((from (message-fetch-field "from"))
2456               x-faces)
2457           (save-current-buffer
2458             (when (and wash-face-p
2459                        (gnus-buffer-live-p gnus-original-article-buffer)
2460                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2461               ;; If type `W f', use gnus-original-article-buffer,
2462               ;; otherwise use the current buffer because displaying
2463               ;; RFC822 parts calls this function too.
2464               (set-buffer gnus-original-article-buffer))
2465             (save-restriction
2466               (mail-narrow-to-head)
2467               (and gnus-article-x-face-command
2468                    (or force
2469                        ;; Check whether this face is censored.
2470                        (not (and gnus-article-x-face-too-ugly
2471                                  (or from
2472                                      (setq from (message-fetch-field "from")))
2473                                  (string-match gnus-article-x-face-too-ugly
2474                                                from))))
2475                    (while (gnus-article-goto-header "X-Face")
2476                      (push (mail-header-field-value) x-faces)))))
2477           (when x-faces
2478             ;; We display the face.
2479             (cond ((functionp gnus-article-x-face-command)
2480                    ;; The command is a lisp function, so we call it.
2481                    (mapc gnus-article-x-face-command x-faces))
2482                   ((stringp gnus-article-x-face-command)
2483                    ;; The command is a string, so we interpret the command
2484                    ;; as a, well, command, and fork it off.
2485                    (let ((process-connection-type nil))
2486                      (gnus-set-process-query-on-exit-flag
2487                       (start-process
2488                        "article-x-face" nil shell-file-name
2489                        shell-command-switch gnus-article-x-face-command)
2490                       nil)
2491                      ;; Sending multiple EOFs to xv doesn't work,
2492                      ;; so we only do a single external face.
2493                      (with-temp-buffer
2494                        (insert (car x-faces))
2495                        (process-send-region "article-x-face"
2496                                             (point-min) (point-max)))
2497                      (process-send-eof "article-x-face")))
2498                   (t
2499                    (error "`%s' set to `%s' is not a function"
2500                           gnus-article-x-face-command
2501                           'gnus-article-x-face-command)))))))))
2502
2503 (defun article-decode-mime-words ()
2504   "Decode all MIME-encoded words in the article."
2505   (interactive)
2506   (gnus-with-article-buffer
2507     (let ((inhibit-point-motion-hooks t)
2508           (mail-parse-charset gnus-newsgroup-charset)
2509           (mail-parse-ignored-charsets
2510            (with-current-buffer gnus-summary-buffer
2511              gnus-newsgroup-ignored-charsets)))
2512       (mail-decode-encoded-word-region (point-min) (point-max)))))
2513
2514 (defun article-decode-charset (&optional prompt)
2515   "Decode charset-encoded text in the article.
2516 If PROMPT (the prefix), prompt for a coding system to use."
2517   (interactive "P")
2518   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2519         (inhibit-read-only t)
2520         (mail-parse-charset gnus-newsgroup-charset)
2521         (mail-parse-ignored-charsets
2522          (save-excursion (condition-case nil
2523                              (set-buffer gnus-summary-buffer)
2524                            (error))
2525                          gnus-newsgroup-ignored-charsets))
2526         ct cte ctl charset format)
2527     (save-excursion
2528       (save-restriction
2529         (article-narrow-to-head)
2530         (setq ct (message-fetch-field "Content-Type" t)
2531               cte (message-fetch-field "Content-Transfer-Encoding" t)
2532               ctl (and ct (mail-header-parse-content-type ct))
2533               charset (cond
2534                        (prompt
2535                         (mm-read-coding-system "Charset to decode: "))
2536                        (ctl
2537                         (mail-content-type-get ctl 'charset)))
2538               format (and ctl (mail-content-type-get ctl 'format)))
2539         (when cte
2540           (setq cte (mail-header-strip cte)))
2541         (if (and ctl (not (string-match "/" (car ctl))))
2542             (setq ctl nil))
2543         (goto-char (point-max)))
2544       (forward-line 1)
2545       (save-restriction
2546         (narrow-to-region (point) (point-max))
2547         (when (and (eq mail-parse-charset 'gnus-decoded)
2548                    (eq (mm-body-7-or-8) '8bit))
2549           ;; The text code could have been decoded.
2550           (setq charset mail-parse-charset))
2551         (when (and (or (not ctl)
2552                        (equal (car ctl) "text/plain"))
2553                    (not format)) ;; article with format will decode later.
2554           (mm-decode-body
2555            charset (and cte (intern (downcase
2556                                      (gnus-strip-whitespace cte))))
2557            (car ctl)))))))
2558
2559 (defun article-decode-encoded-words ()
2560   "Remove encoded-word encoding from headers."
2561   (let ((inhibit-point-motion-hooks t)
2562         (mail-parse-charset gnus-newsgroup-charset)
2563         (mail-parse-ignored-charsets
2564          (save-excursion (condition-case nil
2565                              (set-buffer gnus-summary-buffer)
2566                            (error))
2567                          gnus-newsgroup-ignored-charsets))
2568         (inhibit-read-only t)
2569         end start)
2570     (goto-char (point-min))
2571     (when (search-forward "\n\n" nil 'move)
2572       (forward-line -1))
2573     (setq end (point))
2574     (while (not (bobp))
2575       (while (progn
2576                (forward-line -1)
2577                (and (not (bobp))
2578                     (memq (char-after) '(?\t ? )))))
2579       (setq start (point))
2580       (if (looking-at "\
2581 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2582 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2583           (funcall gnus-decode-address-function start end)
2584         (funcall gnus-decode-header-function start end))
2585       (goto-char (setq end start)))))
2586
2587 (defun article-decode-group-name ()
2588   "Decode group names in Newsgroups, Followup-To and Xref headers."
2589   (let ((inhibit-point-motion-hooks t)
2590         (inhibit-read-only t)
2591         (method (gnus-find-method-for-group gnus-newsgroup-name))
2592         regexp)
2593     (when (and (or gnus-group-name-charset-method-alist
2594                    gnus-group-name-charset-group-alist)
2595                (gnus-buffer-live-p gnus-original-article-buffer))
2596       (save-restriction
2597         (article-narrow-to-head)
2598         (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2599           (with-current-buffer gnus-original-article-buffer
2600             (goto-char (point-min)))
2601           (setq regexp (concat "^" header
2602                                ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2603           (while (re-search-forward regexp nil t)
2604             (replace-match (save-match-data
2605                              (gnus-decode-newsgroups
2606                               ;; XXX how to use data in article buffer?
2607                               (with-current-buffer gnus-original-article-buffer
2608                                 (re-search-forward regexp nil t)
2609                                 (match-string 1))
2610                               gnus-newsgroup-name method))
2611                            t t nil 1))
2612           (goto-char (point-min)))))))
2613
2614 (autoload 'idna-to-unicode "idna")
2615
2616 (defun article-decode-idna-rhs ()
2617   "Decode IDNA strings in RHS in various headers in current buffer.
2618 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2619 Mail-Reply-To: and Mail-Followup-To:."
2620   (when gnus-use-idna
2621     (save-restriction
2622       (let ((inhibit-point-motion-hooks t)
2623             (inhibit-read-only t))
2624         (article-narrow-to-head)
2625         (goto-char (point-min))
2626         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2627           (let (ace unicode)
2628             (when (save-match-data
2629                     (and (setq ace (match-string 1))
2630                          (save-excursion
2631                            (and (re-search-backward "^[^ \t]" nil t)
2632                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2633                          (setq unicode (idna-to-unicode ace))))
2634               (unless (string= ace unicode)
2635                 (replace-match unicode nil nil nil 1)))))))))
2636
2637 (defun article-de-quoted-unreadable (&optional force read-charset)
2638   "Translate a quoted-printable-encoded article.
2639 If FORCE, decode the article whether it is marked as quoted-printable
2640 or not.
2641 If READ-CHARSET, ask for a coding system."
2642   (interactive (list 'force current-prefix-arg))
2643   (save-excursion
2644     (let ((inhibit-read-only t) type charset)
2645       (if (gnus-buffer-live-p gnus-original-article-buffer)
2646           (with-current-buffer gnus-original-article-buffer
2647             (setq type
2648                   (gnus-fetch-field "content-transfer-encoding"))
2649             (let* ((ct (gnus-fetch-field "content-type"))
2650                    (ctl (and ct (mail-header-parse-content-type ct))))
2651               (setq charset (and ctl
2652                                  (mail-content-type-get ctl 'charset)))
2653               (if (stringp charset)
2654                   (setq charset (intern (downcase charset)))))))
2655       (if read-charset
2656           (setq charset (mm-read-coding-system "Charset: " charset)))
2657       (unless charset
2658         (setq charset gnus-newsgroup-charset))
2659       (when (or force
2660                 (and type (let ((case-fold-search t))
2661                             (string-match "quoted-printable" type))))
2662         (article-goto-body)
2663         (quoted-printable-decode-region
2664          (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2665
2666 (defun article-de-base64-unreadable (&optional force read-charset)
2667   "Translate a base64 article.
2668 If FORCE, decode the article whether it is marked as base64 not.
2669 If READ-CHARSET, ask for a coding system."
2670   (interactive (list 'force current-prefix-arg))
2671   (save-excursion
2672     (let ((inhibit-read-only t) type charset)
2673       (if (gnus-buffer-live-p gnus-original-article-buffer)
2674           (with-current-buffer gnus-original-article-buffer
2675             (setq type
2676                   (gnus-fetch-field "content-transfer-encoding"))
2677             (let* ((ct (gnus-fetch-field "content-type"))
2678                    (ctl (and ct (mail-header-parse-content-type ct))))
2679               (setq charset (and ctl
2680                                  (mail-content-type-get ctl 'charset)))
2681               (if (stringp charset)
2682                   (setq charset (intern (downcase charset)))))))
2683       (if read-charset
2684           (setq charset (mm-read-coding-system "Charset: " charset)))
2685       (unless charset
2686         (setq charset gnus-newsgroup-charset))
2687       (when (or force
2688                 (and type (let ((case-fold-search t))
2689                             (string-match "base64" type))))
2690         (article-goto-body)
2691         (save-restriction
2692           (narrow-to-region (point) (point-max))
2693           (base64-decode-region (point-min) (point-max))
2694           (mm-decode-coding-region
2695            (point-min) (point-max)
2696            (mm-charset-to-coding-system charset nil t)))))))
2697
2698 (eval-when-compile
2699   (require 'rfc1843))
2700
2701 (defun article-decode-HZ ()
2702   "Translate a HZ-encoded article."
2703   (interactive)
2704   (require 'rfc1843)
2705   (save-excursion
2706     (let ((inhibit-read-only t))
2707       (rfc1843-decode-region (point-min) (point-max)))))
2708
2709 (defun article-unsplit-urls ()
2710   "Remove the newlines that some other mailers insert into URLs."
2711   (interactive)
2712   (save-excursion
2713     (let ((inhibit-read-only t))
2714       (goto-char (point-min))
2715       (while (re-search-forward
2716               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2717         (replace-match "\\1\\3" t)))
2718     (when (gmm-called-interactively-p 'any)
2719       (gnus-treat-article nil))))
2720
2721 (defun article-wash-html ()
2722   "Format an HTML article."
2723   (interactive)
2724   (let ((handles nil)
2725         (buffer-read-only nil))
2726     (when (gnus-buffer-live-p gnus-original-article-buffer)
2727       (with-current-buffer gnus-original-article-buffer
2728         (setq handles (mm-dissect-buffer t t))))
2729     (article-goto-body)
2730     (delete-region (point) (point-max))
2731     (mm-enable-multibyte)
2732     (mm-inline-text-html handles)))
2733
2734 (defvar gnus-article-browse-html-temp-list nil
2735   "List of temporary files created by `gnus-article-browse-html-parts'.
2736 Internal variable.")
2737
2738 (defcustom gnus-article-browse-delete-temp 'ask
2739   "What to do with temporary files from `gnus-article-browse-html-parts'.
2740 If nil, don't delete temporary files.  If it is t, delete them on
2741 exit from the summary buffer.  If it is the symbol `file', query
2742 on each file, if it is `ask' ask once when exiting from the
2743 summary buffer."
2744   :group 'gnus-article
2745   :version "23.1" ;; No Gnus
2746   :type '(choice (const :tag "Don't delete" nil)
2747                  (const :tag "Don't ask" t)
2748                  (const :tag "Ask" ask)
2749                  (const :tag "Ask for each file" file)))
2750
2751 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2752
2753 (defun gnus-article-browse-delete-temp-files (&optional how)
2754   "Delete temp-files created by `gnus-article-browse-html-parts'."
2755   (when (and gnus-article-browse-html-temp-list
2756              (progn
2757                (or how (setq how gnus-article-browse-delete-temp))
2758                (if (eq how 'ask)
2759                    (let ((files (length gnus-article-browse-html-temp-list)))
2760                      (or (gnus-y-or-n-p
2761                           (if (= files 1)
2762                               "Delete the temporary HTML file? "
2763                             (format "Delete all %s temporary HTML files? "
2764                                     files)))
2765                          (setq gnus-article-browse-html-temp-list nil)))
2766                  how)))
2767     (dolist (file gnus-article-browse-html-temp-list)
2768       (cond ((file-directory-p file)
2769              (when (or (not (eq how 'file))
2770                        (gnus-y-or-n-p
2771                         (format
2772                          "Delete temporary HTML file(s) in directory `%s'? "
2773                          (file-name-as-directory file))))
2774                (gnus-delete-directory file)))
2775             ((file-exists-p file)
2776              (when (or (not (eq how 'file))
2777                        (gnus-y-or-n-p
2778                         (format "Delete temporary HTML file `%s'? " file)))
2779                (delete-file file)))))
2780     ;; Also remove file from the list when not deleted or if file doesn't
2781     ;; exist anymore.
2782     (setq gnus-article-browse-html-temp-list nil))
2783   gnus-article-browse-html-temp-list)
2784
2785 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2786   "Find CID content in HANDLES and save it in a file in DIRECTORY.
2787 Return file name relative to the parent of DIRECTORY."
2788   (save-match-data
2789     (let (file afile)
2790       (catch 'found
2791         (dolist (handle handles)
2792           (cond
2793            ((not (listp handle)))
2794            ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2795            ;; may create.
2796            ((not (or (bufferp (car handle)) (stringp (car handle)))))
2797            ((equal (mm-handle-media-supertype handle) "multipart")
2798             (when (setq file (gnus-article-browse-html-save-cid-content
2799                               cid handle directory))
2800               (throw 'found file)))
2801            ((equal (concat "<" cid ">") (mm-handle-id handle))
2802             (setq file (or (mm-handle-filename handle)
2803                            (concat
2804                             (make-temp-name "cid")
2805                             (car (rassoc (car (mm-handle-type handle))
2806                                          mailcap-mime-extensions))))
2807                   afile (expand-file-name file directory))
2808             (mm-save-part-to-file handle afile)
2809             (throw 'found (concat (file-name-nondirectory
2810                                    (directory-file-name directory))
2811                                   "/" file)))))))))
2812
2813 (defun gnus-article-browse-html-parts (list &optional header)
2814   "View all \"text/html\" parts from LIST.
2815 Recurse into multiparts.  The optional HEADER that should be a decoded
2816 message header will be added to the bodies of the \"text/html\" parts."
2817   ;; Internal function used by `gnus-article-browse-html-article'.
2818   (let (type file charset content cid-dir tmp-file showed)
2819     ;; Find and show the html-parts.
2820     (dolist (handle list)
2821       ;; If HTML, show it:
2822       (cond ((not (listp handle)))
2823             ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2824                  (and (equal (car type) "message/external-body")
2825                       (or header
2826                           (setq file (mm-handle-filename handle)))
2827                       (or (mm-handle-cache handle)
2828                           (condition-case code
2829                               (progn (mm-extern-cache-contents handle) t)
2830                             (error
2831                              (gnus-message 3 "%s" (error-message-string code))
2832                              (when (>= gnus-verbose 3) (sit-for 2))
2833                              nil)))
2834                       (progn
2835                         (setq handle (mm-handle-cache handle)
2836                               type (mm-handle-type handle))
2837                         (equal (car type) "text/html"))))
2838              (setq charset (mail-content-type-get type 'charset)
2839                    content (mm-get-part handle))
2840              (with-temp-buffer
2841                (if (eq charset 'gnus-decoded)
2842                    (mm-enable-multibyte)
2843                  (mm-disable-multibyte))
2844                (insert content)
2845                ;; resolve cid contents
2846                (let ((case-fold-search t)
2847                      st base regexp cid-file)
2848                  (goto-char (point-min))
2849                  (when (and (re-search-forward "<head[\t\n >]" nil t)
2850                             (progn
2851                               (setq st (match-end 0))
2852                               (re-search-forward "</head[\t\n >]" nil t))
2853                             (re-search-backward "<base\
2854 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2855                    (setq base (match-string 1))
2856                    (replace-match "<!--\\&-->")
2857                    (setq st (point))
2858                    (dolist (tag '(("a" . "href") ("form" . "action")
2859                                   ("img" . "src")))
2860                      (setq regexp (concat "<" (car tag)
2861                                           "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2862                                           (cdr tag) "=\"\\([^\"]+\\)"))
2863                      (while (re-search-forward regexp nil t)
2864                        (insert (prog1
2865                                    (condition-case nil
2866                                        (save-match-data
2867                                          (url-expand-file-name (match-string 1)
2868                                                                base))
2869                                      (error (match-string 1)))
2870                                  (delete-region (match-beginning 1)
2871                                                 (match-end 1)))))
2872                      (goto-char st)))
2873                  (while (re-search-forward "\
2874 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2875                                            nil t)
2876                    (unless cid-dir
2877                      (setq cid-dir (mm-make-temp-file "cid" t))
2878                      (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2879                    (setq file nil
2880                          content nil)
2881                    (when (setq cid-file
2882                                (gnus-article-browse-html-save-cid-content
2883                                 (match-string 2)
2884                                 (with-current-buffer gnus-article-buffer
2885                                   gnus-article-mime-handles)
2886                                 cid-dir))
2887                      (replace-match cid-file nil nil nil 1))))
2888                (unless content (setq content (buffer-string))))
2889              (when (or charset header (not file))
2890                (setq tmp-file (mm-make-temp-file
2891                                ;; Do we need to care for 8.3 filenames?
2892                                "mm-" nil ".html")))
2893              ;; Add a meta html tag to specify charset and a header.
2894              (cond
2895               (header
2896                (let (title eheader body hcharset coding)
2897                  (with-temp-buffer
2898                    (mm-enable-multibyte)
2899                    (setq case-fold-search t)
2900                    (insert header "\n")
2901                    (setq title (message-fetch-field "subject"))
2902                    (goto-char (point-min))
2903                    (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2904                                              nil t)
2905                      (replace-match (cond ((match-beginning 1) "&lt;")
2906                                           ((match-beginning 2) "&gt;")
2907                                           ((match-beginning 3) "&amp;")
2908                                           (t "<br>\n"))))
2909                    (goto-char (point-min))
2910                    (while (re-search-forward "^[\t ]+" nil t)
2911                      (dotimes (i (prog1
2912                                      (current-column)
2913                                    (delete-region (match-beginning 0)
2914                                                   (match-end 0))))
2915                        (insert "&nbsp;")))
2916                    (goto-char (point-min))
2917                    (insert "<div align=\"left\">\n")
2918                    (goto-char (point-max))
2919                    (insert "</div>\n<hr>\n")
2920                    ;; We have to examine charset one by one since
2921                    ;; charset specified in parts might be different.
2922                    (if (eq charset 'gnus-decoded)
2923                        (setq charset 'utf-8
2924                              eheader (mm-encode-coding-string (buffer-string)
2925                                                               charset)
2926                              title (when title
2927                                      (mm-encode-coding-string title charset))
2928                              body (mm-encode-coding-string content charset))
2929                      (setq hcharset (mm-find-mime-charset-region (point-min)
2930                                                                  (point-max)))
2931                      (cond ((= (length hcharset) 1)
2932                             (setq hcharset (car hcharset)
2933                                   coding (mm-charset-to-coding-system
2934                                           hcharset nil t)))
2935                            ((> (length hcharset) 1)
2936                             (setq hcharset 'utf-8
2937                                   coding hcharset)))
2938                      (if coding
2939                          (if charset
2940                              (progn
2941                                (setq body
2942                                      (mm-charset-to-coding-system charset
2943                                                                   nil t))
2944                                (if (eq coding body)
2945                                    (setq eheader (mm-encode-coding-string
2946                                                   (buffer-string) coding)
2947                                          title (when title
2948                                                  (mm-encode-coding-string
2949                                                   title coding))
2950                                          body content)
2951                                  (setq charset 'utf-8
2952                                        eheader (mm-encode-coding-string
2953                                                 (buffer-string) charset)
2954                                        title (when title
2955                                                (mm-encode-coding-string
2956                                                 title charset))
2957                                        body (mm-encode-coding-string
2958                                              (mm-decode-coding-string
2959                                               content body)
2960                                              charset))))
2961                            (setq charset hcharset
2962                                  eheader (mm-encode-coding-string
2963                                           (buffer-string) coding)
2964                                  title (when title
2965                                          (mm-encode-coding-string
2966                                           title coding))
2967                                  body content))
2968                        (setq eheader (mm-string-as-unibyte (buffer-string))
2969                              body content)))
2970                    (erase-buffer)
2971                    (mm-disable-multibyte)
2972                    (insert body)
2973                    (when charset
2974                      (mm-add-meta-html-tag handle charset t))
2975                    (when title
2976                      (goto-char (point-min))
2977                      (unless (search-forward "<title>" nil t)
2978                        (re-search-forward "<head>\\s-*" nil t)
2979                        (insert "<title>" title "</title>\n")))
2980                    (goto-char (point-min))
2981                    (or (re-search-forward
2982                         "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2983                        (re-search-forward
2984                         "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2985                    (insert eheader)
2986                    (mm-write-region (point-min) (point-max)
2987                                     tmp-file nil nil nil 'binary t))))
2988               (charset
2989                (mm-with-unibyte-buffer
2990                  (insert (if (eq charset 'gnus-decoded)
2991                              (mm-encode-coding-string content
2992                                                       (setq charset 'utf-8))
2993                            content))
2994                  (if (or (mm-add-meta-html-tag handle charset)
2995                          (not file))
2996                      (mm-write-region (point-min) (point-max)
2997                                       tmp-file nil nil nil 'binary t)
2998                    (setq tmp-file nil))))
2999               (tmp-file
3000                (mm-save-part-to-file handle tmp-file)))
3001              (when tmp-file
3002                (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3003              (add-hook 'gnus-summary-prepare-exit-hook
3004                        'gnus-article-browse-delete-temp-files)
3005              (add-hook 'gnus-exit-gnus-hook
3006                        (lambda  ()
3007                          (gnus-article-browse-delete-temp-files t)))
3008              ;; FIXME: Warn if there's an <img> tag?
3009              (browse-url-of-file (or tmp-file (expand-file-name file)))
3010              (setq showed t))
3011             ;; If multipart, recurse
3012             ((equal (mm-handle-media-supertype handle) "multipart")
3013              (when (gnus-article-browse-html-parts handle header)
3014                (setq showed t)))
3015             ((equal (mm-handle-media-type handle) "message/rfc822")
3016              (mm-with-multibyte-buffer
3017                (mm-insert-part handle)
3018                (setq handle (mm-dissect-buffer t t))
3019                (when (and (bufferp (car handle))
3020                           (stringp (car (mm-handle-type handle))))
3021                  (setq handle (list handle)))
3022                (when header
3023                  (article-decode-encoded-words)
3024                  (let ((gnus-visible-headers
3025                         (or (get 'gnus-visible-headers 'standard-value)
3026                             gnus-visible-headers)))
3027                    (article-hide-headers))
3028                  (goto-char (point-min))
3029                  (search-forward "\n\n" nil 'move)
3030                  (skip-chars-backward "\t\n ")
3031                  (setq header (buffer-substring (point-min) (point)))))
3032              (when (prog1
3033                        (gnus-article-browse-html-parts handle header)
3034                      (mm-destroy-parts handle))
3035                (setq showed t)))))
3036     showed))
3037
3038 (defun gnus-article-browse-html-article (&optional arg)
3039   "View \"text/html\" parts of the current article with a WWW browser.
3040 Inline images embedded in a message using the cid scheme, as they are
3041 generally considered to be safe, will be processed properly.
3042 The message header is added to the beginning of every html part unless
3043 the prefix argument ARG is given.
3044
3045 Warning: Spammers use links to images (using the http scheme) in HTML
3046 articles to verify whether you have read the message.  As
3047 `gnus-article-browse-html-article' passes the HTML content to the
3048 browser without eliminating these \"web bugs\" you should only
3049 use it for mails from trusted senders.
3050
3051 If you always want to display HTML parts in the browser, set
3052 `mm-text-html-renderer' to nil.
3053
3054 This command creates temporary files to pass HTML contents including
3055 images if any to the browser, and deletes them when exiting the group
3056 \(if you want)."
3057   ;; Cf. `mm-w3m-safe-url-regexp'
3058   (interactive "P")
3059   (if arg
3060       (gnus-summary-show-article)
3061     (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3062                                     gnus-visible-headers))
3063           ;; As we insert a <hr>, there's no need for the body boundary.
3064           (gnus-treat-body-boundary nil))
3065       (gnus-summary-show-article)))
3066   (with-current-buffer gnus-article-buffer
3067     (let ((header (unless arg
3068                     (save-restriction
3069                       (widen)
3070                       (buffer-substring-no-properties
3071                        (goto-char (point-min))
3072                        (if (search-forward "\n\n" nil t)
3073                            (match-beginning 0)
3074                          (goto-char (point-max))
3075                          (skip-chars-backward "\t\n ")
3076                          (point))))))
3077           parts)
3078       (set-buffer gnus-original-article-buffer)
3079       (setq parts (mm-dissect-buffer t t))
3080       ;; If singlepart, enforce a list.
3081       (when (and (bufferp (car parts))
3082                  (stringp (car (mm-handle-type parts))))
3083         (setq parts (list parts)))
3084       ;; Process the list
3085       (unless (gnus-article-browse-html-parts parts header)
3086         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3087       (mm-destroy-parts parts)
3088       (unless arg
3089         (gnus-summary-show-article)))))
3090
3091 (defun article-hide-list-identifiers ()
3092   "Remove list identifiers from the Subject header.
3093 The `gnus-list-identifiers' variable specifies what to do."
3094   (interactive)
3095   (let ((inhibit-point-motion-hooks t)
3096         (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3097         (inhibit-read-only t))
3098     (when regexp
3099       (save-excursion
3100         (save-restriction
3101           (article-narrow-to-head)
3102           (goto-char (point-min))
3103           (while (re-search-forward
3104                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3105                   nil t)
3106             (delete-region (match-beginning 2) (match-end 0))
3107             (beginning-of-line))
3108           (when (re-search-forward
3109                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3110             (delete-region (match-beginning 1) (match-end 1))))))))
3111
3112 (defun article-hide-pem (&optional arg)
3113   "Toggle hiding of any PEM headers and signatures in the current article.
3114 If given a negative prefix, always show; if given a positive prefix,
3115 always hide."
3116   (interactive (gnus-article-hidden-arg))
3117   (unless (gnus-article-check-hidden-text 'pem arg)
3118     (save-excursion
3119       (let ((inhibit-read-only t) end)
3120         (goto-char (point-min))
3121         ;; Hide the horrendously ugly "header".
3122         (when (and (search-forward
3123                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3124                     nil t)
3125                    (setq end (1+ (match-beginning 0))))
3126           (gnus-add-wash-type 'pem)
3127           (gnus-article-hide-text-type
3128            end
3129            (if (search-forward "\n\n" nil t)
3130                (match-end 0)
3131              (point-max))
3132            'pem)
3133           ;; Hide the trailer as well
3134           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3135                                 nil t)
3136             (gnus-article-hide-text-type
3137              (match-beginning 0) (match-end 0) 'pem)))))))
3138
3139 (defun article-strip-banner ()
3140   "Strip the banners specified by the `banner' group parameter and by
3141 `gnus-article-address-banner-alist'."
3142   (interactive)
3143   (save-excursion
3144     (save-restriction
3145       (let ((inhibit-point-motion-hooks t))
3146         (when (gnus-parameter-banner gnus-newsgroup-name)
3147           (article-really-strip-banner
3148            (gnus-parameter-banner gnus-newsgroup-name)))
3149         (when gnus-article-address-banner-alist
3150           ;; Note that the From header is decoded here, so it is
3151           ;; required that the *-extract-address-components function
3152           ;; supports non-ASCII text.
3153           (let ((from (save-restriction
3154                         (widen)
3155                         (article-narrow-to-head)
3156                         (mail-fetch-field "from"))))
3157             (when (and from
3158                        (setq from
3159                              (cadr (funcall gnus-extract-address-components
3160                                             from))))
3161               (catch 'found
3162                 (dolist (pair gnus-article-address-banner-alist)
3163                   (when (string-match (car pair) from)
3164                     (throw 'found
3165                            (article-really-strip-banner (cdr pair)))))))))))))
3166
3167 (defun article-really-strip-banner (banner)
3168   "Strip the banner specified by the argument."
3169   (save-excursion
3170     (save-restriction
3171       (let ((inhibit-point-motion-hooks t)
3172             (gnus-signature-limit nil)
3173             (inhibit-read-only t))
3174         (article-goto-body)
3175         (cond
3176          ((eq banner 'signature)
3177           (when (gnus-article-narrow-to-signature)
3178             (widen)
3179             (forward-line -1)
3180             (delete-region (point) (point-max))))
3181          ((symbolp banner)
3182           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3183               (while (re-search-forward banner nil t)
3184                 (delete-region (match-beginning 0) (match-end 0)))))
3185          ((stringp banner)
3186           (while (re-search-forward banner nil t)
3187             (delete-region (match-beginning 0) (match-end 0)))))))))
3188
3189 (defun article-babel ()
3190   "Translate article using an online translation service."
3191   (interactive)
3192   (require 'babel)
3193   (gnus-with-article-buffer
3194     (when (article-goto-body)
3195       (let* ((start (point))
3196              (end (point-max))
3197              (orig (buffer-substring start end))
3198              (trans (babel-as-string orig)))
3199         (save-restriction
3200           (narrow-to-region start end)
3201           (delete-region start end)
3202           (insert trans))))))
3203
3204 (defun article-hide-signature (&optional arg)
3205   "Hide the signature in the current article.
3206 If given a negative prefix, always show; if given a positive prefix,
3207 always hide."
3208   (interactive (gnus-article-hidden-arg))
3209   (unless (gnus-article-check-hidden-text 'signature arg)
3210     (save-excursion
3211       (save-restriction
3212         (let ((inhibit-read-only t))
3213           (when (gnus-article-narrow-to-signature)
3214             (gnus-article-hide-text-type
3215              (point-min) (point-max) 'signature))))))
3216   (gnus-set-mode-line 'article))
3217
3218 (defun article-strip-headers-in-body ()
3219   "Strip offensive headers from bodies."
3220   (interactive)
3221   (save-excursion
3222     (article-goto-body)
3223     (let ((case-fold-search t))
3224       (when (looking-at "x-no-archive:")
3225         (gnus-delete-line)))))
3226
3227 (defun article-strip-leading-blank-lines ()
3228   "Remove all blank lines from the beginning of the article."
3229   (interactive)
3230   (save-excursion
3231     (let ((inhibit-point-motion-hooks t)
3232           (inhibit-read-only t))
3233       (when (article-goto-body)
3234         (while (and (not (eobp))
3235                     (looking-at "[ \t]*$"))
3236           (gnus-delete-line))))))
3237
3238 (defun article-narrow-to-head ()
3239   "Narrow the buffer to the head of the message.
3240 Point is left at the beginning of the narrowed-to region."
3241   (narrow-to-region
3242    (goto-char (point-min))
3243    (cond
3244     ;; Absolutely no headers displayed.
3245     ((looking-at "\n")
3246      (point))
3247     ;; Normal headers.
3248     ((search-forward "\n\n" nil 1)
3249      (1- (point)))
3250     ;; Nothing but headers.
3251     (t
3252      (point-max))))
3253   (goto-char (point-min)))
3254
3255 (defun article-goto-body ()
3256   "Place point at the start of the body."
3257   (goto-char (point-min))
3258   (cond
3259    ;; This variable is only bound when dealing with separate
3260    ;; MIME body parts.
3261    (article-goto-body-goes-to-point-min-p
3262     t)
3263    ((search-forward "\n\n" nil t)
3264     t)
3265    (t
3266     (goto-char (point-max))
3267     nil)))
3268
3269 (defun article-strip-multiple-blank-lines ()
3270   "Replace consecutive blank lines with one empty line."
3271   (interactive)
3272   (save-excursion
3273     (let ((inhibit-point-motion-hooks t)
3274           (inhibit-read-only t))
3275       ;; First make all blank lines empty.
3276       (article-goto-body)
3277       (while (re-search-forward "^[ \t]+$" nil t)
3278         (unless (gnus-annotation-in-region-p
3279                  (match-beginning 0) (match-end 0))
3280           (replace-match "" nil t)))
3281       ;; Then replace multiple empty lines with a single empty line.
3282       (article-goto-body)
3283       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3284         (unless (gnus-annotation-in-region-p
3285                  (match-beginning 0) (match-end 0))
3286           (delete-region (match-beginning 1) (match-end 1)))))))
3287
3288 (defun article-strip-leading-space ()
3289   "Remove all white space from the beginning of the lines in the article."
3290   (interactive)
3291   (save-excursion
3292     (let ((inhibit-point-motion-hooks t)
3293           (inhibit-read-only t))
3294       (article-goto-body)
3295       (while (re-search-forward "^[ \t]+" nil t)
3296         (replace-match "" t t)))))
3297
3298 (defun article-strip-trailing-space ()
3299   "Remove all white space from the end of the lines in the article."
3300   (interactive)
3301   (save-excursion
3302     (let ((inhibit-point-motion-hooks t)
3303           (inhibit-read-only t))
3304       (article-goto-body)
3305       (while (re-search-forward "[ \t]+$" nil t)
3306         (replace-match "" t t)))))
3307
3308 (defun article-strip-blank-lines ()
3309   "Strip leading, trailing and multiple blank lines."
3310   (interactive)
3311   (article-strip-leading-blank-lines)
3312   (article-remove-trailing-blank-lines)
3313   (article-strip-multiple-blank-lines))
3314
3315 (defun article-strip-all-blank-lines ()
3316   "Strip all blank lines."
3317   (interactive)
3318   (save-excursion
3319     (let ((inhibit-point-motion-hooks t)
3320           (inhibit-read-only t))
3321       (article-goto-body)
3322       (while (re-search-forward "^[ \t]*\n" nil t)
3323         (replace-match "" t t)))))
3324
3325 (defun gnus-article-narrow-to-signature ()
3326   "Narrow to the signature; return t if a signature is found, else nil."
3327   (let ((inhibit-point-motion-hooks t))
3328     (when (gnus-article-search-signature)
3329       (forward-line 1)
3330       ;; Check whether we have some limits to what we consider
3331       ;; to be a signature.
3332       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3333                       (list gnus-signature-limit)))
3334             limit limited)
3335         (while (setq limit (pop limits))
3336           (if (or (and (integerp limit)
3337                        (< (- (point-max) (point)) limit))
3338                   (and (floatp limit)
3339                        (< (count-lines (point) (point-max)) limit))
3340                   (and (functionp limit)
3341                        (funcall limit))
3342                   (and (stringp limit)
3343                        (not (re-search-forward limit nil t))))
3344               ()                        ; This limit did not succeed.
3345             (setq limited t
3346                   limits nil)))
3347         (unless limited
3348           (narrow-to-region (point) (point-max))
3349           t)))))
3350
3351 (defun gnus-article-search-signature ()
3352   "Search the current buffer for the signature separator.
3353 Put point at the beginning of the signature separator."
3354   (let ((cur (point)))
3355     (goto-char (point-max))
3356     (if (if (stringp gnus-signature-separator)
3357             (re-search-backward gnus-signature-separator nil t)
3358           (let ((seps gnus-signature-separator))
3359             (while (and seps
3360                         (not (re-search-backward (car seps) nil t)))
3361               (pop seps))
3362             seps))
3363         t
3364       (goto-char cur)
3365       nil)))
3366
3367 (defun gnus-article-hidden-arg ()
3368   "Return the current prefix arg as a number, or 0 if no prefix."
3369   (list (if current-prefix-arg
3370             (prefix-numeric-value current-prefix-arg)
3371           0)))
3372
3373 (defun gnus-article-check-hidden-text (type arg)
3374   "Return nil if hiding is necessary.
3375 Arg can be nil or a number.  nil and positive means hide, negative
3376 means show, 0 means toggle."
3377   (save-excursion
3378     (save-restriction
3379       (let ((hide (gnus-article-hidden-text-p type)))
3380         (cond
3381          ((or (null arg)
3382               (> arg 0))
3383           nil)
3384          ((< arg 0)
3385           (gnus-article-show-hidden-text type)
3386           t)
3387          (t
3388           (if (eq hide 'hidden)
3389               (progn
3390                 (gnus-article-show-hidden-text type)
3391                 t)
3392             nil)))))))
3393
3394 (defun gnus-article-hidden-text-p (type)
3395   "Say whether the current buffer contains hidden text of type TYPE."
3396   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3397     (while (and pos
3398                 (not (get-text-property pos 'invisible))
3399                 (not (get-text-property pos 'dummy-invisible)))
3400       (setq pos
3401             (text-property-any (1+ pos) (point-max) 'article-type type)))
3402     (if pos
3403         'hidden
3404       nil)))
3405
3406 (defun gnus-article-show-hidden-text (type &optional _dummy)
3407   "Show all hidden text of type TYPE.
3408 Originally it is hide instead of DUMMY."
3409   (let ((inhibit-read-only t)
3410         (inhibit-point-motion-hooks t))
3411     (gnus-remove-text-properties-when
3412      'article-type type
3413      (point-min) (point-max)
3414      (cons 'article-type (cons type
3415                                gnus-hidden-properties)))
3416     (gnus-delete-wash-type type)))
3417
3418 (defconst article-time-units
3419   `((year . ,(* 365.25 24 60 60))
3420     (week . ,(* 7 24 60 60))
3421     (day . ,(* 24 60 60))
3422     (hour . ,(* 60 60))
3423     (minute . 60)
3424     (second . 1))
3425   "Mapping from time units to seconds.")
3426
3427 (defun gnus-article-forward-header ()
3428   "Move point to the start of the next header.
3429 If the current header is a continuation header, this can be several
3430 lines forward."
3431   (let ((ended nil))
3432     (while (not ended)
3433       (forward-line 1)
3434       (if (looking-at "[ \t]+[^ \t]")
3435           (forward-line 1)
3436         (setq ended t)))))
3437
3438 (defun article-treat-date ()
3439   (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3440                        (with-current-buffer gnus-summary-buffer
3441                          gnus-article-date-headers)
3442                      gnus-article-date-headers)
3443                    t))
3444
3445 (defun article-date-ut (&optional type _highlight date-position)
3446   "Convert DATE date to TYPE in the current article.
3447 The default type is `ut'.  See `gnus-article-date-headers' for
3448 possible values."
3449   (interactive (list 'ut t))
3450   (let* ((case-fold-search t)
3451          (inhibit-read-only t)
3452          (inhibit-point-motion-hooks t)
3453          (visible-date (mail-fetch-field "Date"))
3454          pos date bface eface)
3455     (save-excursion
3456       (if date-position
3457           (progn
3458             (goto-char date-position)
3459             (setq date (get-text-property (point) 'original-date))
3460             (when (looking-at "[^:]+:[\t ]*")
3461               (setq bface (get-text-property (match-beginning 0) 'face)
3462                     eface (get-text-property (match-end 0) 'face)))
3463             (delete-region (point)
3464                            (progn
3465                              (gnus-article-forward-header)
3466                              (point)))
3467             (article-transform-date date type bface eface))
3468         (save-restriction
3469           (widen)
3470           (goto-char (point-min))
3471           (while (or (get-text-property (setq pos (point)) 'original-date)
3472                      (and (setq pos (next-single-property-change
3473                                      (point) 'original-date))
3474                           (goto-char pos)))
3475             (narrow-to-region pos (if (search-forward "\n\n" nil t)
3476                                       (1+ (match-beginning 0))
3477                                     (point-max)))
3478             (while (setq pos (text-property-not-all pos (point-max)
3479                                                     'gnus-date-type nil))
3480               (setq date (get-text-property pos 'original-date))
3481               (goto-char pos)
3482               (when (looking-at "[^:]+:[\t ]*")
3483                 (setq bface (get-text-property (match-beginning 0) 'face)
3484                       eface (get-text-property (match-end 0) 'face)))
3485               (delete-region pos (or (text-property-any pos (point-max)
3486                                                         'gnus-date-type nil)
3487                                      (point-max))))
3488             (unless date ;; the 1st time
3489               (goto-char (point-min))
3490               (while (re-search-forward "^Date:[\t ]*" nil t)
3491                 (setq date (get-text-property (match-beginning 0)
3492                                               'original-date)
3493                       bface (get-text-property (match-beginning 0) 'face)
3494                       eface (get-text-property (match-end 0) 'face))
3495                 (delete-region (point-at-bol) (progn
3496                                                 (gnus-article-forward-header)
3497                                                 (point)))))
3498             (when (and (not date)
3499                        visible-date)
3500               (setq date visible-date))
3501             (when date
3502               (article-transform-date date type bface eface))
3503             (goto-char (point-max))
3504             (widen)))))))
3505
3506 (defun article-transform-date (date type bface eface)
3507   (dolist (this-type (cond
3508                       ((null type)
3509                        (list 'ut))
3510                       ((atom type)
3511                        (list type))
3512                       (t
3513                        type)))
3514     (goto-char
3515      (prog1
3516          (point)
3517        (add-text-properties
3518         (point)
3519         (progn
3520           (insert (article-make-date-line date (or this-type 'ut)) "\n")
3521           (point))
3522         (list 'original-date date 'gnus-date-type this-type))))
3523     ;; Do highlighting.
3524     (when (looking-at
3525            "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3526       (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3527       (when (match-beginning 2)
3528         (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3529       (while (and (zerop (forward-line 1))
3530                   (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3531         (when (match-beginning 1)
3532           (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3533
3534 (defun article-make-date-line (date type)
3535   "Return a DATE line of TYPE."
3536   (unless (memq type '(local ut original user-defined iso8601 lapsed english
3537                              combined-lapsed))
3538     (error "Unknown conversion type: %s" type))
3539   (condition-case ()
3540       (let ((time (ignore-errors (date-to-time date))))
3541         (cond
3542          ;; Convert to the local timezone.
3543          ((eq type 'local)
3544           (concat "Date: " (message-make-date time)))
3545          ;; Convert to Universal Time.
3546          ((eq type 'ut)
3547           (concat "Date: "
3548                   (substring
3549                    (message-make-date
3550                     (let* ((e (parse-time-string date))
3551                            (tm (apply 'encode-time e))
3552                            (ms (car tm))
3553                            (ls (- (cadr tm) (car (current-time-zone time)))))
3554                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3555                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3556                             (t (list ms ls)))))
3557                    0 -5)
3558                   "UT"))
3559          ;; Get the original date from the article.
3560          ((eq type 'original)
3561           (concat "Date: " (if (string-match "\n+$" date)
3562                                (substring date 0 (match-beginning 0))
3563                              date)))
3564          ;; Let the user define the format.
3565          ((eq type 'user-defined)
3566           (let ((format (or (condition-case nil
3567                                 (with-current-buffer gnus-summary-buffer
3568                                   gnus-article-time-format)
3569                               (error nil))
3570                             gnus-article-time-format)))
3571             (if (functionp format)
3572                 (funcall format time)
3573               (concat "Date: " (format-time-string format time)))))
3574          ;; ISO 8601.
3575          ((eq type 'iso8601)
3576           (let ((tz (car (current-time-zone time))))
3577             (concat
3578              "Date: "
3579              (format-time-string "%Y%m%dT%H%M%S" time)
3580              (format "%s%02d%02d"
3581                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3582                      (/ (% (abs tz) 3600) 60)))))
3583          ;; Do a lapsed format.
3584          ((eq type 'lapsed)
3585           (concat "Date: " (article-lapsed-string time)))
3586          ;; A combined date/lapsed format.
3587          ((eq type 'combined-lapsed)
3588           (let ((date-string (article-make-date-line date 'original))
3589                 (segments 3)
3590                 lapsed-string)
3591             (while (and
3592                     time
3593                     (setq lapsed-string
3594                           (concat " (" (article-lapsed-string time segments) ")"))
3595                     (> (+ (length date-string)
3596                           (length lapsed-string))
3597                        (+ fill-column 6))
3598                     (> segments 0))
3599               (setq segments (1- segments)))
3600             (if (> segments 0)
3601                 (concat date-string lapsed-string)
3602               date-string)))
3603          ;; Display the date in proper English
3604          ((eq type 'english)
3605           (let ((dtime (decode-time time)))
3606             (concat
3607              "Date: the "
3608              (number-to-string (nth 3 dtime))
3609              (let ((digit (% (nth 3 dtime) 10)))
3610                (cond
3611                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3612                 ((= digit 1) "st")
3613                 ((= digit 2) "nd")
3614                 ((= digit 3) "rd")
3615                 (t "th")))
3616              " of "
3617              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3618              " "
3619              (number-to-string (nth 5 dtime))
3620              " at "
3621              (format "%02d" (nth 2 dtime))
3622              ":"
3623              (format "%02d" (nth 1 dtime)))))))
3624     (foo
3625      (format "Date: %s (from Gnus)" date))))
3626
3627 (defun article-lapsed-string (time &optional max-segments)
3628   ;; If the date is seriously mangled, the timezone functions are
3629   ;; liable to bug out, so we ignore all errors.
3630   (let* ((now (current-time))
3631          (real-time (subtract-time now time))
3632          (real-sec (and real-time
3633                         (+ (* (float (car real-time)) 65536)
3634                            (cadr real-time))))
3635          (sec (and real-time (abs real-sec)))
3636          (segments 0)
3637          num prev)
3638     (unless max-segments
3639       (setq max-segments (length article-time-units)))
3640     (cond
3641      ((null real-time)
3642       "Unknown")
3643      ((zerop sec)
3644       "Now")
3645      (t
3646       (concat
3647        ;; This is a bit convoluted, but basically we go
3648        ;; through the time units for years, weeks, etc,
3649        ;; and divide things to see whether that results
3650        ;; in positive answers.
3651        (mapconcat
3652         (lambda (unit)
3653           (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3654                   (>= segments max-segments))
3655               ;; The (remaining) seconds are too few to
3656               ;; be divided into this time unit.
3657               ""
3658             ;; It's big enough, so we output it.
3659             (setq sec (- sec (* num (cdr unit))))
3660             (prog1
3661                 (concat (if prev ", " "") (int-to-string
3662                                            (floor num))
3663                         " " (symbol-name (car unit))
3664                         (if (> num 1) "s" ""))
3665               (setq prev t
3666                     segments (1+ segments)))))
3667         article-time-units "")
3668        ;; If dates are odd, then it might appear like the
3669        ;; article was sent in the future.
3670        (if (> real-sec 0)
3671            " ago"
3672          " in the future"))))))
3673
3674 (defun article-date-local (&optional highlight)
3675   "Convert the current article date to the local timezone."
3676   (interactive (list t))
3677   (article-date-ut 'local highlight))
3678
3679 (defun article-date-english (&optional highlight)
3680   "Convert the current article date to something that is proper English."
3681   (interactive (list t))
3682   (article-date-ut 'english highlight))
3683
3684 (defun article-date-original (&optional highlight)
3685   "Convert the current article date to what it was originally.
3686 This is only useful if you have used some other date conversion
3687 function and want to see what the date was before converting."
3688   (interactive (list t))
3689   (article-date-ut 'original highlight))
3690
3691 (defun article-date-lapsed (&optional highlight)
3692   "Convert the current article date to time lapsed since it was sent."
3693   (interactive (list t))
3694   (article-date-ut 'lapsed highlight))
3695
3696 (defun article-date-combined-lapsed (&optional highlight)
3697   "Convert the current article date to time lapsed since it was sent."
3698   (interactive (list t))
3699   (article-date-ut 'combined-lapsed highlight))
3700
3701 (defun article-update-date-lapsed ()
3702   "Function to be run from a timer to update the lapsed time line."
3703   (save-match-data
3704     (let ((buffer (current-buffer)))
3705       (ignore-errors
3706         (walk-windows
3707          (lambda (w)
3708            (set-buffer (window-buffer w))
3709            (when (derived-mode-p 'gnus-article-mode)
3710              (let ((old-line (count-lines (point-min) (point)))
3711                    (old-column (- (point) (line-beginning-position)))
3712                    (window-start (window-start w))
3713                    (pos (point-min))
3714                    type next end)
3715                (while (setq pos (text-property-not-all pos (point-max)
3716                                                        'gnus-date-type nil))
3717                  (setq next (or (next-single-property-change pos
3718                                                              'gnus-date-type)
3719                                 (point-max)))
3720                  (setq type (get-text-property pos 'gnus-date-type))
3721                  (when (memq type '(lapsed combined-lapsed user-defined))
3722                    (article-date-ut type t pos)
3723                    (setq end (or (next-single-property-change pos
3724                                                               'gnus-date-type)
3725                                  (point-max)))
3726                    (when window-start
3727                      (if (/= window-start next)
3728                          (setq window-start nil)
3729                        (set-window-start w end)))
3730                    (setq next end))
3731                  (setq pos next))
3732                (goto-char (point-min))
3733                (when (> old-column 0)
3734                  (setq old-line (1- old-line)))
3735                (forward-line old-line)
3736                (end-of-line)
3737                (when (> (current-column) old-column)
3738                  (beginning-of-line)
3739                  (forward-char old-column)))))
3740          nil 'visible))
3741       (set-buffer buffer))))
3742
3743 (defun gnus-start-date-timer (&optional n)
3744   "Start a timer to update the Date headers in the article buffers.
3745 The numerical prefix says how frequently (in seconds) the function
3746 is to run."
3747   (interactive "p")
3748   (unless n
3749     (setq n 1))
3750   (gnus-stop-date-timer)
3751   (setq article-lapsed-timer
3752         (run-at-time 1 n 'article-update-date-lapsed)))
3753
3754 (defun gnus-stop-date-timer ()
3755   "Stop the Date timer."
3756   (interactive)
3757   (when article-lapsed-timer
3758     (nnheader-cancel-timer article-lapsed-timer)
3759     (setq article-lapsed-timer nil)))
3760
3761 (defun article-date-user (&optional highlight)
3762   "Convert the current article date to the user-defined format.
3763 This format is defined by the `gnus-article-time-format' variable."
3764   (interactive (list t))
3765   (article-date-ut 'user highlight))
3766
3767 (defun article-date-iso8601 (&optional highlight)
3768   "Convert the current article date to ISO8601."
3769   (interactive (list t))
3770   (article-date-ut 'iso8601 highlight))
3771
3772 (defmacro gnus-article-save-original-date (&rest forms)
3773   "Save the original date as a text property and evaluate FORMS."
3774   `(let* ((case-fold-search t)
3775           (start (progn
3776                    (goto-char (point-min))
3777                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3778                               (not (bolp)))
3779                      (match-end 0))))
3780           (date (when (and start
3781                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3782                                               nil t))
3783                   (buffer-substring-no-properties start
3784                                                   (match-beginning 0)))))
3785      (goto-char (point-max))
3786      (skip-chars-backward "\n")
3787      (put-text-property (point-min) (point) 'original-date date)
3788      ,@forms
3789      (goto-char (point-max))
3790      (skip-chars-backward "\n")
3791      (put-text-property (point-min) (point) 'original-date date)))
3792
3793 ;; (defun article-show-all ()
3794 ;;   "Show all hidden text in the article buffer."
3795 ;;   (interactive)
3796 ;;   (save-excursion
3797 ;;     (let ((inhibit-read-only t))
3798 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3799
3800 (defun article-remove-leading-whitespace ()
3801   "Remove excessive whitespace from all headers."
3802   (interactive)
3803   (save-excursion
3804     (save-restriction
3805       (let ((inhibit-read-only t))
3806         (article-narrow-to-head)
3807         (goto-char (point-min))
3808         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3809           (delete-region (match-beginning 1) (match-end 1)))))))
3810
3811 (defun article-emphasize (&optional arg)
3812   "Emphasize text according to `gnus-emphasis-alist'."
3813   (interactive (gnus-article-hidden-arg))
3814   (unless (gnus-article-check-hidden-text 'emphasis arg)
3815     (save-excursion
3816       (let ((alist (or
3817                     (condition-case nil
3818                         (with-current-buffer gnus-summary-buffer
3819                           gnus-article-emphasis-alist)
3820                       (error))
3821                     gnus-emphasis-alist))
3822             (inhibit-read-only t)
3823             (props (append '(article-type emphasis)
3824                            gnus-hidden-properties))
3825             regexp elem beg invisible visible face)
3826         (article-goto-body)
3827         (setq beg (point))
3828         (while (setq elem (pop alist))
3829           (goto-char beg)
3830           (setq regexp (car elem)
3831                 invisible (nth 1 elem)
3832                 visible (nth 2 elem)
3833                 face (nth 3 elem))
3834           (while (re-search-forward regexp nil t)
3835             (when (and (match-beginning visible) (match-beginning invisible))
3836               (gnus-article-hide-text
3837                (match-beginning invisible) (match-end invisible) props)
3838               (gnus-article-unhide-text-type
3839                (match-beginning visible) (match-end visible) 'emphasis)
3840               (gnus-put-overlay-excluding-newlines
3841                (match-beginning visible) (match-end visible) 'face face)
3842               (gnus-add-wash-type 'emphasis)
3843               (goto-char (match-end invisible)))))))))
3844
3845 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3846   "Setup newsgroup emphasis alist."
3847   (unless gnus-article-emphasis-alist
3848     (let ((name (and gnus-newsgroup-name
3849                      (gnus-group-real-name gnus-newsgroup-name))))
3850       (make-local-variable 'gnus-article-emphasis-alist)
3851       (setq gnus-article-emphasis-alist
3852             (nconc
3853              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3854                (while (setq elem (pop alist))
3855                  (when (and name (string-match (car elem) name))
3856                    (setq alist nil
3857                          highlight (copy-sequence (cdr elem)))))
3858                highlight)
3859              (copy-sequence highlight-words)
3860              (if gnus-newsgroup-name
3861                  (copy-sequence (gnus-group-find-parameter
3862                                  gnus-newsgroup-name 'highlight-words t)))
3863              gnus-emphasis-alist)))))
3864
3865 (defvar gnus-summary-article-menu)
3866 (defvar gnus-summary-post-menu)
3867
3868 ;;; Saving functions.
3869
3870 (defun gnus-article-save (save-buffer file &optional num)
3871   "Save the currently selected article."
3872   (when (or (get gnus-default-article-saver :headers)
3873             (not gnus-save-all-headers))
3874     ;; Remove headers according to `gnus-saved-headers' or the value
3875     ;; of the `:headers' property that the saver function might have.
3876     (let ((gnus-visible-headers
3877            (or (symbol-value (get gnus-default-article-saver :headers))
3878                gnus-saved-headers gnus-visible-headers))
3879           ;; Ignore group parameter.  See `article-hide-headers'.
3880           (gnus-summary-buffer nil))
3881       (with-current-buffer save-buffer
3882         (article-hide-headers 1 t))))
3883   (save-window-excursion
3884     (if (not gnus-default-article-saver)
3885         (error "No default saver is defined")
3886       ;; !!! Magic!  The saving functions all save
3887       ;; `gnus-save-article-buffer' (or so they think), but we
3888       ;; bind that variable to our save-buffer.
3889       (set-buffer gnus-article-buffer)
3890       (let* ((gnus-save-article-buffer save-buffer)
3891              (filename
3892               (cond
3893                ((not gnus-prompt-before-saving) 'default)
3894                ((eq gnus-prompt-before-saving 'always) nil)
3895                (t file)))
3896              (gnus-number-of-articles-to-be-saved
3897               (when (eq gnus-prompt-before-saving t)
3898                 num)))                  ; Magic
3899         (set-buffer gnus-article-current-summary)
3900         (funcall gnus-default-article-saver filename)))))
3901
3902 (defun gnus-read-save-file-name (prompt &optional filename
3903                                         function group headers variable
3904                                         dir-var)
3905   (let ((default-name
3906           (funcall function group headers (symbol-value variable)))
3907         result)
3908     (setq result
3909           (expand-file-name
3910            (cond
3911             ((eq filename 'default)
3912              default-name)
3913             ((eq filename t)
3914              default-name)
3915             (filename filename)
3916             (t
3917              (when (symbol-value dir-var)
3918                (setq default-name (expand-file-name
3919                                    (file-name-nondirectory default-name)
3920                                    (symbol-value dir-var))))
3921              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3922                     (prompt
3923                      (format prompt
3924                              (if (and gnus-number-of-articles-to-be-saved
3925                                       (> gnus-number-of-articles-to-be-saved 1))
3926                                  (format "these %d articles"
3927                                          gnus-number-of-articles-to-be-saved)
3928                                "this article")))
3929                     (file
3930                      ;; Let the split methods have their say.
3931                      (cond
3932                       ;; No split name was found.
3933                       ((null split-name)
3934                        (read-file-name
3935                         (concat prompt " (default "
3936                                 (file-name-nondirectory default-name) "): ")
3937                         (file-name-directory default-name)
3938                         default-name))
3939                       ;; A single group name is returned.
3940                       ((stringp split-name)
3941                        (setq default-name
3942                              (funcall function split-name headers
3943                                       (symbol-value variable)))
3944                        (read-file-name
3945                         (concat prompt " (default "
3946                                 (file-name-nondirectory default-name) "): ")
3947                         (file-name-directory default-name)
3948                         default-name))
3949                       ;; A single split name was found
3950                       ((= 1 (length split-name))
3951                        (let* ((name (expand-file-name
3952                                      (car split-name)
3953                                      gnus-article-save-directory))
3954                               (dir (cond ((file-directory-p name)
3955                                           (file-name-as-directory name))
3956                                          ((file-exists-p name) name)
3957                                          (t gnus-article-save-directory))))
3958                          (read-file-name
3959                           (concat prompt " (default " name "): ")
3960                           dir name)))
3961                       ;; A list of splits was found.
3962                       (t
3963                        (setq split-name (nreverse split-name))
3964                        (let (result)
3965                          (let ((file-name-history
3966                                 (nconc split-name file-name-history)))
3967                            (setq result
3968                                  (expand-file-name
3969                                   (read-file-name
3970                                    (concat prompt " (`M-p' for defaults): ")
3971                                    gnus-article-save-directory
3972                                    (car split-name))
3973                                   gnus-article-save-directory)))
3974                          (car (push result file-name-history)))))))
3975                ;; Create the directory.
3976                (gnus-make-directory (file-name-directory file))
3977                ;; If we have read a directory, we append the default file name.
3978                (when (file-directory-p file)
3979                  (setq file (expand-file-name (file-name-nondirectory
3980                                                default-name)
3981                                               (file-name-as-directory file))))
3982                ;; Possibly translate some characters.
3983                (nnheader-translate-file-chars file))))))
3984     (gnus-make-directory (file-name-directory result))
3985     (when variable
3986       (set variable result))
3987     (when dir-var
3988       (set dir-var (file-name-directory result)))
3989     result))
3990
3991 (defun gnus-article-archive-name (_group)
3992   "Return the first instance of an \"Archive-name\" in the current buffer."
3993   (let ((case-fold-search t))
3994     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3995       (nnheader-concat gnus-article-save-directory
3996                        (match-string 1)))))
3997
3998 (defun gnus-article-nndoc-name (group)
3999   "If GROUP is an nndoc group, return the name of the parent group."
4000   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4001     (gnus-group-get-parameter group 'save-article-group)))
4002
4003 (defun gnus-summary-save-in-rmail (&optional filename)
4004   "Append this article to Rmail file.
4005 Optional argument FILENAME specifies file name.
4006 Directory to save to is default to `gnus-article-save-directory'."
4007   (setq filename (gnus-read-save-file-name
4008                   "Save %s in rmail file" filename
4009                   gnus-rmail-save-name gnus-newsgroup-name
4010                   gnus-current-headers 'gnus-newsgroup-last-rmail))
4011   (with-current-buffer gnus-save-article-buffer
4012     (save-excursion
4013       (save-restriction
4014         (widen)
4015         ;; Note that unlike gnus-summary-save-in-mail, there is no
4016         ;; check to see if filename is Babyl.  Rmail in Emacs 23 does
4017         ;; not use Babyl.
4018         (gnus-output-to-rmail filename))))
4019   filename)
4020
4021 (defun gnus-summary-save-in-mail (&optional filename)
4022   "Append this article to Unix mail file.
4023 Optional argument FILENAME specifies file name.
4024 Directory to save to is default to `gnus-article-save-directory'."
4025   (setq filename (gnus-read-save-file-name
4026                   "Save %s in Unix mail file" filename
4027                   gnus-mail-save-name gnus-newsgroup-name
4028                   gnus-current-headers 'gnus-newsgroup-last-mail))
4029   (with-current-buffer gnus-save-article-buffer
4030     (save-excursion
4031       (save-restriction
4032         (widen)
4033         (if (and (file-readable-p filename)
4034                  (file-regular-p filename)
4035                  (mail-file-babyl-p filename))
4036             (gnus-output-to-rmail filename)
4037           (gnus-output-to-mail filename)))))
4038   filename)
4039
4040 (put 'gnus-summary-save-in-file :decode t)
4041 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4042 (defun gnus-summary-save-in-file (&optional filename overwrite)
4043   "Append this article to file.
4044 Optional argument FILENAME specifies file name.
4045 Directory to save to is default to `gnus-article-save-directory'."
4046   (setq filename (gnus-read-save-file-name
4047                   "Save %s in file" filename
4048                   gnus-file-save-name gnus-newsgroup-name
4049                   gnus-current-headers 'gnus-newsgroup-last-file))
4050   (with-current-buffer gnus-save-article-buffer
4051     (save-excursion
4052       (save-restriction
4053         (widen)
4054         (when (and overwrite
4055                    (file-exists-p filename))
4056           (delete-file filename))
4057         (gnus-output-to-file filename))))
4058   filename)
4059
4060 (put 'gnus-summary-write-to-file :decode t)
4061 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4062 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4063 (defun gnus-summary-write-to-file (&optional filename)
4064   "Write this article to a file, overwriting it if the file exists.
4065 Optional argument FILENAME specifies file name.
4066 The directory to save in defaults to `gnus-article-save-directory'."
4067   (setq filename (gnus-read-save-file-name
4068                   "Save %s in file" filename
4069                   gnus-file-save-name gnus-newsgroup-name
4070                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
4071   (gnus-summary-save-in-file filename t))
4072
4073 (put 'gnus-summary-save-body-in-file :decode t)
4074 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4075   "Append this article body to a file.
4076 Optional argument FILENAME specifies file name.
4077 The directory to save in defaults to `gnus-article-save-directory'."
4078   (setq filename (gnus-read-save-file-name
4079                   "Save %s body in file" filename
4080                   gnus-file-save-name gnus-newsgroup-name
4081                   gnus-current-headers 'gnus-newsgroup-last-file))
4082   (with-current-buffer gnus-save-article-buffer
4083     (save-excursion
4084       (save-restriction
4085         (widen)
4086         (when (article-goto-body)
4087           (narrow-to-region (point) (point-max)))
4088         (when (and overwrite
4089                    (file-exists-p filename))
4090           (delete-file filename))
4091         (gnus-output-to-file filename))))
4092   filename)
4093
4094 (put 'gnus-summary-write-body-to-file :decode t)
4095 (put 'gnus-summary-write-body-to-file
4096      :function 'gnus-summary-save-body-in-file)
4097 (defun gnus-summary-write-body-to-file (&optional filename)
4098   "Write this article body to a file, overwriting it if the file exists.
4099 Optional argument FILENAME specifies file name.
4100 The directory to save in defaults to `gnus-article-save-directory'."
4101   (setq filename (gnus-read-save-file-name
4102                   "Save %s body in file" filename
4103                   gnus-file-save-name gnus-newsgroup-name
4104                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
4105   (gnus-summary-save-body-in-file filename t))
4106
4107 (put 'gnus-summary-save-in-pipe :decode t)
4108 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4109 (defun gnus-summary-save-in-pipe (&optional command raw)
4110   "Pipe this article to subprocess COMMAND.
4111 Valid values for COMMAND include:
4112   a string
4113     The executable command name and possibly arguments.
4114   nil
4115     You will be prompted for the command in the minibuffer.
4116   the symbol `default'
4117     It will be replaced with the command which the variable
4118     `gnus-summary-pipe-output-default-command' holds or the command
4119     last used for saving.
4120 Non-nil value for RAW overrides `:decode' and `:headers' properties
4121 and the raw article including all headers will be piped."
4122   (let ((article (gnus-summary-article-number))
4123         (decode (unless raw
4124                   (get 'gnus-summary-save-in-pipe :decode)))
4125         save-buffer default)
4126     (if article
4127         (if (vectorp (gnus-summary-article-header article))
4128             (save-current-buffer
4129               (gnus-summary-select-article decode decode nil article)
4130               (insert-buffer-substring
4131                (prog1
4132                    (if decode
4133                        gnus-article-buffer
4134                      gnus-original-article-buffer)
4135                  (setq save-buffer
4136                        (nnheader-set-temp-buffer " *Gnus Save*"))))
4137               ;; Remove unwanted headers.
4138               (when (and (not raw)
4139                          (or (get 'gnus-summary-save-in-pipe :headers)
4140                              (not gnus-save-all-headers)))
4141                 (let ((gnus-visible-headers
4142                        (or (symbol-value (get 'gnus-summary-save-in-pipe
4143                                               :headers))
4144                            gnus-saved-headers gnus-visible-headers))
4145                       (gnus-summary-buffer nil))
4146                   (article-hide-headers 1 t))))
4147           (error "%d is not a real article" article))
4148       (error "No article to pipe"))
4149     (setq default (or gnus-summary-pipe-output-default-command
4150                       gnus-last-shell-command))
4151     (unless (stringp command)
4152       (setq command
4153             (if (and (eq command 'default) default)
4154                 default
4155               (gnus-read-shell-command "Shell command on this article: "
4156                                        default))))
4157     (when (string-equal command "")
4158       (if default
4159           (setq command default)
4160         (error "A command is required")))
4161     (with-current-buffer save-buffer
4162       (save-restriction
4163         (widen)
4164         (shell-command-on-region (point-min) (point-max) command nil)))
4165     (gnus-kill-buffer save-buffer))
4166   (setq gnus-summary-pipe-output-default-command command))
4167
4168 (defun gnus-summary-pipe-to-muttprint (&optional command)
4169   "Pipe this article to muttprint."
4170   (unless (stringp command)
4171     (setq command (read-string
4172                    "Print using command: " gnus-summary-muttprint-program
4173                    nil gnus-summary-muttprint-program)))
4174   (let ((gnus-summary-pipe-output-default-command
4175          gnus-summary-pipe-output-default-command))
4176     (gnus-summary-save-in-pipe command))
4177   (setq gnus-summary-muttprint-program command))
4178
4179 ;;; Article file names when saving.
4180
4181 (defun gnus-capitalize-newsgroup (newsgroup)
4182   "Capitalize NEWSGROUP name."
4183   (when (not (zerop (length newsgroup)))
4184     (concat (char-to-string (upcase (aref newsgroup 0)))
4185             (substring newsgroup 1))))
4186
4187 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4188   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4189 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4190 Otherwise, it is like ~/News/news/group/num."
4191   (let ((default
4192           (expand-file-name
4193            (concat (if (gnus-use-long-file-name 'not-save)
4194                        (gnus-capitalize-newsgroup newsgroup)
4195                      (gnus-newsgroup-directory-form newsgroup))
4196                    "/" (int-to-string (mail-header-number headers)))
4197            gnus-article-save-directory)))
4198     (if (and last-file
4199              (string-equal (file-name-directory default)
4200                            (file-name-directory last-file))
4201              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4202         default
4203       (or last-file default))))
4204
4205 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4206   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4207 If variable `gnus-use-long-file-name' is non-nil, it is
4208 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
4209   (let ((default
4210           (expand-file-name
4211            (concat (if (gnus-use-long-file-name 'not-save)
4212                        newsgroup
4213                      (gnus-newsgroup-directory-form newsgroup))
4214                    "/" (int-to-string (mail-header-number headers)))
4215            gnus-article-save-directory)))
4216     (if (and last-file
4217              (string-equal (file-name-directory default)
4218                            (file-name-directory last-file))
4219              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4220         default
4221       (or last-file default))))
4222
4223 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4224   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4225 If variable `gnus-use-long-file-name' is non-nil, it is
4226 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
4227   (or last-file
4228       (expand-file-name
4229        (if (gnus-use-long-file-name 'not-save)
4230            newsgroup
4231          (file-relative-name
4232           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4233           default-directory))
4234        gnus-article-save-directory)))
4235
4236 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4237   "Generate file name from sender."
4238   (let ((from (mail-header-from headers)))
4239     (expand-file-name
4240      (if (and from (string-match "\\([^ <]+\\)@" from))
4241          (match-string 1 from)
4242        "nobody")
4243      gnus-article-save-directory)))
4244
4245 (defun article-verify-x-pgp-sig ()
4246   "Verify X-PGP-Sig."
4247   ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4248   (interactive)
4249   (if (gnus-buffer-live-p gnus-original-article-buffer)
4250       (let ((sig (with-current-buffer gnus-original-article-buffer
4251                    (gnus-fetch-field "X-PGP-Sig")))
4252             items info headers)
4253         (when (and sig
4254                    mml2015-use
4255                    (mml2015-clear-verify-function))
4256           (with-temp-buffer
4257             (insert-buffer-substring gnus-original-article-buffer)
4258             (setq items (split-string sig))
4259             (message-narrow-to-head)
4260             (let ((inhibit-point-motion-hooks t)
4261                   (case-fold-search t))
4262               ;; Don't verify multiple headers.
4263               (setq headers (mapconcat (lambda (header)
4264                                          (concat header ": "
4265                                                  (mail-fetch-field header)
4266                                                  "\n"))
4267                                        (split-string (nth 1 items) ",") "")))
4268             (delete-region (point-min) (point-max))
4269             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4270             (insert "X-Signed-Headers: " (nth 1 items) "\n")
4271             (insert headers)
4272             (widen)
4273             (forward-line)
4274             (while (not (eobp))
4275               (if (looking-at "^-")
4276                   (insert "- "))
4277               (forward-line))
4278             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4279             (insert "Version: " (car items) "\n\n")
4280             (insert (mapconcat 'identity (cddr items) "\n"))
4281             (insert "\n-----END PGP SIGNATURE-----\n")
4282             (let ((mm-security-handle (list (format "multipart/signed"))))
4283               (mml2015-clean-buffer)
4284               (let ((coding-system-for-write (or gnus-newsgroup-charset
4285                                                  'iso-8859-1)))
4286                 (funcall (mml2015-clear-verify-function)))
4287               (setq info
4288                     (or (mm-handle-multipart-ctl-parameter
4289                          mm-security-handle 'gnus-details)
4290                         (mm-handle-multipart-ctl-parameter
4291                          mm-security-handle 'gnus-info)))))
4292           (when info
4293             (let ((inhibit-read-only t) bface eface)
4294               (save-restriction
4295                 (message-narrow-to-head)
4296                 (goto-char (point-max))
4297                 (forward-line -1)
4298                 (setq bface (get-text-property (point-at-bol) 'face)
4299                       eface (get-text-property (1- (point-at-eol)) 'face))
4300                 (message-remove-header "X-Gnus-PGP-Verify")
4301                 (if (re-search-forward "^X-PGP-Sig:" nil t)
4302                     (forward-line)
4303                   (goto-char (point-max)))
4304                 (narrow-to-region (point) (point))
4305                 (insert "X-Gnus-PGP-Verify: " info "\n")
4306                 (goto-char (point-min))
4307                 (forward-line)
4308                 (while (not (eobp))
4309                   (if (not (looking-at "^[ \t]"))
4310                       (insert " "))
4311                   (forward-line))
4312                 ;; Do highlighting.
4313                 (goto-char (point-min))
4314                 (when (looking-at "\\([^:]+\\): *")
4315                   (put-text-property (match-beginning 1) (1+ (match-end 1))
4316                                      'face bface)
4317                   (put-text-property (match-end 0) (point-max)
4318                                      'face eface)))))))))
4319
4320 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4321
4322 (defun article-verify-cancel-lock ()
4323   "Verify Cancel-Lock header."
4324   (interactive)
4325   (if (gnus-buffer-live-p gnus-original-article-buffer)
4326       (canlock-verify gnus-original-article-buffer)))
4327
4328 (eval-and-compile
4329   (mapc
4330    (lambda (func)
4331      (let (afunc gfunc)
4332        (if (consp func)
4333            (setq afunc (car func)
4334                  gfunc (cdr func))
4335          (setq afunc func
4336                gfunc (intern (format "gnus-%s" func))))
4337        (defalias gfunc
4338          (when (fboundp afunc)
4339            `(lambda (&optional interactive &rest args)
4340               ,(documentation afunc t)
4341               (interactive (list t))
4342               (with-current-buffer gnus-article-buffer
4343                 (if interactive
4344                     (call-interactively ',afunc)
4345                   (apply ',afunc args))))))))
4346    '(article-hide-headers
4347      article-verify-x-pgp-sig
4348      article-verify-cancel-lock
4349      article-hide-boring-headers
4350      article-treat-overstrike
4351      article-treat-ansi-sequences
4352      article-fill-long-lines
4353      article-capitalize-sentences
4354      article-remove-cr
4355      article-remove-leading-whitespace
4356      article-display-x-face
4357      article-display-face
4358      article-de-quoted-unreadable
4359      article-de-base64-unreadable
4360      article-decode-HZ
4361      article-wash-html
4362      article-unsplit-urls
4363      article-hide-list-identifiers
4364      article-strip-banner
4365      article-babel
4366      article-hide-pem
4367      article-hide-signature
4368      article-strip-headers-in-body
4369      article-remove-trailing-blank-lines
4370      article-strip-leading-blank-lines
4371      article-strip-multiple-blank-lines
4372      article-strip-leading-space
4373      article-strip-trailing-space
4374      article-strip-blank-lines
4375      article-strip-all-blank-lines
4376      article-date-local
4377      article-date-english
4378      article-date-iso8601
4379      article-date-original
4380      article-treat-date
4381      article-date-ut
4382      article-decode-mime-words
4383      article-decode-charset
4384      article-decode-encoded-words
4385      article-date-user
4386      article-date-lapsed
4387      article-date-combined-lapsed
4388      article-emphasize
4389      article-treat-dumbquotes
4390      article-treat-non-ascii
4391      article-normalize-headers
4392      ;;(article-show-all . gnus-article-show-all-headers)
4393      )))
4394 \f
4395 ;;;
4396 ;;; Gnus article mode
4397 ;;;
4398
4399 (put 'gnus-article-mode 'mode-class 'special)
4400
4401 (set-keymap-parent gnus-article-mode-map widget-keymap)
4402
4403 (gnus-define-keys gnus-article-mode-map
4404   " " gnus-article-goto-next-page
4405   [?\S-\ ] gnus-article-goto-prev-page
4406   "\177" gnus-article-goto-prev-page
4407   [delete] gnus-article-goto-prev-page
4408   "\C-c^" gnus-article-refer-article
4409   "h" gnus-article-show-summary
4410   "s" gnus-article-show-summary
4411   "\C-c\C-m" gnus-article-mail
4412   "?" gnus-article-describe-briefly
4413   "<" beginning-of-buffer
4414   ">" end-of-buffer
4415   "\C-c\C-i" gnus-info-find-node
4416   "\C-c\C-b" gnus-bug
4417   "R" gnus-article-reply-with-original
4418   "F" gnus-article-followup-with-original
4419   "\C-hk" gnus-article-describe-key
4420   "\C-hc" gnus-article-describe-key-briefly
4421   "\C-hb" gnus-article-describe-bindings
4422
4423   "e" gnus-article-read-summary-keys
4424   "\C-d" gnus-article-read-summary-keys
4425   "\M-*" gnus-article-read-summary-keys
4426   "\M-#" gnus-article-read-summary-keys
4427   "\M-^" gnus-article-read-summary-keys
4428   "\M-g" gnus-article-read-summary-keys)
4429
4430 (substitute-key-definition
4431  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4432
4433 (defvar gnus-article-send-map)
4434
4435 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4436   "W" gnus-article-wide-reply-with-original)
4437 (if (featurep 'xemacs)
4438     (set-keymap-default-binding gnus-article-send-map
4439                                 'gnus-article-read-summary-send-keys)
4440   (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4441
4442 (defun gnus-article-make-menu-bar ()
4443   (unless (boundp 'gnus-article-commands-menu)
4444     (gnus-summary-make-menu-bar))
4445   (unless (boundp 'gnus-article-article-menu)
4446     (easy-menu-define
4447      gnus-article-article-menu gnus-article-mode-map ""
4448      '("Article"
4449        ["Scroll forwards" gnus-article-goto-next-page t]
4450        ["Scroll backwards" gnus-article-goto-prev-page t]
4451        ["Show summary" gnus-article-show-summary t]
4452        ["Fetch Message-ID at point" gnus-article-refer-article t]
4453        ["Mail to address at point" gnus-article-mail t]
4454        ["Send a bug report" gnus-bug t]))
4455
4456     (easy-menu-define
4457      gnus-article-treatment-menu gnus-article-mode-map ""
4458      ;; Fixme: this should use :active (and maybe :visible).
4459      '("Treatment"
4460        ["Hide headers" gnus-article-hide-headers t]
4461        ["Hide signature" gnus-article-hide-signature t]
4462        ["Hide citation" gnus-article-hide-citation t]
4463        ["Treat overstrike" gnus-article-treat-overstrike t]
4464        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4465        ["Remove carriage return" gnus-article-remove-cr t]
4466        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4467        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4468        ["Remove base64" gnus-article-de-base64-unreadable t]
4469        ["Treat html" gnus-article-wash-html t]
4470        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4471        ["Decode HZ" gnus-article-decode-HZ t]))
4472
4473     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4474
4475     ;; Note "Post" menu is defined in gnus-sum.el for consistency
4476
4477     (gnus-run-hooks 'gnus-article-menu-hook)))
4478
4479 (defvar bookmark-make-record-function)
4480 (defvar shr-put-image-function)
4481
4482 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4483   "Major mode for displaying an article.
4484
4485 All normal editing commands are switched off.
4486
4487 The following commands are available in addition to all summary mode
4488 commands:
4489 \\<gnus-article-mode-map>
4490 \\[gnus-article-next-page]\t Scroll the article one page forwards
4491 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4492 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4493 \\[gnus-article-show-summary]\t Display the summary buffer
4494 \\[gnus-article-mail]\t Send a reply to the address near point
4495 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4496 \\[gnus-info-find-node]\t Go to the Gnus info node"
4497   (gnus-simplify-mode-line)
4498   (make-local-variable 'minor-mode-alist)
4499   (when (gnus-visual-p 'article-menu 'menu)
4500     (gnus-article-make-menu-bar)
4501     (when gnus-summary-tool-bar-map
4502       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4503   (gnus-update-format-specifications nil 'article-mode)
4504   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4505   (set (make-local-variable 'gnus-page-broken) nil)
4506   (make-local-variable 'gnus-article-current-summary)
4507   (make-local-variable 'gnus-article-mime-handles)
4508   (make-local-variable 'gnus-article-decoded-p)
4509   (make-local-variable 'gnus-article-mime-handle-alist)
4510   (make-local-variable 'gnus-article-wash-types)
4511   (make-local-variable 'gnus-article-image-alist)
4512   (make-local-variable 'gnus-article-charset)
4513   (make-local-variable 'gnus-article-ignored-charsets)
4514   (set (make-local-variable 'bookmark-make-record-function)
4515        'gnus-summary-bookmark-make-record)
4516   ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4517   ;; face.
4518   (set (make-local-variable 'nobreak-char-display) nil)
4519   ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4520   (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4521   (setq cursor-in-non-selected-windows nil)
4522   (gnus-set-default-directory)
4523   (buffer-disable-undo)
4524   (setq buffer-read-only t
4525         show-trailing-whitespace nil)
4526   (mm-enable-multibyte))
4527
4528 (defun gnus-article-setup-buffer ()
4529   "Initialize the article buffer."
4530   (let* ((name (if gnus-single-article-buffer "*Article*"
4531                  (concat "*Article "
4532                          (gnus-group-decoded-name gnus-newsgroup-name)
4533                          "*")))
4534          (original
4535           (progn (string-match "\\*Article" name)
4536                  (concat " *Original Article"
4537                          (substring name (match-end 0))))))
4538     (setq gnus-article-buffer name)
4539     (setq gnus-original-article-buffer original)
4540     (setq gnus-article-mime-handle-alist nil)
4541     (with-current-buffer gnus-summary-buffer
4542       ;; This might be a variable local to the summary buffer.
4543       (unless gnus-single-article-buffer
4544         (setq gnus-article-buffer name)
4545         (setq gnus-original-article-buffer original)
4546         (gnus-set-global-variables)))
4547     (gnus-article-setup-highlight-words)
4548     ;; Init original article buffer.
4549     (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4550       (mm-enable-multibyte)
4551       (setq major-mode 'gnus-original-article-mode)
4552       (make-local-variable 'gnus-original-article))
4553     (if (and (get-buffer name)
4554              (with-current-buffer name
4555                (if gnus-article-edit-mode
4556                    (if (y-or-n-p "Article mode edit in progress; discard? ")
4557                        (progn
4558                          (set-buffer-modified-p nil)
4559                          (gnus-kill-buffer name)
4560                          (message "")
4561                          nil)
4562                      (error "Action aborted"))
4563                  t)))
4564         (let ((summary gnus-summary-buffer))
4565           (with-current-buffer name
4566             (set (make-local-variable 'gnus-article-edit-mode) nil)
4567             (gnus-article-stop-animations)
4568             (when gnus-article-mime-handles
4569               (mm-destroy-parts gnus-article-mime-handles)
4570               (setq gnus-article-mime-handles nil))
4571             ;; Set it to nil in article-buffer!
4572             (setq gnus-article-mime-handle-alist nil)
4573             (buffer-disable-undo)
4574             (setq buffer-read-only t)
4575             (unless (derived-mode-p 'gnus-article-mode)
4576               (gnus-article-mode))
4577             (set (make-local-variable 'gnus-summary-buffer) summary)
4578             (setq truncate-lines gnus-article-truncate-lines)
4579             (current-buffer)))
4580       (let ((summary gnus-summary-buffer))
4581         (with-current-buffer (gnus-get-buffer-create name)
4582           (gnus-article-mode)
4583           (setq truncate-lines gnus-article-truncate-lines)
4584           (set (make-local-variable 'gnus-summary-buffer) summary)
4585           (gnus-summary-set-local-parameters gnus-newsgroup-name)
4586           (when article-lapsed-timer
4587             (gnus-stop-date-timer))
4588           (when gnus-article-update-date-headers
4589             (gnus-start-date-timer gnus-article-update-date-headers))
4590           (current-buffer))))))
4591
4592 (defun gnus-article-stop-animations ()
4593   (dolist (timer (and (boundp 'timer-list)
4594                       timer-list))
4595     (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4596       (cancel-timer timer))))
4597
4598 (defun gnus-stop-downloads ()
4599   (when (boundp 'url-queue)
4600     (set (intern "url-queue" obarray) nil)))
4601
4602 ;; Set article window start at LINE, where LINE is the number of lines
4603 ;; from the head of the article.
4604 (defun gnus-article-set-window-start (&optional line)
4605   (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4606     (when article-window
4607       (set-window-start
4608        article-window
4609        (with-current-buffer gnus-article-buffer
4610          (goto-char (point-min))
4611          (if (not line)
4612              (point-min)
4613            (gnus-message 6 "Moved to bookmark")
4614            (search-forward "\n\n" nil t)
4615            (forward-line line)
4616            (point)))))))
4617
4618 (defvar gnus-tmp-internal-hook)
4619
4620 (defun gnus-article-prepare (article &optional all-headers _header)
4621   "Prepare ARTICLE in article mode buffer.
4622 ARTICLE should either be an article number or a Message-ID.
4623 If ARTICLE is an id, HEADER should be the article headers.
4624 If ALL-HEADERS is non-nil, no headers are hidden."
4625   (save-excursion                ;FIXME: Shouldn't that be save-current-buffer?
4626     ;; Make sure we start in a summary buffer.
4627     (unless (derived-mode-p 'gnus-summary-mode)
4628       (set-buffer gnus-summary-buffer))
4629     (setq gnus-summary-buffer (current-buffer))
4630     (let* ((summary-buffer (current-buffer))
4631            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4632            (group gnus-newsgroup-name)
4633            result)
4634       (save-excursion
4635         (gnus-article-setup-buffer)
4636         (set-buffer gnus-article-buffer)
4637         ;; Deactivate active regions.
4638         (when (and (boundp 'transient-mark-mode)
4639                    transient-mark-mode)
4640           (setq mark-active nil))
4641         (if (not (setq result (let ((inhibit-read-only t))
4642                                 (gnus-request-article-this-buffer
4643                                  article group))))
4644             ;; There is no such article.
4645             (save-excursion
4646               (when (and (numberp article)
4647                          (not (memq article gnus-newsgroup-sparse)))
4648                 (setq gnus-article-current
4649                       (cons gnus-newsgroup-name article))
4650                 (set-buffer gnus-summary-buffer)
4651                 (setq gnus-current-article article)
4652                 (if (and (memq article gnus-newsgroup-undownloaded)
4653                          (not (gnus-online (gnus-find-method-for-group
4654                                             gnus-newsgroup-name))))
4655                     (progn
4656                       (gnus-summary-set-agent-mark article)
4657                       (message "Message marked for downloading"))
4658                   (gnus-summary-mark-article article gnus-canceled-mark)
4659                   (unless (memq article gnus-newsgroup-sparse)
4660                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4661           (if (or (eq result 'pseudo)
4662                   (eq result 'nneething))
4663               (progn
4664                 (with-current-buffer summary-buffer
4665                   (push article gnus-newsgroup-history)
4666                   (setq gnus-last-article gnus-current-article
4667                         gnus-current-article 0
4668                         gnus-current-headers nil
4669                         gnus-article-current nil)
4670                   (if (eq result 'nneething)
4671                       (gnus-configure-windows 'summary)
4672                     (gnus-configure-windows 'article))
4673                   (gnus-set-global-variables))
4674                 (let ((gnus-article-mime-handle-alist-1
4675                        gnus-article-mime-handle-alist))
4676                   (gnus-set-mode-line 'article)))
4677             ;; The result from the `request' was an actual article -
4678             ;; or at least some text that is now displayed in the
4679             ;; article buffer.
4680             (when (and (numberp article)
4681                        (not (eq article gnus-current-article)))
4682               ;; Seems like a new article has been selected.
4683               ;; `gnus-current-article' must be an article number.
4684               (with-current-buffer summary-buffer
4685                 (push article gnus-newsgroup-history)
4686                 (setq gnus-last-article gnus-current-article
4687                       gnus-current-article article
4688                       gnus-current-headers
4689                       (gnus-summary-article-header gnus-current-article)
4690                       gnus-article-current
4691                       (cons gnus-newsgroup-name gnus-current-article))
4692                 (unless (vectorp gnus-current-headers)
4693                   (setq gnus-current-headers nil))
4694                 (gnus-summary-goto-subject gnus-current-article)
4695                 (when (gnus-summary-show-thread)
4696                   ;; If the summary buffer really was folded, the
4697                   ;; previous goto may not actually have gone to
4698                   ;; the right article, but the thread root instead.
4699                   ;; So we go again.
4700                   (gnus-summary-goto-subject gnus-current-article))
4701                 (gnus-run-hooks 'gnus-mark-article-hook)
4702                 (gnus-set-mode-line 'summary)
4703                 (when (gnus-visual-p 'article-highlight 'highlight)
4704                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4705                 ;; Set the global newsgroup variables here.
4706                 (gnus-set-global-variables)
4707                 (setq gnus-have-all-headers
4708                       (or all-headers gnus-show-all-headers))))
4709             (save-excursion
4710               (gnus-configure-windows 'article))
4711             (when (or (numberp article)
4712                       (stringp article))
4713               (gnus-article-prepare-display)
4714               ;; Do page break.
4715               (goto-char (point-min))
4716               (when gnus-break-pages
4717                 (gnus-narrow-to-page)))
4718             (let ((gnus-article-mime-handle-alist-1
4719                    gnus-article-mime-handle-alist))
4720               (gnus-set-mode-line 'article))
4721             (article-goto-body)
4722             (unless (bobp)
4723               (forward-line -1))
4724             (set-window-point (get-buffer-window (current-buffer)) (point))
4725             (gnus-configure-windows 'article)
4726             (gnus-run-hooks 'gnus-article-prepare-hook)
4727             t))))))
4728
4729 (defvar gnus-mime-display-attachment-buttons-in-header)
4730
4731 ;;;###autoload
4732 (defun gnus-article-prepare-display ()
4733   "Make the current buffer look like a nice article."
4734   ;; Hooks for getting information from the article.
4735   ;; This hook must be called before being narrowed.
4736   (let ((gnus-article-buffer (current-buffer))
4737         buffer-read-only
4738         (inhibit-read-only t))
4739     (unless (derived-mode-p 'gnus-article-mode)
4740       (gnus-article-mode))
4741     (setq buffer-read-only nil
4742           gnus-article-wash-types nil
4743           gnus-article-image-alist nil)
4744     (gnus-run-hooks 'gnus-tmp-internal-hook)
4745     (when gnus-display-mime-function
4746       (funcall gnus-display-mime-function))
4747     ;; Add attachment buttons to the header.
4748     (when gnus-mime-display-attachment-buttons-in-header
4749       (gnus-mime-buttonize-attachments-in-header))))
4750
4751 ;;;
4752 ;;; Gnus Sticky Article Mode
4753 ;;;
4754
4755 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4756   "Mode for sticky articles."
4757   ;; Release bindings that won't work.
4758   (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4759                              gnus-sticky-article-mode-map)
4760   (substitute-key-definition 'gnus-article-refer-article 'undefined
4761                              gnus-sticky-article-mode-map)
4762   (dolist (k '("e" "h" "s" "F" "R"))
4763     (define-key gnus-sticky-article-mode-map k nil))
4764   (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4765   (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4766   (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4767   (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4768
4769 (defun gnus-sticky-article (arg)
4770   "Make the current article sticky.
4771 If a prefix ARG is given, ask for a name for this sticky article buffer."
4772   (interactive "P")
4773   (gnus-summary-show-thread)
4774   (gnus-summary-select-article nil nil 'pseudo)
4775   (let (new-art-buf-name)
4776     (gnus-eval-in-buffer-window gnus-article-buffer
4777       (setq new-art-buf-name
4778             (concat
4779              "*Sticky Article: "
4780              (if arg
4781                  (read-from-minibuffer "Sticky article buffer name: ")
4782                (gnus-with-article-headers
4783                  (gnus-article-goto-header "subject")
4784                  (setq new-art-buf-name
4785                        (buffer-substring-no-properties
4786                         (line-beginning-position) (line-end-position)))
4787                  (goto-char (point-min))
4788                  (gnus-article-goto-header "from")
4789                  (setq new-art-buf-name
4790                        (concat
4791                         new-art-buf-name ", "
4792                         (buffer-substring-no-properties
4793                          (line-beginning-position) (line-end-position))))
4794                  (goto-char (point-min))
4795                  (gnus-article-goto-header "date")
4796                  (setq new-art-buf-name
4797                        (concat
4798                         new-art-buf-name ", "
4799                         (buffer-substring-no-properties
4800                          (line-beginning-position) (line-end-position))))))
4801              "*"))
4802       (if (and (gnus-buffer-live-p new-art-buf-name)
4803                (with-current-buffer new-art-buf-name
4804                  (derived-mode-p 'gnus-sticky-article-mode)))
4805           (switch-to-buffer new-art-buf-name)
4806         (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4807       (gnus-sticky-article-mode))
4808     (setq gnus-article-buffer new-art-buf-name))
4809   (gnus-summary-recenter)
4810   (gnus-summary-position-point))
4811
4812 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4813   "Kill the given sticky article BUFFER.
4814 If none is given, assume the current buffer and kill it if it has
4815 `gnus-sticky-article-mode'."
4816   (interactive)
4817   (unless buffer
4818     (setq buffer (current-buffer)))
4819   (with-current-buffer buffer
4820     (when (derived-mode-p 'gnus-sticky-article-mode)
4821       (gnus-kill-buffer buffer))))
4822
4823 (defun gnus-kill-sticky-article-buffers (arg)
4824   "Kill all sticky article buffers.
4825 If a prefix ARG is given, ask for confirmation."
4826   (interactive "P")
4827   (dolist (buf (gnus-buffers))
4828     (with-current-buffer buf
4829       (when (derived-mode-p 'gnus-sticky-article-mode)
4830         (if (not arg)
4831             (gnus-kill-buffer buf)
4832           (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4833             (gnus-kill-buffer buf)))))))
4834
4835 ;;;
4836 ;;; Gnus MIME viewing functions
4837 ;;;
4838
4839 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4840   "Format of the MIME buttons.
4841
4842 Valid specifiers include:
4843 %t  The MIME type
4844 %T  MIME type, along with additional info
4845 %n  The `name' parameter
4846 %d  The description, if any
4847 %l  The length of the encoded part
4848 %p  The part identifier number
4849 %e  Dots if the part isn't displayed
4850
4851 General format specifiers can also be used.  See Info node
4852 `(gnus)Formatting Variables'.")
4853
4854 (defvar gnus-tmp-type)
4855 (defvar gnus-tmp-type-long)
4856 (defvar gnus-tmp-name)
4857 (defvar gnus-tmp-description)
4858 (defvar gnus-tmp-id)
4859 (defvar gnus-tmp-length)
4860 (defvar gnus-tmp-dots)
4861 (defvar gnus-tmp-info)
4862 (defvar gnus-tmp-pressed-details)
4863
4864 (defvar gnus-mime-button-line-format-alist
4865   '((?t gnus-tmp-type ?s)
4866     (?T gnus-tmp-type-long ?s)
4867     (?n gnus-tmp-name ?s)
4868     (?d gnus-tmp-description ?s)
4869     (?p gnus-tmp-id ?s)
4870     (?l gnus-tmp-length ?d)
4871     (?e gnus-tmp-dots ?s)))
4872
4873 (defvar gnus-mime-button-commands
4874   '((gnus-article-press-button "\r" "Toggle Display")
4875     (gnus-mime-view-part "v" "View Interactively...")
4876     (gnus-mime-view-part-as-type "t" "View As Type...")
4877     (gnus-mime-view-part-as-charset "C" "View As charset...")
4878     (gnus-mime-save-part "o" "Save...")
4879     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4880     (gnus-mime-replace-part "r" "Replace part")
4881     (gnus-mime-delete-part "d" "Delete part")
4882     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4883     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4884     (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4885     (gnus-mime-view-part-externally "e" "View Externally")
4886     (gnus-mime-print-part "p" "Print")
4887     (gnus-mime-pipe-part "|" "Pipe To Command...")
4888     (gnus-mime-action-on-part "." "Take action on the part...")))
4889
4890 (defun gnus-article-mime-part-status ()
4891   (if gnus-article-mime-handle-alist-1
4892       (if (eq 1 (length gnus-article-mime-handle-alist-1))
4893           " (1 part)"
4894         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4895     ""))
4896
4897 (defvar gnus-mime-button-map
4898   (let ((map (make-sparse-keymap)))
4899     (define-key map gnus-mouse-2 'gnus-article-push-button)
4900     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4901     (dolist (c gnus-mime-button-commands)
4902       (define-key map (cadr c) (car c)))
4903     map))
4904
4905 (easy-menu-define
4906   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4907   `("MIME Part"
4908     ,@(mapcar (lambda (c)
4909                 (vector (caddr c) (car c) :active t))
4910               gnus-mime-button-commands)))
4911
4912 (defvar gnus-url-button-commands
4913   '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4914
4915 (defvar gnus-url-button-map
4916   (let ((map (make-sparse-keymap)))
4917     (dolist (c gnus-url-button-commands)
4918       (define-key map (cadr c) (car c)))
4919     map))
4920
4921 (easy-menu-define
4922   gnus-url-button-menu gnus-url-button-map "URL button menu."
4923   `("Url Button"
4924     ,@(mapcar (lambda (c)
4925                 (vector (caddr c) (car c) :active t))
4926               gnus-url-button-commands)))
4927
4928 (defmacro gnus-bind-safe-url-regexp (&rest body)
4929   "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4930   `(let ((mm-w3m-safe-url-regexp
4931           (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4932                                 (gnus-buffer-live-p
4933                                  gnus-article-current-summary))
4934                            (with-current-buffer gnus-article-current-summary
4935                              gnus-newsgroup-name)
4936                          gnus-newsgroup-name)))
4937             (if (cond ((not group)
4938                        ;; Maybe we're in a mml-preview buffer
4939                        ;; and no group is selected.
4940                        t)
4941                       ((stringp gnus-safe-html-newsgroups)
4942                        (string-match gnus-safe-html-newsgroups group))
4943                       ((consp gnus-safe-html-newsgroups)
4944                        (member group gnus-safe-html-newsgroups)))
4945                 nil
4946               mm-w3m-safe-url-regexp))))
4947      ,@body))
4948
4949 (defun gnus-mime-button-menu (event prefix)
4950  "Construct a context-sensitive menu of MIME commands."
4951  (interactive "e\nP")
4952  (save-window-excursion
4953    (let ((pos (event-start event)))
4954      (select-window (posn-window pos))
4955      (goto-char (posn-point pos))
4956      (gnus-article-check-buffer)
4957      (popup-menu gnus-mime-button-menu nil prefix))))
4958
4959 (defun gnus-mime-view-all-parts (&optional handles)
4960   "View all the MIME parts."
4961   (interactive)
4962   (with-current-buffer gnus-article-buffer
4963     (let ((handles (or handles gnus-article-mime-handles))
4964           (mail-parse-charset gnus-newsgroup-charset)
4965           (mail-parse-ignored-charsets
4966            (with-current-buffer gnus-summary-buffer
4967              gnus-newsgroup-ignored-charsets)))
4968       (when handles
4969         (mm-remove-parts handles)
4970         (goto-char (point-min))
4971         (or (search-forward "\n\n") (goto-char (point-max)))
4972         (let ((inhibit-read-only t))
4973           (delete-region (point) (point-max))
4974           (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4975
4976 (defun gnus-article-jump-to-part (n)
4977   "Jump to MIME part N."
4978   (interactive "P")
4979   (let ((parts (with-current-buffer gnus-article-buffer
4980                  (length gnus-article-mime-handle-alist))))
4981     (when (zerop parts)
4982       (error "No such part"))
4983     (pop-to-buffer gnus-article-buffer)
4984     (or n
4985         (setq n (if (= parts 1)
4986                     1
4987                   (read-number (format "Jump to part (1..%s): " parts)))))
4988     (unless (and (integerp n) (<= n parts) (>= n 1))
4989       (setq n
4990             (progn
4991               (gnus-message 7 "Invalid part `%s', using %s instead."
4992                             n parts)
4993               parts)))
4994     (gnus-message 9 "Jumping to part %s." n)
4995     (cond ((>= gnus-auto-select-part 1)
4996            (while (and (<= n parts)
4997                        (not (gnus-article-goto-part n)))
4998              (setq n (1+ n))))
4999           ((< gnus-auto-select-part 0)
5000            (while (and (>= n 1)
5001                        (not (gnus-article-goto-part n)))
5002              (setq n (1- n))))
5003           (t
5004            (gnus-article-goto-part n)))))
5005
5006 (defvar gnus-mime-buttonized-part-id nil
5007   "ID of a mime part that should be buttonized.
5008 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5009
5010 (eval-when-compile
5011   (defsubst gnus-article-edit-part (handles &optional current-id)
5012     "Edit an article in order to delete a mime part.
5013 This function is exclusively used by `gnus-mime-save-part-and-strip'
5014 and `gnus-mime-delete-part', and not provided at run-time normally."
5015     (gnus-article-edit-article
5016      `(lambda ()
5017         (buffer-disable-undo)
5018         (let ((mail-parse-charset (or gnus-article-charset
5019                                       ',gnus-newsgroup-charset))
5020               (mail-parse-ignored-charsets
5021                (or gnus-article-ignored-charsets
5022                    ',gnus-newsgroup-ignored-charsets))
5023               (mbl mml-buffer-list))
5024           (setq mml-buffer-list nil)
5025           ;; A new text must be inserted before deleting existing ones
5026           ;; at the end so as not to move existing markers of which
5027           ;; the insertion type is t.
5028           (delete-region
5029            (point-min)
5030            (prog1
5031                (goto-char (point-max))
5032              (insert-buffer-substring gnus-original-article-buffer)))
5033           (mime-to-mml ',handles)
5034           (setq gnus-article-mime-handles nil)
5035           (let ((mbl1 mml-buffer-list))
5036             (setq mml-buffer-list mbl)
5037             (set (make-local-variable 'mml-buffer-list) mbl1))
5038           (gnus-make-local-hook 'kill-buffer-hook)
5039           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5040      `(lambda (no-highlight)
5041         (let ((mail-parse-charset (or gnus-article-charset
5042                                       ',gnus-newsgroup-charset))
5043               (message-options message-options)
5044               (message-options-set-recipient)
5045               (mail-parse-ignored-charsets
5046                (or gnus-article-ignored-charsets
5047                    ',gnus-newsgroup-ignored-charsets)))
5048           (mml-to-mime)
5049           (mml-destroy-buffers)
5050           (remove-hook 'kill-buffer-hook
5051                        'mml-destroy-buffers t)
5052           (kill-local-variable 'mml-buffer-list))
5053         (gnus-summary-edit-article-done
5054          ,(or (mail-header-references gnus-current-headers) "")
5055          ,(gnus-group-read-only-p)
5056          ,gnus-summary-buffer no-highlight))
5057      t)
5058     ;; Force buttonizing this part.
5059     (let ((gnus-mime-buttonized-part-id current-id))
5060       (gnus-article-edit-done))
5061     (gnus-configure-windows 'article)
5062     (sit-for 0)
5063     (when (and current-id (integerp gnus-auto-select-part))
5064       (gnus-article-jump-to-part
5065        (min (max (+ current-id gnus-auto-select-part) 1)
5066             (with-current-buffer gnus-article-buffer
5067               (length gnus-article-mime-handle-alist)))))))
5068
5069 (defun gnus-mime-replace-part (file)
5070   "Replace MIME part under point with an external body."
5071   ;; Useful if file has already been saved to disk
5072   (interactive
5073    (list
5074     (read-file-name "Replace MIME part with file: "
5075                     (or mm-default-directory default-directory)
5076                     nil nil)))
5077   (gnus-mime-save-part-and-strip file))
5078
5079 (defun gnus-mime-save-part-and-strip (&optional file)
5080   "Save the MIME part under point then replace it with an external body.
5081 If FILE is given, use it for the external part."
5082   (interactive)
5083   (gnus-article-check-buffer)
5084   (when (gnus-group-read-only-p)
5085     (error "The current group does not support deleting of parts"))
5086   (when (mm-complicated-handles gnus-article-mime-handles)
5087     (error "\
5088 The current article has a complicated MIME structure, giving up..."))
5089   (let* ((data (get-text-property (point) 'gnus-data))
5090          (id (get-text-property (point) 'gnus-part))
5091          (handles gnus-article-mime-handles))
5092     (unless file
5093       (setq file
5094             (and data (mm-save-part data "Delete MIME part and save to: "))))
5095     (when file
5096       (with-current-buffer (mm-handle-buffer data)
5097         (erase-buffer)
5098         (insert "Content-Type: " (mm-handle-media-type data))
5099         (mml-insert-parameter-string (cdr (mm-handle-type data))
5100                                      '(charset))
5101         ;; Add a filename for the sake of saving the part again.
5102         (mml-insert-parameter
5103          (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5104         (insert "\n")
5105         (insert "Content-ID: " (message-make-message-id) "\n")
5106         (insert "Content-Transfer-Encoding: binary\n")
5107         (insert "\n"))
5108       (setcdr data
5109               (cdr (mm-make-handle nil
5110                                    `("message/external-body"
5111                                      (access-type . "LOCAL-FILE")
5112                                      (name . ,file)))))
5113       ;; (set-buffer gnus-summary-buffer)
5114       (gnus-article-edit-part handles id))))
5115
5116 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5117 ;; parts...>') but with stripping would be nice.
5118
5119 (defun gnus-mime-delete-part ()
5120   "Delete the MIME part under point.
5121 Replace it with some information about the removed part."
5122   (interactive)
5123   (gnus-article-check-buffer)
5124   (when (gnus-group-read-only-p)
5125     (error "The current group does not support deleting of parts"))
5126   (when (mm-complicated-handles gnus-article-mime-handles)
5127     (error "\
5128 The current article has a complicated MIME structure, giving up..."))
5129   (when (or gnus-expert-user
5130             (gnus-yes-or-no-p "\
5131 Deleting parts may malfunction or destroy the article; continue? "))
5132     (let* ((data (get-text-property (point) 'gnus-data))
5133            (id (get-text-property (point) 'gnus-part))
5134            (handles gnus-article-mime-handles)
5135            (description
5136             (let ((desc (mm-handle-description data)))
5137               (when desc
5138                 (mail-decode-encoded-word-string desc))))
5139            (filename (or (mm-handle-filename data) "(none)"))
5140            (type (mm-handle-media-type data)))
5141       (unless data
5142         (error "No MIME part under point"))
5143       (with-current-buffer (mm-handle-buffer data)
5144         (let ((bsize (buffer-size)))
5145           (erase-buffer)
5146           (insert
5147            (concat
5148             ",----\n"
5149             "| The following attachment has been deleted:\n"
5150             "|\n"
5151             "| Type:           " type "\n"
5152             "| Filename:       " filename "\n"
5153             "| Size (encoded): " (format "%s byte%s\n"
5154                                          bsize (if (= bsize 1)
5155                                                    ""
5156                                                  "s"))
5157             (when description
5158               (concat    "| Description:    " description "\n"))
5159             "`----\n"))
5160           (setcdr data
5161                   (cdr (mm-make-handle
5162                         nil `("text/plain" (charset . gnus-decoded)) nil nil
5163                         (list "attachment")
5164                         (format "Deleted attachment (%s bytes)" bsize))))))
5165       ;; (set-buffer gnus-summary-buffer)
5166       (gnus-article-edit-part handles id))))
5167
5168 (defun gnus-mime-save-part ()
5169   "Save the MIME part under point."
5170   (interactive)
5171   (gnus-article-check-buffer)
5172   (let ((data (get-text-property (point) 'gnus-data)))
5173     (when data
5174       (mm-save-part data))))
5175
5176 (defun gnus-mime-pipe-part (&optional cmd)
5177   "Pipe the MIME part under point to a process.
5178 Use CMD as the process."
5179   (interactive)
5180   (gnus-article-check-buffer)
5181   (let ((data (get-text-property (point) 'gnus-data)))
5182     (when data
5183       (mm-pipe-part data cmd))))
5184
5185 (defun gnus-mime-view-part ()
5186   "Interactively choose a viewing method for the MIME part under point."
5187   (interactive)
5188   (gnus-article-check-buffer)
5189   (let ((data (get-text-property (point) 'gnus-data)))
5190     (when data
5191       (setq gnus-article-mime-handles
5192             (mm-merge-handles
5193              gnus-article-mime-handles (setq data (copy-sequence data))))
5194       (mm-interactively-view-part data))))
5195
5196 (defun gnus-mime-view-part-as-type-internal ()
5197   (gnus-article-check-buffer)
5198   (let* ((handle (get-text-property (point) 'gnus-data))
5199          (name (or
5200                 ;; Content-Type: foo/bar; name=...
5201                 (mail-content-type-get (mm-handle-type handle) 'name)
5202                 ;; Content-Disposition: attachment; filename=...
5203                 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5204          (def-type (and name (mm-default-file-encoding name))))
5205     (or (and def-type (cons def-type 0))
5206         (and handle
5207              (equal (mm-handle-media-supertype handle) "text")
5208              '("text/plain" . 0))
5209         '("application/octet-stream" . 0))))
5210
5211 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5212   "Choose a MIME media type, and view the part as such.
5213 If non-nil, PRED is a predicate to use during completion to limit the
5214 available media-types."
5215   (interactive)
5216   (unless mime-type
5217     (setq mime-type
5218           (let ((default (gnus-mime-view-part-as-type-internal)))
5219             (gnus-completing-read
5220              "View as MIME type"
5221              (if pred
5222                  (gnus-remove-if-not pred (mailcap-mime-types))
5223                (mailcap-mime-types))
5224              nil nil nil
5225              (car default)))))
5226   (gnus-article-check-buffer)
5227   (let ((handle (get-text-property (point) 'gnus-data)))
5228     (when handle
5229       (when (equal (mm-handle-media-type handle) "message/external-body")
5230         (unless (mm-handle-cache handle)
5231           (mm-extern-cache-contents handle))
5232         (setq handle (mm-handle-cache handle)))
5233       (setq handle
5234             (mm-make-handle (mm-handle-buffer handle)
5235                             (cons mime-type (cdr (mm-handle-type handle)))
5236                             (mm-handle-encoding handle)
5237                             (mm-handle-undisplayer handle)
5238                             (mm-handle-disposition handle)
5239                             (mm-handle-description handle)
5240                             nil
5241                             (mm-handle-id handle)))
5242       (setq gnus-article-mime-handles
5243             (mm-merge-handles gnus-article-mime-handles handle))
5244       (when (mm-handle-displayed-p handle)
5245         (mm-remove-part handle))
5246       (gnus-mm-display-part handle))))
5247
5248 (defun gnus-mime-copy-part (&optional handle arg)
5249   "Put the MIME part under point into a new buffer.
5250 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5251 are decompressed."
5252   (interactive (list nil current-prefix-arg))
5253   (gnus-article-check-buffer)
5254   (unless handle
5255     (setq handle (get-text-property (point) 'gnus-data)))
5256   (when handle
5257     (let ((filename (mm-handle-filename handle))
5258           contents dont-decode charset coding-system)
5259       (mm-with-unibyte-buffer
5260         (mm-insert-part handle)
5261         (setq contents (or (condition-case nil
5262                                (mm-decompress-buffer filename nil 'sig)
5263                              (error
5264                               (setq dont-decode t)
5265                               nil))
5266                            (buffer-string))))
5267       (setq filename (cond (filename (file-name-nondirectory filename))
5268                            (dont-decode "*raw data*")
5269                            (t "*decoded*")))
5270       (cond
5271        (dont-decode)
5272        ((not arg)
5273         (unless (setq charset (mail-content-type-get
5274                                (mm-handle-type handle) 'charset))
5275           (unless (setq coding-system (mm-with-unibyte-buffer
5276                                         (insert contents)
5277                                         (mm-find-buffer-file-coding-system)))
5278             (setq charset gnus-newsgroup-charset))))
5279        ((numberp arg)
5280         (setq charset (or (cdr (assq arg
5281                                      gnus-summary-show-article-charset-alist))
5282                           (mm-read-coding-system "Charset: ")))))
5283       (switch-to-buffer (generate-new-buffer filename))
5284       (if (or coding-system
5285               (and charset
5286                    (setq coding-system (mm-charset-to-coding-system
5287                                         charset nil t))
5288                    (not (eq coding-system 'ascii))))
5289           (progn
5290             (mm-enable-multibyte)
5291             (insert (mm-decode-coding-string contents coding-system))
5292             (setq buffer-file-coding-system
5293                   (if (boundp 'last-coding-system-used)
5294                       (symbol-value 'last-coding-system-used)
5295                     coding-system)))
5296         (mm-disable-multibyte)
5297         (insert contents)
5298         (setq buffer-file-coding-system mm-binary-coding-system))
5299       ;; We do it this way to make `normal-mode' set the appropriate mode.
5300       (unwind-protect
5301           (progn
5302             (setq buffer-file-name (expand-file-name filename))
5303             (normal-mode))
5304         (setq buffer-file-name nil))
5305       (goto-char (point-min)))))
5306
5307 (defun gnus-mime-print-part (&optional handle filename)
5308   "Print the MIME part under point."
5309   (interactive (list nil (ps-print-preprint current-prefix-arg)))
5310   (gnus-article-check-buffer)
5311   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5312          (contents (and handle (mm-get-part handle)))
5313          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5314          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5315     (when contents
5316         (if printer
5317             (unwind-protect
5318                 (progn
5319                   (mm-save-part-to-file handle file)
5320                   (call-process shell-file-name nil
5321                                 (generate-new-buffer " *mm*")
5322                                 nil
5323                                 shell-command-switch
5324                                 (mm-mailcap-command
5325                                  printer file (mm-handle-type handle))))
5326               (delete-file file))
5327           (with-temp-buffer
5328             (insert contents)
5329             (gnus-print-buffer))
5330           (ps-despool filename)))))
5331
5332 (defun gnus-mime-inline-part (&optional handle arg)
5333   "Insert the MIME part under point into the current buffer.
5334 Compressed files like .gz and .bz2 are decompressed."
5335   (interactive (list nil current-prefix-arg))
5336   (gnus-article-check-buffer)
5337   (let* ((inhibit-read-only t)
5338          (b (point))
5339          (btn ;; position where the MIME button exists
5340           (if handle
5341               (if (eq handle (get-text-property b 'gnus-data))
5342                   b
5343                 (article-goto-body)
5344                 (or (text-property-any (point) (point-max) 'gnus-data handle)
5345                     (text-property-any (point-min) (point) 'gnus-data handle)))
5346             (setq handle (get-text-property b 'gnus-data))
5347             b))
5348          start)
5349     (when handle
5350       (when (= b (prog1
5351                      btn
5352                    (setq start (next-single-property-change btn 'gnus-data
5353                                                             nil (point-max))
5354                          btn (previous-single-property-change start
5355                                                               'gnus-data))))
5356         (setq b btn))
5357       (if (and (not arg) (mm-handle-undisplayer handle))
5358           (progn
5359             (setq b (copy-marker b)
5360                   btn (copy-marker btn))
5361             (mm-remove-part handle))
5362         (cond
5363          ((not arg) nil)
5364          ((numberp arg)
5365           (if (mm-handle-undisplayer handle)
5366               (mm-remove-part handle)))
5367          ((mm-handle-undisplayer handle)
5368           (mm-remove-part handle)))
5369         (goto-char start)
5370         (unless (bolp)
5371           ;; This is a header button.
5372           (forward-line 1))
5373         (mm-display-inline handle))
5374       ;; Toggle the button appearance between `[button]...' and `[button]'.
5375       (when (markerp btn)
5376         (setq btn (prog1 (marker-position btn)
5377                     (set-marker btn nil))))
5378       (goto-char btn)
5379       (let ((displayed-p (mm-handle-displayed-p handle)))
5380         (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5381                                  (list displayed-p))
5382         (if (featurep 'emacs)
5383             (delete-region
5384              (point)
5385              (next-single-property-change (point) 'gnus-data nil (point-max)))
5386           (let* ((end (next-single-property-change (point) 'gnus-data))
5387                  (annots (annotations-at (or end (point-max)))))
5388             (delete-region (point)
5389                            (if end
5390                                (if annots (1+ end) end)
5391                              (point-max)))
5392             (dolist (annot annots)
5393               (set-extent-endpoints annot (point) (point)))))
5394         (setq start (point))
5395         (if (search-backward "\n\n" nil t)
5396             (progn
5397               (goto-char start)
5398               (unless (or displayed-p (eolp))
5399                 ;; Add extra newline.
5400                 (insert (propertize (buffer-substring (1- start) start)
5401                                     'gnus-undeletable t))))
5402           ;; We're in the article header.
5403           (delete-char -1)
5404           (dolist (ovl (gnus-overlays-in btn (point)))
5405             (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5406             (gnus-overlay-put ovl 'face nil))
5407           (save-restriction
5408             (message-narrow-to-field)
5409             (let ((gnus-treatment-function-alist
5410                    '((gnus-treat-highlight-headers
5411                       gnus-article-highlight-headers))))
5412               (gnus-treat-article 'head)))))
5413       (when (markerp b)
5414         (setq b (prog1 (marker-position b)
5415                   (set-marker b nil))))
5416       (goto-char b))))
5417
5418 (defun gnus-mime-set-charset-parameters (handle charset)
5419   "Set CHARSET to parameters in HANDLE.
5420 CHARSET may either be a string or a symbol."
5421   (unless (stringp charset)
5422     (setq charset (symbol-name charset)))
5423   (if (stringp (car handle))
5424       (dolist (h (cdr handle))
5425         (gnus-mime-set-charset-parameters h charset))
5426     (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5427                                             "message/external-body")
5428                                      (progn
5429                                        (unless (mm-handle-cache handle)
5430                                          (mm-extern-cache-contents handle))
5431                                        (mm-handle-cache handle))
5432                                    handle)))
5433            (param (assq 'charset (cdr type))))
5434       (if param
5435           (setcdr param charset)
5436         (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5437
5438 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5439   "Insert the MIME part under point into the current buffer using the
5440 specified charset."
5441   (interactive (list nil current-prefix-arg))
5442   (gnus-article-check-buffer)
5443   (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5444         (fun (get-text-property (point) 'gnus-callback))
5445         (gnus-newsgroup-ignored-charsets 'gnus-all)
5446         charset form preferred parts)
5447     (when handle
5448       (when (prog1
5449                 (and fun
5450                      (setq charset
5451                            (or (cdr (assq
5452                                      arg
5453                                      gnus-summary-show-article-charset-alist))
5454                                (mm-read-coding-system "Charset: "))))
5455               (if (mm-handle-undisplayer handle)
5456                   (mm-remove-part handle)))
5457         (gnus-mime-set-charset-parameters handle charset)
5458         (when (and (consp (setq form (cdr-safe fun)))
5459                    (setq form (ignore-errors
5460                                 (assq 'gnus-mime-display-alternative form)))
5461                    (setq preferred (caddr form))
5462                    (progn
5463                      (when (eq (car preferred) 'quote)
5464                        (setq preferred (cadr preferred)))
5465                      (not (equal preferred
5466                                  (get-text-property (point) 'gnus-data))))
5467                    (setq parts (get-text-property (point) 'gnus-part))
5468                    (setq parts (cdr (assq parts
5469                                           gnus-article-mime-handle-alist)))
5470                    (equal (mm-handle-media-type parts) "multipart/alternative")
5471                    (setq parts (reverse (cdr parts))))
5472           (setcar (cddr form)
5473                   (list 'quote (or (cadr (member preferred parts))
5474                                    (car parts)))))
5475         (funcall fun handle)))))
5476
5477 (defun gnus-mime-view-part-externally (&optional handle)
5478   "View the MIME part under point with an external viewer."
5479   (interactive)
5480   (gnus-article-check-buffer)
5481   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5482          (mm-inlined-types nil)
5483          (mail-parse-charset gnus-newsgroup-charset)
5484          (mail-parse-ignored-charsets
5485           (with-current-buffer gnus-summary-buffer
5486             gnus-newsgroup-ignored-charsets))
5487          (type (mm-handle-media-type handle))
5488          (method (mailcap-mime-info type))
5489          (mm-enable-external t))
5490     (if (not (stringp method))
5491         (gnus-mime-view-part-as-type
5492          nil (lambda (type) (stringp (mailcap-mime-info type))))
5493       (when handle
5494         (mm-display-part handle nil t)))))
5495
5496 (defun gnus-mime-view-part-internally (&optional handle)
5497   "View the MIME part under point with an internal viewer.
5498 If no internal viewer is available, use an external viewer."
5499   (interactive)
5500   (gnus-article-check-buffer)
5501   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5502          (mm-inlined-types '(".*"))
5503          (mm-inline-large-images t)
5504          (mail-parse-charset gnus-newsgroup-charset)
5505          (mail-parse-ignored-charsets
5506           (with-current-buffer gnus-summary-buffer
5507             gnus-newsgroup-ignored-charsets))
5508          (inhibit-read-only t))
5509     (if (not (mm-inlinable-p handle))
5510         (gnus-mime-view-part-as-type
5511          nil (lambda (type) (mm-inlinable-p handle type)))
5512       (when handle
5513         (gnus-bind-safe-url-regexp
5514          (mm-display-part handle nil t))))))
5515
5516 (defun gnus-mime-action-on-part (&optional action)
5517   "Do something with the MIME attachment at \(point\)."
5518   (interactive
5519    (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5520   (gnus-article-check-buffer)
5521   (let ((action-pair (assoc action gnus-mime-action-alist)))
5522     (if action-pair
5523         (funcall (cdr action-pair)))))
5524
5525 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5526   "Call FUNCTION on MIME part N.
5527 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5528 If INTERACTIVE, call FUNCTION interactively."
5529   (let (window frame)
5530     ;; Check whether the article is displayed.
5531     (unless (and (gnus-buffer-live-p gnus-article-buffer)
5532                  (setq window (get-buffer-window gnus-article-buffer t))
5533                  (frame-visible-p (setq frame (window-frame window))))
5534       (error "No article is displayed"))
5535     (with-current-buffer gnus-article-buffer
5536       ;; Check whether the article displays the right contents.
5537       (unless (with-current-buffer gnus-summary-buffer
5538                 (eq gnus-current-article (gnus-summary-article-number)))
5539         (error "You should select the right article first"))
5540       (if n
5541           (setq n (prefix-numeric-value n))
5542         (let ((pt (point)))
5543           (setq n (or (get-text-property pt 'gnus-part)
5544                       (and (not (bobp))
5545                            (get-text-property (1- pt) 'gnus-part))
5546                       (get-text-property (prog2
5547                                              (forward-line 1)
5548                                              (point)
5549                                            (goto-char pt))
5550                                          'gnus-part)
5551                       (get-text-property
5552                        (or (and (setq pt (previous-single-property-change
5553                                           pt 'gnus-part))
5554                                 (1- pt))
5555                            (next-single-property-change (point) 'gnus-part)
5556                            (point))
5557                        'gnus-part)
5558                       1))))
5559       ;; Check whether the specified part exists.
5560       (when (> n (length gnus-article-mime-handle-alist))
5561         (error "No such part")))
5562     (unless
5563         (progn
5564           ;; To select the window is needed so that the cursor
5565           ;; might be visible on the MIME button.
5566           (select-window (prog1
5567                              window
5568                            (setq window (selected-window))
5569                            ;; Article may be displayed in the other frame.
5570                            (gnus-select-frame-set-input-focus
5571                             (prog1
5572                                 frame
5573                               (setq frame (selected-frame))))))
5574           (when (gnus-article-goto-part n)
5575             ;; We point the cursor and the arrow at the MIME button
5576             ;; when the `function' prompt the user for something.
5577             (unless (and (pos-visible-in-window-p)
5578                          (> (count-lines (point) (window-end))
5579                             (/ (1- (window-height)) 3)))
5580               (recenter (/ (1- (window-height)) 3)))
5581             (let ((cursor-in-non-selected-windows t)
5582                   (overlay-arrow-string "=>")
5583                   (overlay-arrow-position (point-marker)))
5584               (unwind-protect
5585                   (cond
5586                    ((and no-handle interactive)
5587                     (call-interactively function))
5588                    (no-handle
5589                     (funcall function))
5590                    (interactive
5591                     (call-interactively
5592                      function (get-text-property (point) 'gnus-data)))
5593                    (t
5594                     (funcall function
5595                              (get-text-property (point) 'gnus-data))))
5596                 (set-marker overlay-arrow-position nil)
5597                 (unless gnus-auto-select-part
5598                   (gnus-select-frame-set-input-focus frame)
5599                   (select-window window))))
5600             t))
5601       (if gnus-inhibit-mime-unbuttonizing
5602           ;; This is the default though the program shouldn't reach here.
5603           (error "No such part")
5604         ;; The part which doesn't have the MIME button is selected.
5605         ;; So, we display all the buttons and redo it.
5606         (let ((gnus-inhibit-mime-unbuttonizing t))
5607           (gnus-summary-show-article)
5608           (gnus-article-part-wrapper n function no-handle))))))
5609
5610 (defun gnus-article-pipe-part (n)
5611   "Pipe MIME part N, which is the numerical prefix."
5612   (interactive "P")
5613   (gnus-article-part-wrapper n 'mm-pipe-part))
5614
5615 (defun gnus-article-save-part (n)
5616   "Save MIME part N, which is the numerical prefix."
5617   (interactive "P")
5618   (gnus-article-part-wrapper n 'mm-save-part))
5619
5620 (defun gnus-article-interactively-view-part (n)
5621   "View MIME part N interactively, which is the numerical prefix."
5622   (interactive "P")
5623   (gnus-article-part-wrapper n 'mm-interactively-view-part))
5624
5625 (defun gnus-article-copy-part (n)
5626   "Copy MIME part N, which is the numerical prefix."
5627   (interactive "P")
5628   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5629
5630 (defun gnus-article-view-part-as-charset (n)
5631   "View MIME part N using a specified charset.
5632 N is the numerical prefix."
5633   (interactive "P")
5634   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5635
5636 (defun gnus-article-view-part-externally (n)
5637   "View MIME part N externally, which is the numerical prefix."
5638   (interactive "P")
5639   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5640
5641 (defun gnus-article-inline-part (n)
5642   "Inline MIME part N, which is the numerical prefix."
5643   (interactive "P")
5644   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5645
5646 (defun gnus-article-save-part-and-strip (n)
5647   "Save MIME part N and replace it with an external body.
5648 N is the numerical prefix."
5649   (interactive "P")
5650   (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5651
5652 (defun gnus-article-replace-part (n)
5653   "Replace MIME part N with an external body.
5654 N is the numerical prefix."
5655   (interactive "P")
5656   (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5657
5658 (defun gnus-article-delete-part (n)
5659   "Delete MIME part N and add some information about the removed part.
5660 N is the numerical prefix."
5661   (interactive "P")
5662   (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5663
5664 (defun gnus-article-view-part-as-type (n)
5665   "Choose a MIME media type, and view part N as such.
5666 N is the numerical prefix."
5667   (interactive "P")
5668   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5669
5670 (defun gnus-article-mime-match-handle-first (condition)
5671   (if condition
5672       (let (n)
5673         (dolist (ihandle gnus-article-mime-handle-alist)
5674           (if (and (cond
5675                     ((functionp condition)
5676                      (funcall condition (cdr ihandle)))
5677                     ((eq condition 'undisplayed)
5678                      (not (or (mm-handle-undisplayer (cdr ihandle))
5679                               (equal (mm-handle-media-type (cdr ihandle))
5680                                      "multipart/alternative"))))
5681                     ((eq condition 'undisplayed-alternative)
5682                      (not (mm-handle-undisplayer (cdr ihandle))))
5683                     (t t))
5684                    (gnus-article-goto-part (car ihandle))
5685                    (or (not n) (< (car ihandle) n)))
5686               (setq n (car ihandle))))
5687         (or n 1))
5688     1))
5689
5690 (defun gnus-article-view-part (&optional n)
5691   "View MIME part N, which is the numerical prefix.
5692 If the part is already shown, hide the part.  If N is nil, view
5693 all parts."
5694   (interactive "P")
5695   (with-current-buffer gnus-article-buffer
5696     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5697                              gnus-article-mime-match-handle-function)))
5698     (when (> n (length gnus-article-mime-handle-alist))
5699       (error "No such part"))
5700     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5701       (when (gnus-article-goto-part n)
5702         (if (equal (car handle) "multipart/alternative")
5703             (progn
5704               (beginning-of-line) ;; Make it toggle subparts
5705               (gnus-article-press-button))
5706           (when (eq (gnus-mm-display-part handle) 'internal)
5707             (gnus-set-window-start)))))))
5708
5709 (defsubst gnus-article-mime-total-parts ()
5710   (if (bufferp (car gnus-article-mime-handles))
5711       1 ;; single part
5712     (1- (length gnus-article-mime-handles))))
5713
5714 (defun gnus-mm-display-part (handle)
5715   "Display HANDLE and fix MIME button."
5716   (let ((id (get-text-property (point) 'gnus-part))
5717         (point (point))
5718         (inhibit-read-only t)
5719         (window (selected-window))
5720         (mail-parse-charset gnus-newsgroup-charset)
5721         (mail-parse-ignored-charsets
5722          (if (gnus-buffer-live-p gnus-summary-buffer)
5723              (with-current-buffer gnus-summary-buffer
5724                gnus-newsgroup-ignored-charsets)
5725            nil))
5726         start retval)
5727     (unwind-protect
5728         (progn
5729           (let ((win (gnus-get-buffer-window (current-buffer) t)))
5730             (when win
5731               (select-window win)
5732               (goto-char point)))
5733           (setq start (next-single-property-change point 'gnus-data
5734                                                    nil (point-max))
5735                 point (previous-single-property-change start 'gnus-data))
5736           (if (mm-handle-displayed-p handle)
5737               ;; This will remove the part.
5738               (setq point (copy-marker point)
5739                     retval (mm-display-part handle))
5740             (let ((part (or (and (mm-inlinable-p handle)
5741                                  (mm-inlined-p handle)
5742                                  t)
5743                             (with-temp-buffer
5744                               (gnus-bind-safe-url-regexp
5745                                (setq retval (mm-display-part handle)))
5746                               (unless (zerop (buffer-size))
5747                                 (buffer-string))))))
5748               (goto-char start)
5749               (unless (bolp)
5750                 ;; This is a header button.
5751                 (forward-line 1))
5752               (cond ((stringp part)
5753                      (save-restriction
5754                        (narrow-to-region (point)
5755                                          (progn
5756                                            (insert part)
5757                                            (unless (bolp) (insert "\n"))
5758                                            (point)))
5759                        (gnus-treat-article nil id
5760                                            (gnus-article-mime-total-parts)
5761                                            (mm-handle-media-type handle))
5762                        (mm-handle-set-undisplayer
5763                         handle
5764                         `(lambda ()
5765                            (let ((inhibit-read-only t))
5766                              (delete-region ,(copy-marker (point-min) t)
5767                                             ,(point-max-marker)))))))
5768                     (part
5769                      (mm-display-inline handle))))))
5770       (when (markerp point)
5771         (setq point (prog1 (marker-position point)
5772                       (set-marker point nil))))
5773       (goto-char point)
5774       ;; Toggle the button appearance between `[button]...' and `[button]'.
5775       (let ((displayed-p (mm-handle-displayed-p handle)))
5776         (gnus-insert-mime-button handle id (list displayed-p))
5777         (if (featurep 'emacs)
5778             (delete-region
5779              (point)
5780              (next-single-property-change (point) 'gnus-data nil (point-max)))
5781           (let* ((end (next-single-property-change (point) 'gnus-data))
5782                  (annots (annotations-at (or end (point-max)))))
5783             (delete-region (point)
5784                            (if end
5785                                (if annots (1+ end) end)
5786                              (point-max)))
5787             (dolist (annot annots)
5788               (set-extent-endpoints annot (point) (point)))))
5789         (setq start (point))
5790         (if (search-backward "\n\n" nil t)
5791             (progn
5792               (goto-char start)
5793               (unless (or displayed-p (eolp))
5794                 ;; Add extra newline.
5795                 (insert (propertize (buffer-substring (1- start) start)
5796                                     'gnus-undeletable t))))
5797           ;; We're in the article header.
5798           (delete-char -1)
5799           (dolist (ovl (gnus-overlays-in point (point)))
5800             (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5801             (gnus-overlay-put ovl 'face nil))
5802           (save-restriction
5803             (message-narrow-to-field)
5804             (let ((gnus-treatment-function-alist
5805                    '((gnus-treat-highlight-headers
5806                       gnus-article-highlight-headers))))
5807               (gnus-treat-article 'head)))))
5808       (goto-char point)
5809       (if (window-live-p window)
5810           (select-window window)))
5811     retval))
5812
5813 (defun gnus-article-goto-part (n)
5814   "Go to MIME part N."
5815   (when gnus-break-pages
5816     (widen))
5817   (article-goto-body)
5818   (prog1
5819       (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5820                        ;; There may be header buttons.
5821                        (text-property-any (point-min) (point) 'gnus-part n)))
5822             part handle end next handles)
5823         (when start
5824           (goto-char start)
5825           (if (setq handle (get-text-property start 'gnus-data))
5826               start
5827             ;; Go to the displayed subpart, assuming this is
5828             ;; multipart/alternative.
5829             (setq part start
5830                   end (point-at-eol))
5831             (while (and (not handle)
5832                         part
5833                         (< part end)
5834                         (setq next (text-property-not-all part end
5835                                                           'gnus-data nil)))
5836               (setq part next
5837                     handle (get-text-property part 'gnus-data))
5838               (push (cons handle part) handles)
5839               (unless (mm-handle-displayed-p handle)
5840                 (setq handle nil
5841                       part (text-property-any part end 'gnus-data nil))))
5842             (unless handle
5843               ;; No subpart is displayed, so we find preferred one.
5844               (setq part
5845                     (cdr (assq (mm-preferred-alternative
5846                                 (nreverse (mapcar 'car handles)))
5847                                handles))))
5848             (if part
5849                 (goto-char (1+ part))
5850               start))))
5851     (when gnus-break-pages
5852       (gnus-narrow-to-page))))
5853
5854 (defun gnus-insert-mime-button (handle id &optional displayed)
5855   (let ((gnus-tmp-name
5856          (or (mm-handle-filename handle)
5857              (mail-content-type-get (mm-handle-type handle) 'url)
5858              ""))
5859         (gnus-tmp-id id)
5860         (gnus-tmp-type (mm-handle-media-type handle))
5861         (gnus-tmp-description (or (mm-handle-description handle) ""))
5862         (gnus-tmp-dots
5863          (if (if displayed (car displayed)
5864                (mm-handle-displayed-p handle))
5865              "" "..."))
5866         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5867                            (buffer-size)))
5868         gnus-tmp-type-long b e)
5869     (when (string-match ".*/" gnus-tmp-name)
5870       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5871     (setq gnus-tmp-type-long (concat gnus-tmp-type
5872                                      (and (not (equal gnus-tmp-name ""))
5873                                           (concat "; " gnus-tmp-name))))
5874     (unless (equal gnus-tmp-description "")
5875       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5876     (setq b (point))
5877     (gnus-eval-format
5878      gnus-mime-button-line-format gnus-mime-button-line-format-alist
5879      `(keymap ,gnus-mime-button-map
5880               gnus-callback gnus-mm-display-part
5881               gnus-part ,gnus-tmp-id
5882               article-type annotation
5883               gnus-data ,handle
5884               rear-nonsticky t))
5885     (setq e (if (bolp)
5886                 ;; Exclude a newline.
5887                 (1- (point))
5888               (point)))
5889     (when gnus-article-button-face
5890       (gnus-overlay-put (gnus-make-overlay b e nil t)
5891                         'face gnus-article-button-face))
5892     (widget-convert-button
5893      'link b e
5894      :mime-handle handle
5895      :action 'gnus-widget-press-button
5896      :button-keymap gnus-mime-button-map
5897      :help-echo
5898      (lambda (widget)
5899        ;; Needed to properly clear the message due to a bug in
5900        ;; wid-edit (XEmacs only).
5901        (if (boundp 'help-echo-owns-message)
5902            (setq help-echo-owns-message t))
5903        (format
5904         "%S: %s the MIME part; %S: more options"
5905         (aref gnus-mouse-2 0)
5906         (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5907             "hide" "show")
5908         (aref gnus-down-mouse-3 0))))))
5909
5910 (defun gnus-widget-press-button (elems _el)
5911   (goto-char (widget-get elems :from))
5912   (gnus-article-press-button))
5913
5914 (defvar gnus-displaying-mime nil)
5915
5916 (defun gnus-display-mime (&optional ihandles)
5917   "Display the MIME parts."
5918   (save-excursion
5919     (save-selected-window
5920       (let ((window (get-buffer-window gnus-article-buffer))
5921             (point (point)))
5922         (when window
5923           (select-window window)
5924           ;; We have to do this since selecting the window
5925           ;; may change the point.  So we set the window point.
5926           (set-window-point window point)))
5927       (let ((handles ihandles)
5928             (inhibit-read-only t))
5929         (cond (handles)
5930               ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5931                (when gnus-article-emulate-mime
5932                  (mm-uu-dissect-text-parts handles)))
5933               (gnus-article-emulate-mime
5934                (setq handles (mm-uu-dissect))))
5935         (when (and (not ihandles)
5936                    (not gnus-displaying-mime))
5937           ;; Top-level call; we clean up.
5938           (when gnus-article-mime-handles
5939             (mm-destroy-parts gnus-article-mime-handles)
5940             (setq gnus-article-mime-handle-alist nil));; A trick.
5941           (setq gnus-article-mime-handles handles)
5942           ;; We allow users to glean info from the handles.
5943           (when gnus-article-mime-part-function
5944             (gnus-mime-part-function handles)))
5945         (if (and handles
5946                  (or (not (stringp (car handles)))
5947                      (cdr handles)))
5948             (progn
5949               (when (and (not ihandles)
5950                          (not gnus-displaying-mime))
5951                 ;; Clean up for mime parts.
5952                 (article-goto-body)
5953                 (delete-region (point) (point-max)))
5954               (let ((gnus-displaying-mime t))
5955                 (gnus-mime-display-part handles)))
5956           (save-restriction
5957             (article-goto-body)
5958             (narrow-to-region (point) (point-max))
5959             (gnus-treat-article nil 1 1 "text/plain")
5960             (widen)))
5961         (unless ihandles
5962           ;; Highlight the headers.
5963           (save-excursion
5964             (save-restriction
5965               (article-goto-body)
5966               (narrow-to-region (point-min) (point))
5967               (gnus-article-save-original-date
5968                (gnus-treat-article 'head)))))))
5969     ;; Cope with broken MIME messages.
5970     (goto-char (point-max))
5971     (unless (bolp)
5972       (insert "\n"))))
5973
5974 (defcustom gnus-mime-display-multipart-as-mixed nil
5975   "Display \"multipart\" parts as  \"multipart/mixed\".
5976
5977 If t, it overrides nil values of
5978 `gnus-mime-display-multipart-alternative-as-mixed' and
5979 `gnus-mime-display-multipart-related-as-mixed'."
5980   :group 'gnus-article-mime
5981   :type 'boolean)
5982
5983 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5984   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
5985   :version "22.1"
5986   :group 'gnus-article-mime
5987   :type 'boolean)
5988
5989 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5990   "Display \"multipart/related\" parts as  \"multipart/mixed\".
5991
5992 If displaying \"text/html\" is discouraged \(see
5993 `mm-discouraged-alternatives'\) images or other material inside a
5994 \"multipart/related\" part might be overlooked when this variable is nil."
5995   :version "22.1"
5996   :group 'gnus-article-mime
5997   :type 'boolean)
5998
5999 (defcustom gnus-mime-display-attachment-buttons-in-header t
6000   "Add attachment buttons in the end of the header of an article.
6001 Since MIME attachments tend to be put at the end of an article, we may
6002 overlook them if there is a huge body.  This option offers you a copy
6003 of all non-inlinable MIME parts as buttons shown in front of an article.
6004 If nil, don't show those extra buttons."
6005   :version "25.1"
6006   :group 'gnus-article-mime
6007   :type 'boolean)
6008
6009 (defun gnus-mime-display-part (handle)
6010   (cond
6011    ;; Maybe a broken MIME message.
6012    ((null handle))
6013    ;; Single part.
6014    ((not (stringp (car handle)))
6015     (gnus-mime-display-single handle))
6016    ;; User-defined multipart
6017    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6018     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6019              handle))
6020    ;; multipart/alternative
6021    ((and (equal (car handle) "multipart/alternative")
6022          (not (or gnus-mime-display-multipart-as-mixed
6023                   gnus-mime-display-multipart-alternative-as-mixed)))
6024     (let ((id (1+ (length gnus-article-mime-handle-alist))))
6025       (push (cons id handle) gnus-article-mime-handle-alist)
6026       (gnus-mime-display-alternative (cdr handle) nil nil id)))
6027    ;; multipart/related
6028    ((and (equal (car handle) "multipart/related")
6029          (not (or gnus-mime-display-multipart-as-mixed
6030                   gnus-mime-display-multipart-related-as-mixed)))
6031     (gnus-mime-display-part (cadr handle)))
6032    ((equal (car handle) "multipart/signed")
6033     (gnus-add-wash-type 'signed)
6034     (gnus-mime-display-security handle))
6035    ((equal (car handle) "multipart/encrypted")
6036     (gnus-add-wash-type 'encrypted)
6037     (gnus-mime-display-security handle))
6038    ;; Other multiparts are handled like multipart/mixed.
6039    (t
6040     (gnus-mime-display-mixed (cdr handle)))))
6041
6042 (defun gnus-mime-part-function (handles)
6043   (if (stringp (car handles))
6044       (mapcar 'gnus-mime-part-function (cdr handles))
6045     (funcall gnus-article-mime-part-function handles)))
6046
6047 (defun gnus-mime-display-mixed (handles)
6048   (mapcar 'gnus-mime-display-part handles))
6049
6050 (defun gnus-mime-display-single (handle)
6051   (let ((type (mm-handle-media-type handle))
6052         (ignored gnus-ignored-mime-types)
6053         (not-attachment t)
6054         display text)
6055     (catch 'ignored
6056       (progn
6057         (while ignored
6058           (when (string-match (pop ignored) type)
6059             (throw 'ignored nil)))
6060         (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6061                                (with-current-buffer gnus-summary-buffer
6062                                  gnus-inhibit-images)
6063                              gnus-inhibit-images)
6064                            (string-match "\\`image/" type)))
6065                  (setq not-attachment
6066                        (and (not (mm-inline-override-p handle))
6067                             (or (not (mm-handle-disposition handle))
6068                                 (equal (car (mm-handle-disposition handle))
6069                                        "inline")
6070                                 (mm-attachment-override-p handle))))
6071                  (mm-automatic-display-p handle)
6072                  (or (and
6073                       (mm-inlinable-p handle)
6074                       (mm-inlined-p handle))
6075                      (mm-automatic-external-display-p type)))
6076             (setq display t)
6077           (when (equal (mm-handle-media-supertype handle) "text")
6078             (setq text t)))
6079         (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6080               beg)
6081           (unless id
6082             (setq id (1+ (length gnus-article-mime-handle-alist)))
6083             (push (cons id handle) gnus-article-mime-handle-alist))
6084           (when (and display
6085                      (equal (mm-handle-media-supertype handle) "message"))
6086             (insert-char
6087              ?\n
6088              (cond ((not (bolp)) 2)
6089                    ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6090                    (t 1))))
6091           (when (or (not display)
6092                     (not (gnus-unbuttonized-mime-type-p type))
6093                     (eq id gnus-mime-buttonized-part-id))
6094             (gnus-insert-mime-button
6095              handle id (list (or display (and not-attachment text)))))
6096           (setq beg (point))
6097           (cond
6098            (display
6099             (let ((mail-parse-charset gnus-newsgroup-charset)
6100                   (mail-parse-ignored-charsets
6101                    (save-excursion (condition-case ()
6102                                        (set-buffer gnus-summary-buffer)
6103                                      (error))
6104                                    gnus-newsgroup-ignored-charsets)))
6105               (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6106            ((and text not-attachment)
6107             (mm-display-inline handle)))
6108           (goto-char (point-max))
6109           (if (string-match "\\`image/" type)
6110               (gnus-article-insert-newline)
6111             (if (prog1
6112                     (= (skip-chars-backward "\n") -1)
6113                   (unless (eobp) (forward-char 1)))
6114                 (gnus-article-insert-newline)
6115               (put-text-property (point) (point-max) 'gnus-undeletable t))
6116             (goto-char (point-max)))
6117           ;; Do highlighting.
6118           (save-excursion
6119             (save-restriction
6120               (narrow-to-region beg (point))
6121               (if (eq handle gnus-article-mime-handles)
6122                   ;; The format=flowed case.
6123                   (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6124                 ;; Don't count signature parts that are never displayed.
6125                 ;; The part number should be re-calculated supposing this
6126                 ;; might be a message/rfc822 part.
6127                 (let (handles)
6128                   (dolist (part gnus-article-mime-handles)
6129                     (unless (or (stringp part)
6130                                 (equal (car (mm-handle-type part))
6131                                        "application/pgp-signature"))
6132                       (push part handles)))
6133                   (gnus-treat-article
6134                    nil (length (memq handle handles)) (length handles)
6135                    (mm-handle-media-type handle)))))))))))
6136
6137 (defun gnus-unbuttonized-mime-type-p (type)
6138   "Say whether TYPE is to be unbuttonized."
6139   (unless gnus-inhibit-mime-unbuttonizing
6140     (when (catch 'found
6141             (let ((types gnus-unbuttonized-mime-types))
6142               (while types
6143                 (when (string-match (pop types) type)
6144                   (throw 'found t)))))
6145       (not (catch 'found
6146              (let ((types gnus-buttonized-mime-types))
6147                (while types
6148                  (when (string-match (pop types) type)
6149                    (throw 'found t)))))))))
6150
6151 (defun gnus-article-insert-newline ()
6152   "Insert a newline, but mark it as undeletable."
6153   (gnus-put-text-property
6154    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6155
6156 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6157   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6158          (ihandles handles)
6159          (point (point))
6160          handle (inhibit-read-only t) from begend not-pref)
6161     (save-window-excursion
6162       (save-restriction
6163         (when ibegend
6164           (narrow-to-region (car ibegend)
6165                             (or (cdr ibegend)
6166                                 (progn
6167                                   (goto-char (car ibegend))
6168                                   (forward-line 2)
6169                                   (point))))
6170           (delete-region (point-min) (point-max))
6171           (mm-remove-parts handles))
6172         (setq begend (list (point-marker)))
6173         ;; Do the toggle.
6174         (unless (setq not-pref (cadr (member preferred ihandles)))
6175           (setq not-pref (car ihandles)))
6176         (when (or ibegend
6177                   (not preferred)
6178                   (not (gnus-unbuttonized-mime-type-p
6179                         "multipart/alternative")))
6180           (gnus-add-text-properties
6181            (setq from (point))
6182            (progn
6183              (insert (format "%d.  " id))
6184              (point))
6185            `(gnus-callback
6186              (lambda (handles)
6187                (unless ,(not ibegend)
6188                  (setq gnus-article-mime-handle-alist
6189                        ',gnus-article-mime-handle-alist))
6190                (gnus-mime-display-alternative
6191                 ',ihandles ',not-pref ',begend ,id))
6192              keymap ,gnus-mime-button-map
6193              ,gnus-mouse-face-prop ,gnus-article-mouse-face
6194              face ,gnus-article-button-face
6195              gnus-part ,id
6196              article-type multipart
6197              rear-nonsticky t))
6198           (widget-convert-button 'link from (point)
6199                                  :action 'gnus-widget-press-button
6200                                  :button-keymap gnus-widget-button-keymap)
6201           ;; Do the handles
6202           (while (setq handle (pop handles))
6203             (gnus-add-text-properties
6204              (setq from (point))
6205              (progn
6206                (insert (format "(%c) %-18s"
6207                                (if (equal handle preferred) ?* ? )
6208                                (mm-handle-media-type handle)))
6209                (point))
6210              `(gnus-callback
6211                (lambda (handles)
6212                  (unless ,(not ibegend)
6213                    (setq gnus-article-mime-handle-alist
6214                          ',gnus-article-mime-handle-alist))
6215                  (gnus-mime-display-alternative
6216                   ',ihandles ',handle ',begend ,id))
6217                keymap ,gnus-mime-button-map
6218                ,gnus-mouse-face-prop ,gnus-article-mouse-face
6219                face ,gnus-article-button-face
6220                gnus-part ,id
6221                gnus-data ,handle
6222                rear-nonsticky t))
6223             (widget-convert-button 'link from (point)
6224                                    :action 'gnus-widget-press-button
6225                                    :button-keymap gnus-widget-button-keymap)
6226             (insert "  "))
6227           (insert "\n\n"))
6228         (when preferred
6229           (if (stringp (car preferred))
6230               (gnus-display-mime preferred)
6231             (let ((mail-parse-charset gnus-newsgroup-charset)
6232                   (mail-parse-ignored-charsets
6233                    (with-current-buffer gnus-summary-buffer
6234                      gnus-newsgroup-ignored-charsets)))
6235               (gnus-bind-safe-url-regexp (mm-display-part preferred))
6236               ;; Do highlighting.
6237               (save-excursion
6238                 (save-restriction
6239                   (narrow-to-region (car begend) (point-max))
6240                   (gnus-treat-article
6241                    nil (length gnus-article-mime-handle-alist)
6242                    (gnus-article-mime-total-parts)
6243                    (mm-handle-media-type preferred))))))
6244           (goto-char (point-max))
6245           (setcdr begend (point-marker)))))
6246     (when ibegend
6247       (goto-char point)))
6248   ;; Redraw attachment buttons in the header.
6249   (when gnus-mime-display-attachment-buttons-in-header
6250     (gnus-mime-buttonize-attachments-in-header)))
6251
6252 (defconst gnus-article-wash-status-strings
6253   (let ((alist '((cite "c" "Possible hidden citation text"
6254                        " " "All citation text visible")
6255                  (headers "h" "Hidden headers"
6256                           " " "All headers visible.")
6257                  (pgp "p" "Encrypted or signed message status hidden"
6258                       " " "No hidden encryption nor digital signature status")
6259                  (signature "s" "Signature has been hidden"
6260                             " " "Signature is visible")
6261                  (overstrike "o" "Overstrike (^H) characters applied"
6262                              " " "No overstrike characters applied")
6263                  (emphasis "e" "/*_Emphasis_*/ characters applied"
6264                            " " "No /*_emphasis_*/ characters applied")))
6265         result)
6266     (dolist (entry alist result)
6267       (let ((key (nth 0 entry))
6268             (on (copy-sequence (nth 1 entry)))
6269             (on-help (nth 2 entry))
6270             (off (copy-sequence (nth 3 entry)))
6271             (off-help (nth 4 entry)))
6272         (put-text-property 0 1 'help-echo on-help on)
6273         (put-text-property 0 1 'help-echo off-help off)
6274         (push (list key on off) result))))
6275   "Alist of strings describing wash status in the mode line.
6276 Each entry has the form (KEY ON OF), where the KEY is a symbol
6277 representing the particular washing function, ON is the string to use
6278 in the article mode line when the washing function is active, and OFF
6279 is the string to use when it is inactive.")
6280
6281 (defun gnus-article-wash-status-entry (key value)
6282   (let ((entry (assoc key gnus-article-wash-status-strings)))
6283     (if value (nth 1 entry) (nth 2 entry))))
6284
6285 (defun gnus-article-wash-status ()
6286   "Return a string which display status of article washing."
6287   (with-current-buffer gnus-article-buffer
6288     (let ((cite (memq 'cite gnus-article-wash-types))
6289           (headers (memq 'headers gnus-article-wash-types))
6290           (boring (memq 'boring-headers gnus-article-wash-types))
6291           (pgp (memq 'pgp gnus-article-wash-types))
6292           (pem (memq 'pem gnus-article-wash-types))
6293           (signed (memq 'signed gnus-article-wash-types))
6294           (encrypted (memq 'encrypted gnus-article-wash-types))
6295           (signature (memq 'signature gnus-article-wash-types))
6296           (overstrike (memq 'overstrike gnus-article-wash-types))
6297           (emphasis (memq 'emphasis gnus-article-wash-types)))
6298       (concat
6299        (gnus-article-wash-status-entry 'cite cite)
6300        (gnus-article-wash-status-entry 'headers (or headers boring))
6301        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6302        (gnus-article-wash-status-entry 'signature signature)
6303        (gnus-article-wash-status-entry 'overstrike overstrike)
6304        (gnus-article-wash-status-entry 'emphasis emphasis)))))
6305
6306 (defun gnus-add-wash-type (type)
6307   "Add a washing of TYPE to the current status."
6308   (add-to-list 'gnus-article-wash-types type))
6309
6310 (defun gnus-delete-wash-type (type)
6311   "Add a washing of TYPE to the current status."
6312   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6313
6314 (defun gnus-add-image (category image)
6315   "Add IMAGE of CATEGORY to the list of displayed images."
6316   (let ((entry (assq category gnus-article-image-alist)))
6317     (unless entry
6318       (setq entry (list category))
6319       (push entry gnus-article-image-alist))
6320     (nconc entry (list image))))
6321
6322 (defun gnus-delete-images (category)
6323   "Delete all images in CATEGORY."
6324   (let ((entry (assq category gnus-article-image-alist)))
6325     (dolist (image (cdr entry))
6326       (gnus-remove-image image category))
6327     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6328     (gnus-delete-wash-type category)))
6329
6330 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6331
6332 (defun gnus-article-maybe-hide-headers ()
6333   "Hide unwanted headers if `gnus-have-all-headers' is nil.
6334 Provided for backwards compatibility."
6335   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6336                  (not (with-current-buffer gnus-summary-buffer
6337                         gnus-have-all-headers)))
6338              (not gnus-inhibit-hiding))
6339     (gnus-article-hide-headers)))
6340
6341 (declare-function shr-put-image "shr" (data alt &optional flags))
6342
6343 (defun gnus-shr-put-image (data alt &optional flags)
6344   "Put image DATA with a string ALT.  Enable image to be deleted."
6345   (let ((image (if flags
6346                    (shr-put-image data (propertize (or alt "*")
6347                                                    'gnus-image-category 'shr)
6348                                   flags)
6349                  ;; Old `shr-put-image' doesn't take the optional `flags'
6350                  ;; argument.
6351                  (shr-put-image data (propertize (or alt "*")
6352                                                  'gnus-image-category 'shr)))))
6353     (when image
6354       (gnus-add-image 'shr image))))
6355
6356 (defun gnus-article-mime-handles (&optional alist id all)
6357   (if alist
6358       (let ((i 1) newid flat)
6359         (dolist (handle alist flat)
6360           (setq newid (append id (list i))
6361                 i (1+ i))
6362           (if (stringp (car handle))
6363               (setq flat (nconc flat (gnus-article-mime-handles
6364                                       (cdr handle) newid all)))
6365             (delq (rassq handle all) all)
6366             (setq flat (nconc flat (list (cons newid handle)))))))
6367     (let ((flat (list nil)))
6368       ;; Assume that elements of `gnus-article-mime-handle-alist'
6369       ;; are in the decreasing order, but unnumbered subsidiaries
6370       ;; in each element are in the increasing order.
6371       (dolist (handle (reverse gnus-article-mime-handle-alist))
6372         (if (stringp (cadr handle))
6373             (setq flat (nconc flat (gnus-article-mime-handles
6374                                     (cddr handle) (list (car handle)) flat)))
6375           (delq (rassq (cdr handle) flat) flat)
6376           (setq flat (nconc flat (list (cons (list (car handle))
6377                                              (cdr handle)))))))
6378       (setq flat (cdr flat))
6379       (mapc (lambda (handle)
6380               (if (cdar handle)
6381                   ;; This is a hidden (i.e. unnumbered) handle.
6382                   (progn
6383                     (setcar handle
6384                             (1+ (caar gnus-article-mime-handle-alist)))
6385                     (push handle gnus-article-mime-handle-alist))
6386                 (setcar handle (caar handle))))
6387             flat)
6388       flat)))
6389
6390 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6391   "Show attachments as buttons in the end of the header of an article.
6392 This function toggles the display when called interactively.  Note that
6393 buttons to be added to the header are only the ones that aren't inlined
6394 in the body.  Use `gnus-header-face-alist' to highlight buttons."
6395   (interactive (list t))
6396   (gnus-with-article-buffer
6397     (let ((case-fold-search t) buttons handle type st)
6398       (save-excursion
6399         (save-restriction
6400           (widen)
6401           (article-narrow-to-head)
6402           ;; Header buttons exist?
6403           (while (and (not buttons)
6404                       (re-search-forward "^attachments?:[\n ]+" nil t))
6405             (when (get-char-property (match-end 0)
6406                                      'gnus-button-attachment-extra)
6407               (setq buttons (match-beginning 0))))
6408           (widen)
6409           (when buttons
6410             ;; Delete header buttons.
6411             (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6412                                        (match-beginning 0)
6413                                      (point-max))))
6414           (unless (and interactive buttons)
6415             ;; Find buttons.
6416             (setq buttons nil)
6417             (dolist (button (gnus-article-mime-handles))
6418               (setq handle (cdr button)
6419                     type (mm-handle-media-type handle))
6420               (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6421                                  (with-current-buffer gnus-summary-buffer
6422                                    gnus-inhibit-images)
6423                                gnus-inhibit-images)
6424                              (string-match "\\`image/" type))
6425                         (mm-inline-override-p handle)
6426                         (and (mm-handle-disposition handle)
6427                              (not (equal (car (mm-handle-disposition handle))
6428                                          "inline"))
6429                              (not (mm-attachment-override-p handle)))
6430                         (not (mm-automatic-display-p handle))
6431                         (not (or (and (mm-inlinable-p handle)
6432                                       (mm-inlined-p handle))
6433                                  (mm-automatic-external-display-p type))))
6434                 (push button buttons)))
6435             (when buttons
6436               ;; Add header buttons.
6437               (article-goto-body)
6438               (forward-line -1)
6439               (narrow-to-region (point) (point))
6440               (insert "Attachment" (if (cdr buttons) "s" "") ":")
6441               (dolist (button (nreverse buttons))
6442                 (setq st (point))
6443                 (insert " ")
6444                 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6445                 (gnus-insert-mime-button handle (car button))
6446                 (skip-chars-backward "\t\n ")
6447                 (delete-region (point) (point-max))
6448                 (when (> (current-column) (window-width))
6449                   (goto-char st)
6450                   (insert "\n")
6451                   (end-of-line)))
6452               (insert "\n")
6453               (dolist (ovl (gnus-overlays-in (point-min) (point)))
6454                 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6455                 (gnus-overlay-put ovl 'face nil))
6456               (let ((gnus-treatment-function-alist
6457                      '((gnus-treat-highlight-headers
6458                         gnus-article-highlight-headers))))
6459                 (gnus-treat-article 'head)))))))))
6460
6461 ;;; Article savers.
6462
6463 (defun gnus-output-to-file (file-name)
6464   "Append the current article to a file named FILE-NAME.
6465 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6466 text and used as the value of the coding cookie which is added to the
6467 top of a file.  Otherwise, this function saves a raw article without
6468 the coding cookie."
6469   (let* ((artbuf (current-buffer))
6470          (file-name-coding-system nnmail-pathname-coding-system)
6471          (coding gnus-article-save-coding-system)
6472          (coding-system-for-read (if coding
6473                                      nil ;; Rely on the coding cookie.
6474                                    mm-text-coding-system))
6475          (coding-system-for-write (or coding
6476                                       mm-text-coding-system-for-write
6477                                       mm-text-coding-system))
6478          (exists (file-exists-p file-name)))
6479     (with-temp-buffer
6480       (when exists
6481         (insert-file-contents file-name)
6482         (goto-char (point-min))
6483         ;; Remove the existing coding cookie.
6484         (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6485           (delete-region (match-beginning 0) (match-end 0))))
6486       (goto-char (point-max))
6487       (insert-buffer-substring artbuf)
6488       ;; Append newline at end of the buffer as separator, and then
6489       ;; save it to file.
6490       (goto-char (point-max))
6491       (insert "\n")
6492       (when coding
6493         ;; If the coding system is not suitable to encode the text,
6494         ;; ask a user for a proper one.
6495         (when (fboundp 'select-safe-coding-system)
6496           (setq coding (coding-system-base
6497                         (save-window-excursion
6498                           (select-safe-coding-system (point-min) (point-max)
6499                                                      coding))))
6500           (setq coding-system-for-write
6501                 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6502                     coding)))
6503         (goto-char (point-min))
6504         ;; Add the coding cookie.
6505         (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6506                         coding-system-for-write)))
6507       (if exists
6508           (progn
6509             (write-region (point-min) (point-max) file-name nil 'no-message)
6510             (message "Appended to %s" file-name))
6511         (write-region (point-min) (point-max) file-name))))
6512   t)
6513
6514 (defun gnus-narrow-to-page (&optional arg)
6515   "Narrow the article buffer to a page.
6516 If given a numerical ARG, move forward ARG pages."
6517   (interactive "P")
6518   (setq arg (if arg (prefix-numeric-value arg) 0))
6519   (with-current-buffer gnus-article-buffer
6520     (widen)
6521     ;; Remove any old next/prev buttons.
6522     (when (gnus-visual-p 'page-marker)
6523       (let ((inhibit-read-only t))
6524         (gnus-remove-text-with-property 'gnus-prev)
6525         (gnus-remove-text-with-property 'gnus-next)))
6526     (let (st nd pt)
6527       (when (save-excursion
6528               (cond ((< arg 0)
6529                      (if (re-search-backward page-delimiter nil 'move (abs arg))
6530                          (prog1
6531                              (setq nd (match-beginning 0)
6532                                    pt nd)
6533                            (when (re-search-backward page-delimiter nil t)
6534                              (setq st (match-end 0))))
6535                        (when (re-search-forward page-delimiter nil t)
6536                          (setq nd (match-beginning 0)
6537                                pt (point-min)))))
6538                     ((> arg 0)
6539                      (if (re-search-forward page-delimiter nil 'move arg)
6540                          (prog1
6541                              (setq st (match-end 0)
6542                                    pt st)
6543                            (when (re-search-forward page-delimiter nil t)
6544                              (setq nd (match-beginning 0))))
6545                        (when (re-search-backward page-delimiter nil t)
6546                          (setq st (match-end 0)
6547                                pt (point-max)))))
6548                     (t
6549                      (when (re-search-backward page-delimiter nil t)
6550                        (goto-char (setq st (match-end 0))))
6551                      (when (re-search-forward page-delimiter nil t)
6552                        (setq nd (match-beginning 0)))
6553                      (or st nd))))
6554         (setq gnus-page-broken t)
6555         (when pt (goto-char pt))
6556         (narrow-to-region (or st (point-min)) (or nd (point-max)))
6557         (when (gnus-visual-p 'page-marker)
6558           (save-excursion
6559             (when nd
6560               (goto-char nd)
6561               (gnus-insert-next-page-button))
6562             (when st
6563               (goto-char st)
6564               (gnus-insert-prev-page-button))))))))
6565
6566 ;; Article mode commands
6567
6568 (defun gnus-article-goto-next-page ()
6569   "Show the next page of the article."
6570   (interactive)
6571   (when (gnus-article-next-page)
6572     (goto-char (point-min))
6573     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6574
6575
6576 (defun gnus-article-goto-prev-page ()
6577   "Show the previous page of the article."
6578   (interactive)
6579   (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6580       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6581     (gnus-article-prev-page nil)))
6582
6583 ;; This is cleaner but currently breaks `gnus-pick-mode':
6584 ;;
6585 ;; (defun gnus-article-goto-next-page ()
6586 ;;   "Show the next page of the article."
6587 ;;   (interactive)
6588 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6589 ;;     (gnus-summary-next-page)))
6590 ;;
6591 ;; (defun gnus-article-goto-prev-page ()
6592 ;;   "Show the next page of the article."
6593 ;;   (interactive)
6594 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
6595 ;;     (gnus-summary-prev-page)))
6596
6597 (defun gnus-article-next-page (&optional lines)
6598   "Show the next page of the current article.
6599 If end of article, return non-nil.  Otherwise return nil.
6600 Argument LINES specifies lines to be scrolled up."
6601   (interactive "p")
6602   (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6603   (if (and (not (and gnus-article-over-scroll
6604                      (> (count-lines (window-start) (point-max))
6605                         (if (featurep 'xemacs)
6606                             (or lines (1- (window-height)))
6607                           (+ (or lines (1- (window-height))) scroll-margin)))))
6608            (save-excursion
6609              (end-of-line)
6610              (and (pos-visible-in-window-p)     ;Not continuation line.
6611                   (>= (point) (point-max)))))
6612       ;; Nothing in this page.
6613       (if (or (not gnus-page-broken)
6614               (save-excursion
6615                 (save-restriction
6616                   (widen)
6617                   (forward-line)
6618                   (eobp)))) ;Real end-of-buffer?
6619           (progn
6620             (when gnus-article-over-scroll
6621               (gnus-article-next-page-1 lines))
6622             t)                  ;Nothing more.
6623         (gnus-narrow-to-page 1)         ;Go to next page.
6624         nil)
6625     ;; More in this page.
6626     (gnus-article-next-page-1 lines)
6627     nil))
6628
6629 (defun gnus-article-beginning-of-window ()
6630   "Move point to the beginning of the window.
6631 In Emacs, the point is placed at the line number which `scroll-margin'
6632 specifies."
6633   (if (featurep 'xemacs)
6634       (move-to-window-line 0)
6635     ;; There is an obscure bug in Emacs that makes it impossible to
6636     ;; scroll past big pictures in the article buffer.  Try to fix
6637     ;; this by adding a sanity check by counting the lines visible.
6638     (when (> (count-lines (window-start) (window-end)) 30)
6639       (move-to-window-line
6640        (min (max 0 scroll-margin)
6641             (max 1 (- (window-height)
6642                       (if mode-line-format 1 0)
6643                       (if header-line-format 1 0)
6644                       2)))))))
6645
6646 (defvar scroll-in-place)
6647
6648 (defun gnus-article-next-page-1 (lines)
6649   (condition-case ()
6650       (let ((scroll-in-place nil)
6651             (auto-window-vscroll nil))
6652         (scroll-up lines))
6653     (end-of-buffer
6654      ;; Long lines may cause an end-of-buffer error.
6655      (goto-char (point-max))))
6656   (gnus-article-beginning-of-window))
6657
6658 (defun gnus-article-prev-page (&optional lines)
6659   "Show previous page of current article.
6660 Argument LINES specifies lines to be scrolled down."
6661   (interactive "p")
6662   (move-to-window-line 0)
6663   (if (and gnus-page-broken
6664            (bobp)
6665            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6666       (progn
6667         (gnus-narrow-to-page -1)        ;Go to previous page.
6668         (goto-char (point-max))
6669         (recenter (if gnus-article-over-scroll
6670                       (if lines
6671                           (max (if (featurep 'xemacs)
6672                                    lines
6673                                  (+ lines scroll-margin))
6674                                3)
6675                         (- (window-height) 2))
6676                     -1)))
6677     (prog1
6678         (condition-case ()
6679             (let ((scroll-in-place nil))
6680               (scroll-down lines))
6681           (beginning-of-buffer
6682            (goto-char (point-min))))
6683       (gnus-article-beginning-of-window))))
6684
6685 (defun gnus-article-only-boring-p ()
6686   "Decide whether there is only boring text remaining in the article.
6687 Something \"interesting\" is a word of at least two letters that does
6688 not have a face in `gnus-article-boring-faces'."
6689   (when (and gnus-article-skip-boring
6690              (boundp 'gnus-article-boring-faces)
6691              (symbol-value 'gnus-article-boring-faces))
6692     (save-excursion
6693       (let ((inhibit-point-motion-hooks t))
6694         (catch 'only-boring
6695           (while (re-search-forward "\\b\\w\\w" nil t)
6696             (forward-char -1)
6697             (when (not (gnus-intersection
6698                         (gnus-faces-at (point))
6699                         (symbol-value 'gnus-article-boring-faces)))
6700               (throw 'only-boring nil)))
6701           (throw 'only-boring t))))))
6702
6703 (defun gnus-article-refer-article ()
6704   "Read article specified by message-id around point."
6705   (interactive)
6706   (save-excursion
6707     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6708     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6709     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6710         (let ((msg-id (concat "<" (match-string 0) ">")))
6711           (set-buffer gnus-summary-buffer)
6712           (gnus-summary-refer-article msg-id))
6713       (error "No references around point"))))
6714
6715 (defun gnus-article-show-summary ()
6716   "Reconfigure windows to show summary buffer."
6717   (interactive)
6718   (if (not (gnus-buffer-live-p gnus-summary-buffer))
6719       (error "There is no summary buffer for this article buffer")
6720     (gnus-article-set-globals)
6721     (gnus-configure-windows 'article)
6722     (gnus-summary-goto-subject gnus-current-article)
6723     (gnus-summary-position-point)))
6724
6725 (defun gnus-article-describe-briefly ()
6726   "Describe article mode commands briefly."
6727   (interactive)
6728   (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")))
6729
6730 (defun gnus-article-check-buffer ()
6731   "Beep if not in an article buffer."
6732   (unless (derived-mode-p 'gnus-article-mode)
6733     (error "Command invoked outside of a Gnus article buffer")))
6734
6735 (defvar gnus-pick-mode)
6736
6737 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6738   "Read a summary buffer key sequence and execute it from the article buffer."
6739   (interactive "P")
6740   (gnus-article-check-buffer)
6741   (let ((nosaves
6742          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
6743            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6744            "=" "^" "\M-^" "|"))
6745         (nosave-but-article
6746          '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6747            "An" "Ap" [?A (meta return)] [?A delete]))
6748         (nosave-in-article
6749          '("AS" "\C-d"))
6750         keys new-sum-point)
6751     (with-current-buffer gnus-article-current-summary
6752       (let (gnus-pick-mode)
6753         (setq unread-command-events (nconc unread-command-events
6754                                            (list (or key last-command-event)))
6755               keys (if (featurep 'xemacs)
6756                        (events-to-keys (read-key-sequence nil t))
6757                      (read-key-sequence nil t)))))
6758
6759     (message "")
6760
6761     (cond
6762      ((eq (aref keys (1- (length keys))) ?\C-h)
6763       (gnus-article-describe-bindings (substring keys 0 -1)))
6764      ((or (member keys nosaves)
6765           (member keys nosave-but-article)
6766           (member keys nosave-in-article))
6767       (let (func)
6768         (save-window-excursion
6769           (pop-to-buffer gnus-article-current-summary)
6770           ;; We disable the pick minor mode commands.
6771           (let (gnus-pick-mode)
6772             (setq func (key-binding keys t))))
6773         (if (or (not func)
6774                 (numberp func))
6775             (ding)
6776           (unless (member keys nosave-in-article)
6777             (set-buffer gnus-article-current-summary))
6778           (when (and (symbolp func)
6779                      (get func 'disabled))
6780             (error "Function %s disabled" func))
6781           (call-interactively func)
6782           (setq new-sum-point (point)))
6783         (when (member keys nosave-but-article)
6784           (pop-to-buffer gnus-article-buffer))))
6785      (t
6786       ;; These commands should restore window configuration.
6787       (let ((obuf (current-buffer))
6788             (owin (current-window-configuration))
6789             win func in-buffer selected new-sum-start new-sum-hscroll err)
6790         (cond (not-restore-window
6791                (pop-to-buffer gnus-article-current-summary)
6792                (setq win (selected-window)))
6793               ((setq win (get-buffer-window gnus-article-current-summary))
6794                (select-window win))
6795               (t
6796                (let ((summary-buffer gnus-article-current-summary))
6797                  (gnus-configure-windows 'article)
6798                  (unless (setq win (get-buffer-window summary-buffer 'visible))
6799                    (let ((gnus-buffer-configuration
6800                           '((article ((vertical 1.0
6801                                                 (summary 0.25 point)
6802                                                 (article 1.0)))))))
6803                      (gnus-configure-windows 'article))
6804                    (setq win (get-buffer-window summary-buffer 'visible)))
6805                  (gnus-select-frame-set-input-focus (window-frame win))
6806                  (select-window win))))
6807         (setq in-buffer (current-buffer))
6808         ;; We disable the pick minor mode commands.
6809         (setq func (let (gnus-pick-mode)
6810                      (key-binding keys t)))
6811         (when (get func 'disabled)
6812           (error "Function %s disabled" func))
6813         (if (and func
6814                  (functionp func)
6815                  (condition-case code
6816                      (progn
6817                        (call-interactively func)
6818                        t)
6819                    (error
6820                     (setq err code)
6821                     nil)))
6822             (progn
6823               (when (eq win (selected-window))
6824                 (setq new-sum-point (point)
6825                       new-sum-start (window-start win)
6826                       new-sum-hscroll (window-hscroll win)))
6827               (when (or (eq in-buffer (current-buffer))
6828                         (when (eq obuf (current-buffer))
6829                           (set-buffer in-buffer)
6830                           t))
6831                 (setq selected (ignore-errors (gnus-summary-select-article)))
6832                 (set-buffer obuf)
6833                 (unless not-restore-window
6834                   (set-window-configuration owin))
6835                 (when (and (eq selected 'old)
6836                            new-sum-point)
6837                   (set-window-start (get-buffer-window (current-buffer))
6838                                     1)
6839                   (set-window-point (get-buffer-window (current-buffer))
6840                                     (if (article-goto-body)
6841                                         (1- (point))
6842                                       (point))))
6843                 (when (and (not not-restore-window)
6844                            new-sum-point
6845                            (window-live-p win)
6846                            (with-current-buffer (window-buffer win)
6847                              (derived-mode-p 'gnus-summary-mode)))
6848                   (set-window-point win new-sum-point)
6849                   (set-window-start win new-sum-start)
6850                   (set-window-hscroll win new-sum-hscroll))))
6851           (set-window-configuration owin)
6852           (if err
6853               (signal (car err) (cdr err))
6854             (ding))))))))
6855
6856 (defun gnus-article-read-summary-send-keys ()
6857   (interactive)
6858   (let ((unread-command-events (list (gnus-character-to-event ?S))))
6859     (gnus-article-read-summary-keys)))
6860
6861 (defun gnus-article-describe-key (key)
6862   "Display documentation of the function invoked by KEY.
6863 KEY is a string or a vector."
6864   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6865                        (read-key-sequence "Describe key: "))))
6866   (gnus-article-check-buffer)
6867   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6868                                   gnus-article-read-summary-send-keys))
6869       (with-current-buffer gnus-article-current-summary
6870         (setq unread-command-events
6871               (if (featurep 'xemacs)
6872                   (append key nil)
6873                 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6874                                         (list 'meta (- x 128))
6875                                       x))
6876                         key)))
6877         (let ((cursor-in-echo-area t)
6878               gnus-pick-mode)
6879           (describe-key (read-key-sequence nil t))))
6880     (describe-key key)))
6881
6882 (defun gnus-article-describe-key-briefly (key &optional insert)
6883   "Display documentation of the function invoked by KEY.
6884 KEY is a string or a vector."
6885   (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6886                        (read-key-sequence "Describe key: "))
6887                      current-prefix-arg))
6888   (gnus-article-check-buffer)
6889   (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6890                                   gnus-article-read-summary-send-keys))
6891       (with-current-buffer gnus-article-current-summary
6892         (setq unread-command-events
6893               (if (featurep 'xemacs)
6894                   (append key nil)
6895                 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6896                                         (list 'meta (- x 128))
6897                                       x))
6898                         key)))
6899         (let ((cursor-in-echo-area t)
6900               gnus-pick-mode)
6901           (describe-key-briefly (read-key-sequence nil t) insert)))
6902     (describe-key-briefly key insert)))
6903
6904 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6905 (defvar gnus-agent-summary-mode)
6906 (defvar gnus-draft-mode)
6907 (defvar help-xref-stack-item)
6908 (defvar help-xref-following)
6909
6910 (defun gnus-article-describe-bindings (&optional prefix)
6911   "Show a list of all defined keys, and their definitions.
6912 The optional argument PREFIX, if non-nil, should be a key sequence;
6913 then we display only bindings that start with that prefix."
6914   (interactive)
6915   (gnus-article-check-buffer)
6916   (let ((keymap (copy-keymap gnus-article-mode-map))
6917         (map (copy-keymap gnus-article-send-map))
6918         (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6919         parent agent draft)
6920     (define-key keymap "S" map)
6921     (define-key map [t] nil)
6922     (with-current-buffer gnus-article-current-summary
6923       (set-keymap-parent
6924        keymap
6925        (if (setq parent (keymap-parent gnus-article-mode-map))
6926            (prog1
6927                (setq parent (copy-keymap parent))
6928              (set-keymap-parent parent (current-local-map)))
6929          (current-local-map)))
6930       (set-keymap-parent map (key-binding "S"))
6931       (let (key def gnus-pick-mode)
6932         (while sumkeys
6933           (setq key (pop sumkeys))
6934           (cond ((and (vectorp key) (= (length key) 1)
6935                       (consp (setq def (aref key 0)))
6936                       (numberp (car def)) (numberp (cdr def)))
6937                  (when (< (max (car def) (cdr def)) 128)
6938                    (setq sumkeys
6939                          (append (mapcar
6940                                   #'vector
6941                                   (nreverse (gnus-uncompress-range def)))
6942                                  sumkeys))))
6943                 ((setq def (key-binding key))
6944                  (unless (eq def 'undefined)
6945                    (define-key keymap key def))))))
6946       (when (boundp 'gnus-agent-summary-mode)
6947         (setq agent gnus-agent-summary-mode))
6948       (when (boundp 'gnus-draft-mode)
6949         (setq draft gnus-draft-mode)))
6950     (with-temp-buffer
6951       (use-local-map keymap)
6952       (set (make-local-variable 'gnus-agent-summary-mode) agent)
6953       (set (make-local-variable 'gnus-draft-mode) draft)
6954       (describe-bindings prefix))
6955     (let ((item `((lambda (prefix)
6956                     (with-current-buffer ,(current-buffer)
6957                       (gnus-article-describe-bindings prefix)))
6958                   ,prefix)))
6959       ;; Loading `help-mode' here is necessary if `describe-bindings'
6960       ;; is replaced with something, e.g. `helm-descbinds'.
6961       (require 'help-mode)
6962       (with-current-buffer (let (help-xref-following) (help-buffer))
6963         (setq help-xref-stack-item item)))))
6964
6965 (defun gnus-article-reply-with-original (&optional wide)
6966   "Start composing a reply mail to the current message.
6967 The text in the region will be yanked.  If the region isn't active,
6968 the entire article will be yanked."
6969   (interactive)
6970   (let ((article (cdr gnus-article-current))
6971         contents)
6972     (if (not (gnus-region-active-p))
6973         (with-current-buffer gnus-summary-buffer
6974           (gnus-summary-reply (list (list article)) wide))
6975       (setq contents (buffer-substring (point) (mark t)))
6976       ;; Deactivate active regions.
6977       (when (and (boundp 'transient-mark-mode)
6978                  transient-mark-mode)
6979         (setq mark-active nil))
6980       (with-current-buffer gnus-summary-buffer
6981         (gnus-summary-reply
6982          (list (list article contents)) wide)))))
6983
6984 (defun gnus-article-wide-reply-with-original ()
6985   "Start composing a wide reply mail to the current message.
6986 The text in the region will be yanked.  If the region isn't active,
6987 the entire article will be yanked."
6988   (interactive)
6989   (gnus-article-reply-with-original t))
6990
6991 (defun gnus-article-followup-with-original ()
6992   "Compose a followup to the current article.
6993 The text in the region will be yanked.  If the region isn't active,
6994 the entire article will be yanked."
6995   (interactive)
6996   (let ((article (cdr gnus-article-current))
6997         contents)
6998       (if (not (gnus-region-active-p))
6999           (with-current-buffer gnus-summary-buffer
7000             (gnus-summary-followup (list (list article))))
7001         (setq contents (buffer-substring (point) (mark t)))
7002         ;; Deactivate active regions.
7003         (when (and (boundp 'transient-mark-mode)
7004                    transient-mark-mode)
7005           (setq mark-active nil))
7006         (with-current-buffer gnus-summary-buffer
7007           (gnus-summary-followup
7008            (list (list article contents)))))))
7009
7010 (defun gnus-article-hide (&optional arg force)
7011   "Hide all the gruft in the current article.
7012 This means that signatures, cited text and (some) headers will be
7013 hidden.
7014 If given a prefix, show the hidden text instead."
7015   (interactive (append (gnus-article-hidden-arg) (list 'force)))
7016   (gnus-article-hide-headers arg)
7017   (gnus-article-hide-list-identifiers arg)
7018   (gnus-article-hide-citation-maybe arg force)
7019   (gnus-article-hide-signature arg))
7020
7021 (defun gnus-check-group-server ()
7022   ;; Make sure the connection to the server is alive.
7023   (unless (gnus-server-opened
7024            (gnus-find-method-for-group gnus-newsgroup-name))
7025     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7026     (gnus-request-group gnus-newsgroup-name t)))
7027
7028 (eval-when-compile
7029   (autoload 'nneething-get-file-name "nneething"))
7030
7031 (defun gnus-request-article-this-buffer (article group)
7032   "Get an article and insert it into this buffer."
7033   (let (do-update-line sparse-header)
7034     (prog1
7035         (save-excursion
7036           (erase-buffer)
7037           (gnus-kill-all-overlays)
7038           (setq group (or group gnus-newsgroup-name))
7039
7040           ;; Using `gnus-request-article' directly will insert the article into
7041           ;; `nntp-server-buffer' - so we'll save some time by not having to
7042           ;; copy it from the server buffer into the article buffer.
7043
7044           ;; We only request an article by message-id when we do not have the
7045           ;; headers for it, so we'll have to get those.
7046           (when (stringp article)
7047             (gnus-read-header article))
7048
7049           ;; If the article number is negative, that means that this article
7050           ;; doesn't belong in this newsgroup (possibly), so we find its
7051           ;; message-id and request it by id instead of number.
7052           (when (and (numberp article)
7053                      gnus-summary-buffer
7054                      (get-buffer gnus-summary-buffer)
7055                      (gnus-buffer-exists-p gnus-summary-buffer))
7056             (with-current-buffer gnus-summary-buffer
7057               (let ((header (gnus-summary-article-header article)))
7058                 (when (< article 0)
7059                   (cond
7060                    ((memq article gnus-newsgroup-sparse)
7061                     ;; This is a sparse gap article.
7062                     (setq do-update-line article)
7063                     (setq article (mail-header-id header))
7064                     (setq sparse-header (gnus-read-header article))
7065                     (setq gnus-newsgroup-sparse
7066                           (delq article gnus-newsgroup-sparse)))
7067                    ((vectorp header)
7068                     ;; It's a real article.
7069                     (setq article (mail-header-id header)))
7070                    (t
7071                     ;; It is an extracted pseudo-article.
7072                     (setq article 'pseudo)
7073                     (gnus-request-pseudo-article header))))
7074
7075                 (let ((method (gnus-find-method-for-group
7076                                gnus-newsgroup-name)))
7077                   (when (and (eq (car method) 'nneething)
7078                              (vectorp header))
7079                     (let ((dir (nneething-get-file-name
7080                                 (mail-header-id header))))
7081                       (when (and (stringp dir)
7082                                  (file-directory-p dir))
7083                         (setq article 'nneething)
7084                         (gnus-group-enter-directory dir))))))))
7085
7086           (cond
7087            ;; Refuse to select canceled articles.
7088            ((and (numberp article)
7089                  gnus-summary-buffer
7090                  (get-buffer gnus-summary-buffer)
7091                  (gnus-buffer-exists-p gnus-summary-buffer)
7092                  (eq (cdr (with-current-buffer gnus-summary-buffer
7093                             (assq article gnus-newsgroup-reads)))
7094                      gnus-canceled-mark))
7095             nil)
7096            ;; We first check `gnus-original-article-buffer'.
7097            ((and (get-buffer gnus-original-article-buffer)
7098                  (numberp article)
7099                  (with-current-buffer gnus-original-article-buffer
7100                    (and (equal (car gnus-original-article) group)
7101                         (eq (cdr gnus-original-article) article))))
7102             ;; `insert-buffer-substring' would incorrectly use the
7103             ;; equivalent of string-make-multibyte which amount to decoding
7104             ;; with locale-coding-system, causing failure of
7105             ;; subsequent decoding.
7106             (insert (mm-string-to-multibyte
7107                      (with-current-buffer gnus-original-article-buffer
7108                        (buffer-substring (point-min) (point-max)))))
7109             'article)
7110            ;; Check the backlog.
7111            ((and gnus-keep-backlog
7112                  (gnus-backlog-request-article group article (current-buffer)))
7113             'article)
7114            ;; Check asynchronous pre-fetch.
7115            ((gnus-async-request-fetched-article group article (current-buffer))
7116             (gnus-async-prefetch-next group article gnus-summary-buffer)
7117             (when (and (numberp article) gnus-keep-backlog)
7118               (gnus-backlog-enter-article group article (current-buffer)))
7119             'article)
7120            ;; Check the cache.
7121            ((and gnus-use-cache
7122                  (numberp article)
7123                  (gnus-cache-request-article article group))
7124             'article)
7125            ;; Check the agent cache.
7126            ((gnus-agent-request-article article group)
7127             'article)
7128            ;; Get the article and put into the article buffer.
7129            ((or (stringp article)
7130                 (numberp article))
7131             (let ((gnus-override-method gnus-override-method)
7132                   (methods (and (stringp article)
7133                                 (with-current-buffer gnus-summary-buffer
7134                                   (gnus-refer-article-methods))))
7135                   (backend (car (gnus-find-method-for-group
7136                                  gnus-newsgroup-name)))
7137                   result
7138                   (inhibit-read-only t))
7139               (when (and (null gnus-override-method)
7140                          methods)
7141                 (setq gnus-override-method (pop methods)))
7142               (while (not result)
7143                 (erase-buffer)
7144                 (gnus-kill-all-overlays)
7145                 (let ((gnus-newsgroup-name group))
7146                   (gnus-check-group-server))
7147                 (cond
7148                  ((gnus-request-article article group (current-buffer))
7149                   (when (numberp article)
7150                     (gnus-async-prefetch-next group article
7151                                               gnus-summary-buffer)
7152                     (when gnus-keep-backlog
7153                       (gnus-backlog-enter-article
7154                        group article (current-buffer)))
7155                     (when (and gnus-agent
7156                                (gnus-agent-group-covered-p group))
7157                       (gnus-agent-store-article article group)))
7158                   (setq result 'article))
7159                  (methods
7160                   (setq gnus-override-method (pop methods)))
7161                  ((not (string-match "^400 "
7162                                      (nnheader-get-report backend)))
7163                   ;; If we get 400 server disconnect, reconnect and
7164                   ;; retry; otherwise, assume the article has expired.
7165                   (setq result 'done))))
7166               (and (eq result 'article) 'article)))
7167            ;; It was a pseudo.
7168            (t article)))
7169
7170       ;; Associate this article with the current summary buffer.
7171       (setq gnus-article-current-summary gnus-summary-buffer)
7172
7173       ;; Take the article from the original article buffer
7174       ;; and place it in the buffer it's supposed to be in.
7175       (when (and (get-buffer gnus-article-buffer)
7176                  (equal (buffer-name (current-buffer))
7177                         (buffer-name (get-buffer gnus-article-buffer))))
7178         (save-excursion
7179           (if (get-buffer gnus-original-article-buffer)
7180               (set-buffer gnus-original-article-buffer)
7181             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7182             (buffer-disable-undo)
7183             (setq major-mode 'gnus-original-article-mode)
7184             (setq buffer-read-only t))
7185           (let ((inhibit-read-only t))
7186             (erase-buffer)
7187             (insert-buffer-substring gnus-article-buffer))
7188           (setq gnus-original-article (cons group article)))
7189
7190         ;; Decode charsets.
7191         (run-hooks 'gnus-article-decode-hook)
7192         ;; Mark article as decoded or not.
7193         (setq gnus-article-decoded-p gnus-article-decode-hook))
7194
7195       ;; Update sparse articles.
7196       (when (and do-update-line
7197                  (or (numberp article)
7198                      (stringp article)))
7199         (let ((buf (current-buffer)))
7200           (set-buffer gnus-summary-buffer)
7201           (gnus-summary-update-article do-update-line sparse-header)
7202           (gnus-summary-goto-subject do-update-line nil t)
7203           (set-window-point (gnus-get-buffer-window (current-buffer) t)
7204                             (point))
7205           (set-buffer buf))))))
7206
7207 (defun gnus-block-private-groups (group)
7208   "Allows images in newsgroups to be shown, blocks images in all
7209 other groups."
7210   (if (or (gnus-news-group-p group)
7211           (gnus-member-of-valid 'global group))
7212       ;; Block nothing in news groups.
7213       nil
7214     ;; Block everything anywhere else.
7215     "."))
7216
7217 (defun gnus-blocked-images ()
7218   (if (functionp gnus-blocked-images)
7219       (funcall gnus-blocked-images gnus-newsgroup-name)
7220     gnus-blocked-images))
7221
7222 ;;;
7223 ;;; Article editing
7224 ;;;
7225
7226 (defcustom gnus-article-edit-mode-hook nil
7227   "Hook run in article edit mode buffers."
7228   :group 'gnus-article-various
7229   :type 'hook)
7230
7231 (defvar gnus-article-edit-done-function nil)
7232
7233 (defvar gnus-article-edit-mode-map nil)
7234
7235 ;; Should we be using derived.el for this?
7236 (unless gnus-article-edit-mode-map
7237   (setq gnus-article-edit-mode-map (make-keymap))
7238   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7239
7240   (gnus-define-keys gnus-article-edit-mode-map
7241     "\C-c?"    describe-mode
7242     "\C-c\C-c" gnus-article-edit-done
7243     "\C-c\C-k" gnus-article-edit-exit
7244     "\C-c\C-f\C-t" message-goto-to
7245     "\C-c\C-f\C-o" message-goto-from
7246     "\C-c\C-f\C-b" message-goto-bcc
7247     ;;"\C-c\C-f\C-w" message-goto-fcc
7248     "\C-c\C-f\C-c" message-goto-cc
7249     "\C-c\C-f\C-s" message-goto-subject
7250     "\C-c\C-f\C-r" message-goto-reply-to
7251     "\C-c\C-f\C-n" message-goto-newsgroups
7252     "\C-c\C-f\C-d" message-goto-distribution
7253     "\C-c\C-f\C-f" message-goto-followup-to
7254     "\C-c\C-f\C-m" message-goto-mail-followup-to
7255     "\C-c\C-f\C-k" message-goto-keywords
7256     "\C-c\C-f\C-u" message-goto-summary
7257     "\C-c\C-f\C-i" message-insert-or-toggle-importance
7258     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7259     "\C-c\C-b" message-goto-body
7260     "\C-c\C-i" message-goto-signature
7261
7262     "\C-c\C-t" message-insert-to
7263     "\C-c\C-n" message-insert-newsgroups
7264     "\C-c\C-o" message-sort-headers
7265     "\C-c\C-e" message-elide-region
7266     "\C-c\C-v" message-delete-not-region
7267     "\C-c\C-z" message-kill-to-signature
7268     "\M-\r" message-newline-and-reformat
7269     "\C-c\C-a" mml-attach-file
7270     "\C-a" message-beginning-of-line
7271     "\t" message-tab
7272     "\M-;" comment-region)
7273
7274   (gnus-define-keys (gnus-article-edit-wash-map
7275                      "\C-c\C-w" gnus-article-edit-mode-map)
7276     "f" gnus-article-edit-full-stops))
7277
7278 (easy-menu-define
7279   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7280   '("Field"
7281     ["Fetch To" message-insert-to t]
7282     ["Fetch Newsgroups" message-insert-newsgroups t]
7283     "----"
7284     ["To" message-goto-to t]
7285     ["From" message-goto-from t]
7286     ["Subject" message-goto-subject t]
7287     ["Cc" message-goto-cc t]
7288     ["Reply-To" message-goto-reply-to t]
7289     ["Summary" message-goto-summary t]
7290     ["Keywords" message-goto-keywords t]
7291     ["Newsgroups" message-goto-newsgroups t]
7292     ["Followup-To" message-goto-followup-to t]
7293     ["Mail-Followup-To" message-goto-mail-followup-to t]
7294     ["Distribution" message-goto-distribution t]
7295     ["Body" message-goto-body t]
7296     ["Signature" message-goto-signature t]))
7297
7298 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7299   "Major mode for editing articles.
7300 This is an extended text-mode.
7301
7302 \\{gnus-article-edit-mode-map}"
7303   (make-local-variable 'gnus-article-edit-done-function)
7304   (make-local-variable 'gnus-prev-winconf)
7305   (set (make-local-variable 'font-lock-defaults)
7306        '(message-font-lock-keywords t))
7307   (set (make-local-variable 'mail-header-separator) "")
7308   (set (make-local-variable 'gnus-article-edit-mode) t)
7309   (easy-menu-add message-mode-field-menu message-mode-map)
7310   (mml-mode)
7311   (setq buffer-read-only nil)
7312   (buffer-enable-undo)
7313   (widen))
7314
7315 (defun gnus-article-edit (&optional force)
7316   "Edit the current article.
7317 This will have permanent effect only in mail groups.
7318 If FORCE is non-nil, allow editing of articles even in read-only
7319 groups."
7320   (interactive "P")
7321   (when (and (not force)
7322              (gnus-group-read-only-p))
7323     (error "The current newsgroup does not support article editing"))
7324   (gnus-article-date-original)
7325   (gnus-article-edit-article
7326    'ignore
7327    `(lambda (no-highlight)
7328       'ignore
7329       (gnus-summary-edit-article-done
7330        ,(or (mail-header-references gnus-current-headers) "")
7331        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7332
7333 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7334   "Start editing the contents of the current article buffer."
7335   (let ((winconf (current-window-configuration)))
7336     (set-buffer gnus-article-buffer)
7337     (let ((message-auto-save-directory
7338            ;; Don't associate the article buffer with a draft file.
7339            nil))
7340       (gnus-article-edit-mode))
7341     (funcall start-func)
7342     (set-buffer-modified-p nil)
7343     (gnus-configure-windows 'edit-article)
7344     (setq gnus-article-edit-done-function exit-func)
7345     (setq gnus-prev-winconf winconf)
7346     (unless quiet
7347       (gnus-message 6 "C-c C-c to end edits"))))
7348
7349 (defun gnus-article-edit-done (&optional arg)
7350   "Update the article edits and exit."
7351   (interactive "P")
7352   (let ((func gnus-article-edit-done-function)
7353         (buf (current-buffer))
7354         (start (window-start))
7355         (winconf gnus-prev-winconf))
7356     (widen) ;; Widen it in case that users narrowed the buffer.
7357     (funcall func arg)
7358     (set-buffer buf)
7359     ;; The cache and backlog have to be flushed somewhat.
7360     (when gnus-keep-backlog
7361       (gnus-backlog-remove-article
7362        (car gnus-article-current) (cdr gnus-article-current)))
7363     ;; Flush original article as well.
7364     (gnus-flush-original-article-buffer)
7365     (when gnus-use-cache
7366       (gnus-cache-update-article
7367        (car gnus-article-current) (cdr gnus-article-current)))
7368     ;; We remove all text props from the article buffer.
7369     (kill-all-local-variables)
7370     (set-text-properties (point-min) (point-max) nil)
7371     (gnus-article-mode)
7372     (set-window-configuration winconf)
7373     (set-buffer buf)
7374     (set-window-start (get-buffer-window buf) start)
7375     (set-window-point (get-buffer-window buf) (point)))
7376   (gnus-summary-show-article))
7377
7378 (defun gnus-flush-original-article-buffer ()
7379   (when (get-buffer gnus-original-article-buffer)
7380     (with-current-buffer gnus-original-article-buffer
7381       (setq gnus-original-article nil))))
7382
7383 (defun gnus-article-edit-exit ()
7384   "Exit the article editing without updating."
7385   (interactive)
7386   (when (or (not (buffer-modified-p))
7387             (yes-or-no-p "Article modified; kill anyway? "))
7388     (let ((curbuf (current-buffer))
7389           (p (point))
7390           (window-start (window-start)))
7391       (erase-buffer)
7392       (if (gnus-buffer-live-p gnus-original-article-buffer)
7393           (insert-buffer-substring gnus-original-article-buffer))
7394       (let ((winconf gnus-prev-winconf))
7395         (kill-all-local-variables)
7396         (gnus-article-mode)
7397         (set-window-configuration winconf)
7398         ;; Tippy-toe some to make sure that point remains where it was.
7399         (save-current-buffer
7400           (set-buffer curbuf)
7401           (set-window-start (get-buffer-window (current-buffer)) window-start)
7402           (goto-char p))))
7403     (gnus-summary-show-article)))
7404
7405 (defun gnus-article-edit-full-stops ()
7406   "Interactively repair spacing at end of sentences."
7407   (interactive)
7408   (save-excursion
7409     (goto-char (point-min))
7410     (search-forward-regexp "^$" nil t)
7411     (let ((case-fold-search nil))
7412       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7413
7414 ;;;
7415 ;;; Article highlights
7416 ;;;
7417
7418 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7419
7420 ;;; Internal Variables:
7421
7422 (defcustom gnus-button-url-regexp
7423   (concat
7424    "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7425    "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7426    "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7427    (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7428        (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7429              (punct "!?:;.,"))
7430          (concat
7431           "\\(?:"
7432           ;; Match paired parentheses, e.g. in Wikipedia URLs:
7433           ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7434           "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7435           "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7436           "\\|"
7437           "[" chars punct "]+" "[" chars "]"
7438           "\\)"))
7439      (concat ;; XEmacs 21.4 doesn't support POSIX.
7440       "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7441       "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7442    "\\)")
7443   "Regular expression that matches URLs."
7444   :version "24.4"
7445   :group 'gnus-article-buttons
7446   :type 'regexp)
7447
7448 (defcustom gnus-button-valid-fqdn-regexp
7449   message-valid-fqdn-regexp
7450   "Regular expression that matches a valid FQDN."
7451   :version "22.1"
7452   :group 'gnus-article-buttons
7453   :type 'regexp)
7454
7455 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7456 (defcustom gnus-button-valid-localpart-regexp
7457   "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7458   "Regular expression that matches a localpart of mail addresses or MIDs."
7459   :version "22.1"
7460   :group 'gnus-article-buttons
7461   :type 'regexp)
7462
7463 (defcustom gnus-button-man-handler 'manual-entry
7464   "Function to use for displaying man pages.
7465 The function must take at least one argument with a string naming the
7466 man page."
7467   :version "22.1"
7468   :type '(choice (function-item :tag "Man" manual-entry)
7469                  (function-item :tag "Woman" woman)
7470                  (function :tag "Other"))
7471   :group 'gnus-article-buttons)
7472
7473 (defcustom gnus-button-mid-or-mail-regexp
7474   (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7475           gnus-button-valid-fqdn-regexp
7476           ">?\\)\\b")
7477   "Regular expression that matches a message ID or a mail address."
7478   :version "22.1"
7479   :group 'gnus-article-buttons
7480   :type 'regexp)
7481
7482 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7483   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7484 Strings like this can be either a message ID or a mail address.  If it is one
7485 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7486 message ID or a mail address, respectively.  If this variable is set to the
7487 symbol `ask', always query the user what do do.  If it is a function, this
7488 function will be called with the string as its only argument.  The function
7489 must return `mid', `mail', `invalid' or `ask'."
7490   :version "22.1"
7491   :group 'gnus-article-buttons
7492   :type '(choice (function-item :tag "Heuristic function"
7493                                 gnus-button-mid-or-mail-heuristic)
7494                  (const ask)
7495                  (const mid)
7496                  (const mail)))
7497
7498 (defcustom gnus-button-mid-or-mail-heuristic-alist
7499   '((-10.0 . ".+\\$.+@")
7500     (-10.0 . "#")
7501     (-10.0 . "\\*")
7502     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
7503     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7504     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7505     (-1.0  . "^[^a-z]+@")
7506     ;;
7507     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7508     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7509     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
7510     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7511     ;;
7512     (-2.0  . "^[0-9]")
7513     (-1.0  . "^[0-9][0-9]")
7514     ;;
7515     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7516     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7517     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7518     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7519     ;;
7520     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7521     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7522     ;;       "[0-9]{8,}.*\@"
7523     (-3.0
7524      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7525     ;; "[0-9]{12,}.*\@"
7526     ;; compensation for TDMA dated mail addresses:
7527     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7528     ;;
7529     (-20.0 . "\\.fsf@") ;; Gnus
7530     (-20.0 . "^slrn")
7531     (-20.0 . "^Pine")
7532     (-20.0 . "^alpine\\.")
7533     (-20.0 . "_-_") ;; Subject change in thread
7534     ;;
7535     (-20.0 . "\\.ln@") ;; leafnode
7536     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7537     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7538     ;;
7539     ;; (5.0 . "") ;; $local_part_len <= 7
7540     (10.0  . "^[^0-9]+@")
7541     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7542     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7543     (3.0   . "\@stud")
7544     ;;
7545     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
7546     ;;
7547     (0.5   . "^[A-Z][a-z]")
7548     (0.5   . "^[A-Z][a-z][a-z]")
7549     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7550     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7551   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7552
7553 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7554 address.  The REGEXP is processed with `case-fold-search' set to nil."
7555   :version "22.1"
7556   :group 'gnus-article-buttons
7557   :type '(repeat (cons (number :tag "Rate")
7558                        (regexp :tag "Regexp"))))
7559
7560 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7561   "Guess whether MID-OR-MAIL is a message ID or a mail address.
7562 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7563 address, `ask' if unsure and `invalid' if the string is invalid."
7564   (let ((case-fold-search nil)
7565         (list gnus-button-mid-or-mail-heuristic-alist)
7566         (result 0) rate regexp lpartlen elem)
7567     (setq lpartlen
7568           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7569     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7570     ;; Certain special cases...
7571     (when (string-match
7572            (concat
7573             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7574             "^[0-9]+\\.[0-9]+@compuserve\\|"
7575             "@public\\.gmane\\.org")
7576            mid-or-mail)
7577       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7578       (setq result 'mail))
7579     (when (string-match "@.*@\\| " mid-or-mail)
7580       (gnus-message 8 "`%s' is invalid." mid-or-mail)
7581       (setq result 'invalid))
7582     ;; Nothing more to do, if result is not a number here...
7583     (when (numberp result)
7584       (while list
7585         (setq elem (car list)
7586               rate (car elem)
7587               regexp (cdr elem)
7588               list (cdr list))
7589         (when (string-match regexp mid-or-mail)
7590           (setq result (+ result rate))
7591           (gnus-message
7592            9 "`%s' matched `%s', rate `%s', result `%s'."
7593            mid-or-mail regexp rate result)))
7594       (when (<= lpartlen 7)
7595         (setq result (+ result 5.0))
7596         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7597                       mid-or-mail result))
7598       (when (>= lpartlen 12)
7599         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7600         (cond
7601          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7602           ;; Long local part should contain realname if e-mail address,
7603           ;; too many digits: message-id.
7604           ;; $score -= 5.0 + 0.1 * $local_part_len;
7605           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7606           (setq result (+ result rate))
7607           (gnus-message
7608            9 "Many digits in `%s', rate `%s', result `%s'."
7609            mid-or-mail rate result))
7610          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7611                         mid-or-mail)
7612           ;; Too few vowels [^aeiouy]{4,}.*\@
7613           (setq result (+ result -5.0))
7614           (gnus-message
7615            9 "Few vowels in `%s', rate `%s', result `%s'."
7616            mid-or-mail -5.0 result))
7617          (t
7618           (setq result (+ result 5.0))
7619           (gnus-message
7620            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7621     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7622     ;; Maybe we should make this a customizable alist: (condition . 'result)
7623     (cond
7624      ((symbolp result) result)
7625      ;; Now convert number into proper results:
7626      ((< result -10.0) 'mid)
7627      ((> result  10.0) 'mail)
7628      (t 'ask))))
7629
7630 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7631   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7632          (url-mid (concat "news" ":" mid-or-mail))
7633          (url-mailto (concat "mailto" ":" mid-or-mail)))
7634     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7635     (when (fboundp pref)
7636       (setq guessed
7637             ;; get rid of surrounding angles...
7638             (funcall pref
7639                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7640       (if (or (eq 'mid guessed) (eq 'mail guessed))
7641           (setq pref guessed)
7642         (setq pref 'ask)))
7643     (if (eq pref 'ask)
7644         (save-window-excursion
7645           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7646               (setq pref 'mail)
7647             (setq pref 'mid))))
7648     (cond ((eq pref 'mid)
7649            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7650            (gnus-button-handle-news url-mid))
7651           ((eq pref 'mail)
7652            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
7653            (gnus-url-mailto url-mailto))
7654           (t (gnus-message 3 "Invalid string.")))))
7655
7656 (defun gnus-button-handle-custom (fun arg)
7657   "Call function FUN on argument ARG.
7658 Both FUN and ARG are supposed to be strings.  ARG will be passed
7659 as a symbol to FUN."
7660   (funcall (intern fun)
7661            (if (string-match "^customize-apropos" fun)
7662                arg
7663              (intern arg))))
7664
7665 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7666
7667 (defun gnus-button-handle-describe-function (url)
7668   "Call `describe-function' when pushing the corresponding URL button."
7669   (describe-function
7670    (intern
7671     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7672
7673 (defun gnus-button-handle-describe-variable (url)
7674   "Call `describe-variable' when pushing the corresponding URL button."
7675   (describe-variable
7676    (intern
7677     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7678
7679 (defun gnus-button-handle-symbol (url)
7680 "Display help on variable or function.
7681 Calls `describe-variable' or `describe-function'."
7682   (let ((sym (intern url)))
7683     (cond
7684      ((fboundp sym) (describe-function sym))
7685      ((boundp sym) (describe-variable sym))
7686      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7687
7688 (defun gnus-button-handle-describe-key (url)
7689   "Call `describe-key' when pushing the corresponding URL button."
7690   (let* ((key-string
7691           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7692          (keys (ignore-errors (eval `(kbd ,key-string)))))
7693     (if keys
7694         (describe-key keys)
7695       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7696
7697 (defun gnus-button-handle-apropos (url)
7698   "Call `apropos' when pushing the corresponding URL button."
7699   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7700
7701 (defun gnus-button-handle-apropos-command (url)
7702   "Call `apropos' when pushing the corresponding URL button."
7703   (apropos-command
7704    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7705
7706 (defun gnus-button-handle-apropos-variable (url)
7707   "Call `apropos' when pushing the corresponding URL button."
7708   (funcall
7709    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7710    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7711
7712 (defun gnus-button-handle-apropos-documentation (url)
7713   "Call `apropos' when pushing the corresponding URL button."
7714   (funcall
7715    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7716    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7717
7718 (defun gnus-button-handle-library (url)
7719   "Call `locate-library' when pushing the corresponding URL button."
7720   (gnus-message 9 "url=`%s'" url)
7721   (let* ((lib (locate-library url))
7722          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7723     (if (not lib)
7724         (gnus-message 1 "Cannot locale library `%s'." url)
7725       (find-file-read-only file))))
7726
7727 (defcustom gnus-button-man-level 5
7728   "*Integer that says how many man-related buttons Gnus will show.
7729 The higher the number, the more buttons will appear and the more false
7730 positives are possible.  Note that you can set this variable local to
7731 specific groups.  Setting it higher in Unix groups is probably a good idea.
7732 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7733 how to set variables in specific groups."
7734   :version "22.1"
7735   :group 'gnus-article-buttons
7736   :link '(custom-manual "(gnus)Group Parameters")
7737   :type 'integer)
7738
7739 (defcustom gnus-button-emacs-level 5
7740   "*Integer that says how many emacs-related buttons Gnus will show.
7741 The higher the number, the more buttons will appear and the more false
7742 positives are possible.  Note that you can set this variable local to
7743 specific groups.  Setting it higher in Emacs or Gnus related groups is
7744 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
7745 `gnus-parameters' on how to set variables in specific groups."
7746   :version "22.1"
7747   :group 'gnus-article-buttons
7748   :link '(custom-manual "(gnus)Group Parameters")
7749   :type 'integer)
7750
7751 (defcustom gnus-button-message-level 5
7752   "*Integer that says how many buttons for news or mail messages will appear.
7753 The higher the number, the more buttons will appear and the more false
7754 positives are possible."
7755   ;; mail addresses, MIDs, URLs for news, ...
7756   :version "22.1"
7757   :group 'gnus-article-buttons
7758   :type 'integer)
7759
7760 (defcustom gnus-button-browse-level 5
7761   "*Integer that says how many buttons for browsing will appear.
7762 The higher the number, the more buttons will appear and the more false
7763 positives are possible."
7764   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7765   :version "22.1"
7766   :group 'gnus-article-buttons
7767   :type 'integer)
7768
7769 (defcustom gnus-button-alist
7770   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7771      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7772     ((concat "\\b\\(nntp\\|news\\):\\("
7773              gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7774      0 t gnus-button-handle-news 2)
7775     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7776      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7777     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7778      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7779     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7780     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7781      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7782     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7783      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7784     ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7785      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7786     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7787      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7788     ;; RFC 2368 (The mailto URL scheme)
7789     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7790      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7791     ("\\bmailto:\\([^ \n\t]+\\)"
7792      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7793     ;; Info Konqueror style <info:/foo/bar baz>.
7794     ;; Must come before " Gnus home-grown style".
7795     ("\\binfo://?\\([^'\">\n\t]+\\)"
7796      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7797    ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7798     ("\\binfo://\\([^'\">\n\t ]+\\)"
7799      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7800     ;; Info GNOME style <info:foo#bar_baz>
7801     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7802      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7803     ;; Info KDE style <info:(foo)bar baz>
7804     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7805      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7806     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7807      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7808     ("\\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,]*\\)\\)?"
7809      ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7810      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7811     ;; This is custom
7812     ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7813      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7814     ;; Emacs help commands
7815     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7816      ;; regexp doesn't match arguments containing ` '.
7817      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7818     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7819      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7820     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7821      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7822     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7823      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7824     ;; The following entries may lead to many false positives so don't enable
7825     ;; them by default (use a high button level).
7826     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7827      ;; Exclude [.?] for URLs in gmane.emacs.cvs
7828      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7829     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7830      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7831     ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7832      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7833     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7834      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7835     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7836      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7837     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7838      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7839     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7840      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7841     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7842      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7843     ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7844      ;; Unlike the other regexps we really have to require quoting
7845      ;; here to determine where it ends.
7846      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7847     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7848     ("<URL: *\\([^\n<>]*\\)>"
7849      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7850     ;; RFC 2396 (2.4.3., delims) ...
7851     ("\"URL: *\\([^\n\"]*\\)\""
7852      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7853     ;; Raw URLs.
7854     (gnus-button-url-regexp
7855      0 (>= gnus-button-browse-level 0) browse-url 0)
7856     ;; man pages
7857     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7858      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7859      gnus-button-handle-man 1)
7860     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7861     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7862      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7863      gnus-button-handle-man 1)
7864     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7865     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7866     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7867      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7868     ;; Recognizing patches to .el files.  This is somewhat obscure,
7869     ;; but considering the percentage of Gnus users who hack Emacs
7870     ;; Lisp files...
7871     ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7872      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7873     ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7874      (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7875     ;; MID or mail: To avoid too many false positives we don't try to catch
7876     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
7877     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
7878     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
7879     ;; so that non-ambiguous entries (see above) match first.
7880     (gnus-button-mid-or-mail-regexp
7881      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7882   "*Alist of regexps matching buttons in article bodies.
7883
7884 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7885 REGEXP: is the string (case insensitive) matching text around the button (can
7886 also be Lisp expression evaluating to a string),
7887 BUTTON: is the number of the regexp grouping actually matching the button,
7888 FORM: is a Lisp expression which must eval to true for the button to
7889 be added,
7890 CALLBACK: is the function to call when the user push this button, and each
7891 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7892
7893 CALLBACK can also be a variable, in that case the value of that
7894 variable it the real callback function."
7895   :group 'gnus-article-buttons
7896   :type '(repeat (list (choice regexp variable sexp)
7897                        (integer :tag "Button")
7898                        (sexp :tag "Form")
7899                        (function :tag "Callback")
7900                        (repeat :tag "Par"
7901                                :inline t
7902                                (integer :tag "Regexp group")))))
7903 (put 'gnus-button-alist 'risky-local-variable t)
7904
7905 (defcustom gnus-header-button-alist
7906   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7907      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7908     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7909      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7910     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7911      0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7912     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7913      0 (>= gnus-button-browse-level 0) browse-url 0)
7914     ("^Subject:" gnus-button-url-regexp
7915      0 (>= gnus-button-browse-level 0) browse-url 0)
7916     ("^[^:]+:" gnus-button-url-regexp
7917      0 (>= gnus-button-browse-level 0) browse-url 0)
7918     ("^OpenPGP:.*url=" gnus-button-url-regexp
7919      0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7920     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7921      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7922     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7923      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7924   "*Alist of headers and regexps to match buttons in article heads.
7925
7926 This alist is very similar to `gnus-button-alist', except that each
7927 alist has an additional HEADER element first in each entry:
7928
7929 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7930
7931 HEADER is a regexp to match a header.  For a fuller explanation, see
7932 `gnus-button-alist'."
7933   :group 'gnus-article-buttons
7934   :group 'gnus-article-headers
7935   :type '(repeat (list (regexp :tag "Header")
7936                        (choice regexp variable)
7937                        (integer :tag "Button")
7938                        (sexp :tag "Form")
7939                        (function :tag "Callback")
7940                        (repeat :tag "Par"
7941                                :inline t
7942                                (integer :tag "Regexp group")))))
7943 (put 'gnus-header-button-alist 'risky-local-variable t)
7944
7945 ;;; Commands:
7946
7947 (defun gnus-article-push-button (event)
7948   "Check text under the mouse pointer for a callback function.
7949 If the text under the mouse pointer has a `gnus-callback' property,
7950 call it with the value of the `gnus-data' text property."
7951   (interactive "e")
7952   (set-buffer (window-buffer (posn-window (event-start event))))
7953   (let* ((pos (posn-point (event-start event)))
7954          (data (get-text-property pos 'gnus-data))
7955          (fun (get-text-property pos 'gnus-callback)))
7956     (goto-char pos)
7957     (when fun
7958       (funcall fun data))))
7959
7960 (defun gnus-article-press-button ()
7961   "Check text at point for a callback function.
7962 If the text at point has a `gnus-callback' property,
7963 call it with the value of the `gnus-data' text property."
7964   (interactive)
7965   (let ((data (get-text-property (point) 'gnus-data))
7966         (fun (get-text-property (point) 'gnus-callback)))
7967     (when fun
7968       (funcall fun data))))
7969
7970 (defun gnus-article-highlight (&optional force)
7971   "Highlight current article.
7972 This function calls `gnus-article-highlight-headers',
7973 `gnus-article-highlight-citation',
7974 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7975 do the highlighting.  See the documentation for those functions."
7976   (interactive (list 'force))
7977   (gnus-article-highlight-headers)
7978   (gnus-article-highlight-citation force)
7979   (gnus-article-highlight-signature)
7980   (gnus-article-add-buttons)
7981   (gnus-article-add-buttons-to-head))
7982
7983 (defun gnus-article-highlight-some (&optional _force)
7984   "Highlight current article.
7985 This function calls `gnus-article-highlight-headers',
7986 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7987 do the highlighting.  See the documentation for those functions."
7988   (interactive (list 'force))
7989   (gnus-article-highlight-headers)
7990   (gnus-article-highlight-signature)
7991   (gnus-article-add-buttons))
7992
7993 (defun gnus-article-highlight-headers ()
7994   "Highlight article headers as specified by `gnus-header-face-alist'."
7995   (interactive)
7996   (gnus-with-article-headers
7997     (let (regexp header-face field-face from hpoints fpoints)
7998       (dolist (entry gnus-header-face-alist)
7999         (goto-char (point-min))
8000         (setq regexp (concat "^\\("
8001                              (if (string-equal "" (nth 0 entry))
8002                                  "[^\t ]"
8003                                (nth 0 entry))
8004                              "\\)")
8005               header-face (nth 1 entry)
8006               field-face (nth 2 entry))
8007         (while (and (re-search-forward regexp nil t)
8008                     (not (eobp)))
8009           (beginning-of-line)
8010           (setq from (point))
8011           (unless (search-forward ":" nil t)
8012             (forward-char 1))
8013           (when (and header-face
8014                      (not (memq (point) hpoints)))
8015             (push (point) hpoints)
8016             (gnus-put-text-property from (point) 'face header-face))
8017           (when (and field-face
8018                      (not (memq (setq from (point)) fpoints)))
8019             (push from fpoints)
8020             (if (re-search-forward "^[^ \t]" nil t)
8021                 (forward-char -2)
8022               (goto-char (point-max)))
8023             (gnus-put-text-property from (point) 'face field-face)))))))
8024
8025 (defun gnus-article-highlight-signature ()
8026   "Highlight the signature in an article.
8027 It does this by highlighting everything after
8028 `gnus-signature-separator' using the face `gnus-signature'."
8029   (interactive)
8030   (gnus-with-article-buffer
8031     (let ((inhibit-point-motion-hooks t))
8032       (save-restriction
8033         (when (and gnus-signature-face
8034                    (gnus-article-narrow-to-signature))
8035           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8036                             'face gnus-signature-face)
8037           (widen)
8038           (gnus-article-search-signature)
8039           (let ((start (match-beginning 0))
8040                 (end (set-marker (make-marker) (1+ (match-end 0)))))
8041             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8042                                      end)))))))
8043
8044 (defun gnus-button-in-region-p (b e prop)
8045   "Say whether PROP exists in the region."
8046   (text-property-not-all b e prop nil))
8047
8048 (defun gnus-article-add-buttons ()
8049   "Find external references in the article and make buttons of them.
8050 \"External references\" are things like Message-IDs and URLs, as
8051 specified by `gnus-button-alist'."
8052   (interactive)
8053   (gnus-with-article-buffer
8054     (let ((inhibit-point-motion-hooks t)
8055           (case-fold-search t)
8056           (alist gnus-button-alist)
8057           beg entry regexp)
8058       ;; We skip the headers.
8059       (article-goto-body)
8060       (setq beg (point))
8061       (while (setq entry (pop alist))
8062         (setq regexp (eval (car entry)))
8063         (goto-char beg)
8064         (while (re-search-forward regexp nil t)
8065           (let ((start (match-beginning (nth 1 entry)))
8066                 (end (match-end (nth 1 entry)))
8067                 (from (match-beginning 0)))
8068             (when (and (eval (nth 2 entry))
8069                        (not (gnus-button-in-region-p
8070                              start end 'gnus-callback)))
8071               ;; That optional form returned non-nil, so we add the
8072               ;; button.
8073               (setq from (set-marker (make-marker) from))
8074               (unless (and (eq (car entry) 'gnus-button-url-regexp)
8075                            (gnus-article-extend-url-button from start end))
8076                 (gnus-article-add-button start end
8077                                          'gnus-button-push (list from entry))
8078                 (gnus-put-text-property
8079                  start end
8080                  'gnus-string (buffer-substring-no-properties
8081                                start end))))))))))
8082
8083 (defun gnus-article-extend-url-button (beg start end)
8084   "Extend url button if url is folded into two or more lines.
8085 Return non-nil if button is extended.  BEG is a marker that points to
8086 the beginning position of a text containing url.  START and END are
8087 the endpoints of a url button before it is extended.  The concatenated
8088 url is put as the `gnus-button-url' overlay property on the button."
8089   (let ((opoint (point))
8090         (points (list start end))
8091         url delim regexp)
8092     (prog1
8093         (when (and (progn
8094                      (goto-char end)
8095                      (not (looking-at "[\t ]*[\">]")))
8096                    (progn
8097                      (goto-char start)
8098                      (string-match
8099                       "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8100                       (buffer-substring (point-at-bol) start)))
8101                    (progn
8102                      (setq url (list (buffer-substring start end))
8103                            delim (if (match-beginning 1) ">" "\""))
8104                      (beginning-of-line)
8105                      (setq regexp (concat
8106                                    (when (and (looking-at
8107                                                message-cite-prefix-regexp)
8108                                               (< (match-end 0) start))
8109                                      (regexp-quote (match-string 0)))
8110                                    "\
8111 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8112                                    delim "\\)"))
8113                      (while (progn
8114                               (forward-line 1)
8115                               (and (looking-at regexp)
8116                                    (prog1
8117                                        (match-beginning 1)
8118                                      (push (or (match-string 2)
8119                                                (match-string 1))
8120                                            url)
8121                                      (push (setq end (or (match-end 2)
8122                                                          (match-end 1)))
8123                                            points)
8124                                      (push (or (match-beginning 2)
8125                                                (match-beginning 1))
8126                                            points)))))
8127                      (match-beginning 2)))
8128           (let (gnus-article-mouse-face widget-mouse-face)
8129             (while points
8130               (gnus-article-add-button (pop points) (pop points)
8131                                        'gnus-button-push
8132                                        (list beg (assq 'gnus-button-url-regexp
8133                                                        gnus-button-alist)))))
8134           (let ((overlay (gnus-make-overlay start end)))
8135             (gnus-overlay-put overlay 'evaporate t)
8136             (gnus-overlay-put overlay 'gnus-button-url
8137                               (list (mapconcat 'identity (nreverse url) "")))
8138             (when gnus-article-mouse-face
8139               (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8140           t)
8141       (goto-char opoint))))
8142
8143 ;; Add buttons to the head of an article.
8144 (defun gnus-article-add-buttons-to-head ()
8145   "Add buttons to the head of the article."
8146   (interactive)
8147   (gnus-with-article-headers
8148     (let (beg end)
8149       (dolist (entry gnus-header-button-alist)
8150         ;; Each alist entry.
8151         (goto-char (point-min))
8152         (while (re-search-forward (car entry) nil t)
8153           ;; Each header matching the entry.
8154           (setq beg (match-beginning 0))
8155           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8156                              (match-beginning 0))
8157                         (point-max)))
8158           (goto-char beg)
8159           (while (re-search-forward (eval (nth 1 entry)) end t)
8160             ;; Each match within a header.
8161             (let* ((entry (cdr entry))
8162                    (start (match-beginning (nth 1 entry)))
8163                    (end (match-end (nth 1 entry)))
8164                    (form (nth 2 entry)))
8165               (goto-char (match-end 0))
8166               (when (eval form)
8167                 (gnus-article-add-button
8168                  start end (nth 3 entry)
8169                  (buffer-substring (match-beginning (nth 4 entry))
8170                                    (match-end (nth 4 entry)))))))
8171           (goto-char end))))))
8172
8173 ;;; External functions:
8174
8175 (defun gnus-article-add-button (from to fun &optional data text)
8176   "Create a button between FROM and TO with callback FUN and data DATA."
8177   (when gnus-article-button-face
8178     (gnus-overlay-put (gnus-make-overlay from to nil t)
8179                       'face gnus-article-button-face))
8180   (gnus-add-text-properties
8181    from to
8182    (nconc (and gnus-article-mouse-face
8183                (list gnus-mouse-face-prop gnus-article-mouse-face))
8184           (list 'gnus-callback fun)
8185           (and data (list 'gnus-data data))))
8186   (widget-convert-button 'link from to :action 'gnus-widget-press-button
8187                          :help-echo (or text "Follow the link")
8188                          :keymap gnus-url-button-map
8189                          :button-keymap gnus-widget-button-keymap))
8190
8191 (defun gnus-article-copy-string ()
8192   "Copy the string in the button to the kill ring."
8193   (interactive)
8194   (gnus-article-check-buffer)
8195   (let ((data (get-text-property (point) 'gnus-string)))
8196     (when data
8197       (with-temp-buffer
8198         (insert data)
8199         (copy-region-as-kill (point-min) (point-max))
8200         (message "Copied %s" data)))))
8201
8202 ;;; Internal functions:
8203
8204 (defun gnus-article-set-globals ()
8205   (with-current-buffer gnus-summary-buffer
8206     (gnus-set-global-variables)))
8207
8208 (defun gnus-signature-toggle (end)
8209   (gnus-with-article-buffer
8210     (let ((inhibit-point-motion-hooks t))
8211       (if (text-property-any end (point-max) 'article-type 'signature)
8212           (progn
8213             (gnus-delete-wash-type 'signature)
8214             (gnus-remove-text-properties-when
8215              'article-type 'signature end (point-max)
8216              (cons 'article-type (cons 'signature
8217                                        gnus-hidden-properties))))
8218         (gnus-add-wash-type 'signature)
8219         (gnus-add-text-properties-when
8220          'article-type nil end (point-max)
8221          (cons 'article-type (cons 'signature
8222                                    gnus-hidden-properties)))))
8223     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8224       (gnus-set-mode-line 'article))))
8225
8226 (defun gnus-button-push (marker-and-entry)
8227   ;; Push button starting at MARKER.
8228   (save-excursion
8229     (let* ((marker (car marker-and-entry))
8230            (entry (cadr marker-and-entry))
8231            (regexp (car entry))
8232            (inhibit-point-motion-hooks t))
8233       (goto-char marker)
8234       ;; This is obviously true, or something bad is happening :)
8235       ;; But we need it to have the match-data
8236       (when (looking-at (or (if (symbolp regexp)
8237                                 (symbol-value regexp)
8238                               regexp)))
8239         (let ((fun (nth 3 entry))
8240               (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8241                              (get-char-property marker 'gnus-button-url))
8242                         (mapcar (lambda (group)
8243                                   (let ((string (match-string group)))
8244                                     (set-text-properties
8245                                      0 (length string) nil string)
8246                                     string))
8247                                 (nthcdr 4 entry)))))
8248
8249           (cond
8250            ((fboundp fun)
8251             (apply fun args))
8252            ((and (boundp fun)
8253                  (fboundp (symbol-value fun)))
8254             (apply (symbol-value fun) args))
8255            (t
8256             (gnus-message 1 "You must define `%S' to use this button"
8257                           (cons fun args)))))))))
8258
8259 (defun gnus-parse-news-url (url)
8260   (let (scheme server port group message-id articles)
8261     (with-temp-buffer
8262       (insert url)
8263       (goto-char (point-min))
8264       (when (looking-at "\\([A-Za-z]+\\):")
8265         (setq scheme (match-string 1))
8266         (goto-char (match-end 0)))
8267       (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8268         (setq server (match-string 1))
8269         (setq port (if (stringp (match-string 3))
8270                        (string-to-number (match-string 3))
8271                      (match-string 3)))
8272         (goto-char (match-end 0)))
8273
8274       (cond
8275        ((looking-at "\\(.*@.*\\)")
8276         (setq message-id (match-string 1)))
8277        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8278         (setq group (match-string 1)
8279               articles (split-string (match-string 2) "-")))
8280        ((looking-at "\\([^/]+\\)/?")
8281         (setq group (match-string 1)))
8282        (t
8283         (error "Unknown news URL syntax"))))
8284     (list scheme server port group message-id articles)))
8285
8286 (defvar nntp-port-number)
8287
8288 (defun gnus-button-handle-news (url)
8289   "Fetch a news URL."
8290   (destructuring-bind (_scheme server port group message-id _articles)
8291       (gnus-parse-news-url url)
8292     (cond
8293      (message-id
8294       (with-current-buffer gnus-summary-buffer
8295         (if server
8296             (let ((gnus-refer-article-method
8297                    (nconc (list (list 'nntp server))
8298                           gnus-refer-article-method))
8299                   (nntp-port-number (or port "nntp")))
8300               (gnus-message 7 "Fetching %s with %s"
8301                             message-id gnus-refer-article-method)
8302               (gnus-summary-refer-article message-id))
8303           (gnus-summary-refer-article message-id))))
8304      (group
8305       (gnus-button-fetch-group url)))))
8306
8307 (defun gnus-button-patch (library line)
8308   "Visit an Emacs Lisp library LIBRARY on line LINE."
8309   (interactive)
8310   (let ((file (locate-library (file-name-nondirectory library))))
8311     (unless file
8312       (error "Couldn't find library %s" library))
8313     (find-file file)
8314     (goto-char (point-min))
8315     (forward-line (1- (string-to-number line)))))
8316
8317 (defun gnus-button-handle-man (url)
8318   "Fetch a man page."
8319   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8320   (when (eq gnus-button-man-handler 'woman)
8321     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8322   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8323   (funcall gnus-button-man-handler url))
8324
8325 (defun gnus-button-handle-info-url (url)
8326   "Fetch an info URL."
8327   (setq url (mm-subst-char-in-string ?+ ?\  url))
8328   (cond
8329    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8330     (gnus-info-find-node
8331      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8332                      "Gnus")
8333              ")" (gnus-url-unhex-string (match-string 2 url)))))
8334    ((string-match "([^)\"]+)[^\"]+" url)
8335     (setq url
8336           (gnus-replace-in-string
8337            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8338     (gnus-info-find-node url))
8339    (t (error "Can't parse %s" url))))
8340
8341 (defun gnus-button-handle-info-url-gnome (url)
8342   "Fetch GNOME style info URL."
8343   (setq url (mm-subst-char-in-string ?_ ?\  url))
8344   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8345       (gnus-info-find-node
8346        (concat "("
8347                (gnus-url-unhex-string
8348                  (match-string 1 url))
8349                ")"
8350                (or (gnus-url-unhex-string
8351                     (match-string 2 url))
8352                    "Top")))
8353     (error "Can't parse %s" url)))
8354
8355 (defun gnus-button-handle-info-url-kde (url)
8356   "Fetch KDE style info URL."
8357   (gnus-info-find-node (gnus-url-unhex-string url)))
8358
8359 ;; (info) will autoload info.el
8360 (declare-function Info-menu "info" (menu-item &optional fork))
8361 (declare-function Info-index-next "info" (num))
8362
8363 (defun gnus-button-handle-info-keystrokes (url)
8364   "Call `info' when pushing the corresponding URL button."
8365   ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8366   (let (node indx comma)
8367     (if (string-match
8368          (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8369                  "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8370                  "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8371                  "\\(?:[ \t\n,]*\\)\\)?")
8372          url)
8373         (setq node (match-string 2 url)
8374               indx (match-string 3 url))
8375       (error "Can't parse %s" url))
8376     (info)
8377     (Info-directory)
8378     (Info-menu node)
8379     (when (> (length indx) 0)
8380       (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8381                             "\\([ \t\n,]*\\)")
8382                     indx)
8383       (setq comma (match-string 2 indx))
8384       (setq indx  (match-string 1 indx))
8385       (Info-index indx)
8386       (when comma
8387         (dotimes (i (with-temp-buffer
8388                       (insert comma)
8389                       ;; Note: the XEmacs version of `how-many' takes
8390                       ;; no optional argument.
8391                       (goto-char (point-min))
8392                       (how-many ",")))
8393           (Info-index-next 1)))
8394       nil)))
8395
8396 (autoload 'pgg-snarf-keys-region "pgg")
8397 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8398 (declare-function pgg-display-output-buffer "pgg" (start end status))
8399
8400 (defun gnus-button-openpgp (url)
8401   "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8402   (with-temp-buffer
8403     (mm-url-insert-file-contents-external url)
8404     (pgg-snarf-keys-region (point-min) (point-max))
8405     (pgg-display-output-buffer nil nil nil)))
8406
8407 (defun gnus-button-message-id (message-id)
8408   "Fetch MESSAGE-ID."
8409   (with-current-buffer gnus-summary-buffer
8410     (gnus-summary-refer-article message-id)))
8411
8412 (defun gnus-button-fetch-group (address &rest _ignore)
8413   "Fetch GROUP specified by ADDRESS."
8414   (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8415                       address)
8416     ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8417     ;; for nntp:// and news://
8418     (setq address (match-string 3 address)))
8419   (if (not (string-match "[:/]" address))
8420       ;; This is just a simple group url.
8421       (gnus-group-read-ephemeral-group address gnus-select-method)
8422     (if (not
8423          (string-match
8424           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8425           address))
8426         (error "Can't parse %s" address)
8427       (gnus-group-read-ephemeral-group
8428        (match-string 4 address)
8429        `(nntp ,(match-string 1 address)
8430               (nntp-address ,(match-string 1 address))
8431               (nntp-port-number ,(if (match-end 3)
8432                                      (match-string 3 address)
8433                                    "nntp")))
8434        nil nil nil
8435        (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8436
8437 (defun gnus-url-parse-query-string (query &optional downcase)
8438   (let (retval pairs cur key val)
8439     (setq pairs (split-string query "&"))
8440     (while pairs
8441       (setq cur (car pairs)
8442             pairs (cdr pairs))
8443       (if (not (string-match "=" cur))
8444           nil                           ; Grace
8445         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8446               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8447         (if downcase
8448             (setq key (downcase key)))
8449         (setq cur (assoc key retval))
8450         (if cur
8451             (setcdr cur (cons val (cdr cur)))
8452           (setq retval (cons (list key val) retval)))))
8453     retval))
8454
8455 (defun gnus-url-mailto (url)
8456   ;; Send mail to someone
8457   (setq url (replace-regexp-in-string "\n" " " url))
8458   (when (string-match "mailto:/*\\(.*\\)" url)
8459     (setq url (substring url (match-beginning 1) nil)))
8460   (let* ((args (gnus-url-parse-query-string
8461                 (if (string-match "^\\?" url)
8462                     (substring url 1)
8463                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8464                       (concat "to=" (match-string 1 url) "&"
8465                               (match-string 2 url))
8466                     (concat "to=" url)))))
8467          (subject (cdr-safe (assoc "subject" args)))
8468          func)
8469     (gnus-msg-mail)
8470     (while args
8471       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8472       (if (fboundp func)
8473           (funcall func)
8474         (message-position-on-field (caar args)))
8475       (insert (gnus-replace-in-string
8476                (mapconcat 'identity (reverse (cdar args)) ", ")
8477                "\r\n" "\n" t))
8478       (setq args (cdr args)))
8479     (if subject
8480         (message-goto-body)
8481       (message-goto-subject))))
8482
8483 (defun gnus-button-embedded-url (address)
8484   "Activate ADDRESS with `browse-url'."
8485   (browse-url (gnus-strip-whitespace address)))
8486
8487 ;;; Next/prev buttons in the article buffer.
8488
8489 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8490 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8491
8492 (defvar gnus-prev-page-map
8493   (let ((map (make-sparse-keymap)))
8494     (define-key map gnus-mouse-2 'gnus-button-prev-page)
8495     (define-key map "\r" 'gnus-button-prev-page)
8496     map))
8497
8498 (defvar gnus-next-page-map
8499   (let ((map (make-sparse-keymap)))
8500     (define-key map gnus-mouse-2 'gnus-button-next-page)
8501     (define-key map "\r" 'gnus-button-next-page)
8502     map))
8503
8504 (defun gnus-insert-prev-page-button ()
8505   (let ((b (point)) e
8506         (inhibit-read-only t))
8507     (gnus-eval-format
8508      gnus-prev-page-line-format nil
8509      `(keymap ,gnus-prev-page-map
8510               gnus-prev t
8511               gnus-callback gnus-article-button-prev-page
8512               article-type annotation))
8513     (setq e (if (bolp)
8514                 ;; Exclude a newline.
8515                 (1- (point))
8516               (point)))
8517     (when gnus-article-button-face
8518       (gnus-overlay-put (gnus-make-overlay b e nil t)
8519                         'face gnus-article-button-face))
8520     (widget-convert-button
8521      'link b e
8522      :action 'gnus-button-prev-page
8523      :button-keymap gnus-prev-page-map)))
8524
8525 (defun gnus-button-next-page (&optional _args _more-args)
8526   "Go to the next page."
8527   (interactive)
8528   (let ((win (selected-window)))
8529     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8530     (gnus-article-next-page)
8531     (select-window win)))
8532
8533 (defun gnus-button-prev-page (&optional _args _more-args)
8534   "Go to the prev page."
8535   (interactive)
8536   (let ((win (selected-window)))
8537     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8538     (gnus-article-prev-page)
8539     (select-window win)))
8540
8541 (defun gnus-insert-next-page-button ()
8542   (let ((b (point)) e
8543         (inhibit-read-only t))
8544     (gnus-eval-format gnus-next-page-line-format nil
8545                       `(keymap ,gnus-next-page-map
8546                                gnus-next t
8547                                gnus-callback gnus-article-button-next-page
8548                                article-type annotation))
8549     (setq e (if (bolp)
8550                 ;; Exclude a newline.
8551                 (1- (point))
8552               (point)))
8553     (when gnus-article-button-face
8554       (gnus-overlay-put (gnus-make-overlay b e nil t)
8555                         'face gnus-article-button-face))
8556     (widget-convert-button
8557      'link b e
8558      :action 'gnus-button-next-page
8559      :button-keymap gnus-next-page-map)))
8560
8561 (defun gnus-article-button-next-page (_arg)
8562   "Go to the next page."
8563   (interactive "P")
8564   (let ((win (selected-window)))
8565     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8566     (gnus-article-next-page)
8567     (select-window win)))
8568
8569 (defun gnus-article-button-prev-page (_arg)
8570   "Go to the prev page."
8571   (interactive "P")
8572   (let ((win (selected-window)))
8573     (select-window (gnus-get-buffer-window gnus-article-buffer t))
8574     (gnus-article-prev-page)
8575     (select-window win)))
8576
8577 (defvar gnus-decode-header-methods
8578   '(mail-decode-encoded-word-region)
8579   "List of methods used to decode headers.
8580
8581 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
8582 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
8583 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8584 whose names match REGEXP.
8585
8586 For example:
8587 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8588  mail-decode-encoded-word-region
8589  (\"chinese\" . rfc1843-decode-region))
8590 ")
8591
8592 (defvar gnus-decode-header-methods-cache nil)
8593
8594 (defun gnus-multi-decode-header (start end)
8595   "Apply the functions from `gnus-encoded-word-methods' that match."
8596   (unless (and gnus-decode-header-methods-cache
8597                (eq gnus-newsgroup-name
8598                    (car gnus-decode-header-methods-cache)))
8599     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8600     (dolist (x gnus-decode-header-methods)
8601       (if (symbolp x)
8602           (nconc gnus-decode-header-methods-cache (list x))
8603         (if (and gnus-newsgroup-name
8604                  (string-match (car x) gnus-newsgroup-name))
8605             (nconc gnus-decode-header-methods-cache
8606                    (list (cdr x)))))))
8607   (let ((xlist gnus-decode-header-methods-cache))
8608     (pop xlist)
8609     (save-restriction
8610       (narrow-to-region start end)
8611       (while xlist
8612         (funcall (pop xlist) (point-min) (point-max))))))
8613
8614 ;;;
8615 ;;; Treatment top-level handling.
8616 ;;;
8617
8618 (defvar gnus-inhibit-article-treatments nil)
8619
8620 ;; Dynamic variables.
8621 (defvar part-number)                    ;FIXME: Lacks a "gnus-" prefix.
8622 (defvar total-parts)                    ;FIXME: Lacks a "gnus-" prefix.
8623 (defvar gnus-treat-type)
8624 (defvar gnus-treat-condition)
8625 (defvar gnus-treat-length)
8626
8627 (defun gnus-treat-article (condition
8628                            &optional part-num total type)
8629   (let ((gnus-treat-condition condition)
8630         (part-number part-num)
8631         (total-parts total)
8632         (gnus-treat-type type)
8633         (gnus-treat-length (- (point-max) (point-min)))
8634         (alist gnus-treatment-function-alist)
8635         (article-goto-body-goes-to-point-min-p t)
8636         (treated-type
8637          (or (not type)
8638              (catch 'found
8639                (let ((list gnus-article-treat-types))
8640                  (while list
8641                    (when (string-match (pop list) type)
8642                      (throw 'found t)))))))
8643         (highlightp (gnus-visual-p 'article-highlight 'highlight))
8644         val)
8645     (gnus-run-hooks 'gnus-part-display-hook)
8646     (dolist (elem alist)
8647       (setq val
8648             (save-excursion
8649               (when (gnus-buffer-live-p gnus-summary-buffer)
8650                 (set-buffer gnus-summary-buffer))
8651               (symbol-value (car elem))))
8652       (when (and (or (consp val)
8653                      treated-type)
8654                  (or (not gnus-inhibit-article-treatments)
8655                      (eq gnus-treat-condition 'head))
8656                  (gnus-treat-predicate val)
8657                  (or (not (get (car elem) 'highlight))
8658                      highlightp))
8659         (save-restriction
8660           (funcall (cadr elem)))))))
8661
8662 (defun gnus-treat-predicate (val)
8663   (cond
8664    ((null val)
8665     nil)
8666    (gnus-treat-condition
8667     (eq gnus-treat-condition val))
8668    ((and (listp val)
8669          (stringp (car val)))
8670     (apply 'gnus-or (mapcar `(lambda (s)
8671                                (string-match s ,(or gnus-newsgroup-name "")))
8672                             val)))
8673    ((listp val)
8674     (let ((pred (pop val)))
8675       (cond
8676        ((eq pred 'or)
8677         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8678        ((eq pred 'and)
8679         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8680        ((eq pred 'not)
8681         (not (gnus-treat-predicate (car val))))
8682        ((eq pred 'typep)
8683         (equal (car val) gnus-treat-type))
8684        ((functionp pred)
8685         (funcall pred))
8686        (t
8687         (error "%S is not a valid predicate" pred)))))
8688    ((eq val t)
8689     t)
8690    ((eq val 'head)
8691     nil)
8692    ((eq val 'first)
8693     (eq part-number 1))
8694    ((eq val 'last)
8695     (eq part-number total-parts))
8696    ((numberp val)
8697     (< gnus-treat-length val))
8698    (t
8699     (error "%S is not a valid value" val))))
8700
8701 (defun gnus-article-encrypt-body (protocol &optional n)
8702   "Encrypt the article body."
8703   (interactive
8704    (list
8705     (or gnus-article-encrypt-protocol
8706         (gnus-completing-read "Encrypt protocol"
8707                               (mapcar 'car gnus-article-encrypt-protocol-alist)
8708                               t))
8709     current-prefix-arg))
8710   ;; User might hit `K E' instead of `K e', so prompt once.
8711   (when (and gnus-article-encrypt-protocol
8712              gnus-novice-user)
8713     (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8714       (error "Encrypt aborted")))
8715   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8716     (unless func
8717       (error "Can't find the encrypt protocol %s" protocol))
8718     (if (member gnus-newsgroup-name '("nndraft:delayed"
8719                                       "nndraft:drafts"
8720                                       "nndraft:queue"))
8721         (error "Can't encrypt the article in group %s"
8722                gnus-newsgroup-name))
8723     (gnus-summary-iterate n
8724       (with-current-buffer gnus-summary-buffer
8725         (let ((mail-parse-charset gnus-newsgroup-charset)
8726               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8727               (summary-buffer gnus-summary-buffer)
8728               references point)
8729           (gnus-set-global-variables)
8730           (when (gnus-group-read-only-p)
8731             (error "The current newsgroup does not support article encrypt"))
8732           (gnus-summary-show-article t)
8733           (setq references
8734               (or (mail-header-references gnus-current-headers) ""))
8735           (set-buffer gnus-article-buffer)
8736           (let* ((inhibit-read-only t)
8737                  (headers
8738                   (mapcar (lambda (field)
8739                             (and (save-restriction
8740                                    (message-narrow-to-head)
8741                                    (goto-char (point-min))
8742                                    (search-forward field nil t))
8743                                  (prog2
8744                                      (message-narrow-to-field)
8745                                      (buffer-string)
8746                                    (delete-region (point-min) (point-max))
8747                                    (widen))))
8748                           '("Content-Type:" "Content-Transfer-Encoding:"
8749                             "Content-Disposition:"))))
8750             (message-narrow-to-head)
8751             (message-remove-header "MIME-Version")
8752             (goto-char (point-max))
8753             (setq point (point))
8754             (insert (apply 'concat headers))
8755             (widen)
8756             (narrow-to-region point (point-max))
8757             (let ((message-options message-options))
8758               (message-options-set 'message-sender user-mail-address)
8759               (message-options-set 'message-recipients user-mail-address)
8760               (message-options-set 'message-sign-encrypt 'not)
8761               (funcall func))
8762             (goto-char (point-min))
8763             (insert "MIME-Version: 1.0\n")
8764             (widen)
8765             (gnus-summary-edit-article-done
8766              references nil summary-buffer t))
8767           (when gnus-keep-backlog
8768             (gnus-backlog-remove-article
8769              (car gnus-article-current) (cdr gnus-article-current)))
8770           (gnus-flush-original-article-buffer)
8771           (when gnus-use-cache
8772             (gnus-cache-update-article
8773              (car gnus-article-current) (cdr gnus-article-current))))))))
8774
8775 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8776   "The following specs can be used:
8777 %t  The security MIME type
8778 %i  Additional info
8779 %d  Details
8780 %D  Details if button is pressed")
8781
8782 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8783   "The following specs can be used:
8784 %t  The security MIME type
8785 %i  Additional info
8786 %d  Details
8787 %D  Details if button is pressed")
8788
8789 (defvar gnus-mime-security-button-line-format-alist
8790   '((?t gnus-tmp-type ?s)
8791     (?i gnus-tmp-info ?s)
8792     (?d gnus-tmp-details ?s)
8793     (?D gnus-tmp-pressed-details ?s)))
8794
8795 (defvar gnus-mime-security-button-commands
8796   '((gnus-article-press-button "\r" "Show Detail")
8797     (undefined "v")
8798     (undefined "t")
8799     (undefined "C")
8800     (gnus-mime-security-save-part "o" "Save...")
8801     (undefined "\C-o")
8802     (undefined "r")
8803     (undefined "d")
8804     (undefined "c")
8805     (undefined "i")
8806     (undefined "E")
8807     (undefined "e")
8808     (undefined "p")
8809     (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8810     (undefined ".")))
8811
8812 (defvar gnus-mime-security-button-map
8813   (let ((map (make-sparse-keymap)))
8814     (define-key map gnus-mouse-2 'gnus-article-push-button)
8815     (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8816     (dolist (c gnus-mime-security-button-commands)
8817       (define-key map (cadr c) (car c)))
8818     map))
8819
8820 (easy-menu-define
8821   gnus-mime-security-button-menu gnus-mime-security-button-map
8822   "Security button menu."
8823   `("Security Part"
8824     ,@(delq nil
8825             (mapcar (lambda (c)
8826                       (unless (eq (car c) 'undefined)
8827                         (vector (caddr c) (car c) :active t)))
8828                     gnus-mime-security-button-commands))))
8829
8830 (defun gnus-mime-security-button-menu (event prefix)
8831   "Construct a context-sensitive menu of security commands."
8832   (interactive "e\nP")
8833   (save-window-excursion
8834     (let ((pos (event-start event)))
8835       (select-window (posn-window pos))
8836       (goto-char (posn-point pos))
8837       (gnus-article-check-buffer)
8838       (popup-menu gnus-mime-security-button-menu nil prefix))))
8839
8840 (defvar gnus-mime-security-details-buffer nil)
8841
8842 (defvar gnus-mime-security-button-pressed nil)
8843
8844 (defvar gnus-mime-security-show-details-inline t
8845   "If non-nil, show details in the article buffer.")
8846
8847 (defun gnus-mime-security-verify-or-decrypt (handle)
8848   (mm-remove-parts (cdr handle))
8849   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8850         point (inhibit-read-only t))
8851     (if region
8852         (goto-char (car region)))
8853     (setq point (point))
8854     (with-current-buffer (mm-handle-multipart-original-buffer handle)
8855       (let* ((mm-verify-option 'known)
8856              (mm-decrypt-option 'known)
8857              (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8858         (unless (eq nparts (cdr handle))
8859           (mm-destroy-parts (cdr handle))
8860           (setcdr handle nparts))))
8861     (gnus-mime-display-security handle)
8862     (when region
8863       (delete-region (point) (cdr region))
8864       (set-marker (car region) nil)
8865       (set-marker (cdr region) nil))
8866     (goto-char point)))
8867
8868 (defun gnus-mime-security-show-details (handle)
8869   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8870     (if (not details)
8871         (gnus-message 5 "No details.")
8872       (if gnus-mime-security-show-details-inline
8873           (let ((gnus-mime-security-button-pressed
8874                  (not (get-text-property (point) 'gnus-mime-details)))
8875                 (gnus-mime-security-button-line-format
8876                  (get-text-property (point) 'gnus-line-format))
8877                 (inhibit-read-only t))
8878             (forward-char -1)
8879             (while (eq (get-text-property (point) 'gnus-line-format)
8880                        gnus-mime-security-button-line-format)
8881               (forward-char -1))
8882             (forward-char)
8883             (save-restriction
8884               (narrow-to-region (point) (point))
8885               (gnus-insert-mime-security-button handle))
8886             (delete-region (point)
8887                            (or (text-property-not-all
8888                                 (point) (point-max)
8889                                 'gnus-line-format
8890                                 gnus-mime-security-button-line-format)
8891                                (point-max))))
8892         ;; Not inlined.
8893         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8894             (with-current-buffer gnus-mime-security-details-buffer
8895               (erase-buffer)
8896               t)
8897           (setq gnus-mime-security-details-buffer
8898                 (gnus-get-buffer-create "*MIME Security Details*")))
8899         (with-current-buffer gnus-mime-security-details-buffer
8900           (insert details)
8901           (goto-char (point-min)))
8902         (pop-to-buffer gnus-mime-security-details-buffer)))))
8903
8904 (defun gnus-mime-security-press-button (handle)
8905   (save-excursion
8906     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8907         (gnus-mime-security-show-details handle)
8908       (gnus-mime-security-verify-or-decrypt handle))))
8909
8910 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8911   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8912          (gnus-tmp-type
8913           (concat
8914            (or (nth 2 (assoc protocol mm-verify-function-alist))
8915                (nth 2 (assoc protocol mm-decrypt-function-alist))
8916                "Unknown")
8917            (if (equal (car handle) "multipart/signed")
8918                " Signed" " Encrypted")
8919            " Part"))
8920          (gnus-tmp-info
8921           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8922               "Undecided"))
8923          (gnus-tmp-details
8924           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8925          gnus-tmp-pressed-details
8926          b e)
8927     (setq gnus-tmp-details
8928           (if gnus-tmp-details
8929               (concat "\n" gnus-tmp-details)
8930             ""))
8931     (setq gnus-tmp-pressed-details
8932           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8933     (unless (bolp)
8934       (insert "\n"))
8935     (setq b (point))
8936     (gnus-eval-format
8937      gnus-mime-security-button-line-format
8938      gnus-mime-security-button-line-format-alist
8939      `(keymap ,gnus-mime-security-button-map
8940          gnus-callback gnus-mime-security-press-button
8941          gnus-line-format ,gnus-mime-security-button-line-format
8942          gnus-mime-details ,gnus-mime-security-button-pressed
8943          article-type annotation
8944          gnus-data ,handle))
8945     (setq e (if (bolp)
8946                 ;; Exclude a newline.
8947                 (1- (point))
8948               (point)))
8949     (when gnus-article-button-face
8950       (gnus-overlay-put (gnus-make-overlay b e nil t)
8951                         'face gnus-article-button-face))
8952     (widget-convert-button
8953      'link b e
8954      :mime-handle handle
8955      :action 'gnus-widget-press-button
8956      :button-keymap gnus-mime-security-button-map
8957      :help-echo
8958      (lambda (_widget)
8959        ;; Needed to properly clear the message due to a bug in
8960        ;; wid-edit (XEmacs only).
8961        (when (boundp 'help-echo-owns-message)
8962          (setq help-echo-owns-message t))
8963        (format
8964         "%S: show detail; %S: more options"
8965         (aref gnus-mouse-2 0)
8966         (aref gnus-down-mouse-3 0))))))
8967
8968 (defun gnus-mime-display-security (handle)
8969   (save-restriction
8970     (narrow-to-region (point) (point))
8971     (unless (gnus-unbuttonized-mime-type-p (car handle))
8972       (gnus-insert-mime-security-button handle))
8973     (gnus-mime-display-part (cadr handle))
8974     (unless (bolp)
8975       (insert "\n"))
8976     (unless (gnus-unbuttonized-mime-type-p (car handle))
8977       (let ((gnus-mime-security-button-line-format
8978              gnus-mime-security-button-end-line-format))
8979         (gnus-insert-mime-security-button handle)))
8980     (mm-set-handle-multipart-parameter
8981      handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8982     (goto-char (point-max))))
8983
8984 (defun gnus-mime-security-run-function (function)
8985   "Run FUNCTION with the security part under point."
8986   (gnus-article-check-buffer)
8987   (let ((data (get-text-property (point) 'gnus-data))
8988         buffer handle)
8989     (when (and (stringp (car-safe data))
8990                (setq buffer (mm-handle-multipart-original-buffer data))
8991                (setq handle (cadr data)))
8992       (if (bufferp (mm-handle-buffer handle))
8993           (progn
8994             (setq handle (cons buffer (copy-sequence (cdr handle))))
8995             (mm-handle-set-undisplayer handle nil))
8996         (setq handle (mm-make-handle
8997                       buffer
8998                       (mm-handle-multipart-ctl-parameter handle 'protocol)
8999                       nil nil nil nil nil nil)))
9000       (funcall function handle))))
9001
9002 (defun gnus-mime-security-save-part ()
9003   "Save the security part under point."
9004   (interactive)
9005   (gnus-mime-security-run-function 'mm-save-part))
9006
9007 (defun gnus-mime-security-pipe-part ()
9008   "Pipe the security part under point to a process."
9009   (interactive)
9010   (gnus-mime-security-run-function 'mm-pipe-part))
9011
9012 (gnus-ems-redefine)
9013
9014 (provide 'gnus-art)
9015
9016 (run-hooks 'gnus-art-load-hook)
9017
9018 ;;; gnus-art.el ends here