5b72bca8ae6c02334ce086ef884594f8df15b7a3
[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-separator-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     (insert (make-string (1- (window-width)) ? )
1639             "\n")
1640     (put-text-property (point) (progn (forward-line -1) (point))
1641                        'face 'gnus-body-separator-face)))
1642
1643 (defun article-fill-long-lines ()
1644   "Fill lines that are wider than the window width."
1645   (interactive)
1646   (save-excursion
1647     (let ((buffer-read-only nil)
1648           (width (window-width (get-buffer-window (current-buffer)))))
1649       (save-restriction
1650         (article-goto-body)
1651         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1652           (while (not (eobp))
1653             (end-of-line)
1654             (when (>= (current-column) (min fill-column width))
1655               (narrow-to-region (point) (gnus-point-at-bol))
1656               (fill-paragraph nil)
1657               (goto-char (point-max))
1658               (widen))
1659             (forward-line 1)))))))
1660
1661 (defun article-capitalize-sentences ()
1662   "Capitalize the first word in each sentence."
1663   (interactive)
1664   (save-excursion
1665     (let ((buffer-read-only nil)
1666           (paragraph-start "^[\n\^L]"))
1667       (article-goto-body)
1668       (while (not (eobp))
1669         (capitalize-word 1)
1670         (forward-sentence)))))
1671
1672 (defun article-remove-cr ()
1673   "Remove trailing CRs and then translate remaining CRs into LFs."
1674   (interactive)
1675   (save-excursion
1676     (let ((buffer-read-only nil))
1677       (goto-char (point-min))
1678       (while (re-search-forward "\r+$" nil t)
1679         (replace-match "" t t))
1680       (goto-char (point-min))
1681       (while (search-forward "\r" nil t)
1682         (replace-match "\n" t t)))))
1683
1684 (defun article-remove-trailing-blank-lines ()
1685   "Remove all trailing blank lines from the article."
1686   (interactive)
1687   (save-excursion
1688     (let ((buffer-read-only nil))
1689       (goto-char (point-max))
1690       (delete-region
1691        (point)
1692        (progn
1693          (while (and (not (bobp))
1694                      (looking-at "^[ \t]*$")
1695                      (not (gnus-annotation-in-region-p
1696                            (point) (gnus-point-at-eol))))
1697            (forward-line -1))
1698          (forward-line 1)
1699          (point))))))
1700
1701 (defun article-display-x-face (&optional force)
1702   "Look for an X-Face header and display it if present."
1703   (interactive (list 'force))
1704   (save-excursion
1705     ;; Delete the old process, if any.
1706     (when (process-status "article-x-face")
1707       (delete-process "article-x-face"))
1708     (let ((inhibit-point-motion-hooks t)
1709           x-faces
1710           (case-fold-search t)
1711           from last)
1712       (save-restriction
1713         (article-narrow-to-head)
1714         (when (and buffer-read-only ;; When type `W f'
1715                    (progn
1716                      (goto-char (point-min))
1717                      (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1718                    (gnus-buffer-live-p gnus-original-article-buffer))
1719           (with-current-buffer gnus-original-article-buffer
1720             (save-restriction
1721               (article-narrow-to-head)
1722               (while (re-search-forward "^X-Face:" nil t)
1723                 (setq x-faces
1724                       (concat
1725                        (or x-faces "")
1726                        (buffer-substring
1727                         (match-beginning 0)
1728                         (1- (re-search-forward
1729                              "^\\($\\|[^ \t]\\)" nil t))))))))
1730           (if x-faces
1731               (let (point start bface eface buffer-read-only)
1732                 (goto-char (point-max))
1733                 (forward-line -1)
1734                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1735                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1736                 (goto-char (point-max))
1737                 (setq point (point))
1738                 (insert x-faces)
1739                 (goto-char point)
1740                 (while (looking-at "\\([^:]+\\): *")
1741                   (put-text-property (match-beginning 1) (1+ (match-end 1))
1742                                      'face bface)
1743                   (setq start (match-end 0))
1744                   (forward-line 1)
1745                   (while (looking-at "[\t ]")
1746                     (forward-line 1))
1747                   (put-text-property start (point)
1748                                      'face eface)))))
1749         (goto-char (point-min))
1750         (setq from (message-fetch-field "from"))
1751         (goto-char (point-min))
1752         (while (and gnus-article-x-face-command
1753                     (not last)
1754                     (or force
1755                         ;; Check whether this face is censored.
1756                         (not gnus-article-x-face-too-ugly)
1757                         (and gnus-article-x-face-too-ugly from
1758                              (not (string-match gnus-article-x-face-too-ugly
1759                                                 from))))
1760                     ;; Has to be present.
1761                     (re-search-forward "^X-Face:[\t ]*" nil t))
1762           ;; This used to try to do multiple faces (`while' instead of
1763           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1764           ;; work (b) it can crash some versions of Emacs (c) are
1765           ;; multiple faces really something to encourage?
1766           (when (stringp gnus-article-x-face-command)
1767             (setq last t))
1768           ;; We now have the area of the buffer where the X-Face is stored.
1769           (save-excursion
1770             (let ((beg (point))
1771                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))
1772                   buffer-read-only)
1773               ;; We display the face.
1774               (if (symbolp gnus-article-x-face-command)
1775                   ;; The command is a lisp function, so we call it.
1776                   (if (gnus-functionp gnus-article-x-face-command)
1777                       (funcall gnus-article-x-face-command beg end)
1778                     (error "%s is not a function" gnus-article-x-face-command))
1779                 ;; The command is a string, so we interpret the command
1780                 ;; as a, well, command, and fork it off.
1781                 (let ((process-connection-type nil))
1782                   (process-kill-without-query
1783                    (start-process
1784                     "article-x-face" nil shell-file-name shell-command-switch
1785                     gnus-article-x-face-command))
1786                   (process-send-region "article-x-face" beg end)
1787                   (process-send-eof "article-x-face"))))))))))
1788
1789 (defun article-decode-mime-words ()
1790   "Decode all MIME-encoded words in the article."
1791   (interactive)
1792   (save-excursion
1793     (set-buffer gnus-article-buffer)
1794     (let ((inhibit-point-motion-hooks t)
1795           buffer-read-only
1796           (mail-parse-charset gnus-newsgroup-charset)
1797           (mail-parse-ignored-charsets
1798            (save-excursion (set-buffer gnus-summary-buffer)
1799                            gnus-newsgroup-ignored-charsets)))
1800       (mail-decode-encoded-word-region (point-min) (point-max)))))
1801
1802 (defun article-decode-charset (&optional prompt)
1803   "Decode charset-encoded text in the article.
1804 If PROMPT (the prefix), prompt for a coding system to use."
1805   (interactive "P")
1806   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1807         buffer-read-only
1808         (mail-parse-charset gnus-newsgroup-charset)
1809         (mail-parse-ignored-charsets
1810          (save-excursion (condition-case nil
1811                              (set-buffer gnus-summary-buffer)
1812                            (error))
1813                          gnus-newsgroup-ignored-charsets))
1814         ct cte ctl charset format)
1815   (save-excursion
1816     (save-restriction
1817       (article-narrow-to-head)
1818       (setq ct (message-fetch-field "Content-Type" t)
1819             cte (message-fetch-field "Content-Transfer-Encoding" t)
1820             ctl (and ct (ignore-errors
1821                           (mail-header-parse-content-type ct)))
1822             charset (cond
1823                      (prompt
1824                       (mm-read-coding-system "Charset to decode: "))
1825                      (ctl
1826                       (mail-content-type-get ctl 'charset)))
1827             format (and ctl (mail-content-type-get ctl 'format)))
1828       (when cte
1829         (setq cte (mail-header-strip cte)))
1830       (if (and ctl (not (string-match "/" (car ctl))))
1831           (setq ctl nil))
1832       (goto-char (point-max)))
1833     (forward-line 1)
1834     (save-restriction
1835       (narrow-to-region (point) (point-max))
1836       (when (and (eq mail-parse-charset 'gnus-decoded)
1837                  (eq (mm-body-7-or-8) '8bit))
1838         ;; The text code could have been decoded.
1839         (setq charset mail-parse-charset))
1840       (when (and (or (not ctl)
1841                      (equal (car ctl) "text/plain"))
1842                  (not format)) ;; article with format will decode later.
1843         (mm-decode-body
1844          charset (and cte (intern (downcase
1845                                    (gnus-strip-whitespace cte))))
1846          (car ctl)))))))
1847
1848 (defun article-decode-encoded-words ()
1849   "Remove encoded-word encoding from headers."
1850   (let ((inhibit-point-motion-hooks t)
1851         (mail-parse-charset gnus-newsgroup-charset)
1852         (mail-parse-ignored-charsets
1853          (save-excursion (condition-case nil
1854                              (set-buffer gnus-summary-buffer)
1855                            (error))
1856                          gnus-newsgroup-ignored-charsets))
1857         buffer-read-only)
1858     (save-restriction
1859       (article-narrow-to-head)
1860       (funcall gnus-decode-header-function (point-min) (point-max)))))
1861
1862 (defun article-decode-group-name ()
1863   "Decode group names in `Newsgroups:'."
1864   (let ((inhibit-point-motion-hooks t)
1865         buffer-read-only
1866         (method (gnus-find-method-for-group gnus-newsgroup-name)))
1867     (when (and (or gnus-group-name-charset-method-alist
1868                    gnus-group-name-charset-group-alist)
1869                (gnus-buffer-live-p gnus-original-article-buffer))
1870       (when (nnmail-fetch-field "Newsgroups")
1871         (nnheader-replace-header "Newsgroups"
1872                                  (gnus-decode-newsgroups
1873                                   (with-current-buffer
1874                                       gnus-original-article-buffer
1875                                     (nnmail-fetch-field "Newsgroups"))
1876                                   gnus-newsgroup-name method)))
1877       (when (nnmail-fetch-field "Followup-To")
1878         (nnheader-replace-header "Followup-To"
1879                                  (gnus-decode-newsgroups
1880                                   (with-current-buffer
1881                                       gnus-original-article-buffer
1882                                     (nnmail-fetch-field "Followup-To"))
1883                                   gnus-newsgroup-name method))))))
1884
1885 (defun article-de-quoted-unreadable (&optional force read-charset)
1886   "Translate a quoted-printable-encoded article.
1887 If FORCE, decode the article whether it is marked as quoted-printable
1888 or not.
1889 If READ-CHARSET, ask for a coding system."
1890   (interactive (list 'force current-prefix-arg))
1891   (save-excursion
1892     (let ((buffer-read-only nil) type charset)
1893       (if (gnus-buffer-live-p gnus-original-article-buffer)
1894           (with-current-buffer gnus-original-article-buffer
1895             (setq type
1896                   (gnus-fetch-field "content-transfer-encoding"))
1897             (let* ((ct (gnus-fetch-field "content-type"))
1898                    (ctl (and ct
1899                              (ignore-errors
1900                                (mail-header-parse-content-type ct)))))
1901               (setq charset (and ctl
1902                                  (mail-content-type-get ctl 'charset)))
1903               (if (stringp charset)
1904                   (setq charset (intern (downcase charset)))))))
1905       (if read-charset
1906           (setq charset (mm-read-coding-system "Charset: " charset)))
1907       (unless charset
1908         (setq charset gnus-newsgroup-charset))
1909       (when (or force
1910                 (and type (let ((case-fold-search t))
1911                             (string-match "quoted-printable" type))))
1912         (article-goto-body)
1913         (quoted-printable-decode-region
1914          (point) (point-max) (mm-charset-to-coding-system charset))))))
1915
1916 (defun article-de-base64-unreadable (&optional force read-charset)
1917   "Translate a base64 article.
1918 If FORCE, decode the article whether it is marked as base64 not.
1919 If READ-CHARSET, ask for a coding system."
1920   (interactive (list 'force current-prefix-arg))
1921   (save-excursion
1922     (let ((buffer-read-only nil) type charset)
1923       (if (gnus-buffer-live-p gnus-original-article-buffer)
1924           (with-current-buffer gnus-original-article-buffer
1925             (setq type
1926                   (gnus-fetch-field "content-transfer-encoding"))
1927             (let* ((ct (gnus-fetch-field "content-type"))
1928                    (ctl (and ct
1929                              (ignore-errors
1930                                (mail-header-parse-content-type ct)))))
1931               (setq charset (and ctl
1932                                  (mail-content-type-get ctl 'charset)))
1933               (if (stringp charset)
1934                   (setq charset (intern (downcase charset)))))))
1935       (if read-charset
1936           (setq charset (mm-read-coding-system "Charset: " charset)))
1937       (unless charset
1938         (setq charset gnus-newsgroup-charset))
1939       (when (or force
1940                 (and type (let ((case-fold-search t))
1941                             (string-match "base64" type))))
1942         (article-goto-body)
1943         (save-restriction
1944           (narrow-to-region (point) (point-max))
1945           (base64-decode-region (point-min) (point-max))
1946           (mm-decode-coding-region
1947            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1948
1949 (eval-when-compile
1950   (require 'rfc1843))
1951
1952 (defun article-decode-HZ ()
1953   "Translate a HZ-encoded article."
1954   (interactive)
1955   (require 'rfc1843)
1956   (save-excursion
1957     (let ((buffer-read-only nil))
1958       (rfc1843-decode-region (point-min) (point-max)))))
1959
1960 (defun article-wash-html (&optional read-charset)
1961   "Format an html article.
1962 If READ-CHARSET, ask for a coding system."
1963   (interactive "P")
1964   (save-excursion
1965     (let ((buffer-read-only nil)
1966           charset)
1967       (if (gnus-buffer-live-p gnus-original-article-buffer)
1968           (with-current-buffer gnus-original-article-buffer
1969             (let* ((ct (gnus-fetch-field "content-type"))
1970                    (ctl (and ct
1971                              (ignore-errors
1972                                (mail-header-parse-content-type ct)))))
1973               (setq charset (and ctl
1974                                  (mail-content-type-get ctl 'charset)))
1975               (if (stringp charset)
1976                   (setq charset (intern (downcase charset)))))))
1977       (if read-charset
1978           (setq charset (mm-read-coding-system "Charset: " charset)))
1979       (unless charset
1980         (setq charset gnus-newsgroup-charset))
1981       (article-goto-body)
1982       (save-window-excursion
1983         (save-restriction
1984           (narrow-to-region (point) (point-max))
1985           (mm-setup-w3)
1986           (let ((w3-strict-width (window-width))
1987                 (url-standalone-mode t)
1988                 (w3-honor-stylesheets nil)
1989                 (w3-delay-image-loads t))
1990             (condition-case var
1991                 (w3-region (point-min) (point-max))
1992               (error))))))))
1993
1994 (defun article-hide-list-identifiers ()
1995   "Remove list identifies from the Subject header.
1996 The `gnus-list-identifiers' variable specifies what to do."
1997   (interactive)
1998   (let ((inhibit-point-motion-hooks t)
1999         (regexp (if (consp gnus-list-identifiers)
2000                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2001                   gnus-list-identifiers))
2002         buffer-read-only)
2003     (when regexp
2004       (save-excursion
2005         (save-restriction
2006           (article-narrow-to-head)
2007           (goto-char (point-min))
2008           (while (re-search-forward
2009                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2010                   nil t)
2011             (delete-region (match-beginning 2) (match-end 0))
2012             (beginning-of-line))
2013           (when (re-search-forward
2014                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2015             (delete-region (match-beginning 1) (match-end 1))))))))
2016
2017 (defun article-hide-pgp ()
2018   "Remove any PGP headers and signatures in the current article."
2019   (interactive)
2020   (save-excursion
2021     (save-restriction
2022       (let ((inhibit-point-motion-hooks t)
2023             buffer-read-only beg end)
2024         (article-goto-body)
2025         ;; Hide the "header".
2026         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2027           (push 'pgp gnus-article-wash-types)
2028           (delete-region (match-beginning 0) (match-end 0))
2029           ;; Remove armor headers (rfc2440 6.2)
2030           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2031                                      (point)))
2032           (setq beg (point))
2033           ;; Hide the actual signature.
2034           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2035                (setq end (1+ (match-beginning 0)))
2036                (delete-region
2037                 end
2038                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2039                     (match-end 0)
2040                   ;; Perhaps we shouldn't hide to the end of the buffer
2041                   ;; if there is no end to the signature?
2042                   (point-max))))
2043           ;; Hide "- " PGP quotation markers.
2044           (when (and beg end)
2045             (narrow-to-region beg end)
2046             (goto-char (point-min))
2047             (while (re-search-forward "^- " nil t)
2048               (delete-region
2049                (match-beginning 0) (match-end 0)))
2050             (widen))
2051           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2052
2053 (defun article-hide-pem (&optional arg)
2054   "Toggle hiding of any PEM headers and signatures in the current article.
2055 If given a negative prefix, always show; if given a positive prefix,
2056 always hide."
2057   (interactive (gnus-article-hidden-arg))
2058   (unless (gnus-article-check-hidden-text 'pem arg)
2059     (save-excursion
2060       (let (buffer-read-only end)
2061         (goto-char (point-min))
2062         ;; Hide the horrendously ugly "header".
2063         (when (and (search-forward
2064                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2065                     nil t)
2066                    (setq end (1+ (match-beginning 0))))
2067           (push 'pem gnus-article-wash-types)
2068           (gnus-article-hide-text-type
2069            end
2070            (if (search-forward "\n\n" nil t)
2071                (match-end 0)
2072              (point-max))
2073            'pem)
2074           ;; Hide the trailer as well
2075           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2076                                 nil t)
2077             (gnus-article-hide-text-type
2078              (match-beginning 0) (match-end 0) 'pem)))))))
2079
2080 (defun article-strip-banner ()
2081   "Strip the banner specified by the `banner' group parameter."
2082   (interactive)
2083   (save-excursion
2084     (save-restriction
2085       (let ((inhibit-point-motion-hooks t)
2086             (banner (gnus-parameter-banner gnus-newsgroup-name))
2087             (gnus-signature-limit nil)
2088             buffer-read-only beg end)
2089         (when banner
2090           (article-goto-body)
2091           (cond
2092            ((eq banner 'signature)
2093             (when (gnus-article-narrow-to-signature)
2094               (widen)
2095               (forward-line -1)
2096               (delete-region (point) (point-max))))
2097            ((symbolp banner)
2098             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2099                 (while (re-search-forward banner nil t)
2100                   (delete-region (match-beginning 0) (match-end 0)))))
2101            ((stringp banner)
2102             (while (re-search-forward banner nil t)
2103               (delete-region (match-beginning 0) (match-end 0))))))))))
2104
2105 (defun article-babel ()
2106   "Translate article using an online translation service."
2107   (interactive)
2108   (require 'babel)
2109   (save-excursion
2110     (set-buffer gnus-article-buffer)
2111     (when (article-goto-body)
2112       (let* ((buffer-read-only nil)
2113              (start (point))
2114              (end (point-max))
2115              (orig (buffer-substring start end))
2116              (trans (babel-as-string orig)))
2117         (save-restriction
2118           (narrow-to-region start end)
2119           (delete-region start end)
2120           (insert trans))))))
2121
2122 (defun article-hide-signature (&optional arg)
2123   "Hide the signature in the current article.
2124 If given a negative prefix, always show; if given a positive prefix,
2125 always hide."
2126   (interactive (gnus-article-hidden-arg))
2127   (unless (gnus-article-check-hidden-text 'signature arg)
2128     (save-excursion
2129       (save-restriction
2130         (let ((buffer-read-only nil))
2131           (when (gnus-article-narrow-to-signature)
2132             (gnus-article-hide-text-type
2133              (point-min) (point-max) 'signature))))))
2134   (gnus-set-mode-line 'article))
2135
2136 (defun article-strip-headers-in-body ()
2137   "Strip offensive headers from bodies."
2138   (interactive)
2139   (save-excursion
2140     (article-goto-body)
2141     (let ((case-fold-search t))
2142       (when (looking-at "x-no-archive:")
2143         (gnus-delete-line)))))
2144
2145 (defun article-strip-leading-blank-lines ()
2146   "Remove all blank lines from the beginning of the article."
2147   (interactive)
2148   (save-excursion
2149     (let ((inhibit-point-motion-hooks t)
2150           buffer-read-only)
2151       (when (article-goto-body)
2152         (while (and (not (eobp))
2153                     (looking-at "[ \t]*$"))
2154           (gnus-delete-line))))))
2155
2156 (defun article-narrow-to-head ()
2157   "Narrow the buffer to the head of the message.
2158 Point is left at the beginning of the narrowed-to region."
2159   (narrow-to-region
2160    (goto-char (point-min))
2161    (if (search-forward "\n\n" nil 1)
2162        (1- (point))
2163      (point-max)))
2164   (goto-char (point-min)))
2165
2166 (defun article-goto-body ()
2167   "Place point at the start of the body."
2168   (goto-char (point-min))
2169   (cond
2170    ;; This variable is only bound when dealing with separate
2171    ;; MIME body parts.
2172    (article-goto-body-goes-to-point-min-p
2173     t)
2174    ((search-forward "\n\n" nil t)
2175     t)
2176    (t
2177     (goto-char (point-max))
2178     nil)))
2179
2180 (defun article-strip-multiple-blank-lines ()
2181   "Replace consecutive blank lines with one empty line."
2182   (interactive)
2183   (save-excursion
2184     (let ((inhibit-point-motion-hooks t)
2185           buffer-read-only)
2186       ;; First make all blank lines empty.
2187       (article-goto-body)
2188       (while (re-search-forward "^[ \t]+$" nil t)
2189         (unless (gnus-annotation-in-region-p
2190                  (match-beginning 0) (match-end 0))
2191           (replace-match "" nil t)))
2192       ;; Then replace multiple empty lines with a single empty line.
2193       (article-goto-body)
2194       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2195         (unless (gnus-annotation-in-region-p
2196                  (match-beginning 0) (match-end 0))
2197           (delete-region (match-beginning 1) (match-end 1)))))))
2198
2199 (defun article-strip-leading-space ()
2200   "Remove all white space from the beginning of the lines in the article."
2201   (interactive)
2202   (save-excursion
2203     (let ((inhibit-point-motion-hooks t)
2204           buffer-read-only)
2205       (article-goto-body)
2206       (while (re-search-forward "^[ \t]+" nil t)
2207         (replace-match "" t t)))))
2208
2209 (defun article-strip-trailing-space ()
2210   "Remove all white space from the end of the lines in the article."
2211   (interactive)
2212   (save-excursion
2213     (let ((inhibit-point-motion-hooks t)
2214           buffer-read-only)
2215       (article-goto-body)
2216       (while (re-search-forward "[ \t]+$" nil t)
2217         (replace-match "" t t)))))
2218
2219 (defun article-strip-blank-lines ()
2220   "Strip leading, trailing and multiple blank lines."
2221   (interactive)
2222   (article-strip-leading-blank-lines)
2223   (article-remove-trailing-blank-lines)
2224   (article-strip-multiple-blank-lines))
2225
2226 (defun article-strip-all-blank-lines ()
2227   "Strip all blank lines."
2228   (interactive)
2229   (save-excursion
2230     (let ((inhibit-point-motion-hooks t)
2231           buffer-read-only)
2232       (article-goto-body)
2233       (while (re-search-forward "^[ \t]*\n" nil t)
2234         (replace-match "" t t)))))
2235
2236 (defun gnus-article-narrow-to-signature ()
2237   "Narrow to the signature; return t if a signature is found, else nil."
2238   (let ((inhibit-point-motion-hooks t))
2239     (when (gnus-article-search-signature)
2240       (forward-line 1)
2241       ;; Check whether we have some limits to what we consider
2242       ;; to be a signature.
2243       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2244                       (list gnus-signature-limit)))
2245             limit limited)
2246         (while (setq limit (pop limits))
2247           (if (or (and (integerp limit)
2248                        (< (- (point-max) (point)) limit))
2249                   (and (floatp limit)
2250                        (< (count-lines (point) (point-max)) limit))
2251                   (and (gnus-functionp limit)
2252                        (funcall limit))
2253                   (and (stringp limit)
2254                        (not (re-search-forward limit nil t))))
2255               ()                        ; This limit did not succeed.
2256             (setq limited t
2257                   limits nil)))
2258         (unless limited
2259           (narrow-to-region (point) (point-max))
2260           t)))))
2261
2262 (defun gnus-article-search-signature ()
2263   "Search the current buffer for the signature separator.
2264 Put point at the beginning of the signature separator."
2265   (let ((cur (point)))
2266     (goto-char (point-max))
2267     (if (if (stringp gnus-signature-separator)
2268             (re-search-backward gnus-signature-separator nil t)
2269           (let ((seps gnus-signature-separator))
2270             (while (and seps
2271                         (not (re-search-backward (car seps) nil t)))
2272               (pop seps))
2273             seps))
2274         t
2275       (goto-char cur)
2276       nil)))
2277
2278 (defun gnus-article-hidden-arg ()
2279   "Return the current prefix arg as a number, or 0 if no prefix."
2280   (list (if current-prefix-arg
2281             (prefix-numeric-value current-prefix-arg)
2282           0)))
2283
2284 (defun gnus-article-check-hidden-text (type arg)
2285   "Return nil if hiding is necessary.
2286 Arg can be nil or a number.  nil and positive means hide, negative
2287 means show, 0 means toggle."
2288   (save-excursion
2289     (save-restriction
2290       (let ((hide (gnus-article-hidden-text-p type)))
2291         (cond
2292          ((or (null arg)
2293               (> arg 0))
2294           nil)
2295          ((< arg 0)
2296           (gnus-article-show-hidden-text type)
2297           t)
2298          (t
2299           (if (eq hide 'hidden)
2300               (progn
2301                 (gnus-article-show-hidden-text type)
2302                 t)
2303             nil)))))))
2304
2305 (defun gnus-article-hidden-text-p (type)
2306   "Say whether the current buffer contains hidden text of type TYPE."
2307   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2308     (while (and pos
2309                 (not (get-text-property pos 'invisible))
2310                 (not (get-text-property pos 'dummy-invisible)))
2311       (setq pos
2312             (text-property-any (1+ pos) (point-max) 'article-type type)))
2313     (if pos
2314         'hidden
2315       nil)))
2316
2317 (defun gnus-article-show-hidden-text (type &optional dummy)
2318   "Show all hidden text of type TYPE.
2319 Originally it is hide instead of DUMMY."
2320   (let ((buffer-read-only nil)
2321         (inhibit-point-motion-hooks t))
2322     (gnus-remove-text-properties-when
2323      'article-type type
2324      (point-min) (point-max)
2325      (cons 'article-type (cons type
2326                                gnus-hidden-properties)))
2327     (setq gnus-article-wash-types (delq type gnus-article-wash-types))))
2328
2329 (defconst article-time-units
2330   `((year . ,(* 365.25 24 60 60))
2331     (week . ,(* 7 24 60 60))
2332     (day . ,(* 24 60 60))
2333     (hour . ,(* 60 60))
2334     (minute . 60)
2335     (second . 1))
2336   "Mapping from time units to seconds.")
2337
2338 (defun article-date-ut (&optional type highlight header)
2339   "Convert DATE date to universal time in the current article.
2340 If TYPE is `local', convert to local time; if it is `lapsed', output
2341 how much time has lapsed since DATE.  For `lapsed', the value of
2342 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2343 should replace the \"Date:\" one, or should be added below it."
2344   (interactive (list 'ut t))
2345   (let* ((header (or header
2346                      (message-fetch-field "date")
2347                      ""))
2348          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2349          (date-regexp
2350           (cond
2351            ((not gnus-article-date-lapsed-new-header)
2352             tdate-regexp)
2353            ((eq type 'lapsed)
2354             "^X-Sent:[ \t]")
2355            (t
2356             "^Date:[ \t]")))
2357          (date (if (vectorp header) (mail-header-date header)
2358                  header))
2359          (inhibit-point-motion-hooks t)
2360          pos
2361          bface eface)
2362     (save-excursion
2363       (save-restriction
2364         (article-narrow-to-head)
2365         (when (re-search-forward tdate-regexp nil t)
2366           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2367                 date (or (get-text-property (gnus-point-at-bol)
2368                                             'original-date)
2369                          date)
2370                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2371           (forward-line 1))
2372         (when (and date (not (string= date "")))
2373           (goto-char (point-min))
2374           (let ((buffer-read-only nil))
2375             ;; Delete any old Date headers.
2376             (while (re-search-forward date-regexp nil t)
2377               (if pos
2378                   (delete-region (progn (beginning-of-line) (point))
2379                                  (progn (forward-line 1) (point)))
2380                 (delete-region (progn (beginning-of-line) (point))
2381                                (progn (end-of-line) (point)))
2382                 (setq pos (point))))
2383             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2384               (forward-line 1))
2385             (if pos (goto-char pos))
2386             (insert (article-make-date-line date (or type 'ut)))
2387             (when (not pos)
2388               (insert "\n")
2389               (forward-line -1))
2390             ;; Do highlighting.
2391             (beginning-of-line)
2392             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2393               (put-text-property (match-beginning 1) (1+ (match-end 1))
2394                                  'original-date date)
2395               (put-text-property (match-beginning 1) (1+ (match-end 1))
2396                                  'face bface)
2397               (put-text-property (match-beginning 2) (match-end 2)
2398                                  'face eface))))))))
2399
2400 (defun article-make-date-line (date type)
2401   "Return a DATE line of TYPE."
2402   (unless (memq type '(local ut original user iso8601 lapsed english))
2403     (error "Unknown conversion type: %s" type))
2404   (condition-case ()
2405       (let ((time (date-to-time date)))
2406         (cond
2407          ;; Convert to the local timezone.
2408          ((eq type 'local)
2409           (let ((tz (car (current-time-zone time))))
2410             (format "Date: %s %s%02d%02d" (current-time-string time)
2411                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2412                     (/ (% (abs tz) 3600) 60))))
2413          ;; Convert to Universal Time.
2414          ((eq type 'ut)
2415           (concat "Date: "
2416                   (current-time-string
2417                    (let* ((e (parse-time-string date))
2418                           (tm (apply 'encode-time e))
2419                           (ms (car tm))
2420                           (ls (- (cadr tm) (car (current-time-zone time)))))
2421                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2422                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2423                            (t (list ms ls)))))
2424                   " UT"))
2425          ;; Get the original date from the article.
2426          ((eq type 'original)
2427           (concat "Date: " (if (string-match "\n+$" date)
2428                                (substring date 0 (match-beginning 0))
2429                              date)))
2430          ;; Let the user define the format.
2431          ((eq type 'user)
2432           (if (gnus-functionp gnus-article-time-format)
2433               (funcall gnus-article-time-format time)
2434             (concat
2435              "Date: "
2436              (format-time-string gnus-article-time-format time))))
2437          ;; ISO 8601.
2438          ((eq type 'iso8601)
2439           (let ((tz (car (current-time-zone time))))
2440             (concat
2441              "Date: "
2442              (format-time-string "%Y%m%dT%H%M%S" time)
2443              (format "%s%02d%02d"
2444                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2445                      (/ (% (abs tz) 3600) 60)))))
2446          ;; Do an X-Sent lapsed format.
2447          ((eq type 'lapsed)
2448           ;; If the date is seriously mangled, the timezone functions are
2449           ;; liable to bug out, so we ignore all errors.
2450           (let* ((now (current-time))
2451                  (real-time (subtract-time now time))
2452                  (real-sec (and real-time
2453                                 (+ (* (float (car real-time)) 65536)
2454                                    (cadr real-time))))
2455                  (sec (and real-time (abs real-sec)))
2456                  num prev)
2457             (cond
2458              ((null real-time)
2459               "X-Sent: Unknown")
2460              ((zerop sec)
2461               "X-Sent: Now")
2462              (t
2463               (concat
2464                "X-Sent: "
2465                ;; This is a bit convoluted, but basically we go
2466                ;; through the time units for years, weeks, etc,
2467                ;; and divide things to see whether that results
2468                ;; in positive answers.
2469                (mapconcat
2470                 (lambda (unit)
2471                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2472                       ;; The (remaining) seconds are too few to
2473                       ;; be divided into this time unit.
2474                       ""
2475                     ;; It's big enough, so we output it.
2476                     (setq sec (- sec (* num (cdr unit))))
2477                     (prog1
2478                         (concat (if prev ", " "") (int-to-string
2479                                                    (floor num))
2480                                 " " (symbol-name (car unit))
2481                                 (if (> num 1) "s" ""))
2482                       (setq prev t))))
2483                 article-time-units "")
2484                ;; If dates are odd, then it might appear like the
2485                ;; article was sent in the future.
2486                (if (> real-sec 0)
2487                    " ago"
2488                  " in the future"))))))
2489          ;; Display the date in proper English
2490          ((eq type 'english)
2491           (let ((dtime (decode-time time)))
2492             (concat
2493              "Date: the "
2494              (number-to-string (nth 3 dtime))
2495              (let ((digit (% (nth 3 dtime) 10)))
2496                (cond
2497                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2498                 ((= digit 1) "st")
2499                 ((= digit 2) "nd")
2500                 ((= digit 3) "rd")
2501                 (t "th")))
2502              " of "
2503              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2504              " "
2505              (number-to-string (nth 5 dtime))
2506              " at "
2507              (format "%02d" (nth 2 dtime))
2508              ":"
2509              (format "%02d" (nth 1 dtime)))))))
2510         (error
2511          (format "Date: %s (from Oort)" date))))
2512
2513 (defun article-date-local (&optional highlight)
2514   "Convert the current article date to the local timezone."
2515   (interactive (list t))
2516   (article-date-ut 'local highlight))
2517
2518 (defun article-date-english (&optional highlight)
2519   "Convert the current article date to something that is proper English."
2520   (interactive (list t))
2521   (article-date-ut 'english highlight))
2522
2523 (defun article-date-original (&optional highlight)
2524   "Convert the current article date to what it was originally.
2525 This is only useful if you have used some other date conversion
2526 function and want to see what the date was before converting."
2527   (interactive (list t))
2528   (article-date-ut 'original highlight))
2529
2530 (defun article-date-lapsed (&optional highlight)
2531   "Convert the current article date to time lapsed since it was sent."
2532   (interactive (list t))
2533   (article-date-ut 'lapsed highlight))
2534
2535 (defun article-update-date-lapsed ()
2536   "Function to be run from a timer to update the lapsed time line."
2537   (let (deactivate-mark)
2538     (save-excursion
2539       (ignore-errors
2540         (walk-windows
2541          (lambda (w)
2542            (set-buffer (window-buffer w))
2543            (when (eq major-mode 'gnus-article-mode)
2544              (goto-char (point-min))
2545              (when (re-search-forward "^X-Sent:" nil t)
2546                (article-date-lapsed t))))
2547          nil 'visible)))))
2548
2549 (defun gnus-start-date-timer (&optional n)
2550   "Start a timer to update the X-Sent header in the article buffers.
2551 The numerical prefix says how frequently (in seconds) the function
2552 is to run."
2553   (interactive "p")
2554   (unless n
2555     (setq n 1))
2556   (gnus-stop-date-timer)
2557   (setq article-lapsed-timer
2558         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2559
2560 (defun gnus-stop-date-timer ()
2561   "Stop the X-Sent timer."
2562   (interactive)
2563   (when article-lapsed-timer
2564     (nnheader-cancel-timer article-lapsed-timer)
2565     (setq article-lapsed-timer nil)))
2566
2567 (defun article-date-user (&optional highlight)
2568   "Convert the current article date to the user-defined format.
2569 This format is defined by the `gnus-article-time-format' variable."
2570   (interactive (list t))
2571   (article-date-ut 'user highlight))
2572
2573 (defun article-date-iso8601 (&optional highlight)
2574   "Convert the current article date to ISO8601."
2575   (interactive (list t))
2576   (article-date-ut 'iso8601 highlight))
2577
2578 (defun article-show-all ()
2579   "Show all hidden text in the article buffer."
2580   (interactive)
2581   (save-excursion
2582     (let ((buffer-read-only nil))
2583       (gnus-article-unhide-text (point-min) (point-max)))))
2584
2585 (defun article-remove-leading-whitespace ()
2586   "Remove excessive whitespace from all headers."
2587   (interactive)
2588   (save-excursion
2589     (save-restriction
2590       (let ((buffer-read-only nil))
2591         (article-narrow-to-head)
2592         (goto-char (point-min))
2593         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2594           (delete-region (match-beginning 1) (match-end 1)))))))
2595
2596 (defun article-emphasize (&optional arg)
2597   "Emphasize text according to `gnus-emphasis-alist'."
2598   (interactive (gnus-article-hidden-arg))
2599   (unless (gnus-article-check-hidden-text 'emphasis arg)
2600     (save-excursion
2601       (let ((alist (or
2602                     (condition-case nil
2603                         (with-current-buffer gnus-summary-buffer
2604                           gnus-article-emphasis-alist)
2605                       (error))
2606                     gnus-emphasis-alist))
2607             (buffer-read-only nil)
2608             (props (append '(article-type emphasis)
2609                            gnus-hidden-properties))
2610             regexp elem beg invisible visible face)
2611         (article-goto-body)
2612         (setq beg (point))
2613         (while (setq elem (pop alist))
2614           (goto-char beg)
2615           (setq regexp (car elem)
2616                 invisible (nth 1 elem)
2617                 visible (nth 2 elem)
2618                 face (nth 3 elem))
2619           (while (re-search-forward regexp nil t)
2620             (when (and (match-beginning visible) (match-beginning invisible))
2621               (gnus-article-hide-text
2622                (match-beginning invisible) (match-end invisible) props)
2623               (gnus-article-unhide-text-type
2624                (match-beginning visible) (match-end visible) 'emphasis)
2625               (gnus-put-overlay-excluding-newlines
2626                (match-beginning visible) (match-end visible) 'face face)
2627               (push 'emphasis gnus-article-wash-types)
2628               (goto-char (match-end invisible)))))))))
2629
2630 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2631   "Setup newsgroup emphasis alist."
2632   (unless gnus-article-emphasis-alist
2633     (let ((name (and gnus-newsgroup-name
2634                      (gnus-group-real-name gnus-newsgroup-name))))
2635       (make-local-variable 'gnus-article-emphasis-alist)
2636       (setq gnus-article-emphasis-alist
2637             (nconc
2638              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2639                (while (setq elem (pop alist))
2640                  (when (and name (string-match (car elem) name))
2641                    (setq alist nil
2642                          highlight (copy-sequence (cdr elem)))))
2643                highlight)
2644              (copy-sequence highlight-words)
2645              (if gnus-newsgroup-name
2646                  (copy-sequence (gnus-group-find-parameter
2647                                  gnus-newsgroup-name 'highlight-words t)))
2648              gnus-emphasis-alist)))))
2649
2650 (eval-when-compile
2651   (defvar gnus-summary-article-menu)
2652   (defvar gnus-summary-post-menu))
2653
2654 ;;; Saving functions.
2655
2656 (defun gnus-article-save (save-buffer file &optional num)
2657   "Save the currently selected article."
2658   (unless gnus-save-all-headers
2659     ;; Remove headers according to `gnus-saved-headers'.
2660     (let ((gnus-visible-headers
2661            (or gnus-saved-headers gnus-visible-headers))
2662           (gnus-article-buffer save-buffer))
2663       (save-excursion
2664         (set-buffer save-buffer)
2665         (article-hide-headers 1 t))))
2666   (save-window-excursion
2667     (if (not gnus-default-article-saver)
2668         (error "No default saver is defined")
2669       ;; !!! Magic!  The saving functions all save
2670       ;; `gnus-save-article-buffer' (or so they think), but we
2671       ;; bind that variable to our save-buffer.
2672       (set-buffer gnus-article-buffer)
2673       (let* ((gnus-save-article-buffer save-buffer)
2674              (filename
2675               (cond
2676                ((not gnus-prompt-before-saving) 'default)
2677                ((eq gnus-prompt-before-saving 'always) nil)
2678                (t file)))
2679              (gnus-number-of-articles-to-be-saved
2680               (when (eq gnus-prompt-before-saving t)
2681                 num)))                  ; Magic
2682         (set-buffer gnus-article-current-summary)
2683         (funcall gnus-default-article-saver filename)))))
2684
2685 (defun gnus-read-save-file-name (prompt &optional filename
2686                                         function group headers variable)
2687   (let ((default-name
2688           (funcall function group headers (symbol-value variable)))
2689         result)
2690     (setq result
2691           (expand-file-name
2692            (cond
2693             ((eq filename 'default)
2694              default-name)
2695             ((eq filename t)
2696              default-name)
2697             (filename filename)
2698             (t
2699              (let* ((split-name (gnus-get-split-value gnus-split-methods))
2700                     (prompt
2701                      (format prompt
2702                              (if (and gnus-number-of-articles-to-be-saved
2703                                       (> gnus-number-of-articles-to-be-saved 1))
2704                                  (format "these %d articles"
2705                                          gnus-number-of-articles-to-be-saved)
2706                                "this article")))
2707                     (file
2708                      ;; Let the split methods have their say.
2709                      (cond
2710                       ;; No split name was found.
2711                       ((null split-name)
2712                        (read-file-name
2713                         (concat prompt " (default "
2714                                 (file-name-nondirectory default-name) ") ")
2715                         (file-name-directory default-name)
2716                         default-name))
2717                       ;; A single group name is returned.
2718                       ((stringp split-name)
2719                        (setq default-name
2720                              (funcall function split-name headers
2721                                       (symbol-value variable)))
2722                        (read-file-name
2723                         (concat prompt " (default "
2724                                 (file-name-nondirectory default-name) ") ")
2725                         (file-name-directory default-name)
2726                         default-name))
2727                       ;; A single split name was found
2728                       ((= 1 (length split-name))
2729                        (let* ((name (expand-file-name
2730                                      (car split-name)
2731                                      gnus-article-save-directory))
2732                               (dir (cond ((file-directory-p name)
2733                                           (file-name-as-directory name))
2734                                          ((file-exists-p name) name)
2735                                          (t gnus-article-save-directory))))
2736                          (read-file-name
2737                           (concat prompt " (default " name ") ")
2738                           dir name)))
2739                       ;; A list of splits was found.
2740                       (t
2741                        (setq split-name (nreverse split-name))
2742                        (let (result)
2743                          (let ((file-name-history
2744                                 (nconc split-name file-name-history)))
2745                            (setq result
2746                                  (expand-file-name
2747                                   (read-file-name
2748                                    (concat prompt " (`M-p' for defaults) ")
2749                                    gnus-article-save-directory
2750                                    (car split-name))
2751                                   gnus-article-save-directory)))
2752                          (car (push result file-name-history)))))))
2753                ;; Create the directory.
2754                (gnus-make-directory (file-name-directory file))
2755       ;; If we have read a directory, we append the default file name.
2756                (when (file-directory-p file)
2757                  (setq file (expand-file-name (file-name-nondirectory
2758                                                default-name)
2759                                               (file-name-as-directory file))))
2760                ;; Possibly translate some characters.
2761                (nnheader-translate-file-chars file))))))
2762     (gnus-make-directory (file-name-directory result))
2763     (set variable result)))
2764
2765 (defun gnus-article-archive-name (group)
2766   "Return the first instance of an \"Archive-name\" in the current buffer."
2767   (let ((case-fold-search t))
2768     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2769       (nnheader-concat gnus-article-save-directory
2770                        (match-string 1)))))
2771
2772 (defun gnus-article-nndoc-name (group)
2773   "If GROUP is an nndoc group, return the name of the parent group."
2774   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2775     (gnus-group-get-parameter group 'save-article-group)))
2776
2777 (defun gnus-summary-save-in-rmail (&optional filename)
2778   "Append this article to Rmail file.
2779 Optional argument FILENAME specifies file name.
2780 Directory to save to is default to `gnus-article-save-directory'."
2781   (setq filename (gnus-read-save-file-name
2782                   "Save %s in rmail file:" filename
2783                   gnus-rmail-save-name gnus-newsgroup-name
2784                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2785   (gnus-eval-in-buffer-window gnus-save-article-buffer
2786     (save-excursion
2787       (save-restriction
2788         (widen)
2789         (gnus-output-to-rmail filename))))
2790   filename)
2791
2792 (defun gnus-summary-save-in-mail (&optional filename)
2793   "Append this article to Unix mail file.
2794 Optional argument FILENAME specifies file name.
2795 Directory to save to is default to `gnus-article-save-directory'."
2796   (setq filename (gnus-read-save-file-name
2797                   "Save %s in Unix mail file:" filename
2798                   gnus-mail-save-name gnus-newsgroup-name
2799                   gnus-current-headers 'gnus-newsgroup-last-mail))
2800   (gnus-eval-in-buffer-window gnus-save-article-buffer
2801     (save-excursion
2802       (save-restriction
2803         (widen)
2804         (if (and (file-readable-p filename)
2805                  (mail-file-babyl-p filename))
2806             (rmail-output-to-rmail-file filename t)
2807           (gnus-output-to-mail filename)))))
2808   filename)
2809
2810 (defun gnus-summary-save-in-file (&optional filename overwrite)
2811   "Append this article to file.
2812 Optional argument FILENAME specifies file name.
2813 Directory to save to is default to `gnus-article-save-directory'."
2814   (setq filename (gnus-read-save-file-name
2815                   "Save %s in file:" filename
2816                   gnus-file-save-name gnus-newsgroup-name
2817                   gnus-current-headers 'gnus-newsgroup-last-file))
2818   (gnus-eval-in-buffer-window gnus-save-article-buffer
2819     (save-excursion
2820       (save-restriction
2821         (widen)
2822         (when (and overwrite
2823                    (file-exists-p filename))
2824           (delete-file filename))
2825         (gnus-output-to-file filename))))
2826   filename)
2827
2828 (defun gnus-summary-write-to-file (&optional filename)
2829   "Write this article to a file, overwriting it if the file exists.
2830 Optional argument FILENAME specifies file name.
2831 The directory to save in defaults to `gnus-article-save-directory'."
2832   (gnus-summary-save-in-file nil t))
2833
2834 (defun gnus-summary-save-body-in-file (&optional filename)
2835   "Append this article body to a file.
2836 Optional argument FILENAME specifies file name.
2837 The directory to save in defaults to `gnus-article-save-directory'."
2838   (setq filename (gnus-read-save-file-name
2839                   "Save %s body in file:" filename
2840                   gnus-file-save-name gnus-newsgroup-name
2841                   gnus-current-headers 'gnus-newsgroup-last-file))
2842   (gnus-eval-in-buffer-window gnus-save-article-buffer
2843     (save-excursion
2844       (save-restriction
2845         (widen)
2846         (when (article-goto-body)
2847           (narrow-to-region (point) (point-max)))
2848         (gnus-output-to-file filename))))
2849   filename)
2850
2851 (defun gnus-summary-save-in-pipe (&optional command)
2852   "Pipe this article to subprocess."
2853   (setq command
2854         (cond ((and (eq command 'default)
2855                     gnus-last-shell-command)
2856                gnus-last-shell-command)
2857               ((stringp command)
2858                command)
2859               (t (read-string
2860                   (format
2861                    "Shell command on %s: "
2862                    (if (and gnus-number-of-articles-to-be-saved
2863                             (> gnus-number-of-articles-to-be-saved 1))
2864                        (format "these %d articles"
2865                                gnus-number-of-articles-to-be-saved)
2866                      "this article"))
2867                   gnus-last-shell-command))))
2868   (when (string-equal command "")
2869     (if gnus-last-shell-command
2870         (setq command gnus-last-shell-command)
2871       (error "A command is required")))
2872   (gnus-eval-in-buffer-window gnus-article-buffer
2873     (save-restriction
2874       (widen)
2875       (shell-command-on-region (point-min) (point-max) command nil)))
2876   (setq gnus-last-shell-command command))
2877
2878 (defun gnus-summary-pipe-to-muttprint (&optional command)
2879   "Pipe this article to muttprint."
2880   (setq command (read-string
2881                  "Print using command: " gnus-summary-muttprint-program
2882                  nil gnus-summary-muttprint-program))
2883   (gnus-summary-save-in-pipe command))
2884
2885 ;;; Article file names when saving.
2886
2887 (defun gnus-capitalize-newsgroup (newsgroup)
2888   "Capitalize NEWSGROUP name."
2889   (when (not (zerop (length newsgroup)))
2890     (concat (char-to-string (upcase (aref newsgroup 0)))
2891             (substring newsgroup 1))))
2892
2893 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2894   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2895 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2896 Otherwise, it is like ~/News/news/group/num."
2897   (let ((default
2898           (expand-file-name
2899            (concat (if (gnus-use-long-file-name 'not-save)
2900                        (gnus-capitalize-newsgroup newsgroup)
2901                      (gnus-newsgroup-directory-form newsgroup))
2902                    "/" (int-to-string (mail-header-number headers)))
2903            gnus-article-save-directory)))
2904     (if (and last-file
2905              (string-equal (file-name-directory default)
2906                            (file-name-directory last-file))
2907              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2908         default
2909       (or last-file default))))
2910
2911 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2912   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2913 If variable `gnus-use-long-file-name' is non-nil, it is
2914 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
2915   (let ((default
2916           (expand-file-name
2917            (concat (if (gnus-use-long-file-name 'not-save)
2918                        newsgroup
2919                      (gnus-newsgroup-directory-form newsgroup))
2920                    "/" (int-to-string (mail-header-number headers)))
2921            gnus-article-save-directory)))
2922     (if (and last-file
2923              (string-equal (file-name-directory default)
2924                            (file-name-directory last-file))
2925              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2926         default
2927       (or last-file default))))
2928
2929 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2930   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2931 If variable `gnus-use-long-file-name' is non-nil, it is
2932 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2933   (or last-file
2934       (expand-file-name
2935        (if (gnus-use-long-file-name 'not-save)
2936            newsgroup
2937          (file-relative-name
2938           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2939           default-directory))
2940        gnus-article-save-directory)))
2941
2942 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2943   "Generate file name from sender."
2944   (let ((from (mail-header-from headers)))
2945     (expand-file-name
2946      (if (and from (string-match "\\([^ <]+\\)@" from))
2947          (match-string 1 from)
2948        "nobody")
2949      gnus-article-save-directory)))
2950
2951 (defun article-verify-x-pgp-sig ()
2952   "Verify X-PGP-Sig."
2953   (interactive)
2954   (if (gnus-buffer-live-p gnus-original-article-buffer)
2955       (let ((sig (with-current-buffer gnus-original-article-buffer
2956                    (gnus-fetch-field "X-PGP-Sig")))
2957             items info headers)
2958         (when (and sig
2959                    mml2015-use
2960                    (mml2015-clear-verify-function))
2961           (with-temp-buffer
2962             (insert-buffer gnus-original-article-buffer)
2963             (setq items (split-string sig))
2964             (message-narrow-to-head)
2965             (let ((inhibit-point-motion-hooks t)
2966                   (case-fold-search t))
2967               ;; Don't verify multiple headers.
2968               (setq headers (mapconcat (lambda (header)
2969                                          (concat header ": "
2970                                                  (mail-fetch-field header) "\n"))
2971                                        (split-string (nth 1 items) ",") "")))
2972             (delete-region (point-min) (point-max))
2973             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2974             (insert "X-Signed-Headers: " (nth 1 items) "\n")
2975             (insert headers)
2976             (widen)
2977             (forward-line)
2978             (while (not (eobp))
2979               (if (looking-at "^-")
2980                   (insert "- "))
2981               (forward-line))
2982             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2983             (insert "Version: " (car items) "\n\n")
2984             (insert (mapconcat 'identity (cddr items) "\n"))
2985             (insert "\n-----END PGP SIGNATURE-----\n")
2986             (let ((mm-security-handle (list (format "multipart/signed"))))
2987               (mml2015-clean-buffer)
2988               (let ((coding-system-for-write (or gnus-newsgroup-charset
2989                                                  'iso-8859-1)))
2990                 (funcall (mml2015-clear-verify-function)))
2991               (setq info
2992                     (or (mm-handle-multipart-ctl-parameter
2993                          mm-security-handle 'gnus-details)
2994                         (mm-handle-multipart-ctl-parameter
2995                          mm-security-handle 'gnus-info)))))
2996           (when info
2997             (let (buffer-read-only bface eface)
2998               (save-restriction
2999                 (message-narrow-to-head)
3000                 (goto-char (point-max))
3001                 (forward-line -1)
3002                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3003                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3004                 (message-remove-header "X-Gnus-PGP-Verify")
3005                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3006                     (forward-line)
3007                   (goto-char (point-max)))
3008                 (narrow-to-region (point) (point))
3009                 (insert "X-Gnus-PGP-Verify: " info "\n")
3010                 (goto-char (point-min))
3011                 (forward-line)
3012                 (while (not (eobp))
3013                   (if (not (looking-at "^[ \t]"))
3014                       (insert " "))
3015                   (forward-line))
3016                 ;; Do highlighting.
3017                 (goto-char (point-min))
3018                 (when (looking-at "\\([^:]+\\): *")
3019                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3020                                      'face bface)
3021                   (put-text-property (match-end 0) (point-max)
3022                                      'face eface)))))))))
3023
3024 (defun article-verify-cancel-lock ()
3025   "Verify Cancel-Lock header."
3026   (interactive)
3027   (if (gnus-buffer-live-p gnus-original-article-buffer)
3028       (canlock-verify gnus-original-article-buffer)))
3029
3030 (eval-and-compile
3031   (mapcar
3032    (lambda (func)
3033      (let (afunc gfunc)
3034        (if (consp func)
3035            (setq afunc (car func)
3036                  gfunc (cdr func))
3037          (setq afunc func
3038                gfunc (intern (format "gnus-%s" func))))
3039        (defalias gfunc
3040          (if (fboundp afunc)
3041            `(lambda (&optional interactive &rest args)
3042               ,(documentation afunc t)
3043               (interactive (list t))
3044               (save-excursion
3045                 (set-buffer gnus-article-buffer)
3046                 (if interactive
3047                     (call-interactively ',afunc)
3048                   (apply ',afunc args))))))))
3049    '(article-hide-headers
3050      article-verify-x-pgp-sig
3051      article-verify-cancel-lock
3052      article-hide-boring-headers
3053      article-treat-overstrike
3054      article-fill-long-lines
3055      article-capitalize-sentences
3056      article-remove-cr
3057      article-remove-leading-whitespace
3058      article-display-x-face
3059      article-de-quoted-unreadable
3060      article-de-base64-unreadable
3061      article-decode-HZ
3062      article-wash-html
3063      article-hide-list-identifiers
3064      article-hide-pgp
3065      article-strip-banner
3066      article-babel
3067      article-hide-pem
3068      article-hide-signature
3069      article-strip-headers-in-body
3070      article-remove-trailing-blank-lines
3071      article-strip-leading-blank-lines
3072      article-strip-multiple-blank-lines
3073      article-strip-leading-space
3074      article-strip-trailing-space
3075      article-strip-blank-lines
3076      article-strip-all-blank-lines
3077      article-replace-with-quoted-text
3078      article-date-local
3079      article-date-english
3080      article-date-iso8601
3081      article-date-original
3082      article-date-ut
3083      article-decode-mime-words
3084      article-decode-charset
3085      article-decode-encoded-words
3086      article-date-user
3087      article-date-lapsed
3088      article-emphasize
3089      article-treat-dumbquotes
3090      article-normalize-headers
3091      (article-show-all . gnus-article-show-all-headers))))
3092 \f
3093 ;;;
3094 ;;; Gnus article mode
3095 ;;;
3096
3097 (put 'gnus-article-mode 'mode-class 'special)
3098
3099 (set-keymap-parent gnus-article-mode-map widget-keymap)
3100
3101 (gnus-define-keys gnus-article-mode-map
3102   " " gnus-article-goto-next-page
3103   "\177" gnus-article-goto-prev-page
3104   [delete] gnus-article-goto-prev-page
3105   [backspace] gnus-article-goto-prev-page
3106   "\C-c^" gnus-article-refer-article
3107   "h" gnus-article-show-summary
3108   "s" gnus-article-show-summary
3109   "\C-c\C-m" gnus-article-mail
3110   "?" gnus-article-describe-briefly
3111   "e" gnus-summary-edit-article
3112   "<" beginning-of-buffer
3113   ">" end-of-buffer
3114   "\C-c\C-i" gnus-info-find-node
3115   "\C-c\C-b" gnus-bug
3116   "\C-hk" gnus-article-describe-key
3117   "\C-hc" gnus-article-describe-key-briefly
3118
3119   "\C-d" gnus-article-read-summary-keys
3120   "\M-*" gnus-article-read-summary-keys
3121   "\M-#" gnus-article-read-summary-keys
3122   "\M-^" gnus-article-read-summary-keys
3123   "\M-g" gnus-article-read-summary-keys)
3124
3125 (substitute-key-definition
3126  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3127
3128 (defun gnus-article-make-menu-bar ()
3129   (unless (boundp 'gnus-article-commands-menu)
3130     (gnus-summary-make-menu-bar))
3131   (gnus-turn-off-edit-menu 'article)
3132   (unless (boundp 'gnus-article-article-menu)
3133     (easy-menu-define
3134      gnus-article-article-menu gnus-article-mode-map ""
3135      '("Article"
3136        ["Scroll forwards" gnus-article-goto-next-page t]
3137        ["Scroll backwards" gnus-article-goto-prev-page t]
3138        ["Show summary" gnus-article-show-summary t]
3139        ["Fetch Message-ID at point" gnus-article-refer-article t]
3140        ["Mail to address at point" gnus-article-mail t]
3141        ["Send a bug report" gnus-bug t]))
3142
3143     (easy-menu-define
3144      gnus-article-treatment-menu gnus-article-mode-map ""
3145      ;; Fixme: this should use :active (and maybe :visible).
3146      '("Treatment"
3147        ["Hide headers" gnus-article-hide-headers t]
3148        ["Hide signature" gnus-article-hide-signature t]
3149        ["Hide citation" gnus-article-hide-citation t]
3150        ["Treat overstrike" gnus-article-treat-overstrike t]
3151        ["Remove carriage return" gnus-article-remove-cr t]
3152        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3153        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3154        ["Remove base64" gnus-article-de-base64-unreadable t]
3155        ["Treat html" gnus-article-wash-html t]
3156        ["Decode HZ" gnus-article-decode-HZ t]))
3157
3158     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3159
3160     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3161
3162     (gnus-run-hooks 'gnus-article-menu-hook)))
3163
3164 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3165 ;; Summary.
3166
3167 (defun gnus-article-mode ()
3168   "Major mode for displaying an article.
3169
3170 All normal editing commands are switched off.
3171
3172 The following commands are available in addition to all summary mode
3173 commands:
3174 \\<gnus-article-mode-map>
3175 \\[gnus-article-next-page]\t Scroll the article one page forwards
3176 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3177 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3178 \\[gnus-article-show-summary]\t Display the summary buffer
3179 \\[gnus-article-mail]\t Send a reply to the address near point
3180 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3181 \\[gnus-info-find-node]\t Go to the Gnus info node"
3182   (interactive)
3183   (gnus-simplify-mode-line)
3184   (setq mode-name "Article")
3185   (setq major-mode 'gnus-article-mode)
3186   (make-local-variable 'minor-mode-alist)
3187   (use-local-map gnus-article-mode-map)
3188   (when (gnus-visual-p 'article-menu 'menu)
3189     (gnus-article-make-menu-bar))
3190   (gnus-update-format-specifications nil 'article-mode)
3191   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3192   (make-local-variable 'gnus-page-broken)
3193   (make-local-variable 'gnus-button-marker-list)
3194   (make-local-variable 'gnus-article-current-summary)
3195   (make-local-variable 'gnus-article-mime-handles)
3196   (make-local-variable 'gnus-article-decoded-p)
3197   (make-local-variable 'gnus-article-mime-handle-alist)
3198   (make-local-variable 'gnus-article-wash-types)
3199   (make-local-variable 'gnus-article-charset)
3200   (make-local-variable 'gnus-article-ignored-charsets)
3201   (gnus-set-default-directory)
3202   (buffer-disable-undo)
3203   (setq buffer-read-only t)
3204   (set-syntax-table gnus-article-mode-syntax-table)
3205   (mm-enable-multibyte)
3206   (gnus-run-hooks 'gnus-article-mode-hook))
3207
3208 (defun gnus-article-setup-buffer ()
3209   "Initialize the article buffer."
3210   (let* ((name (if gnus-single-article-buffer "*Article*"
3211                  (concat "*Article " gnus-newsgroup-name "*")))
3212          (original
3213           (progn (string-match "\\*Article" name)
3214                  (concat " *Original Article"
3215                          (substring name (match-end 0))))))
3216     (setq gnus-article-buffer name)
3217     (setq gnus-original-article-buffer original)
3218     (setq gnus-article-mime-handle-alist nil)
3219     ;; This might be a variable local to the summary buffer.
3220     (unless gnus-single-article-buffer
3221       (save-excursion
3222         (set-buffer gnus-summary-buffer)
3223         (setq gnus-article-buffer name)
3224         (setq gnus-original-article-buffer original)
3225         (gnus-set-global-variables)))
3226     (gnus-article-setup-highlight-words)
3227     ;; Init original article buffer.
3228     (save-excursion
3229       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3230       (mm-enable-multibyte)
3231       (setq major-mode 'gnus-original-article-mode)
3232       (make-local-variable 'gnus-original-article))
3233     (if (get-buffer name)
3234         (save-excursion
3235           (set-buffer name)
3236           (when gnus-article-mime-handles
3237             (mm-destroy-parts gnus-article-mime-handles)
3238             (setq gnus-article-mime-handles nil))
3239           ;; Set it to nil in article-buffer!
3240           (setq gnus-article-mime-handle-alist nil)
3241           (buffer-disable-undo)
3242           (setq buffer-read-only t)
3243           (unless (eq major-mode 'gnus-article-mode)
3244             (gnus-article-mode))
3245           (current-buffer))
3246       (save-excursion
3247         (set-buffer (gnus-get-buffer-create name))
3248         (gnus-article-mode)
3249         (make-local-variable 'gnus-summary-buffer)
3250         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3251         (current-buffer)))))
3252
3253 ;; Set article window start at LINE, where LINE is the number of lines
3254 ;; from the head of the article.
3255 (defun gnus-article-set-window-start (&optional line)
3256   (set-window-start
3257    (gnus-get-buffer-window gnus-article-buffer t)
3258    (save-excursion
3259      (set-buffer gnus-article-buffer)
3260      (goto-char (point-min))
3261      (if (not line)
3262          (point-min)
3263        (gnus-message 6 "Moved to bookmark")
3264        (search-forward "\n\n" nil t)
3265        (forward-line line)
3266        (point)))))
3267
3268 (defun gnus-article-prepare (article &optional all-headers header)
3269   "Prepare ARTICLE in article mode buffer.
3270 ARTICLE should either be an article number or a Message-ID.
3271 If ARTICLE is an id, HEADER should be the article headers.
3272 If ALL-HEADERS is non-nil, no headers are hidden."
3273   (save-excursion
3274     ;; Make sure we start in a summary buffer.
3275     (unless (eq major-mode 'gnus-summary-mode)
3276       (set-buffer gnus-summary-buffer))
3277     (setq gnus-summary-buffer (current-buffer))
3278     (let* ((gnus-article (if header (mail-header-number header) article))
3279            (summary-buffer (current-buffer))
3280            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3281            (group gnus-newsgroup-name)
3282            result)
3283       (save-excursion
3284         (gnus-article-setup-buffer)
3285         (set-buffer gnus-article-buffer)
3286         ;; Deactivate active regions.
3287         (when (and (boundp 'transient-mark-mode)
3288                    transient-mark-mode)
3289           (setq mark-active nil))
3290         (if (not (setq result (let ((buffer-read-only nil))
3291                                 (gnus-request-article-this-buffer
3292                                  article group))))
3293             ;; There is no such article.
3294             (save-excursion
3295               (when (and (numberp article)
3296                          (not (memq article gnus-newsgroup-sparse)))
3297                 (setq gnus-article-current
3298                       (cons gnus-newsgroup-name article))
3299                 (set-buffer gnus-summary-buffer)
3300                 (setq gnus-current-article article)
3301                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3302                     (progn
3303                       (gnus-summary-set-agent-mark article)
3304                       (message "Message marked for downloading"))
3305                   (gnus-summary-mark-article article gnus-canceled-mark)
3306                   (unless (memq article gnus-newsgroup-sparse)
3307                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3308           (if (or (eq result 'pseudo)
3309                   (eq result 'nneething))
3310               (progn
3311                 (save-excursion
3312                   (set-buffer summary-buffer)
3313                   (push article gnus-newsgroup-history)
3314                   (setq gnus-last-article gnus-current-article
3315                         gnus-current-article 0
3316                         gnus-current-headers nil
3317                         gnus-article-current nil)
3318                   (if (eq result 'nneething)
3319                       (gnus-configure-windows 'summary)
3320                     (gnus-configure-windows 'article))
3321                   (gnus-set-global-variables))
3322                 (let ((gnus-article-mime-handle-alist-1
3323                        gnus-article-mime-handle-alist))
3324                   (gnus-set-mode-line 'article)))
3325             ;; The result from the `request' was an actual article -
3326             ;; or at least some text that is now displayed in the
3327             ;; article buffer.
3328             (when (and (numberp article)
3329                        (not (eq article gnus-current-article)))
3330               ;; Seems like a new article has been selected.
3331               ;; `gnus-current-article' must be an article number.
3332               (save-excursion
3333                 (set-buffer summary-buffer)
3334                 (push article gnus-newsgroup-history)
3335                 (setq gnus-last-article gnus-current-article
3336                       gnus-current-article article
3337                       gnus-current-headers
3338                       (gnus-summary-article-header gnus-current-article)
3339                       gnus-article-current
3340                       (cons gnus-newsgroup-name gnus-current-article))
3341                 (unless (vectorp gnus-current-headers)
3342                   (setq gnus-current-headers nil))
3343                 (gnus-summary-goto-subject gnus-current-article)
3344                 (when (gnus-summary-show-thread)
3345                   ;; If the summary buffer really was folded, the
3346                   ;; previous goto may not actually have gone to
3347                   ;; the right article, but the thread root instead.
3348                   ;; So we go again.
3349                   (gnus-summary-goto-subject gnus-current-article))
3350                 (gnus-run-hooks 'gnus-mark-article-hook)
3351                 (gnus-set-mode-line 'summary)
3352                 (when (gnus-visual-p 'article-highlight 'highlight)
3353                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3354                 ;; Set the global newsgroup variables here.
3355                 (gnus-set-global-variables)
3356                 (setq gnus-have-all-headers
3357                       (or all-headers gnus-show-all-headers))))
3358             (save-excursion
3359               (gnus-configure-windows 'article))
3360             (when (or (numberp article)
3361                       (stringp article))
3362               (gnus-article-prepare-display)
3363               ;; Do page break.
3364               (goto-char (point-min))
3365               (setq gnus-page-broken
3366                     (when gnus-break-pages
3367                       (gnus-narrow-to-page)
3368                       t)))
3369             (let ((gnus-article-mime-handle-alist-1
3370                    gnus-article-mime-handle-alist))
3371               (gnus-set-mode-line 'article))
3372             (article-goto-body)
3373             (set-window-point (get-buffer-window (current-buffer)) (point))
3374             (gnus-configure-windows 'article)
3375             t))))))
3376
3377 ;;;###autoload
3378 (defun gnus-article-prepare-display ()
3379   "Make the current buffer look like a nice article."
3380   ;; Hooks for getting information from the article.
3381   ;; This hook must be called before being narrowed.
3382   (let ((gnus-article-buffer (current-buffer))
3383         buffer-read-only)
3384     (unless (eq major-mode 'gnus-article-mode)
3385       (gnus-article-mode))
3386     (setq buffer-read-only nil
3387           gnus-article-wash-types nil)
3388     (gnus-run-hooks 'gnus-tmp-internal-hook)
3389     (when gnus-display-mime-function
3390       (funcall gnus-display-mime-function))
3391     (gnus-run-hooks 'gnus-article-prepare-hook)))
3392
3393 ;;;
3394 ;;; Gnus MIME viewing functions
3395 ;;;
3396
3397 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3398   "The following specs can be used:
3399 %t  The MIME type
3400 %T  MIME type, along with additional info
3401 %n  The `name' parameter
3402 %d  The description, if any
3403 %l  The length of the encoded part
3404 %p  The part identifier number
3405 %e  Dots if the part isn't displayed")
3406
3407 (defvar gnus-mime-button-line-format-alist
3408   '((?t gnus-tmp-type ?s)
3409     (?T gnus-tmp-type-long ?s)
3410     (?n gnus-tmp-name ?s)
3411     (?d gnus-tmp-description ?s)
3412     (?p gnus-tmp-id ?s)
3413     (?l gnus-tmp-length ?d)
3414     (?e gnus-tmp-dots ?s)))
3415
3416 (defvar gnus-mime-button-commands
3417   '((gnus-article-press-button "\r" "Toggle Display")
3418     (gnus-mime-view-part "v" "View Interactively...")
3419     (gnus-mime-view-part-as-type "t" "View As Type...")
3420     (gnus-mime-view-part-as-charset "C" "View As charset...")
3421     (gnus-mime-save-part "o" "Save...")
3422     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3423     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3424     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3425     (gnus-mime-internalize-part "E" "View Internally")
3426     (gnus-mime-externalize-part "e" "View Externally")
3427     (gnus-mime-pipe-part "|" "Pipe To Command...")
3428     (gnus-mime-action-on-part "." "Take action on the part")))
3429
3430 (defun gnus-article-mime-part-status ()
3431   (if gnus-article-mime-handle-alist-1
3432       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3433           " (1 part)"
3434         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3435     ""))
3436
3437 (defvar gnus-mime-button-map
3438   (let ((map (make-sparse-keymap)))
3439     (unless (>= (string-to-number emacs-version) 21)
3440       ;; XEmacs doesn't care.
3441       (set-keymap-parent map gnus-article-mode-map))
3442     (define-key map gnus-mouse-2 'gnus-article-push-button)
3443     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3444     (dolist (c gnus-mime-button-commands)
3445       (define-key map (cadr c) (car c)))
3446     map))
3447
3448 (defun gnus-mime-button-menu (event)
3449   "Construct a context-sensitive menu of MIME commands."
3450   (interactive "e")
3451   (save-window-excursion
3452     (let ((pos (event-start event)))
3453       (select-window (posn-window pos))
3454       (goto-char (posn-point pos))
3455       (gnus-article-check-buffer)
3456       (let ((response (x-popup-menu
3457                        t `("MIME Part"
3458                            ("" ,@(mapcar (lambda (c)
3459                                            (cons (caddr c) (car c)))
3460                                          gnus-mime-button-commands))))))
3461         (if response
3462             (call-interactively response))))))
3463
3464 (defun gnus-mime-view-all-parts (&optional handles)
3465   "View all the MIME parts."
3466   (interactive)
3467   (save-current-buffer
3468     (set-buffer gnus-article-buffer)
3469     (let ((handles (or handles gnus-article-mime-handles))
3470           (mail-parse-charset gnus-newsgroup-charset)
3471           (mail-parse-ignored-charsets
3472            (with-current-buffer gnus-summary-buffer
3473              gnus-newsgroup-ignored-charsets)))
3474       (when handles
3475         (mm-remove-parts handles)
3476         (goto-char (point-min))
3477         (or (search-forward "\n\n") (goto-char (point-max)))
3478         (let (buffer-read-only)
3479           (delete-region (point) (point-max))
3480           (mm-display-parts handles))))))
3481
3482 (defun gnus-mime-save-part-and-strip ()
3483   "Save the MIME part under point then replace it with an external body."
3484   (interactive)
3485   (gnus-article-check-buffer)
3486   (let* ((data (get-text-property (point) 'gnus-data))
3487          file param
3488          (handles gnus-article-mime-handles))
3489     (if (mm-multiple-handles gnus-article-mime-handles)
3490         (error "This function is not implemented"))
3491     (setq file (and data (mm-save-part data)))
3492     (when file
3493       (with-current-buffer (mm-handle-buffer data)
3494         (erase-buffer)
3495         (insert "Content-Type: " (mm-handle-media-type data))
3496         (mml-insert-parameter-string (cdr (mm-handle-type data))
3497                                      '(charset))
3498         (insert "\n")
3499         (insert "Content-ID: " (message-make-message-id) "\n")
3500         (insert "Content-Transfer-Encoding: binary\n")
3501         (insert "\n"))
3502       (setcdr data
3503               (cdr (mm-make-handle nil
3504                                    `("message/external-body"
3505                                      (access-type . "LOCAL-FILE")
3506                                      (name . ,file)))))
3507       (set-buffer gnus-summary-buffer)
3508       (gnus-article-edit-article
3509        `(lambda ()
3510            (erase-buffer)
3511            (let ((mail-parse-charset (or gnus-article-charset
3512                                          ',gnus-newsgroup-charset))
3513                  (mail-parse-ignored-charsets
3514                   (or gnus-article-ignored-charsets
3515                       ',gnus-newsgroup-ignored-charsets))
3516                  (mbl mml-buffer-list))
3517              (setq mml-buffer-list nil)
3518              (insert-buffer gnus-original-article-buffer)
3519              (mime-to-mml ',handles)
3520              (setq gnus-article-mime-handles nil)
3521              (let ((mbl1 mml-buffer-list))
3522                (setq mml-buffer-list mbl)
3523                (set (make-local-variable 'mml-buffer-list) mbl1))
3524              ;; LOCAL argument of add-hook differs between GNU Emacs
3525              ;; and XEmacs. make-local-hook makes sure they are local.
3526              (make-local-hook 'kill-buffer-hook)
3527              (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3528        `(lambda (no-highlight)
3529           (let ((mail-parse-charset (or gnus-article-charset
3530                                         ',gnus-newsgroup-charset))
3531                 (message-options message-options)
3532                 (message-options-set-recipient)
3533                 (mail-parse-ignored-charsets
3534                  (or gnus-article-ignored-charsets
3535                      ',gnus-newsgroup-ignored-charsets)))
3536            (mml-to-mime)
3537            (mml-destroy-buffers)
3538            (remove-hook 'kill-buffer-hook
3539                         'mml-destroy-buffers t)
3540            (kill-local-variable 'mml-buffer-list))
3541           (gnus-summary-edit-article-done
3542            ,(or (mail-header-references gnus-current-headers) "")
3543            ,(gnus-group-read-only-p)
3544            ,gnus-summary-buffer no-highlight))))))
3545
3546 (defun gnus-mime-save-part ()
3547   "Save the MIME part under point."
3548   (interactive)
3549   (gnus-article-check-buffer)
3550   (let ((data (get-text-property (point) 'gnus-data)))
3551     (when data
3552       (mm-save-part data))))
3553
3554 (defun gnus-mime-pipe-part ()
3555   "Pipe the MIME part under point to a process."
3556   (interactive)
3557   (gnus-article-check-buffer)
3558   (let ((data (get-text-property (point) 'gnus-data)))
3559     (when data
3560       (mm-pipe-part data))))
3561
3562 (defun gnus-mime-view-part ()
3563   "Interactively choose a viewing method for the MIME part under point."
3564   (interactive)
3565   (gnus-article-check-buffer)
3566   (let ((data (get-text-property (point) 'gnus-data)))
3567     (when data
3568       (setq gnus-article-mime-handles
3569             (mm-merge-handles
3570              gnus-article-mime-handles (setq data (copy-sequence data))))
3571       (mm-interactively-view-part data))))
3572
3573 (defun gnus-mime-view-part-as-type-internal ()
3574   (gnus-article-check-buffer)
3575   (let* ((name (mail-content-type-get
3576                 (mm-handle-type (get-text-property (point) 'gnus-data))
3577                 'name))
3578          (def-type (and name (mm-default-file-encoding name))))
3579     (and def-type (cons def-type 0))))
3580
3581 (defun gnus-mime-view-part-as-type (&optional mime-type)
3582   "Choose a MIME media type, and view the part as such."
3583   (interactive)
3584   (unless mime-type
3585     (setq mime-type (completing-read
3586                      "View as MIME type: "
3587                      (mapcar #'list (mailcap-mime-types))
3588                      nil nil
3589                      (gnus-mime-view-part-as-type-internal))))
3590   (gnus-article-check-buffer)
3591   (let ((handle (get-text-property (point) 'gnus-data)))
3592     (when handle
3593       (setq handle
3594             (mm-make-handle (mm-handle-buffer handle)
3595                             (cons mime-type (cdr (mm-handle-type handle)))
3596                             (mm-handle-encoding handle)
3597                             (mm-handle-undisplayer handle)
3598                             (mm-handle-disposition handle)
3599                             (mm-handle-description handle)
3600                             nil
3601                             (mm-handle-id handle)))
3602       (setq gnus-article-mime-handles
3603             (mm-merge-handles gnus-article-mime-handles handle))
3604       (gnus-mm-display-part handle))))
3605
3606 (defun gnus-mime-copy-part (&optional handle)
3607   "Put the the MIME part under point into a new buffer."
3608   (interactive)
3609   (gnus-article-check-buffer)
3610   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3611          (contents (and handle (mm-get-part handle)))
3612          (base (and handle
3613                     (file-name-nondirectory
3614                      (or
3615                       (mail-content-type-get (mm-handle-type handle) 'name)
3616                       (mail-content-type-get (mm-handle-type handle)
3617                                              'filename)
3618                       "*decoded*"))))
3619          (buffer (and base (generate-new-buffer base))))
3620     (when contents
3621       (switch-to-buffer buffer)
3622       (insert contents)
3623       ;; We do it this way to make `normal-mode' set the appropriate mode.
3624       (unwind-protect
3625           (progn
3626             (setq buffer-file-name (expand-file-name base))
3627             (normal-mode))
3628         (setq buffer-file-name nil))
3629       (goto-char (point-min)))))
3630
3631 (defun gnus-mime-inline-part (&optional handle arg)
3632   "Insert the MIME part under point into the current buffer."
3633   (interactive (list nil current-prefix-arg))
3634   (gnus-article-check-buffer)
3635   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3636          contents charset
3637          (b (point))
3638          buffer-read-only)
3639     (when handle
3640       (if (and (not arg) (mm-handle-undisplayer handle))
3641           (mm-remove-part handle)
3642         (setq contents (mm-get-part handle))
3643         (cond
3644          ((not arg)
3645           (setq charset (or (mail-content-type-get
3646                              (mm-handle-type handle) 'charset)
3647                             gnus-newsgroup-charset)))
3648          ((numberp arg)
3649           (if (mm-handle-undisplayer handle)
3650               (mm-remove-part handle))
3651           (setq charset
3652                 (or (cdr (assq arg
3653                                gnus-summary-show-article-charset-alist))
3654                     (mm-read-coding-system "Charset: ")))))
3655         (forward-line 2)
3656         (mm-insert-inline handle
3657                           (if (and charset
3658                                    (setq charset (mm-charset-to-coding-system
3659                                                   charset))
3660                                    (not (eq charset 'ascii)))
3661                               (mm-decode-coding-string contents charset)
3662                             contents))
3663         (goto-char b)))))
3664
3665 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3666   "Insert the MIME part under point into the current buffer using the
3667 specified charset."
3668   (interactive (list nil current-prefix-arg))
3669   (gnus-article-check-buffer)
3670   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3671          contents charset
3672          (b (point))
3673          buffer-read-only)
3674     (when handle
3675       (if (mm-handle-undisplayer handle)
3676           (mm-remove-part handle))
3677       (let ((gnus-newsgroup-charset
3678              (or (cdr (assq arg
3679                             gnus-summary-show-article-charset-alist))
3680                  (mm-read-coding-system "Charset: ")))
3681           (gnus-newsgroup-ignored-charsets 'gnus-all))
3682         (gnus-article-press-button)))))
3683
3684 (defun gnus-mime-externalize-part (&optional handle)
3685   "View the MIME part under point with an external viewer."
3686   (interactive)
3687   (gnus-article-check-buffer)
3688   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3689          (mm-user-display-methods nil)
3690          (mm-inlined-types nil)
3691          (mail-parse-charset gnus-newsgroup-charset)
3692          (mail-parse-ignored-charsets
3693           (save-excursion (set-buffer gnus-summary-buffer)
3694                           gnus-newsgroup-ignored-charsets)))
3695     (when handle
3696       (if (mm-handle-undisplayer handle)
3697           (mm-remove-part handle)
3698         (mm-display-part handle)))))
3699
3700 (defun gnus-mime-internalize-part (&optional handle)
3701   "View the MIME part under point with an internal viewer.
3702 If no internal viewer is available, use an external viewer."
3703   (interactive)
3704   (gnus-article-check-buffer)
3705   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3706          (mm-inlined-types '(".*"))
3707          (mm-inline-large-images t)
3708          (mail-parse-charset gnus-newsgroup-charset)
3709          (mail-parse-ignored-charsets
3710           (save-excursion (set-buffer gnus-summary-buffer)
3711                           gnus-newsgroup-ignored-charsets)))
3712     (when handle
3713       (if (mm-handle-undisplayer handle)
3714           (mm-remove-part handle)
3715         (mm-display-part handle)))))
3716
3717 (defun gnus-mime-action-on-part (&optional action)
3718   "Do something with the MIME attachment at \(point\)."
3719   (interactive
3720    (list (completing-read "Action: " gnus-mime-action-alist)))
3721   (gnus-article-check-buffer)
3722   (let ((action-pair (assoc action gnus-mime-action-alist)))
3723     (if action-pair
3724         (funcall (cdr action-pair)))))
3725
3726 (defun gnus-article-part-wrapper (n function)
3727   (save-current-buffer
3728     (set-buffer gnus-article-buffer)
3729     (when (> n (length gnus-article-mime-handle-alist))
3730       (error "No such part"))
3731     (gnus-article-goto-part n)
3732     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3733       (funcall function handle))))
3734
3735 (defun gnus-article-pipe-part (n)
3736   "Pipe MIME part N, which is the numerical prefix."
3737   (interactive "p")
3738   (gnus-article-part-wrapper n 'mm-pipe-part))
3739
3740 (defun gnus-article-save-part (n)
3741   "Save MIME part N, which is the numerical prefix."
3742   (interactive "p")
3743   (gnus-article-part-wrapper n 'mm-save-part))
3744
3745 (defun gnus-article-interactively-view-part (n)
3746   "View MIME part N interactively, which is the numerical prefix."
3747   (interactive "p")
3748   (gnus-article-part-wrapper n 'mm-interactively-view-part))
3749
3750 (defun gnus-article-copy-part (n)
3751   "Copy MIME part N, which is the numerical prefix."
3752   (interactive "p")
3753   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3754
3755 (defun gnus-article-view-part-as-charset (n)
3756   "Copy MIME part N, which is the numerical prefix."
3757   (interactive "p")
3758   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3759
3760 (defun gnus-article-externalize-part (n)
3761   "View MIME part N externally, which is the numerical prefix."
3762   (interactive "p")
3763   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3764
3765 (defun gnus-article-inline-part (n)
3766   "Inline MIME part N, which is the numerical prefix."
3767   (interactive "p")
3768   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3769
3770 (defun gnus-article-mime-match-handle-first (condition)
3771   (if condition
3772       (let ((alist gnus-article-mime-handle-alist) ihandle n)
3773         (while (setq ihandle (pop alist))
3774           (if (and (cond
3775                     ((functionp condition)
3776                      (funcall condition (cdr ihandle)))
3777                     ((eq condition 'undisplayed)
3778                      (not (or (mm-handle-undisplayer (cdr ihandle))
3779                               (equal (mm-handle-media-type (cdr ihandle))
3780                                      "multipart/alternative"))))
3781                     ((eq condition 'undisplayed-alternative)
3782                      (not (mm-handle-undisplayer (cdr ihandle))))
3783                     (t t))
3784                    (gnus-article-goto-part (car ihandle))
3785                    (or (not n) (< (car ihandle) n)))
3786               (setq n (car ihandle))))
3787         (or n 1))
3788     1))
3789
3790 (defun gnus-article-view-part (&optional n)
3791   "View MIME part N, which is the numerical prefix."
3792   (interactive "P")
3793   (save-current-buffer
3794     (set-buffer gnus-article-buffer)
3795     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3796                              gnus-article-mime-match-handle-function)))
3797     (when (> n (length gnus-article-mime-handle-alist))
3798       (error "No such part"))
3799     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3800       (when (gnus-article-goto-part n)
3801         (if (equal (car handle) "multipart/alternative")
3802             (gnus-article-press-button)
3803           (when (eq (gnus-mm-display-part handle) 'internal)
3804             (gnus-set-window-start)))))))
3805
3806 (defsubst gnus-article-mime-total-parts ()
3807   (if (bufferp (car gnus-article-mime-handles))
3808       1 ;; single part
3809     (1- (length gnus-article-mime-handles))))
3810
3811 (defun gnus-mm-display-part (handle)
3812   "Display HANDLE and fix MIME button."
3813   (let ((id (get-text-property (point) 'gnus-part))
3814         (point (point))
3815         buffer-read-only)
3816     (forward-line 1)
3817     (prog1
3818         (let ((window (selected-window))
3819               (mail-parse-charset gnus-newsgroup-charset)
3820               (mail-parse-ignored-charsets
3821                (save-excursion (set-buffer gnus-summary-buffer)
3822                                gnus-newsgroup-ignored-charsets)))
3823           (save-excursion
3824             (unwind-protect
3825                 (let ((win (gnus-get-buffer-window (current-buffer) t))
3826                       (beg (point)))
3827                   (when win
3828                     (select-window win))
3829                   (goto-char point)
3830                   (forward-line)
3831                   (if (mm-handle-displayed-p handle)
3832                       ;; This will remove the part.
3833                       (mm-display-part handle)
3834                     (save-restriction
3835                       (narrow-to-region (point)
3836                                         (if (eobp) (point) (1+ (point))))
3837                       (mm-display-part handle)
3838                       ;; We narrow to the part itself and
3839                       ;; then call the treatment functions.
3840                       (goto-char (point-min))
3841                       (forward-line 1)
3842                       (narrow-to-region (point) (point-max))
3843                       (gnus-treat-article
3844                        nil id
3845                        (gnus-article-mime-total-parts)
3846                        (mm-handle-media-type handle)))))
3847               (if (window-live-p window)
3848                   (select-window window)))))
3849       (goto-char point)
3850       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3851       (gnus-insert-mime-button
3852        handle id (list (mm-handle-displayed-p handle)))
3853       (goto-char point))))
3854
3855 (defun gnus-article-goto-part (n)
3856   "Go to MIME part N."
3857   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3858     (when point
3859       (goto-char point))))
3860
3861 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3862   (let ((gnus-tmp-name
3863          (or (mail-content-type-get (mm-handle-type handle) 'name)
3864              (mail-content-type-get (mm-handle-disposition handle) 'filename)
3865              (mail-content-type-get (mm-handle-type handle) 'url)
3866              ""))
3867         (gnus-tmp-type (mm-handle-media-type handle))
3868         (gnus-tmp-description
3869          (mail-decode-encoded-word-string (or (mm-handle-description handle)
3870                                               "")))
3871         (gnus-tmp-dots
3872          (if (if displayed (car displayed)
3873                (mm-handle-displayed-p handle))
3874              "" "..."))
3875         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3876                            (buffer-size)))
3877         gnus-tmp-type-long b e)
3878     (when (string-match ".*/" gnus-tmp-name)
3879       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3880     (setq gnus-tmp-type-long (concat gnus-tmp-type
3881                                      (and (not (equal gnus-tmp-name ""))
3882                                           (concat "; " gnus-tmp-name))))
3883     (unless (equal gnus-tmp-description "")
3884       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3885     (unless (bolp)
3886       (insert "\n"))
3887     (setq b (point))
3888     (gnus-eval-format
3889      gnus-mime-button-line-format gnus-mime-button-line-format-alist
3890      `(keymap ,gnus-mime-button-map
3891               ,@(if (>= (string-to-number emacs-version) 21)
3892                     nil
3893                   (list 'local-map gnus-mime-button-map))
3894               gnus-callback gnus-mm-display-part
3895               gnus-part ,gnus-tmp-id
3896               article-type annotation
3897               gnus-data ,handle))
3898     (setq e (point))
3899     (widget-convert-button
3900      'link b e
3901      :mime-handle handle
3902      :action 'gnus-widget-press-button
3903      :button-keymap gnus-mime-button-map
3904      :help-echo
3905      (lambda (widget/window &optional overlay pos)
3906        ;; Needed to properly clear the message due to a bug in
3907        ;; wid-edit (XEmacs only).
3908        (if (boundp 'help-echo-owns-message)
3909            (setq help-echo-owns-message t))
3910        (format
3911         "%S: %s the MIME part; %S: more options"
3912         (aref gnus-mouse-2 0)
3913         ;; XEmacs will get a single widget arg; Emacs 21 will get
3914         ;; window, overlay, position.
3915         (if (mm-handle-displayed-p
3916              (if overlay
3917                  (with-current-buffer (gnus-overlay-buffer overlay)
3918                    (widget-get (widget-at (gnus-overlay-start overlay))
3919                                :mime-handle))
3920                (widget-get widget/window :mime-handle)))
3921             "hide" "show")
3922         (aref gnus-down-mouse-3 0))))))
3923
3924 (defun gnus-widget-press-button (elems el)
3925   (goto-char (widget-get elems :from))
3926   (gnus-article-press-button))
3927
3928 (defvar gnus-displaying-mime nil)
3929
3930 (defun gnus-display-mime (&optional ihandles)
3931   "Display the MIME parts."
3932   (save-excursion
3933     (save-selected-window
3934       (let ((window (get-buffer-window gnus-article-buffer))
3935             (point (point)))
3936         (when window
3937           (select-window window)
3938           ;; We have to do this since selecting the window
3939           ;; may change the point.  So we set the window point.
3940           (set-window-point window point)))
3941       (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3942              buffer-read-only handle name type b e display)
3943         (when (and (not ihandles)
3944                    (not gnus-displaying-mime))
3945           ;; Top-level call; we clean up.
3946           (when gnus-article-mime-handles
3947             (mm-destroy-parts gnus-article-mime-handles)
3948             (setq gnus-article-mime-handle-alist nil));; A trick.
3949           (setq gnus-article-mime-handles handles)
3950           ;; We allow users to glean info from the handles.
3951           (when gnus-article-mime-part-function
3952             (gnus-mime-part-function handles)))
3953         (if (and handles
3954                  (or (not (stringp (car handles)))
3955                      (cdr handles)))
3956             (progn
3957               (when (and (not ihandles)
3958                          (not gnus-displaying-mime))
3959                 ;; Clean up for mime parts.
3960                 (article-goto-body)
3961                 (delete-region (point) (point-max)))
3962               (let ((gnus-displaying-mime t))
3963                 (gnus-mime-display-part handles)))
3964           (save-restriction
3965             (article-goto-body)
3966             (narrow-to-region (point) (point-max))
3967             (gnus-treat-article nil 1 1)
3968             (widen)))
3969         (unless ihandles
3970           ;; Highlight the headers.
3971           (save-excursion
3972             (save-restriction
3973               (article-goto-body)
3974               (narrow-to-region (point-min) (point))
3975               (gnus-treat-article 'head))))))))
3976
3977 (defvar gnus-mime-display-multipart-as-mixed nil)
3978 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
3979 (defvar gnus-mime-display-multipart-related-as-mixed nil)
3980
3981 (defun gnus-mime-display-part (handle)
3982   (cond
3983    ;; Single part.
3984    ((not (stringp (car handle)))
3985     (gnus-mime-display-single handle))
3986    ;; User-defined multipart
3987    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3988     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3989              handle))
3990    ;; multipart/alternative
3991    ((and (equal (car handle) "multipart/alternative")
3992          (not (or gnus-mime-display-multipart-as-mixed
3993                   gnus-mime-display-multipart-alternative-as-mixed)))
3994     (let ((id (1+ (length gnus-article-mime-handle-alist))))
3995       (push (cons id handle) gnus-article-mime-handle-alist)
3996       (gnus-mime-display-alternative (cdr handle) nil nil id)))
3997    ;; multipart/related
3998    ((and (equal (car handle) "multipart/related")
3999          (not (or gnus-mime-display-multipart-as-mixed
4000                   gnus-mime-display-multipart-related-as-mixed)))
4001     ;;;!!!We should find the start part, but we just default
4002     ;;;!!!to the first part.
4003     ;;(gnus-mime-display-part (cadr handle))
4004     ;;;!!! Most multipart/related is an HTML message plus images.
4005     ;;;!!! Unfortunately we are unable to let W3 display those
4006     ;;;!!! included images, so we just display it as a mixed multipart.
4007     ;;(gnus-mime-display-mixed (cdr handle))
4008     ;;;!!! No, w3 can display everything just fine.
4009     (gnus-mime-display-part (cadr handle)))
4010    ((equal (car handle) "multipart/signed")
4011     (or (memq 'signed gnus-article-wash-types)
4012         (push 'signed gnus-article-wash-types))
4013     (gnus-mime-display-security handle))
4014    ((equal (car handle) "multipart/encrypted")
4015     (or (memq 'encrypted gnus-article-wash-types)
4016         (push 'encrypted gnus-article-wash-types))
4017     (gnus-mime-display-security handle))
4018    ;; Other multiparts are handled like multipart/mixed.
4019    (t
4020     (gnus-mime-display-mixed (cdr handle)))))
4021
4022 (defun gnus-mime-part-function (handles)
4023   (if (stringp (car handles))
4024       (mapcar 'gnus-mime-part-function (cdr handles))
4025     (funcall gnus-article-mime-part-function handles)))
4026
4027 (defun gnus-mime-display-mixed (handles)
4028   (mapcar 'gnus-mime-display-part handles))
4029
4030 (defun gnus-mime-display-single (handle)
4031   (let ((type (mm-handle-media-type handle))
4032         (ignored gnus-ignored-mime-types)
4033         (not-attachment t)
4034         (move nil)
4035         display text)
4036     (catch 'ignored
4037       (progn
4038         (while ignored
4039           (when (string-match (pop ignored) type)
4040             (throw 'ignored nil)))
4041         (if (and (setq not-attachment
4042                        (and (not (mm-inline-override-p handle))
4043                             (or (not (mm-handle-disposition handle))
4044                                 (equal (car (mm-handle-disposition handle))
4045                                        "inline")
4046                                 (mm-attachment-override-p handle))))
4047                  (mm-automatic-display-p handle)
4048                  (or (and
4049                       (mm-inlinable-p handle)
4050                       (mm-inlined-p handle))
4051                      (mm-automatic-external-display-p type)))
4052             (setq display t)
4053           (when (equal (mm-handle-media-supertype handle) "text")
4054             (setq text t)))
4055         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4056               beg)
4057           (push (cons id handle) gnus-article-mime-handle-alist)
4058           (when (or (not display)
4059                     (not (gnus-unbuttonized-mime-type-p type)))
4060             ;(gnus-article-insert-newline)
4061             (gnus-insert-mime-button
4062              handle id (list (or display (and not-attachment text))))
4063             (gnus-article-insert-newline)
4064             ;(gnus-article-insert-newline)
4065             ;; Remember modify the number of forward lines.
4066             (setq move t))
4067           (setq beg (point))
4068           (cond
4069            (display
4070             (when move
4071               (forward-line -1)
4072               (setq beg (point)))
4073             (let ((mail-parse-charset gnus-newsgroup-charset)
4074                   (mail-parse-ignored-charsets
4075                    (save-excursion (condition-case ()
4076                                        (set-buffer gnus-summary-buffer)
4077                                      (error))
4078                                    gnus-newsgroup-ignored-charsets)))
4079               (mm-display-part handle t))
4080             (goto-char (point-max)))
4081            ((and text not-attachment)
4082             (when move
4083               (forward-line -1)
4084               (setq beg (point)))
4085             (gnus-article-insert-newline)
4086             (mm-insert-inline handle (mm-get-part handle))
4087             (goto-char (point-max))))
4088           ;; Do highlighting.
4089           (save-excursion
4090             (save-restriction
4091               (narrow-to-region beg (point))
4092               (gnus-treat-article
4093                nil id
4094                (gnus-article-mime-total-parts)
4095                (mm-handle-media-type handle)))))))))
4096
4097 (defun gnus-unbuttonized-mime-type-p (type)
4098   "Say whether TYPE is to be unbuttonized."
4099   (unless gnus-inhibit-mime-unbuttonizing
4100     (when (catch 'found
4101             (let ((types gnus-unbuttonized-mime-types))
4102               (while types
4103                 (when (string-match (pop types) type)
4104                   (throw 'found t)))))
4105       (not (catch 'found
4106              (let ((types gnus-buttonized-mime-types))
4107                (while types
4108                  (when (string-match (pop types) type)
4109                    (throw 'found t)))))))))
4110
4111 (defun gnus-article-insert-newline ()
4112   "Insert a newline, but mark it as undeletable."
4113   (gnus-put-text-property
4114    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4115
4116 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4117   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4118          (ihandles handles)
4119          (point (point))
4120          handle buffer-read-only from props begend not-pref)
4121     (save-window-excursion
4122       (save-restriction
4123         (when ibegend
4124           (narrow-to-region (car ibegend)
4125                             (or (cdr ibegend)
4126                                 (progn
4127                                   (goto-char (car ibegend))
4128                                   (forward-line 2)
4129                                   (point))))
4130           (delete-region (point-min) (point-max))
4131           (mm-remove-parts handles))
4132         (setq begend (list (point-marker)))
4133         ;; Do the toggle.
4134         (unless (setq not-pref (cadr (member preferred ihandles)))
4135           (setq not-pref (car ihandles)))
4136         (when (or ibegend
4137                   (not preferred)
4138                   (not (gnus-unbuttonized-mime-type-p
4139                         "multipart/alternative")))
4140           (gnus-add-text-properties
4141            (setq from (point))
4142            (progn
4143              (insert (format "%d.  " id))
4144              (point))
4145            `(gnus-callback
4146              (lambda (handles)
4147                (unless ,(not ibegend)
4148                  (setq gnus-article-mime-handle-alist
4149                        ',gnus-article-mime-handle-alist))
4150                (gnus-mime-display-alternative
4151                 ',ihandles ',not-pref ',begend ,id))
4152              ,@(if (>= (string-to-number emacs-version) 21)
4153                    nil ;; XEmacs doesn't care
4154                  (list 'local-map gnus-mime-button-map))
4155              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4156              face ,gnus-article-button-face
4157              keymap ,gnus-mime-button-map
4158              gnus-part ,id
4159              gnus-data ,handle))
4160           (widget-convert-button 'link from (point)
4161                                  :action 'gnus-widget-press-button
4162                                  :button-keymap gnus-widget-button-keymap)
4163           ;; Do the handles
4164           (while (setq handle (pop handles))
4165             (gnus-add-text-properties
4166              (setq from (point))
4167              (progn
4168                (insert (format "(%c) %-18s"
4169                                (if (equal handle preferred) ?* ? )
4170                                (mm-handle-media-type handle)))
4171                (point))
4172              `(gnus-callback
4173                (lambda (handles)
4174                  (unless ,(not ibegend)
4175                    (setq gnus-article-mime-handle-alist
4176                          ',gnus-article-mime-handle-alist))
4177                  (gnus-mime-display-alternative
4178                   ',ihandles ',handle ',begend ,id))
4179                ,@(if (>= (string-to-number emacs-version) 21)
4180                      nil ;; XEmacs doesn't care
4181                    (list 'local-map gnus-mime-button-map))
4182                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4183                face ,gnus-article-button-face
4184                keymap ,gnus-mime-button-map
4185                gnus-part ,id
4186                gnus-data ,handle))
4187             (widget-convert-button 'link from (point)
4188                                    :action 'gnus-widget-press-button
4189                                    :button-keymap gnus-widget-button-keymap)
4190             (insert "  "))
4191           (insert "\n\n"))
4192         (when preferred
4193           (if (stringp (car preferred))
4194               (gnus-display-mime preferred)
4195             (let ((mail-parse-charset gnus-newsgroup-charset)
4196                   (mail-parse-ignored-charsets
4197                    (save-excursion (set-buffer gnus-summary-buffer)
4198                                    gnus-newsgroup-ignored-charsets)))
4199               (mm-display-part preferred)
4200               ;; Do highlighting.
4201               (save-excursion
4202                 (save-restriction
4203                   (narrow-to-region (car begend) (point-max))
4204                   (gnus-treat-article
4205                    nil (length gnus-article-mime-handle-alist)
4206                    (gnus-article-mime-total-parts)
4207                    (mm-handle-media-type handle))))))
4208           (goto-char (point-max))
4209           (setcdr begend (point-marker)))))
4210     (when ibegend
4211       (goto-char point))))
4212
4213 (defconst gnus-article-wash-status-strings
4214   (let ((alist '((cite "c" "Possible hidden citation text"
4215                        " " "All citation text visible")
4216                  (headers "h" "Hidden headers"
4217                           " " "All headers visible.")
4218                  (pgp "p" "Encrypted or signed message status hidden"
4219                       " " "No hidden encryption nor digital signature status")
4220                  (signature "s" "Signature has been hidden"
4221                             " " "Signature is visible")
4222                  (overstrike "o" "Overstrike (^H) characters applied"
4223                              " " "No overstrike characters applied")
4224                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4225                            " " "No /*_emphasis_*/ characters applied")))
4226         result)
4227     (dolist (entry alist result)
4228       (let ((key (nth 0 entry))
4229             (on (copy-sequence (nth 1 entry)))
4230             (on-help (nth 2 entry))
4231             (off (copy-sequence (nth 3 entry)))
4232             (off-help (nth 4 entry)))
4233         (put-text-property 0 1 'help-echo on-help on)
4234         (put-text-property 0 1 'help-echo off-help off)
4235         (push (list key on off) result))))
4236   "Alist of strings describing wash status in the mode line.
4237 Each entry has the form (KEY ON OF), where the KEY is a symbol
4238 representing the particular washing function, ON is the string to use
4239 in the article mode line when the washing function is active, and OFF
4240 is the string to use when it is inactive.")
4241
4242 (defun gnus-gnus-article-wash-status-entry (key value)
4243   (let ((entry (assoc key gnus-article-wash-status-strings)))
4244     (if value (nth 1 entry) (nth 2 entry))))
4245
4246 (defun gnus-article-wash-status ()
4247   "Return a string which display status of article washing."
4248   (save-excursion
4249     (set-buffer gnus-article-buffer)
4250     (let ((cite (memq 'cite gnus-article-wash-types))
4251           (headers (memq 'headers gnus-article-wash-types))
4252           (boring (memq 'boring-headers gnus-article-wash-types))
4253           (pgp (memq 'pgp gnus-article-wash-types))
4254           (pem (memq 'pem gnus-article-wash-types))
4255           (signed (memq 'signed gnus-article-wash-types))
4256           (encrypted (memq 'encrypted gnus-article-wash-types))
4257           (signature (memq 'signature gnus-article-wash-types))
4258           (overstrike (memq 'overstrike gnus-article-wash-types))
4259           (emphasis (memq 'emphasis gnus-article-wash-types)))
4260       (concat (gnus-gnus-article-wash-status-entry 'cite cite)
4261               (gnus-gnus-article-wash-status-entry 'headers
4262                                                    (or headers boring))
4263               (gnus-gnus-article-wash-status-entry
4264                'pgp (or pgp pem signed encrypted))
4265               (gnus-gnus-article-wash-status-entry 'signature signature)
4266               (gnus-gnus-article-wash-status-entry 'overstrike overstrike)
4267               (gnus-gnus-article-wash-status-entry 'emphasis emphasis)))))
4268
4269 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4270
4271 (defun gnus-article-maybe-hide-headers ()
4272   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4273 Provided for backwards compatibility."
4274   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4275                  (not (save-excursion (set-buffer gnus-summary-buffer)
4276                                       gnus-have-all-headers)))
4277              (not gnus-inhibit-hiding))
4278     (gnus-article-hide-headers)))
4279
4280 ;;; Article savers.
4281
4282 (defun gnus-output-to-file (file-name)
4283   "Append the current article to a file named FILE-NAME."
4284   (let ((artbuf (current-buffer)))
4285     (with-temp-buffer
4286       (insert-buffer-substring artbuf)
4287       ;; Append newline at end of the buffer as separator, and then
4288       ;; save it to file.
4289       (goto-char (point-max))
4290       (insert "\n")
4291       (let ((file-name-coding-system nnmail-pathname-coding-system))
4292         (mm-append-to-file (point-min) (point-max) file-name))
4293       t)))
4294
4295 (defun gnus-narrow-to-page (&optional arg)
4296   "Narrow the article buffer to a page.
4297 If given a numerical ARG, move forward ARG pages."
4298   (interactive "P")
4299   (setq arg (if arg (prefix-numeric-value arg) 0))
4300   (save-excursion
4301     (set-buffer gnus-article-buffer)
4302     (goto-char (point-min))
4303     (widen)
4304     ;; Remove any old next/prev buttons.
4305     (when (gnus-visual-p 'page-marker)
4306       (let ((buffer-read-only nil))
4307         (gnus-remove-text-with-property 'gnus-prev)
4308         (gnus-remove-text-with-property 'gnus-next)))
4309     (when
4310         (cond ((< arg 0)
4311                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4312               ((> arg 0)
4313                (re-search-forward page-delimiter nil 'move arg)))
4314       (goto-char (match-end 0)))
4315     (narrow-to-region
4316      (point)
4317      (if (re-search-forward page-delimiter nil 'move)
4318          (match-beginning 0)
4319        (point)))
4320     (when (and (gnus-visual-p 'page-marker)
4321                (not (= (point-min) 1)))
4322       (save-excursion
4323         (goto-char (point-min))
4324         (gnus-insert-prev-page-button)))
4325     (when (and (gnus-visual-p 'page-marker)
4326                (< (+ (point-max) 2) (buffer-size)))
4327       (save-excursion
4328         (goto-char (point-max))
4329         (gnus-insert-next-page-button)))))
4330
4331 ;; Article mode commands
4332
4333 (defun gnus-article-goto-next-page ()
4334   "Show the next page of the article."
4335   (interactive)
4336   (when (gnus-article-next-page)
4337     (goto-char (point-min))
4338     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4339
4340 (defun gnus-article-goto-prev-page ()
4341   "Show the next page of the article."
4342   (interactive)
4343   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4344     (gnus-article-prev-page nil)))
4345
4346 (defun gnus-article-next-page (&optional lines)
4347   "Show the next page of the current article.
4348 If end of article, return non-nil.  Otherwise return nil.
4349 Argument LINES specifies lines to be scrolled up."
4350   (interactive "p")
4351   (move-to-window-line -1)
4352   (if (save-excursion
4353         (end-of-line)
4354         (and (pos-visible-in-window-p)  ;Not continuation line.
4355              (eobp)))
4356       ;; Nothing in this page.
4357       (if (or (not gnus-page-broken)
4358               (save-excursion
4359                 (save-restriction
4360                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4361           t                             ;Nothing more.
4362         (gnus-narrow-to-page 1)         ;Go to next page.
4363         nil)
4364     ;; More in this page.
4365     (let ((scroll-in-place nil))
4366       (condition-case ()
4367           (scroll-up lines)
4368         (end-of-buffer
4369          ;; Long lines may cause an end-of-buffer error.
4370          (goto-char (point-max)))))
4371     (move-to-window-line 0)
4372     nil))
4373
4374 (defun gnus-article-prev-page (&optional lines)
4375   "Show previous page of current article.
4376 Argument LINES specifies lines to be scrolled down."
4377   (interactive "p")
4378   (move-to-window-line 0)
4379   (if (and gnus-page-broken
4380            (bobp)
4381            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4382       (progn
4383         (gnus-narrow-to-page -1)        ;Go to previous page.
4384         (goto-char (point-max))
4385         (recenter -1))
4386     (let ((scroll-in-place nil))
4387       (prog1
4388           (condition-case ()
4389               (scroll-down lines)
4390             (beginning-of-buffer
4391              (goto-char (point-min))))
4392         (move-to-window-line 0)))))
4393
4394 (defun gnus-article-refer-article ()
4395   "Read article specified by message-id around point."
4396   (interactive)
4397   (let ((point (point)))
4398     (search-forward ">" nil t)          ;Move point to end of "<....>".
4399     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4400         (let ((message-id (match-string 1)))
4401           (goto-char point)
4402           (set-buffer gnus-summary-buffer)
4403           (gnus-summary-refer-article message-id))
4404       (goto-char (point))
4405       (error "No references around point"))))
4406
4407 (defun gnus-article-show-summary ()
4408   "Reconfigure windows to show summary buffer."
4409   (interactive)
4410   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4411       (error "There is no summary buffer for this article buffer")
4412     (gnus-article-set-globals)
4413     (gnus-configure-windows 'article)
4414     (gnus-summary-goto-subject gnus-current-article)
4415     (gnus-summary-position-point)))
4416
4417 (defun gnus-article-describe-briefly ()
4418   "Describe article mode commands briefly."
4419   (interactive)
4420   (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")))
4421
4422 (defun gnus-article-summary-command ()
4423   "Execute the last keystroke in the summary buffer."
4424   (interactive)
4425   (let ((obuf (current-buffer))
4426         (owin (current-window-configuration))
4427         func)
4428     (switch-to-buffer gnus-article-current-summary 'norecord)
4429     (setq func (lookup-key (current-local-map) (this-command-keys)))
4430     (call-interactively func)
4431     (set-buffer obuf)
4432     (set-window-configuration owin)
4433     (set-window-point (get-buffer-window (current-buffer)) (point))))
4434
4435 (defun gnus-article-summary-command-nosave ()
4436   "Execute the last keystroke in the summary buffer."
4437   (interactive)
4438   (let (func)
4439     (pop-to-buffer gnus-article-current-summary 'norecord)
4440     (setq func (lookup-key (current-local-map) (this-command-keys)))
4441     (call-interactively func)))
4442
4443 (defun gnus-article-check-buffer ()
4444   "Beep if not in an article buffer."
4445   (unless (equal major-mode 'gnus-article-mode)
4446     (error "Command invoked outside of a Gnus article buffer")))
4447
4448 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4449   "Read a summary buffer key sequence and execute it from the article buffer."
4450   (interactive "P")
4451   (gnus-article-check-buffer)
4452   (let ((nosaves
4453          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
4454            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4455            "=" "^" "\M-^" "|"))
4456         (nosave-but-article
4457          '("A\r"))
4458         (nosave-in-article
4459          '("\C-d"))
4460         (up-to-top
4461          '("n" "Gn" "p" "Gp"))
4462         keys new-sum-point)
4463     (save-excursion
4464       (set-buffer gnus-article-current-summary)
4465       (let (gnus-pick-mode)
4466         (push (or key last-command-event) unread-command-events)
4467         (setq keys (if (featurep 'xemacs)
4468                        (events-to-keys (read-key-sequence nil))
4469                      (read-key-sequence nil)))))
4470
4471     (message "")
4472
4473     (if (or (member keys nosaves)
4474             (member keys nosave-but-article)
4475             (member keys nosave-in-article))
4476         (let (func)
4477           (save-window-excursion
4478             (pop-to-buffer gnus-article-current-summary 'norecord)
4479             ;; We disable the pick minor mode commands.
4480             (let (gnus-pick-mode)
4481               (setq func (lookup-key (current-local-map) keys))))
4482           (if (or (not func)
4483                   (numberp func))
4484               (ding)
4485             (unless (member keys nosave-in-article)
4486               (set-buffer gnus-article-current-summary))
4487             (call-interactively func)
4488             (setq new-sum-point (point)))
4489           (when (member keys nosave-but-article)
4490             (pop-to-buffer gnus-article-buffer 'norecord)))
4491       ;; These commands should restore window configuration.
4492       (let ((obuf (current-buffer))
4493             (owin (current-window-configuration))
4494             (opoint (point))
4495             (summary gnus-article-current-summary)
4496             func in-buffer selected)
4497         (if not-restore-window
4498             (pop-to-buffer summary 'norecord)
4499           (switch-to-buffer summary 'norecord))
4500         (setq in-buffer (current-buffer))
4501         ;; We disable the pick minor mode commands.
4502         (if (and (setq func (let (gnus-pick-mode)
4503                               (lookup-key (current-local-map) keys)))
4504                  (functionp func))
4505             (progn
4506               (call-interactively func)
4507               (setq new-sum-point (point))
4508               (when (eq in-buffer (current-buffer))
4509                 (setq selected (gnus-summary-select-article))
4510                 (set-buffer obuf)
4511                 (unless not-restore-window
4512                   (set-window-configuration owin))
4513                 (when (eq selected 'old)
4514                   (article-goto-body)
4515                   (set-window-start (get-buffer-window (current-buffer))
4516                                     1)
4517                   (set-window-point (get-buffer-window (current-buffer))
4518                                     (point)))
4519                 (let ((win (get-buffer-window gnus-article-current-summary)))
4520                   (when win
4521                     (set-window-point win new-sum-point))))    )
4522           (switch-to-buffer gnus-article-buffer)
4523           (ding))))))
4524
4525 (defun gnus-article-describe-key (key)
4526   "Display documentation of the function invoked by KEY.  KEY is a string."
4527   (interactive "kDescribe key: ")
4528   (gnus-article-check-buffer)
4529   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4530       (save-excursion
4531         (set-buffer gnus-article-current-summary)
4532         (let (gnus-pick-mode)
4533           (if (featurep 'xemacs)
4534               (progn
4535                 (push (elt key 0) unread-command-events)
4536                 (setq key (events-to-keys
4537                            (read-key-sequence "Describe key: "))))
4538             (setq unread-command-events
4539                   (mapcar
4540                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4541                    (string-to-list key)))
4542             (setq key (read-key-sequence "Describe key: "))))
4543         (describe-key key))
4544     (describe-key key)))
4545
4546 (defun gnus-article-describe-key-briefly (key &optional insert)
4547   "Display documentation of the function invoked by KEY.  KEY is a string."
4548   (interactive "kDescribe key: \nP")
4549   (gnus-article-check-buffer)
4550   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4551       (save-excursion
4552         (set-buffer gnus-article-current-summary)
4553         (let (gnus-pick-mode)
4554           (if (featurep 'xemacs)
4555               (progn
4556                 (push (elt key 0) unread-command-events)
4557                 (setq key (events-to-keys
4558                            (read-key-sequence "Describe key: "))))
4559             (setq unread-command-events
4560                   (mapcar
4561                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4562                    (string-to-list key)))
4563             (setq key (read-key-sequence "Describe key: "))))
4564         (describe-key-briefly key insert))
4565     (describe-key-briefly key insert)))
4566
4567 (defun gnus-article-hide (&optional arg force)
4568   "Hide all the gruft in the current article.
4569 This means that PGP stuff, signatures, cited text and (some)
4570 headers will be hidden.
4571 If given a prefix, show the hidden text instead."
4572   (interactive (append (gnus-article-hidden-arg) (list 'force)))
4573   (gnus-article-hide-headers arg)
4574   (gnus-article-hide-list-identifiers arg)
4575   (gnus-article-hide-pgp arg)
4576   (gnus-article-hide-citation-maybe arg force)
4577   (gnus-article-hide-signature arg))
4578
4579 (defun gnus-article-maybe-highlight ()
4580   "Do some article highlighting if article highlighting is requested."
4581   (when (gnus-visual-p 'article-highlight 'highlight)
4582     (gnus-article-highlight-some)))
4583
4584 (defun gnus-check-group-server ()
4585   ;; Make sure the connection to the server is alive.
4586   (unless (gnus-server-opened
4587            (gnus-find-method-for-group gnus-newsgroup-name))
4588     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4589     (gnus-request-group gnus-newsgroup-name t)))
4590
4591 (defun gnus-request-article-this-buffer (article group)
4592   "Get an article and insert it into this buffer."
4593   (let (do-update-line sparse-header)
4594     (prog1
4595         (save-excursion
4596           (erase-buffer)
4597           (gnus-kill-all-overlays)
4598           (setq group (or group gnus-newsgroup-name))
4599
4600           ;; Using `gnus-request-article' directly will insert the article into
4601           ;; `nntp-server-buffer' - so we'll save some time by not having to
4602           ;; copy it from the server buffer into the article buffer.
4603
4604           ;; We only request an article by message-id when we do not have the
4605           ;; headers for it, so we'll have to get those.
4606           (when (stringp article)
4607             (gnus-read-header article))
4608
4609           ;; If the article number is negative, that means that this article
4610           ;; doesn't belong in this newsgroup (possibly), so we find its
4611           ;; message-id and request it by id instead of number.
4612           (when (and (numberp article)
4613                      gnus-summary-buffer
4614                      (get-buffer gnus-summary-buffer)
4615                      (gnus-buffer-exists-p gnus-summary-buffer))
4616             (save-excursion
4617               (set-buffer gnus-summary-buffer)
4618               (let ((header (gnus-summary-article-header article)))
4619                 (when (< article 0)
4620                   (cond
4621                    ((memq article gnus-newsgroup-sparse)
4622                     ;; This is a sparse gap article.
4623                     (setq do-update-line article)
4624                     (setq article (mail-header-id header))
4625                     (setq sparse-header (gnus-read-header article))
4626                     (setq gnus-newsgroup-sparse
4627                           (delq article gnus-newsgroup-sparse)))
4628                    ((vectorp header)
4629                     ;; It's a real article.
4630                     (setq article (mail-header-id header)))
4631                    (t
4632                     ;; It is an extracted pseudo-article.
4633                     (setq article 'pseudo)
4634                     (gnus-request-pseudo-article header))))
4635
4636                 (let ((method (gnus-find-method-for-group
4637                                gnus-newsgroup-name)))
4638                   (when (and (eq (car method) 'nneething)
4639                              (vectorp header))
4640                     (let ((dir (expand-file-name
4641                                 (mail-header-subject header)
4642                                 (file-name-as-directory
4643                                  (or (cadr (assq 'nneething-address method))
4644                                      (nth 1 method))))))
4645                       (when (file-directory-p dir)
4646                         (setq article 'nneething)
4647                         (gnus-group-enter-directory dir))))))))
4648
4649           (cond
4650            ;; Refuse to select canceled articles.
4651            ((and (numberp article)
4652                  gnus-summary-buffer
4653                  (get-buffer gnus-summary-buffer)
4654                  (gnus-buffer-exists-p gnus-summary-buffer)
4655                  (eq (cdr (save-excursion
4656                             (set-buffer gnus-summary-buffer)
4657                             (assq article gnus-newsgroup-reads)))
4658                      gnus-canceled-mark))
4659             nil)
4660            ;; We first check `gnus-original-article-buffer'.
4661            ((and (get-buffer gnus-original-article-buffer)
4662                  (numberp article)
4663                  (save-excursion
4664                    (set-buffer gnus-original-article-buffer)
4665                    (and (equal (car gnus-original-article) group)
4666                         (eq (cdr gnus-original-article) article))))
4667             (insert-buffer-substring gnus-original-article-buffer)
4668             'article)
4669            ;; Check the backlog.
4670            ((and gnus-keep-backlog
4671                  (gnus-backlog-request-article group article (current-buffer)))
4672             'article)
4673            ;; Check asynchronous pre-fetch.
4674            ((gnus-async-request-fetched-article group article (current-buffer))
4675             (gnus-async-prefetch-next group article gnus-summary-buffer)
4676             (when (and (numberp article) gnus-keep-backlog)
4677               (gnus-backlog-enter-article group article (current-buffer)))
4678             'article)
4679            ;; Check the cache.
4680            ((and gnus-use-cache
4681                  (numberp article)
4682                  (gnus-cache-request-article article group))
4683             'article)
4684            ;; Get the article and put into the article buffer.
4685            ((or (stringp article)
4686                 (numberp article))
4687             (let ((gnus-override-method gnus-override-method)
4688                   (methods (and (stringp article)
4689                                 gnus-refer-article-method))
4690                   result
4691                   (buffer-read-only nil))
4692               (if (or (not (listp methods))
4693                       (and (symbolp (car methods))
4694                            (assq (car methods) nnoo-definition-alist)))
4695                   (setq methods (list methods)))
4696               (when (and (null gnus-override-method)
4697                          methods)
4698                 (setq gnus-override-method (pop methods)))
4699               (while (not result)
4700                 (when (eq gnus-override-method 'current)
4701                   (setq gnus-override-method
4702                         (with-current-buffer gnus-summary-buffer
4703                           gnus-current-select-method)))
4704                 (erase-buffer)
4705                 (gnus-kill-all-overlays)
4706                 (let ((gnus-newsgroup-name group))
4707                   (gnus-check-group-server))
4708                 (when (gnus-request-article article group (current-buffer))
4709                   (when (numberp article)
4710                     (gnus-async-prefetch-next group article
4711                                               gnus-summary-buffer)
4712                     (when gnus-keep-backlog
4713                       (gnus-backlog-enter-article
4714                        group article (current-buffer))))
4715                   (setq result 'article))
4716                 (if (not result)
4717                     (if methods
4718                         (setq gnus-override-method (pop methods))
4719                       (setq result 'done))))
4720               (and (eq result 'article) 'article)))
4721            ;; It was a pseudo.
4722            (t article)))
4723
4724       ;; Associate this article with the current summary buffer.
4725       (setq gnus-article-current-summary gnus-summary-buffer)
4726
4727       ;; Take the article from the original article buffer
4728       ;; and place it in the buffer it's supposed to be in.
4729       (when (and (get-buffer gnus-article-buffer)
4730                  (equal (buffer-name (current-buffer))
4731                         (buffer-name (get-buffer gnus-article-buffer))))
4732         (save-excursion
4733           (if (get-buffer gnus-original-article-buffer)
4734               (set-buffer gnus-original-article-buffer)
4735             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4736             (buffer-disable-undo)
4737             (setq major-mode 'gnus-original-article-mode)
4738             (setq buffer-read-only t))
4739           (let (buffer-read-only)
4740             (erase-buffer)
4741             (insert-buffer-substring gnus-article-buffer))
4742           (setq gnus-original-article (cons group article)))
4743
4744         ;; Decode charsets.
4745         (run-hooks 'gnus-article-decode-hook)
4746         ;; Mark article as decoded or not.
4747         (setq gnus-article-decoded-p gnus-article-decode-hook))
4748
4749       ;; Update sparse articles.
4750       (when (and do-update-line
4751                  (or (numberp article)
4752                      (stringp article)))
4753         (let ((buf (current-buffer)))
4754           (set-buffer gnus-summary-buffer)
4755           (gnus-summary-update-article do-update-line sparse-header)
4756           (gnus-summary-goto-subject do-update-line nil t)
4757           (set-window-point (gnus-get-buffer-window (current-buffer) t)
4758                             (point))
4759           (set-buffer buf))))))
4760
4761 ;;;
4762 ;;; Article editing
4763 ;;;
4764
4765 (defcustom gnus-article-edit-mode-hook nil
4766   "Hook run in article edit mode buffers."
4767   :group 'gnus-article-various
4768   :type 'hook)
4769
4770 (defvar gnus-article-edit-done-function nil)
4771
4772 (defvar gnus-article-edit-mode-map nil)
4773
4774 ;; Should we be using derived.el for this?
4775 (unless gnus-article-edit-mode-map
4776   (setq gnus-article-edit-mode-map (make-sparse-keymap))
4777   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4778
4779   (gnus-define-keys gnus-article-edit-mode-map
4780     "\C-c\C-c" gnus-article-edit-done
4781     "\C-c\C-k" gnus-article-edit-exit)
4782
4783   (gnus-define-keys (gnus-article-edit-wash-map
4784                      "\C-c\C-w" gnus-article-edit-mode-map)
4785     "f" gnus-article-edit-full-stops))
4786
4787 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4788   "Major mode for editing articles.
4789 This is an extended text-mode.
4790
4791 \\{gnus-article-edit-mode-map}"
4792   (make-local-variable 'gnus-article-edit-done-function)
4793   (make-local-variable 'gnus-prev-winconf)
4794   (set (make-local-variable 'font-lock-defaults)
4795        '(message-font-lock-keywords t))
4796   (setq buffer-read-only nil)
4797   (buffer-enable-undo)
4798   (widen))
4799
4800 (defun gnus-article-edit (&optional force)
4801   "Edit the current article.
4802 This will have permanent effect only in mail groups.
4803 If FORCE is non-nil, allow editing of articles even in read-only
4804 groups."
4805   (interactive "P")
4806   (when (and (not force)
4807              (gnus-group-read-only-p))
4808     (error "The current newsgroup does not support article editing"))
4809   (gnus-article-date-original)
4810   (gnus-article-edit-article
4811    'ignore
4812    `(lambda (no-highlight)
4813       'ignore
4814       (gnus-summary-edit-article-done
4815        ,(or (mail-header-references gnus-current-headers) "")
4816        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4817
4818 (defun gnus-article-edit-article (start-func exit-func)
4819   "Start editing the contents of the current article buffer."
4820   (let ((winconf (current-window-configuration)))
4821     (set-buffer gnus-article-buffer)
4822     (gnus-article-edit-mode)
4823     (funcall start-func)
4824     (set-buffer-modified-p nil)
4825     (gnus-configure-windows 'edit-article)
4826     (setq gnus-article-edit-done-function exit-func)
4827     (setq gnus-prev-winconf winconf)
4828     (gnus-message 6 "C-c C-c to end edits")))
4829
4830 (defun gnus-article-edit-done (&optional arg)
4831   "Update the article edits and exit."
4832   (interactive "P")
4833   (let ((func gnus-article-edit-done-function)
4834         (buf (current-buffer))
4835         (start (window-start)))
4836     ;; We remove all text props from the article buffer.
4837     (let ((content
4838            (buffer-substring-no-properties (point-min) (point-max)))
4839           (p (point)))
4840       (erase-buffer)
4841       (insert content)
4842       (let ((winconf gnus-prev-winconf))
4843         (gnus-article-mode)
4844         (set-window-configuration winconf)
4845         ;; Tippy-toe some to make sure that point remains where it was.
4846         (save-current-buffer
4847           (set-buffer buf)
4848           (set-window-start (get-buffer-window (current-buffer)) start)
4849           (goto-char p))))
4850     (save-excursion
4851       (set-buffer buf)
4852       (let ((buffer-read-only nil))
4853         (funcall func arg))
4854       ;; The cache and backlog have to be flushed somewhat.
4855       (when gnus-keep-backlog
4856         (gnus-backlog-remove-article
4857          (car gnus-article-current) (cdr gnus-article-current)))
4858       ;; Flush original article as well.
4859       (save-excursion
4860         (when (get-buffer gnus-original-article-buffer)
4861           (set-buffer gnus-original-article-buffer)
4862           (setq gnus-original-article nil)))
4863       (when gnus-use-cache
4864         (gnus-cache-update-article
4865          (car gnus-article-current) (cdr gnus-article-current))))
4866     (set-buffer buf)
4867     (set-window-start (get-buffer-window buf) start)
4868     (set-window-point (get-buffer-window buf) (point))))
4869
4870 (defun gnus-article-edit-exit ()
4871   "Exit the article editing without updating."
4872   (interactive)
4873   (when (or (not (buffer-modified-p))
4874             (yes-or-no-p "Article modified; kill anyway? "))
4875     (let ((curbuf (current-buffer))
4876           (p (point))
4877           (window-start (window-start)))
4878       (erase-buffer)
4879       (if (gnus-buffer-live-p gnus-original-article-buffer)
4880           (insert-buffer gnus-original-article-buffer))
4881       (let ((winconf gnus-prev-winconf))
4882         (gnus-article-mode)
4883         (set-window-configuration winconf)
4884         ;; Tippy-toe some to make sure that point remains where it was.
4885         (save-current-buffer
4886           (set-buffer curbuf)
4887           (set-window-start (get-buffer-window (current-buffer)) window-start)
4888           (goto-char p))))))
4889
4890 (defun gnus-article-edit-full-stops ()
4891   "Interactively repair spacing at end of sentences."
4892   (interactive)
4893   (save-excursion
4894     (goto-char (point-min))
4895     (search-forward-regexp "^$" nil t)
4896     (let ((case-fold-search nil))
4897       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4898
4899 ;;;
4900 ;;; Article highlights
4901 ;;;
4902
4903 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4904
4905 ;;; Internal Variables:
4906
4907 (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\\)\\)"
4908   "Regular expression that matches URLs."
4909   :group 'gnus-article-buttons
4910   :type 'regexp)
4911
4912 (defcustom gnus-button-alist
4913   `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4914      0 t gnus-button-handle-news 3)
4915     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
4916      gnus-button-handle-news 2)
4917     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4918      1 t
4919      gnus-button-fetch-group 4)
4920     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4921     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4922      t gnus-button-message-id 3)
4923     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4924     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4925     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4926     ;; This is info
4927     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
4928      gnus-button-handle-info 2)
4929     ;; This is how URLs _should_ be embedded in text...
4930     ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4931     ;; Raw URLs.
4932     (,gnus-button-url-regexp 0 t browse-url 0))
4933   "*Alist of regexps matching buttons in article bodies.
4934
4935 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4936 REGEXP: is the string matching text around the button,
4937 BUTTON: is the number of the regexp grouping actually matching the button,
4938 FORM: is a lisp expression which must eval to true for the button to
4939 be added,
4940 CALLBACK: is the function to call when the user push this button, and each
4941 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4942
4943 CALLBACK can also be a variable, in that case the value of that
4944 variable it the real callback function."
4945   :group 'gnus-article-buttons
4946   :type '(repeat (list regexp
4947                        (integer :tag "Button")
4948                        (sexp :tag "Form")
4949                        (function :tag "Callback")
4950                        (repeat :tag "Par"
4951                                :inline t
4952                                (integer :tag "Regexp group")))))
4953
4954 (defcustom gnus-header-button-alist
4955   `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
4956      0 t gnus-button-message-id 0)
4957     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4958     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4959      0 t gnus-button-mailto 0)
4960     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4961     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4962     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4963     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4964      gnus-button-message-id 3))
4965   "*Alist of headers and regexps to match buttons in article heads.
4966
4967 This alist is very similar to `gnus-button-alist', except that each
4968 alist has an additional HEADER element first in each entry:
4969
4970 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4971
4972 HEADER is a regexp to match a header.  For a fuller explanation, see
4973 `gnus-button-alist'."
4974   :group 'gnus-article-buttons
4975   :group 'gnus-article-headers
4976   :type '(repeat (list (regexp :tag "Header")
4977                        regexp
4978                        (integer :tag "Button")
4979                        (sexp :tag "Form")
4980                        (function :tag "Callback")
4981                        (repeat :tag "Par"
4982                                :inline t
4983                                (integer :tag "Regexp group")))))
4984
4985 (defvar gnus-button-regexp nil)
4986 (defvar gnus-button-marker-list nil)
4987 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4988
4989 (defvar gnus-button-last nil)
4990 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4991
4992 ;;; Commands:
4993
4994 (defun gnus-article-push-button (event)
4995   "Check text under the mouse pointer for a callback function.
4996 If the text under the mouse pointer has a `gnus-callback' property,
4997 call it with the value of the `gnus-data' text property."
4998   (interactive "e")
4999   (set-buffer (window-buffer (posn-window (event-start event))))
5000   (let* ((pos (posn-point (event-start event)))
5001          (data (get-text-property pos 'gnus-data))
5002          (fun (get-text-property pos 'gnus-callback)))
5003     (goto-char pos)
5004     (when fun
5005       (funcall fun data))))
5006
5007 (defun gnus-article-press-button ()
5008   "Check text at point for a callback function.
5009 If the text at point has a `gnus-callback' property,
5010 call it with the value of the `gnus-data' text property."
5011   (interactive)
5012   (let* ((data (get-text-property (point) 'gnus-data))
5013          (fun (get-text-property (point) 'gnus-callback)))
5014     (when fun
5015       (funcall fun data))))
5016
5017 (defun gnus-article-highlight (&optional force)
5018   "Highlight current article.
5019 This function calls `gnus-article-highlight-headers',
5020 `gnus-article-highlight-citation',
5021 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5022 do the highlighting.  See the documentation for those functions."
5023   (interactive (list 'force))
5024   (gnus-article-highlight-headers)
5025   (gnus-article-highlight-citation force)
5026   (gnus-article-highlight-signature)
5027   (gnus-article-add-buttons force)
5028   (gnus-article-add-buttons-to-head))
5029
5030 (defun gnus-article-highlight-some (&optional force)
5031   "Highlight current article.
5032 This function calls `gnus-article-highlight-headers',
5033 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5034 do the highlighting.  See the documentation for those functions."
5035   (interactive (list 'force))
5036   (gnus-article-highlight-headers)
5037   (gnus-article-highlight-signature)
5038   (gnus-article-add-buttons))
5039
5040 (defun gnus-article-highlight-headers ()
5041   "Highlight article headers as specified by `gnus-header-face-alist'."
5042   (interactive)
5043   (save-excursion
5044     (set-buffer gnus-article-buffer)
5045     (save-restriction
5046       (let ((alist gnus-header-face-alist)
5047             (buffer-read-only nil)
5048             (case-fold-search t)
5049             (inhibit-point-motion-hooks t)
5050             entry regexp header-face field-face from hpoints fpoints)
5051         (article-narrow-to-head)
5052         (while (setq entry (pop alist))
5053           (goto-char (point-min))
5054           (setq regexp (concat "^\\("
5055                                (if (string-equal "" (nth 0 entry))
5056                                    "[^\t ]"
5057                                  (nth 0 entry))
5058                                "\\)")
5059                 header-face (nth 1 entry)
5060                 field-face (nth 2 entry))
5061           (while (and (re-search-forward regexp nil t)
5062                       (not (eobp)))
5063             (beginning-of-line)
5064             (setq from (point))
5065             (unless (search-forward ":" nil t)
5066               (forward-char 1))
5067             (when (and header-face
5068                        (not (memq (point) hpoints)))
5069               (push (point) hpoints)
5070               (gnus-put-text-property from (point) 'face header-face))
5071             (when (and field-face
5072                        (not (memq (setq from (point)) fpoints)))
5073               (push from fpoints)
5074               (if (re-search-forward "^[^ \t]" nil t)
5075                   (forward-char -2)
5076                 (goto-char (point-max)))
5077               (gnus-put-text-property from (point) 'face field-face))))))))
5078
5079 (defun gnus-article-highlight-signature ()
5080   "Highlight the signature in an article.
5081 It does this by highlighting everything after
5082 `gnus-signature-separator' using `gnus-signature-face'."
5083   (interactive)
5084   (save-excursion
5085     (set-buffer gnus-article-buffer)
5086     (let ((buffer-read-only nil)
5087           (inhibit-point-motion-hooks t))
5088       (save-restriction
5089         (when (and gnus-signature-face
5090                    (gnus-article-narrow-to-signature))
5091           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5092                             'face gnus-signature-face)
5093           (widen)
5094           (gnus-article-search-signature)
5095           (let ((start (match-beginning 0))
5096                 (end (set-marker (make-marker) (1+ (match-end 0)))))
5097             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5098                                      end)))))))
5099
5100 (defun gnus-button-in-region-p (b e prop)
5101   "Say whether PROP exists in the region."
5102   (text-property-not-all b e prop nil))
5103
5104 (defun gnus-article-add-buttons (&optional force)
5105   "Find external references in the article and make buttons of them.
5106 \"External references\" are things like Message-IDs and URLs, as
5107 specified by `gnus-button-alist'."
5108   (interactive (list 'force))
5109   (save-excursion
5110     (set-buffer gnus-article-buffer)
5111     (let ((buffer-read-only nil)
5112           (inhibit-point-motion-hooks t)
5113           (case-fold-search t)
5114           (alist gnus-button-alist)
5115           beg entry regexp)
5116       ;; Remove all old markers.
5117       (let (marker entry new-list)
5118         (while (setq marker (pop gnus-button-marker-list))
5119           (if (or (< marker (point-min)) (>= marker (point-max)))
5120               (push marker new-list)
5121             (goto-char marker)
5122             (when (setq entry (gnus-button-entry))
5123               (put-text-property (match-beginning (nth 1 entry))
5124                                  (match-end (nth 1 entry))
5125                                  'gnus-callback nil))
5126             (set-marker marker nil)))
5127         (setq gnus-button-marker-list new-list))
5128       ;; We skip the headers.
5129       (article-goto-body)
5130       (setq beg (point))
5131       (while (setq entry (pop alist))
5132         (setq regexp (car entry))
5133         (goto-char beg)
5134         (while (re-search-forward regexp nil t)
5135           (let* ((start (and entry (match-beginning (nth 1 entry))))
5136                  (end (and entry (match-end (nth 1 entry))))
5137                  (from (match-beginning 0)))
5138             (when (and (or (eq t (nth 2 entry))
5139                            (eval (nth 2 entry)))
5140                        (not (gnus-button-in-region-p
5141                              start end 'gnus-callback)))
5142               ;; That optional form returned non-nil, so we add the
5143               ;; button.
5144               (gnus-article-add-button
5145                start end 'gnus-button-push
5146                (car (push (set-marker (make-marker) from)
5147                           gnus-button-marker-list))))))))))
5148
5149 ;; Add buttons to the head of an article.
5150 (defun gnus-article-add-buttons-to-head ()
5151   "Add buttons to the head of the article."
5152   (interactive)
5153   (save-excursion
5154     (set-buffer gnus-article-buffer)
5155     (save-restriction
5156       (let ((buffer-read-only nil)
5157             (inhibit-point-motion-hooks t)
5158             (case-fold-search t)
5159             (alist gnus-header-button-alist)
5160             entry beg end)
5161         (article-narrow-to-head)
5162         (while alist
5163           ;; Each alist entry.
5164           (setq entry (car alist)
5165                 alist (cdr alist))
5166           (goto-char (point-min))
5167           (while (re-search-forward (car entry) nil t)
5168             ;; Each header matching the entry.
5169             (setq beg (match-beginning 0))
5170             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5171                                (match-beginning 0))
5172                           (point-max)))
5173             (goto-char beg)
5174             (while (re-search-forward (nth 1 entry) end t)
5175               ;; Each match within a header.
5176               (let* ((entry (cdr entry))
5177                      (start (match-beginning (nth 1 entry)))
5178                      (end (match-end (nth 1 entry)))
5179                      (form (nth 2 entry)))
5180                 (goto-char (match-end 0))
5181                 (when (eval form)
5182                   (gnus-article-add-button
5183                    start end (nth 3 entry)
5184                    (buffer-substring (match-beginning (nth 4 entry))
5185                                      (match-end (nth 4 entry)))))))
5186             (goto-char end)))))))
5187
5188 ;;; External functions:
5189
5190 (defun gnus-article-add-button (from to fun &optional data)
5191   "Create a button between FROM and TO with callback FUN and data DATA."
5192   (when gnus-article-button-face
5193     (gnus-overlay-put (gnus-make-overlay from to)
5194                       'face gnus-article-button-face))
5195   (gnus-add-text-properties
5196    from to
5197    (nconc (and gnus-article-mouse-face
5198                (list gnus-mouse-face-prop gnus-article-mouse-face))
5199           (list 'gnus-callback fun)
5200           (and data (list 'gnus-data data))))
5201   (widget-convert-button 'link from to :action 'gnus-widget-press-button
5202                          :button-keymap gnus-widget-button-keymap))
5203
5204 ;;; Internal functions:
5205
5206 (defun gnus-article-set-globals ()
5207   (save-excursion
5208     (set-buffer gnus-summary-buffer)
5209     (gnus-set-global-variables)))
5210
5211 (defun gnus-signature-toggle (end)
5212   (save-excursion
5213     (set-buffer gnus-article-buffer)
5214     (let ((buffer-read-only nil)
5215           (inhibit-point-motion-hooks t))
5216       (if (text-property-any end (point-max) 'article-type 'signature)
5217           (progn
5218             (setq gnus-article-wash-types
5219                   (delq 'signature gnus-article-wash-types))
5220             (gnus-remove-text-properties-when
5221              'article-type 'signature end (point-max)
5222              (cons 'article-type (cons 'signature
5223                                        gnus-hidden-properties))))
5224         (or (memq 'signature gnus-article-wash-types)
5225             (push 'signature gnus-article-wash-types))
5226         (gnus-add-text-properties-when
5227          'article-type nil end (point-max)
5228          (cons 'article-type (cons 'signature
5229                                    gnus-hidden-properties)))))
5230     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5231       (gnus-set-mode-line 'article))))
5232
5233 (defun gnus-button-entry ()
5234   ;; Return the first entry in `gnus-button-alist' matching this place.
5235   (let ((alist gnus-button-alist)
5236         (entry nil))
5237     (while alist
5238       (setq entry (pop alist))
5239       (if (looking-at (car entry))
5240           (setq alist nil)
5241         (setq entry nil)))
5242     entry))
5243
5244 (defun gnus-button-push (marker)
5245   ;; Push button starting at MARKER.
5246   (save-excursion
5247     (goto-char marker)
5248     (let* ((entry (gnus-button-entry))
5249            (inhibit-point-motion-hooks t)
5250            (fun (nth 3 entry))
5251            (args (mapcar (lambda (group)
5252                            (let ((string (match-string group)))
5253                              (gnus-set-text-properties
5254                               0 (length string) nil string)
5255                              string))
5256                          (nthcdr 4 entry))))
5257       (cond
5258        ((fboundp fun)
5259         (apply fun args))
5260        ((and (boundp fun)
5261              (fboundp (symbol-value fun)))
5262         (apply (symbol-value fun) args))
5263        (t
5264         (gnus-message 1 "You must define `%S' to use this button"
5265                       (cons fun args)))))))
5266
5267 (defun gnus-parse-news-url (url)
5268   (let (scheme server group message-id articles)
5269     (with-temp-buffer
5270       (insert url)
5271       (goto-char (point-min))
5272       (when (looking-at "\\([A-Za-z]+\\):")
5273         (setq scheme (match-string 1))
5274         (goto-char (match-end 0)))
5275       (when (looking-at "//\\([^/]+\\)/")
5276         (setq server (match-string 1))
5277         (goto-char (match-end 0)))
5278
5279       (cond
5280        ((looking-at "\\(.*@.*\\)")
5281         (setq message-id (match-string 1)))
5282        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5283         (setq group (match-string 1)
5284               articles (split-string (match-string 2) "-")))
5285        ((looking-at "\\([^/]+\\)/?")
5286         (setq group (match-string 1)))
5287        (t
5288         (error "Unknown news URL syntax"))))
5289     (list scheme server group message-id articles)))
5290
5291 (defun gnus-button-handle-news (url)
5292   "Fetch a news URL."
5293   (destructuring-bind (scheme server group message-id articles)
5294       (gnus-parse-news-url url)
5295     (cond
5296      (message-id
5297       (save-excursion
5298         (set-buffer gnus-summary-buffer)
5299         (if server
5300             (let ((gnus-refer-article-method (list (list 'nntp server))))
5301               (gnus-summary-refer-article message-id))
5302           (gnus-summary-refer-article message-id))))
5303      (group
5304       (gnus-button-fetch-group url)))))
5305
5306 (defun gnus-button-handle-info (url)
5307   "Fetch an info URL."
5308   (if (string-match
5309        "^\\([^:/]+\\)?/\\(.*\\)"
5310        url)
5311       (gnus-info-find-node
5312        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5313                        "Gnus")
5314                ")"
5315                (gnus-url-unhex-string (match-string 2 url))))
5316     (error "Can't parse %s" url)))
5317
5318 (defun gnus-button-message-id (message-id)
5319   "Fetch MESSAGE-ID."
5320   (save-excursion
5321     (set-buffer gnus-summary-buffer)
5322     (gnus-summary-refer-article message-id)))
5323
5324 (defun gnus-button-fetch-group (address)
5325   "Fetch GROUP specified by ADDRESS."
5326   (if (not (string-match "[:/]" address))
5327       ;; This is just a simple group url.
5328       (gnus-group-read-ephemeral-group address gnus-select-method)
5329     (if (not
5330          (string-match
5331           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5332           address))
5333         (error "Can't parse %s" address)
5334       (gnus-group-read-ephemeral-group
5335        (match-string 4 address)
5336        `(nntp ,(match-string 1 address)
5337               (nntp-address ,(match-string 1 address))
5338               (nntp-port-number ,(if (match-end 3)
5339                                      (match-string 3 address)
5340                                    "nntp")))
5341        nil nil nil
5342        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5343
5344 (defun gnus-url-parse-query-string (query &optional downcase)
5345   (let (retval pairs cur key val)
5346     (setq pairs (split-string query "&"))
5347     (while pairs
5348       (setq cur (car pairs)
5349             pairs (cdr pairs))
5350       (if (not (string-match "=" cur))
5351           nil                           ; Grace
5352         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5353               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5354         (if downcase
5355             (setq key (downcase key)))
5356         (setq cur (assoc key retval))
5357         (if cur
5358             (setcdr cur (cons val (cdr cur)))
5359           (setq retval (cons (list key val) retval)))))
5360     retval))
5361
5362 (defun gnus-url-mailto (url)
5363   ;; Send mail to someone
5364   (when (string-match "mailto:/*\\(.*\\)" url)
5365     (setq url (substring url (match-beginning 1) nil)))
5366   (let (to args subject func)
5367     (if (string-match (regexp-quote "?") url)
5368         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5369               args (gnus-url-parse-query-string
5370                     (substring url (match-end 0) nil) t))
5371       (setq to (gnus-url-unhex-string url)))
5372     (setq args (cons (list "to" to) args)
5373           subject (cdr-safe (assoc "subject" args)))
5374     (gnus-msg-mail)
5375     (while args
5376       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5377       (if (fboundp func)
5378           (funcall func)
5379         (message-position-on-field (caar args)))
5380       (insert (mapconcat 'identity (cdar args) ", "))
5381       (setq args (cdr args)))
5382     (if subject
5383         (message-goto-body)
5384       (message-goto-subject))))
5385
5386 (defun gnus-button-embedded-url (address)
5387   "Activate ADDRESS with `browse-url'."
5388   (browse-url (gnus-strip-whitespace address)))
5389
5390 ;;; Next/prev buttons in the article buffer.
5391
5392 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5393 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5394
5395 (defvar gnus-prev-page-map nil)
5396 (unless gnus-prev-page-map
5397   (setq gnus-prev-page-map (make-sparse-keymap))
5398   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5399   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5400
5401 (defun gnus-insert-prev-page-button ()
5402   (let ((buffer-read-only nil))
5403     (gnus-eval-format
5404      gnus-prev-page-line-format nil
5405      `(gnus-prev t local-map ,gnus-prev-page-map
5406                  gnus-callback gnus-article-button-prev-page
5407                  article-type annotation))))
5408
5409 (defvar gnus-next-page-map nil)
5410 (unless gnus-next-page-map
5411   (setq gnus-next-page-map (make-keymap))
5412   (suppress-keymap gnus-prev-page-map)
5413   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5414   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5415
5416 (defun gnus-button-next-page ()
5417   "Go to the next page."
5418   (interactive)
5419   (let ((win (selected-window)))
5420     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5421     (gnus-article-next-page)
5422     (select-window win)))
5423
5424 (defun gnus-button-prev-page ()
5425   "Go to the prev page."
5426   (interactive)
5427   (let ((win (selected-window)))
5428     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5429     (gnus-article-prev-page)
5430     (select-window win)))
5431
5432 (defun gnus-insert-next-page-button ()
5433   (let ((buffer-read-only nil))
5434     (gnus-eval-format gnus-next-page-line-format nil
5435                       `(gnus-next
5436                         t local-map ,gnus-next-page-map
5437                         gnus-callback gnus-article-button-next-page
5438                         article-type annotation))))
5439
5440 (defun gnus-article-button-next-page (arg)
5441   "Go to the next page."
5442   (interactive "P")
5443   (let ((win (selected-window)))
5444     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5445     (gnus-article-next-page)
5446     (select-window win)))
5447
5448 (defun gnus-article-button-prev-page (arg)
5449   "Go to the prev page."
5450   (interactive "P")
5451   (let ((win (selected-window)))
5452     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5453     (gnus-article-prev-page)
5454     (select-window win)))
5455
5456 (defvar gnus-decode-header-methods
5457   '(mail-decode-encoded-word-region)
5458   "List of methods used to decode headers.
5459
5460 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
5461 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
5462 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5463 whose names match REGEXP.
5464
5465 For example:
5466 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5467  mail-decode-encoded-word-region
5468  (\"chinese\" . rfc1843-decode-region))
5469 ")
5470
5471 (defvar gnus-decode-header-methods-cache nil)
5472
5473 (defun gnus-multi-decode-header (start end)
5474   "Apply the functions from `gnus-encoded-word-methods' that match."
5475   (unless (and gnus-decode-header-methods-cache
5476                (eq gnus-newsgroup-name
5477                    (car gnus-decode-header-methods-cache)))
5478     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5479     (mapcar (lambda (x)
5480               (if (symbolp x)
5481                   (nconc gnus-decode-header-methods-cache (list x))
5482                 (if (and gnus-newsgroup-name
5483                          (string-match (car x) gnus-newsgroup-name))
5484                     (nconc gnus-decode-header-methods-cache
5485                            (list (cdr x))))))
5486           gnus-decode-header-methods))
5487   (let ((xlist gnus-decode-header-methods-cache))
5488     (pop xlist)
5489     (save-restriction
5490       (narrow-to-region start end)
5491       (while xlist
5492         (funcall (pop xlist) (point-min) (point-max))))))
5493
5494 ;;;
5495 ;;; Treatment top-level handling.
5496 ;;;
5497
5498 (defun gnus-treat-article (condition &optional part-number total-parts type)
5499   (let ((length (- (point-max) (point-min)))
5500         (alist gnus-treatment-function-alist)
5501         (article-goto-body-goes-to-point-min-p t)
5502         (treated-type
5503          (or (not type)
5504              (catch 'found
5505                (let ((list gnus-article-treat-types))
5506                  (while list
5507                    (when (string-match (pop list) type)
5508                      (throw 'found t)))))))
5509         (highlightp (gnus-visual-p 'article-highlight 'highlight))
5510         val elem)
5511     (gnus-run-hooks 'gnus-part-display-hook)
5512     (while (setq elem (pop alist))
5513       (setq val
5514             (save-excursion
5515               (if (gnus-buffer-live-p gnus-summary-buffer)
5516                   (set-buffer gnus-summary-buffer))
5517               (symbol-value (car elem))))
5518       (when (and (or (consp val)
5519                      treated-type)
5520                  (gnus-treat-predicate val)
5521                  (or (not (get (car elem) 'highlight))
5522                      highlightp))
5523         (save-restriction
5524           (funcall (cadr elem)))))))
5525
5526 ;; Dynamic variables.
5527 (eval-when-compile
5528   (defvar part-number)
5529   (defvar total-parts)
5530   (defvar type)
5531   (defvar condition)
5532   (defvar length))
5533
5534 (defun gnus-treat-predicate (val)
5535   (cond
5536    ((null val)
5537     nil)
5538    ((and (listp val)
5539          (stringp (car val)))
5540     (apply 'gnus-or (mapcar `(lambda (s)
5541                                (string-match s ,(or gnus-newsgroup-name "")))
5542                             val)))
5543    ((listp val)
5544     (let ((pred (pop val)))
5545       (cond
5546        ((eq pred 'or)
5547         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5548        ((eq pred 'and)
5549         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5550        ((eq pred 'not)
5551         (not (gnus-treat-predicate (car val))))
5552        ((eq pred 'typep)
5553         (equal (car val) type))
5554        (t
5555         (error "%S is not a valid predicate" pred)))))
5556    (condition
5557     (eq condition val))
5558    ((eq val t)
5559     t)
5560    ((eq val 'head)
5561     nil)
5562    ((eq val 'last)
5563     (eq part-number total-parts))
5564    ((numberp val)
5565     (< length val))
5566    (t
5567     (error "%S is not a valid value" val))))
5568
5569 (defun gnus-article-encrypt-body (protocol &optional n)
5570   "Encrypt the article body."
5571   (interactive
5572    (list
5573     (or gnus-article-encrypt-protocol
5574         (completing-read "Encrypt protocol: "
5575                          gnus-article-encrypt-protocol-alist
5576                          nil t))
5577     current-prefix-arg))
5578   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5579     (unless func
5580       (error (format "Can't find the encrypt protocol %s" protocol)))
5581     (if (equal gnus-newsgroup-name "nndraft:drafts")
5582         (error "Can't encrypt the article in group nndraft:drafts"))
5583     (if (equal gnus-newsgroup-name "nndraft:queue")
5584         (error "Don't encrypt the article in group nndraft:queue"))
5585     (gnus-summary-iterate n
5586       (save-excursion
5587         (set-buffer gnus-summary-buffer)
5588         (let ((mail-parse-charset gnus-newsgroup-charset)
5589               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5590               (summary-buffer gnus-summary-buffer)
5591               references point)
5592           (gnus-set-global-variables)
5593           (when (gnus-group-read-only-p)
5594             (error "The current newsgroup does not support article encrypt"))
5595           (gnus-summary-show-article t)
5596           (setq references
5597               (or (mail-header-references gnus-current-headers) ""))
5598           (set-buffer gnus-article-buffer)
5599           (let* ((buffer-read-only nil)
5600                  (headers
5601                   (mapcar (lambda (field)
5602                             (and (save-restriction
5603                                    (message-narrow-to-head)
5604                                    (goto-char (point-min))
5605                                    (search-forward field nil t))
5606                                  (prog2
5607                                      (message-narrow-to-field)
5608                                      (buffer-substring (point-min) (point-max))
5609                                    (delete-region (point-min) (point-max))
5610                                    (widen))))
5611                           '("Content-Type:" "Content-Transfer-Encoding:"
5612                             "Content-Disposition:"))))
5613             (message-narrow-to-head)
5614             (message-remove-header "MIME-Version")
5615             (goto-char (point-max))
5616             (setq point (point))
5617             (insert (apply 'concat headers))
5618             (widen)
5619             (narrow-to-region point (point-max))
5620             (let ((message-options message-options))
5621               (message-options-set 'message-sender user-mail-address)
5622               (message-options-set 'message-recipients user-mail-address)
5623               (message-options-set 'message-sign-encrypt 'not)
5624               (funcall func))
5625             (goto-char (point-min))
5626             (insert "MIME-Version: 1.0\n")
5627             (widen)
5628             (gnus-summary-edit-article-done
5629              references nil summary-buffer t))
5630           (when gnus-keep-backlog
5631             (gnus-backlog-remove-article
5632              (car gnus-article-current) (cdr gnus-article-current)))
5633           (save-excursion
5634             (when (get-buffer gnus-original-article-buffer)
5635               (set-buffer gnus-original-article-buffer)
5636               (setq gnus-original-article nil)))
5637           (when gnus-use-cache
5638             (gnus-cache-update-article
5639              (car gnus-article-current) (cdr gnus-article-current))))))))
5640
5641 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5642   "The following specs can be used:
5643 %t  The security MIME type
5644 %i  Additional info
5645 %d  Details
5646 %D  Details if button is pressed")
5647
5648 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5649   "The following specs can be used:
5650 %t  The security MIME type
5651 %i  Additional info
5652 %d  Details
5653 %D  Details if button is pressed")
5654
5655 (defvar gnus-mime-security-button-line-format-alist
5656   '((?t gnus-tmp-type ?s)
5657     (?i gnus-tmp-info ?s)
5658     (?d gnus-tmp-details ?s)
5659     (?D gnus-tmp-pressed-details ?s)))
5660
5661 (defvar gnus-mime-security-button-map
5662   (let ((map (make-sparse-keymap)))
5663     (unless (>= (string-to-number emacs-version) 21)
5664       (set-keymap-parent map gnus-article-mode-map))
5665     (define-key map gnus-mouse-2 'gnus-article-push-button)
5666     (define-key map "\r" 'gnus-article-press-button)
5667     map))
5668
5669 (defvar gnus-mime-security-details-buffer nil)
5670
5671 (defvar gnus-mime-security-button-pressed nil)
5672
5673 (defvar gnus-mime-security-show-details-inline t
5674   "If non-nil, show details in the article buffer.")
5675
5676 (defun gnus-mime-security-verify-or-decrypt (handle)
5677   (mm-remove-parts (cdr handle))
5678   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5679         point buffer-read-only)
5680     (if region
5681         (goto-char (car region)))
5682     (save-restriction
5683       (narrow-to-region (point) (point))
5684       (with-current-buffer (mm-handle-multipart-original-buffer handle)
5685         (let* ((mm-verify-option 'known)
5686                (mm-decrypt-option 'known)
5687                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5688           (unless (eq nparts (cdr handle))
5689             (mm-destroy-parts (cdr handle))
5690             (setcdr handle nparts))))
5691       (setq point (point))
5692       (gnus-mime-display-security handle)
5693       (goto-char (point-max)))
5694     (when region
5695       (delete-region (point) (cdr region))
5696       (set-marker (car region) nil)
5697       (set-marker (cdr region) nil))
5698     (goto-char point)))
5699
5700 (defun gnus-mime-security-show-details (handle)
5701   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5702     (if details
5703         (if gnus-mime-security-show-details-inline
5704             (let ((gnus-mime-security-button-pressed t)
5705                   (gnus-mime-security-button-line-format
5706                    (get-text-property (point) 'gnus-line-format))
5707                 buffer-read-only)
5708               (forward-char -1)
5709               (while (eq (get-text-property (point) 'gnus-line-format)
5710                          gnus-mime-security-button-line-format)
5711                 (forward-char -1))
5712               (forward-char)
5713               (save-restriction
5714                 (narrow-to-region (point) (point))
5715                 (gnus-insert-mime-security-button handle))
5716               (delete-region (point)
5717                              (or (text-property-not-all
5718                                   (point) (point-max)
5719                                   'gnus-line-format
5720                                   gnus-mime-security-button-line-format)
5721                                  (point-max))))
5722           (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5723               (with-current-buffer gnus-mime-security-details-buffer
5724                 (erase-buffer)
5725                 t)
5726             (setq gnus-mime-security-details-buffer
5727                   (gnus-get-buffer-create "*MIME Security Details*")))
5728           (with-current-buffer gnus-mime-security-details-buffer
5729             (insert details)
5730             (goto-char (point-min)))
5731           (pop-to-buffer gnus-mime-security-details-buffer))
5732       (gnus-message 5 "No details."))))
5733
5734 (defun gnus-mime-security-press-button (handle)
5735   (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5736       (gnus-mime-security-show-details handle)
5737     (gnus-mime-security-verify-or-decrypt handle)))
5738
5739 (defun gnus-insert-mime-security-button (handle &optional displayed)
5740   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5741          (gnus-tmp-type
5742           (concat
5743            (or (nth 2 (assoc protocol mm-verify-function-alist))
5744                (nth 2 (assoc protocol mm-decrypt-function-alist))
5745                "Unknown")
5746            (if (equal (car handle) "multipart/signed")
5747                " Signed" " Encrypted")
5748            " Part"))
5749          (gnus-tmp-info
5750           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5751               "Undecided"))
5752          (gnus-tmp-details
5753           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5754          gnus-tmp-pressed-details
5755          b e)
5756     (setq gnus-tmp-details
5757           (if gnus-tmp-details
5758               (concat "\n" gnus-tmp-details) ""))
5759     (setq gnus-tmp-pressed-details
5760           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5761     (unless (bolp)
5762       (insert "\n"))
5763     (setq b (point))
5764     (gnus-eval-format
5765      gnus-mime-security-button-line-format
5766      gnus-mime-security-button-line-format-alist
5767      `(keymap ,gnus-mime-security-button-map
5768               ,@(if (>= (string-to-number emacs-version) 21)
5769                     nil ;; XEmacs doesn't care
5770                   (list 'local-map gnus-mime-security-button-map))
5771               gnus-callback gnus-mime-security-press-button
5772               gnus-line-format ,gnus-mime-security-button-line-format
5773               article-type annotation
5774               gnus-data ,handle))
5775     (setq e (point))
5776     (widget-convert-button
5777      'link b e
5778      :mime-handle handle
5779      :action 'gnus-widget-press-button
5780      :button-keymap gnus-mime-security-button-map
5781      :help-echo
5782      (lambda (widget/window &optional overlay pos)
5783        ;; Needed to properly clear the message due to a bug in
5784        ;; wid-edit (XEmacs only).
5785        (if (boundp 'help-echo-owns-message)
5786            (setq help-echo-owns-message t))
5787        (format
5788         "%S: show detail"
5789         (aref gnus-mouse-2 0))))))
5790
5791 (defun gnus-mime-display-security (handle)
5792   (save-restriction
5793     (narrow-to-region (point) (point))
5794     (unless (gnus-unbuttonized-mime-type-p (car handle))
5795       (gnus-insert-mime-security-button handle))
5796     (gnus-mime-display-mixed (cdr handle))
5797     (unless (bolp)
5798       (insert "\n"))
5799     (unless (gnus-unbuttonized-mime-type-p (car handle))
5800       (let ((gnus-mime-security-button-line-format
5801              gnus-mime-security-button-end-line-format))
5802         (gnus-insert-mime-security-button handle)))
5803     (mm-set-handle-multipart-parameter
5804      handle 'gnus-region
5805      (cons (set-marker (make-marker) (point-min))
5806            (set-marker (make-marker) (point-max))))))
5807
5808 (defun gnus-article-goto-header (header)
5809   (re-search-forward (concat "^" header ":") nil t))
5810
5811 (gnus-ems-redefine)
5812
5813 (provide 'gnus-art)
5814
5815 (run-hooks 'gnus-art-load-hook)
5816
5817 ;;; gnus-art.el ends here