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