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