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