* gnus-art.el: Comment fix.
[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
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           (set-buffer gnus-original-article-buffer)
1985           (save-restriction
1986             (mail-narrow-to-head)
1987             (while (gnus-article-goto-header "Face")
1988               (push (mail-header-field-value) faces))))
1989         (while (setq face (pop faces))
1990           (let ((png (gnus-convert-face-to-png face))
1991                 image)
1992             (when png
1993               (setq image (gnus-create-image png 'png t))
1994               (gnus-article-goto-header "from")
1995               (when (bobp)
1996                 (insert "From: [no `from' set]\n")
1997                 (forward-char -17))
1998               (gnus-add-wash-type 'face)
1999               (gnus-add-image 'face image)
2000               (gnus-put-image image))))))
2001     ))
2002
2003 (defun article-display-x-face (&optional force)
2004   "Look for an X-Face header and display it if present."
2005   (interactive (list 'force))
2006   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2007     (gnus-with-article-headers
2008       ;; Delete the old process, if any.
2009       (when (process-status "article-x-face")
2010         (delete-process "article-x-face"))
2011       (if (memq 'xface gnus-article-wash-types)
2012           ;; We have already displayed X-Faces, so we remove them
2013           ;; instead.
2014           (gnus-delete-images 'xface)
2015         ;; Display X-Faces.
2016         (let (x-faces from face)
2017           (save-excursion
2018             (when (and wash-face-p
2019                        (progn
2020                          (goto-char (point-min))
2021                          (not (re-search-forward
2022                                "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2023                        (gnus-buffer-live-p gnus-original-article-buffer))
2024               ;; If type `W f', use gnus-original-article-buffer,
2025               ;; otherwise use the current buffer because displaying
2026               ;; RFC822 parts calls this function too.
2027               (set-buffer gnus-original-article-buffer))
2028             (save-restriction
2029               (mail-narrow-to-head)
2030               (while (gnus-article-goto-header "X-Face")
2031                 (push (mail-header-field-value) x-faces))
2032               (setq from (message-fetch-field "from"))))
2033           ;; Sending multiple EOFs to xv doesn't work, so we only do a
2034           ;; single external face.
2035           (when (stringp gnus-article-x-face-command)
2036             (setq x-faces (list (car x-faces))))
2037           (while (and (setq face (pop x-faces))
2038                       gnus-article-x-face-command
2039                       (or force
2040                           ;; Check whether this face is censored.
2041                           (not gnus-article-x-face-too-ugly)
2042                           (and gnus-article-x-face-too-ugly from
2043                                (not (string-match gnus-article-x-face-too-ugly
2044                                                   from)))))
2045             ;; We display the face.
2046             (if (symbolp gnus-article-x-face-command)
2047                 ;; The command is a lisp function, so we call it.
2048                 (if (functionp gnus-article-x-face-command)
2049                     (funcall gnus-article-x-face-command face)
2050                   (error "%s is not a function" gnus-article-x-face-command))
2051               ;; The command is a string, so we interpret the command
2052               ;; as a, well, command, and fork it off.
2053               (let ((process-connection-type nil))
2054                 (process-kill-without-query
2055                  (start-process
2056                   "article-x-face" nil shell-file-name shell-command-switch
2057                   gnus-article-x-face-command))
2058                 (with-temp-buffer
2059                   (insert face)
2060                   (process-send-region "article-x-face"
2061                                        (point-min) (point-max)))
2062                 (process-send-eof "article-x-face")))))))))
2063
2064 (defun article-decode-mime-words ()
2065   "Decode all MIME-encoded words in the article."
2066   (interactive)
2067   (save-excursion
2068     (set-buffer gnus-article-buffer)
2069     (let ((inhibit-point-motion-hooks t)
2070           buffer-read-only
2071           (mail-parse-charset gnus-newsgroup-charset)
2072           (mail-parse-ignored-charsets
2073            (save-excursion (set-buffer gnus-summary-buffer)
2074                            gnus-newsgroup-ignored-charsets)))
2075       (mail-decode-encoded-word-region (point-min) (point-max)))))
2076
2077 (defun article-decode-charset (&optional prompt)
2078   "Decode charset-encoded text in the article.
2079 If PROMPT (the prefix), prompt for a coding system to use."
2080   (interactive "P")
2081   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2082         buffer-read-only
2083         (mail-parse-charset gnus-newsgroup-charset)
2084         (mail-parse-ignored-charsets
2085          (save-excursion (condition-case nil
2086                              (set-buffer gnus-summary-buffer)
2087                            (error))
2088                          gnus-newsgroup-ignored-charsets))
2089         ct cte ctl charset format)
2090   (save-excursion
2091     (save-restriction
2092       (article-narrow-to-head)
2093       (setq ct (message-fetch-field "Content-Type" t)
2094             cte (message-fetch-field "Content-Transfer-Encoding" t)
2095             ctl (and ct (ignore-errors
2096                           (mail-header-parse-content-type ct)))
2097             charset (cond
2098                      (prompt
2099                       (mm-read-coding-system "Charset to decode: "))
2100                      (ctl
2101                       (mail-content-type-get ctl 'charset)))
2102             format (and ctl (mail-content-type-get ctl 'format)))
2103       (when cte
2104         (setq cte (mail-header-strip cte)))
2105       (if (and ctl (not (string-match "/" (car ctl))))
2106           (setq ctl nil))
2107       (goto-char (point-max)))
2108     (forward-line 1)
2109     (save-restriction
2110       (narrow-to-region (point) (point-max))
2111       (when (and (eq mail-parse-charset 'gnus-decoded)
2112                  (eq (mm-body-7-or-8) '8bit))
2113         ;; The text code could have been decoded.
2114         (setq charset mail-parse-charset))
2115       (when (and (or (not ctl)
2116                      (equal (car ctl) "text/plain"))
2117                  (not format)) ;; article with format will decode later.
2118         (mm-decode-body
2119          charset (and cte (intern (downcase
2120                                    (gnus-strip-whitespace cte))))
2121          (car ctl)))))))
2122
2123 (defun article-decode-encoded-words ()
2124   "Remove encoded-word encoding from headers."
2125   (let ((inhibit-point-motion-hooks t)
2126         (mail-parse-charset gnus-newsgroup-charset)
2127         (mail-parse-ignored-charsets
2128          (save-excursion (condition-case nil
2129                              (set-buffer gnus-summary-buffer)
2130                            (error))
2131                          gnus-newsgroup-ignored-charsets))
2132         buffer-read-only)
2133     (save-restriction
2134       (article-narrow-to-head)
2135       (funcall gnus-decode-header-function (point-min) (point-max)))))
2136
2137 (defun article-decode-group-name ()
2138   "Decode group names in `Newsgroups:'."
2139   (let ((inhibit-point-motion-hooks t)
2140         buffer-read-only
2141         (method (gnus-find-method-for-group gnus-newsgroup-name)))
2142     (when (and (or gnus-group-name-charset-method-alist
2143                    gnus-group-name-charset-group-alist)
2144                (gnus-buffer-live-p gnus-original-article-buffer))
2145       (save-restriction
2146         (article-narrow-to-head)
2147         (with-current-buffer gnus-original-article-buffer
2148           (goto-char (point-min)))
2149         (while (re-search-forward
2150                 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2151           (replace-match (save-match-data
2152                            (gnus-decode-newsgroups
2153                             ;; XXX how to use data in article buffer?
2154                             (with-current-buffer gnus-original-article-buffer
2155                               (re-search-forward
2156                                "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2157                                nil t)
2158                               (match-string 1))
2159                             gnus-newsgroup-name method))
2160                          t t nil 1))
2161         (goto-char (point-min))
2162         (with-current-buffer gnus-original-article-buffer
2163           (goto-char (point-min)))
2164         (while (re-search-forward
2165                 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2166           (replace-match (save-match-data
2167                            (gnus-decode-newsgroups
2168                             ;; XXX how to use data in article buffer?
2169                             (with-current-buffer gnus-original-article-buffer
2170                               (re-search-forward
2171                                "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2172                                nil t)
2173                               (match-string 1))
2174                             gnus-newsgroup-name method))
2175                          t t nil 1))))))
2176
2177 (autoload 'idna-to-unicode "idna")
2178
2179 (defun article-decode-idna-rhs ()
2180   "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2181   (when gnus-use-idna
2182     (save-restriction
2183       (let ((inhibit-point-motion-hooks t)
2184             buffer-read-only)
2185         (article-narrow-to-head)
2186         (goto-char (point-min))
2187         (while (re-search-forward "\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2188           (let (ace unicode)
2189             (when (save-match-data
2190                     (and (setq ace (match-string 1))
2191                          (save-excursion
2192                            (and (re-search-backward "^[^ \t]" nil t)
2193                                 (looking-at "From\\|To\\|Cc")))
2194                          (save-excursion (backward-char)
2195                                          (message-idna-inside-rhs-p))
2196                          (setq unicode (idna-to-unicode ace))))
2197               (unless (string= ace unicode)
2198                 (replace-match unicode nil nil nil 1)))))))))
2199
2200 (defun article-de-quoted-unreadable (&optional force read-charset)
2201   "Translate a quoted-printable-encoded article.
2202 If FORCE, decode the article whether it is marked as quoted-printable
2203 or not.
2204 If READ-CHARSET, ask for a coding system."
2205   (interactive (list 'force current-prefix-arg))
2206   (save-excursion
2207     (let ((buffer-read-only nil) type charset)
2208       (if (gnus-buffer-live-p gnus-original-article-buffer)
2209           (with-current-buffer gnus-original-article-buffer
2210             (setq type
2211                   (gnus-fetch-field "content-transfer-encoding"))
2212             (let* ((ct (gnus-fetch-field "content-type"))
2213                    (ctl (and ct
2214                              (ignore-errors
2215                                (mail-header-parse-content-type ct)))))
2216               (setq charset (and ctl
2217                                  (mail-content-type-get ctl 'charset)))
2218               (if (stringp charset)
2219                   (setq charset (intern (downcase charset)))))))
2220       (if read-charset
2221           (setq charset (mm-read-coding-system "Charset: " charset)))
2222       (unless charset
2223         (setq charset gnus-newsgroup-charset))
2224       (when (or force
2225                 (and type (let ((case-fold-search t))
2226                             (string-match "quoted-printable" type))))
2227         (article-goto-body)
2228         (quoted-printable-decode-region
2229          (point) (point-max) (mm-charset-to-coding-system charset))))))
2230
2231 (defun article-de-base64-unreadable (&optional force read-charset)
2232   "Translate a base64 article.
2233 If FORCE, decode the article whether it is marked as base64 not.
2234 If READ-CHARSET, ask for a coding system."
2235   (interactive (list 'force current-prefix-arg))
2236   (save-excursion
2237     (let ((buffer-read-only nil) type charset)
2238       (if (gnus-buffer-live-p gnus-original-article-buffer)
2239           (with-current-buffer gnus-original-article-buffer
2240             (setq type
2241                   (gnus-fetch-field "content-transfer-encoding"))
2242             (let* ((ct (gnus-fetch-field "content-type"))
2243                    (ctl (and ct
2244                              (ignore-errors
2245                                (mail-header-parse-content-type ct)))))
2246               (setq charset (and ctl
2247                                  (mail-content-type-get ctl 'charset)))
2248               (if (stringp charset)
2249                   (setq charset (intern (downcase charset)))))))
2250       (if read-charset
2251           (setq charset (mm-read-coding-system "Charset: " charset)))
2252       (unless charset
2253         (setq charset gnus-newsgroup-charset))
2254       (when (or force
2255                 (and type (let ((case-fold-search t))
2256                             (string-match "base64" type))))
2257         (article-goto-body)
2258         (save-restriction
2259           (narrow-to-region (point) (point-max))
2260           (base64-decode-region (point-min) (point-max))
2261           (mm-decode-coding-region
2262            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2263
2264 (eval-when-compile
2265   (require 'rfc1843))
2266
2267 (defun article-decode-HZ ()
2268   "Translate a HZ-encoded article."
2269   (interactive)
2270   (require 'rfc1843)
2271   (save-excursion
2272     (let ((buffer-read-only nil))
2273       (rfc1843-decode-region (point-min) (point-max)))))
2274
2275 (defun article-unsplit-urls ()
2276   "Remove the newlines that some other mailers insert into URLs."
2277   (interactive)
2278   (save-excursion
2279     (let ((buffer-read-only nil))
2280       (goto-char (point-min))
2281       (while (re-search-forward
2282               "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2283         (replace-match "\\1\\3" t)))
2284     (when (interactive-p)
2285       (gnus-treat-article nil))))
2286
2287
2288 (defun article-wash-html (&optional read-charset)
2289   "Format an HTML article.
2290 If READ-CHARSET, ask for a coding system."
2291   (interactive "P")
2292   (save-excursion
2293     (let ((buffer-read-only nil)
2294           charset)
2295       (when (gnus-buffer-live-p gnus-original-article-buffer)
2296         (with-current-buffer gnus-original-article-buffer
2297           (let* ((ct (gnus-fetch-field "content-type"))
2298                  (ctl (and ct
2299                            (ignore-errors
2300                              (mail-header-parse-content-type ct)))))
2301             (setq charset (and ctl
2302                                (mail-content-type-get ctl 'charset)))
2303             (when (stringp charset)
2304               (setq charset (intern (downcase charset)))))))
2305       (when read-charset
2306         (setq charset (mm-read-coding-system "Charset: " charset)))
2307       (unless charset
2308         (setq charset gnus-newsgroup-charset))
2309       (article-goto-body)
2310       (save-window-excursion
2311         (save-restriction
2312           (narrow-to-region (point) (point-max))
2313           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2314                  (entry (assq func mm-text-html-washer-alist)))
2315             (when entry
2316               (setq func (cdr entry)))
2317             (cond
2318              ((functionp func)
2319               (funcall func))
2320              (t
2321               (apply (car func) (cdr func))))))))))
2322
2323 (defun gnus-article-wash-html-with-w3 ()
2324   "Wash the current buffer with w3."
2325   (mm-setup-w3)
2326   (let ((w3-strict-width (window-width))
2327         (url-standalone-mode t)
2328         (url-gateway-unplugged t)
2329         (w3-honor-stylesheets nil))
2330     (condition-case ()
2331         (w3-region (point-min) (point-max))
2332       (error))))
2333
2334 (defun gnus-article-wash-html-with-w3m ()
2335   "Wash the current buffer with emacs-w3m."
2336   (mm-setup-w3m)
2337   (save-restriction
2338     (narrow-to-region (point) (point-max))
2339     (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2340                                    nil
2341                                  "\\`cid:"))
2342           w3m-force-redisplay)
2343       (w3m-region (point-min) (point-max)))
2344     (when mm-inline-text-html-with-w3m-keymap
2345       (add-text-properties
2346        (point-min) (point-max)
2347        (nconc (mm-w3m-local-map-property)
2348               '(mm-inline-text-html-with-w3m t))))))
2349
2350 (defun article-hide-list-identifiers ()
2351   "Remove list identifies from the Subject header.
2352 The `gnus-list-identifiers' variable specifies what to do."
2353   (interactive)
2354   (let ((inhibit-point-motion-hooks t)
2355         (regexp (if (consp gnus-list-identifiers)
2356                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2357                   gnus-list-identifiers))
2358         buffer-read-only)
2359     (when regexp
2360       (save-excursion
2361         (save-restriction
2362           (article-narrow-to-head)
2363           (goto-char (point-min))
2364           (while (re-search-forward
2365                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2366                   nil t)
2367             (delete-region (match-beginning 2) (match-end 0))
2368             (beginning-of-line))
2369           (when (re-search-forward
2370                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2371             (delete-region (match-beginning 1) (match-end 1))))))))
2372
2373 (defun article-hide-pem (&optional arg)
2374   "Toggle hiding of any PEM headers and signatures in the current article.
2375 If given a negative prefix, always show; if given a positive prefix,
2376 always hide."
2377   (interactive (gnus-article-hidden-arg))
2378   (unless (gnus-article-check-hidden-text 'pem arg)
2379     (save-excursion
2380       (let (buffer-read-only end)
2381         (goto-char (point-min))
2382         ;; Hide the horrendously ugly "header".
2383         (when (and (search-forward
2384                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2385                     nil t)
2386                    (setq end (1+ (match-beginning 0))))
2387           (gnus-add-wash-type 'pem)
2388           (gnus-article-hide-text-type
2389            end
2390            (if (search-forward "\n\n" nil t)
2391                (match-end 0)
2392              (point-max))
2393            'pem)
2394           ;; Hide the trailer as well
2395           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2396                                 nil t)
2397             (gnus-article-hide-text-type
2398              (match-beginning 0) (match-end 0) 'pem)))))))
2399
2400 (defun article-strip-banner ()
2401   "Strip the banners specified by the `banner' group parameter and by
2402 `gnus-article-address-banner-alist'."
2403   (interactive)
2404   (save-excursion
2405     (save-restriction
2406       (let ((inhibit-point-motion-hooks t))
2407         (when (gnus-parameter-banner gnus-newsgroup-name)
2408           (article-really-strip-banner
2409            (gnus-parameter-banner gnus-newsgroup-name)))
2410         (when gnus-article-address-banner-alist
2411           (article-really-strip-banner
2412            (let ((from (save-restriction
2413                          (widen)
2414                          (article-narrow-to-head)
2415                          (mail-fetch-field "from"))))
2416              (when (and from
2417                         (setq from
2418                               (caar (mail-header-parse-addresses from))))
2419                (catch 'found
2420                  (dolist (pair gnus-article-address-banner-alist)
2421                    (when (string-match (car pair) from)
2422                      (throw 'found (cdr pair)))))))))))))
2423
2424 (defun article-really-strip-banner (banner)
2425   "Strip the banner specified by the argument."
2426   (save-excursion
2427     (save-restriction
2428       (let ((inhibit-point-motion-hooks t)
2429             (gnus-signature-limit nil)
2430             buffer-read-only)
2431         (article-goto-body)
2432         (cond
2433          ((eq banner 'signature)
2434           (when (gnus-article-narrow-to-signature)
2435             (widen)
2436             (forward-line -1)
2437             (delete-region (point) (point-max))))
2438          ((symbolp banner)
2439           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2440               (while (re-search-forward banner nil t)
2441                 (delete-region (match-beginning 0) (match-end 0)))))
2442          ((stringp banner)
2443           (while (re-search-forward banner nil t)
2444             (delete-region (match-beginning 0) (match-end 0)))))))))
2445
2446 (defun article-babel ()
2447   "Translate article using an online translation service."
2448   (interactive)
2449   (require 'babel)
2450   (save-excursion
2451     (set-buffer gnus-article-buffer)
2452     (when (article-goto-body)
2453       (let* ((buffer-read-only nil)
2454              (start (point))
2455              (end (point-max))
2456              (orig (buffer-substring start end))
2457              (trans (babel-as-string orig)))
2458         (save-restriction
2459           (narrow-to-region start end)
2460           (delete-region start end)
2461           (insert trans))))))
2462
2463 (defun article-hide-signature (&optional arg)
2464   "Hide the signature in the current article.
2465 If given a negative prefix, always show; if given a positive prefix,
2466 always hide."
2467   (interactive (gnus-article-hidden-arg))
2468   (unless (gnus-article-check-hidden-text 'signature arg)
2469     (save-excursion
2470       (save-restriction
2471         (let ((buffer-read-only nil))
2472           (when (gnus-article-narrow-to-signature)
2473             (gnus-article-hide-text-type
2474              (point-min) (point-max) 'signature))))))
2475   (gnus-set-mode-line 'article))
2476
2477 (defun article-strip-headers-in-body ()
2478   "Strip offensive headers from bodies."
2479   (interactive)
2480   (save-excursion
2481     (article-goto-body)
2482     (let ((case-fold-search t))
2483       (when (looking-at "x-no-archive:")
2484         (gnus-delete-line)))))
2485
2486 (defun article-strip-leading-blank-lines ()
2487   "Remove all blank lines from the beginning of the article."
2488   (interactive)
2489   (save-excursion
2490     (let ((inhibit-point-motion-hooks t)
2491           buffer-read-only)
2492       (when (article-goto-body)
2493         (while (and (not (eobp))
2494                     (looking-at "[ \t]*$"))
2495           (gnus-delete-line))))))
2496
2497 (defun article-narrow-to-head ()
2498   "Narrow the buffer to the head of the message.
2499 Point is left at the beginning of the narrowed-to region."
2500   (narrow-to-region
2501    (goto-char (point-min))
2502    (if (search-forward "\n\n" nil 1)
2503        (1- (point))
2504      (point-max)))
2505   (goto-char (point-min)))
2506
2507 (defun article-goto-body ()
2508   "Place point at the start of the body."
2509   (goto-char (point-min))
2510   (cond
2511    ;; This variable is only bound when dealing with separate
2512    ;; MIME body parts.
2513    (article-goto-body-goes-to-point-min-p
2514     t)
2515    ((search-forward "\n\n" nil t)
2516     t)
2517    (t
2518     (goto-char (point-max))
2519     nil)))
2520
2521 (defun article-strip-multiple-blank-lines ()
2522   "Replace consecutive blank lines with one empty line."
2523   (interactive)
2524   (save-excursion
2525     (let ((inhibit-point-motion-hooks t)
2526           buffer-read-only)
2527       ;; First make all blank lines empty.
2528       (article-goto-body)
2529       (while (re-search-forward "^[ \t]+$" nil t)
2530         (unless (gnus-annotation-in-region-p
2531                  (match-beginning 0) (match-end 0))
2532           (replace-match "" nil t)))
2533       ;; Then replace multiple empty lines with a single empty line.
2534       (article-goto-body)
2535       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2536         (unless (gnus-annotation-in-region-p
2537                  (match-beginning 0) (match-end 0))
2538           (delete-region (match-beginning 1) (match-end 1)))))))
2539
2540 (defun article-strip-leading-space ()
2541   "Remove all white space from the beginning of the lines in the article."
2542   (interactive)
2543   (save-excursion
2544     (let ((inhibit-point-motion-hooks t)
2545           buffer-read-only)
2546       (article-goto-body)
2547       (while (re-search-forward "^[ \t]+" nil t)
2548         (replace-match "" t t)))))
2549
2550 (defun article-strip-trailing-space ()
2551   "Remove all white space from the end of the lines in the article."
2552   (interactive)
2553   (save-excursion
2554     (let ((inhibit-point-motion-hooks t)
2555           buffer-read-only)
2556       (article-goto-body)
2557       (while (re-search-forward "[ \t]+$" nil t)
2558         (replace-match "" t t)))))
2559
2560 (defun article-strip-blank-lines ()
2561   "Strip leading, trailing and multiple blank lines."
2562   (interactive)
2563   (article-strip-leading-blank-lines)
2564   (article-remove-trailing-blank-lines)
2565   (article-strip-multiple-blank-lines))
2566
2567 (defun article-strip-all-blank-lines ()
2568   "Strip all blank lines."
2569   (interactive)
2570   (save-excursion
2571     (let ((inhibit-point-motion-hooks t)
2572           buffer-read-only)
2573       (article-goto-body)
2574       (while (re-search-forward "^[ \t]*\n" nil t)
2575         (replace-match "" t t)))))
2576
2577 (defun gnus-article-narrow-to-signature ()
2578   "Narrow to the signature; return t if a signature is found, else nil."
2579   (let ((inhibit-point-motion-hooks t))
2580     (when (gnus-article-search-signature)
2581       (forward-line 1)
2582       ;; Check whether we have some limits to what we consider
2583       ;; to be a signature.
2584       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2585                       (list gnus-signature-limit)))
2586             limit limited)
2587         (while (setq limit (pop limits))
2588           (if (or (and (integerp limit)
2589                        (< (- (point-max) (point)) limit))
2590                   (and (floatp limit)
2591                        (< (count-lines (point) (point-max)) limit))
2592                   (and (functionp limit)
2593                        (funcall limit))
2594                   (and (stringp limit)
2595                        (not (re-search-forward limit nil t))))
2596               ()                        ; This limit did not succeed.
2597             (setq limited t
2598                   limits nil)))
2599         (unless limited
2600           (narrow-to-region (point) (point-max))
2601           t)))))
2602
2603 (defun gnus-article-search-signature ()
2604   "Search the current buffer for the signature separator.
2605 Put point at the beginning of the signature separator."
2606   (let ((cur (point)))
2607     (goto-char (point-max))
2608     (if (if (stringp gnus-signature-separator)
2609             (re-search-backward gnus-signature-separator nil t)
2610           (let ((seps gnus-signature-separator))
2611             (while (and seps
2612                         (not (re-search-backward (car seps) nil t)))
2613               (pop seps))
2614             seps))
2615         t
2616       (goto-char cur)
2617       nil)))
2618
2619 (defun gnus-article-hidden-arg ()
2620   "Return the current prefix arg as a number, or 0 if no prefix."
2621   (list (if current-prefix-arg
2622             (prefix-numeric-value current-prefix-arg)
2623           0)))
2624
2625 (defun gnus-article-check-hidden-text (type arg)
2626   "Return nil if hiding is necessary.
2627 Arg can be nil or a number.  nil and positive means hide, negative
2628 means show, 0 means toggle."
2629   (save-excursion
2630     (save-restriction
2631       (let ((hide (gnus-article-hidden-text-p type)))
2632         (cond
2633          ((or (null arg)
2634               (> arg 0))
2635           nil)
2636          ((< arg 0)
2637           (gnus-article-show-hidden-text type)
2638           t)
2639          (t
2640           (if (eq hide 'hidden)
2641               (progn
2642                 (gnus-article-show-hidden-text type)
2643                 t)
2644             nil)))))))
2645
2646 (defun gnus-article-hidden-text-p (type)
2647   "Say whether the current buffer contains hidden text of type TYPE."
2648   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2649     (while (and pos
2650                 (not (get-text-property pos 'invisible))
2651                 (not (get-text-property pos 'dummy-invisible)))
2652       (setq pos
2653             (text-property-any (1+ pos) (point-max) 'article-type type)))
2654     (if pos
2655         'hidden
2656       nil)))
2657
2658 (defun gnus-article-show-hidden-text (type &optional dummy)
2659   "Show all hidden text of type TYPE.
2660 Originally it is hide instead of DUMMY."
2661   (let ((buffer-read-only nil)
2662         (inhibit-point-motion-hooks t))
2663     (gnus-remove-text-properties-when
2664      'article-type type
2665      (point-min) (point-max)
2666      (cons 'article-type (cons type
2667                                gnus-hidden-properties)))
2668     (gnus-delete-wash-type type)))
2669
2670 (defconst article-time-units
2671   `((year . ,(* 365.25 24 60 60))
2672     (week . ,(* 7 24 60 60))
2673     (day . ,(* 24 60 60))
2674     (hour . ,(* 60 60))
2675     (minute . 60)
2676     (second . 1))
2677   "Mapping from time units to seconds.")
2678
2679 (defun gnus-article-forward-header ()
2680   "Move point to the start of the next header.
2681 If the current header is a continuation header, this can be several
2682 lines forward."
2683   (let ((ended nil))
2684     (while (not ended)
2685       (forward-line 1)
2686       (if (looking-at "[ \t]+[^ \t]")
2687           (forward-line 1)
2688         (setq ended t)))))
2689
2690 (defun article-date-ut (&optional type highlight header)
2691   "Convert DATE date to universal time in the current article.
2692 If TYPE is `local', convert to local time; if it is `lapsed', output
2693 how much time has lapsed since DATE.  For `lapsed', the value of
2694 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2695 should replace the \"Date:\" one, or should be added below it."
2696   (interactive (list 'ut t))
2697   (let* ((header (or header
2698                      (message-fetch-field "date")
2699                      ""))
2700          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2701          (date-regexp
2702           (cond
2703            ((not gnus-article-date-lapsed-new-header)
2704             tdate-regexp)
2705            ((eq type 'lapsed)
2706             "^X-Sent:[ \t]")
2707            (t
2708             "^Date:[ \t]")))
2709          (date (if (vectorp header) (mail-header-date header)
2710                  header))
2711          (inhibit-point-motion-hooks t)
2712          pos
2713          bface eface)
2714     (save-excursion
2715       (save-restriction
2716         (article-narrow-to-head)
2717         (when (re-search-forward tdate-regexp nil t)
2718           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2719                 date (or (get-text-property (gnus-point-at-bol)
2720                                             'original-date)
2721                          date)
2722                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2723           (forward-line 1))
2724         (when (and date (not (string= date "")))
2725           (goto-char (point-min))
2726           (let ((buffer-read-only nil))
2727             ;; Delete any old Date headers.
2728             (while (re-search-forward date-regexp nil t)
2729               (if pos
2730                   (delete-region (progn (beginning-of-line) (point))
2731                                  (progn (gnus-article-forward-header)
2732                                         (point)))
2733                 (delete-region (progn (beginning-of-line) (point))
2734                                  (progn (gnus-article-forward-header)
2735                                         (forward-char -1)
2736                                         (point)))
2737                 (setq pos (point))))
2738             (when (and (not pos)
2739                        (re-search-forward tdate-regexp nil t))
2740               (forward-line 1))
2741             (when pos
2742               (goto-char pos))
2743             (insert (article-make-date-line date (or type 'ut)))
2744             (unless pos
2745               (insert "\n")
2746               (forward-line -1))
2747             ;; Do highlighting.
2748             (beginning-of-line)
2749             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2750               (put-text-property (match-beginning 1) (1+ (match-end 1))
2751                                  'original-date date)
2752               (put-text-property (match-beginning 1) (1+ (match-end 1))
2753                                  'face bface)
2754               (put-text-property (match-beginning 2) (match-end 2)
2755                                  'face eface))))))))
2756
2757 (defun article-make-date-line (date type)
2758   "Return a DATE line of TYPE."
2759   (unless (memq type '(local ut original user iso8601 lapsed english))
2760     (error "Unknown conversion type: %s" type))
2761   (condition-case ()
2762       (let ((time (date-to-time date)))
2763         (cond
2764          ;; Convert to the local timezone.
2765          ((eq type 'local)
2766           (let ((tz (car (current-time-zone time))))
2767             (format "Date: %s %s%02d%02d" (current-time-string time)
2768                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2769                     (/ (% (abs tz) 3600) 60))))
2770          ;; Convert to Universal Time.
2771          ((eq type 'ut)
2772           (concat "Date: "
2773                   (current-time-string
2774                    (let* ((e (parse-time-string date))
2775                           (tm (apply 'encode-time e))
2776                           (ms (car tm))
2777                           (ls (- (cadr tm) (car (current-time-zone time)))))
2778                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2779                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2780                            (t (list ms ls)))))
2781                   " UT"))
2782          ;; Get the original date from the article.
2783          ((eq type 'original)
2784           (concat "Date: " (if (string-match "\n+$" date)
2785                                (substring date 0 (match-beginning 0))
2786                              date)))
2787          ;; Let the user define the format.
2788          ((eq type 'user)
2789           (let ((format (or (condition-case nil
2790                                 (with-current-buffer gnus-summary-buffer
2791                                   gnus-article-time-format)
2792                               (error nil))
2793                             gnus-article-time-format)))
2794             (if (functionp format)
2795                 (funcall format time)
2796               (concat "Date: " (format-time-string format time)))))
2797          ;; ISO 8601.
2798          ((eq type 'iso8601)
2799           (let ((tz (car (current-time-zone time))))
2800             (concat
2801              "Date: "
2802              (format-time-string "%Y%m%dT%H%M%S" time)
2803              (format "%s%02d%02d"
2804                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2805                      (/ (% (abs tz) 3600) 60)))))
2806          ;; Do an X-Sent lapsed format.
2807          ((eq type 'lapsed)
2808           ;; If the date is seriously mangled, the timezone functions are
2809           ;; liable to bug out, so we ignore all errors.
2810           (let* ((now (current-time))
2811                  (real-time (subtract-time now time))
2812                  (real-sec (and real-time
2813                                 (+ (* (float (car real-time)) 65536)
2814                                    (cadr real-time))))
2815                  (sec (and real-time (abs real-sec)))
2816                  num prev)
2817             (cond
2818              ((null real-time)
2819               "X-Sent: Unknown")
2820              ((zerop sec)
2821               "X-Sent: Now")
2822              (t
2823               (concat
2824                "X-Sent: "
2825                ;; This is a bit convoluted, but basically we go
2826                ;; through the time units for years, weeks, etc,
2827                ;; and divide things to see whether that results
2828                ;; in positive answers.
2829                (mapconcat
2830                 (lambda (unit)
2831                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2832                       ;; The (remaining) seconds are too few to
2833                       ;; be divided into this time unit.
2834                       ""
2835                     ;; It's big enough, so we output it.
2836                     (setq sec (- sec (* num (cdr unit))))
2837                     (prog1
2838                         (concat (if prev ", " "") (int-to-string
2839                                                    (floor num))
2840                                 " " (symbol-name (car unit))
2841                                 (if (> num 1) "s" ""))
2842                       (setq prev t))))
2843                 article-time-units "")
2844                ;; If dates are odd, then it might appear like the
2845                ;; article was sent in the future.
2846                (if (> real-sec 0)
2847                    " ago"
2848                  " in the future"))))))
2849          ;; Display the date in proper English
2850          ((eq type 'english)
2851           (let ((dtime (decode-time time)))
2852             (concat
2853              "Date: the "
2854              (number-to-string (nth 3 dtime))
2855              (let ((digit (% (nth 3 dtime) 10)))
2856                (cond
2857                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2858                 ((= digit 1) "st")
2859                 ((= digit 2) "nd")
2860                 ((= digit 3) "rd")
2861                 (t "th")))
2862              " of "
2863              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2864              " "
2865              (number-to-string (nth 5 dtime))
2866              " at "
2867              (format "%02d" (nth 2 dtime))
2868              ":"
2869              (format "%02d" (nth 1 dtime)))))))
2870     (error
2871      (format "Date: %s (from Gnus)" date))))
2872
2873 (defun article-date-local (&optional highlight)
2874   "Convert the current article date to the local timezone."
2875   (interactive (list t))
2876   (article-date-ut 'local highlight))
2877
2878 (defun article-date-english (&optional highlight)
2879   "Convert the current article date to something that is proper English."
2880   (interactive (list t))
2881   (article-date-ut 'english highlight))
2882
2883 (defun article-date-original (&optional highlight)
2884   "Convert the current article date to what it was originally.
2885 This is only useful if you have used some other date conversion
2886 function and want to see what the date was before converting."
2887   (interactive (list t))
2888   (article-date-ut 'original highlight))
2889
2890 (defun article-date-lapsed (&optional highlight)
2891   "Convert the current article date to time lapsed since it was sent."
2892   (interactive (list t))
2893   (article-date-ut 'lapsed highlight))
2894
2895 (defun article-update-date-lapsed ()
2896   "Function to be run from a timer to update the lapsed time line."
2897   (let (deactivate-mark)
2898     (save-excursion
2899       (ignore-errors
2900         (walk-windows
2901          (lambda (w)
2902            (set-buffer (window-buffer w))
2903            (when (eq major-mode 'gnus-article-mode)
2904              (goto-char (point-min))
2905              (when (re-search-forward "^X-Sent:" nil t)
2906                (article-date-lapsed t))))
2907          nil 'visible)))))
2908
2909 (defun gnus-start-date-timer (&optional n)
2910   "Start a timer to update the X-Sent header in the article buffers.
2911 The numerical prefix says how frequently (in seconds) the function
2912 is to run."
2913   (interactive "p")
2914   (unless n
2915     (setq n 1))
2916   (gnus-stop-date-timer)
2917   (setq article-lapsed-timer
2918         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2919
2920 (defun gnus-stop-date-timer ()
2921   "Stop the X-Sent timer."
2922   (interactive)
2923   (when article-lapsed-timer
2924     (nnheader-cancel-timer article-lapsed-timer)
2925     (setq article-lapsed-timer nil)))
2926
2927 (defun article-date-user (&optional highlight)
2928   "Convert the current article date to the user-defined format.
2929 This format is defined by the `gnus-article-time-format' variable."
2930   (interactive (list t))
2931   (article-date-ut 'user highlight))
2932
2933 (defun article-date-iso8601 (&optional highlight)
2934   "Convert the current article date to ISO8601."
2935   (interactive (list t))
2936   (article-date-ut 'iso8601 highlight))
2937
2938 ;; (defun article-show-all ()
2939 ;;   "Show all hidden text in the article buffer."
2940 ;;   (interactive)
2941 ;;   (save-excursion
2942 ;;     (let ((buffer-read-only nil))
2943 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
2944
2945 (defun article-remove-leading-whitespace ()
2946   "Remove excessive whitespace from all headers."
2947   (interactive)
2948   (save-excursion
2949     (save-restriction
2950       (let ((buffer-read-only nil))
2951         (article-narrow-to-head)
2952         (goto-char (point-min))
2953         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2954           (delete-region (match-beginning 1) (match-end 1)))))))
2955
2956 (defun article-emphasize (&optional arg)
2957   "Emphasize text according to `gnus-emphasis-alist'."
2958   (interactive (gnus-article-hidden-arg))
2959   (unless (gnus-article-check-hidden-text 'emphasis arg)
2960     (save-excursion
2961       (let ((alist (or
2962                     (condition-case nil
2963                         (with-current-buffer gnus-summary-buffer
2964                           gnus-article-emphasis-alist)
2965                       (error))
2966                     gnus-emphasis-alist))
2967             (buffer-read-only nil)
2968             (props (append '(article-type emphasis)
2969                            gnus-hidden-properties))
2970             regexp elem beg invisible visible face)
2971         (article-goto-body)
2972         (setq beg (point))
2973         (while (setq elem (pop alist))
2974           (goto-char beg)
2975           (setq regexp (car elem)
2976                 invisible (nth 1 elem)
2977                 visible (nth 2 elem)
2978                 face (nth 3 elem))
2979           (while (re-search-forward regexp nil t)
2980             (when (and (match-beginning visible) (match-beginning invisible))
2981               (gnus-article-hide-text
2982                (match-beginning invisible) (match-end invisible) props)
2983               (gnus-article-unhide-text-type
2984                (match-beginning visible) (match-end visible) 'emphasis)
2985               (gnus-put-overlay-excluding-newlines
2986                (match-beginning visible) (match-end visible) 'face face)
2987               (gnus-add-wash-type 'emphasis)
2988               (goto-char (match-end invisible)))))))))
2989
2990 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2991   "Setup newsgroup emphasis alist."
2992   (unless gnus-article-emphasis-alist
2993     (let ((name (and gnus-newsgroup-name
2994                      (gnus-group-real-name gnus-newsgroup-name))))
2995       (make-local-variable 'gnus-article-emphasis-alist)
2996       (setq gnus-article-emphasis-alist
2997             (nconc
2998              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2999                (while (setq elem (pop alist))
3000                  (when (and name (string-match (car elem) name))
3001                    (setq alist nil
3002                          highlight (copy-sequence (cdr elem)))))
3003                highlight)
3004              (copy-sequence highlight-words)
3005              (if gnus-newsgroup-name
3006                  (copy-sequence (gnus-group-find-parameter
3007                                  gnus-newsgroup-name 'highlight-words t)))
3008              gnus-emphasis-alist)))))
3009
3010 (eval-when-compile
3011   (defvar gnus-summary-article-menu)
3012   (defvar gnus-summary-post-menu))
3013
3014 ;;; Saving functions.
3015
3016 (defun gnus-article-save (save-buffer file &optional num)
3017   "Save the currently selected article."
3018   (unless gnus-save-all-headers
3019     ;; Remove headers according to `gnus-saved-headers'.
3020     (let ((gnus-visible-headers
3021            (or gnus-saved-headers gnus-visible-headers))
3022           (gnus-article-buffer save-buffer))
3023       (save-excursion
3024         (set-buffer save-buffer)
3025         (article-hide-headers 1 t))))
3026   (save-window-excursion
3027     (if (not gnus-default-article-saver)
3028         (error "No default saver is defined")
3029       ;; !!! Magic!  The saving functions all save
3030       ;; `gnus-save-article-buffer' (or so they think), but we
3031       ;; bind that variable to our save-buffer.
3032       (set-buffer gnus-article-buffer)
3033       (let* ((gnus-save-article-buffer save-buffer)
3034              (filename
3035               (cond
3036                ((not gnus-prompt-before-saving) 'default)
3037                ((eq gnus-prompt-before-saving 'always) nil)
3038                (t file)))
3039              (gnus-number-of-articles-to-be-saved
3040               (when (eq gnus-prompt-before-saving t)
3041                 num)))                  ; Magic
3042         (set-buffer gnus-article-current-summary)
3043         (funcall gnus-default-article-saver filename)))))
3044
3045 (defun gnus-read-save-file-name (prompt &optional filename
3046                                         function group headers variable)
3047   (let ((default-name
3048           (funcall function group headers (symbol-value variable)))
3049         result)
3050     (setq result
3051           (expand-file-name
3052            (cond
3053             ((eq filename 'default)
3054              default-name)
3055             ((eq filename t)
3056              default-name)
3057             (filename filename)
3058             (t
3059              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3060                     (prompt
3061                      (format prompt
3062                              (if (and gnus-number-of-articles-to-be-saved
3063                                       (> gnus-number-of-articles-to-be-saved 1))
3064                                  (format "these %d articles"
3065                                          gnus-number-of-articles-to-be-saved)
3066                                "this article")))
3067                     (file
3068                      ;; Let the split methods have their say.
3069                      (cond
3070                       ;; No split name was found.
3071                       ((null split-name)
3072                        (read-file-name
3073                         (concat prompt " (default "
3074                                 (file-name-nondirectory default-name) ") ")
3075                         (file-name-directory default-name)
3076                         default-name))
3077                       ;; A single group name is returned.
3078                       ((stringp split-name)
3079                        (setq default-name
3080                              (funcall function split-name headers
3081                                       (symbol-value variable)))
3082                        (read-file-name
3083                         (concat prompt " (default "
3084                                 (file-name-nondirectory default-name) ") ")
3085                         (file-name-directory default-name)
3086                         default-name))
3087                       ;; A single split name was found
3088                       ((= 1 (length split-name))
3089                        (let* ((name (expand-file-name
3090                                      (car split-name)
3091                                      gnus-article-save-directory))
3092                               (dir (cond ((file-directory-p name)
3093                                           (file-name-as-directory name))
3094                                          ((file-exists-p name) name)
3095                                          (t gnus-article-save-directory))))
3096                          (read-file-name
3097                           (concat prompt " (default " name ") ")
3098                           dir name)))
3099                       ;; A list of splits was found.
3100                       (t
3101                        (setq split-name (nreverse split-name))
3102                        (let (result)
3103                          (let ((file-name-history
3104                                 (nconc split-name file-name-history)))
3105                            (setq result
3106                                  (expand-file-name
3107                                   (read-file-name
3108                                    (concat prompt " (`M-p' for defaults) ")
3109                                    gnus-article-save-directory
3110                                    (car split-name))
3111                                   gnus-article-save-directory)))
3112                          (car (push result file-name-history)))))))
3113                ;; Create the directory.
3114                (gnus-make-directory (file-name-directory file))
3115                ;; If we have read a directory, we append the default file name.
3116                (when (file-directory-p file)
3117                  (setq file (expand-file-name (file-name-nondirectory
3118                                                default-name)
3119                                               (file-name-as-directory file))))
3120                ;; Possibly translate some characters.
3121                (nnheader-translate-file-chars file))))))
3122     (gnus-make-directory (file-name-directory result))
3123     (set variable result)))
3124
3125 (defun gnus-article-archive-name (group)
3126   "Return the first instance of an \"Archive-name\" in the current buffer."
3127   (let ((case-fold-search t))
3128     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3129       (nnheader-concat gnus-article-save-directory
3130                        (match-string 1)))))
3131
3132 (defun gnus-article-nndoc-name (group)
3133   "If GROUP is an nndoc group, return the name of the parent group."
3134   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3135     (gnus-group-get-parameter group 'save-article-group)))
3136
3137 (defun gnus-summary-save-in-rmail (&optional filename)
3138   "Append this article to Rmail file.
3139 Optional argument FILENAME specifies file name.
3140 Directory to save to is default to `gnus-article-save-directory'."
3141   (setq filename (gnus-read-save-file-name
3142                   "Save %s in rmail file:" filename
3143                   gnus-rmail-save-name gnus-newsgroup-name
3144                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3145   (gnus-eval-in-buffer-window gnus-save-article-buffer
3146     (save-excursion
3147       (save-restriction
3148         (widen)
3149         (gnus-output-to-rmail filename))))
3150   filename)
3151
3152 (defun gnus-summary-save-in-mail (&optional filename)
3153   "Append this article to Unix mail file.
3154 Optional argument FILENAME specifies file name.
3155 Directory to save to is default to `gnus-article-save-directory'."
3156   (setq filename (gnus-read-save-file-name
3157                   "Save %s in Unix mail file:" filename
3158                   gnus-mail-save-name gnus-newsgroup-name
3159                   gnus-current-headers 'gnus-newsgroup-last-mail))
3160   (gnus-eval-in-buffer-window gnus-save-article-buffer
3161     (save-excursion
3162       (save-restriction
3163         (widen)
3164         (if (and (file-readable-p filename)
3165                  (file-regular-p filename)
3166                  (mail-file-babyl-p filename))
3167             (rmail-output-to-rmail-file filename t)
3168           (gnus-output-to-mail filename)))))
3169   filename)
3170
3171 (defun gnus-summary-save-in-file (&optional filename overwrite)
3172   "Append this article to file.
3173 Optional argument FILENAME specifies file name.
3174 Directory to save to is default to `gnus-article-save-directory'."
3175   (setq filename (gnus-read-save-file-name
3176                   "Save %s in file:" filename
3177                   gnus-file-save-name gnus-newsgroup-name
3178                   gnus-current-headers 'gnus-newsgroup-last-file))
3179   (gnus-eval-in-buffer-window gnus-save-article-buffer
3180     (save-excursion
3181       (save-restriction
3182         (widen)
3183         (when (and overwrite
3184                    (file-exists-p filename))
3185           (delete-file filename))
3186         (gnus-output-to-file filename))))
3187   filename)
3188
3189 (defun gnus-summary-write-to-file (&optional filename)
3190   "Write this article to a file, overwriting it if the file exists.
3191 Optional argument FILENAME specifies file name.
3192 The directory to save in defaults to `gnus-article-save-directory'."
3193   (gnus-summary-save-in-file nil t))
3194
3195 (defun gnus-summary-save-body-in-file (&optional filename)
3196   "Append this article body to a file.
3197 Optional argument FILENAME specifies file name.
3198 The directory to save in defaults to `gnus-article-save-directory'."
3199   (setq filename (gnus-read-save-file-name
3200                   "Save %s body in file:" filename
3201                   gnus-file-save-name gnus-newsgroup-name
3202                   gnus-current-headers 'gnus-newsgroup-last-file))
3203   (gnus-eval-in-buffer-window gnus-save-article-buffer
3204     (save-excursion
3205       (save-restriction
3206         (widen)
3207         (when (article-goto-body)
3208           (narrow-to-region (point) (point-max)))
3209         (gnus-output-to-file filename))))
3210   filename)
3211
3212 (defun gnus-summary-save-in-pipe (&optional command)
3213   "Pipe this article to subprocess."
3214   (setq command
3215         (cond ((and (eq command 'default)
3216                     gnus-last-shell-command)
3217                gnus-last-shell-command)
3218               ((stringp command)
3219                command)
3220               (t (read-string
3221                   (format
3222                    "Shell command on %s: "
3223                    (if (and gnus-number-of-articles-to-be-saved
3224                             (> gnus-number-of-articles-to-be-saved 1))
3225                        (format "these %d articles"
3226                                gnus-number-of-articles-to-be-saved)
3227                      "this article"))
3228                   gnus-last-shell-command))))
3229   (when (string-equal command "")
3230     (if gnus-last-shell-command
3231         (setq command gnus-last-shell-command)
3232       (error "A command is required")))
3233   (gnus-eval-in-buffer-window gnus-article-buffer
3234     (save-restriction
3235       (widen)
3236       (shell-command-on-region (point-min) (point-max) command nil)))
3237   (setq gnus-last-shell-command command))
3238
3239 (defmacro gnus-read-string (prompt &optional initial-contents history
3240                             default-value)
3241   "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3242   (if (and (featurep 'xemacs)
3243            (< emacs-minor-version 2))
3244       `(read-string ,prompt ,initial-contents ,history)
3245     `(read-string ,prompt ,initial-contents ,history ,default-value)))
3246
3247 (defun gnus-summary-pipe-to-muttprint (&optional command)
3248   "Pipe this article to muttprint."
3249   (setq command (gnus-read-string
3250                  "Print using command: " gnus-summary-muttprint-program
3251                  nil gnus-summary-muttprint-program))
3252   (gnus-summary-save-in-pipe command))
3253
3254 ;;; Article file names when saving.
3255
3256 (defun gnus-capitalize-newsgroup (newsgroup)
3257   "Capitalize NEWSGROUP name."
3258   (when (not (zerop (length newsgroup)))
3259     (concat (char-to-string (upcase (aref newsgroup 0)))
3260             (substring newsgroup 1))))
3261
3262 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3263   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3264 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3265 Otherwise, it is like ~/News/news/group/num."
3266   (let ((default
3267           (expand-file-name
3268            (concat (if (gnus-use-long-file-name 'not-save)
3269                        (gnus-capitalize-newsgroup newsgroup)
3270                      (gnus-newsgroup-directory-form newsgroup))
3271                    "/" (int-to-string (mail-header-number headers)))
3272            gnus-article-save-directory)))
3273     (if (and last-file
3274              (string-equal (file-name-directory default)
3275                            (file-name-directory last-file))
3276              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3277         default
3278       (or last-file default))))
3279
3280 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3281   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3282 If variable `gnus-use-long-file-name' is non-nil, it is
3283 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3284   (let ((default
3285           (expand-file-name
3286            (concat (if (gnus-use-long-file-name 'not-save)
3287                        newsgroup
3288                      (gnus-newsgroup-directory-form newsgroup))
3289                    "/" (int-to-string (mail-header-number headers)))
3290            gnus-article-save-directory)))
3291     (if (and last-file
3292              (string-equal (file-name-directory default)
3293                            (file-name-directory last-file))
3294              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3295         default
3296       (or last-file default))))
3297
3298 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3299   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3300 If variable `gnus-use-long-file-name' is non-nil, it is
3301 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3302   (or last-file
3303       (expand-file-name
3304        (if (gnus-use-long-file-name 'not-save)
3305            newsgroup
3306          (file-relative-name
3307           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3308           default-directory))
3309        gnus-article-save-directory)))
3310
3311 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3312   "Generate file name from sender."
3313   (let ((from (mail-header-from headers)))
3314     (expand-file-name
3315      (if (and from (string-match "\\([^ <]+\\)@" from))
3316          (match-string 1 from)
3317        "nobody")
3318      gnus-article-save-directory)))
3319
3320 (defun article-verify-x-pgp-sig ()
3321   "Verify X-PGP-Sig."
3322   (interactive)
3323   (if (gnus-buffer-live-p gnus-original-article-buffer)
3324       (let ((sig (with-current-buffer gnus-original-article-buffer
3325                    (gnus-fetch-field "X-PGP-Sig")))
3326             items info headers)
3327         (when (and sig
3328                    mml2015-use
3329                    (mml2015-clear-verify-function))
3330           (with-temp-buffer
3331             (insert-buffer-substring gnus-original-article-buffer)
3332             (setq items (split-string sig))
3333             (message-narrow-to-head)
3334             (let ((inhibit-point-motion-hooks t)
3335                   (case-fold-search t))
3336               ;; Don't verify multiple headers.
3337               (setq headers (mapconcat (lambda (header)
3338                                          (concat header ": "
3339                                                  (mail-fetch-field header)
3340                                                  "\n"))
3341                                        (split-string (nth 1 items) ",") "")))
3342             (delete-region (point-min) (point-max))
3343             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3344             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3345             (insert headers)
3346             (widen)
3347             (forward-line)
3348             (while (not (eobp))
3349               (if (looking-at "^-")
3350                   (insert "- "))
3351               (forward-line))
3352             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3353             (insert "Version: " (car items) "\n\n")
3354             (insert (mapconcat 'identity (cddr items) "\n"))
3355             (insert "\n-----END PGP SIGNATURE-----\n")
3356             (let ((mm-security-handle (list (format "multipart/signed"))))
3357               (mml2015-clean-buffer)
3358               (let ((coding-system-for-write (or gnus-newsgroup-charset
3359                                                  'iso-8859-1)))
3360                 (funcall (mml2015-clear-verify-function)))
3361               (setq info
3362                     (or (mm-handle-multipart-ctl-parameter
3363                          mm-security-handle 'gnus-details)
3364                         (mm-handle-multipart-ctl-parameter
3365                          mm-security-handle 'gnus-info)))))
3366           (when info
3367             (let (buffer-read-only bface eface)
3368               (save-restriction
3369                 (message-narrow-to-head)
3370                 (goto-char (point-max))
3371                 (forward-line -1)
3372                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3373                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3374                 (message-remove-header "X-Gnus-PGP-Verify")
3375                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3376                     (forward-line)
3377                   (goto-char (point-max)))
3378                 (narrow-to-region (point) (point))
3379                 (insert "X-Gnus-PGP-Verify: " info "\n")
3380                 (goto-char (point-min))
3381                 (forward-line)
3382                 (while (not (eobp))
3383                   (if (not (looking-at "^[ \t]"))
3384                       (insert " "))
3385                   (forward-line))
3386                 ;; Do highlighting.
3387                 (goto-char (point-min))
3388                 (when (looking-at "\\([^:]+\\): *")
3389                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3390                                      'face bface)
3391                   (put-text-property (match-end 0) (point-max)
3392                                      'face eface)))))))))
3393
3394 (defun article-verify-cancel-lock ()
3395   "Verify Cancel-Lock header."
3396   (interactive)
3397   (if (gnus-buffer-live-p gnus-original-article-buffer)
3398       (canlock-verify gnus-original-article-buffer)))
3399
3400 (eval-and-compile
3401   (mapcar
3402    (lambda (func)
3403      (let (afunc gfunc)
3404        (if (consp func)
3405            (setq afunc (car func)
3406                  gfunc (cdr func))
3407          (setq afunc func
3408                gfunc (intern (format "gnus-%s" func))))
3409        (defalias gfunc
3410          (when (fboundp afunc)
3411            `(lambda (&optional interactive &rest args)
3412               ,(documentation afunc t)
3413               (interactive (list t))
3414               (save-excursion
3415                 (set-buffer gnus-article-buffer)
3416                 (if interactive
3417                     (call-interactively ',afunc)
3418                   (apply ',afunc args))))))))
3419    '(article-hide-headers
3420      article-verify-x-pgp-sig
3421      article-verify-cancel-lock
3422      article-hide-boring-headers
3423      article-treat-overstrike
3424      article-fill-long-lines
3425      article-capitalize-sentences
3426      article-remove-cr
3427      article-remove-leading-whitespace
3428      article-display-x-face
3429      article-display-face
3430      article-de-quoted-unreadable
3431      article-de-base64-unreadable
3432      article-decode-HZ
3433      article-wash-html
3434      article-unsplit-urls
3435      article-hide-list-identifiers
3436      article-strip-banner
3437      article-babel
3438      article-hide-pem
3439      article-hide-signature
3440      article-strip-headers-in-body
3441      article-remove-trailing-blank-lines
3442      article-strip-leading-blank-lines
3443      article-strip-multiple-blank-lines
3444      article-strip-leading-space
3445      article-strip-trailing-space
3446      article-strip-blank-lines
3447      article-strip-all-blank-lines
3448      article-date-local
3449      article-date-english
3450      article-date-iso8601
3451      article-date-original
3452      article-date-ut
3453      article-decode-mime-words
3454      article-decode-charset
3455      article-decode-encoded-words
3456      article-date-user
3457      article-date-lapsed
3458      article-emphasize
3459      article-treat-dumbquotes
3460      article-normalize-headers
3461 ;;     (article-show-all . gnus-article-show-all-headers)
3462      )))
3463 \f
3464 ;;;
3465 ;;; Gnus article mode
3466 ;;;
3467
3468 (put 'gnus-article-mode 'mode-class 'special)
3469
3470 (set-keymap-parent gnus-article-mode-map widget-keymap)
3471
3472 (gnus-define-keys gnus-article-mode-map
3473   " " gnus-article-goto-next-page
3474   "\177" gnus-article-goto-prev-page
3475   [delete] gnus-article-goto-prev-page
3476   [backspace] gnus-article-goto-prev-page
3477   "\C-c^" gnus-article-refer-article
3478   "h" gnus-article-show-summary
3479   "s" gnus-article-show-summary
3480   "\C-c\C-m" gnus-article-mail
3481   "?" gnus-article-describe-briefly
3482   "e" gnus-summary-edit-article
3483   "<" beginning-of-buffer
3484   ">" end-of-buffer
3485   "\C-c\C-i" gnus-info-find-node
3486   "\C-c\C-b" gnus-bug
3487   "R" gnus-article-reply-with-original
3488   "F" gnus-article-followup-with-original
3489   "\C-hk" gnus-article-describe-key
3490   "\C-hc" gnus-article-describe-key-briefly
3491
3492   "\C-d" gnus-article-read-summary-keys
3493   "\M-*" gnus-article-read-summary-keys
3494   "\M-#" gnus-article-read-summary-keys
3495   "\M-^" gnus-article-read-summary-keys
3496   "\M-g" gnus-article-read-summary-keys)
3497
3498 (substitute-key-definition
3499  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3500
3501 (defun gnus-article-make-menu-bar ()
3502   (unless (boundp 'gnus-article-commands-menu)
3503     (gnus-summary-make-menu-bar))
3504   (gnus-turn-off-edit-menu 'article)
3505   (unless (boundp 'gnus-article-article-menu)
3506     (easy-menu-define
3507      gnus-article-article-menu gnus-article-mode-map ""
3508      '("Article"
3509        ["Scroll forwards" gnus-article-goto-next-page t]
3510        ["Scroll backwards" gnus-article-goto-prev-page t]
3511        ["Show summary" gnus-article-show-summary t]
3512        ["Fetch Message-ID at point" gnus-article-refer-article t]
3513        ["Mail to address at point" gnus-article-mail t]
3514        ["Send a bug report" gnus-bug t]))
3515
3516     (easy-menu-define
3517      gnus-article-treatment-menu gnus-article-mode-map ""
3518      ;; Fixme: this should use :active (and maybe :visible).
3519      '("Treatment"
3520        ["Hide headers" gnus-article-hide-headers t]
3521        ["Hide signature" gnus-article-hide-signature t]
3522        ["Hide citation" gnus-article-hide-citation t]
3523        ["Treat overstrike" gnus-article-treat-overstrike t]
3524        ["Remove carriage return" gnus-article-remove-cr t]
3525        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3526        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3527        ["Remove base64" gnus-article-de-base64-unreadable t]
3528        ["Treat html" gnus-article-wash-html t]
3529        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3530        ["Decode HZ" gnus-article-decode-HZ t]))
3531
3532     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3533
3534     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3535
3536     (gnus-run-hooks 'gnus-article-menu-hook)))
3537
3538 (defun gnus-article-mode ()
3539   "Major mode for displaying an article.
3540
3541 All normal editing commands are switched off.
3542
3543 The following commands are available in addition to all summary mode
3544 commands:
3545 \\<gnus-article-mode-map>
3546 \\[gnus-article-next-page]\t Scroll the article one page forwards
3547 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3548 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3549 \\[gnus-article-show-summary]\t Display the summary buffer
3550 \\[gnus-article-mail]\t Send a reply to the address near point
3551 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3552 \\[gnus-info-find-node]\t Go to the Gnus info node"
3553   (interactive)
3554   (gnus-simplify-mode-line)
3555   (setq mode-name "Article")
3556   (setq major-mode 'gnus-article-mode)
3557   (make-local-variable 'minor-mode-alist)
3558   (use-local-map gnus-article-mode-map)
3559   (when (gnus-visual-p 'article-menu 'menu)
3560     (gnus-article-make-menu-bar)
3561     (when gnus-summary-tool-bar-map
3562       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3563   (gnus-update-format-specifications nil 'article-mode)
3564   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3565   (make-local-variable 'gnus-page-broken)
3566   (make-local-variable 'gnus-button-marker-list)
3567   (make-local-variable 'gnus-article-current-summary)
3568   (make-local-variable 'gnus-article-mime-handles)
3569   (make-local-variable 'gnus-article-decoded-p)
3570   (make-local-variable 'gnus-article-mime-handle-alist)
3571   (make-local-variable 'gnus-article-wash-types)
3572   (make-local-variable 'gnus-article-image-alist)
3573   (make-local-variable 'gnus-article-charset)
3574   (make-local-variable 'gnus-article-ignored-charsets)
3575   (gnus-set-default-directory)
3576   (buffer-disable-undo)
3577   (setq buffer-read-only t)
3578   (set-syntax-table gnus-article-mode-syntax-table)
3579   (mm-enable-multibyte)
3580   (gnus-run-hooks 'gnus-article-mode-hook))
3581
3582 (defun gnus-article-setup-buffer ()
3583   "Initialize the article buffer."
3584   (let* ((name (if gnus-single-article-buffer "*Article*"
3585                  (concat "*Article " gnus-newsgroup-name "*")))
3586          (original
3587           (progn (string-match "\\*Article" name)
3588                  (concat " *Original Article"
3589                          (substring name (match-end 0))))))
3590     (setq gnus-article-buffer name)
3591     (setq gnus-original-article-buffer original)
3592     (setq gnus-article-mime-handle-alist nil)
3593     ;; This might be a variable local to the summary buffer.
3594     (unless gnus-single-article-buffer
3595       (save-excursion
3596         (set-buffer gnus-summary-buffer)
3597         (setq gnus-article-buffer name)
3598         (setq gnus-original-article-buffer original)
3599         (gnus-set-global-variables)))
3600     (gnus-article-setup-highlight-words)
3601     ;; Init original article buffer.
3602     (save-excursion
3603       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3604       (mm-enable-multibyte)
3605       (setq major-mode 'gnus-original-article-mode)
3606       (make-local-variable 'gnus-original-article))
3607     (if (get-buffer name)
3608         (save-excursion
3609           (set-buffer name)
3610           (when (and gnus-article-edit-mode
3611                      (buffer-modified-p)
3612                      (not
3613                       (y-or-n-p "Article mode edit in progress; discard? ")))
3614             (error "Action aborted"))
3615           (set (make-local-variable 'gnus-article-edit-mode) nil)
3616           (when gnus-article-mime-handles
3617             (mm-destroy-parts gnus-article-mime-handles)
3618             (setq gnus-article-mime-handles nil))
3619           ;; Set it to nil in article-buffer!
3620           (setq gnus-article-mime-handle-alist nil)
3621           (buffer-disable-undo)
3622           (setq buffer-read-only t)
3623           ;; This list just keeps growing if we don't reset it.
3624           (setq gnus-button-marker-list nil)
3625           (unless (eq major-mode 'gnus-article-mode)
3626             (gnus-article-mode))
3627           (current-buffer))
3628       (save-excursion
3629         (set-buffer (gnus-get-buffer-create name))
3630         (gnus-article-mode)
3631         (make-local-variable 'gnus-summary-buffer)
3632         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3633         (current-buffer)))))
3634
3635 ;; Set article window start at LINE, where LINE is the number of lines
3636 ;; from the head of the article.
3637 (defun gnus-article-set-window-start (&optional line)
3638   (set-window-start
3639    (gnus-get-buffer-window gnus-article-buffer t)
3640    (save-excursion
3641      (set-buffer gnus-article-buffer)
3642      (goto-char (point-min))
3643      (if (not line)
3644          (point-min)
3645        (gnus-message 6 "Moved to bookmark")
3646        (search-forward "\n\n" nil t)
3647        (forward-line line)
3648        (point)))))
3649
3650 (defun gnus-article-prepare (article &optional all-headers header)
3651   "Prepare ARTICLE in article mode buffer.
3652 ARTICLE should either be an article number or a Message-ID.
3653 If ARTICLE is an id, HEADER should be the article headers.
3654 If ALL-HEADERS is non-nil, no headers are hidden."
3655   (save-excursion
3656     ;; Make sure we start in a summary buffer.
3657     (unless (eq major-mode 'gnus-summary-mode)
3658       (set-buffer gnus-summary-buffer))
3659     (setq gnus-summary-buffer (current-buffer))
3660     (let* ((gnus-article (if header (mail-header-number header) article))
3661            (summary-buffer (current-buffer))
3662            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3663            (group gnus-newsgroup-name)
3664            result)
3665       (save-excursion
3666         (gnus-article-setup-buffer)
3667         (set-buffer gnus-article-buffer)
3668         ;; Deactivate active regions.
3669         (when (and (boundp 'transient-mark-mode)
3670                    transient-mark-mode)
3671           (setq mark-active nil))
3672         (if (not (setq result (let ((buffer-read-only nil))
3673                                 (gnus-request-article-this-buffer
3674                                  article group))))
3675             ;; There is no such article.
3676             (save-excursion
3677               (when (and (numberp article)
3678                          (not (memq article gnus-newsgroup-sparse)))
3679                 (setq gnus-article-current
3680                       (cons gnus-newsgroup-name article))
3681                 (set-buffer gnus-summary-buffer)
3682                 (setq gnus-current-article article)
3683                 (if (and (memq article gnus-newsgroup-undownloaded)
3684                          (not (gnus-online (gnus-find-method-for-group
3685                                             gnus-newsgroup-name))))
3686                     (progn
3687                       (gnus-summary-set-agent-mark article)
3688                       (message "Message marked for downloading"))
3689                   (gnus-summary-mark-article article gnus-canceled-mark)
3690                   (unless (memq article gnus-newsgroup-sparse)
3691                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3692           (if (or (eq result 'pseudo)
3693                   (eq result 'nneething))
3694               (progn
3695                 (save-excursion
3696                   (set-buffer summary-buffer)
3697                   (push article gnus-newsgroup-history)
3698                   (setq gnus-last-article gnus-current-article
3699                         gnus-current-article 0
3700                         gnus-current-headers nil
3701                         gnus-article-current nil)
3702                   (if (eq result 'nneething)
3703                       (gnus-configure-windows 'summary)
3704                     (gnus-configure-windows 'article))
3705                   (gnus-set-global-variables))
3706                 (let ((gnus-article-mime-handle-alist-1
3707                        gnus-article-mime-handle-alist))
3708                   (gnus-set-mode-line 'article)))
3709             ;; The result from the `request' was an actual article -
3710             ;; or at least some text that is now displayed in the
3711             ;; article buffer.
3712             (when (and (numberp article)
3713                        (not (eq article gnus-current-article)))
3714               ;; Seems like a new article has been selected.
3715               ;; `gnus-current-article' must be an article number.
3716               (save-excursion
3717                 (set-buffer summary-buffer)
3718                 (push article gnus-newsgroup-history)
3719                 (setq gnus-last-article gnus-current-article
3720                       gnus-current-article article
3721                       gnus-current-headers
3722                       (gnus-summary-article-header gnus-current-article)
3723                       gnus-article-current
3724                       (cons gnus-newsgroup-name gnus-current-article))
3725                 (unless (vectorp gnus-current-headers)
3726                   (setq gnus-current-headers nil))
3727                 (gnus-summary-goto-subject gnus-current-article)
3728                 (when (gnus-summary-show-thread)
3729                   ;; If the summary buffer really was folded, the
3730                   ;; previous goto may not actually have gone to
3731                   ;; the right article, but the thread root instead.
3732                   ;; So we go again.
3733                   (gnus-summary-goto-subject gnus-current-article))
3734                 (gnus-run-hooks 'gnus-mark-article-hook)
3735                 (gnus-set-mode-line 'summary)
3736                 (when (gnus-visual-p 'article-highlight 'highlight)
3737                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3738                 ;; Set the global newsgroup variables here.
3739                 (gnus-set-global-variables)
3740                 (setq gnus-have-all-headers
3741                       (or all-headers gnus-show-all-headers))))
3742             (save-excursion
3743               (gnus-configure-windows 'article))
3744             (when (or (numberp article)
3745                       (stringp article))
3746               (gnus-article-prepare-display)
3747               ;; Do page break.
3748               (goto-char (point-min))
3749               (setq gnus-page-broken
3750                     (when gnus-break-pages
3751                       (gnus-narrow-to-page)
3752                       t)))
3753             (let ((gnus-article-mime-handle-alist-1
3754                    gnus-article-mime-handle-alist))
3755               (gnus-set-mode-line 'article))
3756             (article-goto-body)
3757             (unless (bobp)
3758               (forward-line -1))
3759             (set-window-point (get-buffer-window (current-buffer)) (point))
3760             (gnus-configure-windows 'article)
3761             t))))))
3762
3763 ;;;###autoload
3764 (defun gnus-article-prepare-display ()
3765   "Make the current buffer look like a nice article."
3766   ;; Hooks for getting information from the article.
3767   ;; This hook must be called before being narrowed.
3768   (let ((gnus-article-buffer (current-buffer))
3769         buffer-read-only)
3770     (unless (eq major-mode 'gnus-article-mode)
3771       (gnus-article-mode))
3772     (setq buffer-read-only nil
3773           gnus-article-wash-types nil
3774           gnus-article-image-alist nil)
3775     (gnus-run-hooks 'gnus-tmp-internal-hook)
3776     (when gnus-display-mime-function
3777       (funcall gnus-display-mime-function))
3778     (gnus-run-hooks 'gnus-article-prepare-hook)))
3779
3780 ;;;
3781 ;;; Gnus MIME viewing functions
3782 ;;;
3783
3784 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3785   "Format of the MIME buttons.
3786
3787 Valid specifiers include:
3788 %t  The MIME type
3789 %T  MIME type, along with additional info
3790 %n  The `name' parameter
3791 %d  The description, if any
3792 %l  The length of the encoded part
3793 %p  The part identifier number
3794 %e  Dots if the part isn't displayed
3795
3796 General format specifiers can also be used.  See Info node
3797 `(gnus)Formatting Variables'.")
3798
3799 (defvar gnus-mime-button-line-format-alist
3800   '((?t gnus-tmp-type ?s)
3801     (?T gnus-tmp-type-long ?s)
3802     (?n gnus-tmp-name ?s)
3803     (?d gnus-tmp-description ?s)
3804     (?p gnus-tmp-id ?s)
3805     (?l gnus-tmp-length ?d)
3806     (?e gnus-tmp-dots ?s)))
3807
3808 (defvar gnus-mime-button-commands
3809   '((gnus-article-press-button "\r" "Toggle Display")
3810     (gnus-mime-view-part "v" "View Interactively...")
3811     (gnus-mime-view-part-as-type "t" "View As Type...")
3812     (gnus-mime-view-part-as-charset "C" "View As charset...")
3813     (gnus-mime-save-part "o" "Save...")
3814     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3815     (gnus-mime-delete-part "d" "Delete part")
3816     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3817     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3818     (gnus-mime-view-part-internally "E" "View Internally")
3819     (gnus-mime-view-part-externally "e" "View Externally")
3820     (gnus-mime-print-part "p" "Print")
3821     (gnus-mime-pipe-part "|" "Pipe To Command...")
3822     (gnus-mime-action-on-part "." "Take action on the part...")))
3823
3824 (defun gnus-article-mime-part-status ()
3825   (if gnus-article-mime-handle-alist-1
3826       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3827           " (1 part)"
3828         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3829     ""))
3830
3831 (defvar gnus-mime-button-map
3832   (let ((map (make-sparse-keymap)))
3833     (unless (>= (string-to-number emacs-version) 21)
3834       ;; XEmacs doesn't care.
3835       (set-keymap-parent map gnus-article-mode-map))
3836     (define-key map gnus-mouse-2 'gnus-article-push-button)
3837     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3838     (dolist (c gnus-mime-button-commands)
3839       (define-key map (cadr c) (car c)))
3840     map))
3841
3842 (easy-menu-define
3843   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
3844   `("MIME Part"
3845     ,@(mapcar (lambda (c)
3846                 (vector (caddr c) (car c) :enable t))
3847               gnus-mime-button-commands)))
3848
3849 (eval-when-compile
3850   (define-compiler-macro popup-menu (&whole form
3851                                             menu &optional position prefix)
3852     (if (and (fboundp 'popup-menu)
3853              (not (memq 'popup-menu (assoc "lmenu" load-history))))
3854         form
3855       ;; Gnus is probably running under Emacs 20.
3856       `(let* ((menu (cdr ,menu))
3857               (response (x-popup-menu
3858                          t (list (car menu)
3859                                  (cons "" (mapcar (lambda (c)
3860                                                     (cons (caddr c) (car c)))
3861                                                   (cdr menu)))))))
3862          (if response
3863              (call-interactively (nth 3 (assq response menu))))))))
3864
3865 (defun gnus-mime-button-menu (event prefix)
3866  "Construct a context-sensitive menu of MIME commands."
3867  (interactive "e\nP")
3868  (save-window-excursion
3869    (let ((pos (event-start event)))
3870      (select-window (posn-window pos))
3871      (goto-char (posn-point pos))
3872      (gnus-article-check-buffer)
3873      (popup-menu gnus-mime-button-menu nil prefix))))
3874
3875 (defun gnus-mime-view-all-parts (&optional handles)
3876   "View all the MIME parts."
3877   (interactive)
3878   (save-current-buffer
3879     (set-buffer gnus-article-buffer)
3880     (let ((handles (or handles gnus-article-mime-handles))
3881           (mail-parse-charset gnus-newsgroup-charset)
3882           (mail-parse-ignored-charsets
3883            (with-current-buffer gnus-summary-buffer
3884              gnus-newsgroup-ignored-charsets)))
3885       (when handles
3886         (mm-remove-parts handles)
3887         (goto-char (point-min))
3888         (or (search-forward "\n\n") (goto-char (point-max)))
3889         (let (buffer-read-only)
3890           (delete-region (point) (point-max))
3891           (mm-display-parts handles))))))
3892
3893 (defun gnus-mime-save-part-and-strip ()
3894   "Save the MIME part under point then replace it with an external body."
3895   (interactive)
3896   (gnus-article-check-buffer)
3897   (let* ((data (get-text-property (point) 'gnus-data))
3898          file param
3899          (handles gnus-article-mime-handles))
3900     (if (mm-multiple-handles gnus-article-mime-handles)
3901         (error "This function is not implemented"))
3902     (setq file (and data (mm-save-part data)))
3903     (when file
3904       (with-current-buffer (mm-handle-buffer data)
3905         (erase-buffer)
3906         (insert "Content-Type: " (mm-handle-media-type data))
3907         (mml-insert-parameter-string (cdr (mm-handle-type data))
3908                                      '(charset))
3909         (insert "\n")
3910         (insert "Content-ID: " (message-make-message-id) "\n")
3911         (insert "Content-Transfer-Encoding: binary\n")
3912         (insert "\n"))
3913       (setcdr data
3914               (cdr (mm-make-handle nil
3915                                    `("message/external-body"
3916                                      (access-type . "LOCAL-FILE")
3917                                      (name . ,file)))))
3918       (set-buffer gnus-summary-buffer)
3919       (gnus-article-edit-article
3920        `(lambda ()
3921            (erase-buffer)
3922            (let ((mail-parse-charset (or gnus-article-charset
3923                                          ',gnus-newsgroup-charset))
3924                  (mail-parse-ignored-charsets
3925                   (or gnus-article-ignored-charsets
3926                       ',gnus-newsgroup-ignored-charsets))
3927                  (mbl mml-buffer-list))
3928              (setq mml-buffer-list nil)
3929              (insert-buffer gnus-original-article-buffer)
3930              (mime-to-mml ',handles)
3931              (setq gnus-article-mime-handles nil)
3932              (let ((mbl1 mml-buffer-list))
3933                (setq mml-buffer-list mbl)
3934                (set (make-local-variable 'mml-buffer-list) mbl1))
3935              (gnus-make-local-hook 'kill-buffer-hook)
3936              (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3937        `(lambda (no-highlight)
3938           (let ((mail-parse-charset (or gnus-article-charset
3939                                         ',gnus-newsgroup-charset))
3940                 (message-options message-options)
3941                 (message-options-set-recipient)
3942                 (mail-parse-ignored-charsets
3943                  (or gnus-article-ignored-charsets
3944                      ',gnus-newsgroup-ignored-charsets)))
3945            (mml-to-mime)
3946            (mml-destroy-buffers)
3947            (remove-hook 'kill-buffer-hook
3948                         'mml-destroy-buffers t)
3949            (kill-local-variable 'mml-buffer-list))
3950           (gnus-summary-edit-article-done
3951            ,(or (mail-header-references gnus-current-headers) "")
3952            ,(gnus-group-read-only-p)
3953            ,gnus-summary-buffer no-highlight))))))
3954
3955 (defun gnus-mime-delete-part ()
3956   "Delete the MIME part under point.
3957 Replace it with some information about the removed part."
3958   (interactive)
3959   (gnus-article-check-buffer)
3960   (unless (and gnus-novice-user
3961                (not (gnus-yes-or-no-p
3962                      "Really delete attachment forever? ")))
3963     (let* ((data (get-text-property (point) 'gnus-data))
3964            (handles gnus-article-mime-handles)
3965            (none "(none)")
3966            (description
3967             (or
3968              (mail-decode-encoded-word-string (or (mm-handle-description data)
3969                                                   none))))
3970            (filename
3971             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
3972                 none))
3973            (type (mm-handle-media-type data)))
3974       (if (mm-multiple-handles gnus-article-mime-handles)
3975           (error "This function is not implemented"))
3976       (with-current-buffer (mm-handle-buffer data)
3977         (let ((bsize (format "%s" (buffer-size))))
3978           (erase-buffer)
3979           (insert
3980            (concat
3981             "<#part type=text/plain nofile=yes disposition=attachment"
3982             " description=\"Deleted attachment (" bsize " Byte)\">"
3983             ",----\n"
3984             "| The following attachment has been deleted:\n"
3985             "|\n"
3986             "| Type:           " type "\n"
3987             "| Filename:       " filename "\n"
3988             "| Size (encoded): " bsize " Byte\n"
3989             "| Description:    " description "\n"
3990             "`----\n"
3991             "<#/part>"))
3992           (setcdr data
3993                   (cdr (mm-make-handle nil `("text/plain"))))))
3994       (set-buffer gnus-summary-buffer)
3995       ;; FIXME: maybe some of the following code (borrowed from
3996       ;; `gnus-mime-save-part-and-strip') isn't necessary?
3997       (gnus-article-edit-article
3998        `(lambda ()
3999           (erase-buffer)
4000           (let ((mail-parse-charset (or gnus-article-charset
4001                                         ',gnus-newsgroup-charset))
4002                 (mail-parse-ignored-charsets
4003                  (or gnus-article-ignored-charsets
4004                      ',gnus-newsgroup-ignored-charsets))
4005                 (mbl mml-buffer-list))
4006             (setq mml-buffer-list nil)
4007             (insert-buffer gnus-original-article-buffer)
4008             (mime-to-mml ',handles)
4009             (setq gnus-article-mime-handles nil)
4010             (let ((mbl1 mml-buffer-list))
4011               (setq mml-buffer-list mbl)
4012               (set (make-local-variable 'mml-buffer-list) mbl1))
4013             (gnus-make-local-hook 'kill-buffer-hook)
4014             (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4015        `(lambda (no-highlight)
4016           (let ((mail-parse-charset (or gnus-article-charset
4017                                         ',gnus-newsgroup-charset))
4018                 (message-options message-options)
4019                 (message-options-set-recipient)
4020                 (mail-parse-ignored-charsets
4021                  (or gnus-article-ignored-charsets
4022                      ',gnus-newsgroup-ignored-charsets)))
4023             (mml-to-mime)
4024             (mml-destroy-buffers)
4025             (remove-hook 'kill-buffer-hook
4026                          'mml-destroy-buffers t)
4027             (kill-local-variable 'mml-buffer-list))
4028           (gnus-summary-edit-article-done
4029            ,(or (mail-header-references gnus-current-headers) "")
4030            ,(gnus-group-read-only-p)
4031            ,gnus-summary-buffer no-highlight)))))
4032   ;; Not in `gnus-mime-save-part-and-strip':
4033   (gnus-article-edit-done)
4034   (gnus-summary-expand-window)
4035   (gnus-summary-show-article))
4036
4037 (defun gnus-mime-save-part ()
4038   "Save the MIME part under point."
4039   (interactive)
4040   (gnus-article-check-buffer)
4041   (let ((data (get-text-property (point) 'gnus-data)))
4042     (when data
4043       (mm-save-part data))))
4044
4045 (defun gnus-mime-pipe-part ()
4046   "Pipe the MIME part under point to a process."
4047   (interactive)
4048   (gnus-article-check-buffer)
4049   (let ((data (get-text-property (point) 'gnus-data)))
4050     (when data
4051       (mm-pipe-part data))))
4052
4053 (defun gnus-mime-view-part ()
4054   "Interactively choose a viewing method for the MIME part under point."
4055   (interactive)
4056   (gnus-article-check-buffer)
4057   (let ((data (get-text-property (point) 'gnus-data)))
4058     (when data
4059       (setq gnus-article-mime-handles
4060             (mm-merge-handles
4061              gnus-article-mime-handles (setq data (copy-sequence data))))
4062       (mm-interactively-view-part data))))
4063
4064 (defun gnus-mime-view-part-as-type-internal ()
4065   (gnus-article-check-buffer)
4066   (let* ((name (mail-content-type-get
4067                 (mm-handle-type (get-text-property (point) 'gnus-data))
4068                 'name))
4069          (def-type (and name (mm-default-file-encoding name))))
4070     (and def-type (cons def-type 0))))
4071
4072 (defun gnus-mime-view-part-as-type (&optional mime-type)
4073   "Choose a MIME media type, and view the part as such."
4074   (interactive)
4075   (unless mime-type
4076     (setq mime-type (completing-read
4077                      "View as MIME type: "
4078                      (mapcar #'list (mailcap-mime-types))
4079                      nil nil
4080                      (gnus-mime-view-part-as-type-internal))))
4081   (gnus-article-check-buffer)
4082   (let ((handle (get-text-property (point) 'gnus-data)))
4083     (when handle
4084       (setq handle
4085             (mm-make-handle (mm-handle-buffer handle)
4086                             (cons mime-type (cdr (mm-handle-type handle)))
4087                             (mm-handle-encoding handle)
4088                             (mm-handle-undisplayer handle)
4089                             (mm-handle-disposition handle)
4090                             (mm-handle-description handle)
4091                             nil
4092                             (mm-handle-id handle)))
4093       (setq gnus-article-mime-handles
4094             (mm-merge-handles gnus-article-mime-handles handle))
4095       (gnus-mm-display-part handle))))
4096
4097 (eval-when-compile
4098   (require 'jka-compr))
4099
4100 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4101 ;; emacs can do that itself.
4102 ;;
4103 (defun gnus-mime-jka-compr-maybe-uncompress ()
4104   "Uncompress the current buffer if `auto-compression-mode' is enabled.
4105 The uncompress method used is derived from `buffer-file-name'."
4106   (when (and (fboundp 'jka-compr-installed-p)
4107              (jka-compr-installed-p))
4108     (let ((info (jka-compr-get-compression-info buffer-file-name)))
4109       (when info
4110         (let ((basename (file-name-nondirectory buffer-file-name))
4111               (args     (jka-compr-info-uncompress-args    info))
4112               (prog     (jka-compr-info-uncompress-program info))
4113               (message  (jka-compr-info-uncompress-message info))
4114               (err-file (jka-compr-make-temp-name)))
4115           (if message
4116               (message "%s %s..." message basename))
4117           (unwind-protect
4118               (unless (memq (apply 'call-process-region
4119                                    (point-min) (point-max)
4120                                    prog
4121                                    t (list t err-file) nil
4122                                    args)
4123                             jka-compr-acceptable-retval-list)
4124                 (jka-compr-error prog args basename message err-file))
4125             (jka-compr-delete-temp-file err-file)))))))
4126
4127 (defun gnus-mime-copy-part (&optional handle)
4128   "Put the MIME part under point into a new buffer.
4129 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4130 are decompressed."
4131   (interactive)
4132   (gnus-article-check-buffer)
4133   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4134          (contents (and handle (mm-get-part handle)))
4135          (base (and handle
4136                     (file-name-nondirectory
4137                      (or
4138                       (mail-content-type-get (mm-handle-type handle) 'name)
4139                       (mail-content-type-get (mm-handle-disposition handle)
4140                                              'filename)
4141                       "*decoded*"))))
4142          (buffer (and base (generate-new-buffer base))))
4143     (when contents
4144       (switch-to-buffer buffer)
4145       (insert contents)
4146       ;; We do it this way to make `normal-mode' set the appropriate mode.
4147       (unwind-protect
4148           (progn
4149             (setq buffer-file-name (expand-file-name base))
4150             (gnus-mime-jka-compr-maybe-uncompress)
4151             (normal-mode))
4152         (setq buffer-file-name nil))
4153       (goto-char (point-min)))))
4154
4155 (defun gnus-mime-print-part (&optional handle filename)
4156   "Print the MIME part under point."
4157   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4158   (gnus-article-check-buffer)
4159   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4160          (contents (and handle (mm-get-part handle)))
4161          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4162          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4163     (when contents
4164         (if printer
4165             (unwind-protect
4166                 (progn
4167                   (mm-save-part-to-file handle file)
4168                   (call-process shell-file-name nil
4169                                 (generate-new-buffer " *mm*")
4170                                 nil
4171                                 shell-command-switch
4172                                 (mm-mailcap-command
4173                                  printer file (mm-handle-type handle))))
4174               (delete-file file))
4175           (with-temp-buffer
4176             (insert contents)
4177             (gnus-print-buffer))
4178           (ps-despool filename)))))
4179
4180 (defun gnus-mime-inline-part (&optional handle arg)
4181   "Insert the MIME part under point into the current buffer."
4182   (interactive (list nil current-prefix-arg))
4183   (gnus-article-check-buffer)
4184   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4185          contents charset
4186          (b (point))
4187          buffer-read-only)
4188     (when handle
4189       (if (and (not arg) (mm-handle-undisplayer handle))
4190           (mm-remove-part handle)
4191         (setq contents (mm-get-part handle))
4192         (cond
4193          ((not arg)
4194           (setq charset (or (mail-content-type-get
4195                              (mm-handle-type handle) 'charset)
4196                             gnus-newsgroup-charset)))
4197          ((numberp arg)
4198           (if (mm-handle-undisplayer handle)
4199               (mm-remove-part handle))
4200           (setq charset
4201                 (or (cdr (assq arg
4202                                gnus-summary-show-article-charset-alist))
4203                     (mm-read-coding-system "Charset: ")))))
4204         (forward-line 2)
4205         (mm-insert-inline handle
4206                           (if (and charset
4207                                    (setq charset (mm-charset-to-coding-system
4208                                                   charset))
4209                                    (not (eq charset 'ascii)))
4210                               (mm-decode-coding-string contents charset)
4211                             contents))
4212         (goto-char b)))))
4213
4214 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4215   "Insert the MIME part under point into the current buffer using the
4216 specified charset."
4217   (interactive (list nil current-prefix-arg))
4218   (gnus-article-check-buffer)
4219   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4220          contents charset
4221          (b (point))
4222          buffer-read-only)
4223     (when handle
4224       (if (mm-handle-undisplayer handle)
4225           (mm-remove-part handle))
4226       (let ((gnus-newsgroup-charset
4227              (or (cdr (assq arg
4228                             gnus-summary-show-article-charset-alist))
4229                  (mm-read-coding-system "Charset: ")))
4230           (gnus-newsgroup-ignored-charsets 'gnus-all))
4231         (gnus-article-press-button)))))
4232
4233 (defun gnus-mime-view-part-externally (&optional handle)
4234   "View the MIME part under point with an external viewer."
4235   (interactive)
4236   (gnus-article-check-buffer)
4237   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4238          (mm-user-display-methods nil)
4239          (mm-inlined-types nil)
4240          (mail-parse-charset gnus-newsgroup-charset)
4241          (mail-parse-ignored-charsets
4242           (save-excursion (set-buffer gnus-summary-buffer)
4243                           gnus-newsgroup-ignored-charsets)))
4244     (when handle
4245       (if (mm-handle-undisplayer handle)
4246           (mm-remove-part handle)
4247         (mm-display-part handle)))))
4248
4249 (defun gnus-mime-view-part-internally (&optional handle)
4250   "View the MIME part under point with an internal viewer.
4251 If no internal viewer is available, use an external viewer."
4252   (interactive)
4253   (gnus-article-check-buffer)
4254   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4255          (mm-inlined-types '(".*"))
4256          (mm-inline-large-images t)
4257          (mail-parse-charset gnus-newsgroup-charset)
4258          (mail-parse-ignored-charsets
4259           (save-excursion (set-buffer gnus-summary-buffer)
4260                           gnus-newsgroup-ignored-charsets))
4261          buffer-read-only)
4262     (when handle
4263       (if (mm-handle-undisplayer handle)
4264           (mm-remove-part handle)
4265         (mm-display-part handle)))))
4266
4267 (defun gnus-mime-action-on-part (&optional action)
4268   "Do something with the MIME attachment at \(point\)."
4269   (interactive
4270    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4271   (gnus-article-check-buffer)
4272   (let ((action-pair (assoc action gnus-mime-action-alist)))
4273     (if action-pair
4274         (funcall (cdr action-pair)))))
4275
4276 (defun gnus-article-part-wrapper (n function)
4277   (save-current-buffer
4278     (set-buffer gnus-article-buffer)
4279     (when (> n (length gnus-article-mime-handle-alist))
4280       (error "No such part"))
4281     (gnus-article-goto-part n)
4282     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4283       (funcall function handle))))
4284
4285 (defun gnus-article-pipe-part (n)
4286   "Pipe MIME part N, which is the numerical prefix."
4287   (interactive "p")
4288   (gnus-article-part-wrapper n 'mm-pipe-part))
4289
4290 (defun gnus-article-save-part (n)
4291   "Save MIME part N, which is the numerical prefix."
4292   (interactive "p")
4293   (gnus-article-part-wrapper n 'mm-save-part))
4294
4295 (defun gnus-article-interactively-view-part (n)
4296   "View MIME part N interactively, which is the numerical prefix."
4297   (interactive "p")
4298   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4299
4300 (defun gnus-article-copy-part (n)
4301   "Copy MIME part N, which is the numerical prefix."
4302   (interactive "p")
4303   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4304
4305 (defun gnus-article-view-part-as-charset (n)
4306   "Copy MIME part N, which is the numerical prefix."
4307   (interactive "p")
4308   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4309
4310 (defun gnus-article-view-part-externally (n)
4311   "View MIME part N externally, which is the numerical prefix."
4312   (interactive "p")
4313   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4314
4315 (defun gnus-article-inline-part (n)
4316   "Inline MIME part N, which is the numerical prefix."
4317   (interactive "p")
4318   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4319
4320 (defun gnus-article-mime-match-handle-first (condition)
4321   (if condition
4322       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4323         (while (setq ihandle (pop alist))
4324           (if (and (cond
4325                     ((functionp condition)
4326                      (funcall condition (cdr ihandle)))
4327                     ((eq condition 'undisplayed)
4328                      (not (or (mm-handle-undisplayer (cdr ihandle))
4329                               (equal (mm-handle-media-type (cdr ihandle))
4330                                      "multipart/alternative"))))
4331                     ((eq condition 'undisplayed-alternative)
4332                      (not (mm-handle-undisplayer (cdr ihandle))))
4333                     (t t))
4334                    (gnus-article-goto-part (car ihandle))
4335                    (or (not n) (< (car ihandle) n)))
4336               (setq n (car ihandle))))
4337         (or n 1))
4338     1))
4339
4340 (defun gnus-article-view-part (&optional n)
4341   "View MIME part N, which is the numerical prefix."
4342   (interactive "P")
4343   (save-current-buffer
4344     (set-buffer gnus-article-buffer)
4345     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4346                              gnus-article-mime-match-handle-function)))
4347     (when (> n (length gnus-article-mime-handle-alist))
4348       (error "No such part"))
4349     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4350       (when (gnus-article-goto-part n)
4351         (if (equal (car handle) "multipart/alternative")
4352             (gnus-article-press-button)
4353           (when (eq (gnus-mm-display-part handle) 'internal)
4354             (gnus-set-window-start)))))))
4355
4356 (defsubst gnus-article-mime-total-parts ()
4357   (if (bufferp (car gnus-article-mime-handles))
4358       1 ;; single part
4359     (1- (length gnus-article-mime-handles))))
4360
4361 (defun gnus-mm-display-part (handle)
4362   "Display HANDLE and fix MIME button."
4363   (let ((id (get-text-property (point) 'gnus-part))
4364         (point (point))
4365         buffer-read-only)
4366     (forward-line 1)
4367     (prog1
4368         (let ((window (selected-window))
4369               (mail-parse-charset gnus-newsgroup-charset)
4370               (mail-parse-ignored-charsets
4371                (if (gnus-buffer-live-p gnus-summary-buffer)
4372                    (save-excursion
4373                      (set-buffer gnus-summary-buffer)
4374                      gnus-newsgroup-ignored-charsets)
4375                  nil)))
4376           (save-excursion
4377             (unwind-protect
4378                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4379                       (beg (point)))
4380                   (when win
4381                     (select-window win))
4382                   (goto-char point)
4383                   (forward-line)
4384                   (if (mm-handle-displayed-p handle)
4385                       ;; This will remove the part.
4386                       (mm-display-part handle)
4387                     (save-restriction
4388                       (narrow-to-region (point)
4389                                         (if (eobp) (point) (1+ (point))))
4390                       (mm-display-part handle)
4391                       ;; We narrow to the part itself and
4392                       ;; then call the treatment functions.
4393                       (goto-char (point-min))
4394                       (forward-line 1)
4395                       (narrow-to-region (point) (point-max))
4396                       (gnus-treat-article
4397                        nil id
4398                        (gnus-article-mime-total-parts)
4399                        (mm-handle-media-type handle)))))
4400               (if (window-live-p window)
4401                   (select-window window)))))
4402       (goto-char point)
4403       (gnus-delete-line)
4404       (gnus-insert-mime-button
4405        handle id (list (mm-handle-displayed-p handle)))
4406       (goto-char point))))
4407
4408 (defun gnus-article-goto-part (n)
4409   "Go to MIME part N."
4410   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4411
4412 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4413   (let ((gnus-tmp-name
4414          (or (mail-content-type-get (mm-handle-type handle) 'name)
4415              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4416              (mail-content-type-get (mm-handle-type handle) 'url)
4417              ""))
4418         (gnus-tmp-type (mm-handle-media-type handle))
4419         (gnus-tmp-description
4420          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4421                                               "")))
4422         (gnus-tmp-dots
4423          (if (if displayed (car displayed)
4424                (mm-handle-displayed-p handle))
4425              "" "..."))
4426         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4427                            (buffer-size)))
4428         gnus-tmp-type-long b e)
4429     (when (string-match ".*/" gnus-tmp-name)
4430       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4431     (setq gnus-tmp-type-long (concat gnus-tmp-type
4432                                      (and (not (equal gnus-tmp-name ""))
4433                                           (concat "; " gnus-tmp-name))))
4434     (unless (equal gnus-tmp-description "")
4435       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4436     (unless (bolp)
4437       (insert "\n"))
4438     (setq b (point))
4439     (gnus-eval-format
4440      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4441      `(,@(gnus-local-map-property gnus-mime-button-map)
4442          gnus-callback gnus-mm-display-part
4443          gnus-part ,gnus-tmp-id
4444          article-type annotation
4445          gnus-data ,handle))
4446     (setq e (if (bolp)
4447                 ;; Exclude a newline.
4448                 (1- (point))
4449               (point)))
4450     (widget-convert-button
4451      'link b e
4452      :mime-handle handle
4453      :action 'gnus-widget-press-button
4454      :button-keymap gnus-mime-button-map
4455      :help-echo
4456      (lambda (widget/window &optional overlay pos)
4457        ;; Needed to properly clear the message due to a bug in
4458        ;; wid-edit (XEmacs only).
4459        (if (boundp 'help-echo-owns-message)
4460            (setq help-echo-owns-message t))
4461        (format
4462         "%S: %s the MIME part; %S: more options"
4463         (aref gnus-mouse-2 0)
4464         ;; XEmacs will get a single widget arg; Emacs 21 will get
4465         ;; window, overlay, position.
4466         (if (mm-handle-displayed-p
4467              (if overlay
4468                  (with-current-buffer (gnus-overlay-buffer overlay)
4469                    (widget-get (widget-at (gnus-overlay-start overlay))
4470                                :mime-handle))
4471                (widget-get widget/window :mime-handle)))
4472             "hide" "show")
4473         (aref gnus-down-mouse-3 0))))))
4474
4475 (defun gnus-widget-press-button (elems el)
4476   (goto-char (widget-get elems :from))
4477   (gnus-article-press-button))
4478
4479 (defvar gnus-displaying-mime nil)
4480
4481 (defun gnus-display-mime (&optional ihandles)
4482   "Display the MIME parts."
4483   (save-excursion
4484     (save-selected-window
4485       (let ((window (get-buffer-window gnus-article-buffer))
4486             (point (point)))
4487         (when window
4488           (select-window window)
4489           ;; We have to do this since selecting the window
4490           ;; may change the point.  So we set the window point.
4491           (set-window-point window point)))
4492       (let* ((handles (or ihandles
4493                           (mm-dissect-buffer nil gnus-article-loose-mime)
4494                           (and gnus-article-emulate-mime
4495                                (mm-uu-dissect))))
4496              buffer-read-only handle name type b e display)
4497         (when (and (not ihandles)
4498                    (not gnus-displaying-mime))
4499           ;; Top-level call; we clean up.
4500           (when gnus-article-mime-handles
4501             (mm-destroy-parts gnus-article-mime-handles)
4502             (setq gnus-article-mime-handle-alist nil));; A trick.
4503           (setq gnus-article-mime-handles handles)
4504           ;; We allow users to glean info from the handles.
4505           (when gnus-article-mime-part-function
4506             (gnus-mime-part-function handles)))
4507         (if (and handles
4508                  (or (not (stringp (car handles)))
4509                      (cdr handles)))
4510             (progn
4511               (when (and (not ihandles)
4512                          (not gnus-displaying-mime))
4513                 ;; Clean up for mime parts.
4514                 (article-goto-body)
4515                 (delete-region (point) (point-max)))
4516               (let ((gnus-displaying-mime t))
4517                 (gnus-mime-display-part handles)))
4518           (save-restriction
4519             (article-goto-body)
4520             (narrow-to-region (point) (point-max))
4521             (gnus-treat-article nil 1 1)
4522             (widen)))
4523         (unless ihandles
4524           ;; Highlight the headers.
4525           (save-excursion
4526             (save-restriction
4527               (article-goto-body)
4528               (narrow-to-region (point-min) (point))
4529               (gnus-treat-article 'head))))))))
4530
4531 (defcustom gnus-mime-display-multipart-as-mixed nil
4532   "Display \"multipart\" parts as  \"multipart/mixed\".
4533
4534 If t, it overrides nil values of
4535 `gnus-mime-display-multipart-alternative-as-mixed' and
4536 `gnus-mime-display-multipart-related-as-mixed'."
4537   :group 'gnus-article-mime
4538   :type 'boolean)
4539
4540 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4541   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
4542   :group 'gnus-article-mime
4543   :type 'boolean)
4544
4545 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4546   "Display \"multipart/related\" parts as  \"multipart/mixed\".
4547
4548 If displaying \"text/html\" is discouraged \(see
4549 `mm-discouraged-alternatives'\) images or other material inside a
4550 \"multipart/related\" part might be overlooked when this variable is nil."
4551   :group 'gnus-article-mime
4552   :type 'boolean)
4553
4554 (defun gnus-mime-display-part (handle)
4555   (cond
4556    ;; Single part.
4557    ((not (stringp (car handle)))
4558     (gnus-mime-display-single handle))
4559    ;; User-defined multipart
4560    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4561     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4562              handle))
4563    ;; multipart/alternative
4564    ((and (equal (car handle) "multipart/alternative")
4565          (not (or gnus-mime-display-multipart-as-mixed
4566                   gnus-mime-display-multipart-alternative-as-mixed)))
4567     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4568       (push (cons id handle) gnus-article-mime-handle-alist)
4569       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4570    ;; multipart/related
4571    ((and (equal (car handle) "multipart/related")
4572          (not (or gnus-mime-display-multipart-as-mixed
4573                   gnus-mime-display-multipart-related-as-mixed)))
4574     ;;;!!!We should find the start part, but we just default
4575     ;;;!!!to the first part.
4576     ;;(gnus-mime-display-part (cadr handle))
4577     ;;;!!! Most multipart/related is an HTML message plus images.
4578     ;;;!!! Unfortunately we are unable to let W3 display those
4579     ;;;!!! included images, so we just display it as a mixed multipart.
4580     ;;(gnus-mime-display-mixed (cdr handle))
4581     ;;;!!! No, w3 can display everything just fine.
4582     (gnus-mime-display-part (cadr handle)))
4583    ((equal (car handle) "multipart/signed")
4584     (gnus-add-wash-type 'signed)
4585     (gnus-mime-display-security handle))
4586    ((equal (car handle) "multipart/encrypted")
4587     (gnus-add-wash-type 'encrypted)
4588     (gnus-mime-display-security handle))
4589    ;; Other multiparts are handled like multipart/mixed.
4590    (t
4591     (gnus-mime-display-mixed (cdr handle)))))
4592
4593 (defun gnus-mime-part-function (handles)
4594   (if (stringp (car handles))
4595       (mapcar 'gnus-mime-part-function (cdr handles))
4596     (funcall gnus-article-mime-part-function handles)))
4597
4598 (defun gnus-mime-display-mixed (handles)
4599   (mapcar 'gnus-mime-display-part handles))
4600
4601 (defun gnus-mime-display-single (handle)
4602   (let ((type (mm-handle-media-type handle))
4603         (ignored gnus-ignored-mime-types)
4604         (not-attachment t)
4605         (move nil)
4606         display text)
4607     (catch 'ignored
4608       (progn
4609         (while ignored
4610           (when (string-match (pop ignored) type)
4611             (throw 'ignored nil)))
4612         (if (and (setq not-attachment
4613                        (and (not (mm-inline-override-p handle))
4614                             (or (not (mm-handle-disposition handle))
4615                                 (equal (car (mm-handle-disposition handle))
4616                                        "inline")
4617                                 (mm-attachment-override-p handle))))
4618                  (mm-automatic-display-p handle)
4619                  (or (and
4620                       (mm-inlinable-p handle)
4621                       (mm-inlined-p handle))
4622                      (mm-automatic-external-display-p type)))
4623             (setq display t)
4624           (when (equal (mm-handle-media-supertype handle) "text")
4625             (setq text t)))
4626         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4627               beg)
4628           (push (cons id handle) gnus-article-mime-handle-alist)
4629           (when (or (not display)
4630                     (not (gnus-unbuttonized-mime-type-p type)))
4631             ;(gnus-article-insert-newline)
4632             (gnus-insert-mime-button
4633              handle id (list (or display (and not-attachment text))))
4634             (gnus-article-insert-newline)
4635             ;(gnus-article-insert-newline)
4636             ;; Remember modify the number of forward lines.
4637             (setq move t))
4638           (setq beg (point))
4639           (cond
4640            (display
4641             (when move
4642               (forward-line -1)
4643               (setq beg (point)))
4644             (let ((mail-parse-charset gnus-newsgroup-charset)
4645                   (mail-parse-ignored-charsets
4646                    (save-excursion (condition-case ()
4647                                        (set-buffer gnus-summary-buffer)
4648                                      (error))
4649                                    gnus-newsgroup-ignored-charsets)))
4650               (mm-display-part handle t))
4651             (goto-char (point-max)))
4652            ((and text not-attachment)
4653             (when move
4654               (forward-line -1)
4655               (setq beg (point)))
4656             (gnus-article-insert-newline)
4657             (mm-insert-inline handle (mm-get-part handle))
4658             (goto-char (point-max))))
4659           ;; Do highlighting.
4660           (save-excursion
4661             (save-restriction
4662               (narrow-to-region beg (point))
4663               (gnus-treat-article
4664                nil id
4665                (gnus-article-mime-total-parts)
4666                (mm-handle-media-type handle)))))))))
4667
4668 (defun gnus-unbuttonized-mime-type-p (type)
4669   "Say whether TYPE is to be unbuttonized."
4670   (unless gnus-inhibit-mime-unbuttonizing
4671     (when (catch 'found
4672             (let ((types gnus-unbuttonized-mime-types))
4673               (while types
4674                 (when (string-match (pop types) type)
4675                   (throw 'found t)))))
4676       (not (catch 'found
4677              (let ((types gnus-buttonized-mime-types))
4678                (while types
4679                  (when (string-match (pop types) type)
4680                    (throw 'found t)))))))))
4681
4682 (defun gnus-article-insert-newline ()
4683   "Insert a newline, but mark it as undeletable."
4684   (gnus-put-text-property
4685    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4686
4687 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4688   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4689          (ihandles handles)
4690          (point (point))
4691          handle buffer-read-only from props begend not-pref)
4692     (save-window-excursion
4693       (save-restriction
4694         (when ibegend
4695           (narrow-to-region (car ibegend)
4696                             (or (cdr ibegend)
4697                                 (progn
4698                                   (goto-char (car ibegend))
4699                                   (forward-line 2)
4700                                   (point))))
4701           (delete-region (point-min) (point-max))
4702           (mm-remove-parts handles))
4703         (setq begend (list (point-marker)))
4704         ;; Do the toggle.
4705         (unless (setq not-pref (cadr (member preferred ihandles)))
4706           (setq not-pref (car ihandles)))
4707         (when (or ibegend
4708                   (not preferred)
4709                   (not (gnus-unbuttonized-mime-type-p
4710                         "multipart/alternative")))
4711           (gnus-add-text-properties
4712            (setq from (point))
4713            (progn
4714              (insert (format "%d.  " id))
4715              (point))
4716            `(gnus-callback
4717              (lambda (handles)
4718                (unless ,(not ibegend)
4719                  (setq gnus-article-mime-handle-alist
4720                        ',gnus-article-mime-handle-alist))
4721                (gnus-mime-display-alternative
4722                 ',ihandles ',not-pref ',begend ,id))
4723              ,@(gnus-local-map-property gnus-mime-button-map)
4724              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4725              face ,gnus-article-button-face
4726              gnus-part ,id
4727              gnus-data ,handle))
4728           (widget-convert-button 'link from (point)
4729                                  :action 'gnus-widget-press-button
4730                                  :button-keymap gnus-widget-button-keymap)
4731           ;; Do the handles
4732           (while (setq handle (pop handles))
4733             (gnus-add-text-properties
4734              (setq from (point))
4735              (progn
4736                (insert (format "(%c) %-18s"
4737                                (if (equal handle preferred) ?* ? )
4738                                (mm-handle-media-type handle)))
4739                (point))
4740              `(gnus-callback
4741                (lambda (handles)
4742                  (unless ,(not ibegend)
4743                    (setq gnus-article-mime-handle-alist
4744                          ',gnus-article-mime-handle-alist))
4745                  (gnus-mime-display-alternative
4746                   ',ihandles ',handle ',begend ,id))
4747                ,@(gnus-local-map-property gnus-mime-button-map)
4748                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4749                face ,gnus-article-button-face
4750                gnus-part ,id
4751                gnus-data ,handle))
4752             (widget-convert-button 'link from (point)
4753                                    :action 'gnus-widget-press-button
4754                                    :button-keymap gnus-widget-button-keymap)
4755             (insert "  "))
4756           (insert "\n\n"))
4757         (when preferred
4758           (if (stringp (car preferred))
4759               (gnus-display-mime preferred)
4760             (let ((mail-parse-charset gnus-newsgroup-charset)
4761                   (mail-parse-ignored-charsets
4762                    (save-excursion (set-buffer gnus-summary-buffer)
4763                                    gnus-newsgroup-ignored-charsets)))
4764               (mm-display-part preferred)
4765               ;; Do highlighting.
4766               (save-excursion
4767                 (save-restriction
4768                   (narrow-to-region (car begend) (point-max))
4769                   (gnus-treat-article
4770                    nil (length gnus-article-mime-handle-alist)
4771                    (gnus-article-mime-total-parts)
4772                    (mm-handle-media-type handle))))))
4773           (goto-char (point-max))
4774           (setcdr begend (point-marker)))))
4775     (when ibegend
4776       (goto-char point))))
4777
4778 (defconst gnus-article-wash-status-strings
4779   (let ((alist '((cite "c" "Possible hidden citation text"
4780                        " " "All citation text visible")
4781                  (headers "h" "Hidden headers"
4782                           " " "All headers visible.")
4783                  (pgp "p" "Encrypted or signed message status hidden"
4784                       " " "No hidden encryption nor digital signature status")
4785                  (signature "s" "Signature has been hidden"
4786                             " " "Signature is visible")
4787                  (overstrike "o" "Overstrike (^H) characters applied"
4788                              " " "No overstrike characters applied")
4789                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4790                            " " "No /*_emphasis_*/ characters applied")))
4791         result)
4792     (dolist (entry alist result)
4793       (let ((key (nth 0 entry))
4794             (on (copy-sequence (nth 1 entry)))
4795             (on-help (nth 2 entry))
4796             (off (copy-sequence (nth 3 entry)))
4797             (off-help (nth 4 entry)))
4798         (put-text-property 0 1 'help-echo on-help on)
4799         (put-text-property 0 1 'help-echo off-help off)
4800         (push (list key on off) result))))
4801   "Alist of strings describing wash status in the mode line.
4802 Each entry has the form (KEY ON OF), where the KEY is a symbol
4803 representing the particular washing function, ON is the string to use
4804 in the article mode line when the washing function is active, and OFF
4805 is the string to use when it is inactive.")
4806
4807 (defun gnus-article-wash-status-entry (key value)
4808   (let ((entry (assoc key gnus-article-wash-status-strings)))
4809     (if value (nth 1 entry) (nth 2 entry))))
4810
4811 (defun gnus-article-wash-status ()
4812   "Return a string which display status of article washing."
4813   (save-excursion
4814     (set-buffer gnus-article-buffer)
4815     (let ((cite (memq 'cite gnus-article-wash-types))
4816           (headers (memq 'headers gnus-article-wash-types))
4817           (boring (memq 'boring-headers gnus-article-wash-types))
4818           (pgp (memq 'pgp gnus-article-wash-types))
4819           (pem (memq 'pem gnus-article-wash-types))
4820           (signed (memq 'signed gnus-article-wash-types))
4821           (encrypted (memq 'encrypted gnus-article-wash-types))
4822           (signature (memq 'signature gnus-article-wash-types))
4823           (overstrike (memq 'overstrike gnus-article-wash-types))
4824           (emphasis (memq 'emphasis gnus-article-wash-types)))
4825       (concat
4826        (gnus-article-wash-status-entry 'cite cite)
4827        (gnus-article-wash-status-entry 'headers (or headers boring))
4828        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4829        (gnus-article-wash-status-entry 'signature signature)
4830        (gnus-article-wash-status-entry 'overstrike overstrike)
4831        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4832
4833 (defun gnus-add-wash-type (type)
4834   "Add a washing of TYPE to the current status."
4835   (add-to-list 'gnus-article-wash-types type))
4836
4837 (defun gnus-delete-wash-type (type)
4838   "Add a washing of TYPE to the current status."
4839   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4840
4841 (defun gnus-add-image (category image)
4842   "Add IMAGE of CATEGORY to the list of displayed images."
4843   (let ((entry (assq category gnus-article-image-alist)))
4844     (unless entry
4845       (setq entry (list category))
4846       (push entry gnus-article-image-alist))
4847     (nconc entry (list image))))
4848
4849 (defun gnus-delete-images (category)
4850   "Delete all images in CATEGORY."
4851   (let ((entry (assq category gnus-article-image-alist)))
4852     (dolist (image (cdr entry))
4853       (gnus-remove-image image))
4854     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4855     (gnus-delete-wash-type category)))
4856
4857 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4858
4859 (defun gnus-article-maybe-hide-headers ()
4860   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4861 Provided for backwards compatibility."
4862   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4863                  (not (save-excursion (set-buffer gnus-summary-buffer)
4864                                       gnus-have-all-headers)))
4865              (not gnus-inhibit-hiding))
4866     (gnus-article-hide-headers)))
4867
4868 ;;; Article savers.
4869
4870 (defun gnus-output-to-file (file-name)
4871   "Append the current article to a file named FILE-NAME."
4872   (let ((artbuf (current-buffer)))
4873     (with-temp-buffer
4874       (insert-buffer-substring artbuf)
4875       ;; Append newline at end of the buffer as separator, and then
4876       ;; save it to file.
4877       (goto-char (point-max))
4878       (insert "\n")
4879       (let ((file-name-coding-system nnmail-pathname-coding-system))
4880         (mm-append-to-file (point-min) (point-max) file-name))
4881       t)))
4882
4883 (defun gnus-narrow-to-page (&optional arg)
4884   "Narrow the article buffer to a page.
4885 If given a numerical ARG, move forward ARG pages."
4886   (interactive "P")
4887   (setq arg (if arg (prefix-numeric-value arg) 0))
4888   (save-excursion
4889     (set-buffer gnus-article-buffer)
4890     (goto-char (point-min))
4891     (widen)
4892     ;; Remove any old next/prev buttons.
4893     (when (gnus-visual-p 'page-marker)
4894       (let ((buffer-read-only nil))
4895         (gnus-remove-text-with-property 'gnus-prev)
4896         (gnus-remove-text-with-property 'gnus-next)))
4897     (when
4898         (cond ((< arg 0)
4899                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4900               ((> arg 0)
4901                (re-search-forward page-delimiter nil 'move arg)))
4902       (goto-char (match-end 0)))
4903     (narrow-to-region
4904      (point)
4905      (if (re-search-forward page-delimiter nil 'move)
4906          (match-beginning 0)
4907        (point)))
4908     (when (and (gnus-visual-p 'page-marker)
4909                (not (= (point-min) 1)))
4910       (save-excursion
4911         (goto-char (point-min))
4912         (gnus-insert-prev-page-button)))
4913     (when (and (gnus-visual-p 'page-marker)
4914                (< (+ (point-max) 2) (buffer-size)))
4915       (save-excursion
4916         (goto-char (point-max))
4917         (gnus-insert-next-page-button)))))
4918
4919 ;; Article mode commands
4920
4921 (defun gnus-article-goto-next-page ()
4922   "Show the next page of the article."
4923   (interactive)
4924   (when (gnus-article-next-page)
4925     (goto-char (point-min))
4926     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4927
4928
4929 (defun gnus-article-goto-prev-page ()
4930   "Show the next page of the article."
4931   (interactive)
4932   (if (bobp)
4933       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4934     (gnus-article-prev-page nil)))
4935
4936 ;; This is cleaner but currently breaks `gnus-pick-mode':
4937 ;;
4938 ;; (defun gnus-article-goto-next-page ()
4939 ;;   "Show the next page of the article."
4940 ;;   (interactive)
4941 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
4942 ;;     (gnus-summary-next-page)))
4943 ;;
4944 ;; (defun gnus-article-goto-prev-page ()
4945 ;;   "Show the next page of the article."
4946 ;;   (interactive)
4947 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
4948 ;;     (gnus-summary-prev-page)))
4949
4950 (defun gnus-article-next-page (&optional lines)
4951   "Show the next page of the current article.
4952 If end of article, return non-nil.  Otherwise return nil.
4953 Argument LINES specifies lines to be scrolled up."
4954   (interactive "p")
4955   (move-to-window-line -1)
4956   (if (save-excursion
4957         (end-of-line)
4958         (and (pos-visible-in-window-p)  ;Not continuation line.
4959              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
4960       ;; Nothing in this page.
4961       (if (or (not gnus-page-broken)
4962               (save-excursion
4963                 (save-restriction
4964                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4965           (progn
4966             (when gnus-article-over-scroll
4967               (gnus-article-next-page-1 lines))
4968             t)                  ;Nothing more.
4969         (gnus-narrow-to-page 1)         ;Go to next page.
4970         nil)
4971     ;; More in this page.
4972     (gnus-article-next-page-1 lines)
4973     nil))
4974
4975 (defun gnus-article-next-page-1 (lines)
4976   (let ((scroll-in-place nil))
4977     (condition-case ()
4978         (scroll-up lines)
4979       (end-of-buffer
4980        ;; Long lines may cause an end-of-buffer error.
4981        (goto-char (point-max)))))
4982   (move-to-window-line 0))
4983
4984 (defun gnus-article-prev-page (&optional lines)
4985   "Show previous page of current article.
4986 Argument LINES specifies lines to be scrolled down."
4987   (interactive "p")
4988   (move-to-window-line 0)
4989   (if (and gnus-page-broken
4990            (bobp)
4991            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4992       (progn
4993         (gnus-narrow-to-page -1)        ;Go to previous page.
4994         (goto-char (point-max))
4995         (recenter -1))
4996     (let ((scroll-in-place nil))
4997       (prog1
4998           (condition-case ()
4999               (scroll-down lines)
5000             (beginning-of-buffer
5001              (goto-char (point-min))))
5002         (move-to-window-line 0)))))
5003
5004 (defun gnus-article-only-boring-p ()
5005   "Decide whether there is only boring text remaining in the article.
5006 Something \"interesting\" is a word of at least two letters that does
5007 not have a face in `gnus-article-boring-faces'."
5008   (when (and gnus-article-skip-boring
5009              (boundp 'gnus-article-boring-faces)
5010              (symbol-value 'gnus-article-boring-faces))
5011     (save-excursion
5012       (catch 'only-boring
5013         (while (re-search-forward "\\b\\w\\w" nil t)
5014           (forward-char -1)
5015           (when (not (gnus-intersection
5016                       (gnus-faces-at (point))
5017                       (symbol-value 'gnus-article-boring-faces)))
5018             (throw 'only-boring nil)))
5019         (throw 'only-boring t)))))
5020
5021 (defun gnus-article-refer-article ()
5022   "Read article specified by message-id around point."
5023   (interactive)
5024   (save-excursion
5025     (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5026     (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5027     (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5028         (let ((msg-id (concat "<" (match-string 0) ">")))
5029           (set-buffer gnus-summary-buffer)
5030           (gnus-summary-refer-article msg-id))
5031       (error "No references around point"))))
5032
5033 (defun gnus-article-show-summary ()
5034   "Reconfigure windows to show summary buffer."
5035   (interactive)
5036   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5037       (error "There is no summary buffer for this article buffer")
5038     (gnus-article-set-globals)
5039     (gnus-configure-windows 'article)
5040     (gnus-summary-goto-subject gnus-current-article)
5041     (gnus-summary-position-point)))
5042
5043 (defun gnus-article-describe-briefly ()
5044   "Describe article mode commands briefly."
5045   (interactive)
5046   (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")))
5047
5048 (defun gnus-article-summary-command ()
5049   "Execute the last keystroke in the summary buffer."
5050   (interactive)
5051   (let ((obuf (current-buffer))
5052         (owin (current-window-configuration))
5053         func)
5054     (switch-to-buffer gnus-article-current-summary 'norecord)
5055     (setq func (lookup-key (current-local-map) (this-command-keys)))
5056     (call-interactively func)
5057     (set-buffer obuf)
5058     (set-window-configuration owin)
5059     (set-window-point (get-buffer-window (current-buffer)) (point))))
5060
5061 (defun gnus-article-summary-command-nosave ()
5062   "Execute the last keystroke in the summary buffer."
5063   (interactive)
5064   (let (func)
5065     (pop-to-buffer gnus-article-current-summary 'norecord)
5066     (setq func (lookup-key (current-local-map) (this-command-keys)))
5067     (call-interactively func)))
5068
5069 (defun gnus-article-check-buffer ()
5070   "Beep if not in an article buffer."
5071   (unless (equal major-mode 'gnus-article-mode)
5072     (error "Command invoked outside of a Gnus article buffer")))
5073
5074 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5075   "Read a summary buffer key sequence and execute it from the article buffer."
5076   (interactive "P")
5077   (gnus-article-check-buffer)
5078   (let ((nosaves
5079          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5080            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5081            "=" "^" "\M-^" "|"))
5082         (nosave-but-article
5083          '("A\r"))
5084         (nosave-in-article
5085          '("\C-d"))
5086         (up-to-top
5087          '("n" "Gn" "p" "Gp"))
5088         keys new-sum-point)
5089     (save-excursion
5090       (set-buffer gnus-article-current-summary)
5091       (let (gnus-pick-mode)
5092         (push (or key last-command-event) unread-command-events)
5093         (setq keys (if (featurep 'xemacs)
5094                        (events-to-keys (read-key-sequence nil))
5095                      (read-key-sequence nil)))))
5096
5097     (message "")
5098
5099     (if (or (member keys nosaves)
5100             (member keys nosave-but-article)
5101             (member keys nosave-in-article))
5102         (let (func)
5103           (save-window-excursion
5104             (pop-to-buffer gnus-article-current-summary 'norecord)
5105             ;; We disable the pick minor mode commands.
5106             (let (gnus-pick-mode)
5107               (setq func (lookup-key (current-local-map) keys))))
5108           (if (or (not func)
5109                   (numberp func))
5110               (ding)
5111             (unless (member keys nosave-in-article)
5112               (set-buffer gnus-article-current-summary))
5113             (call-interactively func)
5114             (setq new-sum-point (point)))
5115           (when (member keys nosave-but-article)
5116             (pop-to-buffer gnus-article-buffer 'norecord)))
5117       ;; These commands should restore window configuration.
5118       (let ((obuf (current-buffer))
5119             (owin (current-window-configuration))
5120             (opoint (point))
5121             (summary gnus-article-current-summary)
5122             func in-buffer selected)
5123         (if not-restore-window
5124             (pop-to-buffer summary 'norecord)
5125           (switch-to-buffer summary 'norecord))
5126         (setq in-buffer (current-buffer))
5127         ;; We disable the pick minor mode commands.
5128         (if (and (setq func (let (gnus-pick-mode)
5129                               (lookup-key (current-local-map) keys)))
5130                  (functionp func))
5131             (progn
5132               (call-interactively func)
5133               (setq new-sum-point (point))
5134               (when (eq in-buffer (current-buffer))
5135                 (setq selected (gnus-summary-select-article))
5136                 (set-buffer obuf)
5137                 (unless not-restore-window
5138                   (set-window-configuration owin))
5139                 (when (eq selected 'old)
5140                   (article-goto-body)
5141                   (set-window-start (get-buffer-window (current-buffer))
5142                                     1)
5143                   (set-window-point (get-buffer-window (current-buffer))
5144                                     (point)))
5145                 (let ((win (get-buffer-window gnus-article-current-summary)))
5146                   (when win
5147                     (set-window-point win new-sum-point))))    )
5148           (switch-to-buffer gnus-article-buffer)
5149           (ding))))))
5150
5151 (defun gnus-article-describe-key (key)
5152   "Display documentation of the function invoked by KEY.  KEY is a string."
5153   (interactive "kDescribe key: ")
5154   (gnus-article-check-buffer)
5155   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5156       (save-excursion
5157         (set-buffer gnus-article-current-summary)
5158         (let (gnus-pick-mode)
5159           (if (featurep 'xemacs)
5160               (progn
5161                 (push (elt key 0) unread-command-events)
5162                 (setq key (events-to-keys
5163                            (read-key-sequence "Describe key: "))))
5164             (setq unread-command-events
5165                   (mapcar
5166                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5167                    (string-to-list key)))
5168             (setq key (read-key-sequence "Describe key: "))))
5169         (describe-key key))
5170     (describe-key key)))
5171
5172 (defun gnus-article-describe-key-briefly (key &optional insert)
5173   "Display documentation of the function invoked by KEY.  KEY is a string."
5174   (interactive "kDescribe key: \nP")
5175   (gnus-article-check-buffer)
5176   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5177       (save-excursion
5178         (set-buffer gnus-article-current-summary)
5179         (let (gnus-pick-mode)
5180           (if (featurep 'xemacs)
5181               (progn
5182                 (push (elt key 0) unread-command-events)
5183                 (setq key (events-to-keys
5184                            (read-key-sequence "Describe key: "))))
5185             (setq unread-command-events
5186                   (mapcar
5187                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5188                    (string-to-list key)))
5189             (setq key (read-key-sequence "Describe key: "))))
5190         (describe-key-briefly key insert))
5191     (describe-key-briefly key insert)))
5192
5193 (defun gnus-article-reply-with-original (&optional wide)
5194   "Start composing a reply mail to the current message.
5195 The text in the region will be yanked.  If the region isn't active,
5196 the entire article will be yanked."
5197   (interactive "P")
5198   (let ((article (cdr gnus-article-current))
5199         contents)
5200     (if (not (gnus-mark-active-p))
5201         (with-current-buffer gnus-summary-buffer
5202           (gnus-summary-reply (list (list article)) wide))
5203       (setq contents (buffer-substring (point) (mark t)))
5204       ;; Deactivate active regions.
5205       (when (and (boundp 'transient-mark-mode)
5206                  transient-mark-mode)
5207         (setq mark-active nil))
5208       (with-current-buffer gnus-summary-buffer
5209         (gnus-summary-reply
5210          (list (list article contents)) wide)))))
5211
5212 (defun gnus-article-followup-with-original ()
5213   "Compose a followup to the current article.
5214 The text in the region will be yanked.  If the region isn't active,
5215 the entire article will be yanked."
5216   (interactive)
5217   (let ((article (cdr gnus-article-current))
5218         contents)
5219       (if (not (gnus-mark-active-p))
5220           (with-current-buffer gnus-summary-buffer
5221             (gnus-summary-followup (list (list article))))
5222         (setq contents (buffer-substring (point) (mark t)))
5223         ;; Deactivate active regions.
5224         (when (and (boundp 'transient-mark-mode)
5225                    transient-mark-mode)
5226           (setq mark-active nil))
5227         (with-current-buffer gnus-summary-buffer
5228           (gnus-summary-followup
5229            (list (list article contents)))))))
5230
5231 (defun gnus-article-hide (&optional arg force)
5232   "Hide all the gruft in the current article.
5233 This means that signatures, cited text and (some) headers will be
5234 hidden.
5235 If given a prefix, show the hidden text instead."
5236   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5237   (gnus-article-hide-headers arg)
5238   (gnus-article-hide-list-identifiers arg)
5239   (gnus-article-hide-citation-maybe arg force)
5240   (gnus-article-hide-signature arg))
5241
5242 (defun gnus-article-maybe-highlight ()
5243   "Do some article highlighting if article highlighting is requested."
5244   (when (gnus-visual-p 'article-highlight 'highlight)
5245     (gnus-article-highlight-some)))
5246
5247 (defun gnus-check-group-server ()
5248   ;; Make sure the connection to the server is alive.
5249   (unless (gnus-server-opened
5250            (gnus-find-method-for-group gnus-newsgroup-name))
5251     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5252     (gnus-request-group gnus-newsgroup-name t)))
5253
5254 (eval-when-compile
5255   (autoload 'nneething-get-file-name "nneething"))
5256
5257 (defun gnus-request-article-this-buffer (article group)
5258   "Get an article and insert it into this buffer."
5259   (let (do-update-line sparse-header)
5260     (prog1
5261         (save-excursion
5262           (erase-buffer)
5263           (gnus-kill-all-overlays)
5264           (setq group (or group gnus-newsgroup-name))
5265
5266           ;; Using `gnus-request-article' directly will insert the article into
5267           ;; `nntp-server-buffer' - so we'll save some time by not having to
5268           ;; copy it from the server buffer into the article buffer.
5269
5270           ;; We only request an article by message-id when we do not have the
5271           ;; headers for it, so we'll have to get those.
5272           (when (stringp article)
5273             (gnus-read-header article))
5274
5275           ;; If the article number is negative, that means that this article
5276           ;; doesn't belong in this newsgroup (possibly), so we find its
5277           ;; message-id and request it by id instead of number.
5278           (when (and (numberp article)
5279                      gnus-summary-buffer
5280                      (get-buffer gnus-summary-buffer)
5281                      (gnus-buffer-exists-p gnus-summary-buffer))
5282             (save-excursion
5283               (set-buffer gnus-summary-buffer)
5284               (let ((header (gnus-summary-article-header article)))
5285                 (when (< article 0)
5286                   (cond
5287                    ((memq article gnus-newsgroup-sparse)
5288                     ;; This is a sparse gap article.
5289                     (setq do-update-line article)
5290                     (setq article (mail-header-id header))
5291                     (setq sparse-header (gnus-read-header article))
5292                     (setq gnus-newsgroup-sparse
5293                           (delq article gnus-newsgroup-sparse)))
5294                    ((vectorp header)
5295                     ;; It's a real article.
5296                     (setq article (mail-header-id header)))
5297                    (t
5298                     ;; It is an extracted pseudo-article.
5299                     (setq article 'pseudo)
5300                     (gnus-request-pseudo-article header))))
5301
5302                 (let ((method (gnus-find-method-for-group
5303                                gnus-newsgroup-name)))
5304                   (when (and (eq (car method) 'nneething)
5305                              (vectorp header))
5306                     (let ((dir (nneething-get-file-name
5307                                 (mail-header-id header))))
5308                       (when (and (stringp dir)
5309                                  (file-directory-p dir))
5310                         (setq article 'nneething)
5311                         (gnus-group-enter-directory dir))))))))
5312
5313           (cond
5314            ;; Refuse to select canceled articles.
5315            ((and (numberp article)
5316                  gnus-summary-buffer
5317                  (get-buffer gnus-summary-buffer)
5318                  (gnus-buffer-exists-p gnus-summary-buffer)
5319                  (eq (cdr (save-excursion
5320                             (set-buffer gnus-summary-buffer)
5321                             (assq article gnus-newsgroup-reads)))
5322                      gnus-canceled-mark))
5323             nil)
5324            ;; We first check `gnus-original-article-buffer'.
5325            ((and (get-buffer gnus-original-article-buffer)
5326                  (numberp article)
5327                  (save-excursion
5328                    (set-buffer gnus-original-article-buffer)
5329                    (and (equal (car gnus-original-article) group)
5330                         (eq (cdr gnus-original-article) article))))
5331             (insert-buffer-substring gnus-original-article-buffer)
5332             'article)
5333            ;; Check the backlog.
5334            ((and gnus-keep-backlog
5335                  (gnus-backlog-request-article group article (current-buffer)))
5336             'article)
5337            ;; Check asynchronous pre-fetch.
5338            ((gnus-async-request-fetched-article group article (current-buffer))
5339             (gnus-async-prefetch-next group article gnus-summary-buffer)
5340             (when (and (numberp article) gnus-keep-backlog)
5341               (gnus-backlog-enter-article group article (current-buffer)))
5342             'article)
5343            ;; Check the cache.
5344            ((and gnus-use-cache
5345                  (numberp article)
5346                  (gnus-cache-request-article article group))
5347             'article)
5348            ;; Check the agent cache.
5349            ((gnus-agent-request-article article group)
5350             'article)
5351            ;; Get the article and put into the article buffer.
5352            ((or (stringp article)
5353                 (numberp article))
5354             (let ((gnus-override-method gnus-override-method)
5355                   (methods (and (stringp article)
5356                                 gnus-refer-article-method))
5357                   (backend (car (gnus-find-method-for-group
5358                                  gnus-newsgroup-name)))
5359                   result
5360                   (buffer-read-only nil))
5361               (if (or (not (listp methods))
5362                       (and (symbolp (car methods))
5363                            (assq (car methods) nnoo-definition-alist)))
5364                   (setq methods (list methods)))
5365               (when (and (null gnus-override-method)
5366                          methods)
5367                 (setq gnus-override-method (pop methods)))
5368               (while (not result)
5369                 (when (eq gnus-override-method 'current)
5370                   (setq gnus-override-method
5371                         (with-current-buffer gnus-summary-buffer
5372                           gnus-current-select-method)))
5373                 (erase-buffer)
5374                 (gnus-kill-all-overlays)
5375                 (let ((gnus-newsgroup-name group))
5376                   (gnus-check-group-server))
5377                 (cond
5378                  ((gnus-request-article article group (current-buffer))
5379                   (when (numberp article)
5380                     (gnus-async-prefetch-next group article
5381                                               gnus-summary-buffer)
5382                     (when gnus-keep-backlog
5383                       (gnus-backlog-enter-article
5384                        group article (current-buffer))))
5385                   (setq result 'article))
5386                  (methods
5387                   (setq gnus-override-method (pop methods)))
5388                  ((not (string-match "^400 "
5389                                      (nnheader-get-report backend)))
5390                   ;; If we get 400 server disconnect, reconnect and
5391                   ;; retry; otherwise, assume the article has expired.
5392                   (setq result 'done))))
5393               (and (eq result 'article) 'article)))
5394            ;; It was a pseudo.
5395            (t article)))
5396
5397       ;; Associate this article with the current summary buffer.
5398       (setq gnus-article-current-summary gnus-summary-buffer)
5399
5400       ;; Take the article from the original article buffer
5401       ;; and place it in the buffer it's supposed to be in.
5402       (when (and (get-buffer gnus-article-buffer)
5403                  (equal (buffer-name (current-buffer))
5404                         (buffer-name (get-buffer gnus-article-buffer))))
5405         (save-excursion
5406           (if (get-buffer gnus-original-article-buffer)
5407               (set-buffer gnus-original-article-buffer)
5408             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5409             (buffer-disable-undo)
5410             (setq major-mode 'gnus-original-article-mode)
5411             (setq buffer-read-only t))
5412           (let (buffer-read-only)
5413             (erase-buffer)
5414             (insert-buffer-substring gnus-article-buffer))
5415           (setq gnus-original-article (cons group article)))
5416
5417         ;; Decode charsets.
5418         (run-hooks 'gnus-article-decode-hook)
5419         ;; Mark article as decoded or not.
5420         (setq gnus-article-decoded-p gnus-article-decode-hook))
5421
5422       ;; Update sparse articles.
5423       (when (and do-update-line
5424                  (or (numberp article)
5425                      (stringp article)))
5426         (let ((buf (current-buffer)))
5427           (set-buffer gnus-summary-buffer)
5428           (gnus-summary-update-article do-update-line sparse-header)
5429           (gnus-summary-goto-subject do-update-line nil t)
5430           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5431                             (point))
5432           (set-buffer buf))))))
5433
5434 ;;;
5435 ;;; Article editing
5436 ;;;
5437
5438 (defcustom gnus-article-edit-mode-hook nil
5439   "Hook run in article edit mode buffers."
5440   :group 'gnus-article-various
5441   :type 'hook)
5442
5443 (defvar gnus-article-edit-done-function nil)
5444
5445 (defvar gnus-article-edit-mode-map nil)
5446 (defvar gnus-article-edit-mode nil)
5447
5448 ;; Should we be using derived.el for this?
5449 (unless gnus-article-edit-mode-map
5450   (setq gnus-article-edit-mode-map (make-keymap))
5451   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5452
5453   (gnus-define-keys gnus-article-edit-mode-map
5454     "\C-c?"    describe-mode
5455     "\C-c\C-c" gnus-article-edit-done
5456     "\C-c\C-k" gnus-article-edit-exit
5457     "\C-c\C-f\C-t" message-goto-to
5458     "\C-c\C-f\C-o" message-goto-from
5459     "\C-c\C-f\C-b" message-goto-bcc
5460     ;;"\C-c\C-f\C-w" message-goto-fcc
5461     "\C-c\C-f\C-c" message-goto-cc
5462     "\C-c\C-f\C-s" message-goto-subject
5463     "\C-c\C-f\C-r" message-goto-reply-to
5464     "\C-c\C-f\C-n" message-goto-newsgroups
5465     "\C-c\C-f\C-d" message-goto-distribution
5466     "\C-c\C-f\C-f" message-goto-followup-to
5467     "\C-c\C-f\C-m" message-goto-mail-followup-to
5468     "\C-c\C-f\C-k" message-goto-keywords
5469     "\C-c\C-f\C-u" message-goto-summary
5470     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5471     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5472     "\C-c\C-b" message-goto-body
5473     "\C-c\C-i" message-goto-signature
5474
5475     "\C-c\C-t" message-insert-to
5476     "\C-c\C-n" message-insert-newsgroups
5477     "\C-c\C-o" message-sort-headers
5478     "\C-c\C-e" message-elide-region
5479     "\C-c\C-v" message-delete-not-region
5480     "\C-c\C-z" message-kill-to-signature
5481     "\M-\r" message-newline-and-reformat
5482     "\C-c\C-a" mml-attach-file
5483     "\C-a" message-beginning-of-line
5484     "\t" message-tab
5485     "\M-;" comment-region)
5486
5487   (gnus-define-keys (gnus-article-edit-wash-map
5488                      "\C-c\C-w" gnus-article-edit-mode-map)
5489     "f" gnus-article-edit-full-stops))
5490
5491 (easy-menu-define
5492   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5493   '("Field"
5494     ["Fetch To" message-insert-to t]
5495     ["Fetch Newsgroups" message-insert-newsgroups t]
5496     "----"
5497     ["To" message-goto-to t]
5498     ["From" message-goto-from t]
5499     ["Subject" message-goto-subject t]
5500     ["Cc" message-goto-cc t]
5501     ["Reply-To" message-goto-reply-to t]
5502     ["Summary" message-goto-summary t]
5503     ["Keywords" message-goto-keywords t]
5504     ["Newsgroups" message-goto-newsgroups t]
5505     ["Followup-To" message-goto-followup-to t]
5506     ["Mail-Followup-To" message-goto-mail-followup-to t]
5507     ["Distribution" message-goto-distribution t]
5508     ["Body" message-goto-body t]
5509     ["Signature" message-goto-signature t]))
5510
5511 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5512   "Major mode for editing articles.
5513 This is an extended text-mode.
5514
5515 \\{gnus-article-edit-mode-map}"
5516   (make-local-variable 'gnus-article-edit-done-function)
5517   (make-local-variable 'gnus-prev-winconf)
5518   (set (make-local-variable 'font-lock-defaults)
5519        '(message-font-lock-keywords t))
5520   (set (make-local-variable 'mail-header-separator) "")
5521   (set (make-local-variable 'gnus-article-edit-mode) t)
5522   (easy-menu-add message-mode-field-menu message-mode-map)
5523   (mml-mode)
5524   (setq buffer-read-only nil)
5525   (buffer-enable-undo)
5526   (widen))
5527
5528 (defun gnus-article-edit (&optional force)
5529   "Edit the current article.
5530 This will have permanent effect only in mail groups.
5531 If FORCE is non-nil, allow editing of articles even in read-only
5532 groups."
5533   (interactive "P")
5534   (when (and (not force)
5535              (gnus-group-read-only-p))
5536     (error "The current newsgroup does not support article editing"))
5537   (gnus-article-date-original)
5538   (gnus-article-edit-article
5539    'ignore
5540    `(lambda (no-highlight)
5541       'ignore
5542       (gnus-summary-edit-article-done
5543        ,(or (mail-header-references gnus-current-headers) "")
5544        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5545
5546 (defun gnus-article-edit-article (start-func exit-func)
5547   "Start editing the contents of the current article buffer."
5548   (let ((winconf (current-window-configuration)))
5549     (set-buffer gnus-article-buffer)
5550     (gnus-article-edit-mode)
5551     (funcall start-func)
5552     (set-buffer-modified-p nil)
5553     (gnus-configure-windows 'edit-article)
5554     (setq gnus-article-edit-done-function exit-func)
5555     (setq gnus-prev-winconf winconf)
5556     (gnus-message 6 "C-c C-c to end edits")))
5557
5558 (defun gnus-article-edit-done (&optional arg)
5559   "Update the article edits and exit."
5560   (interactive "P")
5561   (let ((func gnus-article-edit-done-function)
5562         (buf (current-buffer))
5563         (start (window-start))
5564         (p (point))
5565         (winconf gnus-prev-winconf))
5566     (widen) ;; Widen it in case that users narrowed the buffer.
5567     (funcall func arg)
5568     (set-buffer buf)
5569     ;; The cache and backlog have to be flushed somewhat.
5570     (when gnus-keep-backlog
5571       (gnus-backlog-remove-article
5572        (car gnus-article-current) (cdr gnus-article-current)))
5573     ;; Flush original article as well.
5574     (save-excursion
5575       (when (get-buffer gnus-original-article-buffer)
5576         (set-buffer gnus-original-article-buffer)
5577         (setq gnus-original-article nil)))
5578     (when gnus-use-cache
5579       (gnus-cache-update-article
5580        (car gnus-article-current) (cdr gnus-article-current)))
5581     ;; We remove all text props from the article buffer.
5582     (kill-all-local-variables)
5583     (gnus-set-text-properties (point-min) (point-max) nil)
5584     (gnus-article-mode)
5585     (set-window-configuration winconf)
5586     (set-buffer buf)
5587     (set-window-start (get-buffer-window buf) start)
5588     (set-window-point (get-buffer-window buf) (point))))
5589
5590 (defun gnus-article-edit-exit ()
5591   "Exit the article editing without updating."
5592   (interactive)
5593   (when (or (not (buffer-modified-p))
5594             (yes-or-no-p "Article modified; kill anyway? "))
5595     (let ((curbuf (current-buffer))
5596           (p (point))
5597           (window-start (window-start)))
5598       (erase-buffer)
5599       (if (gnus-buffer-live-p gnus-original-article-buffer)
5600           (insert-buffer gnus-original-article-buffer))
5601       (let ((winconf gnus-prev-winconf))
5602         (kill-all-local-variables)
5603         (gnus-article-mode)
5604         (set-window-configuration winconf)
5605         ;; Tippy-toe some to make sure that point remains where it was.
5606         (save-current-buffer
5607           (set-buffer curbuf)
5608           (set-window-start (get-buffer-window (current-buffer)) window-start)
5609           (goto-char p))))))
5610
5611 (defun gnus-article-edit-full-stops ()
5612   "Interactively repair spacing at end of sentences."
5613   (interactive)
5614   (save-excursion
5615     (goto-char (point-min))
5616     (search-forward-regexp "^$" nil t)
5617     (let ((case-fold-search nil))
5618       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5619
5620 ;;;
5621 ;;; Article highlights
5622 ;;;
5623
5624 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5625
5626 ;;; Internal Variables:
5627
5628 (defcustom gnus-button-url-regexp
5629   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5630       "\\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:]]\\)"
5631     "\\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\\)\\)")
5632   "Regular expression that matches URLs."
5633   :group 'gnus-article-buttons
5634   :type 'regexp)
5635
5636 (defcustom gnus-button-valid-fqdn-regexp
5637   message-valid-fqdn-regexp
5638   "Regular expression that matches a valid FQDN."
5639   :group 'gnus-article-buttons
5640   :type 'regexp)
5641
5642 (defcustom gnus-button-man-handler 'manual-entry
5643   "Function to use for displaying man pages.
5644 The function must take at least one argument with a string naming the
5645 man page."
5646   :type '(choice (function-item :tag "Man" manual-entry)
5647                  (function-item :tag "Woman" woman)
5648                  (function :tag "Other"))
5649   :group 'gnus-article-buttons)
5650
5651 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5652   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5653 If the default site is too slow, try to find a CTAN mirror, see
5654 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
5655 the variable `gnus-button-handle-ctan'."
5656   :group 'gnus-article-buttons
5657   :link '(custom-manual "(gnus)Group Parameters")
5658   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5659                  (const "http://tug.ctan.org/tex-archive/")
5660                  (const "http://www.dante.de/CTAN/")
5661                  (string :tag "Other")))
5662
5663 (defcustom gnus-button-ctan-handler 'browse-url
5664   "Function to use for displaying CTAN links.
5665 The function must take one argument, the string naming the URL."
5666   :type '(choice (function-item :tag "Browse Url" browse-url)
5667                  (function :tag "Other"))
5668   :group 'gnus-article-buttons)
5669
5670 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5671   "Bogus strings removed from CTAN URLs."
5672   :group 'gnus-article-buttons
5673   :type '(choice (const "^/?tex-archive/\\|/")
5674                  (regexp :tag "Other")))
5675
5676 (defcustom gnus-button-ctan-directory-regexp
5677   (concat
5678    "\\("; Cannot use `\(?: ... \)' (compatibility with Emacs 20).
5679    "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
5680    "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
5681    "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
5682    "\\)")
5683   "Regular expression for ctan directories.
5684 It should match all directories in the top level of `gnus-ctan-url'."
5685   :group 'gnus-article-buttons
5686   :type 'regexp)
5687
5688 (defcustom gnus-button-mid-or-mail-regexp
5689   (concat "\\b\\(<?[a-z0-9][^<>\")!;:,{}\n\t ]*@"
5690           gnus-button-valid-fqdn-regexp
5691           ">?\\)\\b")
5692   "Regular expression that matches a message ID or a mail address."
5693   :group 'gnus-article-buttons
5694   :type 'regexp)
5695
5696 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5697   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5698 Strings like this can be either a message ID or a mail address.  If it is one
5699 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5700 message ID or a mail address, respectively.  If this variable is set to the
5701 symbol `ask', always query the user what do do.  If it is a function, this
5702 function will be called with the string as it's only argument.  The function
5703 must return `mid', `mail', `invalid' or `ask'."
5704   :group 'gnus-article-buttons
5705   :type '(choice (function-item :tag "Heuristic function"
5706                                 gnus-button-mid-or-mail-heuristic)
5707                  (const ask)
5708                  (const mid)
5709                  (const mail)))
5710
5711 (defcustom gnus-button-mid-or-mail-heuristic-alist
5712   '((-10.0 . ".+\\$.+@")
5713     (-10.0 . "#")
5714     (-10.0 . "\\*")
5715     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
5716     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5717     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5718     (-1.0  . "^[^a-z]+@")
5719     ;;
5720     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5721     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5722     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
5723     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5724     ;;
5725     (-2.0  . "^[0-9]")
5726     (-1.0  . "^[0-9][0-9]")
5727     ;;
5728     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5729     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5730     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5731     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5732     ;;
5733     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5734     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5735     ;;       "[0-9]{8,}.*\@"
5736     (-3.0
5737      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5738     ;; "[0-9]{12,}.*\@"
5739     ;; compensation for TDMA dated mail addresses:
5740     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5741     ;;
5742     (-20.0 . "\\.fsf@") ;; Gnus
5743     (-20.0 . "^slrn")
5744     (-20.0 . "^Pine")
5745     (-20.0 . "_-_") ;; Subject change in thread
5746     ;;
5747     (-20.0 . "\\.ln@") ;; leafnode
5748     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5749     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5750     ;;
5751     ;; (5.0 . "") ;; $local_part_len <= 7
5752     (10.0  . "^[^0-9]+@")
5753     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5754     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5755     (3.0   . "\@stud")
5756     ;;
5757     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
5758     ;;
5759     (0.5   . "^[A-Z][a-z]")
5760     (0.5   . "^[A-Z][a-z][a-z]")
5761     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5762     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5763   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5764
5765 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5766 address.  The REGEXP is processed with `case-fold-search' set to nil."
5767   :group 'gnus-article-buttons
5768   :type '(repeat (cons (number :tag "Rate")
5769                        (regexp :tag "Regexp"))))
5770
5771 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5772   "Guess whether MID-OR-MAIL is a message ID or a mail address.
5773 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5774 address, `ask' if unsure and `invalid' if the string is invalid."
5775   (let ((case-fold-search nil)
5776         (list gnus-button-mid-or-mail-heuristic-alist)
5777         (result 0) rate regexp lpartlen elem)
5778     (setq lpartlen
5779           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5780     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5781     ;; Certain special cases...
5782     (when (string-match
5783            (concat
5784             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$" "\\|"
5785             "^[0-9]+\.[0-9]+\@compuserve")
5786            mid-or-mail)
5787       (gnus-message 8 "`%s' is a known mail address.")
5788       (setq result 'mail))
5789     (when (string-match "@.*@\\| " mid-or-mail)
5790       (gnus-message 8 "`%s' is invalid.")
5791       (setq result 'invalid))
5792     ;; Nothing more to do, if result is not a number here...
5793     (when (numberp result)
5794       (while list
5795         (setq elem (car list)
5796               rate (car elem)
5797               regexp (cdr elem)
5798               list (cdr list))
5799         (when (string-match regexp mid-or-mail)
5800           (setq result (+ result rate))
5801           (gnus-message
5802            9 "`%s' matched `%s', rate `%s', result `%s'."
5803            mid-or-mail regexp rate result)))
5804       (when (<= lpartlen 7)
5805         (setq result (+ result 5.0))
5806         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
5807                       mid-or-mail result))
5808       (when (>= lpartlen 12)
5809         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
5810         (cond
5811          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
5812           ;; Long local part should contain realname if e-mail address,
5813           ;; too many digits: message-id.
5814           ;; $score -= 5.0 + 0.1 * $local_part_len;
5815           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
5816           (setq result (+ result rate))
5817           (gnus-message
5818            9 "Many digits in `%s', rate `%s', result `%s'."
5819            mid-or-mail rate result))
5820          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
5821                         mid-or-mail)
5822           ;; Too few vowels [^aeiouy]{4,}.*\@
5823           (setq result (+ result -5.0))
5824           (gnus-message
5825            9 "Few vowels in `%s', rate `%s', result `%s'."
5826            mid-or-mail -5.0 result))
5827          (t
5828           (setq result (+ result 5.0))
5829           (gnus-message
5830            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
5831     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
5832     (cond
5833      ;; Maybe we should make this a customizable alist: (condition . 'result)
5834      ((< result -10.0) 'mid)
5835      ((> result  10.0) 'mail)
5836      (t 'ask))))
5837
5838 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5839   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
5840          (url-mid (concat "news" ":" mid-or-mail))
5841          (url-mailto (concat "mailto" ":" mid-or-mail)))
5842     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5843     (when (fboundp pref)
5844       (setq guessed
5845             ;; get rid of surrounding angles...
5846             (funcall pref
5847                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
5848       (if (or (eq 'mid guessed) (eq 'mail guessed))
5849           (setq pref guessed)
5850         (setq pref 'ask)))
5851     (if (eq pref 'ask)
5852         (save-window-excursion
5853           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
5854               (setq pref 'mail)
5855             (setq pref 'mid))))
5856     (cond ((eq pref 'mid)
5857            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
5858            (gnus-button-handle-news url-mid))
5859           ((eq pref 'mail)
5860            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
5861            (gnus-url-mailto url-mailto))
5862           (t (gnus-message 3 "Invalid string.")))))
5863
5864 (defun gnus-button-handle-custom (url)
5865   "Follow a Custom URL."
5866   (customize-apropos (gnus-url-unhex-string url)))
5867
5868 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
5869
5870 ;; FIXME: Maybe we should merge some of the functions that do quite similar
5871 ;; stuff?
5872
5873 (defun gnus-button-handle-describe-function (url)
5874   "Call `describe-function' when pushing the corresponding URL button."
5875   (describe-function
5876    (intern
5877     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5878
5879 (defun gnus-button-handle-describe-variable (url)
5880   "Call `describe-variable' when pushing the corresponding URL button."
5881   (describe-variable
5882    (intern
5883     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5884
5885 (defun gnus-button-handle-symbol (url)
5886 "Display help on variable or function.
5887 Calls `describe-variable' or `describe-function'."
5888   (let ((sym (intern url)))
5889     (cond
5890      ((fboundp sym) (describe-function sym))
5891      ((boundp sym) (describe-variable sym))
5892      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
5893
5894 (defun gnus-button-handle-describe-key (url)
5895   "Call `describe-key' when pushing the corresponding URL button."
5896   (let* ((key-string
5897           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
5898          (keys (ignore-errors (eval `(kbd ,key-string)))))
5899     (if keys
5900         (describe-key keys)
5901       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
5902
5903 (defun gnus-button-handle-apropos (url)
5904   "Call `apropos' when pushing the corresponding URL button."
5905   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5906
5907 (defun gnus-button-handle-apropos-command (url)
5908   "Call `apropos' when pushing the corresponding URL button."
5909   (apropos-command
5910    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5911
5912 (defun gnus-button-handle-apropos-variable (url)
5913   "Call `apropos' when pushing the corresponding URL button."
5914   (funcall
5915    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
5916    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5917
5918 (defun gnus-button-handle-apropos-documentation (url)
5919   "Call `apropos' when pushing the corresponding URL button."
5920   (funcall
5921    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
5922    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5923
5924 (defun gnus-button-handle-library (url)
5925   "Call `locate-library' when pushing the corresponding URL button."
5926   (gnus-message 9 "url=`%s'" url)
5927   (let* ((lib (locate-library url))
5928          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
5929     (if (not lib)
5930         (gnus-message 1 "Cannot locale library `%s'." url)
5931       (find-file-read-only file))))
5932
5933 (defun gnus-button-handle-ctan (url)
5934   "Call `browse-url' when pushing a CTAN URL button."
5935   (funcall
5936    gnus-button-ctan-handler
5937    (concat
5938     gnus-ctan-url
5939     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
5940
5941 (defcustom gnus-button-tex-level 5
5942   "*Integer that says how many TeX-related buttons Gnus will show.
5943 The higher the number, the more buttons will appear and the more false
5944 positives are possible.  Note that you can set this variable local to
5945 specifific groups.  Setting it higher in TeX groups is probably a good idea.
5946 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5947 how to set variables in specific groups."
5948   :group 'gnus-article-buttons
5949   :link '(custom-manual "(gnus)Group Parameters")
5950   :type 'integer)
5951
5952 (defcustom gnus-button-man-level 5
5953   "*Integer that says how many man-related buttons Gnus will show.
5954 The higher the number, the more buttons will appear and the more false
5955 positives are possible.  Note that you can set this variable local to
5956 specifific groups.  Setting it higher in Unix groups is probably a good idea.
5957 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
5958 how to set variables in specific groups."
5959   :group 'gnus-article-buttons
5960   :link '(custom-manual "(gnus)Group Parameters")
5961   :type 'integer)
5962
5963 (defcustom gnus-button-emacs-level 5
5964   "*Integer that says how many emacs-related buttons Gnus will show.
5965 The higher the number, the more buttons will appear and the more false
5966 positives are possible.  Note that you can set this variable local to
5967 specifific groups.  Setting it higher in Emacs or Gnus related groups is
5968 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
5969 `gnus-parameters' on how to set variables in specific groups."
5970   :group 'gnus-article-buttons
5971   :link '(custom-manual "(gnus)Group Parameters")
5972   :type 'integer)
5973
5974 (defcustom gnus-button-message-level 5
5975   "*Integer that says how many buttons for news or mail messages will appear.
5976 The higher the number, the more buttons will appear and the more false
5977 positives are possible."
5978   ;; mail addresses, MIDs, URLs for news, ...
5979   :group 'gnus-article-buttons
5980   :type 'integer)
5981
5982 (defcustom gnus-button-browse-level 5
5983   "*Integer that says how many buttons for browsing will appear.
5984 The higher the number, the more buttons will appear and the more false
5985 positives are possible."
5986   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
5987   :group 'gnus-article-buttons
5988   :type 'integer)
5989
5990 (defcustom gnus-button-alist
5991   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5992      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
5993     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5994      gnus-button-handle-news 2)
5995     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5996      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
5997     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
5998      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
5999     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6000      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6001     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6002      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6003     ("mailto:\\([-a-z.@_+0-9%=?]+\\)"
6004      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6005     ("\\bmailto:\\([^ \n\t]+\\)"
6006      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6007     ;; CTAN
6008     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6009              gnus-button-ctan-directory-regexp
6010              "[^][>)!;:,'\n\t ]+\\)")
6011      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6012     ((concat "\\btex-archive/\\("
6013              gnus-button-ctan-directory-regexp
6014              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6015      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6016     ((concat
6017       "\\b\\("
6018       gnus-button-ctan-directory-regexp
6019       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6020      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6021     ;; This is info
6022     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)"
6023      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6024     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6025      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6026     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6027      ;; Info links like `C-h i d m CC Mode RET'
6028      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6029     ;; This is custom
6030     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6031      0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6032     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6033      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6034     ;; Emacs help commands
6035     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6036      ;; regexp doesn't match arguments containing ` '.
6037      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6038     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6039      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6040     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6041      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6042     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6043      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6044     ;; The following entries may lead to many false positives so don't enable
6045     ;; them by default (use a high button level):
6046     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>"
6047      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6048     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6049      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6050     ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6051      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6052     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6053      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6054     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6055      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6056     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6057      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6058     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6059      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6060     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6061      ;; Unlike the other regexps we really have to require quoting
6062      ;; here to determine where it ends.
6063      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6064     ;; This is how URLs _should_ be embedded in text (RFC 1738)...
6065     ("<URL: *\\([^<>]*\\)>"
6066      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6067     ;; Raw URLs.
6068     (gnus-button-url-regexp
6069      0 (>= gnus-button-browse-level 0) browse-url 0)
6070     ;; man pages
6071     ("\\b\\([a-z][a-z]+\\)([1-9])\\W"
6072      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6073      gnus-button-handle-man 1)
6074     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6075     ("\\b\\([a-z][-_.a-z0-9]+\\)([1-9])\\W"
6076      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6077      gnus-button-handle-man 1)
6078     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6079     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6080     ("\\b\\([a-z][-_.:a-z0-9]+\\)([1-9][X1a-z]*)\\W\\|\\b\\(X\\)([1-9])\\W"
6081      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6082     ;; MID or mail: To avoid too many false positives we don't try to catch
6083     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
6084     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
6085     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
6086     ;; so that non-ambiguous entries (see above) match first.
6087     (gnus-button-mid-or-mail-regexp
6088      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6089   "*Alist of regexps matching buttons in article bodies.
6090
6091 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6092 REGEXP: is the string (case insensitive) matching text around the button (can
6093 also be lisp expression evaluating to a string),
6094 BUTTON: is the number of the regexp grouping actually matching the button,
6095 FORM: is a lisp expression which must eval to true for the button to
6096 be added,
6097 CALLBACK: is the function to call when the user push this button, and each
6098 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6099
6100 CALLBACK can also be a variable, in that case the value of that
6101 variable it the real callback function."
6102   :group 'gnus-article-buttons
6103   :type '(repeat (list (choice regexp variable)
6104                        (integer :tag "Button")
6105                        (sexp :tag "Form")
6106                        (function :tag "Callback")
6107                        (repeat :tag "Par"
6108                                :inline t
6109                                (integer :tag "Regexp group")))))
6110
6111 (defcustom gnus-header-button-alist
6112   '(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
6113      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6114     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6115      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6116     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6117      0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6118     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6119      0 (>= gnus-button-browse-level 0) browse-url 0)
6120     ("^Subject:" gnus-button-url-regexp
6121      0 (>= gnus-button-browse-level 0) browse-url 0)
6122     ("^[^:]+:" gnus-button-url-regexp
6123      0 (>= gnus-button-browse-level 0) browse-url 0)
6124     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?]+\\)"
6125      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6126     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6127      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6128   "*Alist of headers and regexps to match buttons in article heads.
6129
6130 This alist is very similar to `gnus-button-alist', except that each
6131 alist has an additional HEADER element first in each entry:
6132
6133 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6134
6135 HEADER is a regexp to match a header.  For a fuller explanation, see
6136 `gnus-button-alist'."
6137   :group 'gnus-article-buttons
6138   :group 'gnus-article-headers
6139   :type '(repeat (list (regexp :tag "Header")
6140                        regexp
6141                        (integer :tag "Button")
6142                        (sexp :tag "Form")
6143                        (function :tag "Callback")
6144                        (repeat :tag "Par"
6145                                :inline t
6146                                (integer :tag "Regexp group")))))
6147
6148 (defvar gnus-button-regexp nil)
6149 (defvar gnus-button-marker-list nil)
6150 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6151
6152 (defvar gnus-button-last nil)
6153 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6154
6155 ;;; Commands:
6156
6157 (defun gnus-article-push-button (event)
6158   "Check text under the mouse pointer for a callback function.
6159 If the text under the mouse pointer has a `gnus-callback' property,
6160 call it with the value of the `gnus-data' text property."
6161   (interactive "e")
6162   (set-buffer (window-buffer (posn-window (event-start event))))
6163   (let* ((pos (posn-point (event-start event)))
6164          (data (get-text-property pos 'gnus-data))
6165          (fun (get-text-property pos 'gnus-callback)))
6166     (goto-char pos)
6167     (when fun
6168       (funcall fun data))))
6169
6170 (defun gnus-article-press-button ()
6171   "Check text at point for a callback function.
6172 If the text at point has a `gnus-callback' property,
6173 call it with the value of the `gnus-data' text property."
6174   (interactive)
6175   (let ((data (get-text-property (point) 'gnus-data))
6176         (fun (get-text-property (point) 'gnus-callback)))
6177     (when fun
6178       (funcall fun data))))
6179
6180 (defun gnus-article-highlight (&optional force)
6181   "Highlight current article.
6182 This function calls `gnus-article-highlight-headers',
6183 `gnus-article-highlight-citation',
6184 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6185 do the highlighting.  See the documentation for those functions."
6186   (interactive (list 'force))
6187   (gnus-article-highlight-headers)
6188   (gnus-article-highlight-citation force)
6189   (gnus-article-highlight-signature)
6190   (gnus-article-add-buttons force)
6191   (gnus-article-add-buttons-to-head))
6192
6193 (defun gnus-article-highlight-some (&optional force)
6194   "Highlight current article.
6195 This function calls `gnus-article-highlight-headers',
6196 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6197 do the highlighting.  See the documentation for those functions."
6198   (interactive (list 'force))
6199   (gnus-article-highlight-headers)
6200   (gnus-article-highlight-signature)
6201   (gnus-article-add-buttons))
6202
6203 (defun gnus-article-highlight-headers ()
6204   "Highlight article headers as specified by `gnus-header-face-alist'."
6205   (interactive)
6206   (save-excursion
6207     (set-buffer gnus-article-buffer)
6208     (save-restriction
6209       (let ((alist gnus-header-face-alist)
6210             (buffer-read-only nil)
6211             (case-fold-search t)
6212             (inhibit-point-motion-hooks t)
6213             entry regexp header-face field-face from hpoints fpoints)
6214         (article-narrow-to-head)
6215         (while (setq entry (pop alist))
6216           (goto-char (point-min))
6217           (setq regexp (concat "^\\("
6218                                (if (string-equal "" (nth 0 entry))
6219                                    "[^\t ]"
6220                                  (nth 0 entry))
6221                                "\\)")
6222                 header-face (nth 1 entry)
6223                 field-face (nth 2 entry))
6224           (while (and (re-search-forward regexp nil t)
6225                       (not (eobp)))
6226             (beginning-of-line)
6227             (setq from (point))
6228             (unless (search-forward ":" nil t)
6229               (forward-char 1))
6230             (when (and header-face
6231                        (not (memq (point) hpoints)))
6232               (push (point) hpoints)
6233               (gnus-put-text-property from (point) 'face header-face))
6234             (when (and field-face
6235                        (not (memq (setq from (point)) fpoints)))
6236               (push from fpoints)
6237               (if (re-search-forward "^[^ \t]" nil t)
6238                   (forward-char -2)
6239                 (goto-char (point-max)))
6240               (gnus-put-text-property from (point) 'face field-face))))))))
6241
6242 (defun gnus-article-highlight-signature ()
6243   "Highlight the signature in an article.
6244 It does this by highlighting everything after
6245 `gnus-signature-separator' using `gnus-signature-face'."
6246   (interactive)
6247   (save-excursion
6248     (set-buffer gnus-article-buffer)
6249     (let ((buffer-read-only nil)
6250           (inhibit-point-motion-hooks t))
6251       (save-restriction
6252         (when (and gnus-signature-face
6253                    (gnus-article-narrow-to-signature))
6254           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6255                             'face gnus-signature-face)
6256           (widen)
6257           (gnus-article-search-signature)
6258           (let ((start (match-beginning 0))
6259                 (end (set-marker (make-marker) (1+ (match-end 0)))))
6260             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6261                                      end)))))))
6262
6263 (defun gnus-button-in-region-p (b e prop)
6264   "Say whether PROP exists in the region."
6265   (text-property-not-all b e prop nil))
6266
6267 (defun gnus-article-add-buttons (&optional force)
6268   "Find external references in the article and make buttons of them.
6269 \"External references\" are things like Message-IDs and URLs, as
6270 specified by `gnus-button-alist'."
6271   (interactive (list 'force))
6272   (save-excursion
6273     (set-buffer gnus-article-buffer)
6274     (let ((buffer-read-only nil)
6275           (inhibit-point-motion-hooks t)
6276           (case-fold-search t)
6277           (alist gnus-button-alist)
6278           beg entry regexp)
6279       ;; Remove all old markers.
6280       (let (marker entry new-list)
6281         (while (setq marker (pop gnus-button-marker-list))
6282           (if (or (< marker (point-min)) (>= marker (point-max)))
6283               (push marker new-list)
6284             (goto-char marker)
6285             (when (setq entry (gnus-button-entry))
6286               (put-text-property (match-beginning (nth 1 entry))
6287                                  (match-end (nth 1 entry))
6288                                  'gnus-callback nil))
6289             (set-marker marker nil)))
6290         (setq gnus-button-marker-list new-list))
6291       ;; We skip the headers.
6292       (article-goto-body)
6293       (setq beg (point))
6294       (while (setq entry (pop alist))
6295         (setq regexp (eval (car entry)))
6296         (goto-char beg)
6297         (while (re-search-forward regexp nil t)
6298           (let* ((start (and entry (match-beginning (nth 1 entry))))
6299                  (end (and entry (match-end (nth 1 entry))))
6300                  (from (match-beginning 0)))
6301             (when (and (or (eq t (nth 2 entry))
6302                            (eval (nth 2 entry)))
6303                        (not (gnus-button-in-region-p
6304                              start end 'gnus-callback)))
6305               ;; That optional form returned non-nil, so we add the
6306               ;; button.
6307               (gnus-article-add-button
6308                start end 'gnus-button-push
6309                (car (push (set-marker (make-marker) from)
6310                           gnus-button-marker-list))))))))))
6311
6312 ;; Add buttons to the head of an article.
6313 (defun gnus-article-add-buttons-to-head ()
6314   "Add buttons to the head of the article."
6315   (interactive)
6316   (save-excursion
6317     (set-buffer gnus-article-buffer)
6318     (save-restriction
6319       (let ((buffer-read-only nil)
6320             (inhibit-point-motion-hooks t)
6321             (case-fold-search t)
6322             (alist gnus-header-button-alist)
6323             entry beg end)
6324         (article-narrow-to-head)
6325         (while alist
6326           ;; Each alist entry.
6327           (setq entry (car alist)
6328                 alist (cdr alist))
6329           (goto-char (point-min))
6330           (while (re-search-forward (car entry) nil t)
6331             ;; Each header matching the entry.
6332             (setq beg (match-beginning 0))
6333             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6334                                (match-beginning 0))
6335                           (point-max)))
6336             (goto-char beg)
6337             (while (re-search-forward (eval (nth 1 entry)) end t)
6338               ;; Each match within a header.
6339               (let* ((entry (cdr entry))
6340                      (start (match-beginning (nth 1 entry)))
6341                      (end (match-end (nth 1 entry)))
6342                      (form (nth 2 entry)))
6343                 (goto-char (match-end 0))
6344                 (when (eval form)
6345                   (gnus-article-add-button
6346                    start end (nth 3 entry)
6347                    (buffer-substring (match-beginning (nth 4 entry))
6348                                      (match-end (nth 4 entry)))))))
6349             (goto-char end)))))))
6350
6351 ;;; External functions:
6352
6353 (defun gnus-article-add-button (from to fun &optional data)
6354   "Create a button between FROM and TO with callback FUN and data DATA."
6355   (when gnus-article-button-face
6356     (gnus-overlay-put (gnus-make-overlay from to)
6357                       'face gnus-article-button-face))
6358   (gnus-add-text-properties
6359    from to
6360    (nconc (and gnus-article-mouse-face
6361                (list gnus-mouse-face-prop gnus-article-mouse-face))
6362           (list 'gnus-callback fun)
6363           (and data (list 'gnus-data data))))
6364   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6365                          :button-keymap gnus-widget-button-keymap))
6366
6367 ;;; Internal functions:
6368
6369 (defun gnus-article-set-globals ()
6370   (save-excursion
6371     (set-buffer gnus-summary-buffer)
6372     (gnus-set-global-variables)))
6373
6374 (defun gnus-signature-toggle (end)
6375   (save-excursion
6376     (set-buffer gnus-article-buffer)
6377     (let ((buffer-read-only nil)
6378           (inhibit-point-motion-hooks t))
6379       (if (text-property-any end (point-max) 'article-type 'signature)
6380           (progn
6381             (gnus-delete-wash-type 'signature)
6382             (gnus-remove-text-properties-when
6383              'article-type 'signature end (point-max)
6384              (cons 'article-type (cons 'signature
6385                                        gnus-hidden-properties))))
6386         (gnus-add-wash-type 'signature)
6387         (gnus-add-text-properties-when
6388          'article-type nil end (point-max)
6389          (cons 'article-type (cons 'signature
6390                                    gnus-hidden-properties)))))
6391     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6392       (gnus-set-mode-line 'article))))
6393
6394 (defun gnus-button-entry ()
6395   ;; Return the first entry in `gnus-button-alist' matching this place.
6396   (let ((alist gnus-button-alist)
6397         (entry nil))
6398     (while alist
6399       (setq entry (pop alist))
6400       (if (looking-at (eval (car entry)))
6401           (setq alist nil)
6402         (setq entry nil)))
6403     entry))
6404
6405 (defun gnus-button-push (marker)
6406   ;; Push button starting at MARKER.
6407   (save-excursion
6408     (goto-char marker)
6409     (let* ((entry (gnus-button-entry))
6410            (inhibit-point-motion-hooks t)
6411            (fun (nth 3 entry))
6412            (args (mapcar (lambda (group)
6413                            (let ((string (match-string group)))
6414                              (gnus-set-text-properties
6415                               0 (length string) nil string)
6416                              string))
6417                          (nthcdr 4 entry))))
6418       (cond
6419        ((fboundp fun)
6420         (apply fun args))
6421        ((and (boundp fun)
6422              (fboundp (symbol-value fun)))
6423         (apply (symbol-value fun) args))
6424        (t
6425         (gnus-message 1 "You must define `%S' to use this button"
6426                       (cons fun args)))))))
6427
6428 (defun gnus-parse-news-url (url)
6429   (let (scheme server group message-id articles)
6430     (with-temp-buffer
6431       (insert url)
6432       (goto-char (point-min))
6433       (when (looking-at "\\([A-Za-z]+\\):")
6434         (setq scheme (match-string 1))
6435         (goto-char (match-end 0)))
6436       (when (looking-at "//\\([^/]+\\)/")
6437         (setq server (match-string 1))
6438         (goto-char (match-end 0)))
6439
6440       (cond
6441        ((looking-at "\\(.*@.*\\)")
6442         (setq message-id (match-string 1)))
6443        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6444         (setq group (match-string 1)
6445               articles (split-string (match-string 2) "-")))
6446        ((looking-at "\\([^/]+\\)/?")
6447         (setq group (match-string 1)))
6448        (t
6449         (error "Unknown news URL syntax"))))
6450     (list scheme server group message-id articles)))
6451
6452 (defun gnus-button-handle-news (url)
6453   "Fetch a news URL."
6454   (destructuring-bind (scheme server group message-id articles)
6455       (gnus-parse-news-url url)
6456     (cond
6457      (message-id
6458       (save-excursion
6459         (set-buffer gnus-summary-buffer)
6460         (if server
6461             (let ((gnus-refer-article-method (list (list 'nntp server))))
6462               (gnus-summary-refer-article message-id))
6463           (gnus-summary-refer-article message-id))))
6464      (group
6465       (gnus-button-fetch-group url)))))
6466
6467 (defun gnus-button-handle-man (url)
6468   "Fetch a man page."
6469   (funcall gnus-button-man-handler url))
6470
6471 (defun gnus-button-handle-info-url (url)
6472   "Fetch an info URL."
6473   (cond
6474    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6475     (gnus-info-find-node
6476      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6477                      "Gnus")
6478              ")" (gnus-url-unhex-string (match-string 2 url)))))
6479    ((string-match "([^)\"]+)[^\"]+" url)
6480     (setq url
6481           (gnus-replace-in-string
6482            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6483     (gnus-info-find-node url))
6484    (t (error "Can't parse %s" url))))
6485
6486 (defun gnus-button-handle-info-keystrokes (url)
6487   "Call `info' when pushing the corresponding URL button."
6488   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6489   (info)
6490   (Info-directory)
6491   (Info-menu url))
6492
6493 (defun gnus-button-message-id (message-id)
6494   "Fetch MESSAGE-ID."
6495   (save-excursion
6496     (set-buffer gnus-summary-buffer)
6497     (gnus-summary-refer-article message-id)))
6498
6499 (defun gnus-button-fetch-group (address)
6500   "Fetch GROUP specified by ADDRESS."
6501   (if (not (string-match "[:/]" address))
6502       ;; This is just a simple group url.
6503       (gnus-group-read-ephemeral-group address gnus-select-method)
6504     (if (not
6505          (string-match
6506           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6507           address))
6508         (error "Can't parse %s" address)
6509       (gnus-group-read-ephemeral-group
6510        (match-string 4 address)
6511        `(nntp ,(match-string 1 address)
6512               (nntp-address ,(match-string 1 address))
6513               (nntp-port-number ,(if (match-end 3)
6514                                      (match-string 3 address)
6515                                    "nntp")))
6516        nil nil nil
6517        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6518
6519 (defun gnus-url-parse-query-string (query &optional downcase)
6520   (let (retval pairs cur key val)
6521     (setq pairs (split-string query "&"))
6522     (while pairs
6523       (setq cur (car pairs)
6524             pairs (cdr pairs))
6525       (if (not (string-match "=" cur))
6526           nil                           ; Grace
6527         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6528               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6529         (if downcase
6530             (setq key (downcase key)))
6531         (setq cur (assoc key retval))
6532         (if cur
6533             (setcdr cur (cons val (cdr cur)))
6534           (setq retval (cons (list key val) retval)))))
6535     retval))
6536
6537 (defun gnus-url-mailto (url)
6538   ;; Send mail to someone
6539   (when (string-match "mailto:/*\\(.*\\)" url)
6540     (setq url (substring url (match-beginning 1) nil)))
6541   (let (to args subject func)
6542     (if (string-match (regexp-quote "?") url)
6543         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6544               args (gnus-url-parse-query-string
6545                     (substring url (match-end 0) nil) t))
6546       (setq to (gnus-url-unhex-string url)))
6547     (setq args (cons (list "to" to) args)
6548           subject (cdr-safe (assoc "subject" args)))
6549     (gnus-msg-mail)
6550     (while args
6551       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6552       (if (fboundp func)
6553           (funcall func)
6554         (message-position-on-field (caar args)))
6555       (insert (mapconcat 'identity (cdar args) ", "))
6556       (setq args (cdr args)))
6557     (if subject
6558         (message-goto-body)
6559       (message-goto-subject))))
6560
6561 (defun gnus-button-embedded-url (address)
6562   "Activate ADDRESS with `browse-url'."
6563   (browse-url (gnus-strip-whitespace address)))
6564
6565 ;;; Next/prev buttons in the article buffer.
6566
6567 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6568 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6569
6570 (defvar gnus-prev-page-map
6571   (let ((map (make-sparse-keymap)))
6572     (unless (>= emacs-major-version 21)
6573       ;; XEmacs doesn't care.
6574       (set-keymap-parent map gnus-article-mode-map))
6575     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6576     (define-key map "\r" 'gnus-button-prev-page)
6577     map))
6578
6579 (defun gnus-insert-prev-page-button ()
6580   (let ((b (point))
6581         (buffer-read-only nil))
6582     (gnus-eval-format
6583      gnus-prev-page-line-format nil
6584      `(,@(gnus-local-map-property gnus-prev-page-map)
6585          gnus-prev t
6586          gnus-callback gnus-article-button-prev-page
6587          article-type annotation))
6588     (widget-convert-button
6589      'link b (if (bolp)
6590                  ;; Exclude a newline.
6591                  (1- (point))
6592                (point))
6593      :action 'gnus-button-prev-page
6594      :button-keymap gnus-prev-page-map)))
6595
6596 (defvar gnus-prev-page-map
6597   (let ((map (make-sparse-keymap)))
6598     (unless (>= emacs-major-version 21)
6599       ;; XEmacs doesn't care.
6600       (set-keymap-parent map gnus-article-mode-map))
6601     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6602     (define-key map "\r" 'gnus-button-prev-page)
6603     map))
6604
6605 (defvar gnus-next-page-map
6606   (let ((map (make-sparse-keymap)))
6607     (unless (>= emacs-major-version 21)
6608       ;; XEmacs doesn't care.
6609       (set-keymap-parent map gnus-article-mode-map))
6610     (define-key map gnus-mouse-2 'gnus-button-next-page)
6611     (define-key map "\r" 'gnus-button-next-page)
6612     map))
6613
6614 (defun gnus-button-next-page (&optional args more-args)
6615   "Go to the next page."
6616   (interactive)
6617   (let ((win (selected-window)))
6618     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6619     (gnus-article-next-page)
6620     (select-window win)))
6621
6622 (defun gnus-button-prev-page (&optional args more-args)
6623   "Go to the prev page."
6624   (interactive)
6625   (let ((win (selected-window)))
6626     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6627     (gnus-article-prev-page)
6628     (select-window win)))
6629
6630 (defun gnus-insert-next-page-button ()
6631   (let ((b (point))
6632         (buffer-read-only nil))
6633     (gnus-eval-format gnus-next-page-line-format nil
6634                       `(,@(gnus-local-map-property gnus-next-page-map)
6635                           gnus-next t
6636                           gnus-callback gnus-article-button-next-page
6637                           article-type annotation))
6638     (widget-convert-button
6639      'link b (if (bolp)
6640                  ;; Exclude a newline.
6641                  (1- (point))
6642                (point))
6643      :action 'gnus-button-next-page
6644      :button-keymap gnus-next-page-map)))
6645
6646 (defun gnus-article-button-next-page (arg)
6647   "Go to the next page."
6648   (interactive "P")
6649   (let ((win (selected-window)))
6650     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6651     (gnus-article-next-page)
6652     (select-window win)))
6653
6654 (defun gnus-article-button-prev-page (arg)
6655   "Go to the prev page."
6656   (interactive "P")
6657   (let ((win (selected-window)))
6658     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6659     (gnus-article-prev-page)
6660     (select-window win)))
6661
6662 (defvar gnus-decode-header-methods
6663   '(mail-decode-encoded-word-region)
6664   "List of methods used to decode headers.
6665
6666 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6667 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6668 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6669 whose names match REGEXP.
6670
6671 For example:
6672 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6673  mail-decode-encoded-word-region
6674  (\"chinese\" . rfc1843-decode-region))
6675 ")
6676
6677 (defvar gnus-decode-header-methods-cache nil)
6678
6679 (defun gnus-multi-decode-header (start end)
6680   "Apply the functions from `gnus-encoded-word-methods' that match."
6681   (unless (and gnus-decode-header-methods-cache
6682                (eq gnus-newsgroup-name
6683                    (car gnus-decode-header-methods-cache)))
6684     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6685     (mapcar (lambda (x)
6686               (if (symbolp x)
6687                   (nconc gnus-decode-header-methods-cache (list x))
6688                 (if (and gnus-newsgroup-name
6689                          (string-match (car x) gnus-newsgroup-name))
6690                     (nconc gnus-decode-header-methods-cache
6691                            (list (cdr x))))))
6692           gnus-decode-header-methods))
6693   (let ((xlist gnus-decode-header-methods-cache))
6694     (pop xlist)
6695     (save-restriction
6696       (narrow-to-region start end)
6697       (while xlist
6698         (funcall (pop xlist) (point-min) (point-max))))))
6699
6700 ;;;
6701 ;;; Treatment top-level handling.
6702 ;;;
6703
6704 (defun gnus-treat-article (condition &optional part-number total-parts type)
6705   (let ((length (- (point-max) (point-min)))
6706         (alist gnus-treatment-function-alist)
6707         (article-goto-body-goes-to-point-min-p t)
6708         (treated-type
6709          (or (not type)
6710              (catch 'found
6711                (let ((list gnus-article-treat-types))
6712                  (while list
6713                    (when (string-match (pop list) type)
6714                      (throw 'found t)))))))
6715         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6716         val elem)
6717     (gnus-run-hooks 'gnus-part-display-hook)
6718     (dolist (elem alist)
6719       (setq val
6720             (save-excursion
6721               (when (gnus-buffer-live-p gnus-summary-buffer)
6722                 (set-buffer gnus-summary-buffer))
6723               (symbol-value (car elem))))
6724       (when (and (or (consp val)
6725                      treated-type)
6726                  (gnus-treat-predicate val)
6727                  (or (not (get (car elem) 'highlight))
6728                      highlightp))
6729         (save-restriction
6730           (funcall (cadr elem)))))))
6731
6732 ;; Dynamic variables.
6733 (eval-when-compile
6734   (defvar part-number)
6735   (defvar total-parts)
6736   (defvar type)
6737   (defvar condition)
6738   (defvar length))
6739
6740 (defun gnus-treat-predicate (val)
6741   (cond
6742    ((null val)
6743     nil)
6744    (condition
6745     (eq condition val))
6746    ((and (listp val)
6747          (stringp (car val)))
6748     (apply 'gnus-or (mapcar `(lambda (s)
6749                                (string-match s ,(or gnus-newsgroup-name "")))
6750                             val)))
6751    ((listp val)
6752     (let ((pred (pop val)))
6753       (cond
6754        ((eq pred 'or)
6755         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6756        ((eq pred 'and)
6757         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6758        ((eq pred 'not)
6759         (not (gnus-treat-predicate (car val))))
6760        ((eq pred 'typep)
6761         (equal (car val) type))
6762        (t
6763         (error "%S is not a valid predicate" pred)))))
6764    ((eq val t)
6765     t)
6766    ((eq val 'head)
6767     nil)
6768    ((eq val 'last)
6769     (eq part-number total-parts))
6770    ((numberp val)
6771     (< length val))
6772    (t
6773     (error "%S is not a valid value" val))))
6774
6775 (defun gnus-article-encrypt-body (protocol &optional n)
6776   "Encrypt the article body."
6777   (interactive
6778    (list
6779     (or gnus-article-encrypt-protocol
6780         (completing-read "Encrypt protocol: "
6781                          gnus-article-encrypt-protocol-alist
6782                          nil t))
6783     current-prefix-arg))
6784   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6785     (unless func
6786       (error (format "Can't find the encrypt protocol %s" protocol)))
6787     (if (member gnus-newsgroup-name '("nndraft:delayed"
6788                                       "nndraft:drafts"
6789                                       "nndraft:queue"))
6790         (error "Can't encrypt the article in group %s"
6791                gnus-newsgroup-name))
6792     (gnus-summary-iterate n
6793       (save-excursion
6794         (set-buffer gnus-summary-buffer)
6795         (let ((mail-parse-charset gnus-newsgroup-charset)
6796               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6797               (summary-buffer gnus-summary-buffer)
6798               references point)
6799           (gnus-set-global-variables)
6800           (when (gnus-group-read-only-p)
6801             (error "The current newsgroup does not support article encrypt"))
6802           (gnus-summary-show-article t)
6803           (setq references
6804               (or (mail-header-references gnus-current-headers) ""))
6805           (set-buffer gnus-article-buffer)
6806           (let* ((buffer-read-only nil)
6807                  (headers
6808                   (mapcar (lambda (field)
6809                             (and (save-restriction
6810                                    (message-narrow-to-head)
6811                                    (goto-char (point-min))
6812                                    (search-forward field nil t))
6813                                  (prog2
6814                                      (message-narrow-to-field)
6815                                      (buffer-string)
6816                                    (delete-region (point-min) (point-max))
6817                                    (widen))))
6818                           '("Content-Type:" "Content-Transfer-Encoding:"
6819                             "Content-Disposition:"))))
6820             (message-narrow-to-head)
6821             (message-remove-header "MIME-Version")
6822             (goto-char (point-max))
6823             (setq point (point))
6824             (insert (apply 'concat headers))
6825             (widen)
6826             (narrow-to-region point (point-max))
6827             (let ((message-options message-options))
6828               (message-options-set 'message-sender user-mail-address)
6829               (message-options-set 'message-recipients user-mail-address)
6830               (message-options-set 'message-sign-encrypt 'not)
6831               (funcall func))
6832             (goto-char (point-min))
6833             (insert "MIME-Version: 1.0\n")
6834             (widen)
6835             (gnus-summary-edit-article-done
6836              references nil summary-buffer t))
6837           (when gnus-keep-backlog
6838             (gnus-backlog-remove-article
6839              (car gnus-article-current) (cdr gnus-article-current)))
6840           (save-excursion
6841             (when (get-buffer gnus-original-article-buffer)
6842               (set-buffer gnus-original-article-buffer)
6843               (setq gnus-original-article nil)))
6844           (when gnus-use-cache
6845             (gnus-cache-update-article
6846              (car gnus-article-current) (cdr gnus-article-current))))))))
6847
6848 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6849   "The following specs can be used:
6850 %t  The security MIME type
6851 %i  Additional info
6852 %d  Details
6853 %D  Details if button is pressed")
6854
6855 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6856   "The following specs can be used:
6857 %t  The security MIME type
6858 %i  Additional info
6859 %d  Details
6860 %D  Details if button is pressed")
6861
6862 (defvar gnus-mime-security-button-line-format-alist
6863   '((?t gnus-tmp-type ?s)
6864     (?i gnus-tmp-info ?s)
6865     (?d gnus-tmp-details ?s)
6866     (?D gnus-tmp-pressed-details ?s)))
6867
6868 (defvar gnus-mime-security-button-map
6869   (let ((map (make-sparse-keymap)))
6870     (unless (>= (string-to-number emacs-version) 21)
6871       (set-keymap-parent map gnus-article-mode-map))
6872     (define-key map gnus-mouse-2 'gnus-article-push-button)
6873     (define-key map "\r" 'gnus-article-press-button)
6874     map))
6875
6876 (defvar gnus-mime-security-details-buffer nil)
6877
6878 (defvar gnus-mime-security-button-pressed nil)
6879
6880 (defvar gnus-mime-security-show-details-inline t
6881   "If non-nil, show details in the article buffer.")
6882
6883 (defun gnus-mime-security-verify-or-decrypt (handle)
6884   (mm-remove-parts (cdr handle))
6885   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6886         point buffer-read-only)
6887     (if region
6888         (goto-char (car region)))
6889     (save-restriction
6890       (narrow-to-region (point) (point))
6891       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6892         (let* ((mm-verify-option 'known)
6893                (mm-decrypt-option 'known)
6894                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6895           (unless (eq nparts (cdr handle))
6896             (mm-destroy-parts (cdr handle))
6897             (setcdr handle nparts))))
6898       (setq point (point))
6899       (gnus-mime-display-security handle)
6900       (goto-char (point-max)))
6901     (when region
6902       (delete-region (point) (cdr region))
6903       (set-marker (car region) nil)
6904       (set-marker (cdr region) nil))
6905     (goto-char point)))
6906
6907 (defun gnus-mime-security-show-details (handle)
6908   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6909     (if (not details)
6910         (gnus-message 5 "No details.")
6911       (if gnus-mime-security-show-details-inline
6912           (let ((gnus-mime-security-button-pressed
6913                  (not (get-text-property (point) 'gnus-mime-details)))
6914                 (gnus-mime-security-button-line-format
6915                  (get-text-property (point) 'gnus-line-format))
6916                 buffer-read-only)
6917             (forward-char -1)
6918             (while (eq (get-text-property (point) 'gnus-line-format)
6919                        gnus-mime-security-button-line-format)
6920               (forward-char -1))
6921             (forward-char)
6922             (save-restriction
6923               (narrow-to-region (point) (point))
6924               (gnus-insert-mime-security-button handle))
6925             (delete-region (point)
6926                            (or (text-property-not-all
6927                                 (point) (point-max)
6928                                 'gnus-line-format
6929                                 gnus-mime-security-button-line-format)
6930                                (point-max))))
6931         ;; Not inlined.
6932         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6933             (with-current-buffer gnus-mime-security-details-buffer
6934               (erase-buffer)
6935               t)
6936           (setq gnus-mime-security-details-buffer
6937                 (gnus-get-buffer-create "*MIME Security Details*")))
6938         (with-current-buffer gnus-mime-security-details-buffer
6939           (insert details)
6940           (goto-char (point-min)))
6941         (pop-to-buffer gnus-mime-security-details-buffer)))))
6942
6943 (defun gnus-mime-security-press-button (handle)
6944   (save-excursion
6945     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6946         (gnus-mime-security-show-details handle)
6947       (gnus-mime-security-verify-or-decrypt handle))))
6948
6949 (defun gnus-insert-mime-security-button (handle &optional displayed)
6950   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6951          (gnus-tmp-type
6952           (concat
6953            (or (nth 2 (assoc protocol mm-verify-function-alist))
6954                (nth 2 (assoc protocol mm-decrypt-function-alist))
6955                "Unknown")
6956            (if (equal (car handle) "multipart/signed")
6957                " Signed" " Encrypted")
6958            " Part"))
6959          (gnus-tmp-info
6960           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6961               "Undecided"))
6962          (gnus-tmp-details
6963           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6964          gnus-tmp-pressed-details
6965          b e)
6966     (setq gnus-tmp-details
6967           (if gnus-tmp-details
6968               (concat "\n" gnus-tmp-details)
6969             ""))
6970     (setq gnus-tmp-pressed-details
6971           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6972     (unless (bolp)
6973       (insert "\n"))
6974     (setq b (point))
6975     (gnus-eval-format
6976      gnus-mime-security-button-line-format
6977      gnus-mime-security-button-line-format-alist
6978      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6979          gnus-callback gnus-mime-security-press-button
6980          gnus-line-format ,gnus-mime-security-button-line-format
6981          gnus-mime-details ,gnus-mime-security-button-pressed
6982          article-type annotation
6983          gnus-data ,handle))
6984     (setq e (if (bolp)
6985                 ;; Exclude a newline.
6986                 (1- (point))
6987               (point)))
6988     (widget-convert-button
6989      'link b e
6990      :mime-handle handle
6991      :action 'gnus-widget-press-button
6992      :button-keymap gnus-mime-security-button-map
6993      :help-echo
6994      (lambda (widget/window &optional overlay pos)
6995        ;; Needed to properly clear the message due to a bug in
6996        ;; wid-edit (XEmacs only).
6997        (when (boundp 'help-echo-owns-message)
6998          (setq help-echo-owns-message t))
6999        (format
7000         "%S: show detail"
7001         (aref gnus-mouse-2 0))))))
7002
7003 (defun gnus-mime-display-security (handle)
7004   (save-restriction
7005     (narrow-to-region (point) (point))
7006     (unless (gnus-unbuttonized-mime-type-p (car handle))
7007       (gnus-insert-mime-security-button handle))
7008     (gnus-mime-display-mixed (cdr handle))
7009     (unless (bolp)
7010       (insert "\n"))
7011     (unless (gnus-unbuttonized-mime-type-p (car handle))
7012       (let ((gnus-mime-security-button-line-format
7013              gnus-mime-security-button-end-line-format))
7014         (gnus-insert-mime-security-button handle)))
7015     (mm-set-handle-multipart-parameter
7016      handle 'gnus-region
7017      (cons (set-marker (make-marker) (point-min))
7018            (set-marker (make-marker) (point-max))))))
7019
7020 (gnus-ems-redefine)
7021
7022 (provide 'gnus-art)
7023
7024 (run-hooks 'gnus-art-load-hook)
7025
7026 ;;; gnus-art.el ends here