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