0608dffd27d3d95de2b2433d9a7f8bc14e1559ba
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is t, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const :tag "on" t)
79                  (const some)
80                  (const invisible)
81                  number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-refer-thread-limit 200
85   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
86 If t, fetch all the available old headers."
87   :group 'gnus-thread
88   :type '(choice number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-summary-make-false-root 'adopt
92   "*nil means that Gnus won't gather loose threads.
93 If the root of a thread has expired or been read in a previous
94 session, the information necessary to build a complete thread has been
95 lost.  Instead of having many small sub-threads from this original thread
96 scattered all over the summary buffer, Gnus can gather them.
97
98 If non-nil, Gnus will try to gather all loose sub-threads from an
99 original thread into one large thread.
100
101 If this variable is non-nil, it should be one of `none', `adopt',
102 `dummy' or `empty'.
103
104 If this variable is `none', Gnus will not make a false root, but just
105 present the sub-threads after another.
106 If this variable is `dummy', Gnus will create a dummy root that will
107 have all the sub-threads as children.
108 If this variable is `adopt', Gnus will make one of the \"children\"
109 the parent and mark all the step-children as such.
110 If this variable is `empty', the \"children\" are printed with empty
111 subject fields.  (Or rather, they will be printed with a string
112 given by the `gnus-summary-same-subject' variable.)"
113   :group 'gnus-thread
114   :type '(choice (const :tag "off" nil)
115                  (const none)
116                  (const dummy)
117                  (const adopt)
118                  (const empty)))
119
120 (defcustom gnus-summary-make-false-root-always nil
121   "Always make a false dummy root."
122   :version "21.4"
123   :group 'gnus-thread
124   :type 'boolean)
125
126 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
127   "*A regexp to match subjects to be excluded from loose thread gathering.
128 As loose thread gathering is done on subjects only, that means that
129 there can be many false gatherings performed.  By rooting out certain
130 common subjects, gathering might become saner."
131   :group 'gnus-thread
132   :type 'regexp)
133
134 (defcustom gnus-summary-gather-subject-limit nil
135   "*Maximum length of subject comparisons when gathering loose threads.
136 Use nil to compare full subjects.  Setting this variable to a low
137 number will help gather threads that have been corrupted by
138 newsreaders chopping off subject lines, but it might also mean that
139 unrelated articles that have subject that happen to begin with the
140 same few characters will be incorrectly gathered.
141
142 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
143 comparing subjects."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  (const fuzzy)
147                  (sexp :menu-tag "on" t)))
148
149 (defcustom gnus-simplify-subject-functions nil
150   "List of functions taking a string argument that simplify subjects.
151 The functions are applied recursively.
152
153 Useful functions to put in this list include:
154 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
155 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
156   :group 'gnus-thread
157   :type '(repeat function))
158
159 (defcustom gnus-simplify-ignored-prefixes nil
160   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
161   :group 'gnus-thread
162   :type '(choice (const :tag "off" nil)
163                  regexp))
164
165 (defcustom gnus-build-sparse-threads nil
166   "*If non-nil, fill in the gaps in threads.
167 If `some', only fill in the gaps that are needed to tie loose threads
168 together.  If `more', fill in all leaf nodes that Gnus can find.  If
169 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  (const some)
173                  (const more)
174                  (sexp :menu-tag "all" t)))
175
176 (defcustom gnus-summary-thread-gathering-function
177   'gnus-gather-threads-by-subject
178   "*Function used for gathering loose threads.
179 There are two pre-defined functions: `gnus-gather-threads-by-subject',
180 which only takes Subjects into consideration; and
181 `gnus-gather-threads-by-references', which compared the References
182 headers of the articles to find matches."
183   :group 'gnus-thread
184   :type '(radio (function-item gnus-gather-threads-by-subject)
185                 (function-item gnus-gather-threads-by-references)
186                 (function :tag "other")))
187
188 (defcustom gnus-summary-same-subject ""
189   "*String indicating that the current article has the same subject as the previous.
190 This variable will only be used if the value of
191 `gnus-summary-make-false-root' is `empty'."
192   :group 'gnus-summary-format
193   :type 'string)
194
195 (defcustom gnus-summary-goto-unread t
196   "*If t, many commands will go to the next unread article.
197 This applies to marking commands as well as other commands that
198 \"naturally\" select the next article, like, for instance, `SPC' at
199 the end of an article.
200
201 If nil, the marking commands do NOT go to the next unread article
202 \(they go to the next article instead).  If `never', commands that
203 usually go to the next unread article, will go to the next article,
204 whether it is read or not."
205   :group 'gnus-summary-marks
206   :link '(custom-manual "(gnus)Setting Marks")
207   :type '(choice (const :tag "off" nil)
208                  (const never)
209                  (sexp :menu-tag "on" t)))
210
211 (defcustom gnus-summary-default-score 0
212   "*Default article score level.
213 All scores generated by the score files will be added to this score.
214 If this variable is nil, scoring will be disabled."
215   :group 'gnus-score-default
216   :type '(choice (const :tag "disable")
217                  integer))
218
219 (defcustom gnus-summary-default-high-score 0
220   "*Default threshold for a high scored article.
221 An article will be highlighted as high scored if its score is greater
222 than this score."
223   :version "21.4"
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-default-low-score 0
228   "*Default threshold for a low scored article.
229 An article will be highlighted as low scored if its score is smaller
230 than this score."
231   :version "21.4"
232   :group 'gnus-score-default
233   :type 'integer)
234
235 (defcustom gnus-summary-zcore-fuzz 0
236   "*Fuzziness factor for the zcore in the summary buffer.
237 Articles with scores closer than this to `gnus-summary-default-score'
238 will not be marked."
239   :group 'gnus-summary-format
240   :type 'integer)
241
242 (defcustom gnus-simplify-subject-fuzzy-regexp nil
243   "*Strings to be removed when doing fuzzy matches.
244 This can either be a regular expression or list of regular expressions
245 that will be removed from subject strings if fuzzy subject
246 simplification is selected."
247   :group 'gnus-thread
248   :type '(repeat regexp))
249
250 (defcustom gnus-show-threads t
251   "*If non-nil, display threads in summary mode."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-subtree nil
256   "*If non-nil, hide all threads initially.
257 This can be a predicate specifier which says which threads to hide.
258 If threads are hidden, you have to run the command
259 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
260 to expose hidden threads."
261   :group 'gnus-thread
262   :type '(radio (sexp :format "Non-nil\n"
263                       :match (lambda (widget value)
264                                (not (or (consp value) (functionp value))))
265                       :value t)
266                 (const nil)
267                 (sexp :tag "Predicate specifier")))
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :version "21.4"
328   :group 'gnus-group-select
329   :type '(choice (const best)
330                  (const unread)
331                  (const first)
332                  (const unseen)
333                  (const unseen-or-unread)))
334
335 (defcustom gnus-auto-select-next t
336   "*If non-nil, offer to go to the next group from the end of the previous.
337 If the value is t and the next newsgroup is empty, Gnus will exit
338 summary mode and go back to group mode.  If the value is neither nil
339 nor t, Gnus will select the following unread newsgroup.  In
340 particular, if the value is the symbol `quietly', the next unread
341 newsgroup will be selected without any confirmation, and if it is
342 `almost-quietly', the next group will be selected without any
343 confirmation if you are located on the last article in the group.
344 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
345 will go to the next group without confirmation."
346   :group 'gnus-summary-maneuvering
347   :type '(choice (const :tag "off" nil)
348                  (const quietly)
349                  (const almost-quietly)
350                  (const slightly-quietly)
351                  (sexp :menu-tag "on" t)))
352
353 (defcustom gnus-auto-select-same nil
354   "*If non-nil, select the next article with the same subject.
355 If there are no more articles with the same subject, go to
356 the first unread article."
357   :group 'gnus-summary-maneuvering
358   :type 'boolean)
359
360 (defcustom gnus-auto-goto-ignores 'unfetched
361   "*Says how to handle unfetched articles when maneuvering.
362
363 This variable can either be the symbols nil (maneuver to any
364 article), `undownloaded' (maneuvering while unplugged ignores articles
365 that have not been fetched), `always-undownloaded' (maneuvering always
366 ignores articles that have not been fetched), `unfetched' (maneuvering
367 ignores articles whose headers have not been fetched).
368
369 NOTE: The list of unfetched articles will always be nil when plugged
370 and, when unplugged, a subset of the undownloaded article list."
371   :version "21.4"
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "None" nil)
374                  (const :tag "Undownloaded when unplugged" undownloaded)
375                  (const :tag "Undownloaded" always-undownloaded)
376                  (const :tag "Unfetched" unfetched)))
377
378 (defcustom gnus-summary-check-current nil
379   "*If non-nil, consider the current article when moving.
380 The \"unread\" movement commands will stay on the same line if the
381 current article is unread."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-center-summary 2
386   "*If non-nil, always center the current summary buffer.
387 In particular, if `vertical' do only vertical recentering.  If non-nil
388 and non-`vertical', do both horizontal and vertical recentering."
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "none" nil)
391                  (const vertical)
392                  (integer :tag "height")
393                  (sexp :menu-tag "both" t)))
394
395 (defvar gnus-auto-center-group t
396   "*If non-nil, always center the group buffer.")
397
398 (defcustom gnus-show-all-headers nil
399   "*If non-nil, don't hide any headers."
400   :group 'gnus-article-hiding
401   :group 'gnus-article-headers
402   :type 'boolean)
403
404 (defcustom gnus-summary-ignore-duplicates nil
405   "*If non-nil, ignore articles with identical Message-ID headers."
406   :group 'gnus-summary
407   :type 'boolean)
408
409 (defcustom gnus-single-article-buffer t
410   "*If non-nil, display all articles in the same buffer.
411 If nil, each group will get its own article buffer."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-break-pages t
416   "*If non-nil, do page breaking on articles.
417 The page delimiter is specified by the `gnus-page-delimiter'
418 variable."
419   :group 'gnus-article-various
420   :type 'boolean)
421
422 (defcustom gnus-move-split-methods nil
423   "*Variable used to suggest where articles are to be moved to.
424 It uses the same syntax as the `gnus-split-methods' variable.
425 However, whereas `gnus-split-methods' specifies file names as targets,
426 this variable specifies group names."
427   :group 'gnus-summary-mail
428   :type '(repeat (choice (list :value (fun) function)
429                          (cons :value ("" "") regexp (repeat string))
430                          (sexp :value nil))))
431
432 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
433   "Function used to compute default prefix for article move/copy/etc prompts.
434 The function should take one argument, a group name, and return a
435 string with the suggested prefix."
436   :group 'gnus-summary-mail
437   :type 'function)
438
439 ;; FIXME: Although the custom type is `character' for the following variables,
440 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
441
442 (defcustom gnus-unread-mark ?           ;Whitespace
443   "*Mark used for unread articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-ticked-mark ?!
448   "*Mark used for ticked articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-dormant-mark ??
453   "*Mark used for dormant articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-del-mark ?r
458   "*Mark used for del'd articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-read-mark ?R
463   "*Mark used for read articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-expirable-mark ?E
468   "*Mark used for expirable articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-killed-mark ?K
473   "*Mark used for killed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-spam-mark ?$
478   "*Mark used for spam articles."
479   :version "21.4"
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :version "21.4"
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-recent-mark ?N
515   "*Mark used for articles that are recent."
516   :version "21.4"
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :version "21.4"
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-no-mark ?               ;Whitespace
537   "*Mark used for articles that have no other secondary mark."
538   :version "21.4"
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-ancient-mark ?O
543   "*Mark used for ancient articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-sparse-mark ?Q
548   "*Mark used for sparsely reffed articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-canceled-mark ?G
553   "*Mark used for canceled articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-duplicate-mark ?M
558   "*Mark used for duplicate articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-undownloaded-mark ?-
563   "*Mark used for articles that weren't downloaded."
564   :version "21.4"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?     ;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defun gnus-widget-reversible-match (widget value)
699   "Ignoring WIDGET, convert VALUE to internal form.
700 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
701   ;; (debug value)
702   (or (symbolp value)
703       (and (listp value)
704            (eq (length value) 2)
705            (eq (nth 0 value) 'not)
706            (symbolp (nth 1 value)))))
707
708 (defun gnus-widget-reversible-to-internal (widget value)
709   "Ignoring WIDGET, convert VALUE to internal form.
710 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
711 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
712   ;; (debug value)
713   (if (atom value)
714       (list value nil)
715     (list (nth 1 value) t)))
716
717 (defun gnus-widget-reversible-to-external (widget value)
718   "Ignoring WIDGET, convert VALUE to external form.
719 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
720 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
721   ;; (debug value)
722   (if (nth 1 value)
723       (list 'not (nth 0 value))
724     (nth 0 value)))
725
726 (define-widget 'gnus-widget-reversible 'group
727   "A `group' that convert values."
728   :match 'gnus-widget-reversible-match
729   :value-to-internal 'gnus-widget-reversible-to-internal
730   :value-to-external 'gnus-widget-reversible-to-external)
731
732 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
733   "*List of functions used for sorting articles in the summary buffer.
734
735 Each function takes two articles and returns non-nil if the first
736 article should be sorted before the other.  If you use more than one
737 function, the primary sort function should be the last.  You should
738 probably always include `gnus-article-sort-by-number' in the list of
739 sorting functions -- preferably first.  Also note that sorting by date
740 is often much slower than sorting by number, and the sorting order is
741 very similar.  (Sorting by date means sorting by the time the message
742 was sent, sorting by number means sorting by arrival time.)
743
744 Each item can also be a list `(not F)' where F is a function;
745 this reverses the sort order.
746
747 Ready-made functions include `gnus-article-sort-by-number',
748 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
749 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
750 and `gnus-article-sort-by-score'.
751
752 When threading is turned on, the variable `gnus-thread-sort-functions'
753 controls how articles are sorted."
754   :group 'gnus-summary-sort
755   :type '(repeat (gnus-widget-reversible
756                   (choice (function-item gnus-article-sort-by-number)
757                           (function-item gnus-article-sort-by-author)
758                           (function-item gnus-article-sort-by-subject)
759                           (function-item gnus-article-sort-by-date)
760                           (function-item gnus-article-sort-by-score)
761                           (function-item gnus-article-sort-by-random)
762                           (function :tag "other"))
763                   (boolean :tag "Reverse order"))))
764
765
766 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
767   "*List of functions used for sorting threads in the summary buffer.
768 By default, threads are sorted by article number.
769
770 Each function takes two threads and returns non-nil if the first
771 thread should be sorted before the other.  If you use more than one
772 function, the primary sort function should be the last.  You should
773 probably always include `gnus-thread-sort-by-number' in the list of
774 sorting functions -- preferably first.  Also note that sorting by date
775 is often much slower than sorting by number, and the sorting order is
776 very similar.  (Sorting by date means sorting by the time the message
777 was sent, sorting by number means sorting by arrival time.)
778
779 Each list item can also be a list `(not F)' where F is a
780 function; this specifies reversed sort order.
781
782 Ready-made functions include `gnus-thread-sort-by-number',
783 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
784 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
785 `gnus-thread-sort-by-most-recent-number',
786 `gnus-thread-sort-by-most-recent-date',
787 `gnus-thread-sort-by-random', and
788 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
789
790 When threading is turned off, the variable
791 `gnus-article-sort-functions' controls how articles are sorted."
792   :group 'gnus-summary-sort
793   :type '(repeat 
794           (gnus-widget-reversible
795            (choice (function-item gnus-thread-sort-by-number)
796                    (function-item gnus-thread-sort-by-author)
797                    (function-item gnus-thread-sort-by-subject)
798                    (function-item gnus-thread-sort-by-date)
799                    (function-item gnus-thread-sort-by-score)
800                    (function-item gnus-thread-sort-by-most-recent-number)
801                    (function-item gnus-thread-sort-by-most-recent-date)
802                    (function-item gnus-thread-sort-by-random)
803                    (function-item gnus-thread-sort-by-total-score)
804                    (function :tag "other"))
805            (boolean :tag "Reverse order"))))
806
807 (defcustom gnus-thread-score-function '+
808   "*Function used for calculating the total score of a thread.
809
810 The function is called with the scores of the article and each
811 subthread and should then return the score of the thread.
812
813 Some functions you can use are `+', `max', or `min'."
814   :group 'gnus-summary-sort
815   :type 'function)
816
817 (defcustom gnus-summary-expunge-below nil
818   "All articles that have a score less than this variable will be expunged.
819 This variable is local to the summary buffers."
820   :group 'gnus-score-default
821   :type '(choice (const :tag "off" nil)
822                  integer))
823
824 (defcustom gnus-thread-expunge-below nil
825   "All threads that have a total score less than this variable will be expunged.
826 See `gnus-thread-score-function' for en explanation of what a
827 \"thread score\" is.
828
829 This variable is local to the summary buffers."
830   :group 'gnus-threading
831   :group 'gnus-score-default
832   :type '(choice (const :tag "off" nil)
833                  integer))
834
835 (defcustom gnus-summary-mode-hook nil
836   "*A hook for Gnus summary mode.
837 This hook is run before any variables are set in the summary buffer."
838   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
839   :group 'gnus-summary-various
840   :type 'hook)
841
842 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
843 (when (featurep 'xemacs)
844   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
846   (add-hook 'gnus-summary-mode-hook
847             'gnus-xmas-switch-horizontal-scrollbar-off))
848
849 (defcustom gnus-summary-menu-hook nil
850   "*Hook run after the creation of the summary mode menu."
851   :group 'gnus-summary-visual
852   :type 'hook)
853
854 (defcustom gnus-summary-exit-hook nil
855   "*A hook called on exit from the summary buffer.
856 It will be called with point in the group buffer."
857   :group 'gnus-summary-exit
858   :type 'hook)
859
860 (defcustom gnus-summary-prepare-hook nil
861   "*A hook called after the summary buffer has been generated.
862 If you want to modify the summary buffer, you can use this hook."
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 (defcustom gnus-summary-prepared-hook nil
867   "*A hook called as the last thing after the summary buffer has been generated."
868   :group 'gnus-summary-various
869   :type 'hook)
870
871 (defcustom gnus-summary-generate-hook nil
872   "*A hook run just before generating the summary buffer.
873 This hook is commonly used to customize threading variables and the
874 like."
875   :group 'gnus-summary-various
876   :type 'hook)
877
878 (defcustom gnus-select-group-hook nil
879   "*A hook called when a newsgroup is selected.
880
881 If you'd like to simplify subjects like the
882 `gnus-summary-next-same-subject' command does, you can use the
883 following hook:
884
885  (add-hook gnus-select-group-hook
886            (lambda ()
887              (mapcar (lambda (header)
888                        (mail-header-set-subject
889                         header
890                         (gnus-simplify-subject
891                          (mail-header-subject header) 're-only)))
892                      gnus-newsgroup-headers)))"
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-select-article-hook nil
897   "*A hook called when an article is selected."
898   :group 'gnus-summary-choose
899   :options '(gnus-agent-fetch-selected-article)
900   :type 'hook)
901
902 (defcustom gnus-visual-mark-article-hook
903   (list 'gnus-highlight-selected-summary)
904   "*Hook run after selecting an article in the summary buffer.
905 It is meant to be used for highlighting the article in some way.  It
906 is not run if `gnus-visual' is nil."
907   :group 'gnus-summary-visual
908   :type 'hook)
909
910 (defcustom gnus-parse-headers-hook nil
911   "*A hook called before parsing the headers."
912   :group 'gnus-various
913   :type 'hook)
914
915 (defcustom gnus-exit-group-hook nil
916   "*A hook called when exiting summary mode.
917 This hook is not called from the non-updating exit commands like `Q'."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-summary-update-hook
922   (list 'gnus-summary-highlight-line)
923   "*A hook called when a summary line is changed.
924 The hook will not be called if `gnus-visual' is nil.
925
926 The default function `gnus-summary-highlight-line' will
927 highlight the line according to the `gnus-summary-highlight'
928 variable."
929   :group 'gnus-summary-visual
930   :type 'hook)
931
932 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
933   "*A hook called when an article is selected for the first time.
934 The hook is intended to mark an article as read (or unread)
935 automatically when it is selected."
936   :group 'gnus-summary-choose
937   :type 'hook)
938
939 (defcustom gnus-group-no-more-groups-hook nil
940   "*A hook run when returning to group mode having no more (unread) groups."
941   :group 'gnus-group-select
942   :type 'hook)
943
944 (defcustom gnus-ps-print-hook nil
945   "*A hook run before ps-printing something from Gnus."
946   :group 'gnus-summary
947   :type 'hook)
948
949 (defcustom gnus-summary-article-move-hook nil
950   "*A hook called after an article is moved, copied, respooled, or crossposted."
951   :version "21.4"
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-delete-hook nil
956   "*A hook called after an article is deleted."
957   :version "21.4"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-expire-hook nil
962   "*A hook called after an article is expired."
963   :version "21.4"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-display-arrow
968   (and (fboundp 'display-graphic-p)
969        (display-graphic-p))
970   "*If non-nil, display an arrow highlighting the current article."
971   :version "21.4"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
976   "Face used for highlighting the current article in the summary buffer."
977   :group 'gnus-summary-visual
978   :type 'face)
979
980 (defvar gnus-tmp-downloaded nil)
981
982 (defcustom gnus-summary-highlight
983   '(((eq mark gnus-canceled-mark)
984      . gnus-summary-cancelled-face)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded-face)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded-face)
989     (uncached
990      . gnus-summary-normal-undownloaded-face)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked-face)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked-face)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked-face)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient-face)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient-face)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient-face)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread-face)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread-face)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread-face)
1014     ((> score default-high)
1015      . gnus-summary-high-read-face)
1016     ((< score default-low)
1017      . gnus-summary-low-read-face)
1018     (t
1019      . gnus-summary-normal-read-face))
1020   "*Controls the highlighting of summary buffer lines.
1021
1022 A list of (FORM . FACE) pairs.  When deciding how a a particular
1023 summary line should be displayed, each form is evaluated.  The content
1024 of the face field after the first true form is used.  You can change
1025 how those summary lines are displayed, by editing the face field.
1026
1027 You can use the following variables in the FORM field.
1028
1029 score:        The article's score
1030 default:      The default article score.
1031 default-high: The default score for high scored articles.
1032 default-low:  The default score for low scored articles.
1033 below:        The score below which articles are automatically marked as read.
1034 mark:         The article's mark.
1035 uncached:     Non-nil if the article is uncached."
1036   :group 'gnus-summary-visual
1037   :type '(repeat (cons (sexp :tag "Form" nil)
1038                        face)))
1039
1040 (defcustom gnus-alter-header-function nil
1041   "Function called to allow alteration of article header structures.
1042 The function is called with one parameter, the article header vector,
1043 which it may alter in any way."
1044   :type '(choice (const :tag "None" nil)
1045                  function)
1046   :group 'gnus-summary)
1047
1048 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1049   "Variable that says which function should be used to decode a string with encoded words.")
1050
1051 (defcustom gnus-extra-headers '(To Newsgroups)
1052   "*Extra headers to parse."
1053   :version "21.1"
1054   :group 'gnus-summary
1055   :type '(repeat symbol))
1056
1057 (defcustom gnus-ignored-from-addresses
1058   (and user-mail-address (regexp-quote user-mail-address))
1059   "*Regexp of From headers that may be suppressed in favor of To headers."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type 'regexp)
1063
1064 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1065   "List of charsets that should be ignored.
1066 When these charsets are used in the \"charset\" parameter, the
1067 default charset will be used instead."
1068   :version "21.1"
1069   :type '(repeat symbol)
1070   :group 'gnus-charset)
1071
1072 (gnus-define-group-parameter
1073  ignored-charsets
1074  :type list
1075  :function-document
1076  "Return the ignored charsets of GROUP."
1077  :variable gnus-group-ignored-charsets-alist
1078  :variable-default
1079  '(("alt\\.chinese\\.text" iso-8859-1))
1080  :variable-document
1081  "Alist of regexps (to match group names) and charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084  :variable-group gnus-charset
1085  :variable-type '(repeat (cons (regexp :tag "Group")
1086                                (repeat symbol)))
1087  :parameter-type '(choice :tag "Ignored charsets"
1088                           :value nil
1089                           (repeat (symbol)))
1090  :parameter-document       "\
1091 List of charsets that should be ignored.
1092
1093 When these charsets are used in the \"charset\" parameter, the
1094 default charset will be used instead.")
1095
1096 (defcustom gnus-group-highlight-words-alist nil
1097   "Alist of group regexps and highlight regexps.
1098 This variable uses the same syntax as `gnus-emphasis-alist'."
1099   :version "21.1"
1100   :type '(repeat (cons (regexp :tag "Group")
1101                        (repeat (list (regexp :tag "Highlight regexp")
1102                                      (number :tag "Group for entire word" 0)
1103                                      (number :tag "Group for displayed part" 0)
1104                                      (symbol :tag "Face"
1105                                              gnus-emphasis-highlight-words)))))
1106   :group 'gnus-summary-visual)
1107
1108 (defcustom gnus-summary-show-article-charset-alist
1109   nil
1110   "Alist of number and charset.
1111 The article will be shown with the charset corresponding to the
1112 numbered argument.
1113 For example: ((1 . cn-gb-2312) (2 . big5))."
1114   :version "21.1"
1115   :type '(repeat (cons (number :tag "Argument" 1)
1116                        (symbol :tag "Charset")))
1117   :group 'gnus-charset)
1118
1119 (defcustom gnus-preserve-marks t
1120   "Whether marks are preserved when moving, copying and respooling messages."
1121   :version "21.1"
1122   :type 'boolean
1123   :group 'gnus-summary-marks)
1124
1125 (defcustom gnus-alter-articles-to-read-function nil
1126   "Function to be called to alter the list of articles to be selected."
1127   :type '(choice (const nil) function)
1128   :group 'gnus-summary)
1129
1130 (defcustom gnus-orphan-score nil
1131   "*All orphans get this score added.  Set in the score file."
1132   :group 'gnus-score-default
1133   :type '(choice (const nil)
1134                  integer))
1135
1136 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1137   "*A regexp to match MIME parts when saving multiple parts of a
1138 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1139 This regexp will be used by default when prompting the user for which
1140 type of files to save."
1141   :group 'gnus-summary
1142   :type 'regexp)
1143
1144 (defcustom gnus-read-all-available-headers nil
1145   "Whether Gnus should parse all headers made available to it.
1146 This is mostly relevant for slow back ends where the user may
1147 wish to widen the summary buffer to include all headers
1148 that were fetched.  Say, for nnultimate groups."
1149   :version "21.4"
1150   :group 'gnus-summary
1151   :type '(choice boolean regexp))
1152
1153 (defcustom gnus-summary-muttprint-program "muttprint"
1154   "Command (and optional arguments) used to run Muttprint."
1155   :version "21.4"
1156   :group 'gnus-summary
1157   :type 'string)
1158
1159 (defcustom gnus-article-loose-mime t
1160   "If non-nil, don't require MIME-Version header.
1161 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1162 supply the MIME-Version header or deliberately strip it from the mail.
1163 If non-nil (the default), Gnus will treat some articles as MIME
1164 even if the MIME-Version header is missing."
1165   :version "21.4"
1166   :type 'boolean
1167   :group 'gnus-article-mime)
1168
1169 (defcustom gnus-article-emulate-mime t
1170   "If non-nil, use MIME emulation for uuencode and the like.
1171 This means that Gnus will search message bodies for text that look
1172 like uuencoded bits, yEncoded bits, and so on, and present that using
1173 the normal Gnus MIME machinery."
1174   :version "21.4"
1175   :type 'boolean
1176   :group 'gnus-article-mime)
1177
1178 ;;; Internal variables
1179
1180 (defvar gnus-summary-display-cache nil)
1181 (defvar gnus-article-mime-handles nil)
1182 (defvar gnus-article-decoded-p nil)
1183 (defvar gnus-article-charset nil)
1184 (defvar gnus-article-ignored-charsets nil)
1185 (defvar gnus-scores-exclude-files nil)
1186 (defvar gnus-page-broken nil)
1187
1188 (defvar gnus-original-article nil)
1189 (defvar gnus-article-internal-prepare-hook nil)
1190 (defvar gnus-newsgroup-process-stack nil)
1191
1192 (defvar gnus-thread-indent-array nil)
1193 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1194 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1195   "Function called to sort the articles within a thread after it has been gathered together.")
1196
1197 (defvar gnus-summary-save-parts-type-history nil)
1198 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1199
1200 ;; Avoid highlighting in kill files.
1201 (defvar gnus-summary-inhibit-highlight nil)
1202 (defvar gnus-newsgroup-selected-overlay nil)
1203 (defvar gnus-inhibit-limiting nil)
1204 (defvar gnus-newsgroup-adaptive-score-file nil)
1205 (defvar gnus-current-score-file nil)
1206 (defvar gnus-current-move-group nil)
1207 (defvar gnus-current-copy-group nil)
1208 (defvar gnus-current-crosspost-group nil)
1209 (defvar gnus-newsgroup-display nil)
1210
1211 (defvar gnus-newsgroup-dependencies nil)
1212 (defvar gnus-newsgroup-adaptive nil)
1213 (defvar gnus-summary-display-article-function nil)
1214 (defvar gnus-summary-highlight-line-function nil
1215   "Function called after highlighting a summary line.")
1216
1217 (defvar gnus-summary-line-format-alist
1218   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1219     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1220     (?s gnus-tmp-subject-or-nil ?s)
1221     (?n gnus-tmp-name ?s)
1222     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1223         ?s)
1224     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1225             gnus-tmp-from) ?s)
1226     (?F gnus-tmp-from ?s)
1227     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1228     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1229     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1230     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1231     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1232     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1233     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1234     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1235     (?L gnus-tmp-lines ?s)
1236     (?O gnus-tmp-downloaded ?c)
1237     (?I gnus-tmp-indentation ?s)
1238     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1239     (?R gnus-tmp-replied ?c)
1240     (?\[ gnus-tmp-opening-bracket ?c)
1241     (?\] gnus-tmp-closing-bracket ?c)
1242     (?\> (make-string gnus-tmp-level ? ) ?s)
1243     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1244     (?i gnus-tmp-score ?d)
1245     (?z gnus-tmp-score-char ?c)
1246     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1247     (?U gnus-tmp-unread ?c)
1248     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1249         ?s)
1250     (?t (gnus-summary-number-of-articles-in-thread
1251          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1252         ?d)
1253     (?e (gnus-summary-number-of-articles-in-thread
1254          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1255         ?c)
1256     (?u gnus-tmp-user-defined ?s)
1257     (?P (gnus-pick-line-number) ?d)
1258     (?B gnus-tmp-thread-tree-header-string ?s)
1259     (user-date (gnus-user-date
1260                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1261   "An alist of format specifications that can appear in summary lines.
1262 These are paired with what variables they correspond with, along with
1263 the type of the variable (string, integer, character, etc).")
1264
1265 (defvar gnus-summary-dummy-line-format-alist
1266   `((?S gnus-tmp-subject ?s)
1267     (?N gnus-tmp-number ?d)
1268     (?u gnus-tmp-user-defined ?s)))
1269
1270 (defvar gnus-summary-mode-line-format-alist
1271   `((?G gnus-tmp-group-name ?s)
1272     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1273     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1274     (?A gnus-tmp-article-number ?d)
1275     (?Z gnus-tmp-unread-and-unselected ?s)
1276     (?V gnus-version ?s)
1277     (?U gnus-tmp-unread-and-unticked ?d)
1278     (?S gnus-tmp-subject ?s)
1279     (?e gnus-tmp-unselected ?d)
1280     (?u gnus-tmp-user-defined ?s)
1281     (?d (length gnus-newsgroup-dormant) ?d)
1282     (?t (length gnus-newsgroup-marked) ?d)
1283     (?h (length gnus-newsgroup-spam-marked) ?d)
1284     (?r (length gnus-newsgroup-reads) ?d)
1285     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1286     (?E gnus-newsgroup-expunged-tally ?d)
1287     (?s (gnus-current-score-file-nondirectory) ?s)))
1288
1289 (defvar gnus-last-search-regexp nil
1290   "Default regexp for article search command.")
1291
1292 (defvar gnus-last-shell-command nil
1293   "Default shell command on article.")
1294
1295 (defvar gnus-newsgroup-agentized nil
1296   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1297 (defvar gnus-newsgroup-begin nil)
1298 (defvar gnus-newsgroup-end nil)
1299 (defvar gnus-newsgroup-last-rmail nil)
1300 (defvar gnus-newsgroup-last-mail nil)
1301 (defvar gnus-newsgroup-last-folder nil)
1302 (defvar gnus-newsgroup-last-file nil)
1303 (defvar gnus-newsgroup-auto-expire nil)
1304 (defvar gnus-newsgroup-active nil)
1305
1306 (defvar gnus-newsgroup-data nil)
1307 (defvar gnus-newsgroup-data-reverse nil)
1308 (defvar gnus-newsgroup-limit nil)
1309 (defvar gnus-newsgroup-limits nil)
1310 (defvar gnus-summary-use-undownloaded-faces nil)
1311
1312 (defvar gnus-newsgroup-unreads nil
1313   "Sorted list of unread articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-unselected nil
1316   "Sorted list of unselected unread articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-reads nil
1319   "Alist of read articles and article marks in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-expunged-tally nil)
1322
1323 (defvar gnus-newsgroup-marked nil
1324   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1325
1326 (defvar gnus-newsgroup-spam-marked nil
1327   "List of ranges of articles that have been marked as spam.")
1328
1329 (defvar gnus-newsgroup-killed nil
1330   "List of ranges of articles that have been through the scoring process.")
1331
1332 (defvar gnus-newsgroup-cached nil
1333   "Sorted list of articles that come from the article cache.")
1334
1335 (defvar gnus-newsgroup-saved nil
1336   "List of articles that have been saved.")
1337
1338 (defvar gnus-newsgroup-kill-headers nil)
1339
1340 (defvar gnus-newsgroup-replied nil
1341   "List of articles that have been replied to in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-forwarded nil
1344   "List of articles that have been forwarded in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-recent nil
1347   "List of articles that have are recent in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-expirable nil
1350   "Sorted list of articles in the current newsgroup that can be expired.")
1351
1352 (defvar gnus-newsgroup-processable nil
1353   "List of articles in the current newsgroup that can be processed.")
1354
1355 (defvar gnus-newsgroup-downloadable nil
1356   "Sorted list of articles in the current newsgroup that can be processed.")
1357
1358 (defvar gnus-newsgroup-unfetched nil
1359   "Sorted list of articles in the current newsgroup whose headers have
1360 not been fetched into the agent.
1361
1362 This list will always be a subset of gnus-newsgroup-undownloaded.")
1363
1364 (defvar gnus-newsgroup-undownloaded nil
1365   "List of articles in the current newsgroup that haven't been downloaded.")
1366
1367 (defvar gnus-newsgroup-unsendable nil
1368   "List of articles in the current newsgroup that won't be sent.")
1369
1370 (defvar gnus-newsgroup-bookmarks nil
1371   "List of articles in the current newsgroup that have bookmarks.")
1372
1373 (defvar gnus-newsgroup-dormant nil
1374   "Sorted list of dormant articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-unseen nil
1377   "List of unseen articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-seen nil
1380   "Range of seen articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-articles nil
1383   "List of articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-scored nil
1386   "List of scored articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-headers nil
1389   "List of article headers in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-threads nil)
1392
1393 (defvar gnus-newsgroup-prepared nil
1394   "Whether the current group has been prepared properly.")
1395
1396 (defvar gnus-newsgroup-ancient nil
1397   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-sparse nil)
1400
1401 (defvar gnus-current-article nil)
1402 (defvar gnus-article-current nil)
1403 (defvar gnus-current-headers nil)
1404 (defvar gnus-have-all-headers nil)
1405 (defvar gnus-last-article nil)
1406 (defvar gnus-newsgroup-history nil)
1407 (defvar gnus-newsgroup-charset nil)
1408 (defvar gnus-newsgroup-ephemeral-charset nil)
1409 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1410
1411 (defvar gnus-article-before-search nil)
1412
1413 (defvar gnus-summary-local-variables
1414   '(gnus-newsgroup-name
1415     gnus-newsgroup-begin gnus-newsgroup-end
1416     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1417     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1418     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1419     gnus-newsgroup-unselected gnus-newsgroup-marked
1420     gnus-newsgroup-spam-marked
1421     gnus-newsgroup-reads gnus-newsgroup-saved
1422     gnus-newsgroup-replied gnus-newsgroup-forwarded
1423     gnus-newsgroup-recent
1424     gnus-newsgroup-expirable
1425     gnus-newsgroup-processable gnus-newsgroup-killed
1426     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1427     gnus-newsgroup-unfetched
1428     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1429     gnus-newsgroup-seen gnus-newsgroup-articles
1430     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1431     gnus-newsgroup-headers gnus-newsgroup-threads
1432     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1433     gnus-current-article gnus-current-headers gnus-have-all-headers
1434     gnus-last-article gnus-article-internal-prepare-hook
1435     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1436     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1437     gnus-thread-expunge-below
1438     gnus-score-alist gnus-current-score-file
1439     (gnus-summary-expunge-below . global)
1440     (gnus-summary-mark-below . global)
1441     (gnus-orphan-score . global)
1442     gnus-newsgroup-active gnus-scores-exclude-files
1443     gnus-newsgroup-history gnus-newsgroup-ancient
1444     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1445     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1446     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1447     (gnus-newsgroup-expunged-tally . 0)
1448     gnus-cache-removable-articles gnus-newsgroup-cached
1449     gnus-newsgroup-data gnus-newsgroup-data-reverse
1450     gnus-newsgroup-limit gnus-newsgroup-limits
1451     gnus-newsgroup-charset gnus-newsgroup-display
1452     gnus-summary-use-undownloaded-faces)
1453   "Variables that are buffer-local to the summary buffers.")
1454
1455 (defvar gnus-newsgroup-variables nil
1456   "A list of variables that have separate values in different newsgroups.
1457 A list of newsgroup (summary buffer) local variables, or cons of
1458 variables and their default expressions to be evalled (when the default
1459 values are not nil), that should be made global while the summary buffer
1460 is active.
1461
1462 Note: The default expressions will be evaluated (using function `eval')
1463 before assignment to the local variable rather than just assigned to it.
1464 If the default expression is the symbol `global', that symbol will not
1465 be evaluated but the global value of the local variable will be used
1466 instead.
1467
1468 These variables can be used to set variables in the group parameters
1469 while still allowing them to affect operations done in other buffers.
1470 For example:
1471
1472 \(setq gnus-newsgroup-variables
1473      '(message-use-followup-to
1474        (gnus-visible-headers .
1475          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1476 ")
1477
1478 ;; Byte-compiler warning.
1479 (eval-when-compile
1480   ;; Bind features so that require will believe that gnus-sum has
1481   ;; already been loaded (avoids infinite recursion)
1482   (let ((features (cons 'gnus-sum features)))
1483     ;; Several of the declarations in gnus-sum are needed to load the
1484     ;; following files. Right now, these definitions have been
1485     ;; compiled but not defined (evaluated).  We could either do a
1486     ;; eval-and-compile about all of the declarations or evaluate the
1487     ;; source file.
1488     (if (boundp 'gnus-newsgroup-variables)
1489         nil
1490       (load "gnus-sum.el" t t t))
1491     (require 'gnus)
1492     (require 'gnus-art)))
1493
1494 ;; MIME stuff.
1495
1496 (defvar gnus-decode-encoded-word-methods
1497   '(mail-decode-encoded-word-string)
1498   "List of methods used to decode encoded words.
1499
1500 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1501 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1502 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1503 whose names match REGEXP.
1504
1505 For example:
1506 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1507  mail-decode-encoded-word-string
1508  (\"chinese\" . rfc1843-decode-string))")
1509
1510 (defvar gnus-decode-encoded-word-methods-cache nil)
1511
1512 (defun gnus-multi-decode-encoded-word-string (string)
1513   "Apply the functions from `gnus-encoded-word-methods' that match."
1514   (unless (and gnus-decode-encoded-word-methods-cache
1515                (eq gnus-newsgroup-name
1516                    (car gnus-decode-encoded-word-methods-cache)))
1517     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1518     (mapcar (lambda (x)
1519               (if (symbolp x)
1520                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1521                 (if (and gnus-newsgroup-name
1522                          (string-match (car x) gnus-newsgroup-name))
1523                     (nconc gnus-decode-encoded-word-methods-cache
1524                            (list (cdr x))))))
1525             gnus-decode-encoded-word-methods))
1526   (let ((xlist gnus-decode-encoded-word-methods-cache))
1527     (pop xlist)
1528     (while xlist
1529       (setq string (funcall (pop xlist) string))))
1530   string)
1531
1532 ;; Subject simplification.
1533
1534 (defun gnus-simplify-whitespace (str)
1535   "Remove excessive whitespace from STR."
1536   ;; Multiple spaces.
1537   (while (string-match "[ \t][ \t]+" str)
1538     (setq str (concat (substring str 0 (match-beginning 0))
1539                         " "
1540                         (substring str (match-end 0)))))
1541   ;; Leading spaces.
1542   (when (string-match "^[ \t]+" str)
1543     (setq str (substring str (match-end 0))))
1544   ;; Trailing spaces.
1545   (when (string-match "[ \t]+$" str)
1546     (setq str (substring str 0 (match-beginning 0))))
1547   str)
1548
1549 (defun gnus-simplify-all-whitespace (str)
1550   "Remove all whitespace from STR."
1551   (while (string-match "[ \t\n]+" str)
1552     (setq str (replace-match "" nil nil str)))
1553   str)
1554
1555 (defsubst gnus-simplify-subject-re (subject)
1556   "Remove \"Re:\" from subject lines."
1557   (if (string-match message-subject-re-regexp subject)
1558       (substring subject (match-end 0))
1559     subject))
1560
1561 (defun gnus-simplify-subject (subject &optional re-only)
1562   "Remove `Re:' and words in parentheses.
1563 If RE-ONLY is non-nil, strip leading `Re:'s only."
1564   (let ((case-fold-search t))           ;Ignore case.
1565     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1566     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1567       (setq subject (substring subject (match-end 0))))
1568     ;; Remove uninteresting prefixes.
1569     (when (and (not re-only)
1570                gnus-simplify-ignored-prefixes
1571                (string-match gnus-simplify-ignored-prefixes subject))
1572       (setq subject (substring subject (match-end 0))))
1573     ;; Remove words in parentheses from end.
1574     (unless re-only
1575       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1576         (setq subject (substring subject 0 (match-beginning 0)))))
1577     ;; Return subject string.
1578     subject))
1579
1580 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1581 ;; all whitespace.
1582 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1583   (goto-char (point-min))
1584   (while (re-search-forward regexp nil t)
1585     (replace-match (or newtext ""))))
1586
1587 (defun gnus-simplify-buffer-fuzzy ()
1588   "Simplify string in the buffer fuzzily.
1589 The string in the accessible portion of the current buffer is simplified.
1590 It is assumed to be a single-line subject.
1591 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1592 matter is removed.  Additional things can be deleted by setting
1593 `gnus-simplify-subject-fuzzy-regexp'."
1594   (let ((case-fold-search t)
1595         (modified-tick))
1596     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1597
1598     (while (not (eq modified-tick (buffer-modified-tick)))
1599       (setq modified-tick (buffer-modified-tick))
1600       (cond
1601        ((listp gnus-simplify-subject-fuzzy-regexp)
1602         (mapcar 'gnus-simplify-buffer-fuzzy-step
1603                 gnus-simplify-subject-fuzzy-regexp))
1604        (gnus-simplify-subject-fuzzy-regexp
1605         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1606       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1607       (gnus-simplify-buffer-fuzzy-step
1608        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1609       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1610
1611     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1612     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1613     (gnus-simplify-buffer-fuzzy-step " $")
1614     (gnus-simplify-buffer-fuzzy-step "^ +")))
1615
1616 (defun gnus-simplify-subject-fuzzy (subject)
1617   "Simplify a subject string fuzzily.
1618 See `gnus-simplify-buffer-fuzzy' for details."
1619   (save-excursion
1620     (gnus-set-work-buffer)
1621     (let ((case-fold-search t))
1622       ;; Remove uninteresting prefixes.
1623       (when (and gnus-simplify-ignored-prefixes
1624                  (string-match gnus-simplify-ignored-prefixes subject))
1625         (setq subject (substring subject (match-end 0))))
1626       (insert subject)
1627       (inline (gnus-simplify-buffer-fuzzy))
1628       (buffer-string))))
1629
1630 (defsubst gnus-simplify-subject-fully (subject)
1631   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1632   (cond
1633    (gnus-simplify-subject-functions
1634     (gnus-map-function gnus-simplify-subject-functions subject))
1635    ((null gnus-summary-gather-subject-limit)
1636     (gnus-simplify-subject-re subject))
1637    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1638     (gnus-simplify-subject-fuzzy subject))
1639    ((numberp gnus-summary-gather-subject-limit)
1640     (gnus-limit-string (gnus-simplify-subject-re subject)
1641                        gnus-summary-gather-subject-limit))
1642    (t
1643     subject)))
1644
1645 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1646   "Check whether two subjects are equal.
1647 If optional argument SIMPLE-FIRST is t, first argument is already
1648 simplified."
1649   (cond
1650    ((null simple-first)
1651     (equal (gnus-simplify-subject-fully s1)
1652            (gnus-simplify-subject-fully s2)))
1653    (t
1654     (equal s1
1655            (gnus-simplify-subject-fully s2)))))
1656
1657 (defun gnus-summary-bubble-group ()
1658   "Increase the score of the current group.
1659 This is a handy function to add to `gnus-summary-exit-hook' to
1660 increase the score of each group you read."
1661   (gnus-group-add-score gnus-newsgroup-name))
1662
1663 \f
1664 ;;;
1665 ;;; Gnus summary mode
1666 ;;;
1667
1668 (put 'gnus-summary-mode 'mode-class 'special)
1669
1670 (defvar gnus-article-commands-menu)
1671
1672 ;; Non-orthogonal keys
1673
1674 (gnus-define-keys gnus-summary-mode-map
1675   " " gnus-summary-next-page
1676   "\177" gnus-summary-prev-page
1677   [delete] gnus-summary-prev-page
1678   [backspace] gnus-summary-prev-page
1679   "\r" gnus-summary-scroll-up
1680   "\M-\r" gnus-summary-scroll-down
1681   "n" gnus-summary-next-unread-article
1682   "p" gnus-summary-prev-unread-article
1683   "N" gnus-summary-next-article
1684   "P" gnus-summary-prev-article
1685   "\M-\C-n" gnus-summary-next-same-subject
1686   "\M-\C-p" gnus-summary-prev-same-subject
1687   "\M-n" gnus-summary-next-unread-subject
1688   "\M-p" gnus-summary-prev-unread-subject
1689   "." gnus-summary-first-unread-article
1690   "," gnus-summary-best-unread-article
1691   "\M-s" gnus-summary-search-article-forward
1692   "\M-r" gnus-summary-search-article-backward
1693   "<" gnus-summary-beginning-of-article
1694   ">" gnus-summary-end-of-article
1695   "j" gnus-summary-goto-article
1696   "^" gnus-summary-refer-parent-article
1697   "\M-^" gnus-summary-refer-article
1698   "u" gnus-summary-tick-article-forward
1699   "!" gnus-summary-tick-article-forward
1700   "U" gnus-summary-tick-article-backward
1701   "d" gnus-summary-mark-as-read-forward
1702   "D" gnus-summary-mark-as-read-backward
1703   "E" gnus-summary-mark-as-expirable
1704   "\M-u" gnus-summary-clear-mark-forward
1705   "\M-U" gnus-summary-clear-mark-backward
1706   "k" gnus-summary-kill-same-subject-and-select
1707   "\C-k" gnus-summary-kill-same-subject
1708   "\M-\C-k" gnus-summary-kill-thread
1709   "\M-\C-l" gnus-summary-lower-thread
1710   "e" gnus-summary-edit-article
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "\M-\C-t" gnus-summary-toggle-threads
1714   "\M-\C-s" gnus-summary-show-thread
1715   "\M-\C-h" gnus-summary-hide-thread
1716   "\M-\C-f" gnus-summary-next-thread
1717   "\M-\C-b" gnus-summary-prev-thread
1718   [(meta down)] gnus-summary-next-thread
1719   [(meta up)] gnus-summary-prev-thread
1720   "\M-\C-u" gnus-summary-up-thread
1721   "\M-\C-d" gnus-summary-down-thread
1722   "&" gnus-summary-execute-command
1723   "c" gnus-summary-catchup-and-exit
1724   "\C-w" gnus-summary-mark-region-as-read
1725   "\C-t" gnus-summary-toggle-truncation
1726   "?" gnus-summary-mark-as-dormant
1727   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1728   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1729   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1730   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1731   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1732   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1733   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1734   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1735   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1736   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1737   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1738   "=" gnus-summary-expand-window
1739   "\C-x\C-s" gnus-summary-reselect-current-group
1740   "\M-g" gnus-summary-rescan-group
1741   "w" gnus-summary-stop-page-breaking
1742   "\C-c\C-r" gnus-summary-caesar-message
1743   "f" gnus-summary-followup
1744   "F" gnus-summary-followup-with-original
1745   "C" gnus-summary-cancel-article
1746   "r" gnus-summary-reply
1747   "R" gnus-summary-reply-with-original
1748   "\C-c\C-f" gnus-summary-mail-forward
1749   "o" gnus-summary-save-article
1750   "\C-o" gnus-summary-save-article-mail
1751   "|" gnus-summary-pipe-output
1752   "\M-k" gnus-summary-edit-local-kill
1753   "\M-K" gnus-summary-edit-global-kill
1754   ;; "V" gnus-version
1755   "\C-c\C-d" gnus-summary-describe-group
1756   "q" gnus-summary-exit
1757   "Q" gnus-summary-exit-no-update
1758   "\C-c\C-i" gnus-info-find-node
1759   gnus-mouse-2 gnus-mouse-pick-article
1760   [follow-link] mouse-face
1761   "m" gnus-summary-mail-other-window
1762   "a" gnus-summary-post-news
1763   "i" gnus-summary-news-other-window
1764   "x" gnus-summary-limit-to-unread
1765   "s" gnus-summary-isearch-article
1766   "t" gnus-summary-toggle-header
1767   "g" gnus-summary-show-article
1768   "l" gnus-summary-goto-last-article
1769   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1770   "\C-d" gnus-summary-enter-digest-group
1771   "\M-\C-d" gnus-summary-read-document
1772   "\M-\C-e" gnus-summary-edit-parameters
1773   "\M-\C-a" gnus-summary-customize-parameters
1774   "\C-c\C-b" gnus-bug
1775   "*" gnus-cache-enter-article
1776   "\M-*" gnus-cache-remove-article
1777   "\M-&" gnus-summary-universal-argument
1778   "\C-l" gnus-recenter
1779   "I" gnus-summary-increase-score
1780   "L" gnus-summary-lower-score
1781   "\M-i" gnus-symbolic-argument
1782   "h" gnus-summary-select-article-buffer
1783
1784   "b" gnus-article-view-part
1785   "\M-t" gnus-summary-toggle-display-buttonized
1786
1787   "V" gnus-summary-score-map
1788   "X" gnus-uu-extract-map
1789   "S" gnus-summary-send-map)
1790
1791 ;; Sort of orthogonal keymap
1792 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1793   "t" gnus-summary-tick-article-forward
1794   "!" gnus-summary-tick-article-forward
1795   "d" gnus-summary-mark-as-read-forward
1796   "r" gnus-summary-mark-as-read-forward
1797   "c" gnus-summary-clear-mark-forward
1798   " " gnus-summary-clear-mark-forward
1799   "e" gnus-summary-mark-as-expirable
1800   "x" gnus-summary-mark-as-expirable
1801   "?" gnus-summary-mark-as-dormant
1802   "b" gnus-summary-set-bookmark
1803   "B" gnus-summary-remove-bookmark
1804   "#" gnus-summary-mark-as-processable
1805   "\M-#" gnus-summary-unmark-as-processable
1806   "S" gnus-summary-limit-include-expunged
1807   "C" gnus-summary-catchup
1808   "H" gnus-summary-catchup-to-here
1809   "h" gnus-summary-catchup-from-here
1810   "\C-c" gnus-summary-catchup-all
1811   "k" gnus-summary-kill-same-subject-and-select
1812   "K" gnus-summary-kill-same-subject
1813   "P" gnus-uu-mark-map)
1814
1815 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1816   "c" gnus-summary-clear-above
1817   "u" gnus-summary-tick-above
1818   "m" gnus-summary-mark-above
1819   "k" gnus-summary-kill-below)
1820
1821 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1822   "/" gnus-summary-limit-to-subject
1823   "n" gnus-summary-limit-to-articles
1824   "w" gnus-summary-pop-limit
1825   "s" gnus-summary-limit-to-subject
1826   "a" gnus-summary-limit-to-author
1827   "u" gnus-summary-limit-to-unread
1828   "m" gnus-summary-limit-to-marks
1829   "M" gnus-summary-limit-exclude-marks
1830   "v" gnus-summary-limit-to-score
1831   "*" gnus-summary-limit-include-cached
1832   "D" gnus-summary-limit-include-dormant
1833   "T" gnus-summary-limit-include-thread
1834   "d" gnus-summary-limit-exclude-dormant
1835   "t" gnus-summary-limit-to-age
1836   "." gnus-summary-limit-to-unseen
1837   "x" gnus-summary-limit-to-extra
1838   "p" gnus-summary-limit-to-display-predicate
1839   "E" gnus-summary-limit-include-expunged
1840   "c" gnus-summary-limit-exclude-childless-dormant
1841   "C" gnus-summary-limit-mark-excluded-as-read
1842   "o" gnus-summary-insert-old-articles
1843   "N" gnus-summary-insert-new-articles
1844   "r" gnus-summary-limit-to-replied
1845   "R" gnus-summary-limit-to-recipient)
1846
1847 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1848   "n" gnus-summary-next-unread-article
1849   "p" gnus-summary-prev-unread-article
1850   "N" gnus-summary-next-article
1851   "P" gnus-summary-prev-article
1852   "\C-n" gnus-summary-next-same-subject
1853   "\C-p" gnus-summary-prev-same-subject
1854   "\M-n" gnus-summary-next-unread-subject
1855   "\M-p" gnus-summary-prev-unread-subject
1856   "f" gnus-summary-first-unread-article
1857   "b" gnus-summary-best-unread-article
1858   "j" gnus-summary-goto-article
1859   "g" gnus-summary-goto-subject
1860   "l" gnus-summary-goto-last-article
1861   "o" gnus-summary-pop-article)
1862
1863 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1864   "k" gnus-summary-kill-thread
1865   "l" gnus-summary-lower-thread
1866   "i" gnus-summary-raise-thread
1867   "T" gnus-summary-toggle-threads
1868   "t" gnus-summary-rethread-current
1869   "^" gnus-summary-reparent-thread
1870   "s" gnus-summary-show-thread
1871   "S" gnus-summary-show-all-threads
1872   "h" gnus-summary-hide-thread
1873   "H" gnus-summary-hide-all-threads
1874   "n" gnus-summary-next-thread
1875   "p" gnus-summary-prev-thread
1876   "u" gnus-summary-up-thread
1877   "o" gnus-summary-top-thread
1878   "d" gnus-summary-down-thread
1879   "#" gnus-uu-mark-thread
1880   "\M-#" gnus-uu-unmark-thread)
1881
1882 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1883   "g" gnus-summary-prepare
1884   "c" gnus-summary-insert-cached-articles
1885   "d" gnus-summary-insert-dormant-articles)
1886
1887 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1888   "c" gnus-summary-catchup-and-exit
1889   "C" gnus-summary-catchup-all-and-exit
1890   "E" gnus-summary-exit-no-update
1891   "Q" gnus-summary-exit
1892   "Z" gnus-summary-exit
1893   "n" gnus-summary-catchup-and-goto-next-group
1894   "R" gnus-summary-reselect-current-group
1895   "G" gnus-summary-rescan-group
1896   "N" gnus-summary-next-group
1897   "s" gnus-summary-save-newsrc
1898   "P" gnus-summary-prev-group)
1899
1900 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1901   " " gnus-summary-next-page
1902   "n" gnus-summary-next-page
1903   "\177" gnus-summary-prev-page
1904   [delete] gnus-summary-prev-page
1905   "p" gnus-summary-prev-page
1906   "\r" gnus-summary-scroll-up
1907   "\M-\r" gnus-summary-scroll-down
1908   "<" gnus-summary-beginning-of-article
1909   ">" gnus-summary-end-of-article
1910   "b" gnus-summary-beginning-of-article
1911   "e" gnus-summary-end-of-article
1912   "^" gnus-summary-refer-parent-article
1913   "r" gnus-summary-refer-parent-article
1914   "D" gnus-summary-enter-digest-group
1915   "R" gnus-summary-refer-references
1916   "T" gnus-summary-refer-thread
1917   "g" gnus-summary-show-article
1918   "s" gnus-summary-isearch-article
1919   "P" gnus-summary-print-article
1920   "M" gnus-mailing-list-insinuate
1921   "t" gnus-article-babel)
1922
1923 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1924   "b" gnus-article-add-buttons
1925   "B" gnus-article-add-buttons-to-head
1926   "o" gnus-article-treat-overstrike
1927   "e" gnus-article-emphasize
1928   "w" gnus-article-fill-cited-article
1929   "Q" gnus-article-fill-long-lines
1930   "C" gnus-article-capitalize-sentences
1931   "c" gnus-article-remove-cr
1932   "q" gnus-article-de-quoted-unreadable
1933   "6" gnus-article-de-base64-unreadable
1934   "Z" gnus-article-decode-HZ
1935   "A" gnus-article-treat-ansi-sequences
1936   "h" gnus-article-wash-html
1937   "u" gnus-article-unsplit-urls
1938   "s" gnus-summary-force-verify-and-decrypt
1939   "f" gnus-article-display-x-face
1940   "l" gnus-summary-stop-page-breaking
1941   "r" gnus-summary-caesar-message
1942   "m" gnus-summary-morse-message
1943   "t" gnus-summary-toggle-header
1944   "g" gnus-treat-smiley
1945   "v" gnus-summary-verbose-headers
1946   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1947   "p" gnus-article-verify-x-pgp-sig
1948   "d" gnus-article-treat-dumbquotes)
1949
1950 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1951   ;; mnemonic: deuglif*Y*
1952   "u" gnus-article-outlook-unwrap-lines
1953   "a" gnus-article-outlook-repair-attribution
1954   "c" gnus-article-outlook-rearrange-citation
1955   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1956
1957 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1958   "a" gnus-article-hide
1959   "h" gnus-article-hide-headers
1960   "b" gnus-article-hide-boring-headers
1961   "s" gnus-article-hide-signature
1962   "c" gnus-article-hide-citation
1963   "C" gnus-article-hide-citation-in-followups
1964   "l" gnus-article-hide-list-identifiers
1965   "B" gnus-article-strip-banner
1966   "P" gnus-article-hide-pem
1967   "\C-c" gnus-article-hide-citation-maybe)
1968
1969 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1970   "a" gnus-article-highlight
1971   "h" gnus-article-highlight-headers
1972   "c" gnus-article-highlight-citation
1973   "s" gnus-article-highlight-signature)
1974
1975 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1976   "f" gnus-article-treat-fold-headers
1977   "u" gnus-article-treat-unfold-headers
1978   "n" gnus-article-treat-fold-newsgroups)
1979
1980 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1981   "x" gnus-article-display-x-face
1982   "d" gnus-article-display-face
1983   "s" gnus-treat-smiley
1984   "D" gnus-article-remove-images
1985   "f" gnus-treat-from-picon
1986   "m" gnus-treat-mail-picon
1987   "n" gnus-treat-newsgroups-picon)
1988
1989 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1990   "w" gnus-article-decode-mime-words
1991   "c" gnus-article-decode-charset
1992   "v" gnus-mime-view-all-parts
1993   "b" gnus-article-view-part)
1994
1995 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1996   "z" gnus-article-date-ut
1997   "u" gnus-article-date-ut
1998   "l" gnus-article-date-local
1999   "p" gnus-article-date-english
2000   "e" gnus-article-date-lapsed
2001   "o" gnus-article-date-original
2002   "i" gnus-article-date-iso8601
2003   "s" gnus-article-date-user)
2004
2005 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2006   "t" gnus-article-remove-trailing-blank-lines
2007   "l" gnus-article-strip-leading-blank-lines
2008   "m" gnus-article-strip-multiple-blank-lines
2009   "a" gnus-article-strip-blank-lines
2010   "A" gnus-article-strip-all-blank-lines
2011   "s" gnus-article-strip-leading-space
2012   "e" gnus-article-strip-trailing-space
2013   "w" gnus-article-remove-leading-whitespace)
2014
2015 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2016   "v" gnus-version
2017   "f" gnus-summary-fetch-faq
2018   "d" gnus-summary-describe-group
2019   "h" gnus-summary-describe-briefly
2020   "i" gnus-info-find-node
2021   "c" gnus-group-fetch-charter
2022   "C" gnus-group-fetch-control)
2023
2024 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2025   "e" gnus-summary-expire-articles
2026   "\M-\C-e" gnus-summary-expire-articles-now
2027   "\177" gnus-summary-delete-article
2028   [delete] gnus-summary-delete-article
2029   [backspace] gnus-summary-delete-article
2030   "m" gnus-summary-move-article
2031   "r" gnus-summary-respool-article
2032   "w" gnus-summary-edit-article
2033   "c" gnus-summary-copy-article
2034   "B" gnus-summary-crosspost-article
2035   "q" gnus-summary-respool-query
2036   "t" gnus-summary-respool-trace
2037   "i" gnus-summary-import-article
2038   "I" gnus-summary-create-article
2039   "p" gnus-summary-article-posted-p)
2040
2041 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2042   "o" gnus-summary-save-article
2043   "m" gnus-summary-save-article-mail
2044   "F" gnus-summary-write-article-file
2045   "r" gnus-summary-save-article-rmail
2046   "f" gnus-summary-save-article-file
2047   "b" gnus-summary-save-article-body-file
2048   "h" gnus-summary-save-article-folder
2049   "v" gnus-summary-save-article-vm
2050   "p" gnus-summary-pipe-output
2051   "P" gnus-summary-muttprint
2052   "s" gnus-soup-add-article)
2053
2054 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2055   "b" gnus-summary-display-buttonized
2056   "m" gnus-summary-repair-multipart
2057   "v" gnus-article-view-part
2058   "o" gnus-article-save-part
2059   "c" gnus-article-copy-part
2060   "C" gnus-article-view-part-as-charset
2061   "e" gnus-article-view-part-externally
2062   "E" gnus-article-encrypt-body
2063   "i" gnus-article-inline-part
2064   "|" gnus-article-pipe-part)
2065
2066 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2067   "p" gnus-summary-mark-as-processable
2068   "u" gnus-summary-unmark-as-processable
2069   "U" gnus-summary-unmark-all-processable
2070   "v" gnus-uu-mark-over
2071   "s" gnus-uu-mark-series
2072   "r" gnus-uu-mark-region
2073   "g" gnus-uu-unmark-region
2074   "R" gnus-uu-mark-by-regexp
2075   "G" gnus-uu-unmark-by-regexp
2076   "t" gnus-uu-mark-thread
2077   "T" gnus-uu-unmark-thread
2078   "a" gnus-uu-mark-all
2079   "b" gnus-uu-mark-buffer
2080   "S" gnus-uu-mark-sparse
2081   "k" gnus-summary-kill-process-mark
2082   "y" gnus-summary-yank-process-mark
2083   "w" gnus-summary-save-process-mark
2084   "i" gnus-uu-invert-processable)
2085
2086 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2087   ;;"x" gnus-uu-extract-any
2088   "m" gnus-summary-save-parts
2089   "u" gnus-uu-decode-uu
2090   "U" gnus-uu-decode-uu-and-save
2091   "s" gnus-uu-decode-unshar
2092   "S" gnus-uu-decode-unshar-and-save
2093   "o" gnus-uu-decode-save
2094   "O" gnus-uu-decode-save
2095   "b" gnus-uu-decode-binhex
2096   "B" gnus-uu-decode-binhex
2097   "p" gnus-uu-decode-postscript
2098   "P" gnus-uu-decode-postscript-and-save)
2099
2100 (gnus-define-keys
2101     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2102   "u" gnus-uu-decode-uu-view
2103   "U" gnus-uu-decode-uu-and-save-view
2104   "s" gnus-uu-decode-unshar-view
2105   "S" gnus-uu-decode-unshar-and-save-view
2106   "o" gnus-uu-decode-save-view
2107   "O" gnus-uu-decode-save-view
2108   "b" gnus-uu-decode-binhex-view
2109   "B" gnus-uu-decode-binhex-view
2110   "p" gnus-uu-decode-postscript-view
2111   "P" gnus-uu-decode-postscript-and-save-view)
2112
2113 (defvar gnus-article-post-menu nil)
2114
2115 (defconst gnus-summary-menu-maxlen 20)
2116
2117 (defun gnus-summary-menu-split (menu)
2118   ;; If we have lots of elements, divide them into groups of 20
2119   ;; and make a pane (or submenu) for each one.
2120   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2121       (let ((menu menu) sublists next
2122             (i 1))
2123         (while menu
2124           ;; Pull off the next gnus-summary-menu-maxlen elements
2125           ;; and make them the next element of sublist.
2126           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2127           (if next
2128               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2129                       nil))
2130           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2131                                              (aref (car (last menu)) 0)) menu)
2132                                sublists))
2133           (setq i (1+ i))
2134           (setq menu next))
2135         (nreverse sublists))
2136     ;; Few elements--put them all in one pane.
2137     menu))
2138
2139 (defun gnus-summary-make-menu-bar ()
2140   (gnus-turn-off-edit-menu 'summary)
2141
2142   (unless (boundp 'gnus-summary-misc-menu)
2143
2144     (easy-menu-define
2145       gnus-summary-kill-menu gnus-summary-mode-map ""
2146       (cons
2147        "Score"
2148        (nconc
2149         (list
2150          ["Customize" gnus-score-customize t])
2151         (gnus-make-score-map 'increase)
2152         (gnus-make-score-map 'lower)
2153         '(("Mark"
2154            ["Kill below" gnus-summary-kill-below t]
2155            ["Mark above" gnus-summary-mark-above t]
2156            ["Tick above" gnus-summary-tick-above t]
2157            ["Clear above" gnus-summary-clear-above t])
2158           ["Current score" gnus-summary-current-score t]
2159           ["Set score" gnus-summary-set-score t]
2160           ["Switch current score file..." gnus-score-change-score-file t]
2161           ["Set mark below..." gnus-score-set-mark-below t]
2162           ["Set expunge below..." gnus-score-set-expunge-below t]
2163           ["Edit current score file" gnus-score-edit-current-scores t]
2164           ["Edit score file" gnus-score-edit-file t]
2165           ["Trace score" gnus-score-find-trace t]
2166           ["Find words" gnus-score-find-favourite-words t]
2167           ["Rescore buffer" gnus-summary-rescore t]
2168           ["Increase score..." gnus-summary-increase-score t]
2169           ["Lower score..." gnus-summary-lower-score t]))))
2170
2171     ;; Define both the Article menu in the summary buffer and the
2172     ;; equivalent Commands menu in the article buffer here for
2173     ;; consistency.
2174     (let ((innards
2175            `(("Hide"
2176               ["All" gnus-article-hide t]
2177               ["Headers" gnus-article-hide-headers t]
2178               ["Signature" gnus-article-hide-signature t]
2179               ["Citation" gnus-article-hide-citation t]
2180               ["List identifiers" gnus-article-hide-list-identifiers t]
2181               ["Banner" gnus-article-strip-banner t]
2182               ["Boring headers" gnus-article-hide-boring-headers t])
2183              ("Highlight"
2184               ["All" gnus-article-highlight t]
2185               ["Headers" gnus-article-highlight-headers t]
2186               ["Signature" gnus-article-highlight-signature t]
2187               ["Citation" gnus-article-highlight-citation t])
2188              ("MIME"
2189               ["Words" gnus-article-decode-mime-words t]
2190               ["Charset" gnus-article-decode-charset t]
2191               ["QP" gnus-article-de-quoted-unreadable t]
2192               ["Base64" gnus-article-de-base64-unreadable t]
2193               ["View MIME buttons" gnus-summary-display-buttonized t]
2194               ["View all" gnus-mime-view-all-parts t]
2195               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2196               ["Encrypt body" gnus-article-encrypt-body
2197                :active (not (gnus-group-read-only-p))
2198                ,@(if (featurep 'xemacs) nil
2199                    '(:help "Encrypt the message body on disk"))]
2200               ["Extract all parts..." gnus-summary-save-parts t]
2201               ("Multipart"
2202                ["Repair multipart" gnus-summary-repair-multipart t]
2203                ["Pipe part..." gnus-article-pipe-part t]
2204                ["Inline part" gnus-article-inline-part t]
2205                ["Encrypt body" gnus-article-encrypt-body
2206                 :active (not (gnus-group-read-only-p))
2207                ,@(if (featurep 'xemacs) nil
2208                    '(:help "Encrypt the message body on disk"))]
2209                ["View part externally" gnus-article-view-part-externally t]
2210                ["View part with charset..." gnus-article-view-part-as-charset t]
2211                ["Copy part" gnus-article-copy-part t]
2212                ["Save part..." gnus-article-save-part t]
2213                ["View part" gnus-article-view-part t]))
2214              ("Date"
2215               ["Local" gnus-article-date-local t]
2216               ["ISO8601" gnus-article-date-iso8601 t]
2217               ["UT" gnus-article-date-ut t]
2218               ["Original" gnus-article-date-original t]
2219               ["Lapsed" gnus-article-date-lapsed t]
2220               ["User-defined" gnus-article-date-user t])
2221              ("Display"
2222               ["Remove images" gnus-article-remove-images t]
2223               ["Toggle smiley" gnus-treat-smiley t]
2224               ["Show X-Face" gnus-article-display-x-face t]
2225               ["Show picons in From" gnus-treat-from-picon t]
2226               ["Show picons in mail headers" gnus-treat-mail-picon t]
2227               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2228               ("View as different encoding"
2229                ,@(gnus-summary-menu-split
2230                   (mapcar
2231                    (lambda (cs)
2232                      ;; Since easymenu under Emacs doesn't allow
2233                      ;; lambda forms for menu commands, we should
2234                      ;; provide intern'ed function symbols.
2235                      (let ((command (intern (format "\
2236 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2237                        (fset command
2238                              `(lambda ()
2239                                 (interactive)
2240                                 (let ((gnus-summary-show-article-charset-alist
2241                                        '((1 . ,cs))))
2242                                   (gnus-summary-show-article 1))))
2243                        `[,(symbol-name cs) ,command t]))
2244                    (sort (if (fboundp 'coding-system-list)
2245                              (coding-system-list)
2246                            (mapcar 'car mm-mime-mule-charset-alist))
2247                          'string<)))))
2248              ("Washing"
2249               ("Remove Blanks"
2250                ["Leading" gnus-article-strip-leading-blank-lines t]
2251                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2252                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2253                ["All of the above" gnus-article-strip-blank-lines t]
2254                ["All" gnus-article-strip-all-blank-lines t]
2255                ["Leading space" gnus-article-strip-leading-space t]
2256                ["Trailing space" gnus-article-strip-trailing-space t]
2257                ["Leading space in headers"
2258                 gnus-article-remove-leading-whitespace t])
2259               ["Overstrike" gnus-article-treat-overstrike t]
2260               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2261               ["Emphasis" gnus-article-emphasize t]
2262               ["Word wrap" gnus-article-fill-cited-article t]
2263               ["Fill long lines" gnus-article-fill-long-lines t]
2264               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2265               ["Remove CR" gnus-article-remove-cr t]
2266               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2267               ["Base64" gnus-article-de-base64-unreadable t]
2268               ["Rot 13" gnus-summary-caesar-message
2269                ,@(if (featurep 'xemacs) '(t)
2270                    '(:help "\"Caesar rotate\" article by 13"))]
2271               ["Morse decode" gnus-summary-morse-message t]
2272               ["Unix pipe..." gnus-summary-pipe-message t]
2273               ["Add buttons" gnus-article-add-buttons t]
2274               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2275               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2276               ["Verbose header" gnus-summary-verbose-headers t]
2277               ["Toggle header" gnus-summary-toggle-header t]
2278               ["Unfold headers" gnus-article-treat-unfold-headers t]
2279               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2280               ["Html" gnus-article-wash-html t]
2281               ["Unsplit URLs" gnus-article-unsplit-urls t]
2282               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2283               ["Decode HZ" gnus-article-decode-HZ t]
2284               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2285               ("(Outlook) Deuglify"
2286                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2287                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2288                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2289                ["Full (Outlook) deuglify"
2290                 gnus-article-outlook-deuglify-article t])
2291               )
2292              ("Output"
2293               ["Save in default format..." gnus-summary-save-article
2294                ,@(if (featurep 'xemacs) '(t)
2295                    '(:help "Save article using default method"))]
2296               ["Save in file..." gnus-summary-save-article-file
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "Save article in file"))]
2299               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2300               ["Save in MH folder..." gnus-summary-save-article-folder t]
2301               ["Save in VM folder..." gnus-summary-save-article-vm t]
2302               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2303               ["Save body in file..." gnus-summary-save-article-body-file t]
2304               ["Pipe through a filter..." gnus-summary-pipe-output t]
2305               ["Add to SOUP packet" gnus-soup-add-article t]
2306               ["Print with Muttprint..." gnus-summary-muttprint t]
2307               ["Print" gnus-summary-print-article
2308                ,@(if (featurep 'xemacs) '(t)
2309                    '(:help "Generate and print a PostScript image"))])
2310              ("Copy, move,... (Backend)"
2311               ,@(if (featurep 'xemacs) nil
2312                   '(:help "Copying, moving, expiring articles..."))
2313               ["Respool article..." gnus-summary-respool-article t]
2314               ["Move article..." gnus-summary-move-article
2315                (gnus-check-backend-function
2316                 'request-move-article gnus-newsgroup-name)]
2317               ["Copy article..." gnus-summary-copy-article t]
2318               ["Crosspost article..." gnus-summary-crosspost-article
2319                (gnus-check-backend-function
2320                 'request-replace-article gnus-newsgroup-name)]
2321               ["Import file..." gnus-summary-import-article
2322                (gnus-check-backend-function
2323                 'request-accept-article gnus-newsgroup-name)]
2324               ["Create article..." gnus-summary-create-article
2325                (gnus-check-backend-function
2326                 'request-accept-article gnus-newsgroup-name)]
2327               ["Check if posted" gnus-summary-article-posted-p t]
2328               ["Edit article" gnus-summary-edit-article
2329                (not (gnus-group-read-only-p))]
2330               ["Delete article" gnus-summary-delete-article
2331                (gnus-check-backend-function
2332                 'request-expire-articles gnus-newsgroup-name)]
2333               ["Query respool" gnus-summary-respool-query t]
2334               ["Trace respool" gnus-summary-respool-trace t]
2335               ["Delete expirable articles" gnus-summary-expire-articles-now
2336                (gnus-check-backend-function
2337                 'request-expire-articles gnus-newsgroup-name)])
2338              ("Extract"
2339               ["Uudecode" gnus-uu-decode-uu
2340                ,@(if (featurep 'xemacs) '(t)
2341                    '(:help "Decode uuencoded article(s)"))]
2342               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2343               ["Unshar" gnus-uu-decode-unshar t]
2344               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2345               ["Save" gnus-uu-decode-save t]
2346               ["Binhex" gnus-uu-decode-binhex t]
2347               ["Postscript" gnus-uu-decode-postscript t]
2348               ["All MIME parts" gnus-summary-save-parts t])
2349              ("Cache"
2350               ["Enter article" gnus-cache-enter-article t]
2351               ["Remove article" gnus-cache-remove-article t])
2352              ["Translate" gnus-article-babel t]
2353              ["Select article buffer" gnus-summary-select-article-buffer t]
2354              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2355              ["Isearch article..." gnus-summary-isearch-article t]
2356              ["Beginning of the article" gnus-summary-beginning-of-article t]
2357              ["End of the article" gnus-summary-end-of-article t]
2358              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2359              ["Fetch referenced articles" gnus-summary-refer-references t]
2360              ["Fetch current thread" gnus-summary-refer-thread t]
2361              ["Fetch article with id..." gnus-summary-refer-article t]
2362              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2363              ["Redisplay" gnus-summary-show-article t]
2364              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2365       (easy-menu-define
2366         gnus-summary-article-menu gnus-summary-mode-map ""
2367         (cons "Article" innards))
2368
2369       (if (not (keymapp gnus-summary-article-menu))
2370           (easy-menu-define
2371             gnus-article-commands-menu gnus-article-mode-map ""
2372             (cons "Commands" innards))
2373         ;; in Emacs, don't share menu.
2374         (setq gnus-article-commands-menu
2375               (copy-keymap gnus-summary-article-menu))
2376         (define-key gnus-article-mode-map [menu-bar commands]
2377           (cons "Commands" gnus-article-commands-menu))))
2378
2379     (easy-menu-define
2380       gnus-summary-thread-menu gnus-summary-mode-map ""
2381       '("Threads"
2382         ["Find all messages in thread" gnus-summary-refer-thread t]
2383         ["Toggle threading" gnus-summary-toggle-threads t]
2384         ["Hide threads" gnus-summary-hide-all-threads t]
2385         ["Show threads" gnus-summary-show-all-threads t]
2386         ["Hide thread" gnus-summary-hide-thread t]
2387         ["Show thread" gnus-summary-show-thread t]
2388         ["Go to next thread" gnus-summary-next-thread t]
2389         ["Go to previous thread" gnus-summary-prev-thread t]
2390         ["Go down thread" gnus-summary-down-thread t]
2391         ["Go up thread" gnus-summary-up-thread t]
2392         ["Top of thread" gnus-summary-top-thread t]
2393         ["Mark thread as read" gnus-summary-kill-thread t]
2394         ["Lower thread score" gnus-summary-lower-thread t]
2395         ["Raise thread score" gnus-summary-raise-thread t]
2396         ["Rethread current" gnus-summary-rethread-current t]))
2397
2398     (easy-menu-define
2399       gnus-summary-post-menu gnus-summary-mode-map ""
2400       `("Post"
2401         ["Send a message (mail or news)" gnus-summary-post-news
2402          ,@(if (featurep 'xemacs) '(t)
2403              '(:help "Compose a new message (mail or news)"))]
2404         ["Followup" gnus-summary-followup
2405          ,@(if (featurep 'xemacs) '(t)
2406              '(:help "Post followup to this article"))]
2407         ["Followup and yank" gnus-summary-followup-with-original
2408          ,@(if (featurep 'xemacs) '(t)
2409              '(:help "Post followup to this article, quoting its contents"))]
2410         ["Supersede article" gnus-summary-supersede-article t]
2411         ["Cancel article" gnus-summary-cancel-article
2412          ,@(if (featurep 'xemacs) '(t)
2413              '(:help "Cancel an article you posted"))]
2414         ["Reply" gnus-summary-reply t]
2415         ["Reply and yank" gnus-summary-reply-with-original t]
2416         ["Wide reply" gnus-summary-wide-reply t]
2417         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2418          ,@(if (featurep 'xemacs) '(t)
2419              '(:help "Mail a reply, quoting this article"))]
2420         ["Very wide reply" gnus-summary-very-wide-reply t]
2421         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Mail a very wide reply, quoting this article"))]
2424         ["Mail forward" gnus-summary-mail-forward t]
2425         ["Post forward" gnus-summary-post-forward t]
2426         ["Digest and mail" gnus-uu-digest-mail-forward t]
2427         ["Digest and post" gnus-uu-digest-post-forward t]
2428         ["Resend message" gnus-summary-resend-message t]
2429         ["Resend message edit" gnus-summary-resend-message-edit t]
2430         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2431         ["Send a mail" gnus-summary-mail-other-window t]
2432         ["Create a local message" gnus-summary-news-other-window t]
2433         ["Uuencode and post" gnus-uu-post-news
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post a uuencoded article"))]
2436         ["Followup via news" gnus-summary-followup-to-mail t]
2437         ["Followup via news and yank"
2438          gnus-summary-followup-to-mail-with-original t]
2439         ;;("Draft"
2440         ;;["Send" gnus-summary-send-draft t]
2441         ;;["Send bounced" gnus-resend-bounced-mail t])
2442         ))
2443
2444     (cond
2445      ((not (keymapp gnus-summary-post-menu))
2446       (setq gnus-article-post-menu gnus-summary-post-menu))
2447      ((not gnus-article-post-menu)
2448       ;; Don't share post menu.
2449       (setq gnus-article-post-menu
2450             (copy-keymap gnus-summary-post-menu))))
2451     (define-key gnus-article-mode-map [menu-bar post]
2452       (cons "Post" gnus-article-post-menu))
2453
2454     (easy-menu-define
2455       gnus-summary-misc-menu gnus-summary-mode-map ""
2456       `("Gnus"
2457         ("Mark Read"
2458          ["Mark as read" gnus-summary-mark-as-read-forward t]
2459          ["Mark same subject and select"
2460           gnus-summary-kill-same-subject-and-select t]
2461          ["Mark same subject" gnus-summary-kill-same-subject t]
2462          ["Catchup" gnus-summary-catchup
2463           ,@(if (featurep 'xemacs) '(t)
2464               '(:help "Mark unread articles in this group as read"))]
2465          ["Catchup all" gnus-summary-catchup-all t]
2466          ["Catchup to here" gnus-summary-catchup-to-here t]
2467          ["Catchup from here" gnus-summary-catchup-from-here t]
2468          ["Catchup region" gnus-summary-mark-region-as-read
2469           (gnus-mark-active-p)]
2470          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2471         ("Mark Various"
2472          ["Tick" gnus-summary-tick-article-forward t]
2473          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2474          ["Remove marks" gnus-summary-clear-mark-forward t]
2475          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2476          ["Set bookmark" gnus-summary-set-bookmark t]
2477          ["Remove bookmark" gnus-summary-remove-bookmark t])
2478         ("Limit to"
2479          ["Marks..." gnus-summary-limit-to-marks t]
2480          ["Subject..." gnus-summary-limit-to-subject t]
2481          ["Author..." gnus-summary-limit-to-author t]
2482          ["Recipient..." gnus-summary-limit-to-recipient t]
2483          ["Age..." gnus-summary-limit-to-age t]
2484          ["Extra..." gnus-summary-limit-to-extra t]
2485          ["Score..." gnus-summary-limit-to-score t]
2486          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2487          ["Unread" gnus-summary-limit-to-unread t]
2488          ["Unseen" gnus-summary-limit-to-unseen t]
2489          ["Replied" gnus-summary-limit-to-replied t]
2490          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2491          ["Next articles" gnus-summary-limit-to-articles t]
2492          ["Pop limit" gnus-summary-pop-limit t]
2493          ["Show dormant" gnus-summary-limit-include-dormant t]
2494          ["Hide childless dormant"
2495           gnus-summary-limit-exclude-childless-dormant t]
2496          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2497          ["Hide marked" gnus-summary-limit-exclude-marks t]
2498          ["Show expunged" gnus-summary-limit-include-expunged t])
2499         ("Process Mark"
2500          ["Set mark" gnus-summary-mark-as-processable t]
2501          ["Remove mark" gnus-summary-unmark-as-processable t]
2502          ["Remove all marks" gnus-summary-unmark-all-processable t]
2503          ["Invert marks" gnus-uu-invert-processable t]
2504          ["Mark above" gnus-uu-mark-over t]
2505          ["Mark series" gnus-uu-mark-series t]
2506          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2507          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2508          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2509          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2510          ["Mark all" gnus-uu-mark-all t]
2511          ["Mark buffer" gnus-uu-mark-buffer t]
2512          ["Mark sparse" gnus-uu-mark-sparse t]
2513          ["Mark thread" gnus-uu-mark-thread t]
2514          ["Unmark thread" gnus-uu-unmark-thread t]
2515          ("Process Mark Sets"
2516           ["Kill" gnus-summary-kill-process-mark t]
2517           ["Yank" gnus-summary-yank-process-mark
2518            gnus-newsgroup-process-stack]
2519           ["Save" gnus-summary-save-process-mark t]
2520           ["Run command on marked..." gnus-summary-universal-argument t]))
2521         ("Scroll article"
2522          ["Page forward" gnus-summary-next-page
2523           ,@(if (featurep 'xemacs) '(t)
2524               '(:help "Show next page of article"))]
2525          ["Page backward" gnus-summary-prev-page
2526           ,@(if (featurep 'xemacs) '(t)
2527               '(:help "Show previous page of article"))]
2528          ["Line forward" gnus-summary-scroll-up t])
2529         ("Move"
2530          ["Next unread article" gnus-summary-next-unread-article t]
2531          ["Previous unread article" gnus-summary-prev-unread-article t]
2532          ["Next article" gnus-summary-next-article t]
2533          ["Previous article" gnus-summary-prev-article t]
2534          ["Next unread subject" gnus-summary-next-unread-subject t]
2535          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2536          ["Next article same subject" gnus-summary-next-same-subject t]
2537          ["Previous article same subject" gnus-summary-prev-same-subject t]
2538          ["First unread article" gnus-summary-first-unread-article t]
2539          ["Best unread article" gnus-summary-best-unread-article t]
2540          ["Go to subject number..." gnus-summary-goto-subject t]
2541          ["Go to article number..." gnus-summary-goto-article t]
2542          ["Go to the last article" gnus-summary-goto-last-article t]
2543          ["Pop article off history" gnus-summary-pop-article t])
2544         ("Sort"
2545          ["Sort by number" gnus-summary-sort-by-number t]
2546          ["Sort by author" gnus-summary-sort-by-author t]
2547          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2548          ["Sort by subject" gnus-summary-sort-by-subject t]
2549          ["Sort by date" gnus-summary-sort-by-date t]
2550          ["Sort by score" gnus-summary-sort-by-score t]
2551          ["Sort by lines" gnus-summary-sort-by-lines t]
2552          ["Sort by characters" gnus-summary-sort-by-chars t]
2553          ["Randomize" gnus-summary-sort-by-random t]
2554          ["Original sort" gnus-summary-sort-by-original t])
2555         ("Help"
2556          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2557          ["Describe group" gnus-summary-describe-group t]
2558          ["Fetch charter" gnus-group-fetch-charter
2559           ,@(if (featurep 'xemacs) nil
2560               '(:help "Display the charter of the current group"))]
2561          ["Fetch control message" gnus-group-fetch-control
2562           ,@(if (featurep 'xemacs) nil
2563               '(:help "Display the archived control message for the current group"))]
2564          ["Read manual" gnus-info-find-node t])
2565         ("Modes"
2566          ["Pick and read" gnus-pick-mode t]
2567          ["Binary" gnus-binary-mode t])
2568         ("Regeneration"
2569          ["Regenerate" gnus-summary-prepare t]
2570          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2571          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2572          ["Toggle threading" gnus-summary-toggle-threads t])
2573         ["See old articles" gnus-summary-insert-old-articles t]
2574         ["See new articles" gnus-summary-insert-new-articles t]
2575         ["Filter articles..." gnus-summary-execute-command t]
2576         ["Run command on articles..." gnus-summary-universal-argument t]
2577         ["Search articles forward..." gnus-summary-search-article-forward t]
2578         ["Search articles backward..." gnus-summary-search-article-backward t]
2579         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2580         ["Expand window" gnus-summary-expand-window t]
2581         ["Expire expirable articles" gnus-summary-expire-articles
2582          (gnus-check-backend-function
2583           'request-expire-articles gnus-newsgroup-name)]
2584         ["Edit local kill file" gnus-summary-edit-local-kill t]
2585         ["Edit main kill file" gnus-summary-edit-global-kill t]
2586         ["Edit group parameters" gnus-summary-edit-parameters t]
2587         ["Customize group parameters" gnus-summary-customize-parameters t]
2588         ["Send a bug report" gnus-bug t]
2589         ("Exit"
2590          ["Catchup and exit" gnus-summary-catchup-and-exit
2591           ,@(if (featurep 'xemacs) '(t)
2592               '(:help "Mark unread articles in this group as read, then exit"))]
2593          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2594          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2595          ["Exit group" gnus-summary-exit
2596           ,@(if (featurep 'xemacs) '(t)
2597               '(:help "Exit current group, return to group selection mode"))]
2598          ["Exit group without updating" gnus-summary-exit-no-update t]
2599          ["Exit and goto next group" gnus-summary-next-group t]
2600          ["Exit and goto prev group" gnus-summary-prev-group t]
2601          ["Reselect group" gnus-summary-reselect-current-group t]
2602          ["Rescan group" gnus-summary-rescan-group t]
2603          ["Update dribble" gnus-summary-save-newsrc t])))
2604
2605     (gnus-run-hooks 'gnus-summary-menu-hook)))
2606
2607 (defvar gnus-summary-tool-bar-map nil)
2608
2609 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2610 (defun gnus-summary-make-tool-bar ()
2611   (if (and (fboundp 'tool-bar-add-item-from-menu)
2612            (default-value 'tool-bar-mode)
2613            (not gnus-summary-tool-bar-map))
2614       (setq gnus-summary-tool-bar-map
2615             (let ((tool-bar-map (make-sparse-keymap))
2616                   (load-path (mm-image-load-path)))
2617               (tool-bar-add-item-from-menu
2618                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-post-news "post" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-followup "followup" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-reply "reply" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2649               tool-bar-map)))
2650   (if gnus-summary-tool-bar-map
2651       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2652
2653 (defun gnus-score-set-default (var value)
2654   "A version of set that updates the GNU Emacs menu-bar."
2655   (set var value)
2656   ;; It is the message that forces the active status to be updated.
2657   (message ""))
2658
2659 (defun gnus-make-score-map (type)
2660   "Make a summary score map of type TYPE."
2661   (if t
2662       nil
2663     (let ((headers '(("author" "from" string)
2664                      ("subject" "subject" string)
2665                      ("article body" "body" string)
2666                      ("article head" "head" string)
2667                      ("xref" "xref" string)
2668                      ("extra header" "extra" string)
2669                      ("lines" "lines" number)
2670                      ("followups to author" "followup" string)))
2671           (types '((number ("less than" <)
2672                            ("greater than" >)
2673                            ("equal" =))
2674                    (string ("substring" s)
2675                            ("exact string" e)
2676                            ("fuzzy string" f)
2677                            ("regexp" r))))
2678           (perms '(("temporary" (current-time-string))
2679                    ("permanent" nil)
2680                    ("immediate" now)))
2681           header)
2682       (list
2683        (apply
2684         'nconc
2685         (list
2686          (if (eq type 'lower)
2687              "Lower score"
2688            "Increase score"))
2689         (let (outh)
2690           (while headers
2691             (setq header (car headers))
2692             (setq outh
2693                   (cons
2694                    (apply
2695                     'nconc
2696                     (list (car header))
2697                     (let ((ts (cdr (assoc (nth 2 header) types)))
2698                           outt)
2699                       (while ts
2700                         (setq outt
2701                               (cons
2702                                (apply
2703                                 'nconc
2704                                 (list (caar ts))
2705                                 (let ((ps perms)
2706                                       outp)
2707                                   (while ps
2708                                     (setq outp
2709                                           (cons
2710                                            (vector
2711                                             (caar ps)
2712                                             (list
2713                                              'gnus-summary-score-entry
2714                                              (nth 1 header)
2715                                              (if (or (string= (nth 1 header)
2716                                                               "head")
2717                                                      (string= (nth 1 header)
2718                                                               "body"))
2719                                                  ""
2720                                                (list 'gnus-summary-header
2721                                                      (nth 1 header)))
2722                                              (list 'quote (nth 1 (car ts)))
2723                                              (list 'gnus-score-delta-default
2724                                                    nil)
2725                                              (nth 1 (car ps))
2726                                              t)
2727                                             t)
2728                                            outp))
2729                                     (setq ps (cdr ps)))
2730                                   (list (nreverse outp))))
2731                                outt))
2732                         (setq ts (cdr ts)))
2733                       (list (nreverse outt))))
2734                    outh))
2735             (setq headers (cdr headers)))
2736           (list (nreverse outh))))))))
2737
2738 \f
2739
2740 (defun gnus-summary-mode (&optional group)
2741   "Major mode for reading articles.
2742
2743 All normal editing commands are switched off.
2744 \\<gnus-summary-mode-map>
2745 Each line in this buffer represents one article.  To read an
2746 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2747 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2748 respectively.
2749
2750 You can also post articles and send mail from this buffer.  To
2751 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2752 of an article, type `\\[gnus-summary-reply]'.
2753
2754 There are approx. one gazillion commands you can execute in this
2755 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2756
2757 The following commands are available:
2758
2759 \\{gnus-summary-mode-map}"
2760   (interactive)
2761   (kill-all-local-variables)
2762   (when (gnus-visual-p 'summary-menu 'menu)
2763     (gnus-summary-make-menu-bar)
2764     (gnus-summary-make-tool-bar))
2765   (gnus-summary-make-local-variables)
2766   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2767     (gnus-summary-make-local-variables))
2768   (gnus-make-thread-indent-array)
2769   (gnus-simplify-mode-line)
2770   (setq major-mode 'gnus-summary-mode)
2771   (setq mode-name "Summary")
2772   (make-local-variable 'minor-mode-alist)
2773   (use-local-map gnus-summary-mode-map)
2774   (buffer-disable-undo)
2775   (setq buffer-read-only t              ;Disable modification
2776         show-trailing-whitespace nil)
2777   (setq truncate-lines t)
2778   (setq selective-display t)
2779   (setq selective-display-ellipses t)   ;Display `...'
2780   (gnus-summary-set-display-table)
2781   (gnus-set-default-directory)
2782   (setq gnus-newsgroup-name group)
2783   (make-local-variable 'gnus-summary-line-format)
2784   (make-local-variable 'gnus-summary-line-format-spec)
2785   (make-local-variable 'gnus-summary-dummy-line-format)
2786   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2787   (make-local-variable 'gnus-summary-mark-positions)
2788   (gnus-make-local-hook 'pre-command-hook)
2789   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2790   (gnus-run-hooks 'gnus-summary-mode-hook)
2791   (turn-on-gnus-mailing-list-mode)
2792   (mm-enable-multibyte)
2793   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2794   (gnus-update-summary-mark-positions))
2795
2796 (defun gnus-summary-make-local-variables ()
2797   "Make all the local summary buffer variables."
2798   (let (global)
2799     (dolist (local gnus-summary-local-variables)
2800       (if (consp local)
2801           (progn
2802             (if (eq (cdr local) 'global)
2803                 ;; Copy the global value of the variable.
2804                 (setq global (symbol-value (car local)))
2805               ;; Use the value from the list.
2806               (setq global (eval (cdr local))))
2807             (set (make-local-variable (car local)) global))
2808         ;; Simple nil-valued local variable.
2809         (set (make-local-variable local) nil)))))
2810
2811 (defun gnus-summary-clear-local-variables ()
2812   (let ((locals gnus-summary-local-variables))
2813     (while locals
2814       (if (consp (car locals))
2815           (and (symbolp (caar locals))
2816                (set (caar locals) nil))
2817         (and (symbolp (car locals))
2818              (set (car locals) nil)))
2819       (setq locals (cdr locals)))))
2820
2821 ;; Summary data functions.
2822
2823 (defmacro gnus-data-number (data)
2824   `(car ,data))
2825
2826 (defmacro gnus-data-set-number (data number)
2827   `(setcar ,data ,number))
2828
2829 (defmacro gnus-data-mark (data)
2830   `(nth 1 ,data))
2831
2832 (defmacro gnus-data-set-mark (data mark)
2833   `(setcar (nthcdr 1 ,data) ,mark))
2834
2835 (defmacro gnus-data-pos (data)
2836   `(nth 2 ,data))
2837
2838 (defmacro gnus-data-set-pos (data pos)
2839   `(setcar (nthcdr 2 ,data) ,pos))
2840
2841 (defmacro gnus-data-header (data)
2842   `(nth 3 ,data))
2843
2844 (defmacro gnus-data-set-header (data header)
2845   `(setf (nth 3 ,data) ,header))
2846
2847 (defmacro gnus-data-level (data)
2848   `(nth 4 ,data))
2849
2850 (defmacro gnus-data-unread-p (data)
2851   `(= (nth 1 ,data) gnus-unread-mark))
2852
2853 (defmacro gnus-data-read-p (data)
2854   `(/= (nth 1 ,data) gnus-unread-mark))
2855
2856 (defmacro gnus-data-pseudo-p (data)
2857   `(consp (nth 3 ,data)))
2858
2859 (defmacro gnus-data-find (number)
2860   `(assq ,number gnus-newsgroup-data))
2861
2862 (defmacro gnus-data-find-list (number &optional data)
2863   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2864      (memq (assq ,number bdata)
2865            bdata)))
2866
2867 (defmacro gnus-data-make (number mark pos header level)
2868   `(list ,number ,mark ,pos ,header ,level))
2869
2870 (defun gnus-data-enter (after-article number mark pos header level offset)
2871   (let ((data (gnus-data-find-list after-article)))
2872     (unless data
2873       (error "No such article: %d" after-article))
2874     (setcdr data (cons (gnus-data-make number mark pos header level)
2875                        (cdr data)))
2876     (setq gnus-newsgroup-data-reverse nil)
2877     (gnus-data-update-list (cddr data) offset)))
2878
2879 (defun gnus-data-enter-list (after-article list &optional offset)
2880   (when list
2881     (let ((data (and after-article (gnus-data-find-list after-article)))
2882           (ilist list))
2883       (if (not (or data
2884                    after-article))
2885           (let ((odata gnus-newsgroup-data))
2886             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2887             (when offset
2888               (gnus-data-update-list odata offset)))
2889         ;; Find the last element in the list to be spliced into the main
2890         ;; list.
2891         (setq list (last list))
2892         (if (not data)
2893             (progn
2894               (setcdr list gnus-newsgroup-data)
2895               (setq gnus-newsgroup-data ilist)
2896               (when offset
2897                 (gnus-data-update-list (cdr list) offset)))
2898           (setcdr list (cdr data))
2899           (setcdr data ilist)
2900           (when offset
2901             (gnus-data-update-list (cdr list) offset))))
2902       (setq gnus-newsgroup-data-reverse nil))))
2903
2904 (defun gnus-data-remove (article &optional offset)
2905   (let ((data gnus-newsgroup-data))
2906     (if (= (gnus-data-number (car data)) article)
2907         (progn
2908           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2909                 gnus-newsgroup-data-reverse nil)
2910           (when offset
2911             (gnus-data-update-list gnus-newsgroup-data offset)))
2912       (while (cdr data)
2913         (when (= (gnus-data-number (cadr data)) article)
2914           (setcdr data (cddr data))
2915           (when offset
2916             (gnus-data-update-list (cdr data) offset))
2917           (setq data nil
2918                 gnus-newsgroup-data-reverse nil))
2919         (setq data (cdr data))))))
2920
2921 (defmacro gnus-data-list (backward)
2922   `(if ,backward
2923        (or gnus-newsgroup-data-reverse
2924            (setq gnus-newsgroup-data-reverse
2925                  (reverse gnus-newsgroup-data)))
2926      gnus-newsgroup-data))
2927
2928 (defun gnus-data-update-list (data offset)
2929   "Add OFFSET to the POS of all data entries in DATA."
2930   (setq gnus-newsgroup-data-reverse nil)
2931   (while data
2932     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2933     (setq data (cdr data))))
2934
2935 (defun gnus-summary-article-pseudo-p (article)
2936   "Say whether this article is a pseudo article or not."
2937   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2938
2939 (defmacro gnus-summary-article-sparse-p (article)
2940   "Say whether this article is a sparse article or not."
2941   `(memq ,article gnus-newsgroup-sparse))
2942
2943 (defmacro gnus-summary-article-ancient-p (article)
2944   "Say whether this article is a sparse article or not."
2945   `(memq ,article gnus-newsgroup-ancient))
2946
2947 (defun gnus-article-parent-p (number)
2948   "Say whether this article is a parent or not."
2949   (let ((data (gnus-data-find-list number)))
2950     (and (cdr data)              ; There has to be an article after...
2951          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2952             (gnus-data-level (nth 1 data))))))
2953
2954 (defun gnus-article-children (number)
2955   "Return a list of all children to NUMBER."
2956   (let* ((data (gnus-data-find-list number))
2957          (level (gnus-data-level (car data)))
2958          children)
2959     (setq data (cdr data))
2960     (while (and data
2961                 (= (gnus-data-level (car data)) (1+ level)))
2962       (push (gnus-data-number (car data)) children)
2963       (setq data (cdr data)))
2964     children))
2965
2966 (defmacro gnus-summary-skip-intangible ()
2967   "If the current article is intangible, then jump to a different article."
2968   '(let ((to (get-text-property (point) 'gnus-intangible)))
2969      (and to (gnus-summary-goto-subject to))))
2970
2971 (defmacro gnus-summary-article-intangible-p ()
2972   "Say whether this article is intangible or not."
2973   '(get-text-property (point) 'gnus-intangible))
2974
2975 (defun gnus-article-read-p (article)
2976   "Say whether ARTICLE is read or not."
2977   (not (or (memq article gnus-newsgroup-marked)
2978            (memq article gnus-newsgroup-spam-marked)
2979            (memq article gnus-newsgroup-unreads)
2980            (memq article gnus-newsgroup-unselected)
2981            (memq article gnus-newsgroup-dormant))))
2982
2983 ;; Some summary mode macros.
2984
2985 (defmacro gnus-summary-article-number ()
2986   "The article number of the article on the current line.
2987 If there isn't an article number here, then we return the current
2988 article number."
2989   '(progn
2990      (gnus-summary-skip-intangible)
2991      (or (get-text-property (point) 'gnus-number)
2992          (gnus-summary-last-subject))))
2993
2994 (defmacro gnus-summary-article-header (&optional number)
2995   "Return the header of article NUMBER."
2996   `(gnus-data-header (gnus-data-find
2997                       ,(or number '(gnus-summary-article-number)))))
2998
2999 (defmacro gnus-summary-thread-level (&optional number)
3000   "Return the level of thread that starts with article NUMBER."
3001   `(if (and (eq gnus-summary-make-false-root 'dummy)
3002             (get-text-property (point) 'gnus-intangible))
3003        0
3004      (gnus-data-level (gnus-data-find
3005                        ,(or number '(gnus-summary-article-number))))))
3006
3007 (defmacro gnus-summary-article-mark (&optional number)
3008   "Return the mark of article NUMBER."
3009   `(gnus-data-mark (gnus-data-find
3010                     ,(or number '(gnus-summary-article-number)))))
3011
3012 (defmacro gnus-summary-article-pos (&optional number)
3013   "Return the position of the line of article NUMBER."
3014   `(gnus-data-pos (gnus-data-find
3015                    ,(or number '(gnus-summary-article-number)))))
3016
3017 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3018 (defmacro gnus-summary-article-subject (&optional number)
3019   "Return current subject string or nil if nothing."
3020   `(let ((headers
3021           ,(if number
3022                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3023              '(gnus-data-header (assq (gnus-summary-article-number)
3024                                       gnus-newsgroup-data)))))
3025      (and headers
3026           (vectorp headers)
3027           (mail-header-subject headers))))
3028
3029 (defmacro gnus-summary-article-score (&optional number)
3030   "Return current article score."
3031   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3032                   gnus-newsgroup-scored))
3033        gnus-summary-default-score 0))
3034
3035 (defun gnus-summary-article-children (&optional number)
3036   "Return a list of article numbers that are children of article NUMBER."
3037   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3038          (level (gnus-data-level (car data)))
3039          l children)
3040     (while (and (setq data (cdr data))
3041                 (> (setq l (gnus-data-level (car data))) level))
3042       (and (= (1+ level) l)
3043            (push (gnus-data-number (car data))
3044                  children)))
3045     (nreverse children)))
3046
3047 (defun gnus-summary-article-parent (&optional number)
3048   "Return the article number of the parent of article NUMBER."
3049   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3050                                     (gnus-data-list t)))
3051          (level (gnus-data-level (car data))))
3052     (if (zerop level)
3053         ()                              ; This is a root.
3054       ;; We search until we find an article with a level less than
3055       ;; this one.  That function has to be the parent.
3056       (while (and (setq data (cdr data))
3057                   (not (< (gnus-data-level (car data)) level))))
3058       (and data (gnus-data-number (car data))))))
3059
3060 (defun gnus-unread-mark-p (mark)
3061   "Say whether MARK is the unread mark."
3062   (= mark gnus-unread-mark))
3063
3064 (defun gnus-read-mark-p (mark)
3065   "Say whether MARK is one of the marks that mark as read.
3066 This is all marks except unread, ticked, dormant, and expirable."
3067   (not (or (= mark gnus-unread-mark)
3068            (= mark gnus-ticked-mark)
3069            (= mark gnus-spam-mark)
3070            (= mark gnus-dormant-mark)
3071            (= mark gnus-expirable-mark))))
3072
3073 (defmacro gnus-article-mark (number)
3074   "Return the MARK of article NUMBER.
3075 This macro should only be used when computing the mark the \"first\"
3076 time; i.e., when generating the summary lines.  After that,
3077 `gnus-summary-article-mark' should be used to examine the
3078 marks of articles."
3079   `(cond
3080     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3081     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3082     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3083     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3084     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3085     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3086     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3087     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3088            gnus-ancient-mark))))
3089
3090 ;; Saving hidden threads.
3091
3092 (defmacro gnus-save-hidden-threads (&rest forms)
3093   "Save hidden threads, eval FORMS, and restore the hidden threads."
3094   (let ((config (make-symbol "config")))
3095     `(let ((,config (gnus-hidden-threads-configuration)))
3096        (unwind-protect
3097            (save-excursion
3098              ,@forms)
3099          (gnus-restore-hidden-threads-configuration ,config)))))
3100 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3101 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3102
3103 (defun gnus-data-compute-positions ()
3104   "Compute the positions of all articles."
3105   (setq gnus-newsgroup-data-reverse nil)
3106   (let ((data gnus-newsgroup-data))
3107     (save-excursion
3108       (gnus-save-hidden-threads
3109         (gnus-summary-show-all-threads)
3110         (goto-char (point-min))
3111         (while data
3112           (while (get-text-property (point) 'gnus-intangible)
3113             (forward-line 1))
3114           (gnus-data-set-pos (car data) (+ (point) 3))
3115           (setq data (cdr data))
3116           (forward-line 1))))))
3117
3118 (defun gnus-hidden-threads-configuration ()
3119   "Return the current hidden threads configuration."
3120   (save-excursion
3121     (let (config)
3122       (goto-char (point-min))
3123       (while (search-forward "\r" nil t)
3124         (push (1- (point)) config))
3125       config)))
3126
3127 (defun gnus-restore-hidden-threads-configuration (config)
3128   "Restore hidden threads configuration from CONFIG."
3129   (save-excursion
3130     (let (point buffer-read-only)
3131       (while (setq point (pop config))
3132         (when (and (< point (point-max))
3133                    (goto-char point)
3134                    (eq (char-after) ?\n))
3135           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3136
3137 ;; Various summary mode internalish functions.
3138
3139 (defun gnus-mouse-pick-article (e)
3140   (interactive "e")
3141   (mouse-set-point e)
3142   (gnus-summary-next-page nil t))
3143
3144 (defun gnus-summary-set-display-table ()
3145   "Change the display table.
3146 Odd characters have a tendency to mess
3147 up nicely formatted displays - we make all possible glyphs
3148 display only a single character."
3149
3150   ;; We start from the standard display table, if any.
3151   (let ((table (or (copy-sequence standard-display-table)
3152                    (make-display-table)))
3153         (i 32))
3154     ;; Nix out all the control chars...
3155     (while (>= (setq i (1- i)) 0)
3156       (aset table i [??]))
3157    ;; ... but not newline and cr, of course.  (cr is necessary for the
3158     ;; selective display).
3159     (aset table ?\n nil)
3160     (aset table ?\r nil)
3161     ;; We keep TAB as well.
3162     (aset table ?\t nil)
3163     ;; We nix out any glyphs over 126 that are not set already.
3164     (let ((i 256))
3165       (while (>= (setq i (1- i)) 127)
3166         ;; Only modify if the entry is nil.
3167         (unless (aref table i)
3168           (aset table i [??]))))
3169     (setq buffer-display-table table)))
3170
3171 (defun gnus-summary-set-article-display-arrow (pos)
3172   "Update the overlay arrow to point to line at position POS."
3173   (when (and gnus-summary-display-arrow
3174              (boundp 'overlay-arrow-position)
3175              (boundp 'overlay-arrow-string))
3176     (save-excursion
3177       (goto-char pos)
3178       (beginning-of-line)
3179       (unless overlay-arrow-position
3180         (setq overlay-arrow-position (make-marker)))
3181       (setq overlay-arrow-string "=>"
3182             overlay-arrow-position (set-marker overlay-arrow-position
3183                                                (point)
3184                                                (current-buffer))))))
3185
3186 (defun gnus-summary-setup-buffer (group)
3187   "Initialize summary buffer."
3188   (let ((buffer (gnus-summary-buffer-name group))
3189         (dead-name (concat "*Dead Summary "
3190                            (gnus-group-decoded-name group) "*")))
3191     ;; If a dead summary buffer exists, we kill it.
3192     (when (gnus-buffer-live-p dead-name)
3193       (gnus-kill-buffer dead-name))
3194     (if (get-buffer buffer)
3195         (progn
3196           (set-buffer buffer)
3197           (setq gnus-summary-buffer (current-buffer))
3198           (not gnus-newsgroup-prepared))
3199       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3200       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3201       (gnus-summary-mode group)
3202       (when gnus-carpal
3203         (gnus-carpal-setup-buffer 'summary))
3204       (unless gnus-single-article-buffer
3205         (make-local-variable 'gnus-article-buffer)
3206         (make-local-variable 'gnus-article-current)
3207         (make-local-variable 'gnus-original-article-buffer))
3208       (setq gnus-newsgroup-name group)
3209       ;; Set any local variables in the group parameters.
3210       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3211       t)))
3212
3213 (defun gnus-set-global-variables ()
3214   "Set the global equivalents of the buffer-local variables.
3215 They are set to the latest values they had.  These reflect the summary
3216 buffer that was in action when the last article was fetched."
3217   (when (eq major-mode 'gnus-summary-mode)
3218     (setq gnus-summary-buffer (current-buffer))
3219     (let ((name gnus-newsgroup-name)
3220           (marked gnus-newsgroup-marked)
3221           (spam gnus-newsgroup-spam-marked)
3222           (unread gnus-newsgroup-unreads)
3223           (headers gnus-current-headers)
3224           (data gnus-newsgroup-data)
3225           (summary gnus-summary-buffer)
3226           (article-buffer gnus-article-buffer)
3227           (original gnus-original-article-buffer)
3228           (gac gnus-article-current)
3229           (reffed gnus-reffed-article-number)
3230           (score-file gnus-current-score-file)
3231           (default-charset gnus-newsgroup-charset)
3232           vlist)
3233       (let ((locals gnus-newsgroup-variables))
3234         (while locals
3235           (if (consp (car locals))
3236               (push (eval (caar locals)) vlist)
3237             (push (eval (car locals)) vlist))
3238           (setq locals (cdr locals)))
3239         (setq vlist (nreverse vlist)))
3240       (with-current-buffer gnus-group-buffer
3241         (setq gnus-newsgroup-name name
3242               gnus-newsgroup-marked marked
3243               gnus-newsgroup-spam-marked spam
3244               gnus-newsgroup-unreads unread
3245               gnus-current-headers headers
3246               gnus-newsgroup-data data
3247               gnus-article-current gac
3248               gnus-summary-buffer summary
3249               gnus-article-buffer article-buffer
3250               gnus-original-article-buffer original
3251               gnus-reffed-article-number reffed
3252               gnus-current-score-file score-file
3253               gnus-newsgroup-charset default-charset)
3254         (let ((locals gnus-newsgroup-variables))
3255           (while locals
3256             (if (consp (car locals))
3257                 (set (caar locals) (pop vlist))
3258               (set (car locals) (pop vlist)))
3259             (setq locals (cdr locals))))
3260         ;; The article buffer also has local variables.
3261         (when (gnus-buffer-live-p gnus-article-buffer)
3262           (set-buffer gnus-article-buffer)
3263           (setq gnus-summary-buffer summary))))))
3264
3265 (defun gnus-summary-article-unread-p (article)
3266   "Say whether ARTICLE is unread or not."
3267   (memq article gnus-newsgroup-unreads))
3268
3269 (defun gnus-summary-first-article-p (&optional article)
3270   "Return whether ARTICLE is the first article in the buffer."
3271   (if (not (setq article (or article (gnus-summary-article-number))))
3272       nil
3273     (eq article (caar gnus-newsgroup-data))))
3274
3275 (defun gnus-summary-last-article-p (&optional article)
3276   "Return whether ARTICLE is the last article in the buffer."
3277   (if (not (setq article (or article (gnus-summary-article-number))))
3278       ;; All non-existent numbers are the last article.  :-)
3279       t
3280     (not (cdr (gnus-data-find-list article)))))
3281
3282 (defun gnus-make-thread-indent-array ()
3283   (let ((n 200))
3284     (unless (and gnus-thread-indent-array
3285                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3286       (setq gnus-thread-indent-array (make-vector 201 "")
3287             gnus-thread-indent-array-level gnus-thread-indent-level)
3288       (while (>= n 0)
3289         (aset gnus-thread-indent-array n
3290               (make-string (* n gnus-thread-indent-level) ? ))
3291         (setq n (1- n))))))
3292
3293 (defun gnus-update-summary-mark-positions ()
3294   "Compute where the summary marks are to go."
3295   (save-excursion
3296     (when (gnus-buffer-exists-p gnus-summary-buffer)
3297       (set-buffer gnus-summary-buffer))
3298     (let ((spec gnus-summary-line-format-spec)
3299           pos)
3300       (save-excursion
3301         (gnus-set-work-buffer)
3302         (let ((gnus-tmp-unread ?Z)
3303               (gnus-replied-mark ?Z)
3304               (gnus-score-below-mark ?Z)
3305               (gnus-score-over-mark ?Z)
3306               (gnus-undownloaded-mark ?Z)
3307               (gnus-summary-line-format-spec spec)
3308               (gnus-newsgroup-downloadable '(0))
3309               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3310               case-fold-search ignores)
3311           ;; Here, all marks are bound to Z.
3312           (gnus-summary-insert-line header
3313                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3314           (goto-char (point-min))
3315           ;; Memorize the positions of the same characters as dummy marks.
3316           (while (re-search-forward "[A-D]" nil t)
3317             (push (point) ignores))
3318           (erase-buffer)
3319           ;; We use A-D as dummy marks in order to know column positions
3320           ;; where marks should be inserted.
3321           (setq gnus-tmp-unread ?A
3322                 gnus-replied-mark ?B
3323                 gnus-score-below-mark ?C
3324                 gnus-score-over-mark ?C
3325                 gnus-undownloaded-mark ?D)
3326           (gnus-summary-insert-line header
3327                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3328           ;; Ignore characters which aren't dummy marks.
3329           (dolist (p ignores)
3330             (delete-region (goto-char (1- p)) p)
3331             (insert ?Z))
3332           (goto-char (point-min))
3333           (setq pos (list (cons 'unread
3334                                 (and (search-forward "A" nil t)
3335                                      (- (point) (point-min) 1)))))
3336           (goto-char (point-min))
3337           (push (cons 'replied (and (search-forward "B" nil t)
3338                                     (- (point) (point-min) 1)))
3339                 pos)
3340           (goto-char (point-min))
3341           (push (cons 'score (and (search-forward "C" nil t)
3342                                   (- (point) (point-min) 1)))
3343                 pos)
3344           (goto-char (point-min))
3345           (push (cons 'download (and (search-forward "D" nil t)
3346                                      (- (point) (point-min) 1)))
3347                 pos)))
3348       (setq gnus-summary-mark-positions pos))))
3349
3350 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3351   "Insert a dummy root in the summary buffer."
3352   (beginning-of-line)
3353   (gnus-add-text-properties
3354    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3355    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3356
3357 (defun gnus-summary-extract-address-component (from)
3358   (or (car (funcall gnus-extract-address-components from))
3359       from))
3360
3361 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3362   (let ((mail-parse-charset gnus-newsgroup-charset)
3363         ; Is it really necessary to do this next part for each summary line?
3364         ; Luckily, doesn't seem to slow things down much.
3365         (mail-parse-ignored-charsets
3366          (with-current-buffer gnus-summary-buffer
3367            gnus-newsgroup-ignored-charsets)))
3368     (or
3369      (and gnus-ignored-from-addresses
3370           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3371           (let ((extra-headers (mail-header-extra header))
3372                 to
3373                 newsgroups)
3374             (cond
3375              ((setq to (cdr (assq 'To extra-headers)))
3376               (concat "-> "
3377                       (inline
3378                         (gnus-summary-extract-address-component
3379                          (funcall gnus-decode-encoded-word-function to)))))
3380              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3381               (concat "=> " newsgroups)))))
3382      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3383
3384 (defun gnus-summary-insert-line (gnus-tmp-header
3385                                  gnus-tmp-level gnus-tmp-current
3386                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3387                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3388                                  &optional gnus-tmp-dummy gnus-tmp-score
3389                                  gnus-tmp-process)
3390   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3391          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3392          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3393          (gnus-tmp-score-char
3394           (if (or (null gnus-summary-default-score)
3395                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3396                       gnus-summary-zcore-fuzz))
3397               ?                         ;Whitespace
3398             (if (< gnus-tmp-score gnus-summary-default-score)
3399                 gnus-score-below-mark gnus-score-over-mark)))
3400          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3401          (gnus-tmp-replied
3402           (cond (gnus-tmp-process gnus-process-mark)
3403                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3404                  gnus-cached-mark)
3405                 (gnus-tmp-replied gnus-replied-mark)
3406                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3407                  gnus-forwarded-mark)
3408                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3409                  gnus-saved-mark)
3410                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3411                  gnus-recent-mark)
3412                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3413                  gnus-unseen-mark)
3414                 (t gnus-no-mark)))
3415          (gnus-tmp-downloaded
3416           (cond (undownloaded
3417                  gnus-undownloaded-mark)
3418                 (gnus-newsgroup-agentized
3419                  gnus-downloaded-mark)
3420                 (t
3421                  gnus-no-mark)))
3422          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3423          (gnus-tmp-name
3424           (cond
3425            ((string-match "<[^>]+> *$" gnus-tmp-from)
3426             (let ((beg (match-beginning 0)))
3427               (or (and (string-match "^\".+\"" gnus-tmp-from)
3428                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3429                   (substring gnus-tmp-from 0 beg))))
3430            ((string-match "(.+)" gnus-tmp-from)
3431             (substring gnus-tmp-from
3432                        (1+ (match-beginning 0)) (1- (match-end 0))))
3433            (t gnus-tmp-from)))
3434          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3435          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3436          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3437          (buffer-read-only nil))
3438     (when (string= gnus-tmp-name "")
3439       (setq gnus-tmp-name gnus-tmp-from))
3440     (unless (numberp gnus-tmp-lines)
3441       (setq gnus-tmp-lines -1))
3442     (if (= gnus-tmp-lines -1)
3443         (setq gnus-tmp-lines "?")
3444       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3445       (gnus-put-text-property
3446      (point)
3447      (progn (eval gnus-summary-line-format-spec) (point))
3448        'gnus-number gnus-tmp-number)
3449     (when (gnus-visual-p 'summary-highlight 'highlight)
3450       (forward-line -1)
3451       (gnus-run-hooks 'gnus-summary-update-hook)
3452       (forward-line 1))))
3453
3454 (defun gnus-summary-update-line (&optional dont-update)
3455   "Update summary line after change."
3456   (when (and gnus-summary-default-score
3457              (not gnus-summary-inhibit-highlight))
3458     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3459            (article (gnus-summary-article-number))
3460            (score (gnus-summary-article-score article)))
3461       (unless dont-update
3462         (if (and gnus-summary-mark-below
3463                  (< (gnus-summary-article-score)
3464                     gnus-summary-mark-below))
3465             ;; This article has a low score, so we mark it as read.
3466             (when (memq article gnus-newsgroup-unreads)
3467               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3468           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3469             ;; This article was previously marked as read on account
3470             ;; of a low score, but now it has risen, so we mark it as
3471             ;; unread.
3472             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3473         (gnus-summary-update-mark
3474          (if (or (null gnus-summary-default-score)
3475                  (<= (abs (- score gnus-summary-default-score))
3476                      gnus-summary-zcore-fuzz))
3477              ?                          ;Whitespace
3478            (if (< score gnus-summary-default-score)
3479                gnus-score-below-mark gnus-score-over-mark))
3480          'score))
3481       ;; Do visual highlighting.
3482       (when (gnus-visual-p 'summary-highlight 'highlight)
3483         (gnus-run-hooks 'gnus-summary-update-hook)))))
3484
3485 (defvar gnus-tmp-new-adopts nil)
3486
3487 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3488   "Return the number of articles in THREAD.
3489 This may be 0 in some cases -- if none of the articles in
3490 the thread are to be displayed."
3491   (let* ((number
3492          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3493           (cond
3494            ((not (listp thread))
3495             1)
3496            ((and (consp thread) (cdr thread))
3497             (apply
3498              '+ 1 (mapcar
3499                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3500            ((null thread)
3501             1)
3502            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3503             1)
3504            (t 0))))
3505     (when (and level (zerop level) gnus-tmp-new-adopts)
3506       (incf number
3507             (apply '+ (mapcar
3508                        'gnus-summary-number-of-articles-in-thread
3509                        gnus-tmp-new-adopts))))
3510     (if char
3511         (if (> number 1) gnus-not-empty-thread-mark
3512           gnus-empty-thread-mark)
3513       number)))
3514
3515 (defsubst gnus-summary-line-message-size (head)
3516   "Return pretty-printed version of message size.
3517 This function is intended to be used in
3518 `gnus-summary-line-format-alist'."
3519   (let ((c (or (mail-header-chars head) -1)))
3520     (cond ((< c 0) "n/a")               ; chars not available
3521           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3522           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3523           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3524           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3525
3526
3527 (defun gnus-summary-set-local-parameters (group)
3528   "Go through the local params of GROUP and set all variable specs in that list."
3529   (let ((vars '(quit-config)))          ; Ignore quit-config.
3530     (dolist (elem (gnus-group-find-parameter group))
3531       (and (consp elem)                 ; Has to be a cons.
3532            (consp (cdr elem))           ; The cdr has to be a list.
3533            (symbolp (car elem))         ; Has to be a symbol in there.
3534            (not (memq (car elem) vars))
3535            (ignore-errors               ; So we set it.
3536              (push (car elem) vars)
3537              (make-local-variable (car elem))
3538              (set (car elem) (eval (nth 1 elem))))))))
3539
3540 (defun gnus-summary-read-group (group &optional show-all no-article
3541                                       kill-buffer no-display backward
3542                                       select-articles)
3543   "Start reading news in newsgroup GROUP.
3544 If SHOW-ALL is non-nil, already read articles are also listed.
3545 If NO-ARTICLE is non-nil, no article is selected initially.
3546 If NO-DISPLAY, don't generate a summary buffer."
3547   (let (result)
3548     (while (and group
3549                 (null (setq result
3550                             (let ((gnus-auto-select-next nil))
3551                               (or (gnus-summary-read-group-1
3552                                    group show-all no-article
3553                                    kill-buffer no-display
3554                                    select-articles)
3555                                   (setq show-all nil
3556                                         select-articles nil)))))
3557                 (eq gnus-auto-select-next 'quietly))
3558       (set-buffer gnus-group-buffer)
3559       ;; The entry function called above goes to the next
3560       ;; group automatically, so we go two groups back
3561       ;; if we are searching for the previous group.
3562       (when backward
3563         (gnus-group-prev-unread-group 2))
3564       (if (not (equal group (gnus-group-group-name)))
3565           (setq group (gnus-group-group-name))
3566         (setq group nil)))
3567     result))
3568
3569 (defun gnus-summary-read-group-1 (group show-all no-article
3570                                         kill-buffer no-display
3571                                         &optional select-articles)
3572   ;; Killed foreign groups can't be entered.
3573   ;;  (when (and (not (gnus-group-native-p group))
3574   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3575   ;;    (error "Dead non-native groups can't be entered"))
3576   (gnus-message 5 "Retrieving newsgroup: %s..."
3577                 (gnus-group-decoded-name group))
3578   (let* ((new-group (gnus-summary-setup-buffer group))
3579          (quit-config (gnus-group-quit-config group))
3580          (did-select (and new-group (gnus-select-newsgroup
3581                                      group show-all select-articles))))
3582     (cond
3583      ;; This summary buffer exists already, so we just select it.
3584      ((not new-group)
3585       (gnus-set-global-variables)
3586       (when kill-buffer
3587         (gnus-kill-or-deaden-summary kill-buffer))
3588       (gnus-configure-windows 'summary 'force)
3589       (gnus-set-mode-line 'summary)
3590       (gnus-summary-position-point)
3591       (message "")
3592       t)
3593      ;; We couldn't select this group.
3594      ((null did-select)
3595       (when (and (eq major-mode 'gnus-summary-mode)
3596                  (not (equal (current-buffer) kill-buffer)))
3597         (kill-buffer (current-buffer))
3598         (if (not quit-config)
3599             (progn
3600               ;; Update the info -- marks might need to be removed,
3601               ;; for instance.
3602               (gnus-summary-update-info)
3603               (set-buffer gnus-group-buffer)
3604               (gnus-group-jump-to-group group)
3605               (gnus-group-next-unread-group 1))
3606           (gnus-handle-ephemeral-exit quit-config)))
3607       (let ((grpinfo (gnus-get-info group)))
3608         (if (null (gnus-info-read grpinfo))
3609             (gnus-message 3 "Group %s contains no messages"
3610                           (gnus-group-decoded-name group))
3611           (gnus-message 3 "Can't select group")))
3612       nil)
3613      ;; The user did a `C-g' while prompting for number of articles,
3614      ;; so we exit this group.
3615      ((eq did-select 'quit)
3616       (and (eq major-mode 'gnus-summary-mode)
3617            (not (equal (current-buffer) kill-buffer))
3618            (kill-buffer (current-buffer)))
3619       (when kill-buffer
3620         (gnus-kill-or-deaden-summary kill-buffer))
3621       (if (not quit-config)
3622           (progn
3623             (set-buffer gnus-group-buffer)
3624             (gnus-group-jump-to-group group)
3625             (gnus-group-next-unread-group 1)
3626             (gnus-configure-windows 'group 'force))
3627         (gnus-handle-ephemeral-exit quit-config))
3628       ;; Finally signal the quit.
3629       (signal 'quit nil))
3630      ;; The group was successfully selected.
3631      (t
3632       (gnus-set-global-variables)
3633       ;; Save the active value in effect when the group was entered.
3634       (setq gnus-newsgroup-active
3635             (gnus-copy-sequence
3636              (gnus-active gnus-newsgroup-name)))
3637       ;; You can change the summary buffer in some way with this hook.
3638       (gnus-run-hooks 'gnus-select-group-hook)
3639       (when (memq 'summary (gnus-update-format-specifications
3640                             nil 'summary 'summary-mode 'summary-dummy))
3641         ;; The format specification for the summary line was updated,
3642         ;; so we need to update the mark positions as well.
3643         (gnus-update-summary-mark-positions))
3644       ;; Do score processing.
3645       (when gnus-use-scoring
3646         (gnus-possibly-score-headers))
3647       ;; Check whether to fill in the gaps in the threads.
3648       (when gnus-build-sparse-threads
3649         (gnus-build-sparse-threads))
3650       ;; Find the initial limit.
3651       (if show-all
3652           (let ((gnus-newsgroup-dormant nil))
3653             (gnus-summary-initial-limit show-all))
3654         (gnus-summary-initial-limit show-all))
3655       ;; Generate the summary buffer.
3656       (unless no-display
3657         (gnus-summary-prepare))
3658       (when gnus-use-trees
3659         (gnus-tree-open group)
3660         (setq gnus-summary-highlight-line-function
3661               'gnus-tree-highlight-article))
3662       ;; If the summary buffer is empty, but there are some low-scored
3663       ;; articles or some excluded dormants, we include these in the
3664       ;; buffer.
3665       (when (and (zerop (buffer-size))
3666                  (not no-display))
3667         (cond (gnus-newsgroup-dormant
3668                (gnus-summary-limit-include-dormant))
3669               ((and gnus-newsgroup-scored show-all)
3670                (gnus-summary-limit-include-expunged t))))
3671       ;; Function `gnus-apply-kill-file' must be called in this hook.
3672       (gnus-run-hooks 'gnus-apply-kill-hook)
3673       (if (and (zerop (buffer-size))
3674                (not no-display))
3675           (progn
3676             ;; This newsgroup is empty.
3677             (gnus-summary-catchup-and-exit nil t)
3678             (gnus-message 6 "No unread news")
3679             (when kill-buffer
3680               (gnus-kill-or-deaden-summary kill-buffer))
3681             ;; Return nil from this function.
3682             nil)
3683         ;; Hide conversation thread subtrees.  We cannot do this in
3684         ;; gnus-summary-prepare-hook since kill processing may not
3685         ;; work with hidden articles.
3686         (gnus-summary-maybe-hide-threads)
3687         (when kill-buffer
3688           (gnus-kill-or-deaden-summary kill-buffer))
3689         (gnus-summary-auto-select-subject)
3690         ;; Show first unread article if requested.
3691         (if (and (not no-article)
3692                  (not no-display)
3693                  gnus-newsgroup-unreads
3694                  gnus-auto-select-first)
3695             (progn
3696               (gnus-configure-windows 'summary)
3697               (let ((art (gnus-summary-article-number)))
3698                 (unless (and (not gnus-plugged)
3699                              (or (memq art gnus-newsgroup-undownloaded)
3700                                  (memq art gnus-newsgroup-downloadable)))
3701                   (gnus-summary-goto-article art))))
3702           ;; Don't select any articles.
3703           (gnus-summary-position-point)
3704           (gnus-configure-windows 'summary 'force)
3705           (gnus-set-mode-line 'summary))
3706         (when (and gnus-auto-center-group
3707                    (get-buffer-window gnus-group-buffer t))
3708           ;; Gotta use windows, because recenter does weird stuff if
3709           ;; the current buffer ain't the displayed window.
3710           (let ((owin (selected-window)))
3711             (select-window (get-buffer-window gnus-group-buffer t))
3712             (when (gnus-group-goto-group group)
3713               (recenter))
3714             (select-window owin)))
3715         ;; Mark this buffer as "prepared".
3716         (setq gnus-newsgroup-prepared t)
3717         (gnus-run-hooks 'gnus-summary-prepared-hook)
3718         (unless (gnus-ephemeral-group-p group)
3719           (gnus-group-update-group group))
3720         t)))))
3721
3722 (defun gnus-summary-auto-select-subject ()
3723   "Select the subject line on initial group entry."
3724   (goto-char (point-min))
3725   (cond
3726    ((eq gnus-auto-select-subject 'best)
3727     (gnus-summary-best-unread-subject))
3728    ((eq gnus-auto-select-subject 'unread)
3729     (gnus-summary-first-unread-subject))
3730    ((eq gnus-auto-select-subject 'unseen)
3731     (gnus-summary-first-unseen-subject))
3732    ((eq gnus-auto-select-subject 'unseen-or-unread)
3733     (gnus-summary-first-unseen-or-unread-subject))
3734    ((eq gnus-auto-select-subject 'first)
3735     ;; Do nothing.
3736     )
3737    ((functionp gnus-auto-select-subject)
3738     (funcall gnus-auto-select-subject))))
3739
3740 (defun gnus-summary-prepare ()
3741   "Generate the summary buffer."
3742   (interactive)
3743   (let ((buffer-read-only nil))
3744     (erase-buffer)
3745     (setq gnus-newsgroup-data nil
3746           gnus-newsgroup-data-reverse nil)
3747     (gnus-run-hooks 'gnus-summary-generate-hook)
3748     ;; Generate the buffer, either with threads or without.
3749     (when gnus-newsgroup-headers
3750       (gnus-summary-prepare-threads
3751        (if gnus-show-threads
3752            (gnus-sort-gathered-threads
3753             (funcall gnus-summary-thread-gathering-function
3754                      (gnus-sort-threads
3755                       (gnus-cut-threads (gnus-make-threads)))))
3756          ;; Unthreaded display.
3757          (gnus-sort-articles gnus-newsgroup-headers))))
3758     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3759     ;; Call hooks for modifying summary buffer.
3760     (goto-char (point-min))
3761     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3762
3763 (defsubst gnus-general-simplify-subject (subject)
3764   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3765   (setq subject
3766         (cond
3767          ;; Truncate the subject.
3768          (gnus-simplify-subject-functions
3769           (gnus-map-function gnus-simplify-subject-functions subject))
3770          ((numberp gnus-summary-gather-subject-limit)
3771           (setq subject (gnus-simplify-subject-re subject))
3772           (if (> (length subject) gnus-summary-gather-subject-limit)
3773               (substring subject 0 gnus-summary-gather-subject-limit)
3774             subject))
3775          ;; Fuzzily simplify it.
3776          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3777           (gnus-simplify-subject-fuzzy subject))
3778          ;; Just remove the leading "Re:".
3779          (t
3780           (gnus-simplify-subject-re subject))))
3781
3782   (if (and gnus-summary-gather-exclude-subject
3783            (string-match gnus-summary-gather-exclude-subject subject))
3784       nil                         ; This article shouldn't be gathered
3785     subject))
3786
3787 (defun gnus-summary-simplify-subject-query ()
3788   "Query where the respool algorithm would put this article."
3789   (interactive)
3790   (gnus-summary-select-article)
3791   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3792
3793 (defun gnus-gather-threads-by-subject (threads)
3794   "Gather threads by looking at Subject headers."
3795   (if (not gnus-summary-make-false-root)
3796       threads
3797     (let ((hashtb (gnus-make-hashtable 1024))
3798           (prev threads)
3799           (result threads)
3800           subject hthread whole-subject)
3801       (while threads
3802         (setq subject (gnus-general-simplify-subject
3803                        (setq whole-subject (mail-header-subject
3804                                             (caar threads)))))
3805         (when subject
3806           (if (setq hthread (gnus-gethash subject hashtb))
3807               (progn
3808                 ;; We enter a dummy root into the thread, if we
3809                 ;; haven't done that already.
3810                 (unless (stringp (caar hthread))
3811                   (setcar hthread (list whole-subject (car hthread))))
3812                 ;; We add this new gathered thread to this gathered
3813                 ;; thread.
3814                 (setcdr (car hthread)
3815                         (nconc (cdar hthread) (list (car threads))))
3816                 ;; Remove it from the list of threads.
3817                 (setcdr prev (cdr threads))
3818                 (setq threads prev))
3819             ;; Enter this thread into the hash table.
3820             (gnus-sethash subject
3821                           (if gnus-summary-make-false-root-always
3822                               (progn
3823                                 ;; If you want a dummy root above all
3824                                 ;; threads...
3825                                 (setcar threads (list whole-subject
3826                                                       (car threads)))
3827                                 threads)
3828                             threads)
3829                           hashtb)))
3830         (setq prev threads)
3831         (setq threads (cdr threads)))
3832       result)))
3833
3834 (defun gnus-gather-threads-by-references (threads)
3835   "Gather threads by looking at References headers."
3836   (let ((idhashtb (gnus-make-hashtable 1024))
3837         (thhashtb (gnus-make-hashtable 1024))
3838         (prev threads)
3839         (result threads)
3840         ids references id gthread gid entered ref)
3841     (while threads
3842       (when (setq references (mail-header-references (caar threads)))
3843         (setq id (mail-header-id (caar threads))
3844               ids (inline (gnus-split-references references))
3845               entered nil)
3846         (while (setq ref (pop ids))
3847           (setq ids (delete ref ids))
3848           (if (not (setq gid (gnus-gethash ref idhashtb)))
3849               (progn
3850                 (gnus-sethash ref id idhashtb)
3851                 (gnus-sethash id threads thhashtb))
3852             (setq gthread (gnus-gethash gid thhashtb))
3853             (unless entered
3854               ;; We enter a dummy root into the thread, if we
3855               ;; haven't done that already.
3856               (unless (stringp (caar gthread))
3857                 (setcar gthread (list (mail-header-subject (caar gthread))
3858                                       (car gthread))))
3859               ;; We add this new gathered thread to this gathered
3860               ;; thread.
3861               (setcdr (car gthread)
3862                       (nconc (cdar gthread) (list (car threads)))))
3863             ;; Add it into the thread hash table.
3864             (gnus-sethash id gthread thhashtb)
3865             (setq entered t)
3866             ;; Remove it from the list of threads.
3867             (setcdr prev (cdr threads))
3868             (setq threads prev))))
3869       (setq prev threads)
3870       (setq threads (cdr threads)))
3871     result))
3872
3873 (defun gnus-sort-gathered-threads (threads)
3874   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3875   (let ((result threads))
3876     (while threads
3877       (when (stringp (caar threads))
3878         (setcdr (car threads)
3879                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3880       (setq threads (cdr threads)))
3881     result))
3882
3883 (defun gnus-thread-loop-p (root thread)
3884   "Say whether ROOT is in THREAD."
3885   (let ((stack (list thread))
3886         (infloop 0)
3887         th)
3888     (while (setq thread (pop stack))
3889       (setq th (cdr thread))
3890       (while (and th
3891                   (not (eq (caar th) root)))
3892         (pop th))
3893       (if th
3894           ;; We have found a loop.
3895           (let (ref-dep)
3896             (setcdr thread (delq (car th) (cdr thread)))
3897             (if (boundp (setq ref-dep (intern "none"
3898                                               gnus-newsgroup-dependencies)))
3899                 (setcdr (symbol-value ref-dep)
3900                         (nconc (cdr (symbol-value ref-dep))
3901                                (list (car th))))
3902               (set ref-dep (list nil (car th))))
3903             (setq infloop 1
3904                   stack nil))
3905         ;; Push all the subthreads onto the stack.
3906         (push (cdr thread) stack)))
3907     infloop))
3908
3909 (defun gnus-make-threads ()
3910   "Go through the dependency hashtb and find the roots.  Return all threads."
3911   (let (threads)
3912     (while (catch 'infloop
3913              (mapatoms
3914               (lambda (refs)
3915                 ;; Deal with self-referencing References loops.
3916                 (when (and (car (symbol-value refs))
3917                            (not (zerop
3918                                  (apply
3919                                   '+
3920                                   (mapcar
3921                                    (lambda (thread)
3922                                      (gnus-thread-loop-p
3923                                       (car (symbol-value refs)) thread))
3924                                    (cdr (symbol-value refs)))))))
3925                   (setq threads nil)
3926                   (throw 'infloop t))
3927                 (unless (car (symbol-value refs))
3928                   ;; These threads do not refer back to any other
3929                   ;; articles, so they're roots.
3930                   (setq threads (append (cdr (symbol-value refs)) threads))))
3931               gnus-newsgroup-dependencies)))
3932     threads))
3933
3934 ;; Build the thread tree.
3935 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3936   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3937
3938 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3939 if it was already present.
3940
3941 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3942 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3943 Message-IDs will be renamed to a unique Message-ID before being
3944 entered.
3945
3946 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3947   (let* ((id (mail-header-id header))
3948          (id-dep (and id (intern id dependencies)))
3949          parent-id ref ref-dep ref-header replaced)
3950     ;; Enter this `header' in the `dependencies' table.
3951     (cond
3952      ((not id-dep)
3953       (setq header nil))
3954      ;; The first two cases do the normal part: enter a new `header'
3955      ;; in the `dependencies' table.
3956      ((not (boundp id-dep))
3957       (set id-dep (list header)))
3958      ((null (car (symbol-value id-dep)))
3959       (setcar (symbol-value id-dep) header))
3960
3961      ;; From here the `header' was already present in the
3962      ;; `dependencies' table.
3963      (force-new
3964       ;; Overrides an existing entry;
3965       ;; just set the header part of the entry.
3966       (setcar (symbol-value id-dep) header)
3967       (setq replaced t))
3968
3969      ;; Renames the existing `header' to a unique Message-ID.
3970      ((not gnus-summary-ignore-duplicates)
3971       ;; An article with this Message-ID has already been seen.
3972       ;; We rename the Message-ID.
3973       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3974            (list header))
3975       (mail-header-set-id header id))
3976
3977      ;; The last case ignores an existing entry, except it adds any
3978      ;; additional Xrefs (in case the two articles came from different
3979      ;; servers.
3980      ;; Also sets `header' to `nil' meaning that the `dependencies'
3981      ;; table was *not* modified.
3982      (t
3983       (mail-header-set-xref
3984        (car (symbol-value id-dep))
3985        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3986                    "")
3987                (or (mail-header-xref header) "")))
3988       (setq header nil)))
3989
3990     (when (and header (not replaced))
3991       ;; First check that we are not creating a References loop.
3992       (setq parent-id (gnus-parent-id (mail-header-references header)))
3993       (setq ref parent-id)
3994       (while (and ref
3995                   (setq ref-dep (intern-soft ref dependencies))
3996                   (boundp ref-dep)
3997                   (setq ref-header (car (symbol-value ref-dep))))
3998         (if (string= id ref)
3999             ;; Yuk!  This is a reference loop.  Make the article be a
4000             ;; root article.
4001             (progn
4002               (mail-header-set-references (car (symbol-value id-dep)) "none")
4003               (setq ref nil)
4004               (setq parent-id nil))
4005           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4006       (setq ref-dep (intern (or parent-id "none") dependencies))
4007       (if (boundp ref-dep)
4008           (setcdr (symbol-value ref-dep)
4009                   (nconc (cdr (symbol-value ref-dep))
4010                          (list (symbol-value id-dep))))
4011         (set ref-dep (list nil (symbol-value id-dep)))))
4012     header))
4013
4014 (defun gnus-extract-message-id-from-in-reply-to (string)
4015   (if (string-match "<[^>]+>" string)
4016       (substring string (match-beginning 0) (match-end 0))
4017     nil))
4018
4019 (defun gnus-build-sparse-threads ()
4020   (let ((headers gnus-newsgroup-headers)
4021         (mail-parse-charset gnus-newsgroup-charset)
4022         (gnus-summary-ignore-duplicates t)
4023         header references generation relations
4024         subject child end new-child date)
4025     ;; First we create an alist of generations/relations, where
4026     ;; generations is how much we trust the relation, and the relation
4027     ;; is parent/child.
4028     (gnus-message 7 "Making sparse threads...")
4029     (save-excursion
4030       (nnheader-set-temp-buffer " *gnus sparse threads*")
4031       (while (setq header (pop headers))
4032         (when (and (setq references (mail-header-references header))
4033                    (not (string= references "")))
4034           (insert references)
4035           (setq child (mail-header-id header)
4036                 subject (mail-header-subject header)
4037                 date (mail-header-date header)
4038                 generation 0)
4039           (while (search-backward ">" nil t)
4040             (setq end (1+ (point)))
4041             (when (search-backward "<" nil t)
4042               (setq new-child (buffer-substring (point) end))
4043               (push (list (incf generation)
4044                           child (setq child new-child)
4045                           subject date)
4046                     relations)))
4047           (when child
4048             (push (list (1+ generation) child nil subject) relations))
4049           (erase-buffer)))
4050       (kill-buffer (current-buffer)))
4051     ;; Sort over trustworthiness.
4052     (mapcar
4053      (lambda (relation)
4054        (when (gnus-dependencies-add-header
4055               (make-full-mail-header
4056                gnus-reffed-article-number
4057                (nth 3 relation) "" (or (nth 4 relation) "")
4058                (nth 1 relation)
4059                (or (nth 2 relation) "") 0 0 "")
4060               gnus-newsgroup-dependencies nil)
4061          (push gnus-reffed-article-number gnus-newsgroup-limit)
4062          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4063          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4064                gnus-newsgroup-reads)
4065          (decf gnus-reffed-article-number)))
4066      (sort relations 'car-less-than-car))
4067     (gnus-message 7 "Making sparse threads...done")))
4068
4069 (defun gnus-build-old-threads ()
4070   ;; Look at all the articles that refer back to old articles, and
4071   ;; fetch the headers for the articles that aren't there.  This will
4072   ;; build complete threads - if the roots haven't been expired by the
4073   ;; server, that is.
4074   (let ((mail-parse-charset gnus-newsgroup-charset)
4075         id heads)
4076     (mapatoms
4077      (lambda (refs)
4078        (when (not (car (symbol-value refs)))
4079          (setq heads (cdr (symbol-value refs)))
4080          (while heads
4081            (if (memq (mail-header-number (caar heads))
4082                      gnus-newsgroup-dormant)
4083                (setq heads (cdr heads))
4084              (setq id (symbol-name refs))
4085              (while (and (setq id (gnus-build-get-header id))
4086                          (not (car (gnus-id-to-thread id)))))
4087              (setq heads nil)))))
4088      gnus-newsgroup-dependencies)))
4089
4090 (defsubst gnus-remove-odd-characters (string)
4091   "Translate STRING into something that doesn't contain weird characters."
4092   (mm-subst-char-in-string
4093    ?\r ?\-
4094    (mm-subst-char-in-string ?\n ?\- string t) t))
4095
4096 ;; This function has to be called with point after the article number
4097 ;; on the beginning of the line.
4098 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4099   (let ((eol (point-at-eol))
4100         (buffer (current-buffer))
4101         header references in-reply-to)
4102
4103     ;; overview: [num subject from date id refs chars lines misc]
4104     (unwind-protect
4105         (let (x)
4106           (narrow-to-region (point) eol)
4107           (unless (eobp)
4108             (forward-char))
4109
4110           (setq header
4111                 (make-full-mail-header
4112                  number                 ; number
4113                  (condition-case ()     ; subject
4114                      (gnus-remove-odd-characters
4115                       (funcall gnus-decode-encoded-word-function
4116                                (setq x (nnheader-nov-field))))
4117                    (error x))
4118                  (condition-case ()     ; from
4119                      (gnus-remove-odd-characters
4120                       (funcall gnus-decode-encoded-word-function
4121                                (setq x (nnheader-nov-field))))
4122                    (error x))
4123                  (nnheader-nov-field)   ; date
4124                  (nnheader-nov-read-message-id number)  ; id
4125                  (setq references (nnheader-nov-field)) ; refs
4126                  (nnheader-nov-read-integer) ; chars
4127                  (nnheader-nov-read-integer) ; lines
4128                  (unless (eobp)
4129                    (if (looking-at "Xref: ")
4130                        (goto-char (match-end 0)))
4131                    (nnheader-nov-field)) ; Xref
4132                  (nnheader-nov-parse-extra)))) ; extra
4133
4134       (widen))
4135
4136     (when (and (string= references "")
4137                (setq in-reply-to (mail-header-extra header))
4138                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4139       (mail-header-set-references
4140        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4141
4142     (when gnus-alter-header-function
4143       (funcall gnus-alter-header-function header))
4144     (gnus-dependencies-add-header header dependencies force-new)))
4145
4146 (defun gnus-build-get-header (id)
4147   "Look through the buffer of NOV lines and find the header to ID.
4148 Enter this line into the dependencies hash table, and return
4149 the id of the parent article (if any)."
4150   (let ((deps gnus-newsgroup-dependencies)
4151         found header)
4152     (prog1
4153         (save-excursion
4154           (set-buffer nntp-server-buffer)
4155           (let ((case-fold-search nil))
4156             (goto-char (point-min))
4157             (while (and (not found)
4158                         (search-forward id nil t))
4159               (beginning-of-line)
4160               (setq found (looking-at
4161                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4162                                    (regexp-quote id))))
4163               (or found (beginning-of-line 2)))
4164             (when found
4165               (beginning-of-line)
4166               (and
4167                (setq header (gnus-nov-parse-line
4168                              (read (current-buffer)) deps))
4169                (gnus-parent-id (mail-header-references header))))))
4170       (when header
4171         (let ((number (mail-header-number header)))
4172           (push number gnus-newsgroup-limit)
4173           (push header gnus-newsgroup-headers)
4174           (if (memq number gnus-newsgroup-unselected)
4175               (progn
4176                 (setq gnus-newsgroup-unreads
4177                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4178                                                number))
4179                 (setq gnus-newsgroup-unselected
4180                       (delq number gnus-newsgroup-unselected)))
4181             (push number gnus-newsgroup-ancient)))))))
4182
4183 (defun gnus-build-all-threads ()
4184   "Read all the headers."
4185   (let ((gnus-summary-ignore-duplicates t)
4186         (mail-parse-charset gnus-newsgroup-charset)
4187         (dependencies gnus-newsgroup-dependencies)
4188         header article)
4189     (save-excursion
4190       (set-buffer nntp-server-buffer)
4191       (let ((case-fold-search nil))
4192         (goto-char (point-min))
4193         (while (not (eobp))
4194           (ignore-errors
4195             (setq article (read (current-buffer))
4196                   header (gnus-nov-parse-line article dependencies)))
4197           (when header
4198             (with-current-buffer gnus-summary-buffer
4199               (push header gnus-newsgroup-headers)
4200               (if (memq (setq article (mail-header-number header))
4201                         gnus-newsgroup-unselected)
4202                   (progn
4203                     (setq gnus-newsgroup-unreads
4204                           (gnus-add-to-sorted-list
4205                            gnus-newsgroup-unreads article))
4206                     (setq gnus-newsgroup-unselected
4207                           (delq article gnus-newsgroup-unselected)))
4208                 (push article gnus-newsgroup-ancient)))
4209             (forward-line 1)))))))
4210
4211 (defun gnus-summary-update-article-line (article header)
4212   "Update the line for ARTICLE using HEADER."
4213   (let* ((id (mail-header-id header))
4214          (thread (gnus-id-to-thread id)))
4215     (unless thread
4216       (error "Article in no thread"))
4217     ;; Update the thread.
4218     (setcar thread header)
4219     (gnus-summary-goto-subject article)
4220     (let* ((datal (gnus-data-find-list article))
4221            (data (car datal))
4222            (buffer-read-only nil)
4223            (level (gnus-summary-thread-level)))
4224       (gnus-delete-line)
4225       (let ((inserted (- (point)
4226                          (progn
4227                            (gnus-summary-insert-line
4228                             header level nil
4229                             (memq article gnus-newsgroup-undownloaded)
4230                             (gnus-article-mark article)
4231                             (memq article gnus-newsgroup-replied)
4232                             (memq article gnus-newsgroup-expirable)
4233                             ;; Only insert the Subject string when it's different
4234                             ;; from the previous Subject string.
4235                             (if (and
4236                                  gnus-show-threads
4237                                  (gnus-subject-equal
4238                                   (condition-case ()
4239                                       (mail-header-subject
4240                                        (gnus-data-header
4241                                         (cadr
4242                                          (gnus-data-find-list
4243                                           article
4244                                           (gnus-data-list t)))))
4245                                     ;; Error on the side of excessive subjects.
4246                                     (error ""))
4247                                   (mail-header-subject header)))
4248                                 ""
4249                               (mail-header-subject header))
4250                             nil (cdr (assq article gnus-newsgroup-scored))
4251                             (memq article gnus-newsgroup-processable))
4252                            (point)))))
4253         (when (cdr datal)
4254           (gnus-data-update-list
4255            (cdr datal)
4256            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4257
4258 (defun gnus-summary-update-article (article &optional iheader)
4259   "Update ARTICLE in the summary buffer."
4260   (set-buffer gnus-summary-buffer)
4261   (let* ((header (gnus-summary-article-header article))
4262          (id (mail-header-id header))
4263          (data (gnus-data-find article))
4264          (thread (gnus-id-to-thread id))
4265          (references (mail-header-references header))
4266          (parent
4267           (gnus-id-to-thread
4268            (or (gnus-parent-id
4269                 (when (and references
4270                            (not (equal "" references)))
4271                   references))
4272                "none")))
4273          (buffer-read-only nil)
4274          (old (car thread)))
4275     (when thread
4276       (unless iheader
4277         (setcar thread nil)
4278         (when parent
4279           (delq thread parent)))
4280       (if (gnus-summary-insert-subject id header)
4281           ;; Set the (possibly) new article number in the data structure.
4282           (gnus-data-set-number data (gnus-id-to-article id))
4283         (setcar thread old)
4284         nil))))
4285
4286 (defun gnus-rebuild-thread (id &optional line)
4287   "Rebuild the thread containing ID.
4288 If LINE, insert the rebuilt thread starting on line LINE."
4289   (let ((buffer-read-only nil)
4290         old-pos current thread data)
4291     (if (not gnus-show-threads)
4292         (setq thread (list (car (gnus-id-to-thread id))))
4293       ;; Get the thread this article is part of.
4294       (setq thread (gnus-remove-thread id)))
4295     (setq old-pos (point-at-bol))
4296     (setq current (save-excursion
4297                     (and (re-search-backward "[\r\n]" nil t)
4298                          (gnus-summary-article-number))))
4299     ;; If this is a gathered thread, we have to go some re-gathering.
4300     (when (stringp (car thread))
4301       (let ((subject (car thread))
4302             roots thr)
4303         (setq thread (cdr thread))
4304         (while thread
4305           (unless (memq (setq thr (gnus-id-to-thread
4306                                    (gnus-root-id
4307                                     (mail-header-id (caar thread)))))
4308                         roots)
4309             (push thr roots))
4310           (setq thread (cdr thread)))
4311         ;; We now have all (unique) roots.
4312         (if (= (length roots) 1)
4313             ;; All the loose roots are now one solid root.
4314             (setq thread (car roots))
4315           (setq thread (cons subject (gnus-sort-threads roots))))))
4316     (let (threads)
4317       ;; We then insert this thread into the summary buffer.
4318       (when line
4319         (goto-char (point-min))
4320         (forward-line (1- line)))
4321       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4322         (if gnus-show-threads
4323             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4324           (gnus-summary-prepare-unthreaded thread))
4325         (setq data (nreverse gnus-newsgroup-data))
4326         (setq threads gnus-newsgroup-threads))
4327       ;; We splice the new data into the data structure.
4328       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4329       ;;!!! then we want to insert at the beginning of the buffer.
4330       ;;!!! That happens to be true with Gnus now, but that may
4331       ;;!!! change in the future.  Perhaps.
4332       (gnus-data-enter-list
4333        (if line nil current) data (- (point) old-pos))
4334       (setq gnus-newsgroup-threads
4335             (nconc threads gnus-newsgroup-threads))
4336       (gnus-data-compute-positions))))
4337
4338 (defun gnus-number-to-header (number)
4339   "Return the header for article NUMBER."
4340   (let ((headers gnus-newsgroup-headers))
4341     (while (and headers
4342                 (not (= number (mail-header-number (car headers)))))
4343       (pop headers))
4344     (when headers
4345       (car headers))))
4346
4347 (defun gnus-parent-headers (in-headers &optional generation)
4348   "Return the headers of the GENERATIONeth parent of HEADERS."
4349   (unless generation
4350     (setq generation 1))
4351   (let ((parent t)
4352         (headers in-headers)
4353         references)
4354     (while (and parent
4355                 (not (zerop generation))
4356                 (setq references (mail-header-references headers)))
4357       (setq headers (if (and references
4358                              (setq parent (gnus-parent-id references)))
4359                         (car (gnus-id-to-thread parent))
4360                       nil))
4361       (decf generation))
4362     (and (not (eq headers in-headers))
4363          headers)))
4364
4365 (defun gnus-id-to-thread (id)
4366   "Return the (sub-)thread where ID appears."
4367   (gnus-gethash id gnus-newsgroup-dependencies))
4368
4369 (defun gnus-id-to-article (id)
4370   "Return the article number of ID."
4371   (let ((thread (gnus-id-to-thread id)))
4372     (when (and thread
4373                (car thread))
4374       (mail-header-number (car thread)))))
4375
4376 (defun gnus-id-to-header (id)
4377   "Return the article headers of ID."
4378   (car (gnus-id-to-thread id)))
4379
4380 (defun gnus-article-displayed-root-p (article)
4381   "Say whether ARTICLE is a root(ish) article."
4382   (let ((level (gnus-summary-thread-level article))
4383         (refs (mail-header-references  (gnus-summary-article-header article)))
4384         particle)
4385     (cond
4386      ((null level) nil)
4387      ((zerop level) t)
4388      ((null refs) t)
4389      ((null (gnus-parent-id refs)) t)
4390      ((and (= 1 level)
4391            (null (setq particle (gnus-id-to-article
4392                                  (gnus-parent-id refs))))
4393            (null (gnus-summary-thread-level particle)))))))
4394
4395 (defun gnus-root-id (id)
4396   "Return the id of the root of the thread where ID appears."
4397   (let (last-id prev)
4398     (while (and id (setq prev (car (gnus-id-to-thread id))))
4399       (setq last-id id
4400             id (gnus-parent-id (mail-header-references prev))))
4401     last-id))
4402
4403 (defun gnus-articles-in-thread (thread)
4404   "Return the list of articles in THREAD."
4405   (cons (mail-header-number (car thread))
4406         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4407
4408 (defun gnus-remove-thread (id &optional dont-remove)
4409   "Remove the thread that has ID in it."
4410   (let (headers thread last-id)
4411     ;; First go up in this thread until we find the root.
4412     (setq last-id (gnus-root-id id)
4413           headers (message-flatten-list (gnus-id-to-thread last-id)))
4414     ;; We have now found the real root of this thread.  It might have
4415     ;; been gathered into some loose thread, so we have to search
4416     ;; through the threads to find the thread we wanted.
4417     (let ((threads gnus-newsgroup-threads)
4418           sub)
4419       (while threads
4420         (setq sub (car threads))
4421         (if (stringp (car sub))
4422             ;; This is a gathered thread, so we look at the roots
4423             ;; below it to find whether this article is in this
4424             ;; gathered root.
4425             (progn
4426               (setq sub (cdr sub))
4427               (while sub
4428                 (when (member (caar sub) headers)
4429                   (setq thread (car threads)
4430                         threads nil
4431                         sub nil))
4432                 (setq sub (cdr sub))))
4433           ;; It's an ordinary thread, so we check it.
4434           (when (eq (car sub) (car headers))
4435             (setq thread sub
4436                   threads nil)))
4437         (setq threads (cdr threads)))
4438       ;; If this article is in no thread, then it's a root.
4439       (if thread
4440           (unless dont-remove
4441             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4442         (setq thread (gnus-id-to-thread last-id)))
4443       (when thread
4444         (prog1
4445             thread                      ; We return this thread.
4446           (unless dont-remove
4447             (if (stringp (car thread))
4448                 (progn
4449                   ;; If we use dummy roots, then we have to remove the
4450                   ;; dummy root as well.
4451                   (when (eq gnus-summary-make-false-root 'dummy)
4452                     ;; We go to the dummy root by going to
4453                     ;; the first sub-"thread", and then one line up.
4454                     (gnus-summary-goto-article
4455                      (mail-header-number (caadr thread)))
4456                     (forward-line -1)
4457                     (gnus-delete-line)
4458                     (gnus-data-compute-positions))
4459                   (setq thread (cdr thread))
4460                   (while thread
4461                     (gnus-remove-thread-1 (car thread))
4462                     (setq thread (cdr thread))))
4463               (gnus-remove-thread-1 thread))))))))
4464
4465 (defun gnus-remove-thread-1 (thread)
4466   "Remove the thread THREAD recursively."
4467   (let ((number (mail-header-number (pop thread)))
4468         d)
4469     (setq thread (reverse thread))
4470     (while thread
4471       (gnus-remove-thread-1 (pop thread)))
4472     (when (setq d (gnus-data-find number))
4473       (goto-char (gnus-data-pos d))
4474       (gnus-summary-show-thread)
4475       (gnus-data-remove
4476        number
4477        (- (point-at-bol)
4478           (prog1
4479               (1+ (point-at-eol))
4480             (gnus-delete-line)))))))
4481
4482 (defun gnus-sort-threads-1 (threads func)
4483   (sort (mapcar (lambda (thread)
4484                   (cons (car thread)
4485                         (and (cdr thread)
4486                              (gnus-sort-threads-1 (cdr thread) func))))
4487                 threads) func))
4488
4489 (defun gnus-sort-threads (threads)
4490   "Sort THREADS."
4491   (if (not gnus-thread-sort-functions)
4492       threads
4493     (gnus-message 8 "Sorting threads...")
4494     (let ((max-lisp-eval-depth 5000))
4495       (prog1 (gnus-sort-threads-1
4496          threads
4497          (gnus-make-sort-function gnus-thread-sort-functions))
4498         (gnus-message 8 "Sorting threads...done")))))
4499
4500 (defun gnus-sort-articles (articles)
4501   "Sort ARTICLES."
4502   (when gnus-article-sort-functions
4503     (gnus-message 7 "Sorting articles...")
4504     (prog1
4505         (setq gnus-newsgroup-headers
4506               (sort articles (gnus-make-sort-function
4507                               gnus-article-sort-functions)))
4508       (gnus-message 7 "Sorting articles...done"))))
4509
4510 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4511 (defmacro gnus-thread-header (thread)
4512   "Return header of first article in THREAD.
4513 Note that THREAD must never, ever be anything else than a variable -
4514 using some other form will lead to serious barfage."
4515   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4516   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4517   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4518         (vector thread) 2))
4519
4520 (defsubst gnus-article-sort-by-number (h1 h2)
4521   "Sort articles by article number."
4522   (< (mail-header-number h1)
4523      (mail-header-number h2)))
4524
4525 (defun gnus-thread-sort-by-number (h1 h2)
4526   "Sort threads by root article number."
4527   (gnus-article-sort-by-number
4528    (gnus-thread-header h1) (gnus-thread-header h2)))
4529
4530 (defsubst gnus-article-sort-by-random (h1 h2)
4531   "Sort articles by article number."
4532   (zerop (random 2)))
4533
4534 (defun gnus-thread-sort-by-random (h1 h2)
4535   "Sort threads by root article number."
4536   (gnus-article-sort-by-random
4537    (gnus-thread-header h1) (gnus-thread-header h2)))
4538
4539 (defsubst gnus-article-sort-by-lines (h1 h2)
4540   "Sort articles by article Lines header."
4541   (< (mail-header-lines h1)
4542      (mail-header-lines h2)))
4543
4544 (defun gnus-thread-sort-by-lines (h1 h2)
4545   "Sort threads by root article Lines header."
4546   (gnus-article-sort-by-lines
4547    (gnus-thread-header h1) (gnus-thread-header h2)))
4548
4549 (defsubst gnus-article-sort-by-chars (h1 h2)
4550   "Sort articles by octet length."
4551   (< (mail-header-chars h1)
4552      (mail-header-chars h2)))
4553
4554 (defun gnus-thread-sort-by-chars (h1 h2)
4555   "Sort threads by root article octet length."
4556   (gnus-article-sort-by-chars
4557    (gnus-thread-header h1) (gnus-thread-header h2)))
4558
4559 (defsubst gnus-article-sort-by-author (h1 h2)
4560   "Sort articles by root author."
4561   (string-lessp
4562    (let ((extract (funcall
4563                    gnus-extract-address-components
4564                    (mail-header-from h1))))
4565      (or (car extract) (cadr extract) ""))
4566    (let ((extract (funcall
4567                    gnus-extract-address-components
4568                    (mail-header-from h2))))
4569      (or (car extract) (cadr extract) ""))))
4570
4571 (defun gnus-thread-sort-by-author (h1 h2)
4572   "Sort threads by root author."
4573   (gnus-article-sort-by-author
4574    (gnus-thread-header h1)  (gnus-thread-header h2)))
4575
4576 (defsubst gnus-article-sort-by-recipient (h1 h2)
4577   "Sort articles by recipient."
4578   (string-lessp
4579    (let ((extract (funcall
4580                    gnus-extract-address-components
4581                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4582      (or (car extract) (cadr extract)))
4583    (let ((extract (funcall
4584                    gnus-extract-address-components
4585                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4586      (or (car extract) (cadr extract)))))
4587
4588 (defsubst gnus-article-sort-by-subject (h1 h2)
4589   "Sort articles by root subject."
4590   (string-lessp
4591    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4592    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4593
4594 (defun gnus-thread-sort-by-subject (h1 h2)
4595   "Sort threads by root subject."
4596   (gnus-article-sort-by-subject
4597    (gnus-thread-header h1) (gnus-thread-header h2)))
4598
4599 (defsubst gnus-article-sort-by-date (h1 h2)
4600   "Sort articles by root article date."
4601   (time-less-p
4602    (gnus-date-get-time (mail-header-date h1))
4603    (gnus-date-get-time (mail-header-date h2))))
4604
4605 (defun gnus-thread-sort-by-date (h1 h2)
4606   "Sort threads by root article date."
4607   (gnus-article-sort-by-date
4608    (gnus-thread-header h1) (gnus-thread-header h2)))
4609
4610 (defsubst gnus-article-sort-by-score (h1 h2)
4611   "Sort articles by root article score.
4612 Unscored articles will be counted as having a score of zero."
4613   (> (or (cdr (assq (mail-header-number h1)
4614                     gnus-newsgroup-scored))
4615          gnus-summary-default-score 0)
4616      (or (cdr (assq (mail-header-number h2)
4617                     gnus-newsgroup-scored))
4618          gnus-summary-default-score 0)))
4619
4620 (defun gnus-thread-sort-by-score (h1 h2)
4621   "Sort threads by root article score."
4622   (gnus-article-sort-by-score
4623    (gnus-thread-header h1) (gnus-thread-header h2)))
4624
4625 (defun gnus-thread-sort-by-total-score (h1 h2)
4626   "Sort threads by the sum of all scores in the thread.
4627 Unscored articles will be counted as having a score of zero."
4628   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4629
4630 (defun gnus-thread-total-score (thread)
4631   ;; This function find the total score of THREAD.
4632   (cond
4633    ((null thread)
4634     0)
4635    ((consp thread)
4636     (if (stringp (car thread))
4637         (apply gnus-thread-score-function 0
4638                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4639       (gnus-thread-total-score-1 thread)))
4640    (t
4641     (gnus-thread-total-score-1 (list thread)))))
4642
4643 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4644   "Sort threads such that the thread with the most recently arrived article comes first."
4645   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4646
4647 (defun gnus-thread-highest-number (thread)
4648   "Return the highest article number in THREAD."
4649   (apply 'max (mapcar (lambda (header)
4650                         (mail-header-number header))
4651                       (message-flatten-list thread))))
4652
4653 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4654   "Sort threads such that the thread with the most recently dated article comes first."
4655   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4656
4657 (defun gnus-thread-latest-date (thread)
4658   "Return the highest article date in THREAD."
4659   (let ((previous-time 0))
4660     (apply 'max
4661            (mapcar
4662             (lambda (header)
4663               (setq previous-time
4664                     (condition-case ()
4665                         (time-to-seconds (mail-header-parse-date
4666                                           (mail-header-date header)))
4667                       (error previous-time))))
4668             (sort
4669              (message-flatten-list thread)
4670              (lambda (h1 h2)
4671                (< (mail-header-number h1)
4672                   (mail-header-number h2))))))))
4673
4674 (defun gnus-thread-total-score-1 (root)
4675   ;; This function find the total score of the thread below ROOT.
4676   (setq root (car root))
4677   (apply gnus-thread-score-function
4678          (or (append
4679               (mapcar 'gnus-thread-total-score
4680                       (cdr (gnus-id-to-thread (mail-header-id root))))
4681               (when (> (mail-header-number root) 0)
4682                 (list (or (cdr (assq (mail-header-number root)
4683                                      gnus-newsgroup-scored))
4684                           gnus-summary-default-score 0))))
4685              (list gnus-summary-default-score)
4686              '(0))))
4687
4688 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4689 (defvar gnus-tmp-prev-subject nil)
4690 (defvar gnus-tmp-false-parent nil)
4691 (defvar gnus-tmp-root-expunged nil)
4692 (defvar gnus-tmp-dummy-line nil)
4693
4694 (eval-when-compile (defvar gnus-tmp-header))
4695 (defun gnus-extra-header (type &optional header)
4696   "Return the extra header of TYPE."
4697   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4698       ""))
4699
4700 (defvar gnus-tmp-thread-tree-header-string "")
4701
4702 (defcustom gnus-sum-thread-tree-root "> "
4703   "With %B spec, used for the root of a thread.
4704 If nil, use subject instead."
4705   :version "21.4"
4706   :type '(radio (const :format "%v  " nil) string)
4707   :group 'gnus-thread)
4708 (defcustom gnus-sum-thread-tree-false-root "> "
4709   "With %B spec, used for a false root of a thread.
4710 If nil, use subject instead."
4711   :version "21.4"
4712   :type '(radio (const :format "%v  " nil) string)
4713   :group 'gnus-thread)
4714 (defcustom gnus-sum-thread-tree-single-indent ""
4715   "With %B spec, used for a thread with just one message.
4716 If nil, use subject instead."
4717   :version "21.4"
4718   :type '(radio (const :format "%v  " nil) string)
4719   :group 'gnus-thread)
4720 (defcustom gnus-sum-thread-tree-vertical "| "
4721   "With %B spec, used for drawing a vertical line."
4722   :version "21.4"
4723   :type 'string
4724   :group 'gnus-thread)
4725 (defcustom gnus-sum-thread-tree-indent "  "
4726   "With %B spec, used for indenting."
4727   :version "21.4"
4728   :type 'string
4729   :group 'gnus-thread)
4730 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4731   "With %B spec, used for a leaf with brothers."
4732   :version "21.4"
4733   :type 'string
4734   :group 'gnus-thread)
4735 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4736   "With %B spec, used for a leaf without brothers."
4737   :version "21.4"
4738   :type 'string
4739   :group 'gnus-thread)
4740
4741 (defun gnus-summary-prepare-threads (threads)
4742   "Prepare summary buffer from THREADS and indentation LEVEL.
4743 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4744 or a straight list of headers."
4745   (gnus-message 7 "Generating summary...")
4746
4747   (setq gnus-newsgroup-threads threads)
4748   (beginning-of-line)
4749
4750   (let ((gnus-tmp-level 0)
4751         (default-score (or gnus-summary-default-score 0))
4752         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4753         (building-line-count gnus-summary-display-while-building)
4754         (building-count (integerp gnus-summary-display-while-building))
4755         thread number subject stack state gnus-tmp-gathered beg-match
4756         new-roots gnus-tmp-new-adopts thread-end simp-subject
4757         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4758         gnus-tmp-replied gnus-tmp-subject-or-nil
4759         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4760         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4761         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4762         tree-stack)
4763
4764     (setq gnus-tmp-prev-subject nil
4765           gnus-tmp-thread-tree-header-string "")
4766
4767     (if (vectorp (car threads))
4768         ;; If this is a straight (sic) list of headers, then a
4769         ;; threaded summary display isn't required, so we just create
4770         ;; an unthreaded one.
4771         (gnus-summary-prepare-unthreaded threads)
4772
4773       ;; Do the threaded display.
4774
4775       (if gnus-summary-display-while-building
4776           (switch-to-buffer (buffer-name)))
4777       (while (or threads stack gnus-tmp-new-adopts new-roots)
4778
4779         (if (and (= gnus-tmp-level 0)
4780                  (or (not stack)
4781                      (= (caar stack) 0))
4782                  (not gnus-tmp-false-parent)
4783                  (or gnus-tmp-new-adopts new-roots))
4784             (if gnus-tmp-new-adopts
4785                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4786                       thread (list (car gnus-tmp-new-adopts))
4787                       gnus-tmp-header (caar thread)
4788                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4789               (when new-roots
4790                 (setq thread (list (car new-roots))
4791                       gnus-tmp-header (caar thread)
4792                       new-roots (cdr new-roots))))
4793
4794           (if threads
4795               ;; If there are some threads, we do them before the
4796               ;; threads on the stack.
4797               (setq thread threads
4798                     gnus-tmp-header (caar thread))
4799             ;; There were no current threads, so we pop something off
4800             ;; the stack.
4801             (setq state (car stack)
4802                   gnus-tmp-level (car state)
4803                   tree-stack (cadr state)
4804                   thread (caddr state)
4805                   stack (cdr stack)
4806                   gnus-tmp-header (caar thread))))
4807
4808         (setq gnus-tmp-false-parent nil)
4809         (setq gnus-tmp-root-expunged nil)
4810         (setq thread-end nil)
4811
4812         (if (stringp gnus-tmp-header)
4813             ;; The header is a dummy root.
4814             (cond
4815              ((eq gnus-summary-make-false-root 'adopt)
4816               ;; We let the first article adopt the rest.
4817               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4818                                                (cddar thread)))
4819               (setq gnus-tmp-gathered
4820                     (nconc (mapcar
4821                             (lambda (h) (mail-header-number (car h)))
4822                             (cddar thread))
4823                            gnus-tmp-gathered))
4824               (setq thread (cons (list (caar thread)
4825                                        (cadar thread))
4826                                  (cdr thread)))
4827               (setq gnus-tmp-level -1
4828                     gnus-tmp-false-parent t))
4829              ((eq gnus-summary-make-false-root 'empty)
4830               ;; We print adopted articles with empty subject fields.
4831               (setq gnus-tmp-gathered
4832                     (nconc (mapcar
4833                             (lambda (h) (mail-header-number (car h)))
4834                             (cddar thread))
4835                            gnus-tmp-gathered))
4836               (setq gnus-tmp-level -1))
4837              ((eq gnus-summary-make-false-root 'dummy)
4838               ;; We remember that we probably want to output a dummy
4839               ;; root.
4840               (setq gnus-tmp-dummy-line gnus-tmp-header)
4841               (setq gnus-tmp-prev-subject gnus-tmp-header))
4842              (t
4843               ;; We do not make a root for the gathered
4844               ;; sub-threads at all.
4845               (setq gnus-tmp-level -1)))
4846
4847           (setq number (mail-header-number gnus-tmp-header)
4848                 subject (mail-header-subject gnus-tmp-header)
4849                 simp-subject (gnus-simplify-subject-fully subject))
4850
4851           (cond
4852            ;; If the thread has changed subject, we might want to make
4853            ;; this subthread into a root.
4854            ((and (null gnus-thread-ignore-subject)
4855                  (not (zerop gnus-tmp-level))
4856                  gnus-tmp-prev-subject
4857                  (not (string= gnus-tmp-prev-subject simp-subject)))
4858             (setq new-roots (nconc new-roots (list (car thread)))
4859                   thread-end t
4860                   gnus-tmp-header nil))
4861            ;; If the article lies outside the current limit,
4862            ;; then we do not display it.
4863            ((not (memq number gnus-newsgroup-limit))
4864             (setq gnus-tmp-gathered
4865                   (nconc (mapcar
4866                           (lambda (h) (mail-header-number (car h)))
4867                           (cdar thread))
4868                          gnus-tmp-gathered))
4869             (setq gnus-tmp-new-adopts (if (cdar thread)
4870                                           (append gnus-tmp-new-adopts
4871                                                   (cdar thread))
4872                                         gnus-tmp-new-adopts)
4873                   thread-end t
4874                   gnus-tmp-header nil)
4875             (when (zerop gnus-tmp-level)
4876               (setq gnus-tmp-root-expunged t)))
4877            ;; Perhaps this article is to be marked as read?
4878            ((and gnus-summary-mark-below
4879                  (< (or (cdr (assq number gnus-newsgroup-scored))
4880                         default-score)
4881                     gnus-summary-mark-below)
4882                  ;; Don't touch sparse articles.
4883                  (not (gnus-summary-article-sparse-p number))
4884                  (not (gnus-summary-article-ancient-p number)))
4885             (setq gnus-newsgroup-unreads
4886                   (delq number gnus-newsgroup-unreads))
4887             (if gnus-newsgroup-auto-expire
4888                 (setq gnus-newsgroup-expirable
4889                       (gnus-add-to-sorted-list
4890                        gnus-newsgroup-expirable number))
4891               (push (cons number gnus-low-score-mark)
4892                     gnus-newsgroup-reads))))
4893
4894           (when gnus-tmp-header
4895             ;; We may have an old dummy line to output before this
4896             ;; article.
4897             (when (and gnus-tmp-dummy-line
4898                        (gnus-subject-equal
4899                         gnus-tmp-dummy-line
4900                         (mail-header-subject gnus-tmp-header)))
4901               (gnus-summary-insert-dummy-line
4902                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4903               (setq gnus-tmp-dummy-line nil))
4904
4905             ;; Compute the mark.
4906             (setq gnus-tmp-unread (gnus-article-mark number))
4907
4908             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4909                                   gnus-tmp-header gnus-tmp-level)
4910                   gnus-newsgroup-data)
4911
4912             ;; Actually insert the line.
4913             (setq
4914              gnus-tmp-subject-or-nil
4915              (cond
4916               ((and gnus-thread-ignore-subject
4917                     gnus-tmp-prev-subject
4918                     (not (string= gnus-tmp-prev-subject simp-subject)))
4919                subject)
4920               ((zerop gnus-tmp-level)
4921                (if (and (eq gnus-summary-make-false-root 'empty)
4922                         (memq number gnus-tmp-gathered)
4923                         gnus-tmp-prev-subject
4924                         (string= gnus-tmp-prev-subject simp-subject))
4925                    gnus-summary-same-subject
4926                  subject))
4927               (t gnus-summary-same-subject)))
4928             (if (and (eq gnus-summary-make-false-root 'adopt)
4929                      (= gnus-tmp-level 1)
4930                      (memq number gnus-tmp-gathered))
4931                 (setq gnus-tmp-opening-bracket ?\<
4932                       gnus-tmp-closing-bracket ?\>)
4933               (setq gnus-tmp-opening-bracket ?\[
4934                     gnus-tmp-closing-bracket ?\]))
4935             (setq
4936              gnus-tmp-indentation
4937              (aref gnus-thread-indent-array gnus-tmp-level)
4938              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4939              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4940                                 gnus-summary-default-score 0)
4941              gnus-tmp-score-char
4942              (if (or (null gnus-summary-default-score)
4943                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4944                          gnus-summary-zcore-fuzz))
4945                  ?                      ;Whitespace
4946                (if (< gnus-tmp-score gnus-summary-default-score)
4947                    gnus-score-below-mark gnus-score-over-mark))
4948              gnus-tmp-replied
4949              (cond ((memq number gnus-newsgroup-processable)
4950                     gnus-process-mark)
4951                    ((memq number gnus-newsgroup-cached)
4952                     gnus-cached-mark)
4953                    ((memq number gnus-newsgroup-replied)
4954                     gnus-replied-mark)
4955                    ((memq number gnus-newsgroup-forwarded)
4956                     gnus-forwarded-mark)
4957                    ((memq number gnus-newsgroup-saved)
4958                     gnus-saved-mark)
4959                    ((memq number gnus-newsgroup-recent)
4960                     gnus-recent-mark)
4961                    ((memq number gnus-newsgroup-unseen)
4962                     gnus-unseen-mark)
4963                    (t gnus-no-mark))
4964              gnus-tmp-downloaded
4965              (cond ((memq number gnus-newsgroup-undownloaded)
4966                     gnus-undownloaded-mark)
4967                    (gnus-newsgroup-agentized
4968                     gnus-downloaded-mark)
4969                    (t
4970                     gnus-no-mark))
4971              gnus-tmp-from (mail-header-from gnus-tmp-header)
4972              gnus-tmp-name
4973              (cond
4974               ((string-match "<[^>]+> *$" gnus-tmp-from)
4975                (setq beg-match (match-beginning 0))
4976                (or (and (string-match "^\".+\"" gnus-tmp-from)
4977                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4978                    (substring gnus-tmp-from 0 beg-match)))
4979               ((string-match "(.+)" gnus-tmp-from)
4980                (substring gnus-tmp-from
4981                           (1+ (match-beginning 0)) (1- (match-end 0))))
4982               (t gnus-tmp-from))
4983
4984              ;; Do the %B string
4985              gnus-tmp-thread-tree-header-string
4986              (cond
4987               ((not gnus-show-threads) "")
4988               ((zerop gnus-tmp-level)
4989                (cond ((cdar thread)
4990                       (or gnus-sum-thread-tree-root subject))
4991                      (gnus-tmp-new-adopts
4992                       (or gnus-sum-thread-tree-false-root subject))
4993                      (t
4994                       (or gnus-sum-thread-tree-single-indent subject))))
4995               (t
4996                (concat (apply 'concat
4997                               (mapcar (lambda (item)
4998                                         (if (= item 1)
4999                                             gnus-sum-thread-tree-vertical
5000                                           gnus-sum-thread-tree-indent))
5001                                       (cdr (reverse tree-stack))))
5002                        (if (nth 1 thread)
5003                            gnus-sum-thread-tree-leaf-with-other
5004                          gnus-sum-thread-tree-single-leaf)))))
5005             (when (string= gnus-tmp-name "")
5006               (setq gnus-tmp-name gnus-tmp-from))
5007             (unless (numberp gnus-tmp-lines)
5008               (setq gnus-tmp-lines -1))
5009             (if (= gnus-tmp-lines -1)
5010                 (setq gnus-tmp-lines "?")
5011               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5012               (gnus-put-text-property
5013              (point)
5014              (progn (eval gnus-summary-line-format-spec) (point))
5015                'gnus-number number)
5016             (when gnus-visual-p
5017               (forward-line -1)
5018               (gnus-run-hooks 'gnus-summary-update-hook)
5019               (forward-line 1))
5020
5021             (setq gnus-tmp-prev-subject simp-subject)))
5022
5023         (when (nth 1 thread)
5024           (push (list (max 0 gnus-tmp-level)
5025                       (copy-sequence tree-stack)
5026                       (nthcdr 1 thread))
5027                 stack))
5028         (push (if (nth 1 thread) 1 0) tree-stack)
5029         (incf gnus-tmp-level)
5030         (setq threads (if thread-end nil (cdar thread)))
5031         (if gnus-summary-display-while-building
5032             (if building-count
5033                 (progn
5034                   ;; use a set frequency
5035                   (setq building-line-count (1- building-line-count))
5036                   (when (= building-line-count 0)
5037                     (sit-for 0)
5038                     (setq building-line-count
5039                           gnus-summary-display-while-building)))
5040               ;; always
5041               (sit-for 0)))
5042         (unless threads
5043           (setq gnus-tmp-level 0)))))
5044   (gnus-message 7 "Generating summary...done"))
5045
5046 (defun gnus-summary-prepare-unthreaded (headers)
5047   "Generate an unthreaded summary buffer based on HEADERS."
5048   (let (header number mark)
5049
5050     (beginning-of-line)
5051
5052     (while headers
5053       ;; We may have to root out some bad articles...
5054       (when (memq (setq number (mail-header-number
5055                                 (setq header (pop headers))))
5056                   gnus-newsgroup-limit)
5057         ;; Mark article as read when it has a low score.
5058         (when (and gnus-summary-mark-below
5059                    (< (or (cdr (assq number gnus-newsgroup-scored))
5060                           gnus-summary-default-score 0)
5061                       gnus-summary-mark-below)
5062                    (not (gnus-summary-article-ancient-p number)))
5063           (setq gnus-newsgroup-unreads
5064                 (delq number gnus-newsgroup-unreads))
5065           (if gnus-newsgroup-auto-expire
5066               (push number gnus-newsgroup-expirable)
5067             (push (cons number gnus-low-score-mark)
5068                   gnus-newsgroup-reads)))
5069
5070         (setq mark (gnus-article-mark number))
5071         (push (gnus-data-make number mark (1+ (point)) header 0)
5072               gnus-newsgroup-data)
5073         (gnus-summary-insert-line
5074          header 0 number
5075          (memq number gnus-newsgroup-undownloaded)
5076          mark (memq number gnus-newsgroup-replied)
5077          (memq number gnus-newsgroup-expirable)
5078          (mail-header-subject header) nil
5079          (cdr (assq number gnus-newsgroup-scored))
5080          (memq number gnus-newsgroup-processable))))))
5081
5082 (defun gnus-summary-remove-list-identifiers ()
5083   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5084   (let ((regexp (if (consp gnus-list-identifiers)
5085                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5086                   gnus-list-identifiers))
5087         changed subject)
5088     (when regexp
5089       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5090       (dolist (header gnus-newsgroup-headers)
5091         (setq subject (mail-header-subject header)
5092               changed nil)
5093         (while (string-match regexp subject)
5094           (setq subject
5095                 (concat (substring subject 0 (match-beginning 1))
5096                         (substring subject (match-end 0)))
5097                 changed t))
5098         (when changed
5099           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5100             (setq subject
5101                   (concat (substring subject 0 (match-beginning 1))
5102                           (substring subject (match-end 1)))))
5103           (mail-header-set-subject header subject))))))
5104
5105 (defun gnus-fetch-headers (articles)
5106   "Fetch headers of ARTICLES."
5107   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5108     (gnus-message 5 "Fetching headers for %s..." name)
5109     (prog1
5110         (if (eq 'nov
5111                 (setq gnus-headers-retrieved-by
5112                       (gnus-retrieve-headers
5113                        articles gnus-newsgroup-name
5114                        ;; We might want to fetch old headers, but
5115                        ;; not if there is only 1 article.
5116                        (and (or (and
5117                                  (not (eq gnus-fetch-old-headers 'some))
5118                                  (not (numberp gnus-fetch-old-headers)))
5119                                 (> (length articles) 1))
5120                             gnus-fetch-old-headers))))
5121             (gnus-get-newsgroup-headers-xover
5122              articles nil nil gnus-newsgroup-name t)
5123           (gnus-get-newsgroup-headers))
5124       (gnus-message 5 "Fetching headers for %s...done" name))))
5125
5126 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5127   "Select newsgroup GROUP.
5128 If READ-ALL is non-nil, all articles in the group are selected.
5129 If SELECT-ARTICLES, only select those articles from GROUP."
5130   (let* ((entry (gnus-group-entry group))
5131          ;;!!! Dirty hack; should be removed.
5132          (gnus-summary-ignore-duplicates
5133           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5134               t
5135             gnus-summary-ignore-duplicates))
5136          (info (nth 2 entry))
5137          articles fetched-articles cached)
5138
5139     (unless (gnus-check-server
5140              (set (make-local-variable 'gnus-current-select-method)
5141                   (gnus-find-method-for-group group)))
5142       (error "Couldn't open server"))
5143
5144     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5145         (gnus-activate-group group)     ; Or we can activate it...
5146         (progn                          ; Or we bug out.
5147           (when (equal major-mode 'gnus-summary-mode)
5148             (gnus-kill-buffer (current-buffer)))
5149           (error "Couldn't activate group %s: %s"
5150                  group (gnus-status-message group))))
5151
5152     (unless (gnus-request-group group t)
5153       (when (equal major-mode 'gnus-summary-mode)
5154         (gnus-kill-buffer (current-buffer)))
5155       (error "Couldn't request group %s: %s"
5156              group (gnus-status-message group)))
5157
5158     (when gnus-agent
5159       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5160
5161       (setq gnus-summary-use-undownloaded-faces
5162             (gnus-agent-find-parameter
5163              group
5164              'agent-enable-undownloaded-faces)))
5165
5166     (setq gnus-newsgroup-name group
5167           gnus-newsgroup-unselected nil
5168           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5169
5170     (let ((display (gnus-group-find-parameter group 'display)))
5171       (setq gnus-newsgroup-display
5172             (cond
5173              ((not (zerop (or (car-safe read-all) 0)))
5174               ;; The user entered the group with C-u SPC/RET, let's show
5175               ;; all articles.
5176               'gnus-not-ignore)
5177              ((eq display 'all)
5178               'gnus-not-ignore)
5179              ((arrayp display)
5180               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5181              ((numberp display)
5182               ;; The following is probably the "correct" solution, but
5183               ;; it makes Gnus fetch all headers and then limit the
5184               ;; articles (which is slow), so instead we hack the
5185               ;; select-articles parameter instead. -- Simon Josefsson
5186               ;; <jas@kth.se>
5187               ;;
5188               ;; (gnus-byte-compile
5189               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5190               ;;                         display)))))
5191               (setq select-articles
5192                     (gnus-uncompress-range
5193                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5194                              (if (> tmp 0)
5195                                  tmp
5196                                1))
5197                            (cdr (gnus-active group)))))
5198               nil)
5199              (t
5200               nil))))
5201
5202     (gnus-summary-setup-default-charset)
5203
5204     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5205     (when (gnus-virtual-group-p group)
5206       (setq cached gnus-newsgroup-cached))
5207
5208     (setq gnus-newsgroup-unreads
5209           (gnus-sorted-ndifference
5210            (gnus-sorted-ndifference gnus-newsgroup-unreads
5211                                     gnus-newsgroup-marked)
5212            gnus-newsgroup-dormant))
5213
5214     (setq gnus-newsgroup-processable nil)
5215
5216     (gnus-update-read-articles group gnus-newsgroup-unreads)
5217
5218     ;; Adjust and set lists of article marks.
5219     (when info
5220       (gnus-adjust-marked-articles info))
5221     (if (setq articles select-articles)
5222         (setq gnus-newsgroup-unselected
5223               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5224       (setq articles (gnus-articles-to-read group read-all)))
5225
5226     (cond
5227      ((null articles)
5228       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5229       'quit)
5230      ((eq articles 0) nil)
5231      (t
5232       ;; Init the dependencies hash table.
5233       (setq gnus-newsgroup-dependencies
5234             (gnus-make-hashtable (length articles)))
5235       (gnus-set-global-variables)
5236       ;; Retrieve the headers and read them in.
5237
5238       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5239
5240       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5241       (when cached
5242         (setq gnus-newsgroup-cached cached))
5243
5244       ;; Suppress duplicates?
5245       (when gnus-suppress-duplicates
5246         (gnus-dup-suppress-articles))
5247
5248       ;; Set the initial limit.
5249       (setq gnus-newsgroup-limit (copy-sequence articles))
5250       ;; Remove canceled articles from the list of unread articles.
5251       (setq fetched-articles
5252             (mapcar (lambda (headers) (mail-header-number headers))
5253                     gnus-newsgroup-headers))
5254       (setq gnus-newsgroup-articles fetched-articles)
5255       (setq gnus-newsgroup-unreads
5256             (gnus-sorted-nintersection
5257              gnus-newsgroup-unreads fetched-articles))
5258       (gnus-compute-unseen-list)
5259
5260       ;; Removed marked articles that do not exist.
5261       (gnus-update-missing-marks
5262        (gnus-sorted-difference articles fetched-articles))
5263       ;; We might want to build some more threads first.
5264       (when (and gnus-fetch-old-headers
5265                  (eq gnus-headers-retrieved-by 'nov))
5266         (if (eq gnus-fetch-old-headers 'invisible)
5267             (gnus-build-all-threads)
5268           (gnus-build-old-threads)))
5269       ;; Let the Gnus agent mark articles as read.
5270       (when gnus-agent
5271         (gnus-agent-get-undownloaded-list))
5272       ;; Remove list identifiers from subject
5273       (when gnus-list-identifiers
5274         (gnus-summary-remove-list-identifiers))
5275       ;; Check whether auto-expire is to be done in this group.
5276       (setq gnus-newsgroup-auto-expire
5277             (gnus-group-auto-expirable-p group))
5278       ;; Set up the article buffer now, if necessary.
5279       (unless gnus-single-article-buffer
5280         (gnus-article-setup-buffer))
5281       ;; First and last article in this newsgroup.
5282       (when gnus-newsgroup-headers
5283         (setq gnus-newsgroup-begin
5284               (mail-header-number (car gnus-newsgroup-headers))
5285               gnus-newsgroup-end
5286               (mail-header-number
5287                (gnus-last-element gnus-newsgroup-headers))))
5288       ;; GROUP is successfully selected.
5289       (or gnus-newsgroup-headers t)))))
5290
5291 (defun gnus-compute-unseen-list ()
5292   ;; The `seen' marks are treated specially.
5293   (if (not gnus-newsgroup-seen)
5294       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5295     (setq gnus-newsgroup-unseen
5296           (gnus-inverse-list-range-intersection
5297            gnus-newsgroup-articles gnus-newsgroup-seen))))
5298
5299 (defun gnus-summary-display-make-predicate (display)
5300   (require 'gnus-agent)
5301   (when (= (length display) 1)
5302     (setq display (car display)))
5303   (unless gnus-summary-display-cache
5304     (dolist (elem (append '((unread . unread)
5305                             (read . read)
5306                             (unseen . unseen))
5307                           gnus-article-mark-lists))
5308       (push (cons (cdr elem)
5309                   (gnus-byte-compile
5310                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5311             gnus-summary-display-cache)))
5312   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5313         (gnus-category-predicate-cache gnus-summary-display-cache))
5314     (gnus-get-predicate display)))
5315
5316 ;; Uses the dynamically bound `number' variable.
5317 (eval-when-compile
5318   (defvar number))
5319 (defun gnus-article-marked-p (type &optional article)
5320   (let ((article (or article number)))
5321     (cond
5322      ((eq type 'tick)
5323       (memq article gnus-newsgroup-marked))
5324      ((eq type 'spam)
5325       (memq article gnus-newsgroup-spam-marked))
5326      ((eq type 'unsend)
5327       (memq article gnus-newsgroup-unsendable))
5328      ((eq type 'undownload)
5329       (memq article gnus-newsgroup-undownloaded))
5330      ((eq type 'download)
5331       (memq article gnus-newsgroup-downloadable))
5332      ((eq type 'unread)
5333       (memq article gnus-newsgroup-unreads))
5334      ((eq type 'read)
5335       (memq article gnus-newsgroup-reads))
5336      ((eq type 'dormant)
5337       (memq article gnus-newsgroup-dormant) )
5338      ((eq type 'expire)
5339       (memq article gnus-newsgroup-expirable))
5340      ((eq type 'reply)
5341       (memq article gnus-newsgroup-replied))
5342      ((eq type 'killed)
5343       (memq article gnus-newsgroup-killed))
5344      ((eq type 'bookmark)
5345       (assq article gnus-newsgroup-bookmarks))
5346      ((eq type 'score)
5347       (assq article gnus-newsgroup-scored))
5348      ((eq type 'save)
5349       (memq article gnus-newsgroup-saved))
5350      ((eq type 'cache)
5351       (memq article gnus-newsgroup-cached))
5352      ((eq type 'forward)
5353       (memq article gnus-newsgroup-forwarded))
5354      ((eq type 'seen)
5355       (not (memq article gnus-newsgroup-unseen)))
5356      ((eq type 'recent)
5357       (memq article gnus-newsgroup-recent))
5358      (t t))))
5359
5360 (defun gnus-articles-to-read (group &optional read-all)
5361   "Find out what articles the user wants to read."
5362   (let* ((articles
5363           ;; Select all articles if `read-all' is non-nil, or if there
5364           ;; are no unread articles.
5365           (if (or read-all
5366                   (and (zerop (length gnus-newsgroup-marked))
5367                        (zerop (length gnus-newsgroup-unreads)))
5368                   ;; Fetch all if the predicate is non-nil.
5369                   gnus-newsgroup-display)
5370               ;; We want to select the headers for all the articles in
5371               ;; the group, so we select either all the active
5372               ;; articles in the group, or (if that's nil), the
5373               ;; articles in the cache.
5374               (or
5375                (gnus-uncompress-range (gnus-active group))
5376                (gnus-cache-articles-in-group group))
5377             ;; Select only the "normal" subset of articles.
5378             (gnus-sorted-nunion
5379              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5380              gnus-newsgroup-unreads)))
5381          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5382          (scored (length scored-list))
5383          (number (length articles))
5384          (marked (+ (length gnus-newsgroup-marked)
5385                     (length gnus-newsgroup-dormant)))
5386          (select
5387           (cond
5388            ((numberp read-all)
5389             read-all)
5390            ((numberp gnus-newsgroup-display)
5391             gnus-newsgroup-display)
5392            (t
5393             (condition-case ()
5394                 (cond
5395                  ((and (or (<= scored marked) (= scored number))
5396                        (numberp gnus-large-newsgroup)
5397                        (> number gnus-large-newsgroup))
5398                   (let* ((cursor-in-echo-area nil)
5399                          (initial (gnus-parameter-large-newsgroup-initial
5400                                    gnus-newsgroup-name))
5401                          (input
5402                           (read-string
5403                            (format
5404                             "How many articles from %s (%s %d): "
5405                             (gnus-limit-string
5406                              (gnus-group-decoded-name gnus-newsgroup-name)
5407                              35)
5408                             (if initial "max" "default")
5409                             number)
5410                            (if initial
5411                                (cons (number-to-string initial)
5412                                      0)))))
5413                     (if (string-match "^[ \t]*$" input) number input)))
5414                  ((and (> scored marked) (< scored number)
5415                        (> (- scored number) 20))
5416                   (let ((input
5417                          (read-string
5418                           (format "%s %s (%d scored, %d total): "
5419                                   "How many articles from"
5420                                   (gnus-group-decoded-name group)
5421                                   scored number))))
5422                     (if (string-match "^[ \t]*$" input)
5423                         number input)))
5424                  (t number))
5425               (quit
5426                (message "Quit getting the articles to read")
5427                nil))))))
5428     (setq select (if (stringp select) (string-to-number select) select))
5429     (if (or (null select) (zerop select))
5430         select
5431       (if (and (not (zerop scored)) (<= (abs select) scored))
5432           (progn
5433             (setq articles (sort scored-list '<))
5434             (setq number (length articles)))
5435         (setq articles (copy-sequence articles)))
5436
5437       (when (< (abs select) number)
5438         (if (< select 0)
5439             ;; Select the N oldest articles.
5440             (setcdr (nthcdr (1- (abs select)) articles) nil)
5441           ;; Select the N most recent articles.
5442           (setq articles (nthcdr (- number select) articles))))
5443       (setq gnus-newsgroup-unselected
5444             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5445       (when gnus-alter-articles-to-read-function
5446         (setq articles
5447               (sort
5448                (funcall gnus-alter-articles-to-read-function
5449                         gnus-newsgroup-name articles)
5450                '<)))
5451       articles)))
5452
5453 (defun gnus-killed-articles (killed articles)
5454   (let (out)
5455     (while articles
5456       (when (inline (gnus-member-of-range (car articles) killed))
5457         (push (car articles) out))
5458       (setq articles (cdr articles)))
5459     out))
5460
5461 (defun gnus-uncompress-marks (marks)
5462   "Uncompress the mark ranges in MARKS."
5463   (let ((uncompressed '(score bookmark))
5464         out)
5465     (while marks
5466       (if (memq (caar marks) uncompressed)
5467           (push (car marks) out)
5468         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5469       (setq marks (cdr marks)))
5470     out))
5471
5472 (defun gnus-article-mark-to-type (mark)
5473   "Return the type of MARK."
5474   (or (cadr (assq mark gnus-article-special-mark-lists))
5475       'list))
5476
5477 (defun gnus-article-unpropagatable-p (mark)
5478   "Return whether MARK should be propagated to back end."
5479   (memq mark gnus-article-unpropagated-mark-lists))
5480
5481 (defun gnus-adjust-marked-articles (info)
5482   "Set all article lists and remove all marks that are no longer valid."
5483   (let* ((marked-lists (gnus-info-marks info))
5484          (active (gnus-active (gnus-info-group info)))
5485          (min (car active))
5486          (max (cdr active))
5487          (types gnus-article-mark-lists)
5488          marks var articles article mark mark-type
5489          bgn end)
5490
5491     (dolist (marks marked-lists)
5492       (setq mark (car marks)
5493             mark-type (gnus-article-mark-to-type mark)