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