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