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