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