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