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