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