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