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