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