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