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