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