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