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