f2fa92f4345d00108cca52b3797f26bef34fb6e1
[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-strip-list-identifiers gnus-article-hide-list-identifiers)
1329     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1330     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1331     (gnus-treat-strip-pem gnus-article-hide-pem)
1332     (gnus-treat-from-picon gnus-treat-from-picon)
1333     (gnus-treat-mail-picon gnus-treat-mail-picon)
1334     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1335     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1336     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1337     (gnus-treat-strip-trailing-blank-lines
1338      gnus-article-remove-trailing-blank-lines)
1339     (gnus-treat-strip-leading-blank-lines
1340      gnus-article-strip-leading-blank-lines)
1341     (gnus-treat-strip-multiple-blank-lines
1342      gnus-article-strip-multiple-blank-lines)
1343     (gnus-treat-overstrike gnus-article-treat-overstrike)
1344     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1345     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1346     ;; Displaying X-Face should be done after unfolding headers
1347     ;; to protect bitmap lines.
1348     (gnus-treat-display-xface gnus-article-display-x-face)
1349     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1350     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1351     (gnus-treat-display-smileys gnus-treat-smiley)
1352     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1353     (gnus-treat-emphasize gnus-article-emphasize)
1354     (gnus-treat-hide-citation gnus-article-hide-citation)
1355     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1356     (gnus-treat-highlight-citation gnus-article-highlight-citation)
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         (url-gateway-unplugged t)
2287         (w3-honor-stylesheets nil)
2288         (w3-delay-image-loads t))
2289     (condition-case var
2290         (w3-region (point-min) (point-max))
2291       (error))))
2292
2293 (defun gnus-article-wash-html-with-w3m ()
2294   "Wash the current buffer with emacs-w3m."
2295   (mm-setup-w3m)
2296   (save-restriction
2297     (narrow-to-region (point) (point-max))
2298     (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2299                                    nil
2300                                  "\\`cid:"))
2301           (w3m-display-inline-images mm-inline-text-html-with-images)
2302           w3m-force-redisplay)
2303       (w3m-region (point-min) (point-max)))
2304     (when mm-inline-text-html-with-w3m-keymap
2305       (add-text-properties
2306        (point-min) (point-max)
2307        (append '(mm-inline-text-html-with-w3m t)
2308                (gnus-local-map-property mm-w3m-mode-map))))))
2309
2310 (defun article-hide-list-identifiers ()
2311   "Remove list identifies from the Subject header.
2312 The `gnus-list-identifiers' variable specifies what to do."
2313   (interactive)
2314   (let ((inhibit-point-motion-hooks t)
2315         (regexp (if (consp gnus-list-identifiers)
2316                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2317                   gnus-list-identifiers))
2318         buffer-read-only)
2319     (when regexp
2320       (save-excursion
2321         (save-restriction
2322           (article-narrow-to-head)
2323           (goto-char (point-min))
2324           (while (re-search-forward
2325                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2326                   nil t)
2327             (delete-region (match-beginning 2) (match-end 0))
2328             (beginning-of-line))
2329           (when (re-search-forward
2330                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2331             (delete-region (match-beginning 1) (match-end 1))))))))
2332
2333 (defun article-hide-pgp ()
2334   "Remove any PGP headers and signatures in the current article."
2335   (interactive)
2336   (save-excursion
2337     (save-restriction
2338       (let ((inhibit-point-motion-hooks t)
2339             buffer-read-only beg end)
2340         (article-goto-body)
2341         ;; Hide the "header".
2342         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2343           (gnus-add-wash-type 'pgp)
2344           (delete-region (match-beginning 0) (match-end 0))
2345           ;; Remove armor headers (rfc2440 6.2)
2346           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2347                                      (point)))
2348           (setq beg (point))
2349           ;; Hide the actual signature.
2350           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2351                (setq end (1+ (match-beginning 0)))
2352                (delete-region
2353                 end
2354                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2355                     (match-end 0)
2356                   ;; Perhaps we shouldn't hide to the end of the buffer
2357                   ;; if there is no end to the signature?
2358                   (point-max))))
2359           ;; Hide "- " PGP quotation markers.
2360           (when (and beg end)
2361             (narrow-to-region beg end)
2362             (goto-char (point-min))
2363             (while (re-search-forward "^- " nil t)
2364               (delete-region
2365                (match-beginning 0) (match-end 0)))
2366             (widen))
2367           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2368
2369 (defun article-hide-pem (&optional arg)
2370   "Toggle hiding of any PEM headers and signatures in the current article.
2371 If given a negative prefix, always show; if given a positive prefix,
2372 always hide."
2373   (interactive (gnus-article-hidden-arg))
2374   (unless (gnus-article-check-hidden-text 'pem arg)
2375     (save-excursion
2376       (let (buffer-read-only end)
2377         (goto-char (point-min))
2378         ;; Hide the horrendously ugly "header".
2379         (when (and (search-forward
2380                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2381                     nil t)
2382                    (setq end (1+ (match-beginning 0))))
2383           (gnus-add-wash-type 'pem)
2384           (gnus-article-hide-text-type
2385            end
2386            (if (search-forward "\n\n" nil t)
2387                (match-end 0)
2388              (point-max))
2389            'pem)
2390           ;; Hide the trailer as well
2391           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2392                                 nil t)
2393             (gnus-article-hide-text-type
2394              (match-beginning 0) (match-end 0) 'pem)))))))
2395
2396 (defun article-strip-banner ()
2397   "Strip the banner specified by the `banner' group parameter."
2398   (interactive)
2399   (save-excursion
2400     (save-restriction
2401       (let ((inhibit-point-motion-hooks t)
2402             (banner (gnus-parameter-banner gnus-newsgroup-name))
2403             (gnus-signature-limit nil)
2404             buffer-read-only beg end)
2405         (when banner
2406           (article-goto-body)
2407           (cond
2408            ((eq banner 'signature)
2409             (when (gnus-article-narrow-to-signature)
2410               (widen)
2411               (forward-line -1)
2412               (delete-region (point) (point-max))))
2413            ((symbolp banner)
2414             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2415                 (while (re-search-forward banner nil t)
2416                   (delete-region (match-beginning 0) (match-end 0)))))
2417            ((stringp banner)
2418             (while (re-search-forward banner nil t)
2419               (delete-region (match-beginning 0) (match-end 0))))))))))
2420
2421 (defun article-babel ()
2422   "Translate article using an online translation service."
2423   (interactive)
2424   (require 'babel)
2425   (save-excursion
2426     (set-buffer gnus-article-buffer)
2427     (when (article-goto-body)
2428       (let* ((buffer-read-only nil)
2429              (start (point))
2430              (end (point-max))
2431              (orig (buffer-substring start end))
2432              (trans (babel-as-string orig)))
2433         (save-restriction
2434           (narrow-to-region start end)
2435           (delete-region start end)
2436           (insert trans))))))
2437
2438 (defun article-hide-signature (&optional arg)
2439   "Hide the signature in the current article.
2440 If given a negative prefix, always show; if given a positive prefix,
2441 always hide."
2442   (interactive (gnus-article-hidden-arg))
2443   (save-excursion
2444     (save-restriction
2445       (if (interactive-p)
2446           (progn
2447             (widen)
2448             (article-goto-body))
2449         (goto-char (point-min)))
2450       (unless (gnus-article-check-hidden-text 'signature arg)
2451         (let ((buffer-read-only nil)
2452               (button (point)))
2453           (while (setq button (text-property-any button (point-max)
2454                                                  'gnus-callback
2455                                                  'gnus-signature-toggle))
2456             (setq button (text-property-not-all button (point-max)
2457                                                 'gnus-callback
2458                                                 'gnus-signature-toggle))
2459             (when (and button (not (eobp)))
2460               (gnus-article-hide-text-type
2461                (1+ button)
2462                (next-single-property-change (1+ button) 'mime-view-entity
2463                                             nil (point-max))
2464                'signature)))))))
2465   (gnus-set-mode-line 'article))
2466
2467 (defun article-strip-headers-in-body ()
2468   "Strip offensive headers from bodies."
2469   (interactive)
2470   (save-excursion
2471     (article-goto-body)
2472     (let ((case-fold-search t))
2473       (when (looking-at "x-no-archive:")
2474         (gnus-delete-line)))))
2475
2476 (defun article-strip-leading-blank-lines ()
2477   "Remove all blank lines from the beginning of the article."
2478   (interactive)
2479   (save-excursion
2480     (let ((inhibit-point-motion-hooks t)
2481           buffer-read-only)
2482       (when (article-goto-body)
2483         (while (and (not (eobp))
2484                     (looking-at "[ \t]*$"))
2485           (gnus-delete-line))))))
2486
2487 (defun article-narrow-to-head ()
2488   "Narrow the buffer to the head of the message.
2489 Point is left at the beginning of the narrowed-to region."
2490   (narrow-to-region
2491    (goto-char (point-min))
2492    (if (search-forward "\n\n" nil 1)
2493        (1- (point))
2494      (point-max)))
2495   (goto-char (point-min)))
2496
2497 (defun article-goto-body ()
2498   "Place point at the start of the body."
2499   (goto-char (point-min))
2500   (cond
2501    ;; This variable is only bound when dealing with separate
2502    ;; MIME body parts.
2503    (article-goto-body-goes-to-point-min-p
2504     t)
2505    ((search-forward "\n\n" nil t)
2506     t)
2507    (t
2508     (goto-char (point-max))
2509     nil)))
2510
2511 (defun article-strip-multiple-blank-lines ()
2512   "Replace consecutive blank lines with one empty line."
2513   (interactive)
2514   (save-excursion
2515     (let ((inhibit-point-motion-hooks t)
2516           buffer-read-only)
2517       ;; First make all blank lines empty.
2518       (article-goto-body)
2519       (while (re-search-forward "^[ \t]+$" nil t)
2520         (unless (gnus-annotation-in-region-p
2521                  (match-beginning 0) (match-end 0))
2522           (replace-match "" nil t)))
2523       ;; Then replace multiple empty lines with a single empty line.
2524       (article-goto-body)
2525       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2526         (unless (gnus-annotation-in-region-p
2527                  (match-beginning 0) (match-end 0))
2528           (delete-region (match-beginning 1) (match-end 1)))))))
2529
2530 (defun article-strip-leading-space ()
2531   "Remove all white space from the beginning of the lines in the article."
2532   (interactive)
2533   (save-excursion
2534     (let ((inhibit-point-motion-hooks t)
2535           buffer-read-only)
2536       (article-goto-body)
2537       (while (re-search-forward "^[ \t]+" nil t)
2538         (replace-match "" t t)))))
2539
2540 (defun article-strip-trailing-space ()
2541   "Remove all white space from the end of the lines in the article."
2542   (interactive)
2543   (save-excursion
2544     (let ((inhibit-point-motion-hooks t)
2545           buffer-read-only)
2546       (article-goto-body)
2547       (while (re-search-forward "[ \t]+$" nil t)
2548         (replace-match "" t t)))))
2549
2550 (defun article-strip-blank-lines ()
2551   "Strip leading, trailing and multiple blank lines."
2552   (interactive)
2553   (article-strip-leading-blank-lines)
2554   (article-remove-trailing-blank-lines)
2555   (article-strip-multiple-blank-lines))
2556
2557 (defun article-strip-all-blank-lines ()
2558   "Strip all blank lines."
2559   (interactive)
2560   (save-excursion
2561     (let ((inhibit-point-motion-hooks t)
2562           buffer-read-only)
2563       (article-goto-body)
2564       (while (re-search-forward "^[ \t]*\n" nil t)
2565         (replace-match "" t t)))))
2566
2567 (defun gnus-article-narrow-to-signature ()
2568   "Narrow to the signature; return t if a signature is found, else nil."
2569   (let ((inhibit-point-motion-hooks t))
2570     (when (gnus-article-search-signature)
2571       (forward-line 1)
2572       ;; Check whether we have some limits to what we consider
2573       ;; to be a signature.
2574       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2575                       (list gnus-signature-limit)))
2576             limit limited)
2577         (while (setq limit (pop limits))
2578           (if (or (and (integerp limit)
2579                        (< (- (point-max) (point)) limit))
2580                   (and (floatp limit)
2581                        (< (count-lines (point) (point-max)) limit))
2582                   (and (gnus-functionp limit)
2583                        (funcall limit))
2584                   (and (stringp limit)
2585                        (not (re-search-forward limit nil t))))
2586               ()                        ; This limit did not succeed.
2587             (setq limited t
2588                   limits nil)))
2589         (unless limited
2590           (narrow-to-region (point) (point-max))
2591           t)))))
2592
2593 (defun gnus-article-search-signature ()
2594   "Search the current buffer for the signature separator.
2595 Put point at the beginning of the signature separator."
2596   (let ((cur (point)))
2597     (goto-char (point-max))
2598     (if (if (stringp gnus-signature-separator)
2599             (re-search-backward gnus-signature-separator nil t)
2600           (let ((seps gnus-signature-separator))
2601             (while (and seps
2602                         (not (re-search-backward (car seps) nil t)))
2603               (pop seps))
2604             seps))
2605         t
2606       (goto-char cur)
2607       nil)))
2608
2609 (defun gnus-article-hidden-arg ()
2610   "Return the current prefix arg as a number, or 0 if no prefix."
2611   (list (if current-prefix-arg
2612             (prefix-numeric-value current-prefix-arg)
2613           0)))
2614
2615 (defun gnus-article-check-hidden-text (type arg)
2616   "Return nil if hiding is necessary.
2617 Arg can be nil or a number.  nil and positive means hide, negative
2618 means show, 0 means toggle."
2619   (save-excursion
2620     (save-restriction
2621       (let ((hide (gnus-article-hidden-text-p type)))
2622         (cond
2623          ((or (null arg)
2624               (> arg 0))
2625           nil)
2626          ((< arg 0)
2627           (gnus-article-show-hidden-text type)
2628           t)
2629          (t
2630           (if (eq hide 'hidden)
2631               (progn
2632                 (gnus-article-show-hidden-text type)
2633                 t)
2634             nil)))))))
2635
2636 (defun gnus-article-hidden-text-p (type)
2637   "Say whether the current buffer contains hidden text of type TYPE."
2638   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2639     (while (and pos
2640                 (not (get-text-property pos 'invisible))
2641                 (not (get-text-property pos 'dummy-invisible)))
2642       (setq pos
2643             (text-property-any (1+ pos) (point-max) 'article-type type)))
2644     (if pos
2645         'hidden
2646       nil)))
2647
2648 (defun gnus-article-show-hidden-text (type &optional dummy)
2649   "Show all hidden text of type TYPE.
2650 Originally it is hide instead of DUMMY."
2651   (let ((buffer-read-only nil)
2652         (inhibit-point-motion-hooks t))
2653     (gnus-remove-text-properties-when
2654      'article-type type
2655      (point-min) (point-max)
2656      (cons 'article-type (cons type
2657                                gnus-hidden-properties)))
2658     (gnus-delete-wash-type type)))
2659
2660 (defconst article-time-units
2661   `((year . ,(* 365.25 24 60 60))
2662     (week . ,(* 7 24 60 60))
2663     (day . ,(* 24 60 60))
2664     (hour . ,(* 60 60))
2665     (minute . 60)
2666     (second . 1))
2667   "Mapping from time units to seconds.")
2668
2669 (defun article-date-ut (&optional type highlight header)
2670   "Convert DATE date to universal time in the current article.
2671 If TYPE is `local', convert to local time; if it is `lapsed', output
2672 how much time has lapsed since DATE.  For `lapsed', the value of
2673 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2674 should replace the \"Date:\" one, or should be added below it."
2675   (interactive (list 'ut t))
2676   (let* ((header (or header
2677                      (and (eq 1 (point-min))
2678                           (mail-header-date (save-excursion
2679                                               (set-buffer gnus-summary-buffer)
2680                                               gnus-current-headers)))
2681                      (message-fetch-field "date")
2682                      ""))
2683          (date (if (vectorp header) (mail-header-date header)
2684                  header))
2685          (inhibit-point-motion-hooks t)
2686          bface eface date-pos)
2687     (when (and date (not (string= date "")))
2688       (save-excursion
2689         (save-restriction
2690           (article-narrow-to-head)
2691           (when (or (and (eq type 'lapsed)
2692                          gnus-article-date-lapsed-new-header
2693                          ;; Attempt to get the face of X-Sent first.
2694                          (re-search-forward "^X-Sent:[ \t]" nil t))
2695                     (re-search-forward "^Date:[ \t]" nil t)
2696                     ;; If Date is missing, try again for X-Sent.
2697                     (re-search-forward "^X-Sent:[ \t]" nil t))
2698             (setq bface (get-text-property (gnus-point-at-bol) 'face)
2699                   date (or (get-text-property (gnus-point-at-bol)
2700                                               'original-date)
2701                            date)
2702                   eface (get-text-property (1- (gnus-point-at-eol))
2703                                            'face)))
2704           (let ((buffer-read-only nil))
2705             ;; Delete any old X-Sent headers.
2706             (when (setq date-pos
2707                         (text-property-any (point-min) (point-max)
2708                                            'article-date-lapsed t))
2709               (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2710               (delete-region (match-beginning 0)
2711                              (progn (forward-line 1) (point))))
2712             (goto-char (point-min))
2713             ;; Delete any old Date headers.
2714             (while (re-search-forward "^Date:[ \t]" nil t)
2715               (unless date-pos
2716                 (setq date-pos (match-beginning 0)))
2717               (unless (and (eq type 'lapsed)
2718                            gnus-article-date-lapsed-new-header)
2719                 (delete-region (match-beginning 0)
2720                                (progn (message-next-header) (point)))))
2721             (if date-pos
2722                 (progn
2723                   (goto-char date-pos)
2724                   (unless (bolp)
2725                     ;; Possibly, Date has been deleted.
2726                     (insert "\n"))
2727                   (when (and (eq type 'lapsed)
2728                              gnus-article-date-lapsed-new-header
2729                              (looking-at "Date:"))
2730                     (forward-line 1)))
2731               (goto-char (point-min)))
2732             (insert (article-make-date-line date type))
2733             (when (eq type 'lapsed)
2734               (put-text-property (gnus-point-at-bol) (point)
2735                                  'article-date-lapsed t))
2736             (insert "\n")
2737             (forward-line -1)
2738             ;; Do highlighting.
2739             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2740               (put-text-property (match-beginning 1) (1+ (match-end 1))
2741                                  'original-date date)
2742               (put-text-property (match-beginning 1) (1+ (match-end 1))
2743                                  'face bface)
2744               (put-text-property (match-beginning 2) (match-end 2)
2745                                  'face eface))))))))
2746
2747 (defun article-make-date-line (date type)
2748   "Return a DATE line of TYPE."
2749   (unless (memq type '(local ut original user iso8601 lapsed english))
2750     (error "Unknown conversion type: %s" type))
2751   (condition-case ()
2752       (let ((time (date-to-time date)))
2753         (cond
2754          ;; Convert to the local timezone.
2755          ((eq type 'local)
2756           (let ((tz (car (current-time-zone time))))
2757             (format "Date: %s %s%02d%02d" (current-time-string time)
2758                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2759                     (/ (% (abs tz) 3600) 60))))
2760          ;; Convert to Universal Time.
2761          ((eq type 'ut)
2762           (concat "Date: "
2763                   (current-time-string
2764                    (let* ((e (parse-time-string date))
2765                           (tm (apply 'encode-time e))
2766                           (ms (car tm))
2767                           (ls (- (cadr tm) (car (current-time-zone time)))))
2768                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2769                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2770                            (t (list ms ls)))))
2771                   " UT"))
2772          ;; Get the original date from the article.
2773          ((eq type 'original)
2774           (concat "Date: " (if (string-match "\n+$" date)
2775                                (substring date 0 (match-beginning 0))
2776                              date)))
2777          ;; Let the user define the format.
2778          ((eq type 'user)
2779           (if (gnus-functionp gnus-article-time-format)
2780               (funcall gnus-article-time-format time)
2781             (concat
2782              "Date: "
2783              (format-time-string gnus-article-time-format time))))
2784          ;; ISO 8601.
2785          ((eq type 'iso8601)
2786           (let ((tz (car (current-time-zone time))))
2787             (concat
2788              "Date: "
2789              (format-time-string "%Y%m%dT%H%M%S" time)
2790              (format "%s%02d%02d"
2791                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2792                      (/ (% (abs tz) 3600) 60)))))
2793          ;; Do an X-Sent lapsed format.
2794          ((eq type 'lapsed)
2795           ;; If the date is seriously mangled, the timezone functions are
2796           ;; liable to bug out, so we ignore all errors.
2797           (let* ((now (current-time))
2798                  (real-time (subtract-time now time))
2799                  (real-sec (and real-time
2800                                 (+ (* (float (car real-time)) 65536)
2801                                    (cadr real-time))))
2802                  (sec (and real-time (abs real-sec)))
2803                  num prev)
2804             (cond
2805              ((null real-time)
2806               "X-Sent: Unknown")
2807              ((zerop sec)
2808               "X-Sent: Now")
2809              (t
2810               (concat
2811                "X-Sent: "
2812                ;; This is a bit convoluted, but basically we go
2813                ;; through the time units for years, weeks, etc,
2814                ;; and divide things to see whether that results
2815                ;; in positive answers.
2816                (mapconcat
2817                 (lambda (unit)
2818                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2819                       ;; The (remaining) seconds are too few to
2820                       ;; be divided into this time unit.
2821                       ""
2822                     ;; It's big enough, so we output it.
2823                     (setq sec (- sec (* num (cdr unit))))
2824                     (prog1
2825                         (concat (if prev ", " "") (int-to-string
2826                                                    (floor num))
2827                                 " " (symbol-name (car unit))
2828                                 (if (> num 1) "s" ""))
2829                       (setq prev t))))
2830                 article-time-units "")
2831                ;; If dates are odd, then it might appear like the
2832                ;; article was sent in the future.
2833                (if (> real-sec 0)
2834                    " ago"
2835                  " in the future"))))))
2836          ;; Display the date in proper English
2837          ((eq type 'english)
2838           (let ((dtime (decode-time time)))
2839             (concat
2840              "Date: the "
2841              (number-to-string (nth 3 dtime))
2842              (let ((digit (% (nth 3 dtime) 10)))
2843                (cond
2844                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2845                 ((= digit 1) "st")
2846                 ((= digit 2) "nd")
2847                 ((= digit 3) "rd")
2848                 (t "th")))
2849              " of "
2850              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2851              " "
2852              (number-to-string (nth 5 dtime))
2853              " at "
2854              (format "%02d" (nth 2 dtime))
2855              ":"
2856              (format "%02d" (nth 1 dtime)))))))
2857     (error
2858      (format "Date: %s (from Oort)" date))))
2859
2860 (defun article-date-local (&optional highlight)
2861   "Convert the current article date to the local timezone."
2862   (interactive (list t))
2863   (article-date-ut 'local highlight))
2864
2865 (defun article-date-english (&optional highlight)
2866   "Convert the current article date to something that is proper English."
2867   (interactive (list t))
2868   (article-date-ut 'english highlight))
2869
2870 (defun article-date-original (&optional highlight)
2871   "Convert the current article date to what it was originally.
2872 This is only useful if you have used some other date conversion
2873 function and want to see what the date was before converting."
2874   (interactive (list t))
2875   (article-date-ut 'original highlight))
2876
2877 (defun article-date-lapsed (&optional highlight)
2878   "Convert the current article date to time lapsed since it was sent."
2879   (interactive (list t))
2880   (article-date-ut 'lapsed highlight))
2881
2882 (defun article-update-date-lapsed ()
2883   "Function to be run from a timer to update the lapsed time line."
2884   (let (deactivate-mark)
2885     (save-excursion
2886       (ignore-errors
2887         (walk-windows
2888          (lambda (w)
2889            (set-buffer (window-buffer w))
2890            (when (eq major-mode 'gnus-article-mode)
2891              (goto-char (point-min))
2892              (when (re-search-forward "^X-Sent:" nil t)
2893                (article-date-lapsed t))))
2894          nil 'visible)))))
2895
2896 (defun gnus-start-date-timer (&optional n)
2897   "Start a timer to update the X-Sent header in the article buffers.
2898 The numerical prefix says how frequently (in seconds) the function
2899 is to run."
2900   (interactive "p")
2901   (unless n
2902     (setq n 1))
2903   (gnus-stop-date-timer)
2904   (setq article-lapsed-timer
2905         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2906
2907 (defun gnus-stop-date-timer ()
2908   "Stop the X-Sent timer."
2909   (interactive)
2910   (when article-lapsed-timer
2911     (nnheader-cancel-timer article-lapsed-timer)
2912     (setq article-lapsed-timer nil)))
2913
2914 (defun article-date-user (&optional highlight)
2915   "Convert the current article date to the user-defined format.
2916 This format is defined by the `gnus-article-time-format' variable."
2917   (interactive (list t))
2918   (article-date-ut 'user highlight))
2919
2920 (defun article-date-iso8601 (&optional highlight)
2921   "Convert the current article date to ISO8601."
2922   (interactive (list t))
2923   (article-date-ut 'iso8601 highlight))
2924
2925 ;; (defun article-show-all ()
2926 ;;   "Show all hidden text in the article buffer."
2927 ;;   (interactive)
2928 ;;   (save-excursion
2929 ;;     (widen)
2930 ;;     (let ((buffer-read-only nil))
2931 ;;       (gnus-article-unhide-text (point-min) (point-max))
2932 ;;       (gnus-remove-text-with-property 'gnus-prev)
2933 ;;       (gnus-remove-text-with-property 'gnus-next))))
2934
2935 (defun article-show-all-headers ()
2936   "Show all hidden headers in the article buffer."
2937   (interactive)
2938   (save-excursion
2939     (save-restriction
2940       (widen)
2941       (article-narrow-to-head)
2942       (let ((buffer-read-only nil))
2943         (gnus-article-unhide-text (point-min) (point-max))))))
2944
2945 (defun article-remove-leading-whitespace ()
2946   "Remove excessive whitespace from all headers."
2947   (interactive)
2948   (save-excursion
2949     (save-restriction
2950       (let ((buffer-read-only nil))
2951         (article-narrow-to-head)
2952         (goto-char (point-min))
2953         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2954           (delete-region (match-beginning 1) (match-end 1)))))))
2955
2956 (defun article-emphasize (&optional arg)
2957   "Emphasize text according to `gnus-emphasis-alist'."
2958   (interactive (gnus-article-hidden-arg))
2959   (unless (gnus-article-check-hidden-text 'emphasis arg)
2960     (save-excursion
2961       (let ((alist (or
2962                     (condition-case nil
2963                         (with-current-buffer gnus-summary-buffer
2964                           gnus-article-emphasis-alist)
2965                       (error))
2966                     gnus-emphasis-alist))
2967             (buffer-read-only nil)
2968             (props (append '(article-type emphasis)
2969                            gnus-hidden-properties))
2970             regexp elem beg invisible visible face)
2971         (article-goto-body)
2972         (setq beg (point))
2973         (while (setq elem (pop alist))
2974           (goto-char beg)
2975           (setq regexp (car elem)
2976                 invisible (nth 1 elem)
2977                 visible (nth 2 elem)
2978                 face (nth 3 elem))
2979           (while (re-search-forward regexp nil t)
2980             (when (and (match-beginning visible) (match-beginning invisible))
2981               (gnus-article-hide-text
2982                (match-beginning invisible) (match-end invisible) props)
2983               (gnus-article-unhide-text-type
2984                (match-beginning visible) (match-end visible) 'emphasis)
2985               (gnus-put-overlay-excluding-newlines
2986                (match-beginning visible) (match-end visible) 'face face)
2987               (gnus-add-wash-type 'emphasis)
2988               (goto-char (match-end invisible)))))))))
2989
2990 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2991   "Setup newsgroup emphasis alist."
2992   (unless gnus-article-emphasis-alist
2993     (let ((name (and gnus-newsgroup-name
2994                      (gnus-group-real-name gnus-newsgroup-name))))
2995       (make-local-variable 'gnus-article-emphasis-alist)
2996       (setq gnus-article-emphasis-alist
2997             (nconc
2998              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2999                (while (setq elem (pop alist))
3000                  (when (and name (string-match (car elem) name))
3001                    (setq alist nil
3002                          highlight (copy-sequence (cdr elem)))))
3003                highlight)
3004              (copy-sequence highlight-words)
3005              (if gnus-newsgroup-name
3006                  (copy-sequence (gnus-group-find-parameter
3007                                  gnus-newsgroup-name 'highlight-words t)))
3008              gnus-emphasis-alist)))))
3009
3010 (eval-when-compile
3011   (defvar gnus-summary-article-menu)
3012   (defvar gnus-summary-post-menu))
3013
3014 ;;; Saving functions.
3015
3016 (defun gnus-article-save (save-buffer file &optional num)
3017   "Save the currently selected article."
3018   (unless gnus-save-all-headers
3019     ;; Remove headers according to `gnus-saved-headers'.
3020     (let ((gnus-visible-headers
3021            (or gnus-saved-headers gnus-visible-headers))
3022           (gnus-article-buffer save-buffer))
3023       (save-excursion
3024         (set-buffer save-buffer)
3025         (article-hide-headers 1 t))))
3026   (save-window-excursion
3027     (if (not gnus-default-article-saver)
3028         (error "No default saver is defined")
3029       ;; !!! Magic!  The saving functions all save
3030       ;; `gnus-save-article-buffer' (or so they think), but we
3031       ;; bind that variable to our save-buffer.
3032       (set-buffer gnus-article-buffer)
3033       (let* ((gnus-save-article-buffer save-buffer)
3034              (filename
3035               (cond
3036                ((not gnus-prompt-before-saving) 'default)
3037                ((eq gnus-prompt-before-saving 'always) nil)
3038                (t file)))
3039              (gnus-number-of-articles-to-be-saved
3040               (when (eq gnus-prompt-before-saving t)
3041                 num)))                  ; Magic
3042         (set-buffer gnus-article-current-summary)
3043         (funcall gnus-default-article-saver filename)))))
3044
3045 (defun gnus-read-save-file-name (prompt &optional filename
3046                                         function group headers variable)
3047   (let ((default-name
3048           (funcall function group headers (symbol-value variable)))
3049         result)
3050     (setq result
3051           (expand-file-name
3052            (cond
3053             ((eq filename 'default)
3054              default-name)
3055             ((eq filename t)
3056              default-name)
3057             (filename filename)
3058             (t
3059              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3060                     (prompt
3061                      (format prompt
3062                              (if (and gnus-number-of-articles-to-be-saved
3063                                       (> gnus-number-of-articles-to-be-saved 1))
3064                                  (format "these %d articles"
3065                                          gnus-number-of-articles-to-be-saved)
3066                                "this article")))
3067                     (file
3068                      ;; Let the split methods have their say.
3069                      (cond
3070                       ;; No split name was found.
3071                       ((null split-name)
3072                        (read-file-name
3073                         (concat prompt " (default "
3074                                 (file-name-nondirectory default-name) ") ")
3075                         (file-name-directory default-name)
3076                         default-name))
3077                       ;; A single group name is returned.
3078                       ((stringp split-name)
3079                        (setq default-name
3080                              (funcall function split-name headers
3081                                       (symbol-value variable)))
3082                        (read-file-name
3083                         (concat prompt " (default "
3084                                 (file-name-nondirectory default-name) ") ")
3085                         (file-name-directory default-name)
3086                         default-name))
3087                       ;; A single split name was found
3088                       ((= 1 (length split-name))
3089                        (let* ((name (expand-file-name
3090                                      (car split-name)
3091                                      gnus-article-save-directory))
3092                               (dir (cond ((file-directory-p name)
3093                                           (file-name-as-directory name))
3094                                          ((file-exists-p name) name)
3095                                          (t gnus-article-save-directory))))
3096                          (read-file-name
3097                           (concat prompt " (default " name ") ")
3098                           dir name)))
3099                       ;; A list of splits was found.
3100                       (t
3101                        (setq split-name (nreverse split-name))
3102                        (let (result)
3103                          (let ((file-name-history
3104                                 (nconc split-name file-name-history)))
3105                            (setq result
3106                                  (expand-file-name
3107                                   (read-file-name
3108                                    (concat prompt " (`M-p' for defaults) ")
3109                                    gnus-article-save-directory
3110                                    (car split-name))
3111                                   gnus-article-save-directory)))
3112                          (car (push result file-name-history)))))))
3113                ;; Create the directory.
3114                (gnus-make-directory (file-name-directory file))
3115                ;; If we have read a directory, we append the default file name.
3116                (when (file-directory-p file)
3117                  (setq file (expand-file-name (file-name-nondirectory
3118                                                default-name)
3119                                               (file-name-as-directory file))))
3120                ;; Possibly translate some characters.
3121                (nnheader-translate-file-chars file))))))
3122     (gnus-make-directory (file-name-directory result))
3123     (set variable result)))
3124
3125 (defun gnus-article-archive-name (group)
3126   "Return the first instance of an \"Archive-name\" in the current buffer."
3127   (let ((case-fold-search t))
3128     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3129       (nnheader-concat gnus-article-save-directory
3130                        (match-string 1)))))
3131
3132 (defun gnus-article-nndoc-name (group)
3133   "If GROUP is an nndoc group, return the name of the parent group."
3134   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3135     (gnus-group-get-parameter group 'save-article-group)))
3136
3137 (defun gnus-summary-save-in-rmail (&optional filename)
3138   "Append this article to Rmail file.
3139 Optional argument FILENAME specifies file name.
3140 Directory to save to is default to `gnus-article-save-directory'."
3141   (setq filename (gnus-read-save-file-name
3142                   "Save %s in rmail file:" filename
3143                   gnus-rmail-save-name gnus-newsgroup-name
3144                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3145   (gnus-eval-in-buffer-window gnus-save-article-buffer
3146     (save-excursion
3147       (save-restriction
3148         (widen)
3149         (gnus-output-to-rmail filename))))
3150   filename)
3151
3152 (defun gnus-summary-save-in-mail (&optional filename)
3153   "Append this article to Unix mail file.
3154 Optional argument FILENAME specifies file name.
3155 Directory to save to is default to `gnus-article-save-directory'."
3156   (setq filename (gnus-read-save-file-name
3157                   "Save %s in Unix mail file:" filename
3158                   gnus-mail-save-name gnus-newsgroup-name
3159                   gnus-current-headers 'gnus-newsgroup-last-mail))
3160   (gnus-eval-in-buffer-window gnus-save-article-buffer
3161     (save-excursion
3162       (save-restriction
3163         (widen)
3164         (if (and (file-readable-p filename)
3165                  (mail-file-babyl-p filename))
3166             (rmail-output-to-rmail-file filename t)
3167           (gnus-output-to-mail filename)))))
3168   filename)
3169
3170 (defun gnus-summary-save-in-file (&optional filename overwrite)
3171   "Append this article to file.
3172 Optional argument FILENAME specifies file name.
3173 Directory to save to is default to `gnus-article-save-directory'."
3174   (setq filename (gnus-read-save-file-name
3175                   "Save %s in file:" filename
3176                   gnus-file-save-name gnus-newsgroup-name
3177                   gnus-current-headers 'gnus-newsgroup-last-file))
3178   (gnus-eval-in-buffer-window gnus-save-article-buffer
3179     (save-excursion
3180       (save-restriction
3181         (widen)
3182         (when (and overwrite
3183                    (file-exists-p filename))
3184           (delete-file filename))
3185         (gnus-output-to-file filename))))
3186   filename)
3187
3188 (defun gnus-summary-write-to-file (&optional filename)
3189   "Write this article to a file, overwriting it if the file exists.
3190 Optional argument FILENAME specifies file name.
3191 The directory to save in defaults to `gnus-article-save-directory'."
3192   (gnus-summary-save-in-file nil t))
3193
3194 (defun gnus-summary-save-body-in-file (&optional filename)
3195   "Append this article body to a file.
3196 Optional argument FILENAME specifies file name.
3197 The directory to save in defaults to `gnus-article-save-directory'."
3198   (setq filename (gnus-read-save-file-name
3199                   "Save %s body in file:" filename
3200                   gnus-file-save-name gnus-newsgroup-name
3201                   gnus-current-headers 'gnus-newsgroup-last-file))
3202   (gnus-eval-in-buffer-window gnus-save-article-buffer
3203     (save-excursion
3204       (save-restriction
3205         (widen)
3206         (when (article-goto-body)
3207           (narrow-to-region (point) (point-max)))
3208         (gnus-output-to-file filename))))
3209   filename)
3210
3211 (defun gnus-summary-save-in-pipe (&optional command)
3212   "Pipe this article to subprocess."
3213   (setq command
3214         (cond ((and (eq command 'default)
3215                     gnus-last-shell-command)
3216                gnus-last-shell-command)
3217               ((stringp command)
3218                command)
3219               (t (read-string
3220                   (format
3221                    "Shell command on %s: "
3222                    (if (and gnus-number-of-articles-to-be-saved
3223                             (> gnus-number-of-articles-to-be-saved 1))
3224                        (format "these %d articles"
3225                                gnus-number-of-articles-to-be-saved)
3226                      "this article"))
3227                   gnus-last-shell-command))))
3228   (when (string-equal command "")
3229     (if gnus-last-shell-command
3230         (setq command gnus-last-shell-command)
3231       (error "A command is required")))
3232   (gnus-eval-in-buffer-window gnus-article-buffer
3233     (save-restriction
3234       (widen)
3235       (shell-command-on-region (point-min) (point-max) command nil)))
3236   (setq gnus-last-shell-command command))
3237
3238 (defun gnus-summary-pipe-to-muttprint (&optional command)
3239   "Pipe this article to muttprint."
3240   (setq command (read-string
3241                  "Print using command: " gnus-summary-muttprint-program
3242                  nil gnus-summary-muttprint-program))
3243   (gnus-summary-save-in-pipe command))
3244
3245 ;;; Article file names when saving.
3246
3247 (defun gnus-capitalize-newsgroup (newsgroup)
3248   "Capitalize NEWSGROUP name."
3249   (when (not (zerop (length newsgroup)))
3250     (concat (char-to-string (upcase (aref newsgroup 0)))
3251             (substring newsgroup 1))))
3252
3253 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3254   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3255 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3256 Otherwise, it is like ~/News/news/group/num."
3257   (let ((default
3258           (expand-file-name
3259            (concat (if (gnus-use-long-file-name 'not-save)
3260                        (gnus-capitalize-newsgroup newsgroup)
3261                      (gnus-newsgroup-directory-form newsgroup))
3262                    "/" (int-to-string (mail-header-number headers)))
3263            gnus-article-save-directory)))
3264     (if (and last-file
3265              (string-equal (file-name-directory default)
3266                            (file-name-directory last-file))
3267              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3268         default
3269       (or last-file default))))
3270
3271 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3272   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3273 If variable `gnus-use-long-file-name' is non-nil, it is
3274 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3275   (let ((default
3276           (expand-file-name
3277            (concat (if (gnus-use-long-file-name 'not-save)
3278                        newsgroup
3279                      (gnus-newsgroup-directory-form newsgroup))
3280                    "/" (int-to-string (mail-header-number headers)))
3281            gnus-article-save-directory)))
3282     (if (and last-file
3283              (string-equal (file-name-directory default)
3284                            (file-name-directory last-file))
3285              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3286         default
3287       (or last-file default))))
3288
3289 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3290   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3291 If variable `gnus-use-long-file-name' is non-nil, it is
3292 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3293   (or last-file
3294       (expand-file-name
3295        (if (gnus-use-long-file-name 'not-save)
3296            newsgroup
3297          (file-relative-name
3298           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3299           default-directory))
3300        gnus-article-save-directory)))
3301
3302 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3303   "Generate file name from sender."
3304   (let ((from (mail-header-from headers)))
3305     (expand-file-name
3306      (if (and from (string-match "\\([^ <]+\\)@" from))
3307          (match-string 1 from)
3308        "nobody")
3309      gnus-article-save-directory)))
3310
3311 (defun article-verify-x-pgp-sig ()
3312   "Verify X-PGP-Sig."
3313   (interactive)
3314   (if (gnus-buffer-live-p gnus-original-article-buffer)
3315       (let ((sig (with-current-buffer gnus-original-article-buffer
3316                    (gnus-fetch-field "X-PGP-Sig")))
3317             items info headers)
3318         (when (and sig
3319                    mml2015-use
3320                    (mml2015-clear-verify-function))
3321           (with-temp-buffer
3322             (insert-buffer gnus-original-article-buffer)
3323             (setq items (split-string sig))
3324             (message-narrow-to-head)
3325             (let ((inhibit-point-motion-hooks t)
3326                   (case-fold-search t))
3327               ;; Don't verify multiple headers.
3328               (setq headers (mapconcat (lambda (header)
3329                                          (concat header ": "
3330                                                  (mail-fetch-field header) "\n"))
3331                                        (split-string (nth 1 items) ",") "")))
3332             (delete-region (point-min) (point-max))
3333             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3334             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3335             (insert headers)
3336             (widen)
3337             (forward-line)
3338             (while (not (eobp))
3339               (if (looking-at "^-")
3340                   (insert "- "))
3341               (forward-line))
3342             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3343             (insert "Version: " (car items) "\n\n")
3344             (insert (mapconcat 'identity (cddr items) "\n"))
3345             (insert "\n-----END PGP SIGNATURE-----\n")
3346             (let ((mm-security-handle (list (format "multipart/signed"))))
3347               (mml2015-clean-buffer)
3348               (let ((coding-system-for-write (or gnus-newsgroup-charset
3349                                                  'iso-8859-1)))
3350                 (funcall (mml2015-clear-verify-function)))
3351               (setq info
3352                     (or (mm-handle-multipart-ctl-parameter
3353                          mm-security-handle 'gnus-details)
3354                         (mm-handle-multipart-ctl-parameter
3355                          mm-security-handle 'gnus-info)))))
3356           (when info
3357             (let (buffer-read-only bface eface)
3358               (save-restriction
3359                 (message-narrow-to-head)
3360                 (goto-char (point-max))
3361                 (forward-line -1)
3362                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3363                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3364                 (message-remove-header "X-Gnus-PGP-Verify")
3365                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3366                     (forward-line)
3367                   (goto-char (point-max)))
3368                 (narrow-to-region (point) (point))
3369                 (insert "X-Gnus-PGP-Verify: " info "\n")
3370                 (goto-char (point-min))
3371                 (forward-line)
3372                 (while (not (eobp))
3373                   (if (not (looking-at "^[ \t]"))
3374                       (insert " "))
3375                   (forward-line))
3376                 ;; Do highlighting.
3377                 (goto-char (point-min))
3378                 (when (looking-at "\\([^:]+\\): *")
3379                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3380                                      'face bface)
3381                   (put-text-property (match-end 0) (point-max)
3382                                      'face eface)))))))))
3383
3384 (defun article-verify-cancel-lock ()
3385   "Verify Cancel-Lock header."
3386   (interactive)
3387   (if (gnus-buffer-live-p gnus-original-article-buffer)
3388       (canlock-verify gnus-original-article-buffer)))
3389
3390 (eval-and-compile
3391   (mapcar
3392    (lambda (func)
3393      (let (afunc gfunc)
3394        (if (consp func)
3395            (setq afunc (car func)
3396                  gfunc (cdr func))
3397          (setq afunc func
3398                gfunc (intern (format "gnus-%s" func))))
3399        (defalias gfunc
3400          (when (fboundp afunc)
3401            `(lambda (&optional interactive &rest args)
3402               ,(documentation afunc t)
3403               (interactive (list t))
3404               (save-excursion
3405                 (set-buffer gnus-article-buffer)
3406                 (if interactive
3407                     (call-interactively ',afunc)
3408                   (apply ',afunc args))))))))
3409    '(article-hide-headers
3410      article-verify-x-pgp-sig
3411      article-verify-cancel-lock
3412      article-hide-boring-headers
3413      article-toggle-headers
3414      article-treat-overstrike
3415      article-fill-long-lines
3416      article-capitalize-sentences
3417      article-remove-cr
3418      article-remove-leading-whitespace
3419      article-display-x-face
3420      article-de-quoted-unreadable
3421      article-de-base64-unreadable
3422      article-decode-HZ
3423      article-wash-html
3424      article-hide-list-identifiers
3425      article-hide-pgp
3426      article-strip-banner
3427      article-babel
3428      article-hide-pem
3429      article-hide-signature
3430      article-strip-headers-in-body
3431      article-remove-trailing-blank-lines
3432      article-strip-leading-blank-lines
3433      article-strip-multiple-blank-lines
3434      article-strip-leading-space
3435      article-strip-trailing-space
3436      article-strip-blank-lines
3437      article-strip-all-blank-lines
3438      article-date-local
3439      article-date-english
3440      article-date-iso8601
3441      article-date-original
3442      article-date-ut
3443      article-decode-mime-words
3444      article-decode-charset
3445      article-decode-encoded-words
3446      article-date-user
3447      article-date-lapsed
3448      article-emphasize
3449      article-treat-dumbquotes
3450      article-normalize-headers
3451      (article-show-all-headers . gnus-article-show-all-headers)
3452 ;;      (article-show-all . gnus-article-show-all)
3453      )))
3454 \f
3455 ;;;
3456 ;;; Gnus article mode
3457 ;;;
3458
3459 (put 'gnus-article-mode 'mode-class 'special)
3460
3461 (gnus-define-keys gnus-article-mode-map
3462   " " gnus-article-goto-next-page
3463   "\177" gnus-article-goto-prev-page
3464   [delete] gnus-article-goto-prev-page
3465   [backspace] gnus-article-goto-prev-page
3466   "\C-c^" gnus-article-refer-article
3467   "h" gnus-article-show-summary
3468   "s" gnus-article-show-summary
3469   "\C-c\C-m" gnus-article-mail
3470   "?" gnus-article-describe-briefly
3471   "e" gnus-summary-edit-article
3472   "<" beginning-of-buffer
3473   ">" end-of-buffer
3474   "\C-c\C-i" gnus-info-find-node
3475   "\C-c\C-b" gnus-bug
3476   "R" gnus-article-reply-with-original
3477   "F" gnus-article-followup-with-original
3478   "\C-hk" gnus-article-describe-key
3479   "\C-hc" gnus-article-describe-key-briefly
3480
3481   "\C-d" gnus-article-read-summary-keys
3482   "\M-*" gnus-article-read-summary-keys
3483   "\M-#" gnus-article-read-summary-keys
3484   "\M-^" gnus-article-read-summary-keys
3485   "\M-g" gnus-article-read-summary-keys)
3486
3487 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3488 (let (keys)
3489   (let ((key 32))
3490     (while (<= key 127)
3491       (push (char-to-string key) keys)
3492       (incf key))
3493     (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3494       (setq key (car elem))
3495       (when (and (> (length key) 0)
3496                  (not (eq 'menu-bar (aref key 0)))
3497                  (symbolp (lookup-key gnus-summary-mode-map key)))
3498         (push key keys))))
3499   (dolist (key keys)
3500     (unless (lookup-key gnus-article-mode-map key)
3501       (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3502
3503 (defun gnus-article-make-menu-bar ()
3504   (unless (boundp 'gnus-article-commands-menu)
3505     (gnus-summary-make-menu-bar))
3506   (gnus-turn-off-edit-menu 'article)
3507   (unless (boundp 'gnus-article-article-menu)
3508     (easy-menu-define
3509      gnus-article-article-menu gnus-article-mode-map ""
3510      '("Article"
3511        ["Scroll forwards" gnus-article-goto-next-page t]
3512        ["Scroll backwards" gnus-article-goto-prev-page t]
3513        ["Show summary" gnus-article-show-summary t]
3514        ["Fetch Message-ID at point" gnus-article-refer-article t]
3515        ["Mail to address at point" gnus-article-mail t]
3516        ["Send a bug report" gnus-bug t]))
3517
3518     (easy-menu-define
3519      gnus-article-treatment-menu gnus-article-mode-map ""
3520      ;; Fixme: this should use :active (and maybe :visible).
3521      '("Treatment"
3522        ["Hide headers" gnus-article-toggle-headers t]
3523        ["Hide signature" gnus-article-hide-signature t]
3524        ["Hide citation" gnus-article-hide-citation t]
3525        ["Treat overstrike" gnus-article-treat-overstrike t]
3526        ["Remove carriage return" gnus-article-remove-cr t]
3527        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3528        ["Treat html" gnus-article-wash-html t]
3529        ["Decode HZ" gnus-article-decode-HZ t]))
3530
3531     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3532
3533     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3534
3535     (gnus-run-hooks 'gnus-article-menu-hook)))
3536
3537 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3538 ;; Summary.
3539
3540 (defun gnus-article-mode ()
3541   "Major mode for displaying an article.
3542
3543 All normal editing commands are switched off.
3544
3545 The following commands are available in addition to all summary mode
3546 commands:
3547 \\<gnus-article-mode-map>
3548 \\[gnus-article-next-page]\t Scroll the article one page forwards
3549 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3550 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3551 \\[gnus-article-show-summary]\t Display the summary buffer
3552 \\[gnus-article-mail]\t Send a reply to the address near point
3553 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3554 \\[gnus-info-find-node]\t Go to the Gnus info node"
3555   (interactive)
3556   (gnus-simplify-mode-line)
3557   (setq mode-name "Article")
3558   (setq major-mode 'gnus-article-mode)
3559   (make-local-variable 'minor-mode-alist)
3560   (unless (assq 'gnus-show-mime minor-mode-alist)
3561     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3562   (use-local-map gnus-article-mode-map)
3563   (when (gnus-visual-p 'article-menu 'menu)
3564     (gnus-article-make-menu-bar))
3565   (gnus-update-format-specifications nil 'article-mode)
3566   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3567   (make-local-variable 'gnus-page-broken)
3568   (make-local-variable 'gnus-button-marker-list)
3569   (make-local-variable 'gnus-article-current-summary)
3570   (make-local-variable 'gnus-article-mime-handles)
3571   (make-local-variable 'gnus-article-decoded-p)
3572   (make-local-variable 'gnus-article-mime-handle-alist)
3573   (make-local-variable 'gnus-article-wash-types)
3574   (make-local-variable 'gnus-article-image-alist)
3575   (make-local-variable 'gnus-article-charset)
3576   (make-local-variable 'gnus-article-ignored-charsets)
3577   (gnus-set-default-directory)
3578   (buffer-disable-undo)
3579   (setq buffer-read-only t)
3580   (set-syntax-table gnus-article-mode-syntax-table)
3581   (gnus-run-hooks 'gnus-article-mode-hook))
3582
3583 (defun gnus-article-setup-buffer ()
3584   "Initialize the article buffer."
3585   (let* ((name (if gnus-single-article-buffer "*Article*"
3586                  (concat "*Article " gnus-newsgroup-name "*")))
3587          (original
3588           (progn (string-match "\\*Article" name)
3589                  (concat " *Original Article"
3590                          (substring name (match-end 0))))))
3591     (setq gnus-article-buffer name)
3592     (setq gnus-original-article-buffer original)
3593     (setq gnus-article-mime-handle-alist nil)
3594     ;; This might be a variable local to the summary buffer.
3595     (unless gnus-single-article-buffer
3596       (save-excursion
3597         (set-buffer gnus-summary-buffer)
3598         (setq gnus-article-buffer name)
3599         (setq gnus-original-article-buffer original)
3600         (gnus-set-global-variables)))
3601     (gnus-article-setup-highlight-words)
3602     ;; Init original article buffer.
3603     (save-excursion
3604       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3605       (set-buffer-multibyte t)
3606       (setq major-mode 'gnus-original-article-mode)
3607       (make-local-variable 'gnus-original-article))
3608     (if (get-buffer name)
3609         (save-excursion
3610           (set-buffer name)
3611           (buffer-disable-undo)
3612           (setq buffer-read-only t)
3613           (unless (eq major-mode 'gnus-article-mode)
3614             (gnus-article-mode))
3615           (current-buffer))
3616       (save-excursion
3617         (set-buffer (gnus-get-buffer-create name))
3618         (gnus-article-mode)
3619         (make-local-variable 'gnus-summary-buffer)
3620         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3621         (current-buffer)))))
3622
3623 ;; Set article window start at LINE, where LINE is the number of lines
3624 ;; from the head of the article.
3625 (defun gnus-article-set-window-start (&optional line)
3626   (set-window-start
3627    (gnus-get-buffer-window gnus-article-buffer t)
3628    (save-excursion
3629      (set-buffer gnus-article-buffer)
3630      (goto-char (point-min))
3631      (if (not line)
3632          (point-min)
3633        (gnus-message 6 "Moved to bookmark")
3634        (search-forward "\n\n" nil t)
3635        (forward-line line)
3636        (point)))))
3637
3638 ;;; @@ article filters
3639 ;;;
3640
3641 (defun gnus-article-display-mime-message ()
3642   "Article display method for MIME message."
3643   ;; called from `gnus-original-article-buffer'.
3644   (let (charset all-headers)
3645     (with-current-buffer gnus-summary-buffer
3646       (setq charset default-mime-charset
3647             all-headers gnus-have-all-headers))
3648     (make-local-variable 'default-mime-charset)
3649     (setq default-mime-charset charset)
3650     (with-current-buffer (get-buffer-create gnus-article-buffer)
3651       (make-local-variable 'default-mime-charset)
3652       (setq default-mime-charset charset))
3653     (mime-display-message mime-message-structure
3654                           gnus-article-buffer nil gnus-article-mode-map)
3655     (when all-headers
3656       (gnus-article-hide-headers nil -1)))
3657   (run-hooks 'gnus-mime-article-prepare-hook))
3658
3659 (defun gnus-article-display-traditional-message ()
3660   "Article display method for traditional message."
3661   (set-buffer gnus-article-buffer)
3662   (let (buffer-read-only)
3663     (erase-buffer)
3664     (insert-buffer-substring gnus-original-article-buffer)))
3665
3666 (defun gnus-article-make-full-mail-header (&optional number charset)
3667   "Create a new mail header structure in a raw article buffer."
3668   (unless (and number charset)
3669     (save-current-buffer
3670       (set-buffer gnus-summary-buffer)
3671       (unless number
3672         (setq number (or (cdr gnus-article-current) 0)))
3673       (unless charset
3674         (setq charset (or default-mime-charset 'x-ctext)))))
3675   (goto-char (point-min))
3676   (let ((header-end (if (search-forward "\n\n" nil t)
3677                         (1- (point))
3678                       (goto-char (point-max))))
3679         (chars (- (point-max) (point)))
3680         (lines (count-lines (point) (point-max)))
3681         (default-mime-charset charset)
3682         xref)
3683     (narrow-to-region (point-min) header-end)
3684     (setq xref (std11-fetch-field "xref"))
3685     (prog1
3686         (make-full-mail-header
3687          number
3688          (std11-fetch-field "subject")
3689          (std11-fetch-field "from")
3690          (std11-fetch-field "date")
3691          (std11-fetch-field "message-id")
3692          (std11-fetch-field "references")
3693          chars
3694          lines
3695          (when xref (concat "Xref: " xref)))
3696       (widen))))
3697
3698 (defun gnus-article-prepare (article &optional all-headers header)
3699   "Prepare ARTICLE in article mode buffer.
3700 ARTICLE should either be an article number or a Message-ID.
3701 If ARTICLE is an id, HEADER should be the article headers.
3702 If ALL-HEADERS is non-nil, no headers are hidden."
3703   (save-excursion
3704     ;; Make sure we start in a summary buffer.
3705     (unless (eq major-mode 'gnus-summary-mode)
3706       (set-buffer gnus-summary-buffer))
3707     (setq gnus-summary-buffer (current-buffer))
3708     (let* ((gnus-article (if header (mail-header-number header) article))
3709            (summary-buffer (current-buffer))
3710            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3711            (group gnus-newsgroup-name)
3712            result)
3713       (save-excursion
3714         (gnus-article-setup-buffer)
3715         (set-buffer gnus-article-buffer)
3716         ;; Deactivate active regions.
3717         (when (and (boundp 'transient-mark-mode)
3718                    transient-mark-mode)
3719           (setq mark-active nil))
3720         (if (not (setq result (let ((buffer-read-only nil))
3721                                 (gnus-request-article-this-buffer
3722                                  article group))))
3723             ;; There is no such article.
3724             (save-excursion
3725               (when (and (numberp article)
3726                          (not (memq article gnus-newsgroup-sparse)))
3727                 (setq gnus-article-current
3728                       (cons gnus-newsgroup-name article))
3729                 (set-buffer gnus-summary-buffer)
3730                 (setq gnus-current-article article)
3731                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3732                     (progn
3733                       (gnus-summary-set-agent-mark article)
3734                       (message "Message marked for downloading"))
3735                   (gnus-summary-mark-article article gnus-canceled-mark)
3736                   (unless (memq article gnus-newsgroup-sparse)
3737                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3738           (if (or (eq result 'pseudo)
3739                   (eq result 'nneething))
3740               (progn
3741                 (save-excursion
3742                   (set-buffer summary-buffer)
3743                   (push article gnus-newsgroup-history)
3744                   (setq gnus-last-article gnus-current-article
3745                         gnus-current-article 0
3746                         gnus-current-headers nil
3747                         gnus-article-current nil)
3748                   (if (eq result 'nneething)
3749                       (gnus-configure-windows 'summary)
3750                     (gnus-configure-windows 'article))
3751                   (gnus-set-global-variables))
3752                 (let ((gnus-article-mime-handle-alist-1
3753                        gnus-article-mime-handle-alist))
3754                   (gnus-set-mode-line 'article)))
3755             ;; The result from the `request' was an actual article -
3756             ;; or at least some text that is now displayed in the
3757             ;; article buffer.
3758             (when (and (numberp article)
3759                        (not (eq article gnus-current-article)))
3760               ;; Seems like a new article has been selected.
3761               ;; `gnus-current-article' must be an article number.
3762               (save-excursion
3763                 (set-buffer summary-buffer)
3764                 (push article gnus-newsgroup-history)
3765                 (setq gnus-last-article gnus-current-article
3766                       gnus-current-article article
3767                       gnus-current-headers
3768                       (gnus-summary-article-header gnus-current-article)
3769                       gnus-article-current
3770                       (cons gnus-newsgroup-name gnus-current-article))
3771                 (unless (vectorp gnus-current-headers)
3772                   (setq gnus-current-headers nil))
3773                 (gnus-summary-goto-subject gnus-current-article)
3774                 (when (gnus-summary-show-thread)
3775                   ;; If the summary buffer really was folded, the
3776                   ;; previous goto may not actually have gone to
3777                   ;; the right article, but the thread root instead.
3778                   ;; So we go again.
3779                   (gnus-summary-goto-subject gnus-current-article))
3780                 (gnus-run-hooks 'gnus-mark-article-hook)
3781                 (gnus-set-mode-line 'summary)
3782                 (when (gnus-visual-p 'article-highlight 'highlight)
3783                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3784                 ;; Set the global newsgroup variables here.
3785                 (gnus-set-global-variables)
3786                 (setq gnus-have-all-headers
3787                       (or all-headers gnus-show-all-headers))))
3788             (save-excursion
3789               (gnus-configure-windows 'article))
3790             (when (or (numberp article)
3791                       (stringp article))
3792               (gnus-article-prepare-display)
3793               ;; Do page break.
3794               (goto-char (point-min))
3795               (setq gnus-page-broken
3796                     (when gnus-break-pages
3797                       (gnus-narrow-to-page)
3798                       t)))
3799             (let ((gnus-article-mime-handle-alist-1
3800                    gnus-article-mime-handle-alist))
3801               (gnus-set-mode-line 'article))
3802             (article-goto-body)
3803             (set-window-point (get-buffer-window (current-buffer)) (point))
3804             (gnus-configure-windows 'article)
3805             t))))))
3806
3807 (defun gnus-article-prepare-mime-display (&optional number)
3808   (goto-char (point-min))
3809   (when (re-search-forward "^[^\t ]+:" nil t)
3810     (goto-char (match-beginning 0)))
3811   (let ((entity (if (eq 1 (point-min))
3812                     (get-text-property 1 'mime-view-entity)
3813                   (get-text-property (point) 'mime-view-entity)))
3814         last-entity child-entity next type)
3815     (setq child-entity (mime-entity-children entity))
3816     (if child-entity
3817         (setq last-entity (nth (1- (length child-entity))
3818                                child-entity))
3819       (setq last-entity entity))
3820     (save-restriction
3821       (narrow-to-region (point)
3822                         (if (search-forward "\n\n" nil t)
3823                             (point)
3824                           (point-max)))
3825       (gnus-treat-article 'head)
3826       (put-text-property (point-min) (point-max) 'article-treated-header t)
3827       (goto-char (point-max)))
3828     (while (and (not (eobp)) entity)
3829       (setq next (set-marker
3830                   (make-marker)
3831                   (next-single-property-change (point) 'mime-view-entity
3832                                                nil (point-max))))
3833       (let ((types (mime-entity-content-type entity)))
3834         (while (eq 'multipart (mime-content-type-primary-type types))
3835           (setq entity (car (mime-entity-children entity))
3836                 types (mime-entity-content-type entity)))
3837         (when types
3838           (setq type (format "%s/%s"
3839                              (mime-content-type-primary-type types)
3840                              (mime-content-type-subtype types)))))
3841       (if (string-equal type "message/rfc822")
3842           (progn
3843             (setq next (point))
3844             (let ((children (mime-entity-children entity))
3845                   last-children)
3846               (when children
3847                 (setq last-children (nth (1- (length children)) children))
3848                 (while
3849                     (and
3850                      (not (eq last-children
3851                               (get-text-property next 'mime-view-entity)))
3852                      (setq next
3853                            (next-single-property-change next
3854                                                         'mime-view-entity
3855                                                         nil (point-max)))))))
3856             (setq next (next-single-property-change next 'mime-view-entity
3857                                                     nil (point-max)))
3858             (save-restriction
3859               (narrow-to-region (point) next)
3860               (gnus-article-prepare-mime-display)
3861               (goto-char (point-max)))
3862             (setq entity (get-text-property (point) 'mime-view-entity)))
3863         (save-restriction
3864           (narrow-to-region (point) next)
3865           ;; Kludge. We have to count true number, but for now,
3866           ;; part number is here only to achieve `last'.
3867           (gnus-treat-article nil 1
3868                               (if (eq entity last-entity)
3869                                   1 2)
3870                               type)
3871           (goto-char (point-max)))
3872         (setq entity (get-text-property next 'mime-view-entity))))))
3873
3874 ;;;###autoload
3875 (defun gnus-article-prepare-display ()
3876   "Make the current buffer look like a nice article."
3877   (let ((gnus-article-buffer (current-buffer))
3878         buffer-read-only)
3879     (unless (eq major-mode 'gnus-article-mode)
3880       (gnus-article-mode))
3881     (setq buffer-read-only nil
3882           gnus-button-marker-list nil
3883           gnus-article-wash-types nil
3884           gnus-article-image-alist nil)
3885     (save-restriction
3886       (widen)
3887       (static-if (featurep 'xemacs)
3888           (map-extents (lambda (extent maparg) (delete-extent extent)))
3889         (let ((lists (overlay-lists)))
3890           (dolist (overlay (nconc (car lists) (cdr lists)))
3891             (delete-overlay overlay)))))
3892     (gnus-run-hooks 'gnus-tmp-internal-hook))
3893   (set-buffer gnus-original-article-buffer)
3894   ;; Display message.
3895   (setq mime-message-structure gnus-current-headers)
3896   (mime-buffer-entity-set-buffer-internal mime-message-structure
3897                                           gnus-original-article-buffer)
3898   (mime-entity-set-representation-type-internal mime-message-structure
3899                                                 'mime-buffer-entity)
3900   (luna-send mime-message-structure 'initialize-instance
3901              mime-message-structure)
3902   (if gnus-show-mime
3903       (let (mime-display-header-hook mime-display-text/plain-hook)
3904         (funcall gnus-article-display-method-for-mime))
3905     (funcall gnus-article-display-method-for-traditional))
3906   ;; Call the treatment functions.
3907   (let ((inhibit-read-only t))
3908     (save-restriction
3909       (widen)
3910       (if gnus-show-mime
3911           (gnus-article-prepare-mime-display)
3912         (narrow-to-region (goto-char (point-min))
3913                           (if (search-forward "\n\n" nil t)
3914                               (point)
3915                             (point-max)))
3916         (gnus-treat-article 'head)
3917         (put-text-property (point-min) (point-max) 'article-treated-header t)
3918         (goto-char (point-max))
3919         (widen)
3920         (narrow-to-region (point) (point-max))
3921         (gnus-treat-article nil))
3922       (put-text-property (point-min) (point-max) 'read-only nil)))
3923   (gnus-run-hooks 'gnus-article-prepare-hook))
3924
3925 (defun gnus-article-decode-article-as-default-mime-charset ()
3926   "Decode an article as `default-mime-charset'.  It won't work if the
3927 value of the variable `gnus-show-mime' is non-nil."
3928   (unless gnus-show-mime
3929     (set (make-local-variable 'default-mime-charset)
3930          (with-current-buffer gnus-summary-buffer
3931            default-mime-charset))
3932     (decode-mime-charset-region (point-min) (point-max)
3933                                 default-mime-charset)))
3934
3935 ;;;
3936 ;;; Gnus MIME viewing functions
3937 ;;;
3938
3939 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3940   "Format of the MIME buttons.
3941
3942 Valid specifiers include:
3943 %t  The MIME type
3944 %T  MIME type, along with additional info
3945 %n  The `name' parameter
3946 %d  The description, if any
3947 %l  The length of the encoded part
3948 %p  The part identifier number
3949 %e  Dots if the part isn't displayed
3950
3951 General format specifiers can also be used.  See
3952 (gnus)Formatting Variables.")
3953
3954 (defvar gnus-mime-button-line-format-alist
3955   '((?t gnus-tmp-type ?s)
3956     (?T gnus-tmp-type-long ?s)
3957     (?n gnus-tmp-name ?s)
3958     (?d gnus-tmp-description ?s)
3959     (?p gnus-tmp-id ?s)
3960     (?l gnus-tmp-length ?d)
3961     (?e gnus-tmp-dots ?s)))
3962
3963 (defvar gnus-mime-button-commands
3964   '((gnus-article-press-button "\r" "Toggle Display")
3965     (gnus-mime-view-part "v" "View Interactively...")
3966     (gnus-mime-view-part-as-type "t" "View As Type...")
3967     (gnus-mime-view-part-as-charset "C" "View As charset...")
3968     (gnus-mime-save-part "o" "Save...")
3969     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3970     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3971     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3972     (gnus-mime-internalize-part "E" "View Internally")
3973     (gnus-mime-externalize-part "e" "View Externally")
3974     (gnus-mime-print-part "p" "Print")
3975     (gnus-mime-pipe-part "|" "Pipe To Command...")
3976     (gnus-mime-action-on-part "." "Take action on the part")))
3977
3978 (defun gnus-article-mime-part-status ()
3979   (with-current-buffer gnus-article-buffer
3980     (let ((entity (get-text-property (point-min) 'mime-view-entity))
3981           children)
3982       (if (and entity
3983                (setq children (mime-entity-children entity))
3984                (setq children (length children)))
3985           (if (eq 1 children)
3986               " (1 part)"
3987             (format " (%d parts)" children))
3988         ""))))
3989
3990 (defvar gnus-mime-button-map
3991   (let ((map (make-sparse-keymap)))
3992     (unless (>= (string-to-number emacs-version) 21)
3993       ;; XEmacs doesn't care.
3994       (set-keymap-parent map gnus-article-mode-map))
3995     (define-key map gnus-mouse-2 'gnus-article-push-button)
3996     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3997     (dolist (c gnus-mime-button-commands)
3998       (define-key map (cadr c) (car c)))
3999     map))
4000
4001 (defun gnus-mime-button-menu (event)
4002   "Construct a context-sensitive menu of MIME commands."
4003   (interactive "e")
4004   (save-window-excursion
4005     (let ((pos (event-start event)))
4006       (select-window (posn-window pos))
4007       (goto-char (posn-point pos))
4008       (gnus-article-check-buffer)
4009       (let ((response (x-popup-menu
4010                        t `("MIME Part"
4011                            ("" ,@(mapcar (lambda (c)
4012                                            (cons (caddr c) (car c)))
4013                                          gnus-mime-button-commands))))))
4014         (if response
4015             (call-interactively response))))))
4016
4017 (defun gnus-mime-view-all-parts (&optional handles)
4018   "View all the MIME parts."
4019   (interactive)
4020   (save-current-buffer
4021     (set-buffer gnus-article-buffer)
4022     (let ((handles (or handles gnus-article-mime-handles))
4023           (mail-parse-charset gnus-newsgroup-charset)
4024           (mail-parse-ignored-charsets
4025            (with-current-buffer gnus-summary-buffer
4026              gnus-newsgroup-ignored-charsets)))
4027       (when handles
4028         (mm-remove-parts handles)
4029         (goto-char (point-min))
4030         (or (search-forward "\n\n") (goto-char (point-max)))
4031         (let (buffer-read-only)
4032           (delete-region (point) (point-max))
4033           (mm-display-parts handles))))))
4034
4035 (defun gnus-mime-save-part-and-strip ()
4036   "Save the MIME part under point then replace it with an external body."
4037   (interactive)
4038   (gnus-article-check-buffer)
4039   (let* ((data (get-text-property (point) 'gnus-data))
4040          file param
4041          (handles gnus-article-mime-handles))
4042     (if (mm-multiple-handles gnus-article-mime-handles)
4043         (error "This function is not implemented"))
4044     (setq file (and data (mm-save-part data)))
4045     (when file
4046       (with-current-buffer (mm-handle-buffer data)
4047         (erase-buffer)
4048         (insert "Content-Type: " (mm-handle-media-type data))
4049         (mml-insert-parameter-string (cdr (mm-handle-type data))
4050                                      '(charset))
4051         (insert "\n")
4052         (insert "Content-ID: " (message-make-message-id) "\n")
4053         (insert "Content-Transfer-Encoding: binary\n")
4054         (insert "\n"))
4055       (setcdr data
4056               (cdr (mm-make-handle nil
4057                                    `("message/external-body"
4058                                      (access-type . "LOCAL-FILE")
4059                                      (name . ,file)))))
4060       (set-buffer gnus-summary-buffer)
4061       (gnus-article-edit-article
4062        `(lambda ()
4063           (erase-buffer)
4064           (let ((mail-parse-charset (or gnus-article-charset
4065                                         ',gnus-newsgroup-charset))
4066                 (mail-parse-ignored-charsets
4067                  (or gnus-article-ignored-charsets
4068                      ',gnus-newsgroup-ignored-charsets))
4069                 (mbl mml-buffer-list))
4070             (setq mml-buffer-list nil)
4071             (insert-buffer gnus-original-article-buffer)
4072             (mime-to-mml ',handles)
4073             (setq gnus-article-mime-handles nil)
4074             (let ((mbl1 mml-buffer-list))
4075               (setq mml-buffer-list mbl)
4076               (set (make-local-variable 'mml-buffer-list) mbl1))
4077             ;; LOCAL argument of add-hook differs between GNU Emacs
4078             ;; and XEmacs. make-local-hook makes sure they are local.
4079             (make-local-hook 'kill-buffer-hook)
4080             (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4081        `(lambda (no-highlight)
4082           (let ((mail-parse-charset (or gnus-article-charset
4083                                         ',gnus-newsgroup-charset))
4084                 (message-options message-options)
4085                 (message-options-set-recipient)
4086                 (mail-parse-ignored-charsets
4087                  (or gnus-article-ignored-charsets
4088                      ',gnus-newsgroup-ignored-charsets)))
4089             (mml-to-mime)
4090             (mml-destroy-buffers)
4091             (remove-hook 'kill-buffer-hook
4092                          'mml-destroy-buffers t)
4093             (kill-local-variable 'mml-buffer-list))
4094           (gnus-summary-edit-article-done
4095            ,(or (mail-header-references gnus-current-headers) "")
4096            ,(gnus-group-read-only-p)
4097            ,gnus-summary-buffer no-highlight))))))
4098
4099 (defun gnus-mime-save-part ()
4100   "Save the MIME part under point."
4101   (interactive)
4102   (gnus-article-check-buffer)
4103   (let ((data (get-text-property (point) 'gnus-data)))
4104     (when data
4105       (mm-save-part data))))
4106
4107 (defun gnus-mime-pipe-part ()
4108   "Pipe the MIME part under point to a process."
4109   (interactive)
4110   (gnus-article-check-buffer)
4111   (let ((data (get-text-property (point) 'gnus-data)))
4112     (when data
4113       (mm-pipe-part data))))
4114
4115 (defun gnus-mime-view-part ()
4116   "Interactively choose a viewing method for the MIME part under point."
4117   (interactive)
4118   (gnus-article-check-buffer)
4119   (let ((data (get-text-property (point) 'gnus-data)))
4120     (when data
4121       (setq gnus-article-mime-handles
4122             (mm-merge-handles
4123              gnus-article-mime-handles (setq data (copy-sequence data))))
4124       (mm-interactively-view-part data))))
4125
4126 (defun gnus-mime-view-part-as-type-internal ()
4127   (gnus-article-check-buffer)
4128   (let* ((name (mail-content-type-get
4129                 (mm-handle-type (get-text-property (point) 'gnus-data))
4130                 'name))
4131          (def-type (and name (mm-default-file-encoding name))))
4132     (and def-type (cons def-type 0))))
4133
4134 (defun gnus-mime-view-part-as-type (&optional mime-type)
4135   "Choose a MIME media type, and view the part as such."
4136   (interactive)
4137   (unless mime-type
4138     (setq mime-type (completing-read
4139                      "View as MIME type: "
4140                      (mapcar #'list (mailcap-mime-types))
4141                      nil nil
4142                      (gnus-mime-view-part-as-type-internal))))
4143   (gnus-article-check-buffer)
4144   (let ((handle (get-text-property (point) 'gnus-data)))
4145     (when handle
4146       (setq handle
4147             (mm-make-handle (mm-handle-buffer handle)
4148                             (cons mime-type (cdr (mm-handle-type handle)))
4149                             (mm-handle-encoding handle)
4150                             (mm-handle-undisplayer handle)
4151                             (mm-handle-disposition handle)
4152                             (mm-handle-description handle)
4153                             nil
4154                             (mm-handle-id handle)))
4155       (setq gnus-article-mime-handles
4156             (mm-merge-handles gnus-article-mime-handles handle))
4157       (gnus-mm-display-part handle))))
4158
4159 (defun gnus-mime-copy-part (&optional handle)
4160   "Put the MIME part under point into a new buffer."
4161   (interactive)
4162   (gnus-article-check-buffer)
4163   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4164          (contents (and handle (mm-get-part handle)))
4165          (base (and handle
4166                     (file-name-nondirectory
4167                      (or
4168                       (mail-content-type-get (mm-handle-type handle) 'name)
4169                       (mail-content-type-get (mm-handle-type handle)
4170                                              'filename)
4171                       "*decoded*"))))
4172          (buffer (and base (generate-new-buffer base))))
4173     (when contents
4174       (switch-to-buffer buffer)
4175       (insert contents)
4176       ;; We do it this way to make `normal-mode' set the appropriate mode.
4177       (unwind-protect
4178           (progn
4179             (setq buffer-file-name (expand-file-name base))
4180             (normal-mode))
4181         (setq buffer-file-name nil))
4182       (goto-char (point-min)))))
4183
4184 (defun gnus-mime-print-part (&optional handle filename)
4185   "Print the MIME part under point."
4186   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4187   (gnus-article-check-buffer)
4188   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4189          (contents (and handle (mm-get-part handle)))
4190          (file (make-temp-name (expand-file-name "mm." mm-tmp-directory)))
4191          (printer (mailcap-mime-info (mm-handle-type handle) "print")))
4192     (when contents
4193         (if printer
4194             (unwind-protect
4195                 (progn
4196                   (with-temp-file file
4197                     (insert contents))
4198                   (call-process shell-file-name nil
4199                                 (generate-new-buffer " *mm*")
4200                                 nil
4201                                 shell-command-switch
4202                                 (mm-mailcap-command
4203                                  printer file (mm-handle-type handle))))
4204               (delete-file file))
4205           (with-temp-buffer
4206             (insert contents)
4207             (gnus-print-buffer))
4208           (ps-despool filename)))))
4209
4210 (defun gnus-mime-inline-part (&optional handle arg)
4211   "Insert the MIME part under point into the current buffer."
4212   (interactive (list nil current-prefix-arg))
4213   (gnus-article-check-buffer)
4214   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4215          contents charset
4216          (b (point))
4217          buffer-read-only)
4218     (when handle
4219       (if (and (not arg) (mm-handle-undisplayer handle))
4220           (mm-remove-part handle)
4221         (setq contents (mm-get-part handle))
4222         (cond
4223          ((not arg)
4224           (setq charset (or (mail-content-type-get
4225                              (mm-handle-type handle) 'charset)
4226                             gnus-newsgroup-charset)))
4227          ((numberp arg)
4228           (if (mm-handle-undisplayer handle)
4229               (mm-remove-part handle))
4230           (setq charset
4231                 (or (cdr (assq arg
4232                                gnus-summary-show-article-charset-alist))
4233                     (mm-read-coding-system "Charset: ")))))
4234         (forward-line 2)
4235         (mm-insert-inline handle
4236                           (if (and charset
4237                                    (setq charset (mm-charset-to-coding-system
4238                                                   charset))
4239                                    (not (eq charset 'ascii)))
4240                               (mm-decode-coding-string contents charset)
4241                             contents))
4242         (goto-char b)))))
4243
4244 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4245   "Insert the MIME part under point into the current buffer using the
4246 specified charset."
4247   (interactive (list nil current-prefix-arg))
4248   (gnus-article-check-buffer)
4249   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4250          contents charset
4251          (b (point))
4252          buffer-read-only)
4253     (when handle
4254       (if (mm-handle-undisplayer handle)
4255           (mm-remove-part handle))
4256       (let ((gnus-newsgroup-charset
4257              (or (cdr (assq arg
4258                             gnus-summary-show-article-charset-alist))
4259                  (mm-read-coding-system "Charset: ")))
4260             (gnus-newsgroup-ignored-charsets 'gnus-all))
4261         (gnus-article-press-button)))))
4262
4263 (defun gnus-mime-externalize-part (&optional handle)
4264   "View the MIME part under point with an external viewer."
4265   (interactive)
4266   (gnus-article-check-buffer)
4267   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4268          (mm-user-display-methods nil)
4269          (mm-inlined-types nil)
4270          (mail-parse-charset gnus-newsgroup-charset)
4271          (mail-parse-ignored-charsets
4272           (save-excursion (set-buffer gnus-summary-buffer)
4273                           gnus-newsgroup-ignored-charsets)))
4274     (when handle
4275       (if (mm-handle-undisplayer handle)
4276           (mm-remove-part handle)
4277         (mm-display-part handle)))))
4278
4279 (defun gnus-mime-internalize-part (&optional handle)
4280   "View the MIME part under point with an internal viewer.
4281 If no internal viewer is available, use an external viewer."
4282   (interactive)
4283   (gnus-article-check-buffer)
4284   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4285          (mm-inlined-types '(".*"))
4286          (mm-inline-large-images t)
4287          (mail-parse-charset gnus-newsgroup-charset)
4288          (mail-parse-ignored-charsets
4289           (save-excursion (set-buffer gnus-summary-buffer)
4290                           gnus-newsgroup-ignored-charsets)))
4291     (when handle
4292       (if (mm-handle-undisplayer handle)
4293           (mm-remove-part handle)
4294         (mm-display-part handle)))))
4295
4296 (defun gnus-mime-action-on-part (&optional action)
4297   "Do something with the MIME attachment at \(point\)."
4298   (interactive
4299    (list (completing-read "Action: " gnus-mime-action-alist)))
4300   (gnus-article-check-buffer)
4301   (let ((action-pair (assoc action gnus-mime-action-alist)))
4302     (if action-pair
4303         (funcall (cdr action-pair)))))
4304
4305 (defun gnus-article-part-wrapper (n function)
4306   (save-current-buffer
4307     (set-buffer gnus-article-buffer)
4308     (when (> n (length gnus-article-mime-handle-alist))
4309       (error "No such part"))
4310     (gnus-article-goto-part n)
4311     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4312       (funcall function handle))))
4313
4314 (defun gnus-article-pipe-part (n)
4315   "Pipe MIME part N, which is the numerical prefix."
4316   (interactive "p")
4317   (gnus-article-part-wrapper n 'mm-pipe-part))
4318
4319 (defun gnus-article-save-part (n)
4320   "Save MIME part N, which is the numerical prefix."
4321   (interactive "p")
4322   (gnus-article-part-wrapper n 'mm-save-part))
4323
4324 (defun gnus-article-interactively-view-part (n)
4325   "View MIME part N interactively, which is the numerical prefix."
4326   (interactive "p")
4327   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4328
4329 (defun gnus-article-copy-part (n)
4330   "Copy MIME part N, which is the numerical prefix."
4331   (interactive "p")
4332   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4333
4334 (defun gnus-article-view-part-as-charset (n)
4335   "Copy MIME part N, which is the numerical prefix."
4336   (interactive "p")
4337   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4338
4339 (defun gnus-article-externalize-part (n)
4340   "View MIME part N externally, which is the numerical prefix."
4341   (interactive "p")
4342   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
4343
4344 (defun gnus-article-inline-part (n)
4345   "Inline MIME part N, which is the numerical prefix."
4346   (interactive "p")
4347   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4348
4349 (defun gnus-article-mime-match-handle-first (condition)
4350   (if condition
4351       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4352         (while (setq ihandle (pop alist))
4353           (if (and (cond
4354                     ((functionp condition)
4355                      (funcall condition (cdr ihandle)))
4356                     ((eq condition 'undisplayed)
4357                      (not (or (mm-handle-undisplayer (cdr ihandle))
4358                               (equal (mm-handle-media-type (cdr ihandle))
4359                                      "multipart/alternative"))))
4360                     ((eq condition 'undisplayed-alternative)
4361                      (not (mm-handle-undisplayer (cdr ihandle))))
4362                     (t t))
4363                    (gnus-article-goto-part (car ihandle))
4364                    (or (not n) (< (car ihandle) n)))
4365               (setq n (car ihandle))))
4366         (or n 1))
4367     1))
4368
4369 (defun gnus-article-view-part (&optional n)
4370   "View MIME part N, which is the numerical prefix."
4371   (interactive "P")
4372   (save-current-buffer
4373     (set-buffer gnus-article-buffer)
4374     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4375                              gnus-article-mime-match-handle-function)))
4376     (when (> n (length gnus-article-mime-handle-alist))
4377       (error "No such part"))
4378     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4379       (when (gnus-article-goto-part n)
4380         (if (equal (car handle) "multipart/alternative")
4381             (gnus-article-press-button)
4382           (when (eq (gnus-mm-display-part handle) 'internal)
4383             (gnus-set-window-start)))))))
4384
4385 (defsubst gnus-article-mime-total-parts ()
4386   (if (bufferp (car gnus-article-mime-handles))
4387       1 ;; single part
4388     (1- (length gnus-article-mime-handles))))
4389
4390 (defun gnus-mm-display-part (handle)
4391   "Display HANDLE and fix MIME button."
4392   (let ((id (get-text-property (point) 'gnus-part))
4393         (point (point))
4394         buffer-read-only)
4395     (forward-line 1)
4396     (prog1
4397         (let ((window (selected-window))
4398               (mail-parse-charset gnus-newsgroup-charset)
4399               (mail-parse-ignored-charsets
4400                (if (gnus-buffer-live-p gnus-summary-buffer)
4401                    (save-excursion
4402                      (set-buffer gnus-summary-buffer)
4403                      gnus-newsgroup-ignored-charsets)
4404                  nil)))
4405           (save-excursion
4406             (unwind-protect
4407                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4408                       (beg (point)))
4409                   (when win
4410                     (select-window win))
4411                   (goto-char point)
4412                   (forward-line)
4413                   (if (mm-handle-displayed-p handle)
4414                       ;; This will remove the part.
4415                       (mm-display-part handle)
4416                     (save-restriction
4417                       (narrow-to-region (point)
4418                                         (if (eobp) (point) (1+ (point))))
4419                       (mm-display-part handle)
4420                       ;; We narrow to the part itself and
4421                       ;; then call the treatment functions.
4422                       (goto-char (point-min))
4423                       (forward-line 1)
4424                       (narrow-to-region (point) (point-max))
4425                       (gnus-treat-article
4426                        nil id
4427                        (gnus-article-mime-total-parts)
4428                        (mm-handle-media-type handle)))))
4429               (if (window-live-p window)
4430                   (select-window window)))))
4431       (goto-char point)
4432       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4433       (gnus-insert-mime-button
4434        handle id (list (mm-handle-displayed-p handle)))
4435       (goto-char point))))
4436
4437 (defun gnus-article-goto-part (n)
4438   "Go to MIME part N."
4439   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4440     (when point
4441       (goto-char point))))
4442
4443 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4444   (let ((gnus-tmp-name
4445          (or (mail-content-type-get (mm-handle-type handle) 'name)
4446              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4447              (mail-content-type-get (mm-handle-type handle) 'url)
4448              ""))
4449         (gnus-tmp-type (mm-handle-media-type handle))
4450         (gnus-tmp-description
4451          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4452                                               "")))
4453         (gnus-tmp-dots
4454          (if (if displayed (car displayed)
4455                (mm-handle-displayed-p handle))
4456              "" "..."))
4457         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4458                            (buffer-size)))
4459         gnus-tmp-type-long b e)
4460     (when (string-match ".*/" gnus-tmp-name)
4461       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4462     (setq gnus-tmp-type-long (concat gnus-tmp-type
4463                                      (and (not (equal gnus-tmp-name ""))
4464                                           (concat "; " gnus-tmp-name))))
4465     (unless (equal gnus-tmp-description "")
4466       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4467     (unless (bolp)
4468       (insert "\n"))
4469     (setq b (point))
4470     (gnus-eval-format
4471      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4472      `(,@(gnus-local-map-property gnus-mime-button-map)
4473          gnus-callback gnus-mm-display-part
4474          gnus-part ,gnus-tmp-id
4475          article-type annotation
4476          gnus-data ,handle))
4477     (setq e (point))
4478     (widget-convert-button
4479      'link b e
4480      :mime-handle handle
4481      :action 'gnus-widget-press-button
4482      :button-keymap gnus-mime-button-map
4483      :help-echo
4484      (lambda (widget/window &optional overlay pos)
4485        ;; Needed to properly clear the message due to a bug in
4486        ;; wid-edit (XEmacs only).
4487        (if (boundp 'help-echo-owns-message)
4488            (setq help-echo-owns-message t))
4489        (format
4490         "%S: %s the MIME part; %S: more options"
4491         (aref gnus-mouse-2 0)
4492         ;; XEmacs will get a single widget arg; Emacs 21 will get
4493         ;; window, overlay, position.
4494         (if (mm-handle-displayed-p
4495              (if overlay
4496                  (with-current-buffer (gnus-overlay-buffer overlay)
4497                    (widget-get (widget-at (gnus-overlay-start overlay))
4498                                :mime-handle))
4499                (widget-get widget/window :mime-handle)))
4500             "hide" "show")
4501         (aref gnus-down-mouse-3 0))))))
4502
4503 (defun gnus-widget-press-button (elems el)
4504   (goto-char (widget-get elems :from))
4505   (gnus-article-press-button))
4506
4507 (defvar gnus-displaying-mime nil)
4508
4509 (defun gnus-display-mime (&optional ihandles)
4510   "Display the MIME parts."
4511   (save-excursion
4512     (save-selected-window
4513       (let ((window (get-buffer-window gnus-article-buffer))
4514             (point (point)))
4515         (when window
4516           (select-window window)
4517           ;; We have to do this since selecting the window
4518           ;; may change the point.  So we set the window point.
4519           (set-window-point window point)))
4520       (let* ((handles (or ihandles (mm-dissect-buffer
4521                                     gnus-article-no-strict-mime)
4522                           (mm-uu-dissect)))
4523              buffer-read-only handle name type b e display)
4524         (when (and (not ihandles)
4525                    (not gnus-displaying-mime))
4526           ;; Top-level call; we clean up.
4527           (when gnus-article-mime-handles
4528             (mm-destroy-parts gnus-article-mime-handles)
4529             (setq gnus-article-mime-handle-alist nil));; A trick.
4530           (setq gnus-article-mime-handles handles)
4531           ;; We allow users to glean info from the handles.
4532           (when gnus-article-mime-part-function
4533             (gnus-mime-part-function handles)))
4534         (if (and handles
4535                  (or (not (stringp (car handles)))
4536                      (cdr handles)))
4537             (progn
4538               (when (and (not ihandles)
4539                          (not gnus-displaying-mime))
4540                 ;; Clean up for mime parts.
4541                 (article-goto-body)
4542                 (delete-region (point) (point-max)))
4543               (let ((gnus-displaying-mime t))
4544                 (gnus-mime-display-part handles)))
4545           (save-restriction
4546             (article-goto-body)
4547             (narrow-to-region (point) (point-max))
4548             (gnus-treat-article nil 1 1)
4549             (widen)))
4550         (unless ihandles
4551           ;; Highlight the headers.
4552           (save-excursion
4553             (save-restriction
4554               (article-goto-body)
4555               (narrow-to-region (point-min) (point))
4556               (gnus-treat-article 'head))))))))
4557
4558 (defvar gnus-mime-display-multipart-as-mixed nil)
4559 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4560 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4561
4562 (defun gnus-mime-display-part (handle)
4563   (cond
4564    ;; Single part.
4565    ((not (stringp (car handle)))
4566     (gnus-mime-display-single handle))
4567    ;; User-defined multipart
4568    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4569     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4570              handle))
4571    ;; multipart/alternative
4572    ((and (equal (car handle) "multipart/alternative")
4573          (not (or gnus-mime-display-multipart-as-mixed
4574                   gnus-mime-display-multipart-alternative-as-mixed)))
4575     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4576       (push (cons id handle) gnus-article-mime-handle-alist)
4577       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4578    ;; multipart/related
4579    ((and (equal (car handle) "multipart/related")
4580          (not (or gnus-mime-display-multipart-as-mixed
4581                   gnus-mime-display-multipart-related-as-mixed)))
4582     ;;;!!!We should find the start part, but we just default
4583     ;;;!!!to the first part.
4584     ;;(gnus-mime-display-part (cadr handle))
4585     ;;;!!! Most multipart/related is an HTML message plus images.
4586     ;;;!!! Unfortunately we are unable to let W3 display those
4587     ;;;!!! included images, so we just display it as a mixed multipart.
4588     ;;(gnus-mime-display-mixed (cdr handle))
4589     ;;;!!! No, w3 can display everything just fine.
4590     (gnus-mime-display-part (cadr handle)))
4591    ((equal (car handle) "multipart/signed")
4592     (gnus-add-wash-type 'signed)
4593     (gnus-mime-display-security handle))
4594    ((equal (car handle) "multipart/encrypted")
4595     (gnus-add-wash-type 'encrypted)
4596     (gnus-mime-display-security handle))
4597    ;; Other multiparts are handled like multipart/mixed.
4598    (t
4599     (gnus-mime-display-mixed (cdr handle)))))
4600
4601 (defun gnus-mime-part-function (handles)
4602   (if (stringp (car handles))
4603       (mapcar 'gnus-mime-part-function (cdr handles))
4604     (funcall gnus-article-mime-part-function handles)))
4605
4606 (defun gnus-mime-display-mixed (handles)
4607   (mapcar 'gnus-mime-display-part handles))
4608
4609 (defun gnus-mime-display-single (handle)
4610   (let ((type (mm-handle-media-type handle))
4611         (ignored gnus-ignored-mime-types)
4612         (not-attachment t)
4613         (move nil)
4614         display text)
4615     (catch 'ignored
4616       (progn
4617         (while ignored
4618           (when (string-match (pop ignored) type)
4619             (throw 'ignored nil)))
4620         (if (and (setq not-attachment
4621                        (and (not (mm-inline-override-p handle))
4622                             (or (not (mm-handle-disposition handle))
4623                                 (equal (car (mm-handle-disposition handle))
4624                                        "inline")
4625                                 (mm-attachment-override-p handle))))
4626                  (mm-automatic-display-p handle)
4627                  (or (and
4628                       (mm-inlinable-p handle)
4629                       (mm-inlined-p handle))
4630                      (mm-automatic-external-display-p type)))
4631             (setq display t)
4632           (when (equal (mm-handle-media-supertype handle) "text")
4633             (setq text t)))
4634         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4635               beg)
4636           (push (cons id handle) gnus-article-mime-handle-alist)
4637           (when (or (not display)
4638                     (not (gnus-unbuttonized-mime-type-p type)))
4639             ;(gnus-article-insert-newline)
4640             (gnus-insert-mime-button
4641              handle id (list (or display (and not-attachment text))))
4642             (gnus-article-insert-newline)
4643             ;(gnus-article-insert-newline)
4644             ;; Remember modify the number of forward lines.
4645             (setq move t))
4646           (setq beg (point))
4647           (cond
4648            (display
4649             (when move
4650               (forward-line -1)
4651               (setq beg (point)))
4652             (let ((mail-parse-charset gnus-newsgroup-charset)
4653                   (mail-parse-ignored-charsets
4654                    (save-excursion (condition-case ()
4655                                        (set-buffer gnus-summary-buffer)
4656                                      (error))
4657                                    gnus-newsgroup-ignored-charsets)))
4658               (mm-display-part handle t))
4659             (goto-char (point-max)))
4660            ((and text not-attachment)
4661             (when move
4662               (forward-line -1)
4663               (setq beg (point)))
4664             (gnus-article-insert-newline)
4665             (mm-insert-inline handle (mm-get-part handle))
4666             (goto-char (point-max))))
4667           ;; Do highlighting.
4668           (save-excursion
4669             (save-restriction
4670               (narrow-to-region beg (point))
4671               (gnus-treat-article
4672                nil id
4673                (gnus-article-mime-total-parts)
4674                (mm-handle-media-type handle)))))))))
4675
4676 (defun gnus-unbuttonized-mime-type-p (type)
4677   "Say whether TYPE is to be unbuttonized."
4678   (unless gnus-inhibit-mime-unbuttonizing
4679     (when (catch 'found
4680             (let ((types gnus-unbuttonized-mime-types))
4681               (while types
4682                 (when (string-match (pop types) type)
4683                   (throw 'found t)))))
4684       (not (catch 'found
4685              (let ((types gnus-buttonized-mime-types))
4686                (while types
4687                  (when (string-match (pop types) type)
4688                    (throw 'found t)))))))))
4689
4690 (defun gnus-article-insert-newline ()
4691   "Insert a newline, but mark it as undeletable."
4692   (gnus-put-text-property
4693    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4694
4695 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4696   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4697          (ihandles handles)
4698          (point (point))
4699          handle buffer-read-only from props begend not-pref)
4700     (save-window-excursion
4701       (save-restriction
4702         (when ibegend
4703           (narrow-to-region (car ibegend)
4704                             (or (cdr ibegend)
4705                                 (progn
4706                                   (goto-char (car ibegend))
4707                                   (forward-line 2)
4708                                   (point))))
4709           (delete-region (point-min) (point-max))
4710           (mm-remove-parts handles))
4711         (setq begend (list (point-marker)))
4712         ;; Do the toggle.
4713         (unless (setq not-pref (cadr (member preferred ihandles)))
4714           (setq not-pref (car ihandles)))
4715         (when (or ibegend
4716                   (not preferred)
4717                   (not (gnus-unbuttonized-mime-type-p
4718                         "multipart/alternative")))
4719           (gnus-add-text-properties
4720            (setq from (point))
4721            (progn
4722              (insert (format "%d.  " id))
4723              (point))
4724            `(gnus-callback
4725              (lambda (handles)
4726                (unless ,(not ibegend)
4727                  (setq gnus-article-mime-handle-alist
4728                        ',gnus-article-mime-handle-alist))
4729                (gnus-mime-display-alternative
4730                 ',ihandles ',not-pref ',begend ,id))
4731              ,@(gnus-local-map-property gnus-mime-button-map)
4732              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4733              face ,gnus-article-button-face
4734              gnus-part ,id
4735              gnus-data ,handle))
4736           (widget-convert-button 'link from (point)
4737                                  :action 'gnus-widget-press-button
4738                                  :button-keymap gnus-widget-button-keymap)
4739           ;; Do the handles
4740           (while (setq handle (pop handles))
4741             (gnus-add-text-properties
4742              (setq from (point))
4743              (progn
4744                (insert (format "(%c) %-18s"
4745                                (if (equal handle preferred) ?* ? )
4746                                (mm-handle-media-type handle)))
4747                (point))
4748              `(gnus-callback
4749                (lambda (handles)
4750                  (unless ,(not ibegend)
4751                    (setq gnus-article-mime-handle-alist
4752                          ',gnus-article-mime-handle-alist))
4753                  (gnus-mime-display-alternative
4754                   ',ihandles ',handle ',begend ,id))
4755                ,@(gnus-local-map-property gnus-mime-button-map)
4756                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4757                face ,gnus-article-button-face
4758                gnus-part ,id
4759                gnus-data ,handle))
4760             (widget-convert-button 'link from (point)
4761                                    :action 'gnus-widget-press-button
4762                                    :button-keymap gnus-widget-button-keymap)
4763             (insert "  "))
4764           (insert "\n\n"))
4765         (when preferred
4766           (if (stringp (car preferred))
4767               (gnus-display-mime preferred)
4768             (let ((mail-parse-charset gnus-newsgroup-charset)
4769                   (mail-parse-ignored-charsets
4770                    (save-excursion (set-buffer gnus-summary-buffer)
4771                                    gnus-newsgroup-ignored-charsets)))
4772               (mm-display-part preferred)
4773               ;; Do highlighting.
4774               (save-excursion
4775                 (save-restriction
4776                   (narrow-to-region (car begend) (point-max))
4777                   (gnus-treat-article
4778                    nil (length gnus-article-mime-handle-alist)
4779                    (gnus-article-mime-total-parts)
4780                    (mm-handle-media-type handle))))))
4781           (goto-char (point-max))
4782           (setcdr begend (point-marker)))))
4783     (when ibegend
4784       (goto-char point))))
4785
4786 (defconst gnus-article-wash-status-strings
4787   (let ((alist '((cite "c" "Possible hidden citation text"
4788                        " " "All citation text visible")
4789                  (headers "h" "Hidden headers"
4790                           " " "All headers visible.")
4791                  (pgp "p" "Encrypted or signed message status hidden"
4792                       " " "No hidden encryption nor digital signature status")
4793                  (signature "s" "Signature has been hidden"
4794                             " " "Signature is visible")
4795                  (overstrike "o" "Overstrike (^H) characters applied"
4796                              " " "No overstrike characters applied")
4797                  (gnus-show-mime "m" "Mime processing is activated"
4798                                  " " "Mime processing is not activated")
4799                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4800                            " " "No /*_emphasis_*/ characters applied")))
4801         result)
4802     (dolist (entry alist result)
4803       (let ((key (nth 0 entry))
4804             (on (copy-sequence (nth 1 entry)))
4805             (on-help (nth 2 entry))
4806             (off (copy-sequence (nth 3 entry)))
4807             (off-help (nth 4 entry)))
4808         (put-text-property 0 1 'help-echo on-help on)
4809         (put-text-property 0 1 'help-echo off-help off)
4810         (push (list key on off) result))))
4811   "Alist of strings describing wash status in the mode line.
4812 Each entry has the form (KEY ON OF), where the KEY is a symbol
4813 representing the particular washing function, ON is the string to use
4814 in the article mode line when the washing function is active, and OFF
4815 is the string to use when it is inactive.")
4816
4817 (defun gnus-article-wash-status-entry (key value)
4818   (let ((entry (assoc key gnus-article-wash-status-strings)))
4819     (if value (nth 1 entry) (nth 2 entry))))
4820
4821 (defun gnus-article-wash-status ()
4822   "Return a string which display status of article washing."
4823   (save-excursion
4824     (set-buffer gnus-article-buffer)
4825     (let ((cite (memq 'cite gnus-article-wash-types))
4826           (headers (memq 'headers gnus-article-wash-types))
4827           (boring (memq 'boring-headers gnus-article-wash-types))
4828           (pgp (memq 'pgp gnus-article-wash-types))
4829           (pem (memq 'pem gnus-article-wash-types))
4830           (signed (memq 'signed gnus-article-wash-types))
4831           (encrypted (memq 'encrypted gnus-article-wash-types))
4832           (signature (memq 'signature gnus-article-wash-types))
4833           (overstrike (memq 'overstrike gnus-article-wash-types))
4834           (emphasis (memq 'emphasis gnus-article-wash-types)))
4835       (concat
4836        (gnus-article-wash-status-entry 'cite cite)
4837        (gnus-article-wash-status-entry 'headers (or headers boring))
4838        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4839        (gnus-article-wash-status-entry 'signature signature)
4840        (gnus-article-wash-status-entry 'overstrike overstrike)
4841        (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
4842        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4843
4844 (defun gnus-add-wash-type (type)
4845   "Add a washing of TYPE to the current status."
4846   (add-to-list 'gnus-article-wash-types type))
4847
4848 (defun gnus-delete-wash-type (type)
4849   "Add a washing of TYPE to the current status."
4850   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4851
4852 (defun gnus-add-image (category image)
4853   "Add IMAGE of CATEGORY to the list of displayed images."
4854   (let ((entry (assq category gnus-article-image-alist)))
4855     (unless entry
4856       (setq entry (list category))
4857       (push entry gnus-article-image-alist))
4858     (nconc entry (list image))))
4859
4860 (defun gnus-delete-images (category)
4861   "Delete all images in CATEGORY."
4862   (let ((entry (assq category gnus-article-image-alist)))
4863     (dolist (image (cdr entry))
4864       (gnus-remove-image image))
4865     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4866     (gnus-delete-wash-type category)))
4867
4868 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4869
4870 (defun gnus-article-maybe-hide-headers ()
4871   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4872 Provided for backwards compatibility."
4873   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4874                  (not (save-excursion (set-buffer gnus-summary-buffer)
4875                                       gnus-have-all-headers)))
4876              (not gnus-inhibit-hiding))
4877     (gnus-article-hide-headers)))
4878
4879 ;;; Article savers.
4880
4881 (defun gnus-output-to-file (file-name)
4882   "Append the current article to a file named FILE-NAME."
4883   (let ((artbuf (current-buffer)))
4884     (with-temp-buffer
4885       (insert-buffer-substring artbuf)
4886       ;; Append newline at end of the buffer as separator, and then
4887       ;; save it to file.
4888       (goto-char (point-max))
4889       (insert "\n")
4890       (let ((file-name-coding-system nnmail-pathname-coding-system)
4891             (pathname-coding-system nnmail-pathname-coding-system))
4892         (write-region-as-binary (point-min) (point-max) file-name 'append))
4893       t)))
4894
4895 (defun gnus-narrow-to-page (&optional arg)
4896   "Narrow the article buffer to a page.
4897 If given a numerical ARG, move forward ARG pages."
4898   (interactive "P")
4899   (setq arg (if arg (prefix-numeric-value arg) 0))
4900   (save-excursion
4901     (set-buffer gnus-article-buffer)
4902     (goto-char (point-min))
4903     (widen)
4904     ;; Remove any old next/prev buttons.
4905     (when (gnus-visual-p 'page-marker)
4906       (let ((buffer-read-only nil))
4907         (gnus-remove-text-with-property 'gnus-prev)
4908         (gnus-remove-text-with-property 'gnus-next)))
4909     (when
4910         (cond ((< arg 0)
4911                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4912               ((> arg 0)
4913                (re-search-forward page-delimiter nil 'move arg)))
4914       (goto-char (match-end 0)))
4915     (narrow-to-region
4916      (point)
4917      (if (re-search-forward page-delimiter nil 'move)
4918          (match-beginning 0)
4919        (point)))
4920     (when (and (gnus-visual-p 'page-marker)
4921                (not (= (point-min) 1)))
4922       (save-excursion
4923         (goto-char (point-min))
4924         (gnus-insert-prev-page-button)))
4925     (when (and (gnus-visual-p 'page-marker)
4926                (< (+ (point-max) 2) (buffer-size)))
4927       (save-excursion
4928         (goto-char (point-max))
4929         (gnus-insert-next-page-button)))))
4930
4931 ;; Article mode commands
4932
4933 (defun gnus-article-goto-next-page ()
4934   "Show the next page of the article."
4935   (interactive)
4936   (when (gnus-article-next-page)
4937     (goto-char (point-min))
4938     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4939
4940 (defun gnus-article-goto-prev-page ()
4941   "Show the next page of the article."
4942   (interactive)
4943   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4944     (gnus-article-prev-page nil)))
4945
4946 (defun gnus-article-next-page (&optional lines)
4947   "Show the next page of the current article.
4948 If end of article, return non-nil.  Otherwise return nil.
4949 Argument LINES specifies lines to be scrolled up."
4950   (interactive "p")
4951   (let ((start (window-start))
4952         end-of-buffer end-of-page)
4953     (save-excursion
4954       (move-to-window-line -1)
4955       (if (<= (point) start)
4956           (progn
4957             (forward-line 2)
4958             (setq start (point)))
4959         (forward-line 1)
4960         (setq start nil))
4961       (unless (or (cond ((eq (1+ (buffer-size)) (point))
4962                          (and (pos-visible-in-window-p)
4963                               (setq end-of-buffer t)))
4964                         ((eobp)
4965                          (setq end-of-page t)))
4966                   (not lines))
4967         (move-to-window-line lines)
4968         (unless (search-backward "\n\n" nil t)
4969           (setq start (point)))))
4970     (cond (end-of-buffer t)
4971           (end-of-page
4972            (gnus-narrow-to-page 1)
4973            nil)
4974           (t
4975            (if start
4976                (set-window-start (selected-window) start)
4977              (let (window-pixel-scroll-increment)
4978                (scroll-up lines)))
4979            nil))))
4980
4981 (defun gnus-article-prev-page (&optional lines)
4982   "Show previous page of current article.
4983 Argument LINES specifies lines to be scrolled down."
4984   (interactive "p")
4985   (let (beginning-of-buffer beginning-of-page)
4986     (save-excursion
4987       (move-to-window-line 0)
4988       (cond ((eq 1 (point))
4989              (setq beginning-of-buffer t))
4990             ((bobp)
4991              (setq beginning-of-page t))))
4992     (cond (beginning-of-buffer)
4993           (beginning-of-page
4994            (gnus-narrow-to-page -1))
4995           (t
4996            (condition-case nil
4997                (let (window-pixel-scroll-increment)
4998                  (scroll-down lines))
4999              (beginning-of-buffer
5000               (goto-char (point-min))))))))
5001
5002 (defun gnus-article-refer-article ()
5003   "Read article specified by message-id around point."
5004   (interactive)
5005   (let ((point (point)))
5006     (search-forward ">" nil t)          ;Move point to end of "<....>".
5007     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
5008         (let ((message-id (match-string 1)))
5009           (goto-char point)
5010           (set-buffer gnus-summary-buffer)
5011           (gnus-summary-refer-article message-id))
5012       (goto-char (point))
5013       (error "No references around point"))))
5014
5015 (defun gnus-article-show-summary ()
5016   "Reconfigure windows to show summary buffer."
5017   (interactive)
5018   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5019       (error "There is no summary buffer for this article buffer")
5020     (gnus-article-set-globals)
5021     (gnus-configure-windows 'article)
5022     (gnus-summary-goto-subject gnus-current-article)
5023     (gnus-summary-position-point)))
5024
5025 (defun gnus-article-describe-briefly ()
5026   "Describe article mode commands briefly."
5027   (interactive)
5028   (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")))
5029
5030 (defun gnus-article-summary-command ()
5031   "Execute the last keystroke in the summary buffer."
5032   (interactive)
5033   (let ((obuf (current-buffer))
5034         (owin (current-window-configuration))
5035         func)
5036     (switch-to-buffer gnus-article-current-summary 'norecord)
5037     (setq func (lookup-key (current-local-map) (this-command-keys)))
5038     (call-interactively func)
5039     (set-buffer obuf)
5040     (set-window-configuration owin)
5041     (set-window-point (get-buffer-window (current-buffer)) (point))))
5042
5043 (defun gnus-article-summary-command-nosave ()
5044   "Execute the last keystroke in the summary buffer."
5045   (interactive)
5046   (let (func)
5047     (pop-to-buffer gnus-article-current-summary 'norecord)
5048     (setq func (lookup-key (current-local-map) (this-command-keys)))
5049     (call-interactively func)))
5050
5051 (defun gnus-article-check-buffer ()
5052   "Beep if not in an article buffer."
5053   (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5054     (error "Command invoked outside of a Gnus article buffer")))
5055
5056 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5057   "Read a summary buffer key sequence and execute it from the article buffer."
5058   (interactive "P")
5059   (gnus-article-check-buffer)
5060   (let ((nosaves
5061          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5062            "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5063            "=" "^" "\M-^" "|"))
5064         (nosave-but-article
5065          '("A\r"))
5066         (nosave-in-article
5067          '("\C-d"))
5068         (up-to-top
5069          '("n" "Gn" "p" "Gp"))
5070         keys new-sum-point)
5071     (save-excursion
5072       (set-buffer gnus-article-current-summary)
5073       (let (gnus-pick-mode)
5074         (push (or key last-command-event) unread-command-events)
5075         (setq keys (static-if (featurep 'xemacs)
5076                        (events-to-keys (read-key-sequence nil))
5077                      (read-key-sequence nil)))))
5078     (message "")
5079
5080     (if (or (member keys nosaves)
5081             (member keys nosave-but-article)
5082             (member keys nosave-in-article))
5083         (let (func)
5084           (save-window-excursion
5085             (pop-to-buffer gnus-article-current-summary 'norecord)
5086             ;; We disable the pick minor mode commands.
5087             (let (gnus-pick-mode)
5088               (setq func (lookup-key (current-local-map) keys))))
5089           (if (or (not func)
5090                   (numberp func))
5091               (ding)
5092             (unless (member keys nosave-in-article)
5093               (set-buffer gnus-article-current-summary))
5094             (call-interactively func)
5095             (setq new-sum-point (point)))
5096           (when (member keys nosave-but-article)
5097             (pop-to-buffer gnus-article-buffer 'norecord)))
5098       ;; These commands should restore window configuration.
5099       (let ((obuf (current-buffer))
5100             (owin (current-window-configuration))
5101             (opoint (point))
5102             (summary gnus-article-current-summary)
5103             func in-buffer selected)
5104         (if not-restore-window
5105             (pop-to-buffer summary 'norecord)
5106           (switch-to-buffer summary 'norecord))
5107         (setq in-buffer (current-buffer))
5108         ;; We disable the pick minor mode commands.
5109         (if (and (setq func (let (gnus-pick-mode)
5110                               (lookup-key (current-local-map) keys)))
5111                  (functionp func))
5112             (progn
5113               (call-interactively func)
5114               (setq new-sum-point (point))
5115               (when (eq in-buffer (current-buffer))
5116                 (setq selected (gnus-summary-select-article))
5117                 (set-buffer obuf)
5118                 (unless not-restore-window
5119                   (set-window-configuration owin))
5120                 (when (eq selected 'old)
5121                   (article-goto-body)
5122                   (set-window-start (get-buffer-window (current-buffer))
5123                                     1)
5124                   (set-window-point (get-buffer-window (current-buffer))
5125                                     (point)))
5126                 (let ((win (get-buffer-window gnus-article-current-summary)))
5127                   (when win
5128                     (set-window-point win new-sum-point))))    )
5129           (switch-to-buffer gnus-article-buffer)
5130           (ding))))))
5131
5132 (defun gnus-article-describe-key (key)
5133   "Display documentation of the function invoked by KEY.  KEY is a string."
5134   (interactive "kDescribe key: ")
5135   (gnus-article-check-buffer)
5136   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5137       (save-excursion
5138         (set-buffer gnus-article-current-summary)
5139         (let (gnus-pick-mode)
5140           (if (featurep 'xemacs)
5141               (progn
5142                 (push (elt key 0) unread-command-events)
5143                 (setq key (events-to-keys
5144                            (read-key-sequence "Describe key: "))))
5145             (setq unread-command-events
5146                   (mapcar
5147                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5148                    key))
5149             (setq key (read-key-sequence "Describe key: "))))
5150         (describe-key key))
5151     (describe-key key)))
5152
5153 (defun gnus-article-describe-key-briefly (key &optional insert)
5154   "Display documentation of the function invoked by KEY.  KEY is a string."
5155   (interactive "kDescribe key: \nP")
5156   (gnus-article-check-buffer)
5157   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5158       (save-excursion
5159         (set-buffer gnus-article-current-summary)
5160         (let (gnus-pick-mode)
5161           (if (featurep 'xemacs)
5162               (progn
5163                 (push (elt key 0) unread-command-events)
5164                 (setq key (events-to-keys
5165                            (read-key-sequence "Describe key: "))))
5166             (setq unread-command-events
5167                   (mapcar
5168                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5169                    key))
5170             (setq key (read-key-sequence "Describe key: "))))
5171         (describe-key-briefly key insert))
5172     (describe-key-briefly key insert)))
5173
5174 (defun gnus-article-reply-with-original (&optional wide)
5175   "Start composing a reply mail to the current message.
5176 The text in the region will be yanked.  If the region isn't active,
5177 the entire article will be yanked."
5178   (interactive "P")
5179   (let ((article (cdr gnus-article-current)) cont)
5180     (if (not (mark t))
5181         (gnus-summary-reply (list (list article)) wide)
5182       (setq cont (buffer-substring (point) (mark t)))
5183       ;; Deactivate active regions.
5184       (when (and (boundp 'transient-mark-mode)
5185                  transient-mark-mode)
5186         (setq mark-active nil))
5187       (gnus-summary-reply
5188        (list (list article cont)) wide))))
5189
5190 (defun gnus-article-followup-with-original ()
5191   "Compose a followup to the current article.
5192 The text in the region will be yanked.  If the region isn't active,
5193 the entire article will be yanked."
5194   (interactive)
5195   (let ((article (cdr gnus-article-current))
5196         cont)
5197     (if (not (mark t))
5198         (gnus-summary-followup (list (list article)))
5199       (setq cont (buffer-substring (point) (mark t)))
5200       ;; Deactivate active regions.
5201       (when (and (boundp 'transient-mark-mode)
5202                  transient-mark-mode)
5203         (setq mark-active nil))
5204       (gnus-summary-followup
5205        (list (list article cont))))))
5206
5207 (defun gnus-article-hide (&optional arg force)
5208   "Hide all the gruft in the current article.
5209 This means that PGP stuff, signatures, cited text and (some)
5210 headers will be hidden.
5211 If given a prefix, show the hidden text instead."
5212   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5213   (gnus-article-hide-headers arg)
5214   (gnus-article-hide-list-identifiers arg)
5215   (gnus-article-hide-pgp arg)
5216   (gnus-article-hide-citation-maybe arg force)
5217   (gnus-article-hide-signature arg))
5218
5219 (defun gnus-article-maybe-highlight ()
5220   "Do some article highlighting if article highlighting is requested."
5221   (when (gnus-visual-p 'article-highlight 'highlight)
5222     (gnus-article-highlight-some)))
5223
5224 (defun gnus-check-group-server ()
5225   ;; Make sure the connection to the server is alive.
5226   (unless (gnus-server-opened
5227            (gnus-find-method-for-group gnus-newsgroup-name))
5228     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5229     (gnus-request-group gnus-newsgroup-name t)))
5230
5231 (eval-when-compile
5232   (autoload 'nneething-get-file-name "nneething"))
5233
5234 (defun gnus-request-article-this-buffer (article group)
5235   "Get an article and insert it into this buffer.
5236 T-gnus change: Insert an article into `gnus-original-article-buffer'."
5237   (let (do-update-line sparse-header)
5238     ;; The current buffer is `gnus-article-buffer'.
5239     (prog1
5240         (save-excursion
5241           (erase-buffer)
5242           (gnus-kill-all-overlays)
5243           (setq group (or group gnus-newsgroup-name))
5244
5245           ;; Using `gnus-request-article' directly will insert the article into
5246           ;; `nntp-server-buffer' - so we'll save some time by not having to
5247           ;; copy it from the server buffer into the article buffer.
5248
5249           ;; We only request an article by message-id when we do not have the
5250           ;; headers for it, so we'll have to get those.
5251           (when (stringp article)
5252             (gnus-read-header article))
5253
5254           ;; If the article number is negative, that means that this article
5255           ;; doesn't belong in this newsgroup (possibly), so we find its
5256           ;; message-id and request it by id instead of number.
5257           (when (and (numberp article)
5258                      gnus-summary-buffer
5259                      (get-buffer gnus-summary-buffer)
5260                      (gnus-buffer-exists-p gnus-summary-buffer))
5261             (save-excursion
5262               (set-buffer gnus-summary-buffer)
5263               (let ((header (gnus-summary-article-header article)))
5264                 (when (< article 0)
5265                   (cond
5266                    ((memq article gnus-newsgroup-sparse)
5267                     ;; This is a sparse gap article.
5268                     (setq do-update-line article)
5269                     (setq article (mail-header-id header))
5270                     (setq sparse-header (gnus-read-header article))
5271                     (setq gnus-newsgroup-sparse
5272                           (delq article gnus-newsgroup-sparse)))
5273                    ((vectorp header)
5274                     ;; It's a real article.
5275                     (setq article (mail-header-id header)))
5276                    (t
5277                     ;; It is an extracted pseudo-article.
5278                     (setq article 'pseudo)
5279                     (gnus-request-pseudo-article header))))
5280
5281                 (let ((method (gnus-find-method-for-group
5282                                gnus-newsgroup-name)))
5283                   (when (and (eq (car method) 'nneething)
5284                              (vectorp header))
5285                     (let ((dir (nneething-get-file-name
5286                                 (mail-header-id header))))
5287                       (when (and (stringp dir)
5288                                  (file-directory-p dir))
5289                         (setq article 'nneething)
5290                         (gnus-group-enter-directory dir))))))))
5291           (setq gnus-original-article (cons group article))
5292
5293           ;; The current buffer is `gnus-original-article-buffer'.
5294           (if (get-buffer gnus-original-article-buffer)
5295               (set-buffer gnus-original-article-buffer)
5296             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5297             (set-buffer-multibyte nil)
5298             (buffer-disable-undo)
5299             (setq major-mode 'gnus-original-article-mode)
5300             (setq buffer-read-only nil))
5301
5302           (cond
5303            ;; Refuse to select canceled articles.
5304            ((and (numberp article)
5305                  gnus-summary-buffer
5306                  (get-buffer gnus-summary-buffer)
5307                  (gnus-buffer-exists-p gnus-summary-buffer)
5308                  (eq (cdr (save-excursion
5309                             (set-buffer gnus-summary-buffer)
5310                             (assq article gnus-newsgroup-reads)))
5311                      gnus-canceled-mark))
5312             nil)
5313            ;; Check the backlog.
5314            ((and gnus-keep-backlog
5315                  (gnus-backlog-request-article group article (current-buffer)))
5316             'article)
5317            ;; Check asynchronous pre-fetch.
5318            ((gnus-async-request-fetched-article group article (current-buffer))
5319             (gnus-async-prefetch-next group article gnus-summary-buffer)
5320             (when (and (numberp article) gnus-keep-backlog)
5321               (gnus-backlog-enter-article group article (current-buffer)))
5322             'article)
5323            ;; Check the cache.
5324            ((and gnus-use-cache
5325                  (numberp article)
5326                  (gnus-cache-request-article article group))
5327             'article)
5328            ;; Check the agent cache.
5329            ((and gnus-agent gnus-agent-cache gnus-plugged
5330                  (numberp article)
5331                  (gnus-agent-request-article article group))
5332             'article)
5333            ;; Get the article and put into the article buffer.
5334            ((or (stringp article)
5335                 (numberp article))
5336             (let ((gnus-override-method gnus-override-method)
5337                   (methods (and (stringp article)
5338                                 gnus-refer-article-method))
5339                   result
5340                   (buffer-read-only nil))
5341               (if (or (not (listp methods))
5342                       (and (symbolp (car methods))
5343                            (assq (car methods) nnoo-definition-alist)))
5344                   (setq methods (list methods)))
5345               (when (and (null gnus-override-method)
5346                          methods)
5347                 (setq gnus-override-method (pop methods)))
5348               (while (not result)
5349                 (when (eq gnus-override-method 'current)
5350                   (setq gnus-override-method
5351                         (with-current-buffer gnus-summary-buffer
5352                           gnus-current-select-method)))
5353                 (erase-buffer)
5354                 (gnus-kill-all-overlays)
5355                 (let ((gnus-newsgroup-name group))
5356                   (gnus-check-group-server))
5357                 (when (gnus-request-article article group (current-buffer))
5358                   (when (numberp article)
5359                     (gnus-async-prefetch-next group article
5360                                               gnus-summary-buffer)
5361                     (when gnus-keep-backlog
5362                       (gnus-backlog-enter-article
5363                        group article (current-buffer))))
5364                   (setq result 'article))
5365                 (if (not result)
5366                     (if methods
5367                         (setq gnus-override-method (pop methods))
5368                       (setq result 'done))))
5369               (and (eq result 'article) 'article)))
5370            ;; It was a pseudo.
5371            (t article)))
5372
5373       ;; Associate this article with the current summary buffer.
5374       (setq gnus-article-current-summary gnus-summary-buffer)
5375
5376       ;; Copy the requested article from `gnus-original-article-buffer'.
5377       (unless (equal (buffer-name (current-buffer))
5378                      (buffer-name (get-buffer gnus-original-article-buffer)))
5379         (insert-buffer gnus-original-article-buffer))
5380
5381       ;; Decode charsets.
5382       (run-hooks 'gnus-article-decode-hook)
5383       ;; Mark article as decoded or not.
5384       (setq gnus-article-decoded-p gnus-article-decode-hook)
5385
5386       ;; Update sparse articles.
5387       (when (and do-update-line
5388                  (or (numberp article)
5389                      (stringp article)))
5390         (let ((buf (current-buffer)))
5391           (set-buffer gnus-summary-buffer)
5392           (gnus-summary-update-article do-update-line sparse-header)
5393           (gnus-summary-goto-subject do-update-line nil t)
5394           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5395                             (point))
5396           (set-buffer buf))))))
5397
5398 ;;;
5399 ;;; Article editing
5400 ;;;
5401
5402 (defcustom gnus-article-edit-mode-hook nil
5403   "Hook run in article edit mode buffers."
5404   :group 'gnus-article-various
5405   :type 'hook)
5406
5407 (defcustom gnus-article-edit-article-setup-function
5408   'gnus-article-mime-edit-article-setup
5409   "Function called to setup an editing article buffer."
5410   :group 'gnus-article-various
5411   :type 'function)
5412
5413 (defvar gnus-article-edit-done-function nil)
5414
5415 (defvar gnus-article-edit-mode-map nil)
5416
5417 ;; Should we be using derived.el for this?
5418 (unless gnus-article-edit-mode-map
5419   (setq gnus-article-edit-mode-map (make-sparse-keymap))
5420   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5421
5422   (gnus-define-keys gnus-article-edit-mode-map
5423     "\C-c\C-c" gnus-article-edit-done
5424     "\C-c\C-k" gnus-article-edit-exit)
5425
5426   (gnus-define-keys (gnus-article-edit-wash-map
5427                      "\C-c\C-w" gnus-article-edit-mode-map)
5428     "f" gnus-article-edit-full-stops))
5429
5430 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5431   "Major mode for editing articles.
5432 This is an extended text-mode.
5433
5434 \\{gnus-article-edit-mode-map}"
5435   (make-local-variable 'gnus-article-edit-done-function)
5436   (make-local-variable 'gnus-prev-winconf)
5437   (set (make-local-variable 'font-lock-defaults)
5438        '(message-font-lock-keywords t))
5439   (setq buffer-read-only nil)
5440   (buffer-enable-undo)
5441   (widen))
5442
5443 (defun gnus-article-edit (&optional force)
5444   "Edit the current article.
5445 This will have permanent effect only in mail groups.
5446 If FORCE is non-nil, allow editing of articles even in read-only
5447 groups."
5448   (interactive "P")
5449   (when (and (not force)
5450              (gnus-group-read-only-p))
5451     (error "The current newsgroup does not support article editing"))
5452   (gnus-article-date-original)
5453   (gnus-article-edit-article
5454    'ignore
5455    `(lambda (no-highlight)
5456       'ignore
5457       (gnus-summary-edit-article-done
5458        ,(or (mail-header-references gnus-current-headers) "")
5459        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5460
5461 (defun gnus-article-edit-article (start-func exit-func)
5462   "Start editing the contents of the current article buffer."
5463   (let ((winconf (current-window-configuration)))
5464     (set-buffer gnus-article-buffer)
5465     (gnus-article-edit-mode)
5466     (funcall start-func)
5467     (set-buffer-modified-p nil)
5468     (gnus-configure-windows 'edit-article)
5469     (setq gnus-article-edit-done-function exit-func)
5470     (setq gnus-prev-winconf winconf)
5471     (when gnus-article-edit-article-setup-function
5472       (funcall gnus-article-edit-article-setup-function))
5473     (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5474
5475 (defun gnus-article-edit-done (&optional arg)
5476   "Update the article edits and exit."
5477   (interactive "P")
5478   (let ((func gnus-article-edit-done-function)
5479         (buf (current-buffer))
5480         (start (window-start)))
5481     (remove-hook 'gnus-article-mode-hook
5482                  'gnus-article-mime-edit-article-unwind)
5483     ;; We remove all text props from the article buffer.
5484     (let ((content
5485            (buffer-substring-no-properties (point-min) (point-max)))
5486           (p (point)))
5487       (erase-buffer)
5488       (insert content)
5489       (let ((winconf gnus-prev-winconf))
5490         (gnus-article-mode)
5491         (set-window-configuration winconf)
5492         ;; Tippy-toe some to make sure that point remains where it was.
5493         (save-current-buffer
5494           (set-buffer buf)
5495           (set-window-start (get-buffer-window (current-buffer)) start)
5496           (goto-char p))))
5497     (save-excursion
5498       (set-buffer buf)
5499       (let ((buffer-read-only nil))
5500         (funcall func arg))
5501       ;; The cache and backlog have to be flushed somewhat.
5502       (when gnus-keep-backlog
5503         (gnus-backlog-remove-article
5504          (car gnus-article-current) (cdr gnus-article-current)))
5505       ;; Flush original article as well.
5506       (save-excursion
5507         (when (get-buffer gnus-original-article-buffer)
5508           (set-buffer gnus-original-article-buffer)
5509           (setq gnus-original-article nil)))
5510       (when gnus-use-cache
5511         (gnus-cache-update-article
5512          (car gnus-article-current) (cdr gnus-article-current))))
5513     (set-buffer buf)
5514     (set-window-start (get-buffer-window buf) start)
5515     (set-window-point (get-buffer-window buf) (point))))
5516
5517 (defun gnus-article-edit-exit ()
5518   "Exit the article editing without updating."
5519   (interactive)
5520   (when (or (not (buffer-modified-p))
5521             (yes-or-no-p "Article modified; kill anyway? "))
5522     (let ((curbuf (current-buffer))
5523           (p (point))
5524           (window-start (window-start)))
5525       (erase-buffer)
5526       (if (gnus-buffer-live-p gnus-original-article-buffer)
5527           (insert-buffer gnus-original-article-buffer))
5528       (let ((winconf gnus-prev-winconf))
5529         (gnus-article-mode)
5530         (set-window-configuration winconf)
5531         ;; Tippy-toe some to make sure that point remains where it was.
5532         (save-current-buffer
5533           (set-buffer curbuf)
5534           (set-window-start (get-buffer-window (current-buffer)) window-start)
5535           (goto-char p))))))
5536
5537 (defun gnus-article-edit-full-stops ()
5538   "Interactively repair spacing at end of sentences."
5539   (interactive)
5540   (save-excursion
5541     (goto-char (point-min))
5542     (search-forward-regexp "^$" nil t)
5543     (let ((case-fold-search nil))
5544       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5545
5546 ;;;
5547 ;;; Article editing with MIME-Edit
5548 ;;;
5549
5550 (defcustom gnus-article-mime-edit-article-setup-hook nil
5551   "Hook run after setting up a MIME editing article buffer."
5552   :group 'gnus-article-various
5553   :type 'hook)
5554
5555 (defun gnus-article-mime-edit-article-unwind ()
5556   "Unwind `gnus-article-buffer' if article editing was given up."
5557   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5558   (when (featurep 'font-lock)
5559     (setq font-lock-defaults nil)
5560     (font-lock-mode -1))
5561   (when mime-edit-mode-flag
5562     (mime-edit-exit 'nomime 'no-error)
5563     (message "")))
5564
5565 (defun gnus-article-mime-edit-article-setup ()
5566   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5567 after replacing with the original article."
5568   (setq gnus-show-mime t)
5569   (setq gnus-article-edit-done-function
5570         `(lambda (&rest args)
5571            (when mime-edit-mode-flag
5572              (let (mime-edit-insert-user-agent-field)
5573                (mime-edit-exit))
5574              (message ""))
5575            (goto-char (point-min))
5576            (let (case-fold-search)
5577              (when (re-search-forward
5578                     (format "^%s$" (regexp-quote mail-header-separator))
5579                     nil t)
5580                (replace-match "")))
5581            (apply ,gnus-article-edit-done-function args)
5582            (insert
5583             (prog1
5584                 (buffer-substring-no-properties (point-min) (point-max))
5585               (set-buffer (get-buffer-create gnus-original-article-buffer))
5586               (erase-buffer)))
5587            (setq gnus-current-headers (gnus-article-make-full-mail-header))
5588            (set-buffer gnus-article-buffer)
5589            (gnus-article-prepare-display)))
5590   (substitute-key-definition 'gnus-article-edit-done
5591                              'gnus-article-mime-edit-done
5592                              gnus-article-edit-mode-map)
5593   (substitute-key-definition 'gnus-article-edit-exit
5594                              'gnus-article-mime-edit-exit
5595                              gnus-article-edit-mode-map)
5596   (erase-buffer)
5597   (insert-buffer gnus-original-article-buffer)
5598   (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5599     (fset 'mime-edit-decode-single-part-in-buffer
5600           (lambda (&rest args)
5601             (if (let ((content-type (car args)))
5602                   (and (eq 'message (mime-content-type-primary-type
5603                                      content-type))
5604                        (eq 'rfc822 (mime-content-type-subtype content-type))))
5605                 (setcar (cdr args) 'not-decode-text))
5606             (apply ofn args)))
5607     (unwind-protect
5608         (mime-edit-again)
5609       (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5610   (when (featurep 'font-lock)
5611     (set (make-local-variable 'font-lock-defaults)
5612          '(message-font-lock-keywords t))
5613     (font-lock-set-defaults)
5614     (turn-on-font-lock))
5615   (set-buffer-modified-p nil)
5616   (delete-other-windows)
5617   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5618   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5619
5620 (defun gnus-article-mime-edit-done (&optional arg)
5621   "Update the article MIME edits and exit."
5622   (interactive "P")
5623   (when (featurep 'font-lock)
5624     (setq font-lock-defaults nil)
5625     (font-lock-mode -1))
5626   (gnus-article-edit-done arg))
5627
5628 (defun gnus-article-mime-edit-exit ()
5629   "Exit the article MIME editing without updating."
5630   (interactive)
5631   (when (or (not (buffer-modified-p))
5632             (yes-or-no-p "Article modified; kill anyway? "))
5633     (when (featurep 'font-lock)
5634       (setq font-lock-defaults nil)
5635       (font-lock-mode -1))
5636     (when mime-edit-mode-flag
5637       (let (mime-edit-insert-user-agent-field)
5638         (mime-edit-exit))
5639       (message ""))
5640     (goto-char (point-min))
5641     (let (case-fold-search)
5642       (when (re-search-forward
5643              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5644         (replace-match "")))
5645     (let ((winconf gnus-prev-winconf))
5646       (insert (prog1
5647                   (buffer-substring-no-properties (point-min) (point-max))
5648                 (set-buffer (get-buffer-create gnus-original-article-buffer))
5649                 (erase-buffer)))
5650       (setq gnus-current-headers (gnus-article-make-full-mail-header))
5651       (set-buffer gnus-article-buffer)
5652       (gnus-article-prepare-display)
5653       (set-window-configuration winconf))))
5654
5655 ;;;
5656 ;;; Article highlights
5657 ;;;
5658
5659 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5660
5661 ;;; Internal Variables:
5662
5663 (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\\)\\)"
5664   "Regular expression that matches URLs."
5665   :group 'gnus-article-buttons
5666   :type 'regexp)
5667
5668 (defcustom gnus-button-alist
5669   `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5670      0 t gnus-button-handle-news 3)
5671     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5672      gnus-button-handle-news 2)
5673     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5674      1 t
5675      gnus-button-fetch-group 4)
5676     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5677     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5678      t gnus-button-message-id 3)
5679     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5680     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5681     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5682     ;; This is info
5683     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
5684      gnus-button-handle-info 2)
5685     ;; This is how URLs _should_ be embedded in text...
5686     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5687     ;; Raw URLs.
5688     (,gnus-button-url-regexp 0 t browse-url 0))
5689   "*Alist of regexps matching buttons in article bodies.
5690
5691 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5692 REGEXP: is the string matching text around the button,
5693 BUTTON: is the number of the regexp grouping actually matching the button,
5694 FORM: is a lisp expression which must eval to true for the button to
5695 be added,
5696 CALLBACK: is the function to call when the user push this button, and each
5697 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5698
5699 CALLBACK can also be a variable, in that case the value of that
5700 variable it the real callback function."
5701   :group 'gnus-article-buttons
5702   :type '(repeat (list regexp
5703                        (integer :tag "Button")
5704                        (sexp :tag "Form")
5705                        (function :tag "Callback")
5706                        (repeat :tag "Par"
5707                                :inline t
5708                                (integer :tag "Regexp group")))))
5709
5710 (defcustom gnus-header-button-alist
5711   `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5712      0 t gnus-button-message-id 0)
5713     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5714     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5715      0 t gnus-button-mailto 0)
5716     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5717     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5718     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5719     ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5720     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5721      gnus-button-message-id 3))
5722   "*Alist of headers and regexps to match buttons in article heads.
5723
5724 This alist is very similar to `gnus-button-alist', except that each
5725 alist has an additional HEADER element first in each entry:
5726
5727 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5728
5729 HEADER is a regexp to match a header.  For a fuller explanation, see
5730 `gnus-button-alist'."
5731   :group 'gnus-article-buttons
5732   :group 'gnus-article-headers
5733   :type '(repeat (list (regexp :tag "Header")
5734                        regexp
5735                        (integer :tag "Button")
5736                        (sexp :tag "Form")
5737                        (function :tag "Callback")
5738                        (repeat :tag "Par"
5739                                :inline t
5740                                (integer :tag "Regexp group")))))
5741
5742 (defvar gnus-button-regexp nil)
5743 (defvar gnus-button-marker-list nil)
5744 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5745
5746 (defvar gnus-button-last nil)
5747 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5748
5749 ;;; Commands:
5750
5751 (defun gnus-article-push-button (event)
5752   "Check text under the mouse pointer for a callback function.
5753 If the text under the mouse pointer has a `gnus-callback' property,
5754 call it with the value of the `gnus-data' text property."
5755   (interactive "e")
5756   (set-buffer (window-buffer (posn-window (event-start event))))
5757   (let* ((pos (posn-point (event-start event)))
5758          (data (get-text-property pos 'gnus-data))
5759          (fun (get-text-property pos 'gnus-callback)))
5760     (goto-char pos)
5761     (when fun
5762       (funcall fun data))))
5763
5764 (defun gnus-article-press-button ()
5765   "Check text at point for a callback function.
5766 If the text at point has a `gnus-callback' property,
5767 call it with the value of the `gnus-data' text property."
5768   (interactive)
5769   (let* ((data (get-text-property (point) 'gnus-data))
5770          (fun (get-text-property (point) 'gnus-callback)))
5771     (when fun
5772       (funcall fun data))))
5773
5774 (defun gnus-article-prev-button (n)
5775   "Move point to N buttons backward.
5776 If N is negative, move forward instead."
5777   (interactive "p")
5778   (gnus-article-next-button (- n)))
5779
5780 (defun gnus-article-next-button (n)
5781   "Move point to N buttons forward.
5782 If N is negative, move backward instead."
5783   (interactive "p")
5784   (let ((function (if (< n 0) 'previous-single-property-change
5785                     'next-single-property-change))
5786         (inhibit-point-motion-hooks t)
5787         (backward (< n 0))
5788         (limit (if (< n 0) (point-min) (point-max))))
5789     (setq n (abs n))
5790     (while (and (not (= limit (point)))
5791                 (> n 0))
5792       ;; Skip past the current button.
5793       (when (get-text-property (point) 'gnus-callback)
5794         (goto-char (funcall function (point) 'gnus-callback nil limit)))
5795       ;; Go to the next (or previous) button.
5796       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5797       ;; Put point at the start of the button.
5798       (when (and backward (not (get-text-property (point) 'gnus-callback)))
5799         (goto-char (funcall function (point) 'gnus-callback nil limit)))
5800       ;; Skip past intangible buttons.
5801       (when (get-text-property (point) 'intangible)
5802         (incf n))
5803       (decf n))
5804     (unless (zerop n)
5805       (gnus-message 5 "No more buttons"))
5806     n))
5807
5808 (defun gnus-article-highlight (&optional force)
5809   "Highlight current article.
5810 This function calls `gnus-article-highlight-headers',
5811 `gnus-article-highlight-citation',
5812 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5813 do the highlighting.  See the documentation for those functions."
5814   (interactive (list 'force))
5815   (gnus-article-highlight-headers)
5816   (gnus-article-highlight-citation force)
5817   (gnus-article-highlight-signature)
5818   (gnus-article-add-buttons force)
5819   (gnus-article-add-buttons-to-head))
5820
5821 (defun gnus-article-highlight-some (&optional force)
5822   "Highlight current article.
5823 This function calls `gnus-article-highlight-headers',
5824 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5825 do the highlighting.  See the documentation for those functions."
5826   (interactive (list 'force))
5827   (gnus-article-highlight-headers)
5828   (gnus-article-highlight-signature)
5829   (gnus-article-add-buttons))
5830
5831 (defun gnus-article-highlight-headers ()
5832   "Highlight article headers as specified by `gnus-header-face-alist'."
5833   (interactive)
5834   (save-excursion
5835     (set-buffer gnus-article-buffer)
5836     (save-restriction
5837       (let ((alist gnus-header-face-alist)
5838             (buffer-read-only nil)
5839             (case-fold-search t)
5840             (inhibit-point-motion-hooks t)
5841             entry regexp header-face field-face from hpoints fpoints)
5842         (article-narrow-to-head)
5843         (while (setq entry (pop alist))
5844           (goto-char (point-min))
5845           (setq regexp (concat "^\\("
5846                                (if (string-equal "" (nth 0 entry))
5847                                    "[^\t ]"
5848                                  (nth 0 entry))
5849                                "\\)")
5850                 header-face (nth 1 entry)
5851                 field-face (nth 2 entry))
5852           (while (and (re-search-forward regexp nil t)
5853                       (not (eobp)))
5854             (beginning-of-line)
5855             (setq from (point))
5856             (unless (search-forward ":" nil t)
5857               (forward-char 1))
5858             (when (and header-face
5859                        (not (memq (point) hpoints)))
5860               (push (point) hpoints)
5861               (gnus-put-text-property from (point) 'face header-face))
5862             (when (and field-face
5863                        (not (memq (setq from (point)) fpoints)))
5864               (push from fpoints)
5865               (if (re-search-forward "^[^ \t]" nil t)
5866                   (forward-char -2)
5867                 (goto-char (point-max)))
5868               (gnus-put-text-property from (point) 'face field-face))))))))
5869
5870 (defun gnus-article-highlight-signature ()
5871   "Highlight the signature in an article.
5872 It does this by highlighting everything after
5873 `gnus-signature-separator' using `gnus-signature-face'."
5874   (interactive)
5875   (when gnus-signature-face
5876     (save-excursion
5877       (set-buffer gnus-article-buffer)
5878       (let ((buffer-read-only nil)
5879             (inhibit-point-motion-hooks t))
5880         (save-restriction
5881           (when (gnus-article-narrow-to-signature)
5882             (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5883                               'face gnus-signature-face)))))))
5884
5885 (defun gnus-article-buttonize-signature ()
5886   "Add button to the signature."
5887   (interactive)
5888   (save-excursion
5889     (set-buffer gnus-article-buffer)
5890     (let ((buffer-read-only nil)
5891           (inhibit-point-motion-hooks t))
5892       (when (gnus-article-search-signature)
5893         (gnus-article-add-button (match-beginning 0) (match-end 0)
5894                                  'gnus-signature-toggle
5895                                  (set-marker (make-marker)
5896                                              (1+ (match-end 0))))))))
5897
5898 (defun gnus-button-in-region-p (b e prop)
5899   "Say whether PROP exists in the region."
5900   (text-property-not-all b e prop nil))
5901
5902 (defun gnus-article-add-buttons (&optional force)
5903   "Find external references in the article and make buttons of them.
5904 \"External references\" are things like Message-IDs and URLs, as
5905 specified by `gnus-button-alist'."
5906   (interactive (list 'force))
5907   (save-excursion
5908     (set-buffer gnus-article-buffer)
5909     (let ((buffer-read-only nil)
5910           (inhibit-point-motion-hooks t)
5911           (case-fold-search t)
5912           (alist gnus-button-alist)
5913           beg entry regexp)
5914       ;; Remove all old markers.
5915       (let (marker entry new-list)
5916         (while (setq marker (pop gnus-button-marker-list))
5917           (if (or (< marker (point-min)) (>= marker (point-max)))
5918               (push marker new-list)
5919             (goto-char marker)
5920             (when (setq entry (gnus-button-entry))
5921               (put-text-property (match-beginning (nth 1 entry))
5922                                  (match-end (nth 1 entry))
5923                                  'gnus-callback nil))
5924             (set-marker marker nil)))
5925         (setq gnus-button-marker-list new-list))
5926       ;; We skip the headers.
5927       (article-goto-body)
5928       (setq beg (point))
5929       (while (setq entry (pop alist))
5930         (setq regexp (car entry))
5931         (goto-char beg)
5932         (while (re-search-forward regexp nil t)
5933           (let* ((start (and entry (match-beginning (nth 1 entry))))
5934                  (end (and entry (match-end (nth 1 entry))))
5935                  (from (match-beginning 0)))
5936             (when (and (or (eq t (nth 2 entry))
5937                            (eval (nth 2 entry)))
5938                        (not (gnus-button-in-region-p
5939                              start end 'gnus-callback)))
5940               ;; That optional form returned non-nil, so we add the
5941               ;; button.
5942               (gnus-article-add-button
5943                start end 'gnus-button-push
5944                (car (push (set-marker (make-marker) from)
5945                           gnus-button-marker-list))))))))))
5946
5947 ;; Add buttons to the head of an article.
5948 (defun gnus-article-add-buttons-to-head ()
5949   "Add buttons to the head of the article."
5950   (interactive)
5951   (save-excursion
5952     (set-buffer gnus-article-buffer)
5953     (save-restriction
5954       (let ((buffer-read-only nil)
5955             (inhibit-point-motion-hooks t)
5956             (case-fold-search t)
5957             (alist gnus-header-button-alist)
5958             entry beg end)
5959         (article-narrow-to-head)
5960         (while alist
5961           ;; Each alist entry.
5962           (setq entry (car alist)
5963                 alist (cdr alist))
5964           (goto-char (point-min))
5965           (while (re-search-forward (car entry) nil t)
5966             ;; Each header matching the entry.
5967             (setq beg (match-beginning 0))
5968             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5969                                (match-beginning 0))
5970                           (point-max)))
5971             (goto-char beg)
5972             (while (re-search-forward (nth 1 entry) end t)
5973               ;; Each match within a header.
5974               (let* ((entry (cdr entry))
5975                      (start (match-beginning (nth 1 entry)))
5976                      (end (match-end (nth 1 entry)))
5977                      (form (nth 2 entry)))
5978                 (goto-char (match-end 0))
5979                 (when (eval form)
5980                   (gnus-article-add-button
5981                    start end (nth 3 entry)
5982                    (buffer-substring (match-beginning (nth 4 entry))
5983                                      (match-end (nth 4 entry)))))))
5984             (goto-char end)))))))
5985
5986 ;;; External functions:
5987
5988 (defun gnus-article-add-button (from to fun &optional data)
5989   "Create a button between FROM and TO with callback FUN and data DATA."
5990   (when gnus-article-button-face
5991     (gnus-overlay-put (gnus-make-overlay from to)
5992                       'face gnus-article-button-face))
5993   (gnus-add-text-properties
5994    from to
5995    (nconc (and gnus-article-mouse-face
5996                (list gnus-mouse-face-prop gnus-article-mouse-face))
5997           (list 'gnus-callback fun)
5998           (and data (list 'gnus-data data))))
5999   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6000                          ;; Quote `:button-keymap' for Mule 2.3
6001                          ;; but it won't work.
6002                          ':button-keymap gnus-widget-button-keymap))
6003
6004 ;;; Internal functions:
6005
6006 (defun gnus-article-set-globals ()
6007   (save-excursion
6008     (set-buffer gnus-summary-buffer)
6009     (gnus-set-global-variables)))
6010
6011 (defun gnus-signature-toggle (end)
6012   (save-excursion
6013     (set-buffer gnus-article-buffer)
6014     (let ((buffer-read-only nil)
6015           (inhibit-point-motion-hooks t)
6016           (limit (next-single-property-change end 'mime-view-entity
6017                                               nil (point-max))))
6018       (if (text-property-any end limit 'article-type 'signature)
6019           (progn
6020             (gnus-delete-wash-type 'signature)
6021             (gnus-remove-text-properties-when
6022              'article-type 'signature end limit
6023              (cons 'article-type (cons 'signature
6024                                        gnus-hidden-properties))))
6025         (gnus-add-wash-type 'signature)
6026         (gnus-add-text-properties-when
6027          'article-type nil end limit
6028          (cons 'article-type (cons 'signature
6029                                    gnus-hidden-properties)))))
6030     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6031       (gnus-set-mode-line 'article))))
6032
6033 (defun gnus-button-entry ()
6034   ;; Return the first entry in `gnus-button-alist' matching this place.
6035   (let ((alist gnus-button-alist)
6036         (entry nil))
6037     (while alist
6038       (setq entry (pop alist))
6039       (if (looking-at (car entry))
6040           (setq alist nil)
6041         (setq entry nil)))
6042     entry))
6043
6044 (defun gnus-button-push (marker)
6045   ;; Push button starting at MARKER.
6046   (save-excursion
6047     (goto-char marker)
6048     (let* ((entry (gnus-button-entry))
6049            (inhibit-point-motion-hooks t)
6050            (fun (nth 3 entry))
6051            (args (mapcar (lambda (group)
6052                            (let ((string (match-string group)))
6053                              (gnus-set-text-properties
6054                               0 (length string) nil string)
6055                              string))
6056                          (nthcdr 4 entry))))
6057       (cond
6058        ((fboundp fun)
6059         (apply fun args))
6060        ((and (boundp fun)
6061              (fboundp (symbol-value fun)))
6062         (apply (symbol-value fun) args))
6063        (t
6064         (gnus-message 1 "You must define `%S' to use this button"
6065                       (cons fun args)))))))
6066
6067 (defun gnus-parse-news-url (url)
6068   (let (scheme server group message-id articles)
6069     (with-temp-buffer
6070       (insert url)
6071       (goto-char (point-min))
6072       (when (looking-at "\\([A-Za-z]+\\):")
6073         (setq scheme (match-string 1))
6074         (goto-char (match-end 0)))
6075       (when (looking-at "//\\([^/]+\\)/")
6076         (setq server (match-string 1))
6077         (goto-char (match-end 0)))
6078
6079       (cond
6080        ((looking-at "\\(.*@.*\\)")
6081         (setq message-id (match-string 1)))
6082        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6083         (setq group (match-string 1)
6084               articles (split-string (match-string 2) "-")))
6085        ((looking-at "\\([^/]+\\)/?")
6086         (setq group (match-string 1)))
6087        (t
6088         (error "Unknown news URL syntax"))))
6089     (list scheme server group message-id articles)))
6090
6091 (defun gnus-button-handle-news (url)
6092   "Fetch a news URL."
6093   (destructuring-bind (scheme server group message-id articles)
6094       (gnus-parse-news-url url)
6095     (cond
6096      (message-id
6097       (save-excursion
6098         (set-buffer gnus-summary-buffer)
6099         (if server
6100             (let ((gnus-refer-article-method (list (list 'nntp server))))
6101               (gnus-summary-refer-article message-id))
6102           (gnus-summary-refer-article message-id))))
6103      (group
6104       (gnus-button-fetch-group url)))))
6105
6106 (defun gnus-button-handle-info (url)
6107   "Fetch an info URL."
6108   (if (string-match
6109        "^\\([^:/]+\\)?/\\(.*\\)"
6110        url)
6111       (gnus-info-find-node
6112        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6113                        "Gnus")
6114                ")"
6115                (gnus-url-unhex-string (match-string 2 url))))
6116     (error "Can't parse %s" url)))
6117
6118 (defun gnus-button-message-id (message-id)
6119   "Fetch MESSAGE-ID."
6120   (save-excursion
6121     (set-buffer gnus-summary-buffer)
6122     (gnus-summary-refer-article message-id)))
6123
6124 (defun gnus-button-fetch-group (address)
6125   "Fetch GROUP specified by ADDRESS."
6126   (if (not (string-match "[:/]" address))
6127       ;; This is just a simple group url.
6128       (gnus-group-read-ephemeral-group address gnus-select-method)
6129     (if (not
6130          (string-match
6131           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6132           address))
6133         (error "Can't parse %s" address)
6134       (gnus-group-read-ephemeral-group
6135        (match-string 4 address)
6136        `(nntp ,(match-string 1 address)
6137               (nntp-address ,(match-string 1 address))
6138               (nntp-port-number ,(if (match-end 3)
6139                                      (match-string 3 address)
6140                                    "nntp")))
6141        nil nil nil
6142        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6143
6144 (defun gnus-url-parse-query-string (query &optional downcase)
6145   (let (retval pairs cur key val)
6146     (setq pairs (split-string query "&"))
6147     (while pairs
6148       (setq cur (car pairs)
6149             pairs (cdr pairs))
6150       (if (not (string-match "=" cur))
6151           nil                           ; Grace
6152         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6153               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6154         (if downcase
6155             (setq key (downcase key)))
6156         (setq cur (assoc key retval))
6157         (if cur
6158             (setcdr cur (cons val (cdr cur)))
6159           (setq retval (cons (list key val) retval)))))
6160     retval))
6161
6162 (defun gnus-url-mailto (url)
6163   ;; Send mail to someone
6164   (when (string-match "mailto:/*\\(.*\\)" url)
6165     (setq url (substring url (match-beginning 1) nil)))
6166   (let (to args subject func)
6167     (if (string-match (regexp-quote "?") url)
6168         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6169               args (gnus-url-parse-query-string
6170                     (substring url (match-end 0) nil) t))
6171       (setq to (gnus-url-unhex-string url)))
6172     (setq args (cons (list "to" to) args)
6173           subject (cdr-safe (assoc "subject" args)))
6174     (gnus-msg-mail)
6175     (while args
6176       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6177       (if (fboundp func)
6178           (funcall func)
6179         (message-position-on-field (caar args)))
6180       (insert (mapconcat 'identity (cdar args) ", "))
6181       (setq args (cdr args)))
6182     (if subject
6183         (message-goto-body)
6184       (message-goto-subject))))
6185
6186 (defun gnus-button-embedded-url (address)
6187   "Activate ADDRESS with `browse-url'."
6188   (browse-url (gnus-strip-whitespace address)))
6189
6190 ;;; Next/prev buttons in the article buffer.
6191
6192 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6193 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6194
6195 (defvar gnus-prev-page-map
6196   (let ((map (make-sparse-keymap)))
6197     (unless (>= emacs-major-version 21)
6198       ;; XEmacs doesn't care.
6199       (set-keymap-parent map gnus-article-mode-map))
6200     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6201     (define-key map "\r" 'gnus-button-prev-page)
6202     map))
6203
6204 (defun gnus-insert-prev-page-button ()
6205   (let ((b (point))
6206         (buffer-read-only nil)
6207         (situation (get-text-property (point-min) 'mime-view-situation)))
6208     (gnus-eval-format
6209      gnus-prev-page-line-format nil
6210      `(,@(gnus-local-map-property gnus-prev-page-map)
6211          gnus-prev t
6212          gnus-callback gnus-article-button-prev-page
6213          article-type annotation
6214          mime-view-situation ,situation))
6215     (widget-convert-button
6216      'link b (point)
6217      :action 'gnus-button-prev-page
6218      :button-keymap gnus-prev-page-map)))
6219
6220 (defvar gnus-next-page-map
6221   (let ((map (make-sparse-keymap)))
6222     (unless (>= emacs-major-version 21)
6223       ;; XEmacs doesn't care.
6224       (set-keymap-parent map gnus-article-mode-map))
6225     (define-key map gnus-mouse-2 'gnus-button-next-page)
6226     (define-key map "\r" 'gnus-button-next-page)
6227     map))
6228
6229 (defun gnus-button-next-page (&optional args more-args)
6230   "Go to the next page."
6231   (interactive)
6232   (let ((win (selected-window)))
6233     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6234     (gnus-article-next-page)
6235     (select-window win)))
6236
6237 (defun gnus-button-prev-page (&optional args more-args)
6238   "Go to the prev page."
6239   (interactive)
6240   (let ((win (selected-window)))
6241     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6242     (gnus-article-prev-page)
6243     (select-window win)))
6244
6245 (defun gnus-insert-next-page-button ()
6246   (let ((b (point))
6247         (buffer-read-only nil)
6248         (situation (get-text-property (point-min) 'mime-view-situation)))
6249     (gnus-eval-format gnus-next-page-line-format nil
6250                       `(,@(gnus-local-map-property gnus-next-page-map)
6251                           gnus-next t
6252                           gnus-callback gnus-article-button-next-page
6253                           article-type annotation
6254                           mime-view-situation ,situation))
6255     (widget-convert-button
6256      'link b (point)
6257      :action 'gnus-button-next-page
6258      :button-keymap gnus-next-page-map)))
6259
6260 (defun gnus-article-button-next-page (arg)
6261   "Go to the next page."
6262   (interactive "P")
6263   (let ((win (selected-window)))
6264     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6265     (gnus-article-next-page)
6266     (select-window win)))
6267
6268 (defun gnus-article-button-prev-page (arg)
6269   "Go to the prev page."
6270   (interactive "P")
6271   (let ((win (selected-window)))
6272     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6273     (gnus-article-prev-page)
6274     (select-window win)))
6275
6276 (defvar gnus-decode-header-methods
6277   '(mail-decode-encoded-word-region)
6278   "List of methods used to decode headers.
6279
6280 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6281 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6282 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6283 whose names match REGEXP.
6284
6285 For example:
6286 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6287  mail-decode-encoded-word-region
6288  (\"chinese\" . rfc1843-decode-region))
6289 ")
6290
6291 (defvar gnus-decode-header-methods-cache nil)
6292
6293 (defun gnus-multi-decode-header (start end)
6294   "Apply the functions from `gnus-encoded-word-methods' that match."
6295   (unless (and gnus-decode-header-methods-cache
6296                (eq gnus-newsgroup-name
6297                    (car gnus-decode-header-methods-cache)))
6298     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6299     (mapcar (lambda (x)
6300               (if (symbolp x)
6301                   (nconc gnus-decode-header-methods-cache (list x))
6302                 (if (and gnus-newsgroup-name
6303                          (string-match (car x) gnus-newsgroup-name))
6304                     (nconc gnus-decode-header-methods-cache
6305                            (list (cdr x))))))
6306             gnus-decode-header-methods))
6307   (let ((xlist gnus-decode-header-methods-cache))
6308     (pop xlist)
6309     (save-restriction
6310       (narrow-to-region start end)
6311       (while xlist
6312         (funcall (pop xlist) (point-min) (point-max))))))
6313
6314 ;;;
6315 ;;; Treatment top-level handling.
6316 ;;;
6317
6318 (defun gnus-treat-article (condition &optional part-number total-parts type)
6319   (let ((length (- (point-max) (point-min)))
6320         (alist gnus-treatment-function-alist)
6321         (article-goto-body-goes-to-point-min-p t)
6322         (treated-type
6323          (or (not type)
6324              (catch 'found
6325                (let ((list gnus-article-treat-types))
6326                  (while list
6327                    (when (string-match (pop list) type)
6328                      (throw 'found t)))))))
6329         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6330         (entity (static-unless (featurep 'xemacs)
6331                   (when (eq 'head condition)
6332                     (get-text-property (point-min) 'mime-view-entity))))
6333         val elem buttonized)
6334     (gnus-run-hooks 'gnus-part-display-hook)
6335     (unless gnus-inhibit-treatment
6336       (while (setq elem (pop alist))
6337         (setq val
6338               (save-excursion
6339                 (if (gnus-buffer-live-p gnus-summary-buffer)
6340                     (set-buffer gnus-summary-buffer))
6341                 (symbol-value (car elem))))
6342         (when (and (or (consp val)
6343                        treated-type)
6344                    (gnus-treat-predicate val)
6345                    (or (not (get (car elem) 'highlight))
6346                        highlightp))
6347           (when (and (not buttonized)
6348                      (memq (car elem)
6349                            '(gnus-treat-hide-signature
6350                              gnus-treat-highlight-signature)))
6351             (gnus-article-buttonize-signature)
6352             (setq buttonized t))
6353           (save-restriction
6354             (funcall (cadr elem)))))
6355       ;; FSF Emacsen does not inherit the existing text properties
6356       ;; in the new text, so we should do it for `mime-view-entity'.
6357       (static-unless (featurep 'xemacs)
6358         (when entity
6359           (put-text-property (point-min) (point-max)
6360                              'mime-view-entity entity))))))
6361
6362 ;; Dynamic variables.
6363 (eval-when-compile
6364   (defvar part-number)
6365   (defvar total-parts)
6366   (defvar type)
6367   (defvar condition)
6368   (defvar length))
6369
6370 (defun gnus-treat-predicate (val)
6371   (cond
6372    ((null val)
6373     nil)
6374    ((and (listp val)
6375          (stringp (car val)))
6376     (apply 'gnus-or (mapcar `(lambda (s)
6377                                (string-match s ,(or gnus-newsgroup-name "")))
6378                             val)))
6379    ((listp val)
6380     (let ((pred (pop val)))
6381       (cond
6382        ((eq pred 'or)
6383         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6384        ((eq pred 'and)
6385         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6386        ((eq pred 'not)
6387         (not (gnus-treat-predicate (car val))))
6388        ((eq pred 'typep)
6389         (equal (car val) type))
6390        (t
6391         (error "%S is not a valid predicate" pred)))))
6392    ((eq val 'mime)
6393     gnus-show-mime)
6394    (condition
6395     (eq condition val))
6396    ((eq val t)
6397     t)
6398    ((eq val 'head)
6399     nil)
6400    ((eq val 'last)
6401     (eq part-number total-parts))
6402    ((numberp val)
6403     (< length val))
6404    (t
6405     (error "%S is not a valid value" val))))
6406
6407 (defun gnus-article-encrypt-body (protocol &optional n)
6408   "Encrypt the article body."
6409   (interactive
6410    (list
6411     (or gnus-article-encrypt-protocol
6412         (completing-read "Encrypt protocol: "
6413                          gnus-article-encrypt-protocol-alist
6414                          nil t))
6415     current-prefix-arg))
6416   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6417     (unless func
6418       (error (format "Can't find the encrypt protocol %s" protocol)))
6419     (if (equal gnus-newsgroup-name "nndraft:drafts")
6420         (error "Can't encrypt the article in group nndraft:drafts"))
6421     (if (equal gnus-newsgroup-name "nndraft:queue")
6422         (error "Don't encrypt the article in group nndraft:queue"))
6423     (gnus-summary-iterate n
6424       (save-excursion
6425         (set-buffer gnus-summary-buffer)
6426         (let ((mail-parse-charset gnus-newsgroup-charset)
6427               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6428               (summary-buffer gnus-summary-buffer)
6429               references point)
6430           (gnus-set-global-variables)
6431           (when (gnus-group-read-only-p)
6432             (error "The current newsgroup does not support article encrypt"))
6433           (gnus-summary-show-article t)
6434           (setq references
6435                 (or (mail-header-references gnus-current-headers) ""))
6436           (set-buffer gnus-article-buffer)
6437           (let* ((buffer-read-only nil)
6438                  (headers
6439                   (mapcar (lambda (field)
6440                             (and (save-restriction
6441                                    (message-narrow-to-head)
6442                                    (goto-char (point-min))
6443                                    (search-forward field nil t))
6444                                  (prog2
6445                                      (message-narrow-to-field)
6446                                      (buffer-substring (point-min) (point-max))
6447                                    (delete-region (point-min) (point-max))
6448                                    (widen))))
6449                           '("Content-Type:" "Content-Transfer-Encoding:"
6450                             "Content-Disposition:"))))
6451             (message-narrow-to-head)
6452             (message-remove-header "MIME-Version")
6453             (goto-char (point-max))
6454             (setq point (point))
6455             (insert (apply 'concat headers))
6456             (widen)
6457             (narrow-to-region point (point-max))
6458             (let ((message-options message-options))
6459               (message-options-set 'message-sender user-mail-address)
6460               (message-options-set 'message-recipients user-mail-address)
6461               (message-options-set 'message-sign-encrypt 'not)
6462               (funcall func))
6463             (goto-char (point-min))
6464             (insert "MIME-Version: 1.0\n")
6465             (widen)
6466             (gnus-summary-edit-article-done
6467              references nil summary-buffer t))
6468           (when gnus-keep-backlog
6469             (gnus-backlog-remove-article
6470              (car gnus-article-current) (cdr gnus-article-current)))
6471           (save-excursion
6472             (when (get-buffer gnus-original-article-buffer)
6473               (set-buffer gnus-original-article-buffer)
6474               (setq gnus-original-article nil)))
6475           (when gnus-use-cache
6476             (gnus-cache-update-article
6477              (car gnus-article-current) (cdr gnus-article-current))))))))
6478
6479 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6480   "The following specs can be used:
6481 %t  The security MIME type
6482 %i  Additional info
6483 %d  Details
6484 %D  Details if button is pressed")
6485
6486 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6487   "The following specs can be used:
6488 %t  The security MIME type
6489 %i  Additional info
6490 %d  Details
6491 %D  Details if button is pressed")
6492
6493 (defvar gnus-mime-security-button-line-format-alist
6494   '((?t gnus-tmp-type ?s)
6495     (?i gnus-tmp-info ?s)
6496     (?d gnus-tmp-details ?s)
6497     (?D gnus-tmp-pressed-details ?s)))
6498
6499 (defvar gnus-mime-security-button-map
6500   (let ((map (make-sparse-keymap)))
6501     (unless (>= (string-to-number emacs-version) 21)
6502       (set-keymap-parent map gnus-article-mode-map))
6503     (define-key map gnus-mouse-2 'gnus-article-push-button)
6504     (define-key map "\r" 'gnus-article-press-button)
6505     map))
6506
6507 (defvar gnus-mime-security-details-buffer nil)
6508
6509 (defvar gnus-mime-security-button-pressed nil)
6510
6511 (defvar gnus-mime-security-show-details-inline t
6512   "If non-nil, show details in the article buffer.")
6513
6514 (defun gnus-mime-security-verify-or-decrypt (handle)
6515   (mm-remove-parts (cdr handle))
6516   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6517         point buffer-read-only)
6518     (if region
6519         (goto-char (car region)))
6520     (save-restriction
6521       (narrow-to-region (point) (point))
6522       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6523         (let* ((mm-verify-option 'known)
6524                (mm-decrypt-option 'known)
6525                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6526           (unless (eq nparts (cdr handle))
6527             (mm-destroy-parts (cdr handle))
6528             (setcdr handle nparts))))
6529       (setq point (point))
6530       (gnus-mime-display-security handle)
6531       (goto-char (point-max)))
6532     (when region
6533       (delete-region (point) (cdr region))
6534       (set-marker (car region) nil)
6535       (set-marker (cdr region) nil))
6536     (goto-char point)))
6537
6538 (defun gnus-mime-security-show-details (handle)
6539   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6540     (if details
6541         (if gnus-mime-security-show-details-inline
6542             (let ((gnus-mime-security-button-pressed t)
6543                   (gnus-mime-security-button-line-format
6544                    (get-text-property (point) 'gnus-line-format))
6545                   buffer-read-only)
6546               (forward-char -1)
6547               (while (eq (get-text-property (point) 'gnus-line-format)
6548                          gnus-mime-security-button-line-format)
6549                 (forward-char -1))
6550               (forward-char)
6551               (save-restriction
6552                 (narrow-to-region (point) (point))
6553                 (gnus-insert-mime-security-button handle))
6554               (delete-region (point)
6555                              (or (text-property-not-all
6556                                   (point) (point-max)
6557                                   'gnus-line-format
6558                                   gnus-mime-security-button-line-format)
6559                                  (point-max))))
6560           (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6561               (with-current-buffer gnus-mime-security-details-buffer
6562                 (erase-buffer)
6563                 t)
6564             (setq gnus-mime-security-details-buffer
6565                   (gnus-get-buffer-create "*MIME Security Details*")))
6566           (with-current-buffer gnus-mime-security-details-buffer
6567             (insert details)
6568             (goto-char (point-min)))
6569           (pop-to-buffer gnus-mime-security-details-buffer))
6570       (gnus-message 5 "No details."))))
6571
6572 (defun gnus-mime-security-press-button (handle)
6573   (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6574       (gnus-mime-security-show-details handle)
6575     (gnus-mime-security-verify-or-decrypt handle)))
6576
6577 (defun gnus-insert-mime-security-button (handle &optional displayed)
6578   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6579          (gnus-tmp-type
6580           (concat
6581            (or (nth 2 (assoc protocol mm-verify-function-alist))
6582                (nth 2 (assoc protocol mm-decrypt-function-alist))
6583                "Unknown")
6584            (if (equal (car handle) "multipart/signed")
6585                " Signed" " Encrypted")
6586            " Part"))
6587          (gnus-tmp-info
6588           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6589               "Undecided"))
6590          (gnus-tmp-details
6591           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6592          gnus-tmp-pressed-details
6593          b e)
6594     (setq gnus-tmp-details
6595           (if gnus-tmp-details
6596               (concat "\n" gnus-tmp-details) ""))
6597     (setq gnus-tmp-pressed-details
6598           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6599     (unless (bolp)
6600       (insert "\n"))
6601     (setq b (point))
6602     (gnus-eval-format
6603      gnus-mime-security-button-line-format
6604      gnus-mime-security-button-line-format-alist
6605      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6606          gnus-callback gnus-mime-security-press-button
6607          gnus-line-format ,gnus-mime-security-button-line-format
6608          article-type annotation
6609          gnus-data ,handle))
6610     (setq e (point))
6611     (widget-convert-button
6612      'link b e
6613      :mime-handle handle
6614      :action 'gnus-widget-press-button
6615      :button-keymap gnus-mime-security-button-map
6616      :help-echo
6617      (lambda (widget/window &optional overlay pos)
6618        ;; Needed to properly clear the message due to a bug in
6619        ;; wid-edit (XEmacs only).
6620        (if (boundp 'help-echo-owns-message)
6621            (setq help-echo-owns-message t))
6622        (format
6623         "%S: show detail"
6624         (aref gnus-mouse-2 0))))))
6625
6626 (defun gnus-mime-display-security (handle)
6627   (save-restriction
6628     (narrow-to-region (point) (point))
6629     (unless (gnus-unbuttonized-mime-type-p (car handle))
6630       (gnus-insert-mime-security-button handle))
6631     (gnus-mime-display-mixed (cdr handle))
6632     (unless (bolp)
6633       (insert "\n"))
6634     (unless (gnus-unbuttonized-mime-type-p (car handle))
6635       (let ((gnus-mime-security-button-line-format
6636              gnus-mime-security-button-end-line-format))
6637         (gnus-insert-mime-security-button handle)))
6638     (mm-set-handle-multipart-parameter
6639      handle 'gnus-region
6640      (cons (set-marker (make-marker) (point-min))
6641            (set-marker (make-marker) (point-max))))))
6642
6643
6644 ;;; @ for mime-view
6645 ;;;
6646
6647 (defun gnus-article-header-presentation-method (entity situation)
6648   (mime-insert-header entity)
6649   (article-decode-group-name))
6650
6651 (set-alist 'mime-header-presentation-method-alist
6652            'gnus-original-article-mode
6653            #'gnus-article-header-presentation-method)
6654
6655 (defun gnus-mime-preview-quitting-method ()
6656   (mime-preview-kill-buffer)
6657   (delete-other-windows)
6658   (gnus-article-show-summary)
6659   (gnus-summary-select-article gnus-show-all-headers t))
6660
6661 (set-alist 'mime-preview-quitting-method-alist
6662            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6663
6664 (set-alist 'mime-preview-following-method-alist
6665            'gnus-original-article-mode #'gnus-following-method)
6666
6667 (set-alist 'mime-preview-over-to-previous-method-alist
6668            'gnus-original-article-mode
6669            (lambda ()
6670              (if (> (point-min) 1)
6671                  (gnus-article-prev-page)
6672                (gnus-article-read-summary-keys
6673                 nil (gnus-character-to-event ?P)))))
6674
6675 (set-alist 'mime-preview-over-to-next-method-alist
6676            'gnus-original-article-mode'
6677            (lambda ()
6678              (if (< (point-max) (buffer-size))
6679                  (gnus-article-next-page)
6680                (gnus-article-read-summary-keys
6681                 nil (gnus-character-to-event ?N)))))
6682
6683
6684 ;;; @ end
6685 ;;;
6686
6687 (gnus-ems-redefine)
6688
6689 (provide 'gnus-art)
6690
6691 (run-hooks 'gnus-art-load-hook)
6692
6693 ;;; gnus-art.el ends here