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