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