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