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