Synch to Oort Gnus 200304050540.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-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 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (require 'gnus-clfns)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44 (require 'mime-view)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
57 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is non-nil, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const some)
89                  number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-refer-thread-limit 200
93   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
94 If t, fetch all the available old headers."
95   :group 'gnus-thread
96   :type '(choice number
97                  (sexp :menu-tag "other" t)))
98
99 (defcustom gnus-summary-make-false-root 'adopt
100   "*nil means that Gnus won't gather loose threads.
101 If the root of a thread has expired or been read in a previous
102 session, the information necessary to build a complete thread has been
103 lost.  Instead of having many small sub-threads from this original thread
104 scattered all over the summary buffer, Gnus can gather them.
105
106 If non-nil, Gnus will try to gather all loose sub-threads from an
107 original thread into one large thread.
108
109 If this variable is non-nil, it should be one of `none', `adopt',
110 `dummy' or `empty'.
111
112 If this variable is `none', Gnus will not make a false root, but just
113 present the sub-threads after another.
114 If this variable is `dummy', Gnus will create a dummy root that will
115 have all the sub-threads as children.
116 If this variable is `adopt', Gnus will make one of the \"children\"
117 the parent and mark all the step-children as such.
118 If this variable is `empty', the \"children\" are printed with empty
119 subject fields.  (Or rather, they will be printed with a string
120 given by the `gnus-summary-same-subject' variable.)"
121   :group 'gnus-thread
122   :type '(choice (const :tag "off" nil)
123                  (const none)
124                  (const dummy)
125                  (const adopt)
126                  (const empty)))
127
128 (defcustom gnus-summary-make-false-root-always nil
129   "Always make a false dummy root."
130   :group 'gnus-thread
131   :type 'boolean)
132
133 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
134   "*A regexp to match subjects to be excluded from loose thread gathering.
135 As loose thread gathering is done on subjects only, that means that
136 there can be many false gatherings performed.  By rooting out certain
137 common subjects, gathering might become saner."
138   :group 'gnus-thread
139   :type 'regexp)
140
141 (defcustom gnus-summary-gather-subject-limit nil
142   "*Maximum length of subject comparisons when gathering loose threads.
143 Use nil to compare full subjects.  Setting this variable to a low
144 number will help gather threads that have been corrupted by
145 newsreaders chopping off subject lines, but it might also mean that
146 unrelated articles that have subject that happen to begin with the
147 same few characters will be incorrectly gathered.
148
149 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
150 comparing subjects."
151   :group 'gnus-thread
152   :type '(choice (const :tag "off" nil)
153                  (const fuzzy)
154                  (sexp :menu-tag "on" t)))
155
156 (defcustom gnus-simplify-subject-functions nil
157   "List of functions taking a string argument that simplify subjects.
158 The functions are applied recursively.
159
160 Useful functions to put in this list include:
161 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
162 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
163   :group 'gnus-thread
164   :type '(repeat function))
165
166 (defcustom gnus-simplify-ignored-prefixes nil
167   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
168   :group 'gnus-thread
169   :type '(choice (const :tag "off" nil)
170                  regexp))
171
172 (defcustom gnus-build-sparse-threads nil
173   "*If non-nil, fill in the gaps in threads.
174 If `some', only fill in the gaps that are needed to tie loose threads
175 together.  If `more', fill in all leaf nodes that Gnus can find.  If
176 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
177   :group 'gnus-thread
178   :type '(choice (const :tag "off" nil)
179                  (const some)
180                  (const more)
181                  (sexp :menu-tag "all" t)))
182
183 (defcustom gnus-summary-thread-gathering-function
184   'gnus-gather-threads-by-subject
185   "*Function used for gathering loose threads.
186 There are two pre-defined functions: `gnus-gather-threads-by-subject',
187 which only takes Subjects into consideration; and
188 `gnus-gather-threads-by-references', which compared the References
189 headers of the articles to find matches."
190   :group 'gnus-thread
191   :type '(radio (function-item gnus-gather-threads-by-subject)
192                 (function-item gnus-gather-threads-by-references)
193                 (function :tag "other")))
194
195 (defcustom gnus-summary-same-subject ""
196   "*String indicating that the current article has the same subject as the previous.
197 This variable will only be used if the value of
198 `gnus-summary-make-false-root' is `empty'."
199   :group 'gnus-summary-format
200   :type 'string)
201
202 (defcustom gnus-summary-goto-unread t
203   "*If t, many commands will go to the next unread article.
204 This applies to marking commands as well as other commands that
205 \"naturally\" select the next article, like, for instance, `SPC' at
206 the end of an article.
207
208 If nil, the marking commands do NOT go to the next unread article
209 \(they go to the next article instead).  If `never', commands that
210 usually go to the next unread article, will go to the next article,
211 whether it is read or not."
212   :group 'gnus-summary-marks
213   :link '(custom-manual "(gnus)Setting Marks")
214   :type '(choice (const :tag "off" nil)
215                  (const never)
216                  (sexp :menu-tag "on" t)))
217
218 (defcustom gnus-summary-default-score 0
219   "*Default article score level.
220 All scores generated by the score files will be added to this score.
221 If this variable is nil, scoring will be disabled."
222   :group 'gnus-score-default
223   :type '(choice (const :tag "disable")
224                  integer))
225
226 (defcustom gnus-summary-default-high-score 0
227   "*Default threshold for a high scored article.
228 An article will be highlighted as high scored if its score is greater
229 than this score."
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :group 'gnus-score-default
238   :type 'integer)
239
240 (defcustom gnus-summary-zcore-fuzz 0
241   "*Fuzziness factor for the zcore in the summary buffer.
242 Articles with scores closer than this to `gnus-summary-default-score'
243 will not be marked."
244   :group 'gnus-summary-format
245   :type 'integer)
246
247 (defcustom gnus-simplify-subject-fuzzy-regexp nil
248   "*Strings to be removed when doing fuzzy matches.
249 This can either be a regular expression or list of regular expressions
250 that will be removed from subject strings if fuzzy subject
251 simplification is selected."
252   :group 'gnus-thread
253   :type '(repeat regexp))
254
255 (defcustom gnus-show-threads t
256   "*If non-nil, display threads in summary mode."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-hide-subtree nil
261   "*If non-nil, hide all threads initially.
262 This can be a predicate specifier which says which threads to hide.
263 If threads are hidden, you have to run the command
264 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
265 to expose hidden threads."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :group 'gnus-group-select
328   :type '(choice (const best)
329                  (const unread)
330                  (const first)
331                  (const unseen)
332                  (const unseen-or-unread)))
333
334 (defcustom gnus-dont-select-after-jump-to-other-group nil
335   "If non-nil, don't select the first unread article after entering the
336 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
337 it is depend on the value of `gnus-auto-select-first' whether to select
338 or not."
339   :group 'gnus-group-select
340   :type 'boolean)
341
342 (defcustom gnus-auto-select-next t
343   "*If non-nil, offer to go to the next group from the end of the previous.
344 If the value is t and the next newsgroup is empty, Gnus will exit
345 summary mode and go back to group mode.  If the value is neither nil
346 nor t, Gnus will select the following unread newsgroup.  In
347 particular, if the value is the symbol `quietly', the next unread
348 newsgroup will be selected without any confirmation, and if it is
349 `almost-quietly', the next group will be selected without any
350 confirmation if you are located on the last article in the group.
351 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
352 will go to the next group without confirmation."
353   :group 'gnus-summary-maneuvering
354   :type '(choice (const :tag "off" nil)
355                  (const quietly)
356                  (const almost-quietly)
357                  (const slightly-quietly)
358                  (sexp :menu-tag "on" t)))
359
360 (defcustom gnus-auto-select-same nil
361   "*If non-nil, select the next article with the same subject.
362 If there are no more articles with the same subject, go to
363 the first unread article."
364   :group 'gnus-summary-maneuvering
365   :type 'boolean)
366
367 (defcustom gnus-auto-goto-ignores 'unfetched
368   "*Says how to handle unfetched articles when maneuvering.
369
370 This variable can either be the symbols `nil' (maneuver to any
371 article), `undownloaded' (maneuvering while unplugged ignores articles
372 that have not been fetched), `always-undownloaded' (maneuvering always
373 ignores articles that have not been fetched), `unfetched' (maneuvering
374 ignores articles whose headers have not been fetched).
375
376 NOTE: The list of unfetched articles will always be nil when plugged
377 and, when unplugged, a subset of the undownloaded article list."
378   :group 'gnus-summary-maneuvering
379   :type '(choice (const :tag "None" nil)
380                  (const :tag "Undownloaded when unplugged" undownloaded)
381                  (const :tag "Undownloaded" always-undownloaded)
382                  (const :tag "Unfetched" unfetched)))
383
384 (defcustom gnus-summary-check-current nil
385   "*If non-nil, consider the current article when moving.
386 The \"unread\" movement commands will stay on the same line if the
387 current article is unread."
388   :group 'gnus-summary-maneuvering
389   :type 'boolean)
390
391 (defcustom gnus-auto-center-summary t
392   "*If non-nil, always center the current summary buffer.
393 In particular, if `vertical' do only vertical recentering.  If non-nil
394 and non-`vertical', do both horizontal and vertical recentering."
395   :group 'gnus-summary-maneuvering
396   :type '(choice (const :tag "none" nil)
397                  (const vertical)
398                  (integer :tag "height")
399                  (sexp :menu-tag "both" t)))
400
401 (defvar gnus-auto-center-group t
402   "*If non-nil, always center the group buffer.")
403
404 (defcustom gnus-show-all-headers nil
405   "*If non-nil, don't hide any headers."
406   :group 'gnus-article-hiding
407   :group 'gnus-article-headers
408   :type 'boolean)
409
410 (defcustom gnus-summary-ignore-duplicates nil
411   "*If non-nil, ignore articles with identical Message-ID headers."
412   :group 'gnus-summary
413   :type 'boolean)
414
415 (defcustom gnus-single-article-buffer t
416   "*If non-nil, display all articles in the same buffer.
417 If nil, each group will get its own article buffer."
418   :group 'gnus-article-various
419   :type 'boolean)
420
421 (defcustom gnus-break-pages t
422   "*If non-nil, do page breaking on articles.
423 The page delimiter is specified by the `gnus-page-delimiter'
424 variable."
425   :group 'gnus-article-various
426   :type 'boolean)
427
428 (defcustom gnus-show-mime t
429   "*If non-nil, do mime processing of articles.
430 The articles will simply be fed to the function given by
431 `gnus-article-display-method-for-mime'."
432   :group 'gnus-article-mime
433   :type 'boolean)
434
435 (defcustom gnus-move-split-methods nil
436   "*Variable used to suggest where articles are to be moved to.
437 It uses the same syntax as the `gnus-split-methods' variable.
438 However, whereas `gnus-split-methods' specifies file names as targets,
439 this variable specifies group names."
440   :group 'gnus-summary-mail
441   :type '(repeat (choice (list :value (fun) function)
442                          (cons :value ("" "") regexp (repeat string))
443                          (sexp :value nil))))
444
445 (defcustom gnus-unread-mark ?\ ;;;Whitespace
446   "*Mark used for unread articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-ticked-mark ?!
451   "*Mark used for ticked articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-dormant-mark ??
456   "*Mark used for dormant articles."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-del-mark ?r
461   "*Mark used for del'd articles."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-read-mark ?R
466   "*Mark used for read articles."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-expirable-mark ?E
471   "*Mark used for expirable articles."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-killed-mark ?K
476   "*Mark used for killed articles."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-spam-mark ?$
481   "*Mark used for spam articles."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-souped-mark ?F
486   "*Mark used for souped articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-kill-file-mark ?X
491   "*Mark used for articles killed by kill files."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-low-score-mark ?Y
496   "*Mark used for articles with a low score."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-catchup-mark ?C
501   "*Mark used for articles that are caught up."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-replied-mark ?A
506   "*Mark used for articles that have been replied to."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-forwarded-mark ?F
511   "*Mark used for articles that have been forwarded."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-recent-mark ?N
516   "*Mark used for articles that are recent."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-no-mark ?\ ;;;Whitespace
536   "*Mark used for articles that have no other secondary mark."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-ancient-mark ?O
541   "*Mark used for ancient articles."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-sparse-mark ?Q
546   "*Mark used for sparsely reffed articles."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-canceled-mark ?G
551   "*Mark used for canceled articles."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-duplicate-mark ?M
556   "*Mark used for duplicate articles."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-undownloaded-mark ?-
561   "*Mark used for articles that weren't downloaded."
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-downloaded-mark ?+
566   "*Mark used for articles that were downloaded."
567   :group 'gnus-summary-marks
568   :type 'character)
569
570 (defcustom gnus-downloadable-mark ?%
571   "*Mark used for articles that are to be downloaded."
572   :group 'gnus-summary-marks
573   :type 'character)
574
575 (defcustom gnus-unsendable-mark ?=
576   "*Mark used for articles that won't be sent."
577   :group 'gnus-summary-marks
578   :type 'character)
579
580 (defcustom gnus-score-over-mark ?+
581   "*Score mark used for articles with high scores."
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-score-below-mark ?-
586   "*Score mark used for articles with low scores."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
591   "*There is no thread under the article."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-not-empty-thread-mark ?=
596   "*There is a thread under the article."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-view-pseudo-asynchronously nil
601   "*If non-nil, Gnus will view pseudo-articles asynchronously."
602   :group 'gnus-extract-view
603   :type 'boolean)
604
605 (defcustom gnus-auto-expirable-marks
606   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
607         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
608         gnus-souped-mark gnus-duplicate-mark)
609   "*The list of marks converted into expiration if a group is auto-expirable."
610   :version "21.1"
611   :group 'gnus-summary
612   :type '(repeat character))
613
614 (defcustom gnus-inhibit-user-auto-expire t
615   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
616   :version "21.1"
617   :group 'gnus-summary
618   :type 'boolean)
619
620 (defcustom gnus-view-pseudos nil
621   "*If `automatic', pseudo-articles will be viewed automatically.
622 If `not-confirm', pseudos will be viewed automatically, and the user
623 will not be asked to confirm the command."
624   :group 'gnus-extract-view
625   :type '(choice (const :tag "off" nil)
626                  (const automatic)
627                  (const not-confirm)))
628
629 (defcustom gnus-view-pseudos-separately t
630   "*If non-nil, one pseudo-article will be created for each file to be viewed.
631 If nil, all files that use the same viewing command will be given as a
632 list of parameters to that command."
633   :group 'gnus-extract-view
634   :type 'boolean)
635
636 (defcustom gnus-insert-pseudo-articles t
637   "*If non-nil, insert pseudo-articles when decoding articles."
638   :group 'gnus-extract-view
639   :type 'boolean)
640
641 (defcustom gnus-summary-dummy-line-format
642   "   %(:                             :%) %S\n"
643   "*The format specification for the dummy roots in the summary buffer.
644 It works along the same lines as a normal formatting string,
645 with some simple extensions.
646
647 %S  The subject
648
649 General format specifiers can also be used.
650 See `(gnus)Formatting Variables'."
651   :link '(custom-manual "(gnus)Formatting Variables")
652   :group 'gnus-threading
653   :type 'string)
654
655 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
656   "*The format specification for the summary mode line.
657 It works along the same lines as a normal formatting string,
658 with some simple extensions:
659
660 %G  Group name
661 %p  Unprefixed group name
662 %A  Current article number
663 %z  Current article score
664 %V  Gnus version
665 %U  Number of unread articles in the group
666 %e  Number of unselected articles in the group
667 %Z  A string with unread/unselected article counts
668 %g  Shortish group name
669 %S  Subject of the current article
670 %u  User-defined spec
671 %s  Current score file name
672 %d  Number of dormant articles
673 %r  Number of articles that have been marked as read in this session
674 %E  Number of articles expunged by the score files"
675   :group 'gnus-summary-format
676   :type 'string)
677
678 (defcustom gnus-list-identifiers nil
679   "Regexp that matches list identifiers to be removed from subject.
680 This can also be a list of regexps."
681   :version "21.1"
682   :group 'gnus-summary-format
683   :group 'gnus-article-hiding
684   :type '(choice (const :tag "none" nil)
685                  (regexp :value ".*")
686                  (repeat :value (".*") regexp)))
687
688 (defcustom gnus-summary-mark-below 0
689   "*Mark all articles with a score below this variable as read.
690 This variable is local to each summary buffer and usually set by the
691 score file."
692   :group 'gnus-score-default
693   :type 'integer)
694
695 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
696   "*List of functions used for sorting articles in the summary buffer.
697
698 Each function takes two articles and returns non-nil if the first
699 article should be sorted before the other.  If you use more than one
700 function, the primary sort function should be the last.  You should
701 probably always include `gnus-article-sort-by-number' in the list of
702 sorting functions -- preferably first.  Also note that sorting by date
703 is often much slower than sorting by number, and the sorting order is
704 very similar.  (Sorting by date means sorting by the time the message
705 was sent, sorting by number means sorting by arrival time.)
706
707 Ready-made functions include `gnus-article-sort-by-number',
708 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
709 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
710 and `gnus-article-sort-by-score'.
711
712 When threading is turned on, the variable `gnus-thread-sort-functions'
713 controls how articles are sorted."
714   :group 'gnus-summary-sort
715   :type '(repeat (choice (function-item gnus-article-sort-by-number)
716                          (function-item gnus-article-sort-by-author)
717                          (function-item gnus-article-sort-by-subject)
718                          (function-item gnus-article-sort-by-date)
719                          (function-item gnus-article-sort-by-score)
720                          (function-item gnus-article-sort-by-random)
721                          (function :tag "other"))))
722
723 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
724   "*List of functions used for sorting threads in the summary buffer.
725 By default, threads are sorted by article number.
726
727 Each function takes two threads and returns non-nil if the first
728 thread should be sorted before the other.  If you use more than one
729 function, the primary sort function should be the last.  You should
730 probably always include `gnus-thread-sort-by-number' in the list of
731 sorting functions -- preferably first.  Also note that sorting by date
732 is often much slower than sorting by number, and the sorting order is
733 very similar.  (Sorting by date means sorting by the time the message
734 was sent, sorting by number means sorting by arrival time.)
735
736 Ready-made functions include `gnus-thread-sort-by-number',
737 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
738 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
739 `gnus-thread-sort-by-most-recent-number',
740 `gnus-thread-sort-by-most-recent-date',
741 `gnus-thread-sort-by-random', and
742 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
743
744 When threading is turned off, the variable
745 `gnus-article-sort-functions' controls how articles are sorted."
746   :group 'gnus-summary-sort
747   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
748                          (function-item gnus-thread-sort-by-author)
749                          (function-item gnus-thread-sort-by-subject)
750                          (function-item gnus-thread-sort-by-date)
751                          (function-item gnus-thread-sort-by-score)
752                          (function-item gnus-thread-sort-by-total-score)
753                          (function-item gnus-thread-sort-by-random)
754                          (function :tag "other"))))
755
756 (defcustom gnus-thread-score-function '+
757   "*Function used for calculating the total score of a thread.
758
759 The function is called with the scores of the article and each
760 subthread and should then return the score of the thread.
761
762 Some functions you can use are `+', `max', or `min'."
763   :group 'gnus-summary-sort
764   :type 'function)
765
766 (defcustom gnus-summary-expunge-below nil
767   "All articles that have a score less than this variable will be expunged.
768 This variable is local to the summary buffers."
769   :group 'gnus-score-default
770   :type '(choice (const :tag "off" nil)
771                  integer))
772
773 (defcustom gnus-thread-expunge-below nil
774   "All threads that have a total score less than this variable will be expunged.
775 See `gnus-thread-score-function' for en explanation of what a
776 \"thread score\" is.
777
778 This variable is local to the summary buffers."
779   :group 'gnus-threading
780   :group 'gnus-score-default
781   :type '(choice (const :tag "off" nil)
782                  integer))
783
784 (defcustom gnus-summary-mode-hook nil
785   "*A hook for Gnus summary mode.
786 This hook is run before any variables are set in the summary buffer."
787   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
788   :group 'gnus-summary-various
789   :type 'hook)
790
791 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
792 (when (featurep 'xemacs)
793   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
794   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
795   (add-hook 'gnus-summary-mode-hook
796             'gnus-xmas-switch-horizontal-scrollbar-off))
797
798 (defcustom gnus-summary-menu-hook nil
799   "*Hook run after the creation of the summary mode menu."
800   :group 'gnus-summary-visual
801   :type 'hook)
802
803 (defcustom gnus-summary-exit-hook nil
804   "*A hook called on exit from the summary buffer.
805 It will be called with point in the group buffer."
806   :group 'gnus-summary-exit
807   :type 'hook)
808
809 (defcustom gnus-summary-prepare-hook nil
810   "*A hook called after the summary buffer has been generated.
811 If you want to modify the summary buffer, you can use this hook."
812   :group 'gnus-summary-various
813   :type 'hook)
814
815 (defcustom gnus-summary-prepared-hook nil
816   "*A hook called as the last thing after the summary buffer has been generated."
817   :group 'gnus-summary-various
818   :type 'hook)
819
820 (defcustom gnus-summary-generate-hook nil
821   "*A hook run just before generating the summary buffer.
822 This hook is commonly used to customize threading variables and the
823 like."
824   :group 'gnus-summary-various
825   :type 'hook)
826
827 (defcustom gnus-select-group-hook nil
828   "*A hook called when a newsgroup is selected.
829
830 If you'd like to simplify subjects like the
831 `gnus-summary-next-same-subject' command does, you can use the
832 following hook:
833
834  (add-hook gnus-select-group-hook
835            (lambda ()
836              (mapcar (lambda (header)
837                        (mail-header-set-subject
838                         header
839                         (gnus-simplify-subject
840                          (mail-header-subject header) 're-only)))
841                      gnus-newsgroup-headers)))"
842   :group 'gnus-group-select
843   :type 'hook)
844
845 (defcustom gnus-select-article-hook nil
846   "*A hook called when an article is selected."
847   :group 'gnus-summary-choose
848   :options '(gnus-agent-fetch-selected-article)
849   :type 'hook)
850
851 (defcustom gnus-visual-mark-article-hook
852   (list 'gnus-highlight-selected-summary)
853   "*Hook run after selecting an article in the summary buffer.
854 It is meant to be used for highlighting the article in some way.  It
855 is not run if `gnus-visual' is nil."
856   :group 'gnus-summary-visual
857   :type 'hook)
858
859 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
860   "*A hook called before parsing the headers."
861   :group 'gnus-various
862   :type 'hook)
863
864 (defcustom gnus-exit-group-hook nil
865   "*A hook called when exiting summary mode.
866 This hook is not called from the non-updating exit commands like `Q'."
867   :group 'gnus-various
868   :type 'hook)
869
870 (defcustom gnus-summary-update-hook
871   (list 'gnus-summary-highlight-line)
872   "*A hook called when a summary line is changed.
873 The hook will not be called if `gnus-visual' is nil.
874
875 The default function `gnus-summary-highlight-line' will
876 highlight the line according to the `gnus-summary-highlight'
877 variable."
878   :group 'gnus-summary-visual
879   :type 'hook)
880
881 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
882   "*A hook called when an article is selected for the first time.
883 The hook is intended to mark an article as read (or unread)
884 automatically when it is selected."
885   :group 'gnus-summary-choose
886   :type 'hook)
887
888 (defcustom gnus-group-no-more-groups-hook nil
889   "*A hook run when returning to group mode having no more (unread) groups."
890   :group 'gnus-group-select
891   :type 'hook)
892
893 (defcustom gnus-ps-print-hook nil
894   "*A hook run before ps-printing something from Gnus."
895   :group 'gnus-summary
896   :type 'hook)
897
898 (defcustom gnus-summary-article-move-hook nil
899   "*A hook called after an article is moved, copied, respooled, or crossposted."
900   :group 'gnus-summary
901   :type 'hook)
902
903 (defcustom gnus-summary-article-delete-hook nil
904   "*A hook called after an article is deleted."
905   :group 'gnus-summary
906   :type 'hook)
907
908 (defcustom gnus-summary-article-expire-hook nil
909   "*A hook called after an article is expired."
910   :group 'gnus-summary
911   :type 'hook)
912
913 (defcustom gnus-summary-display-arrow
914   (and (fboundp 'display-graphic-p)
915        (display-graphic-p))
916   "*If non-nil, display an arrow highlighting the current article."
917   :version "21.1"
918   :group 'gnus-summary
919   :type 'boolean)
920
921 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
922   "Face used for highlighting the current article in the summary buffer."
923   :group 'gnus-summary-visual
924   :type 'face)
925
926 (defvar gnus-tmp-downloaded nil)
927
928 (defcustom gnus-summary-highlight
929   '(((eq mark gnus-canceled-mark)
930      . gnus-summary-cancelled-face)
931     ((and uncached (> score default-high))
932      . gnus-summary-high-undownloaded-face)
933     ((and uncached (< score default-low))
934      . gnus-summary-low-undownloaded-face)
935     (uncached
936      . gnus-summary-normal-undownloaded-face)
937     ((and (> score default-high)
938           (or (eq mark gnus-dormant-mark)
939               (eq mark gnus-ticked-mark)))
940      . gnus-summary-high-ticked-face)
941     ((and (< score default-low)
942           (or (eq mark gnus-dormant-mark)
943               (eq mark gnus-ticked-mark)))
944      . gnus-summary-low-ticked-face)
945     ((or (eq mark gnus-dormant-mark)
946          (eq mark gnus-ticked-mark))
947      . gnus-summary-normal-ticked-face)
948     ((and (> score default-high) (eq mark gnus-ancient-mark))
949      . gnus-summary-high-ancient-face)
950     ((and (< score default-low) (eq mark gnus-ancient-mark))
951      . gnus-summary-low-ancient-face)
952     ((eq mark gnus-ancient-mark)
953      . gnus-summary-normal-ancient-face)
954     ((and (> score default-high) (eq mark gnus-unread-mark))
955      . gnus-summary-high-unread-face)
956     ((and (< score default-low) (eq mark gnus-unread-mark))
957      . gnus-summary-low-unread-face)
958     ((eq mark gnus-unread-mark)
959      . gnus-summary-normal-unread-face)
960     ((> score default-high)
961      . gnus-summary-high-read-face)
962     ((< score default-low)
963      . gnus-summary-low-read-face)
964     (t
965      . gnus-summary-normal-read-face))
966   "*Controls the highlighting of summary buffer lines.
967
968 A list of (FORM . FACE) pairs.  When deciding how a a particular
969 summary line should be displayed, each form is evaluated.  The content
970 of the face field after the first true form is used.  You can change
971 how those summary lines are displayed, by editing the face field.
972
973 You can use the following variables in the FORM field.
974
975 score:        The article's score
976 default:      The default article score.
977 default-high: The default score for high scored articles.
978 default-low:  The default score for low scored articles.
979 below:        The score below which articles are automatically marked as read.
980 mark:         The articles mark."
981   :group 'gnus-summary-visual
982   :type '(repeat (cons (sexp :tag "Form" nil)
983                        face)))
984
985 (defcustom gnus-alter-header-function nil
986   "Function called to allow alteration of article header structures.
987 The function is called with one parameter, the article header vector,
988 which it may alter in any way."
989   :type '(choice (const :tag "None" nil)
990                  function)
991   :group 'gnus-summary)
992
993 (defvar gnus-decode-encoded-word-function
994   (mime-find-field-decoder 'From 'nov)
995   "Variable that says which function should be used to decode a string with encoded words.")
996
997 (defcustom gnus-extra-headers '(To Newsgroups)
998   "*Extra headers to parse."
999   :version "21.1"
1000   :group 'gnus-summary
1001   :type '(repeat symbol))
1002
1003 (defcustom gnus-ignored-from-addresses
1004   (and user-mail-address (regexp-quote user-mail-address))
1005   "*Regexp of From headers that may be suppressed in favor of To headers."
1006   :version "21.1"
1007   :group 'gnus-summary
1008   :type 'regexp)
1009
1010 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1011   "List of charsets that should be ignored.
1012 When these charsets are used in the \"charset\" parameter, the
1013 default charset will be used instead."
1014   :version "21.1"
1015   :type '(repeat symbol)
1016   :group 'gnus-charset)
1017
1018 (gnus-define-group-parameter
1019  ignored-charsets
1020  :type list
1021  :function-document
1022  "Return the ignored charsets of GROUP."
1023  :variable gnus-group-ignored-charsets-alist
1024  :variable-default
1025  '(("alt\\.chinese\\.text" iso-8859-1))
1026  :variable-document
1027  "Alist of regexps (to match group names) and charsets that should be ignored.
1028 When these charsets are used in the \"charset\" parameter, the
1029 default charset will be used instead."
1030  :variable-group gnus-charset
1031  :variable-type '(repeat (cons (regexp :tag "Group")
1032                                (repeat symbol)))
1033  :parameter-type '(choice :tag "Ignored charsets"
1034                           :value nil
1035                           (repeat (symbol)))
1036  :parameter-document       "\
1037 List of charsets that should be ignored.
1038
1039 When these charsets are used in the \"charset\" parameter, the
1040 default charset will be used instead.")
1041
1042 (defcustom gnus-group-highlight-words-alist nil
1043   "Alist of group regexps and highlight regexps.
1044 This variable uses the same syntax as `gnus-emphasis-alist'."
1045   :version "21.1"
1046   :type '(repeat (cons (regexp :tag "Group")
1047                        (repeat (list (regexp :tag "Highlight regexp")
1048                                      (number :tag "Group for entire word" 0)
1049                                      (number :tag "Group for displayed part" 0)
1050                                      (symbol :tag "Face"
1051                                              gnus-emphasis-highlight-words)))))
1052   :group 'gnus-summary-visual)
1053
1054 (defcustom gnus-use-wheel nil
1055   "Use Intelli-mouse on summary movement"
1056   :type 'boolean
1057   :group 'gnus-summary-maneuvering)
1058
1059 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1060   "Amount to scroll messages by spinning the mouse wheel.
1061 This is actually a cons cell, where the first item is the amount to scroll
1062 on a normal wheel event, and the second is the amount to scroll when the
1063 wheel is moved with the shift key depressed."
1064   :type '(cons (integer :tag "Shift") integer)
1065   :group 'gnus-summary-maneuvering)
1066
1067 (defcustom gnus-wheel-edge-resistance 2
1068   "How hard it should be to change the current article
1069 by moving the mouse over the edge of the article window."
1070   :type 'integer
1071   :group 'gnus-summary-maneuvering)
1072
1073 (defcustom gnus-summary-show-article-charset-alist
1074   nil
1075   "Alist of number and charset.
1076 The article will be shown with the charset corresponding to the
1077 numbered argument.
1078 For example: ((1 . cn-gb-2312) (2 . big5))."
1079   :version "21.1"
1080   :type '(repeat (cons (number :tag "Argument" 1)
1081                        (symbol :tag "Charset")))
1082   :group 'gnus-charset)
1083
1084 (defcustom gnus-preserve-marks t
1085   "Whether marks are preserved when moving, copying and respooling messages."
1086   :version "21.1"
1087   :type 'boolean
1088   :group 'gnus-summary-marks)
1089
1090 (defcustom gnus-alter-articles-to-read-function nil
1091   "Function to be called to alter the list of articles to be selected."
1092   :type '(choice (const nil) function)
1093   :group 'gnus-summary)
1094
1095 (defcustom gnus-orphan-score nil
1096   "*All orphans get this score added.  Set in the score file."
1097   :group 'gnus-score-default
1098   :type '(choice (const nil)
1099                  integer))
1100
1101 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1102   "*A regexp to match MIME parts when saving multiple parts of a
1103 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1104 This regexp will be used by default when prompting the user for which
1105 type of files to save."
1106   :group 'gnus-summary
1107   :type 'regexp)
1108
1109 (defcustom gnus-read-all-available-headers nil
1110   "Whether Gnus should parse all headers made available to it.
1111 This is mostly relevant for slow backends where the user may
1112 wish to widen the summary buffer to include all headers
1113 that were fetched.  Say, for nnultimate groups."
1114   :group 'gnus-summary
1115   :type '(choice boolean regexp))
1116
1117 (defcustom gnus-summary-muttprint-program "muttprint"
1118   "Command (and optional arguments) used to run Muttprint."
1119   :version "21.3"
1120   :group 'gnus-summary
1121   :type 'string)
1122
1123 (defcustom gnus-article-loose-mime nil
1124   "If non-nil, don't require MIME-Version header.
1125 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1126 supply the MIME-Version header or deliberately strip it From the mail.
1127 Set it to non-nil, Gnus will treat some articles as MIME even if
1128 the MIME-Version header is missed."
1129   :version "21.3"
1130   :type 'boolean
1131   :group 'gnus-article-mime)
1132
1133 (defcustom gnus-article-emulate-mime t
1134   "If non-nil, use MIME emulation for uuencode and the like.
1135 This means that Gnus will search message bodies for text that look
1136 like uuencoded bits, yEncoded bits, and so on, and present that using
1137 the normal Gnus MIME machinery."
1138   :type 'boolean
1139   :group 'gnus-article-mime)
1140
1141 ;;; Internal variables
1142
1143 (defvar gnus-summary-display-cache nil)
1144 (defvar gnus-article-mime-handles nil)
1145 (defvar gnus-article-decoded-p nil)
1146 (defvar gnus-article-charset nil)
1147 (defvar gnus-article-ignored-charsets nil)
1148 (defvar gnus-scores-exclude-files nil)
1149 (defvar gnus-page-broken nil)
1150
1151 (defvar gnus-original-article nil)
1152 (defvar gnus-article-internal-prepare-hook nil)
1153 (defvar gnus-newsgroup-process-stack nil)
1154
1155 (defvar gnus-thread-indent-array nil)
1156 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1157 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1158   "Function called to sort the articles within a thread after it has been gathered together.")
1159
1160 (defvar gnus-summary-save-parts-type-history nil)
1161 (defvar gnus-summary-save-parts-last-directory nil)
1162
1163 ;; Avoid highlighting in kill files.
1164 (defvar gnus-summary-inhibit-highlight nil)
1165 (defvar gnus-newsgroup-selected-overlay nil)
1166 (defvar gnus-inhibit-limiting nil)
1167 (defvar gnus-newsgroup-adaptive-score-file nil)
1168 (defvar gnus-current-score-file nil)
1169 (defvar gnus-current-move-group nil)
1170 (defvar gnus-current-copy-group nil)
1171 (defvar gnus-current-crosspost-group nil)
1172 (defvar gnus-newsgroup-display nil)
1173
1174 (defvar gnus-newsgroup-dependencies nil)
1175 (defvar gnus-newsgroup-adaptive nil)
1176 (defvar gnus-summary-display-article-function nil)
1177 (defvar gnus-summary-highlight-line-function nil
1178   "Function called after highlighting a summary line.")
1179
1180 (defvar gnus-summary-line-format-alist
1181   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1182     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1183     (?s gnus-tmp-subject-or-nil ?s)
1184     (?n gnus-tmp-name ?s)
1185     (?A (std11-address-string
1186          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1187     (?a (or (std11-full-name-string
1188              (car (mime-entity-read-field gnus-tmp-header 'From)))
1189             gnus-tmp-from) ?s)
1190     (?F gnus-tmp-from ?s)
1191     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1192     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1193     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1194     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1195     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1196     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1197     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1198     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1199     (?L gnus-tmp-lines ?s)
1200     (?O gnus-tmp-downloaded ?c)
1201     (?I gnus-tmp-indentation ?s)
1202     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1203     (?R gnus-tmp-replied ?c)
1204     (?\[ gnus-tmp-opening-bracket ?c)
1205     (?\] gnus-tmp-closing-bracket ?c)
1206     (?\> (make-string gnus-tmp-level ? ) ?s)
1207     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1208     (?i gnus-tmp-score ?d)
1209     (?z gnus-tmp-score-char ?c)
1210     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1211     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1212     (?U gnus-tmp-unread ?c)
1213     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1214         ?s)
1215     (?t (gnus-summary-number-of-articles-in-thread
1216          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1217         ?d)
1218     (?e (gnus-summary-number-of-articles-in-thread
1219          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1220         ?c)
1221     (?u gnus-tmp-user-defined ?s)
1222     (?P (gnus-pick-line-number) ?d)
1223     (?B gnus-tmp-thread-tree-header-string ?s)
1224     (user-date (gnus-user-date
1225                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1226   "An alist of format specifications that can appear in summary lines.
1227 These are paired with what variables they correspond with, along with
1228 the type of the variable (string, integer, character, etc).")
1229
1230 (defvar gnus-summary-dummy-line-format-alist
1231   `((?S gnus-tmp-subject ?s)
1232     (?N gnus-tmp-number ?d)
1233     (?u gnus-tmp-user-defined ?s)))
1234
1235 (defvar gnus-summary-mode-line-format-alist
1236   `((?G gnus-tmp-group-name ?s)
1237     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1238     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1239     (?A gnus-tmp-article-number ?d)
1240     (?Z gnus-tmp-unread-and-unselected ?s)
1241     (?V gnus-version ?s)
1242     (?U gnus-tmp-unread-and-unticked ?d)
1243     (?S gnus-tmp-subject ?s)
1244     (?e gnus-tmp-unselected ?d)
1245     (?u gnus-tmp-user-defined ?s)
1246     (?d (length gnus-newsgroup-dormant) ?d)
1247     (?t (length gnus-newsgroup-marked) ?d)
1248     (?h (length gnus-newsgroup-spam-marked) ?d)
1249     (?r (length gnus-newsgroup-reads) ?d)
1250     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1251     (?E gnus-newsgroup-expunged-tally ?d)
1252     (?s (gnus-current-score-file-nondirectory) ?s)))
1253
1254 (defvar gnus-last-search-regexp nil
1255   "Default regexp for article search command.")
1256
1257 (defvar gnus-summary-search-article-matched-data nil
1258   "Last matched data of article search command.  It is the local variable
1259 in `gnus-article-buffer' which consists of the list of start position,
1260 end position and text.")
1261
1262 (defvar gnus-last-shell-command nil
1263   "Default shell command on article.")
1264
1265 (defvar gnus-newsgroup-agentized nil
1266   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1267 (defvar gnus-newsgroup-begin nil)
1268 (defvar gnus-newsgroup-end nil)
1269 (defvar gnus-newsgroup-last-rmail nil)
1270 (defvar gnus-newsgroup-last-mail nil)
1271 (defvar gnus-newsgroup-last-folder nil)
1272 (defvar gnus-newsgroup-last-file nil)
1273 (defvar gnus-newsgroup-auto-expire nil)
1274 (defvar gnus-newsgroup-active nil)
1275
1276 (defvar gnus-newsgroup-data nil)
1277 (defvar gnus-newsgroup-data-reverse nil)
1278 (defvar gnus-newsgroup-limit nil)
1279 (defvar gnus-newsgroup-limits nil)
1280
1281 (defvar gnus-newsgroup-unreads nil
1282   "Sorted list of unread articles in the current newsgroup.")
1283
1284 (defvar gnus-newsgroup-unselected nil
1285   "Sorted list of unselected unread articles in the current newsgroup.")
1286
1287 (defvar gnus-newsgroup-reads nil
1288   "Alist of read articles and article marks in the current newsgroup.")
1289
1290 (defvar gnus-newsgroup-expunged-tally nil)
1291
1292 (defvar gnus-newsgroup-marked nil
1293   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1294
1295 (defvar gnus-newsgroup-spam-marked nil
1296   "List of ranges of articles that have been marked as spam.")
1297
1298 (defvar gnus-newsgroup-killed nil
1299   "List of ranges of articles that have been through the scoring process.")
1300
1301 (defvar gnus-newsgroup-cached nil
1302   "Sorted list of articles that come from the article cache.")
1303
1304 (defvar gnus-newsgroup-saved nil
1305   "List of articles that have been saved.")
1306
1307 (defvar gnus-newsgroup-kill-headers nil)
1308
1309 (defvar gnus-newsgroup-replied nil
1310   "List of articles that have been replied to in the current newsgroup.")
1311
1312 (defvar gnus-newsgroup-forwarded nil
1313   "List of articles that have been forwarded in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-recent nil
1316   "List of articles that have are recent in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-expirable nil
1319   "Sorted list of articles in the current newsgroup that can be expired.")
1320
1321 (defvar gnus-newsgroup-processable nil
1322   "List of articles in the current newsgroup that can be processed.")
1323
1324 (defvar gnus-newsgroup-downloadable nil
1325   "Sorted list of articles in the current newsgroup that can be processed.")
1326
1327 (defvar gnus-newsgroup-unfetched nil
1328   "Sorted list of articles in the current newsgroup whose headers have
1329 not been fetched into the agent.
1330
1331 This list will always be a subset of gnus-newsgroup-undownloaded.")
1332
1333 (defvar gnus-newsgroup-undownloaded nil
1334   "List of articles in the current newsgroup that haven't been downloaded.")
1335
1336 (defvar gnus-newsgroup-unsendable nil
1337   "List of articles in the current newsgroup that won't be sent.")
1338
1339 (defvar gnus-newsgroup-bookmarks nil
1340   "List of articles in the current newsgroup that have bookmarks.")
1341
1342 (defvar gnus-newsgroup-dormant nil
1343   "Sorted list of dormant articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-unseen nil
1346   "List of unseen articles in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-seen nil
1349   "Range of seen articles in the current newsgroup.")
1350
1351 (defvar gnus-newsgroup-articles nil
1352   "List of articles in the current newsgroup.")
1353
1354 (defvar gnus-newsgroup-scored nil
1355   "List of scored articles in the current newsgroup.")
1356
1357 (defvar gnus-newsgroup-incorporated nil
1358   "List of incorporated articles in the current newsgroup.")
1359
1360 (defvar gnus-newsgroup-headers nil
1361   "List of article headers in the current newsgroup.")
1362
1363 (defvar gnus-newsgroup-threads nil)
1364
1365 (defvar gnus-newsgroup-prepared nil
1366   "Whether the current group has been prepared properly.")
1367
1368 (defvar gnus-newsgroup-ancient nil
1369   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-sparse nil)
1372
1373 (defvar gnus-current-article nil)
1374 (defvar gnus-article-current nil)
1375 (defvar gnus-current-headers nil)
1376 (defvar gnus-have-all-headers nil)
1377 (defvar gnus-last-article nil)
1378 (defvar gnus-newsgroup-history nil)
1379 (defvar gnus-newsgroup-charset nil)
1380 (defvar gnus-newsgroup-ephemeral-charset nil)
1381 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1382
1383 (defvar gnus-article-before-search nil)
1384
1385 (defconst gnus-summary-local-variables
1386   '(gnus-newsgroup-name
1387     gnus-newsgroup-begin gnus-newsgroup-end
1388     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1389     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1390     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1391     gnus-newsgroup-unselected gnus-newsgroup-marked
1392     gnus-newsgroup-spam-marked
1393     gnus-newsgroup-reads gnus-newsgroup-saved
1394     gnus-newsgroup-replied gnus-newsgroup-forwarded
1395     gnus-newsgroup-recent
1396     gnus-newsgroup-expirable
1397     gnus-newsgroup-processable gnus-newsgroup-killed
1398     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1399     gnus-newsgroup-unfetched
1400     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1401     gnus-newsgroup-seen gnus-newsgroup-articles
1402     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1403     gnus-newsgroup-headers gnus-newsgroup-threads
1404     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1405     gnus-current-article gnus-current-headers gnus-have-all-headers
1406     gnus-last-article gnus-article-internal-prepare-hook
1407     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1408     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1409     gnus-thread-expunge-below
1410     gnus-score-alist gnus-current-score-file
1411     (gnus-summary-expunge-below . global)
1412     (gnus-summary-mark-below . global)
1413     (gnus-orphan-score . global)
1414     gnus-newsgroup-active gnus-scores-exclude-files
1415     gnus-newsgroup-history gnus-newsgroup-ancient
1416     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1417     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1418     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1419     (gnus-newsgroup-expunged-tally . 0)
1420     gnus-cache-removable-articles gnus-newsgroup-cached
1421     gnus-newsgroup-data gnus-newsgroup-data-reverse
1422     gnus-newsgroup-limit gnus-newsgroup-limits
1423     gnus-newsgroup-charset gnus-newsgroup-display
1424     gnus-newsgroup-incorporated)
1425   "Variables that are buffer-local to the summary buffers.")
1426
1427 (defvar gnus-newsgroup-variables nil
1428   "A list of variables that have separate values in different newsgroups.
1429 A list of newsgroup (summary buffer) local variables, or cons of
1430 variables and their default values (when the default values are not
1431 nil), that should be made global while the summary buffer is active.
1432 These variables can be used to set variables in the group parameters
1433 while still allowing them to affect operations done in other
1434 buffers. For example:
1435
1436 \(setq gnus-newsgroup-variables
1437      '(message-use-followup-to
1438        (gnus-visible-headers .
1439          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1440 ")
1441
1442 ;; Byte-compiler warning.
1443 (eval-when-compile
1444   ;; Bind features so that require will believe that gnus-sum has
1445   ;; already been loaded (avoids infinite recursion)
1446   (let ((features (cons 'gnus-sum features)))
1447     ;; Several of the declarations in gnus-sum are needed to load the
1448     ;; following files. Right now, these definitions have been
1449     ;; compiled but not defined (evaluated).  We could either do a
1450     ;; eval-and-compile about all of the declarations or evaluate the
1451     ;; source file.
1452     (if (boundp 'gnus-newsgroup-variables)
1453         nil
1454       (if (featurep 'xemacs)
1455           (load "gnus-sum.el" t t t)
1456         (load "gnus-sum.el" t t t t)))
1457     (require 'gnus)
1458     (require 'gnus-agent)
1459     (require 'gnus-art)))
1460
1461 ;; Subject simplification.
1462
1463 (defun gnus-simplify-whitespace (str)
1464   "Remove excessive whitespace from STR."
1465   ;; Multiple spaces.
1466   (while (string-match "[ \t][ \t]+" str)
1467     (setq str (concat (substring str 0 (match-beginning 0))
1468                         " "
1469                         (substring str (match-end 0)))))
1470   ;; Leading spaces.
1471   (when (string-match "^[ \t]+" str)
1472     (setq str (substring str (match-end 0))))
1473   ;; Trailing spaces.
1474   (when (string-match "[ \t]+$" str)
1475     (setq str (substring str 0 (match-beginning 0))))
1476   str)
1477
1478 (defun gnus-simplify-all-whitespace (str)
1479   "Remove all whitespace from STR."
1480   (while (string-match "[ \t\n]+" str)
1481     (setq str (replace-match "" nil nil str)))
1482   str)
1483
1484 (defsubst gnus-simplify-subject-re (subject)
1485   "Remove \"Re:\" from subject lines."
1486   (if (string-match message-subject-re-regexp subject)
1487       (substring subject (match-end 0))
1488     subject))
1489
1490 (defun gnus-simplify-subject (subject &optional re-only)
1491   "Remove `Re:' and words in parentheses.
1492 If RE-ONLY is non-nil, strip leading `Re:'s only."
1493   (let ((case-fold-search t))           ;Ignore case.
1494     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1495     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1496       (setq subject (substring subject (match-end 0))))
1497     ;; Remove uninteresting prefixes.
1498     (when (and (not re-only)
1499                gnus-simplify-ignored-prefixes
1500                (string-match gnus-simplify-ignored-prefixes subject))
1501       (setq subject (substring subject (match-end 0))))
1502     ;; Remove words in parentheses from end.
1503     (unless re-only
1504       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1505         (setq subject (substring subject 0 (match-beginning 0)))))
1506     ;; Return subject string.
1507     subject))
1508
1509 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1510 ;; all whitespace.
1511 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1512   (goto-char (point-min))
1513   (while (re-search-forward regexp nil t)
1514     (replace-match (or newtext ""))))
1515
1516 (defun gnus-simplify-buffer-fuzzy ()
1517   "Simplify string in the buffer fuzzily.
1518 The string in the accessible portion of the current buffer is simplified.
1519 It is assumed to be a single-line subject.
1520 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1521 matter is removed.  Additional things can be deleted by setting
1522 `gnus-simplify-subject-fuzzy-regexp'."
1523   (let ((case-fold-search t)
1524         (modified-tick))
1525     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1526
1527     (while (not (eq modified-tick (buffer-modified-tick)))
1528       (setq modified-tick (buffer-modified-tick))
1529       (cond
1530        ((listp gnus-simplify-subject-fuzzy-regexp)
1531         (mapcar 'gnus-simplify-buffer-fuzzy-step
1532                 gnus-simplify-subject-fuzzy-regexp))
1533        (gnus-simplify-subject-fuzzy-regexp
1534         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1535       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1536       (gnus-simplify-buffer-fuzzy-step
1537        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1538       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1539
1540     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1541     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1542     (gnus-simplify-buffer-fuzzy-step " $")
1543     (gnus-simplify-buffer-fuzzy-step "^ +")))
1544
1545 (defun gnus-simplify-subject-fuzzy (subject)
1546   "Simplify a subject string fuzzily.
1547 See `gnus-simplify-buffer-fuzzy' for details."
1548   (save-excursion
1549     (gnus-set-work-buffer)
1550     (let ((case-fold-search t))
1551       ;; Remove uninteresting prefixes.
1552       (when (and gnus-simplify-ignored-prefixes
1553                  (string-match gnus-simplify-ignored-prefixes subject))
1554         (setq subject (substring subject (match-end 0))))
1555       (insert subject)
1556       (inline (gnus-simplify-buffer-fuzzy))
1557       (buffer-string))))
1558
1559 (defsubst gnus-simplify-subject-fully (subject)
1560   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1561   (cond
1562    (gnus-simplify-subject-functions
1563     (gnus-map-function gnus-simplify-subject-functions subject))
1564    ((null gnus-summary-gather-subject-limit)
1565     (gnus-simplify-subject-re subject))
1566    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1567     (gnus-simplify-subject-fuzzy subject))
1568    ((numberp gnus-summary-gather-subject-limit)
1569     (gnus-limit-string (gnus-simplify-subject-re subject)
1570                        gnus-summary-gather-subject-limit))
1571    (t
1572     subject)))
1573
1574 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1575   "Check whether two subjects are equal.
1576 If optional argument SIMPLE-FIRST is t, first argument is already
1577 simplified."
1578   (cond
1579    ((null simple-first)
1580     (equal (gnus-simplify-subject-fully s1)
1581            (gnus-simplify-subject-fully s2)))
1582    (t
1583     (equal s1
1584            (gnus-simplify-subject-fully s2)))))
1585
1586 (defun gnus-summary-bubble-group ()
1587   "Increase the score of the current group.
1588 This is a handy function to add to `gnus-summary-exit-hook' to
1589 increase the score of each group you read."
1590   (gnus-group-add-score gnus-newsgroup-name))
1591
1592 \f
1593 ;;;
1594 ;;; Gnus summary mode
1595 ;;;
1596
1597 (put 'gnus-summary-mode 'mode-class 'special)
1598
1599 (defvar gnus-article-commands-menu)
1600
1601 ;; Non-orthogonal keys
1602
1603 (gnus-define-keys gnus-summary-mode-map
1604   " " gnus-summary-next-page
1605   "\177" gnus-summary-prev-page
1606   [delete] gnus-summary-prev-page
1607   [backspace] gnus-summary-prev-page
1608   "\r" gnus-summary-scroll-up
1609   "\M-\r" gnus-summary-scroll-down
1610   "n" gnus-summary-next-unread-article
1611   "p" gnus-summary-prev-unread-article
1612   "N" gnus-summary-next-article
1613   "P" gnus-summary-prev-article
1614   "\M-\C-n" gnus-summary-next-same-subject
1615   "\M-\C-p" gnus-summary-prev-same-subject
1616   "\M-n" gnus-summary-next-unread-subject
1617   "\M-p" gnus-summary-prev-unread-subject
1618   "." gnus-summary-first-unread-article
1619   "," gnus-summary-best-unread-article
1620   "\M-s" gnus-summary-search-article-forward
1621   "\M-r" gnus-summary-search-article-backward
1622   "<" gnus-summary-beginning-of-article
1623   ">" gnus-summary-end-of-article
1624   "j" gnus-summary-goto-article
1625   "^" gnus-summary-refer-parent-article
1626   "\M-^" gnus-summary-refer-article
1627   "u" gnus-summary-tick-article-forward
1628   "!" gnus-summary-tick-article-forward
1629   "U" gnus-summary-tick-article-backward
1630   "d" gnus-summary-mark-as-read-forward
1631   "D" gnus-summary-mark-as-read-backward
1632   "E" gnus-summary-mark-as-expirable
1633   "\M-u" gnus-summary-clear-mark-forward
1634   "\M-U" gnus-summary-clear-mark-backward
1635   "k" gnus-summary-kill-same-subject-and-select
1636   "\C-k" gnus-summary-kill-same-subject
1637   "\M-\C-k" gnus-summary-kill-thread
1638   "\M-\C-l" gnus-summary-lower-thread
1639   "e" gnus-summary-edit-article
1640   "#" gnus-summary-mark-as-processable
1641   "\M-#" gnus-summary-unmark-as-processable
1642   "\M-\C-t" gnus-summary-toggle-threads
1643   "\M-\C-s" gnus-summary-show-thread
1644   "\M-\C-h" gnus-summary-hide-thread
1645   "\M-\C-f" gnus-summary-next-thread
1646   "\M-\C-b" gnus-summary-prev-thread
1647   [(meta down)] gnus-summary-next-thread
1648   [(meta up)] gnus-summary-prev-thread
1649   "\M-\C-u" gnus-summary-up-thread
1650   "\M-\C-d" gnus-summary-down-thread
1651   "&" gnus-summary-execute-command
1652   "c" gnus-summary-catchup-and-exit
1653   "\C-w" gnus-summary-mark-region-as-read
1654   "\C-t" gnus-summary-toggle-truncation
1655   "?" gnus-summary-mark-as-dormant
1656   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1657   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1658   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1659   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1660   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1661   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1662   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1663   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1664   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1665   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1666   "=" gnus-summary-expand-window
1667   "\C-x\C-s" gnus-summary-reselect-current-group
1668   "\M-g" gnus-summary-rescan-group
1669   "w" gnus-summary-stop-page-breaking
1670   "\C-c\C-r" gnus-summary-caesar-message
1671   "\M-t" gnus-summary-toggle-mime
1672   "f" gnus-summary-followup
1673   "F" gnus-summary-followup-with-original
1674   "C" gnus-summary-cancel-article
1675   "r" gnus-summary-reply
1676   "R" gnus-summary-reply-with-original
1677   "\C-c\C-f" gnus-summary-mail-forward
1678   "o" gnus-summary-save-article
1679   "\C-o" gnus-summary-save-article-mail
1680   "|" gnus-summary-pipe-output
1681   "\M-k" gnus-summary-edit-local-kill
1682   "\M-K" gnus-summary-edit-global-kill
1683   ;; "V" gnus-version
1684   "\C-c\C-d" gnus-summary-describe-group
1685   "q" gnus-summary-exit
1686   "Q" gnus-summary-exit-no-update
1687   "\C-c\C-i" gnus-info-find-node
1688   gnus-mouse-2 gnus-mouse-pick-article
1689   "m" gnus-summary-mail-other-window
1690   "a" gnus-summary-post-news
1691   "i" gnus-summary-news-other-window
1692   "x" gnus-summary-limit-to-unread
1693   "s" gnus-summary-isearch-article
1694   "t" gnus-summary-toggle-header
1695   "g" gnus-summary-show-article
1696   "l" gnus-summary-goto-last-article
1697   "v" gnus-summary-preview-mime-message
1698   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1699   "\C-d" gnus-summary-enter-digest-group
1700   "\M-\C-d" gnus-summary-read-document
1701   "\M-\C-e" gnus-summary-edit-parameters
1702   "\M-\C-a" gnus-summary-customize-parameters
1703   "\C-c\C-b" gnus-bug
1704   "\C-c\C-n" gnus-namazu-search
1705   "*" gnus-cache-enter-article
1706   "\M-*" gnus-cache-remove-article
1707   "\M-&" gnus-summary-universal-argument
1708   "\C-l" gnus-recenter
1709   "I" gnus-summary-increase-score
1710   "L" gnus-summary-lower-score
1711   "\M-i" gnus-symbolic-argument
1712   "h" gnus-summary-select-article-buffer
1713
1714   "V" gnus-summary-score-map
1715   "X" gnus-uu-extract-map
1716   "S" gnus-summary-send-map)
1717
1718   ;; Sort of orthogonal keymap
1719 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1720   "t" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "d" gnus-summary-mark-as-read-forward
1723   "r" gnus-summary-mark-as-read-forward
1724   "c" gnus-summary-clear-mark-forward
1725   " " gnus-summary-clear-mark-forward
1726   "e" gnus-summary-mark-as-expirable
1727   "x" gnus-summary-mark-as-expirable
1728   "?" gnus-summary-mark-as-dormant
1729   "b" gnus-summary-set-bookmark
1730   "B" gnus-summary-remove-bookmark
1731   "#" gnus-summary-mark-as-processable
1732   "\M-#" gnus-summary-unmark-as-processable
1733   "S" gnus-summary-limit-include-expunged
1734   "C" gnus-summary-catchup
1735   "H" gnus-summary-catchup-to-here
1736   "h" gnus-summary-catchup-from-here
1737   "\C-c" gnus-summary-catchup-all
1738   "k" gnus-summary-kill-same-subject-and-select
1739   "K" gnus-summary-kill-same-subject
1740   "P" gnus-uu-mark-map)
1741
1742 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1743   "c" gnus-summary-clear-above
1744   "u" gnus-summary-tick-above
1745   "m" gnus-summary-mark-above
1746   "k" gnus-summary-kill-below)
1747
1748 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1749   "/" gnus-summary-limit-to-subject
1750   "n" gnus-summary-limit-to-articles
1751   "w" gnus-summary-pop-limit
1752   "s" gnus-summary-limit-to-subject
1753   "a" gnus-summary-limit-to-author
1754   "u" gnus-summary-limit-to-unread
1755   "m" gnus-summary-limit-to-marks
1756   "M" gnus-summary-limit-exclude-marks
1757   "v" gnus-summary-limit-to-score
1758   "*" gnus-summary-limit-include-cached
1759   "D" gnus-summary-limit-include-dormant
1760   "T" gnus-summary-limit-include-thread
1761   "d" gnus-summary-limit-exclude-dormant
1762   "t" gnus-summary-limit-to-age
1763   "." gnus-summary-limit-to-unseen
1764   "x" gnus-summary-limit-to-extra
1765   "p" gnus-summary-limit-to-display-predicate
1766   "E" gnus-summary-limit-include-expunged
1767   "c" gnus-summary-limit-exclude-childless-dormant
1768   "C" gnus-summary-limit-mark-excluded-as-read
1769   "o" gnus-summary-insert-old-articles
1770   "N" gnus-summary-insert-new-articles)
1771
1772 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1773   "n" gnus-summary-next-unread-article
1774   "p" gnus-summary-prev-unread-article
1775   "N" gnus-summary-next-article
1776   "P" gnus-summary-prev-article
1777   "\C-n" gnus-summary-next-same-subject
1778   "\C-p" gnus-summary-prev-same-subject
1779   "\M-n" gnus-summary-next-unread-subject
1780   "\M-p" gnus-summary-prev-unread-subject
1781   "f" gnus-summary-first-unread-article
1782   "b" gnus-summary-best-unread-article
1783   "j" gnus-summary-goto-article
1784   "g" gnus-summary-goto-subject
1785   "l" gnus-summary-goto-last-article
1786   "o" gnus-summary-pop-article)
1787
1788 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1789   "k" gnus-summary-kill-thread
1790   "l" gnus-summary-lower-thread
1791   "i" gnus-summary-raise-thread
1792   "T" gnus-summary-toggle-threads
1793   "t" gnus-summary-rethread-current
1794   "^" gnus-summary-reparent-thread
1795   "s" gnus-summary-show-thread
1796   "S" gnus-summary-show-all-threads
1797   "h" gnus-summary-hide-thread
1798   "H" gnus-summary-hide-all-threads
1799   "n" gnus-summary-next-thread
1800   "p" gnus-summary-prev-thread
1801   "u" gnus-summary-up-thread
1802   "o" gnus-summary-top-thread
1803   "d" gnus-summary-down-thread
1804   "#" gnus-uu-mark-thread
1805   "\M-#" gnus-uu-unmark-thread)
1806
1807 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1808   "g" gnus-summary-prepare
1809   "c" gnus-summary-insert-cached-articles
1810   "d" gnus-summary-insert-dormant-articles)
1811
1812 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1813   "c" gnus-summary-catchup-and-exit
1814   "C" gnus-summary-catchup-all-and-exit
1815   "E" gnus-summary-exit-no-update
1816   "J" gnus-summary-jump-to-other-group
1817   "Q" gnus-summary-exit
1818   "Z" gnus-summary-exit
1819   "n" gnus-summary-catchup-and-goto-next-group
1820   "R" gnus-summary-reselect-current-group
1821   "G" gnus-summary-rescan-group
1822   "N" gnus-summary-next-group
1823   "s" gnus-summary-save-newsrc
1824   "P" gnus-summary-prev-group)
1825
1826 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1827   " " gnus-summary-next-page
1828   "n" gnus-summary-next-page
1829   "\177" gnus-summary-prev-page
1830   [delete] gnus-summary-prev-page
1831   "p" gnus-summary-prev-page
1832   "\r" gnus-summary-scroll-up
1833   "\M-\r" gnus-summary-scroll-down
1834   "<" gnus-summary-beginning-of-article
1835   ">" gnus-summary-end-of-article
1836   "b" gnus-summary-beginning-of-article
1837   "e" gnus-summary-end-of-article
1838   "^" gnus-summary-refer-parent-article
1839   "r" gnus-summary-refer-parent-article
1840   "D" gnus-summary-enter-digest-group
1841   "R" gnus-summary-refer-references
1842   "T" gnus-summary-refer-thread
1843   "g" gnus-summary-show-article
1844   "s" gnus-summary-isearch-article
1845   "P" gnus-summary-print-article
1846   "M" gnus-mailing-list-insinuate
1847   "t" gnus-article-babel)
1848
1849 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1850   "b" gnus-article-add-buttons
1851   "B" gnus-article-add-buttons-to-head
1852   "o" gnus-article-treat-overstrike
1853   "e" gnus-article-emphasize
1854   "w" gnus-article-fill-cited-article
1855   "Q" gnus-article-fill-long-lines
1856   "C" gnus-article-capitalize-sentences
1857   "c" gnus-article-remove-cr
1858   "Z" gnus-article-decode-HZ
1859   "h" gnus-article-wash-html
1860   "u" gnus-article-unsplit-urls
1861   "f" gnus-article-display-x-face
1862   "l" gnus-summary-stop-page-breaking
1863   "r" gnus-summary-caesar-message
1864   "m" gnus-summary-morse-message
1865   "t" gnus-summary-toggle-header
1866   "g" gnus-treat-smiley
1867   "v" gnus-summary-verbose-headers
1868   "m" gnus-summary-toggle-mime
1869   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1870   "p" gnus-article-verify-x-pgp-sig
1871   "d" gnus-article-treat-dumbquotes)
1872
1873 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1874   ;; mnemonic: deuglif*Y*
1875   "u" gnus-article-outlook-unwrap-lines
1876   "a" gnus-article-outlook-repair-attribution
1877   "c" gnus-article-outlook-rearrange-citation
1878   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1879
1880 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1881   "a" gnus-article-hide
1882   "h" gnus-article-hide-headers
1883   "b" gnus-article-hide-boring-headers
1884   "s" gnus-article-hide-signature
1885   "c" gnus-article-hide-citation
1886   "C" gnus-article-hide-citation-in-followups
1887   "l" gnus-article-hide-list-identifiers
1888   "B" gnus-article-strip-banner
1889   "P" gnus-article-hide-pem
1890   "\C-c" gnus-article-hide-citation-maybe)
1891
1892 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1893   "a" gnus-article-highlight
1894   "h" gnus-article-highlight-headers
1895   "c" gnus-article-highlight-citation
1896   "s" gnus-article-highlight-signature)
1897
1898 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1899   "f" gnus-article-treat-fold-headers
1900   "u" gnus-article-treat-unfold-headers
1901   "n" gnus-article-treat-fold-newsgroups)
1902
1903 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1904   "x" gnus-article-display-x-face
1905   "d" gnus-article-display-face
1906   "s" gnus-treat-smiley
1907   "D" gnus-article-remove-images
1908   "f" gnus-treat-from-picon
1909   "m" gnus-treat-mail-picon
1910   "n" gnus-treat-newsgroups-picon)
1911
1912 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1913   "z" gnus-article-date-ut
1914   "u" gnus-article-date-ut
1915   "l" gnus-article-date-local
1916   "p" gnus-article-date-english
1917   "e" gnus-article-date-lapsed
1918   "o" gnus-article-date-original
1919   "i" gnus-article-date-iso8601
1920   "s" gnus-article-date-user)
1921
1922 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1923   "t" gnus-article-remove-trailing-blank-lines
1924   "l" gnus-article-strip-leading-blank-lines
1925   "m" gnus-article-strip-multiple-blank-lines
1926   "a" gnus-article-strip-blank-lines
1927   "A" gnus-article-strip-all-blank-lines
1928   "s" gnus-article-strip-leading-space
1929   "e" gnus-article-strip-trailing-space
1930   "w" gnus-article-remove-leading-whitespace)
1931
1932 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1933   "v" gnus-version
1934   "f" gnus-summary-fetch-faq
1935   "d" gnus-summary-describe-group
1936   "h" gnus-summary-describe-briefly
1937   "i" gnus-info-find-node
1938   "c" gnus-group-fetch-charter
1939   "C" gnus-group-fetch-control)
1940
1941 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1942   "e" gnus-summary-expire-articles
1943   "\M-\C-e" gnus-summary-expire-articles-now
1944   "\177" gnus-summary-delete-article
1945   [delete] gnus-summary-delete-article
1946   [backspace] gnus-summary-delete-article
1947   "m" gnus-summary-move-article
1948   "r" gnus-summary-respool-article
1949   "w" gnus-summary-edit-article
1950   "c" gnus-summary-copy-article
1951   "B" gnus-summary-crosspost-article
1952   "q" gnus-summary-respool-query
1953   "t" gnus-summary-respool-trace
1954   "i" gnus-summary-import-article
1955   "I" gnus-summary-create-article
1956   "p" gnus-summary-article-posted-p)
1957
1958 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1959   "o" gnus-summary-save-article
1960   "m" gnus-summary-save-article-mail
1961   "F" gnus-summary-write-article-file
1962   "r" gnus-summary-save-article-rmail
1963   "f" gnus-summary-save-article-file
1964   "b" gnus-summary-save-article-body-file
1965   "h" gnus-summary-save-article-folder
1966   "v" gnus-summary-save-article-vm
1967   "p" gnus-summary-pipe-output
1968   "P" gnus-summary-muttprint
1969   "s" gnus-soup-add-article)
1970
1971 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1972   "b" gnus-summary-display-buttonized
1973   "m" gnus-summary-repair-multipart
1974   "v" gnus-article-view-part
1975   "o" gnus-article-save-part
1976   "c" gnus-article-copy-part
1977   "C" gnus-article-view-part-as-charset
1978   "e" gnus-article-view-part-externally
1979   "E" gnus-article-encrypt-body
1980   "i" gnus-article-inline-part
1981   "|" gnus-article-pipe-part)
1982
1983 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1984   "p" gnus-summary-mark-as-processable
1985   "u" gnus-summary-unmark-as-processable
1986   "U" gnus-summary-unmark-all-processable
1987   "v" gnus-uu-mark-over
1988   "s" gnus-uu-mark-series
1989   "r" gnus-uu-mark-region
1990   "g" gnus-uu-unmark-region
1991   "R" gnus-uu-mark-by-regexp
1992   "G" gnus-uu-unmark-by-regexp
1993   "t" gnus-uu-mark-thread
1994   "T" gnus-uu-unmark-thread
1995   "a" gnus-uu-mark-all
1996   "b" gnus-uu-mark-buffer
1997   "S" gnus-uu-mark-sparse
1998   "k" gnus-summary-kill-process-mark
1999   "y" gnus-summary-yank-process-mark
2000   "w" gnus-summary-save-process-mark
2001   "i" gnus-uu-invert-processable)
2002
2003 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2004   ;;"x" gnus-uu-extract-any
2005   "m" gnus-summary-save-parts
2006   "u" gnus-uu-decode-uu
2007   "U" gnus-uu-decode-uu-and-save
2008   "s" gnus-uu-decode-unshar
2009   "S" gnus-uu-decode-unshar-and-save
2010   "o" gnus-uu-decode-save
2011   "O" gnus-uu-decode-save
2012   "b" gnus-uu-decode-binhex
2013   "B" gnus-uu-decode-binhex
2014   "p" gnus-uu-decode-postscript
2015   "P" gnus-uu-decode-postscript-and-save)
2016
2017 (gnus-define-keys
2018     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2019   "u" gnus-uu-decode-uu-view
2020   "U" gnus-uu-decode-uu-and-save-view
2021   "s" gnus-uu-decode-unshar-view
2022   "S" gnus-uu-decode-unshar-and-save-view
2023   "o" gnus-uu-decode-save-view
2024   "O" gnus-uu-decode-save-view
2025   "b" gnus-uu-decode-binhex-view
2026   "B" gnus-uu-decode-binhex-view
2027   "p" gnus-uu-decode-postscript-view
2028   "P" gnus-uu-decode-postscript-and-save-view)
2029
2030 (defvar gnus-article-post-menu nil)
2031
2032 (defconst gnus-summary-menu-maxlen 20)
2033
2034 (defun gnus-summary-menu-split (menu)
2035   ;; If we have lots of elements, divide them into groups of 20
2036   ;; and make a pane (or submenu) for each one.
2037   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2038       (let ((menu menu) sublists next
2039             (i 1))
2040         (while menu
2041           ;; Pull off the next gnus-summary-menu-maxlen elements
2042           ;; and make them the next element of sublist.
2043           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2044           (if next
2045               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2046                       nil))
2047           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2048                                              (aref (car (last menu)) 0)) menu)
2049                                sublists))
2050           (setq i (1+ i))
2051           (setq menu next))
2052         (nreverse sublists))
2053     ;; Few elements--put them all in one pane.
2054     menu))
2055
2056 (defun gnus-summary-make-menu-bar ()
2057   (gnus-turn-off-edit-menu 'summary)
2058
2059   (unless (boundp 'gnus-summary-misc-menu)
2060
2061     (easy-menu-define
2062      gnus-summary-kill-menu gnus-summary-mode-map ""
2063      (cons
2064       "Score"
2065       (nconc
2066        (list
2067         ["Customize" gnus-score-customize t])
2068        (gnus-make-score-map 'increase)
2069        (gnus-make-score-map 'lower)
2070        '(("Mark"
2071           ["Kill below" gnus-summary-kill-below t]
2072           ["Mark above" gnus-summary-mark-above t]
2073           ["Tick above" gnus-summary-tick-above t]
2074           ["Clear above" gnus-summary-clear-above t])
2075          ["Current score" gnus-summary-current-score t]
2076          ["Set score" gnus-summary-set-score t]
2077          ["Switch current score file..." gnus-score-change-score-file t]
2078          ["Set mark below..." gnus-score-set-mark-below t]
2079          ["Set expunge below..." gnus-score-set-expunge-below t]
2080          ["Edit current score file" gnus-score-edit-current-scores t]
2081          ["Edit score file" gnus-score-edit-file t]
2082          ["Trace score" gnus-score-find-trace t]
2083          ["Find words" gnus-score-find-favourite-words t]
2084          ["Rescore buffer" gnus-summary-rescore t]
2085          ["Increase score..." gnus-summary-increase-score t]
2086          ["Lower score..." gnus-summary-lower-score t]))))
2087
2088     ;; Define both the Article menu in the summary buffer and the
2089     ;; equivalent Commands menu in the article buffer here for
2090     ;; consistency.
2091     (let ((innards
2092            `(("Hide"
2093               ["All" gnus-article-hide t]
2094               ["Headers" gnus-article-hide-headers t]
2095               ["Signature" gnus-article-hide-signature t]
2096               ["Citation" gnus-article-hide-citation t]
2097               ["List identifiers" gnus-article-hide-list-identifiers t]
2098               ["Banner" gnus-article-strip-banner t]
2099               ["Boring headers" gnus-article-hide-boring-headers t])
2100              ("Highlight"
2101               ["All" gnus-article-highlight t]
2102               ["Headers" gnus-article-highlight-headers t]
2103               ["Signature" gnus-article-highlight-signature t]
2104               ["Citation" gnus-article-highlight-citation t])
2105              ("Date"
2106               ["Local" gnus-article-date-local t]
2107               ["ISO8601" gnus-article-date-iso8601 t]
2108               ["UT" gnus-article-date-ut t]
2109               ["Original" gnus-article-date-original t]
2110               ["Lapsed" gnus-article-date-lapsed t]
2111               ["User-defined" gnus-article-date-user t])
2112              ("Display"
2113               ["Remove images" gnus-article-remove-images t]
2114               ["Toggle smiley" gnus-treat-smiley t]
2115               ["Show X-Face" gnus-article-display-x-face t]
2116               ["Show picons in From" gnus-treat-from-picon t]
2117               ["Show picons in mail headers" gnus-treat-mail-picon t]
2118               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2119               ("View as different encoding"
2120                ,@(gnus-summary-menu-split
2121                   (mapcar
2122                    (lambda (cs)
2123                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2124                      ;; forms for menu commands, we should provide intern'ed
2125                      ;; function symbols.
2126                      (let ((command (intern (format "\
2127 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2128                        (fset command
2129                              `(lambda ()
2130                                 (interactive)
2131                                 (let ((gnus-summary-show-article-charset-alist
2132                                        '((1 . ,cs))))
2133                                   (gnus-summary-show-article 1))))
2134                        `[,(symbol-name cs) ,command t]))
2135                    (sort (if (fboundp 'coding-system-list)
2136                              (coding-system-list)
2137                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2138                            )
2139                          'string<)))))
2140              ("Washing"
2141               ("Remove Blanks"
2142                ["Leading" gnus-article-strip-leading-blank-lines t]
2143                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2144                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2145                ["All of the above" gnus-article-strip-blank-lines t]
2146                ["All" gnus-article-strip-all-blank-lines t]
2147                ["Leading space" gnus-article-strip-leading-space t]
2148                ["Trailing space" gnus-article-strip-trailing-space t]
2149                ["Leading space in headers"
2150                 gnus-article-remove-leading-whitespace t])
2151               ["Overstrike" gnus-article-treat-overstrike t]
2152               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2153               ["Emphasis" gnus-article-emphasize t]
2154               ["Word wrap" gnus-article-fill-cited-article t]
2155               ["Fill long lines" gnus-article-fill-long-lines t]
2156               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2157               ["CR" gnus-article-remove-cr t]
2158               ["Rot 13" gnus-summary-caesar-message
2159                ,@(if (featurep 'xemacs) '(t)
2160                    '(:help "\"Caesar rotate\" article by 13"))]
2161               ["Morse decode" gnus-summary-morse-message t]
2162               ["Unix pipe..." gnus-summary-pipe-message t]
2163               ["Add buttons" gnus-article-add-buttons t]
2164               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2165               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2166               ["Toggle MIME" gnus-summary-toggle-mime t]
2167               ["Verbose header" gnus-summary-verbose-headers t]
2168               ["Toggle header" gnus-summary-toggle-header t]
2169               ["Unfold headers" gnus-article-treat-unfold-headers t]
2170               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2171               ["Html" gnus-article-wash-html t]
2172               ["URLs" gnus-article-unsplit-urls t]
2173               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2174               ["HZ" gnus-article-decode-HZ t]
2175               ("(Outlook) Deuglify"
2176                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2177                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2178                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2179                ["Full (Outlook) deuglify"
2180                 gnus-article-outlook-deuglify-article t])
2181               )
2182              ("Output"
2183               ["Save in default format" gnus-summary-save-article
2184                ,@(if (featurep 'xemacs) '(t)
2185                    '(:help "Save article using default method"))]
2186               ["Save in file" gnus-summary-save-article-file
2187                ,@(if (featurep 'xemacs) '(t)
2188                    '(:help "Save article in file"))]
2189               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2190               ["Save in MH folder" gnus-summary-save-article-folder t]
2191               ["Save in VM folder" gnus-summary-save-article-vm t]
2192               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2193               ["Save body in file" gnus-summary-save-article-body-file t]
2194               ["Pipe through a filter" gnus-summary-pipe-output t]
2195               ["Add to SOUP packet" gnus-soup-add-article t]
2196               ["Print with Muttprint" gnus-summary-muttprint t]
2197               ["Print" gnus-summary-print-article t])
2198              ("Backend"
2199               ["Respool article..." gnus-summary-respool-article t]
2200               ["Move article..." gnus-summary-move-article
2201                (gnus-check-backend-function
2202                 'request-move-article gnus-newsgroup-name)]
2203               ["Copy article..." gnus-summary-copy-article t]
2204               ["Crosspost article..." gnus-summary-crosspost-article
2205                (gnus-check-backend-function
2206                 'request-replace-article gnus-newsgroup-name)]
2207               ["Import file..." gnus-summary-import-article t]
2208               ["Create article..." gnus-summary-create-article t]
2209               ["Check if posted" gnus-summary-article-posted-p t]
2210               ["Edit article" gnus-summary-edit-article
2211                (not (gnus-group-read-only-p))]
2212               ["Delete article" gnus-summary-delete-article
2213                (gnus-check-backend-function
2214                 'request-expire-articles gnus-newsgroup-name)]
2215               ["Query respool" gnus-summary-respool-query t]
2216               ["Trace respool" gnus-summary-respool-trace t]
2217               ["Delete expirable articles" gnus-summary-expire-articles-now
2218                (gnus-check-backend-function
2219                 'request-expire-articles gnus-newsgroup-name)])
2220              ("Extract"
2221               ["Uudecode" gnus-uu-decode-uu
2222                ,@(if (featurep 'xemacs) '(t)
2223                    '(:help "Decode uuencoded article(s)"))]
2224               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2225               ["Unshar" gnus-uu-decode-unshar t]
2226               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2227               ["Save" gnus-uu-decode-save t]
2228               ["Binhex" gnus-uu-decode-binhex t]
2229               ["Postscript" gnus-uu-decode-postscript t])
2230              ("Cache"
2231               ["Enter article" gnus-cache-enter-article t]
2232               ["Remove article" gnus-cache-remove-article t])
2233              ["Translate" gnus-article-babel t]
2234              ["Select article buffer" gnus-summary-select-article-buffer t]
2235              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2236              ["Isearch article..." gnus-summary-isearch-article t]
2237              ["Beginning of the article" gnus-summary-beginning-of-article t]
2238              ["End of the article" gnus-summary-end-of-article t]
2239              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2240              ["Fetch referenced articles" gnus-summary-refer-references t]
2241              ["Fetch current thread" gnus-summary-refer-thread t]
2242              ["Fetch article with id..." gnus-summary-refer-article t]
2243              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2244              ["Redisplay" gnus-summary-show-article t]
2245              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2246       (easy-menu-define
2247        gnus-summary-article-menu gnus-summary-mode-map ""
2248        (cons "Article" innards))
2249
2250       (if (not (keymapp gnus-summary-article-menu))
2251           (easy-menu-define
2252            gnus-article-commands-menu gnus-article-mode-map ""
2253            (cons "Commands" innards))
2254         ;; in Emacs, don't share menu.
2255         (setq gnus-article-commands-menu
2256               (copy-keymap gnus-summary-article-menu))
2257         (define-key gnus-article-mode-map [menu-bar commands]
2258           (cons "Commands" gnus-article-commands-menu))))
2259
2260     (easy-menu-define
2261      gnus-summary-thread-menu gnus-summary-mode-map ""
2262      '("Threads"
2263        ["Find all messages in thread" gnus-summary-refer-thread t]
2264        ["Toggle threading" gnus-summary-toggle-threads t]
2265        ["Hide threads" gnus-summary-hide-all-threads t]
2266        ["Show threads" gnus-summary-show-all-threads t]
2267        ["Hide thread" gnus-summary-hide-thread t]
2268        ["Show thread" gnus-summary-show-thread t]
2269        ["Go to next thread" gnus-summary-next-thread t]
2270        ["Go to previous thread" gnus-summary-prev-thread t]
2271        ["Go down thread" gnus-summary-down-thread t]
2272        ["Go up thread" gnus-summary-up-thread t]
2273        ["Top of thread" gnus-summary-top-thread t]
2274        ["Mark thread as read" gnus-summary-kill-thread t]
2275        ["Lower thread score" gnus-summary-lower-thread t]
2276        ["Raise thread score" gnus-summary-raise-thread t]
2277        ["Rethread current" gnus-summary-rethread-current t]))
2278
2279     (easy-menu-define
2280      gnus-summary-post-menu gnus-summary-mode-map ""
2281      `("Post"
2282        ["Send a message (mail or news)" gnus-summary-post-news
2283         ,@(if (featurep 'xemacs) '(t)
2284             '(:help "Post an article"))]
2285        ["Followup" gnus-summary-followup
2286         ,@(if (featurep 'xemacs) '(t)
2287             '(:help "Post followup to this article"))]
2288        ["Followup and yank" gnus-summary-followup-with-original
2289         ,@(if (featurep 'xemacs) '(t)
2290             '(:help "Post followup to this article, quoting its contents"))]
2291        ["Supersede article" gnus-summary-supersede-article t]
2292        ["Cancel article" gnus-summary-cancel-article
2293         ,@(if (featurep 'xemacs) '(t)
2294             '(:help "Cancel an article you posted"))]
2295        ["Reply" gnus-summary-reply t]
2296        ["Reply and yank" gnus-summary-reply-with-original t]
2297        ["Wide reply" gnus-summary-wide-reply t]
2298        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2299         ,@(if (featurep 'xemacs) '(t)
2300             '(:help "Mail a reply, quoting this article"))]
2301        ["Very wide reply" gnus-summary-very-wide-reply t]
2302        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2303         ,@(if (featurep 'xemacs) '(t)
2304             '(:help "Mail a very wide reply, quoting this article"))]
2305        ["Mail forward" gnus-summary-mail-forward t]
2306        ["Post forward" gnus-summary-post-forward t]
2307        ["Digest and mail" gnus-summary-digest-mail-forward t]
2308        ["Digest and post" gnus-summary-digest-post-forward t]
2309        ["Resend message" gnus-summary-resend-message t]
2310        ["Resend message edit" gnus-summary-resend-message-edit t]
2311        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2312        ["Send a mail" gnus-summary-mail-other-window t]
2313        ["Create a local message" gnus-summary-news-other-window t]
2314        ["Uuencode and post" gnus-uu-post-news
2315         ,@(if (featurep 'xemacs) '(t)
2316             '(:help "Post a uuencoded article"))]
2317        ["Followup via news" gnus-summary-followup-to-mail t]
2318        ["Followup via news and yank"
2319         gnus-summary-followup-to-mail-with-original t]
2320        ;;("Draft"
2321        ;;["Send" gnus-summary-send-draft t]
2322        ;;["Send bounced" gnus-resend-bounced-mail t])
2323        ))
2324
2325     (cond
2326      ((not (keymapp gnus-summary-post-menu))
2327       (setq gnus-article-post-menu gnus-summary-post-menu))
2328      ((not gnus-article-post-menu)
2329       ;; Don't share post menu.
2330       (setq gnus-article-post-menu
2331             (copy-keymap gnus-summary-post-menu))))
2332     (define-key gnus-article-mode-map [menu-bar post]
2333       (cons "Post" gnus-article-post-menu))
2334
2335     (easy-menu-define
2336      gnus-summary-misc-menu gnus-summary-mode-map ""
2337      `("Gnus"
2338        ("Mark Read"
2339         ["Mark as read" gnus-summary-mark-as-read-forward t]
2340         ["Mark same subject and select"
2341          gnus-summary-kill-same-subject-and-select t]
2342         ["Mark same subject" gnus-summary-kill-same-subject t]
2343         ["Catchup" gnus-summary-catchup
2344          ,@(if (featurep 'xemacs) '(t)
2345              '(:help "Mark unread articles in this group as read"))]
2346         ["Catchup all" gnus-summary-catchup-all t]
2347         ["Catchup to here" gnus-summary-catchup-to-here t]
2348         ["Catchup from here" gnus-summary-catchup-from-here t]
2349         ["Catchup region" gnus-summary-mark-region-as-read
2350          (gnus-mark-active-p)]
2351         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2352        ("Mark Various"
2353         ["Tick" gnus-summary-tick-article-forward t]
2354         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2355         ["Remove marks" gnus-summary-clear-mark-forward t]
2356         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2357         ["Set bookmark" gnus-summary-set-bookmark t]
2358         ["Remove bookmark" gnus-summary-remove-bookmark t])
2359        ("Limit to"
2360         ["Marks..." gnus-summary-limit-to-marks t]
2361         ["Subject..." gnus-summary-limit-to-subject t]
2362         ["Author..." gnus-summary-limit-to-author t]
2363         ["Age..." gnus-summary-limit-to-age t]
2364         ["Extra..." gnus-summary-limit-to-extra t]
2365         ["Score..." gnus-summary-limit-to-score t]
2366         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2367         ["Unread" gnus-summary-limit-to-unread t]
2368         ["Unseen" gnus-summary-limit-to-unseen t]
2369         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2370         ["Next articles" gnus-summary-limit-to-articles t]
2371         ["Pop limit" gnus-summary-pop-limit t]
2372         ["Show dormant" gnus-summary-limit-include-dormant t]
2373         ["Hide childless dormant"
2374          gnus-summary-limit-exclude-childless-dormant t]
2375         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2376         ["Hide marked" gnus-summary-limit-exclude-marks t]
2377         ["Show expunged" gnus-summary-limit-include-expunged t])
2378        ("Process Mark"
2379         ["Set mark" gnus-summary-mark-as-processable t]
2380         ["Remove mark" gnus-summary-unmark-as-processable t]
2381         ["Remove all marks" gnus-summary-unmark-all-processable t]
2382         ["Mark above" gnus-uu-mark-over t]
2383         ["Mark series" gnus-uu-mark-series t]
2384         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2385         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2386         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2387         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2388         ["Mark all" gnus-uu-mark-all t]
2389         ["Mark buffer" gnus-uu-mark-buffer t]
2390         ["Mark sparse" gnus-uu-mark-sparse t]
2391         ["Mark thread" gnus-uu-mark-thread t]
2392         ["Unmark thread" gnus-uu-unmark-thread t]
2393         ("Process Mark Sets"
2394          ["Kill" gnus-summary-kill-process-mark t]
2395          ["Yank" gnus-summary-yank-process-mark
2396           gnus-newsgroup-process-stack]
2397          ["Save" gnus-summary-save-process-mark t]
2398          ["Run command on marked..." gnus-summary-universal-argument t]))
2399        ("Scroll article"
2400         ["Page forward" gnus-summary-next-page
2401          ,@(if (featurep 'xemacs) '(t)
2402              '(:help "Show next page of article"))]
2403         ["Page backward" gnus-summary-prev-page
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Show previous page of article"))]
2406         ["Line forward" gnus-summary-scroll-up t])
2407        ("Move"
2408         ["Next unread article" gnus-summary-next-unread-article t]
2409         ["Previous unread article" gnus-summary-prev-unread-article t]
2410         ["Next article" gnus-summary-next-article t]
2411         ["Previous article" gnus-summary-prev-article t]
2412         ["Next unread subject" gnus-summary-next-unread-subject t]
2413         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2414         ["Next article same subject" gnus-summary-next-same-subject t]
2415         ["Previous article same subject" gnus-summary-prev-same-subject t]
2416         ["First unread article" gnus-summary-first-unread-article t]
2417         ["Best unread article" gnus-summary-best-unread-article t]
2418         ["Go to subject number..." gnus-summary-goto-subject t]
2419         ["Go to article number..." gnus-summary-goto-article t]
2420         ["Go to the last article" gnus-summary-goto-last-article t]
2421         ["Pop article off history" gnus-summary-pop-article t])
2422        ("Sort"
2423         ["Sort by number" gnus-summary-sort-by-number t]
2424         ["Sort by author" gnus-summary-sort-by-author t]
2425         ["Sort by subject" gnus-summary-sort-by-subject t]
2426         ["Sort by date" gnus-summary-sort-by-date t]
2427         ["Sort by score" gnus-summary-sort-by-score t]
2428         ["Sort by lines" gnus-summary-sort-by-lines t]
2429         ["Sort by characters" gnus-summary-sort-by-chars t]
2430         ["Randomize" gnus-summary-sort-by-random t]
2431         ["Original sort" gnus-summary-sort-by-original t])
2432        ("Help"
2433         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2434         ["Describe group" gnus-summary-describe-group t]
2435         ["Fetch charter" gnus-group-fetch-charter
2436          ,@(if (featurep 'xemacs) nil
2437              '(:help "Display the charter of the current group"))]
2438         ["Fetch control message" gnus-group-fetch-control
2439          ,@(if (featurep 'xemacs) nil
2440              '(:help "Display the archived control message for the current group"))]
2441         ["Read manual" gnus-info-find-node t])
2442        ("Modes"
2443         ["Pick and read" gnus-pick-mode t]
2444         ["Binary" gnus-binary-mode t])
2445        ("Regeneration"
2446         ["Regenerate" gnus-summary-prepare t]
2447         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2448         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2449         ["Toggle threading" gnus-summary-toggle-threads t])
2450        ["See old articles" gnus-summary-insert-old-articles t]
2451        ["See new articles" gnus-summary-insert-new-articles t]
2452        ["Filter articles..." gnus-summary-execute-command t]
2453        ["Run command on articles..." gnus-summary-universal-argument t]
2454        ["Search articles forward..." gnus-summary-search-article-forward t]
2455        ["Search articles backward..." gnus-summary-search-article-backward t]
2456        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2457        ["Expand window" gnus-summary-expand-window t]
2458        ["Expire expirable articles" gnus-summary-expire-articles
2459         (gnus-check-backend-function
2460          'request-expire-articles gnus-newsgroup-name)]
2461        ["Edit local kill file" gnus-summary-edit-local-kill t]
2462        ["Edit main kill file" gnus-summary-edit-global-kill t]
2463        ["Edit group parameters" gnus-summary-edit-parameters t]
2464        ["Customize group parameters" gnus-summary-customize-parameters t]
2465        ["Send a bug report" gnus-bug t]
2466        ("Exit"
2467         ["Catchup and exit" gnus-summary-catchup-and-exit
2468          ,@(if (featurep 'xemacs) '(t)
2469              '(:help "Mark unread articles in this group as read, then exit"))]
2470         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2471         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2472         ["Exit group" gnus-summary-exit
2473          ,@(if (featurep 'xemacs) '(t)
2474              '(:help "Exit current group, return to group selection mode"))]
2475         ["Exit group without updating" gnus-summary-exit-no-update t]
2476         ["Exit and goto next group" gnus-summary-next-group t]
2477         ["Exit and goto prev group" gnus-summary-prev-group t]
2478         ["Reselect group" gnus-summary-reselect-current-group t]
2479         ["Rescan group" gnus-summary-rescan-group t]
2480         ["Update dribble" gnus-summary-save-newsrc t])))
2481
2482     (gnus-run-hooks 'gnus-summary-menu-hook)))
2483
2484 (defvar gnus-summary-tool-bar-map nil)
2485
2486 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2487 (defun gnus-summary-make-tool-bar ()
2488   (if (and (fboundp 'tool-bar-add-item-from-menu)
2489            (default-value 'tool-bar-mode)
2490            (not gnus-summary-tool-bar-map))
2491       (setq gnus-summary-tool-bar-map
2492             (let ((tool-bar-map (make-sparse-keymap))
2493                   (load-path (mm-image-load-path)))
2494               (tool-bar-add-item-from-menu
2495                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2496               (tool-bar-add-item-from-menu
2497                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2498               (tool-bar-add-item-from-menu
2499                'gnus-summary-post-news "post" gnus-summary-mode-map)
2500               (tool-bar-add-item-from-menu
2501                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2502               (tool-bar-add-item-from-menu
2503                'gnus-summary-followup "followup" gnus-summary-mode-map)
2504               (tool-bar-add-item-from-menu
2505                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2506               (tool-bar-add-item-from-menu
2507                'gnus-summary-reply "reply" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2520               (tool-bar-add-item-from-menu
2521                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2522               (tool-bar-add-item-from-menu
2523                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2524               tool-bar-map)))
2525   (if gnus-summary-tool-bar-map
2526       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2527
2528 (defun gnus-score-set-default (var value)
2529   "A version of set that updates the GNU Emacs menu-bar."
2530   (set var value)
2531   ;; It is the message that forces the active status to be updated.
2532   (message ""))
2533
2534 (defun gnus-make-score-map (type)
2535   "Make a summary score map of type TYPE."
2536   (if t
2537       nil
2538     (let ((headers '(("author" "from" string)
2539                      ("subject" "subject" string)
2540                      ("article body" "body" string)
2541                      ("article head" "head" string)
2542                      ("xref" "xref" string)
2543                      ("extra header" "extra" string)
2544                      ("lines" "lines" number)
2545                      ("followups to author" "followup" string)))
2546           (types '((number ("less than" <)
2547                            ("greater than" >)
2548                            ("equal" =))
2549                    (string ("substring" s)
2550                            ("exact string" e)
2551                            ("fuzzy string" f)
2552                            ("regexp" r))))
2553           (perms '(("temporary" (current-time-string))
2554                    ("permanent" nil)
2555                    ("immediate" now)))
2556           header)
2557       (list
2558        (apply
2559         'nconc
2560         (list
2561          (if (eq type 'lower)
2562              "Lower score"
2563            "Increase score"))
2564         (let (outh)
2565           (while headers
2566             (setq header (car headers))
2567             (setq outh
2568                   (cons
2569                    (apply
2570                     'nconc
2571                     (list (car header))
2572                     (let ((ts (cdr (assoc (nth 2 header) types)))
2573                           outt)
2574                       (while ts
2575                         (setq outt
2576                               (cons
2577                                (apply
2578                                 'nconc
2579                                 (list (caar ts))
2580                                 (let ((ps perms)
2581                                       outp)
2582                                   (while ps
2583                                     (setq outp
2584                                           (cons
2585                                            (vector
2586                                             (caar ps)
2587                                             (list
2588                                              'gnus-summary-score-entry
2589                                              (nth 1 header)
2590                                              (if (or (string= (nth 1 header)
2591                                                               "head")
2592                                                      (string= (nth 1 header)
2593                                                               "body"))
2594                                                  ""
2595                                                (list 'gnus-summary-header
2596                                                      (nth 1 header)))
2597                                              (list 'quote (nth 1 (car ts)))
2598                                              (list 'gnus-score-delta-default
2599                                                    nil)
2600                                              (nth 1 (car ps))
2601                                              t)
2602                                             t)
2603                                            outp))
2604                                     (setq ps (cdr ps)))
2605                                   (list (nreverse outp))))
2606                                outt))
2607                         (setq ts (cdr ts)))
2608                       (list (nreverse outt))))
2609                    outh))
2610             (setq headers (cdr headers)))
2611           (list (nreverse outh))))))))
2612
2613 \f
2614
2615 (defun gnus-summary-mode (&optional group)
2616   "Major mode for reading articles.
2617
2618 All normal editing commands are switched off.
2619 \\<gnus-summary-mode-map>
2620 Each line in this buffer represents one article.  To read an
2621 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2622 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2623 respectively.
2624
2625 You can also post articles and send mail from this buffer.  To
2626 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2627 of an article, type `\\[gnus-summary-reply]'.
2628
2629 There are approx. one gazillion commands you can execute in this
2630 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2631
2632 The following commands are available:
2633
2634 \\{gnus-summary-mode-map}"
2635   (interactive)
2636   (kill-all-local-variables)
2637   (when (gnus-visual-p 'summary-menu 'menu)
2638     (gnus-summary-make-menu-bar)
2639     (gnus-summary-make-tool-bar))
2640   (gnus-summary-make-local-variables)
2641   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2642     (gnus-summary-make-local-variables))
2643   (gnus-make-thread-indent-array)
2644   (gnus-simplify-mode-line)
2645   (setq major-mode 'gnus-summary-mode)
2646   (setq mode-name "Summary")
2647   (make-local-variable 'minor-mode-alist)
2648   (use-local-map gnus-summary-mode-map)
2649   (buffer-disable-undo)
2650   (setq buffer-read-only t)             ;Disable modification
2651   (setq truncate-lines t)
2652   (setq selective-display t)
2653   (setq selective-display-ellipses t)   ;Display `...'
2654   (gnus-summary-set-display-table)
2655   (gnus-set-default-directory)
2656   (setq gnus-newsgroup-name group)
2657   (unless (gnus-news-group-p group)
2658     (setq gnus-newsgroup-incorporated
2659           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2660   (make-local-variable 'gnus-summary-line-format)
2661   (make-local-variable 'gnus-summary-line-format-spec)
2662   (make-local-variable 'gnus-summary-dummy-line-format)
2663   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2664   (make-local-variable 'gnus-summary-mark-positions)
2665   (make-local-hook 'pre-command-hook)
2666   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2667   (gnus-run-hooks 'gnus-summary-mode-hook)
2668   (turn-on-gnus-mailing-list-mode)
2669   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2670   (gnus-update-summary-mark-positions))
2671
2672 (defun gnus-summary-make-local-variables ()
2673   "Make all the local summary buffer variables."
2674   (let (global)
2675     (dolist (local gnus-summary-local-variables)
2676       (if (consp local)
2677           (progn
2678             (if (eq (cdr local) 'global)
2679                 ;; Copy the global value of the variable.
2680                 (setq global (symbol-value (car local)))
2681               ;; Use the value from the list.
2682               (setq global (eval (cdr local))))
2683             (set (make-local-variable (car local)) global))
2684         ;; Simple nil-valued local variable.
2685         (set (make-local-variable local) nil)))))
2686
2687 (defun gnus-summary-clear-local-variables ()
2688   (let ((locals gnus-summary-local-variables))
2689     (while locals
2690       (if (consp (car locals))
2691           (and (vectorp (caar locals))
2692                (set (caar locals) nil))
2693         (and (vectorp (car locals))
2694              (set (car locals) nil)))
2695       (setq locals (cdr locals)))))
2696
2697 ;; Summary data functions.
2698
2699 (defmacro gnus-data-number (data)
2700   `(car ,data))
2701
2702 (defmacro gnus-data-set-number (data number)
2703   `(setcar ,data ,number))
2704
2705 (defmacro gnus-data-mark (data)
2706   `(nth 1 ,data))
2707
2708 (defmacro gnus-data-set-mark (data mark)
2709   `(setcar (nthcdr 1 ,data) ,mark))
2710
2711 (defmacro gnus-data-pos (data)
2712   `(nth 2 ,data))
2713
2714 (defmacro gnus-data-set-pos (data pos)
2715   `(setcar (nthcdr 2 ,data) ,pos))
2716
2717 (defmacro gnus-data-header (data)
2718   `(nth 3 ,data))
2719
2720 (defmacro gnus-data-set-header (data header)
2721   `(setcar (nthcdr 3 ,data) ,header))
2722
2723 (defmacro gnus-data-level (data)
2724   `(nth 4 ,data))
2725
2726 (defmacro gnus-data-unread-p (data)
2727   `(= (nth 1 ,data) gnus-unread-mark))
2728
2729 (defmacro gnus-data-read-p (data)
2730   `(/= (nth 1 ,data) gnus-unread-mark))
2731
2732 (defmacro gnus-data-pseudo-p (data)
2733   `(consp (nth 3 ,data)))
2734
2735 (defmacro gnus-data-find (number)
2736   `(assq ,number gnus-newsgroup-data))
2737
2738 (defmacro gnus-data-find-list (number &optional data)
2739   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2740      (memq (assq ,number bdata)
2741            bdata)))
2742
2743 (defmacro gnus-data-make (number mark pos header level)
2744   `(list ,number ,mark ,pos ,header ,level))
2745
2746 (defun gnus-data-enter (after-article number mark pos header level offset)
2747   (let ((data (gnus-data-find-list after-article)))
2748     (unless data
2749       (error "No such article: %d" after-article))
2750     (setcdr data (cons (gnus-data-make number mark pos header level)
2751                        (cdr data)))
2752     (setq gnus-newsgroup-data-reverse nil)
2753     (gnus-data-update-list (cddr data) offset)))
2754
2755 (defun gnus-data-enter-list (after-article list &optional offset)
2756   (when list
2757     (let ((data (and after-article (gnus-data-find-list after-article)))
2758           (ilist list))
2759       (if (not (or data
2760                    after-article))
2761           (let ((odata gnus-newsgroup-data))
2762             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2763             (when offset
2764               (gnus-data-update-list odata offset)))
2765         ;; Find the last element in the list to be spliced into the main
2766         ;; list.
2767         (while (cdr list)
2768           (setq list (cdr list)))
2769         (if (not data)
2770             (progn
2771               (setcdr list gnus-newsgroup-data)
2772               (setq gnus-newsgroup-data ilist)
2773               (when offset
2774                 (gnus-data-update-list (cdr list) offset)))
2775           (setcdr list (cdr data))
2776           (setcdr data ilist)
2777           (when offset
2778             (gnus-data-update-list (cdr list) offset))))
2779       (setq gnus-newsgroup-data-reverse nil))))
2780
2781 (defun gnus-data-remove (article &optional offset)
2782   (let ((data gnus-newsgroup-data))
2783     (if (= (gnus-data-number (car data)) article)
2784         (progn
2785           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2786                 gnus-newsgroup-data-reverse nil)
2787           (when offset
2788             (gnus-data-update-list gnus-newsgroup-data offset)))
2789       (while (cdr data)
2790         (when (= (gnus-data-number (cadr data)) article)
2791           (setcdr data (cddr data))
2792           (when offset
2793             (gnus-data-update-list (cdr data) offset))
2794           (setq data nil
2795                 gnus-newsgroup-data-reverse nil))
2796         (setq data (cdr data))))))
2797
2798 (defmacro gnus-data-list (backward)
2799   `(if ,backward
2800        (or gnus-newsgroup-data-reverse
2801            (setq gnus-newsgroup-data-reverse
2802                  (reverse gnus-newsgroup-data)))
2803      gnus-newsgroup-data))
2804
2805 (defun gnus-data-update-list (data offset)
2806   "Add OFFSET to the POS of all data entries in DATA."
2807   (setq gnus-newsgroup-data-reverse nil)
2808   (while data
2809     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2810     (setq data (cdr data))))
2811
2812 (defun gnus-summary-article-pseudo-p (article)
2813   "Say whether this article is a pseudo article or not."
2814   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2815
2816 (defmacro gnus-summary-article-sparse-p (article)
2817   "Say whether this article is a sparse article or not."
2818   `(memq ,article gnus-newsgroup-sparse))
2819
2820 (defmacro gnus-summary-article-ancient-p (article)
2821   "Say whether this article is a sparse article or not."
2822   `(memq ,article gnus-newsgroup-ancient))
2823
2824 (defun gnus-article-parent-p (number)
2825   "Say whether this article is a parent or not."
2826   (let ((data (gnus-data-find-list number)))
2827     (and (cdr data)                     ; There has to be an article after...
2828          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2829             (gnus-data-level (nth 1 data))))))
2830
2831 (defun gnus-article-children (number)
2832   "Return a list of all children to NUMBER."
2833   (let* ((data (gnus-data-find-list number))
2834          (level (gnus-data-level (car data)))
2835          children)
2836     (setq data (cdr data))
2837     (while (and data
2838                 (= (gnus-data-level (car data)) (1+ level)))
2839       (push (gnus-data-number (car data)) children)
2840       (setq data (cdr data)))
2841     children))
2842
2843 (defmacro gnus-summary-skip-intangible ()
2844   "If the current article is intangible, then jump to a different article."
2845   '(let ((to (get-text-property (point) 'gnus-intangible)))
2846      (and to (gnus-summary-goto-subject to))))
2847
2848 (defmacro gnus-summary-article-intangible-p ()
2849   "Say whether this article is intangible or not."
2850   '(get-text-property (point) 'gnus-intangible))
2851
2852 (defun gnus-article-read-p (article)
2853   "Say whether ARTICLE is read or not."
2854   (not (or (memq article gnus-newsgroup-marked)
2855            (memq article gnus-newsgroup-spam-marked)
2856            (memq article gnus-newsgroup-unreads)
2857            (memq article gnus-newsgroup-unselected)
2858            (memq article gnus-newsgroup-dormant))))
2859
2860 ;; Some summary mode macros.
2861
2862 (defmacro gnus-summary-article-number ()
2863   "The article number of the article on the current line.
2864 If there isn't an article number here, then we return the current
2865 article number."
2866   '(progn
2867      (gnus-summary-skip-intangible)
2868      (or (get-text-property (point) 'gnus-number)
2869          (gnus-summary-last-subject))))
2870
2871 (defmacro gnus-summary-article-header (&optional number)
2872   "Return the header of article NUMBER."
2873   `(gnus-data-header (gnus-data-find
2874                       ,(or number '(gnus-summary-article-number)))))
2875
2876 (defmacro gnus-summary-thread-level (&optional number)
2877   "Return the level of thread that starts with article NUMBER."
2878   `(if (and (eq gnus-summary-make-false-root 'dummy)
2879             (get-text-property (point) 'gnus-intangible))
2880        0
2881      (gnus-data-level (gnus-data-find
2882                        ,(or number '(gnus-summary-article-number))))))
2883
2884 (defmacro gnus-summary-article-mark (&optional number)
2885   "Return the mark of article NUMBER."
2886   `(gnus-data-mark (gnus-data-find
2887                     ,(or number '(gnus-summary-article-number)))))
2888
2889 (defmacro gnus-summary-article-pos (&optional number)
2890   "Return the position of the line of article NUMBER."
2891   `(gnus-data-pos (gnus-data-find
2892                    ,(or number '(gnus-summary-article-number)))))
2893
2894 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2895 (defmacro gnus-summary-article-subject (&optional number)
2896   "Return current subject string or nil if nothing."
2897   `(let ((headers
2898           ,(if number
2899                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2900              '(gnus-data-header (assq (gnus-summary-article-number)
2901                                       gnus-newsgroup-data)))))
2902      (and headers
2903           (vectorp headers)
2904           (mail-header-subject headers))))
2905
2906 (defmacro gnus-summary-article-score (&optional number)
2907   "Return current article score."
2908   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2909                   gnus-newsgroup-scored))
2910        gnus-summary-default-score 0))
2911
2912 (defun gnus-summary-article-children (&optional number)
2913   "Return a list of article numbers that are children of article NUMBER."
2914   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2915          (level (gnus-data-level (car data)))
2916          l children)
2917     (while (and (setq data (cdr data))
2918                 (> (setq l (gnus-data-level (car data))) level))
2919       (and (= (1+ level) l)
2920            (push (gnus-data-number (car data))
2921                  children)))
2922     (nreverse children)))
2923
2924 (defun gnus-summary-article-parent (&optional number)
2925   "Return the article number of the parent of article NUMBER."
2926   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2927                                     (gnus-data-list t)))
2928          (level (gnus-data-level (car data))))
2929     (if (zerop level)
2930         ()                              ; This is a root.
2931       ;; We search until we find an article with a level less than
2932       ;; this one.  That function has to be the parent.
2933       (while (and (setq data (cdr data))
2934                   (not (< (gnus-data-level (car data)) level))))
2935       (and data (gnus-data-number (car data))))))
2936
2937 (defun gnus-unread-mark-p (mark)
2938   "Say whether MARK is the unread mark."
2939   (= mark gnus-unread-mark))
2940
2941 (defun gnus-read-mark-p (mark)
2942   "Say whether MARK is one of the marks that mark as read.
2943 This is all marks except unread, ticked, dormant, and expirable."
2944   (not (or (= mark gnus-unread-mark)
2945            (= mark gnus-ticked-mark)
2946            (= mark gnus-spam-mark)
2947            (= mark gnus-dormant-mark)
2948            (= mark gnus-expirable-mark))))
2949
2950 (defmacro gnus-article-mark (number)
2951   "Return the MARK of article NUMBER.
2952 This macro should only be used when computing the mark the \"first\"
2953 time; i.e., when generating the summary lines.  After that,
2954 `gnus-summary-article-mark' should be used to examine the
2955 marks of articles."
2956   `(cond
2957     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2958     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2959     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2960     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2961     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2962     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2963     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2964     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2965            gnus-ancient-mark))))
2966
2967 ;; Saving hidden threads.
2968
2969 (defmacro gnus-save-hidden-threads (&rest forms)
2970   "Save hidden threads, eval FORMS, and restore the hidden threads."
2971   (let ((config (make-symbol "config")))
2972     `(let ((,config (gnus-hidden-threads-configuration)))
2973        (unwind-protect
2974            (save-excursion
2975              ,@forms)
2976          (gnus-restore-hidden-threads-configuration ,config)))))
2977 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2978 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2979
2980 (defun gnus-data-compute-positions ()
2981   "Compute the positions of all articles."
2982   (setq gnus-newsgroup-data-reverse nil)
2983   (let ((data gnus-newsgroup-data))
2984     (save-excursion
2985       (gnus-save-hidden-threads
2986         (gnus-summary-show-all-threads)
2987         (goto-char (point-min))
2988         (while data
2989           (while (get-text-property (point) 'gnus-intangible)
2990             (forward-line 1))
2991           (gnus-data-set-pos (car data) (+ (point) 3))
2992           (setq data (cdr data))
2993           (forward-line 1))))))
2994
2995 (defun gnus-hidden-threads-configuration ()
2996   "Return the current hidden threads configuration."
2997   (save-excursion
2998     (let (config)
2999       (goto-char (point-min))
3000       (while (search-forward "\r" nil t)
3001         (push (1- (point)) config))
3002       config)))
3003
3004 (defun gnus-restore-hidden-threads-configuration (config)
3005   "Restore hidden threads configuration from CONFIG."
3006   (save-excursion
3007     (let (point buffer-read-only)
3008       (while (setq point (pop config))
3009         (when (and (< point (point-max))
3010                    (goto-char point)
3011                    (eq (char-after) ?\n))
3012           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3013
3014 ;; Various summary mode internalish functions.
3015
3016 (defun gnus-mouse-pick-article (e)
3017   (interactive "e")
3018   (mouse-set-point e)
3019   (gnus-summary-next-page nil t))
3020
3021 (defun gnus-summary-set-display-table ()
3022   "Change the display table.
3023 Odd characters have a tendency to mess
3024 up nicely formatted displays - we make all possible glyphs
3025 display only a single character."
3026
3027   ;; We start from the standard display table, if any.
3028   (let ((table (or (copy-sequence standard-display-table)
3029                    (make-display-table)))
3030         (i 32))
3031     ;; Nix out all the control chars...
3032     (while (>= (setq i (1- i)) 0)
3033       (aset table i [??]))
3034     ;; ... but not newline and cr, of course.  (cr is necessary for the
3035     ;; selective display).
3036     (aset table ?\n nil)
3037     (aset table ?\r nil)
3038     ;; We keep TAB as well.
3039     (aset table ?\t nil)
3040     ;; We nix out any glyphs over 126 that are not set already.
3041     (let ((i 256))
3042       (while (>= (setq i (1- i)) 127)
3043         ;; Only modify if the entry is nil.
3044         (unless (aref table i)
3045           (aset table i [??]))))
3046     (setq buffer-display-table table)))
3047
3048 (defun gnus-summary-set-article-display-arrow (pos)
3049   "Update the overlay arrow to point to line at position POS."
3050   (when (and gnus-summary-display-arrow
3051              (boundp 'overlay-arrow-position)
3052              (boundp 'overlay-arrow-string))
3053     (save-excursion
3054       (goto-char pos)
3055       (beginning-of-line)
3056       (unless overlay-arrow-position
3057         (setq overlay-arrow-position (make-marker)))
3058       (setq overlay-arrow-string "=>"
3059             overlay-arrow-position (set-marker overlay-arrow-position
3060                                                (point)
3061                                                (current-buffer))))))
3062
3063 (defun gnus-summary-setup-buffer (group)
3064   "Initialize summary buffer."
3065   (let ((buffer (gnus-summary-buffer-name group))
3066         (dead-name (concat "*Dead Summary "
3067                            (gnus-group-decoded-name group) "*")))
3068     ;; If a dead summary buffer exists, we kill it.
3069     (when (gnus-buffer-live-p dead-name)
3070       (gnus-kill-buffer dead-name))
3071     (if (get-buffer buffer)
3072         (progn
3073           (set-buffer buffer)
3074           (setq gnus-summary-buffer (current-buffer))
3075           (not gnus-newsgroup-prepared))
3076       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3077       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3078       (gnus-summary-mode group)
3079       (when gnus-carpal
3080         (gnus-carpal-setup-buffer 'summary))
3081       (unless gnus-single-article-buffer
3082         (make-local-variable 'gnus-article-buffer)
3083         (make-local-variable 'gnus-article-current)
3084         (make-local-variable 'gnus-original-article-buffer))
3085       (setq gnus-newsgroup-name group)
3086       ;; Set any local variables in the group parameters.
3087       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3088       t)))
3089
3090 (defun gnus-set-global-variables ()
3091   "Set the global equivalents of the buffer-local variables.
3092 They are set to the latest values they had.  These reflect the summary
3093 buffer that was in action when the last article was fetched."
3094   (when (eq major-mode 'gnus-summary-mode)
3095     (setq gnus-summary-buffer (current-buffer))
3096     (let ((name gnus-newsgroup-name)
3097           (marked gnus-newsgroup-marked)
3098           (spam gnus-newsgroup-spam-marked)
3099           (unread gnus-newsgroup-unreads)
3100           (headers gnus-current-headers)
3101           (data gnus-newsgroup-data)
3102           (summary gnus-summary-buffer)
3103           (article-buffer gnus-article-buffer)
3104           (original gnus-original-article-buffer)
3105           (gac gnus-article-current)
3106           (reffed gnus-reffed-article-number)
3107           (score-file gnus-current-score-file)
3108           (default-charset gnus-newsgroup-charset)
3109           vlist)
3110       (let ((locals gnus-newsgroup-variables))
3111         (while locals
3112           (if (consp (car locals))
3113               (push (eval (caar locals)) vlist)
3114             (push (eval (car locals)) vlist))
3115           (setq locals (cdr locals)))
3116         (setq vlist (nreverse vlist)))
3117       (save-excursion
3118         (set-buffer gnus-group-buffer)
3119         (setq gnus-newsgroup-name name
3120               gnus-newsgroup-marked marked
3121               gnus-newsgroup-spam-marked spam
3122               gnus-newsgroup-unreads unread
3123               gnus-current-headers headers
3124               gnus-newsgroup-data data
3125               gnus-article-current gac
3126               gnus-summary-buffer summary
3127               gnus-article-buffer article-buffer
3128               gnus-original-article-buffer original
3129               gnus-reffed-article-number reffed
3130               gnus-current-score-file score-file
3131               gnus-newsgroup-charset default-charset)
3132         (let ((locals gnus-newsgroup-variables))
3133           (while locals
3134             (if (consp (car locals))
3135                 (set (caar locals) (pop vlist))
3136               (set (car locals) (pop vlist)))
3137             (setq locals (cdr locals))))
3138         ;; The article buffer also has local variables.
3139         (when (gnus-buffer-live-p gnus-article-buffer)
3140           (set-buffer gnus-article-buffer)
3141           (setq gnus-summary-buffer summary))))))
3142
3143 (defun gnus-summary-article-unread-p (article)
3144   "Say whether ARTICLE is unread or not."
3145   (memq article gnus-newsgroup-unreads))
3146
3147 (defun gnus-summary-first-article-p (&optional article)
3148   "Return whether ARTICLE is the first article in the buffer."
3149   (if (not (setq article (or article (gnus-summary-article-number))))
3150       nil
3151     (eq article (caar gnus-newsgroup-data))))
3152
3153 (defun gnus-summary-last-article-p (&optional article)
3154   "Return whether ARTICLE is the last article in the buffer."
3155   (if (not (setq article (or article (gnus-summary-article-number))))
3156       ;; All non-existent numbers are the last article.  :-)
3157       t
3158     (not (cdr (gnus-data-find-list article)))))
3159
3160 (defun gnus-make-thread-indent-array ()
3161   (let ((n 200))
3162     (unless (and gnus-thread-indent-array
3163                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3164       (setq gnus-thread-indent-array (make-vector 201 "")
3165             gnus-thread-indent-array-level gnus-thread-indent-level)
3166       (while (>= n 0)
3167         (aset gnus-thread-indent-array n
3168               (make-string (* n gnus-thread-indent-level) ? ))
3169         (setq n (1- n))))))
3170
3171 (defun gnus-update-summary-mark-positions ()
3172   "Compute where the summary marks are to go."
3173   (save-excursion
3174     (when (gnus-buffer-exists-p gnus-summary-buffer)
3175       (set-buffer gnus-summary-buffer))
3176     (let ((gnus-replied-mark 129)
3177           (gnus-score-below-mark 130)
3178           (gnus-score-over-mark 130)
3179           (gnus-undownloaded-mark 131)
3180           (spec gnus-summary-line-format-spec)
3181           gnus-visual pos)
3182       (save-excursion
3183         (gnus-set-work-buffer)
3184         (let ((gnus-summary-line-format-spec spec)
3185               (gnus-newsgroup-downloadable '(0)))
3186           (gnus-summary-insert-line
3187            (make-full-mail-header 0 "" "nobody"
3188                                   "05 Apr 2001 23:33:09 +0400"
3189                                   "" "" 0 0 "" nil)
3190            0 nil t 128 t nil "" nil 1)
3191           (goto-char (point-min))
3192           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3193                                              (- (point) (point-min) 1)))))
3194           (goto-char (point-min))
3195           (push (cons 'replied (and (search-forward "\201" nil t)
3196                                     (- (point) (point-min) 1)))
3197                 pos)
3198           (goto-char (point-min))
3199           (push (cons 'score (and (search-forward "\202" nil t)
3200                                   (- (point) (point-min) 1)))
3201                 pos)
3202           (goto-char (point-min))
3203           (push (cons 'download
3204                       (and (search-forward "\203" nil t)
3205                            (- (point) (point-min) 1)))
3206                 pos)))
3207       (setq gnus-summary-mark-positions pos))))
3208
3209 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3210   "Insert a dummy root in the summary buffer."
3211   (beginning-of-line)
3212   (gnus-add-text-properties
3213    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3214    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3215
3216 (defun gnus-summary-extract-address-component (from)
3217   (or (car (funcall gnus-extract-address-components from))
3218       from))
3219
3220 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3221   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3222                                 default-mime-charset)))
3223     ;; Is it really necessary to do this next part for each summary line?
3224     ;; Luckily, doesn't seem to slow things down much.
3225     (or
3226      (and gnus-ignored-from-addresses
3227           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3228           (let ((extra-headers (mail-header-extra header))
3229                 to
3230                 newsgroups)
3231             (cond
3232              ((setq to (cdr (assq 'To extra-headers)))
3233               (concat "-> "
3234                       (inline
3235                         (gnus-summary-extract-address-component
3236                          (funcall gnus-decode-encoded-word-function to)))))
3237              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3238               (concat "=> " newsgroups)))))
3239      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3240
3241 (defun gnus-summary-insert-line (gnus-tmp-header
3242                                  gnus-tmp-level gnus-tmp-current
3243                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3244                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3245                                  &optional gnus-tmp-dummy gnus-tmp-score
3246                                  gnus-tmp-process)
3247   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3248          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3249          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3250          (gnus-tmp-score-char
3251           (if (or (null gnus-summary-default-score)
3252                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3253                       gnus-summary-zcore-fuzz))
3254               ?\ ;;;Whitespace
3255             (if (< gnus-tmp-score gnus-summary-default-score)
3256                 gnus-score-below-mark gnus-score-over-mark)))
3257          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3258          (gnus-tmp-replied
3259           (cond (gnus-tmp-process gnus-process-mark)
3260                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3261                  gnus-cached-mark)
3262                 (gnus-tmp-replied gnus-replied-mark)
3263                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3264                  gnus-forwarded-mark)
3265                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3266                  gnus-saved-mark)
3267                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3268                  gnus-recent-mark)
3269                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3270                  gnus-unseen-mark)
3271                 (t gnus-no-mark)))
3272          (gnus-tmp-downloaded
3273           (cond (undownloaded 
3274                  gnus-undownloaded-mark)
3275                 (gnus-newsgroup-agentized
3276                  gnus-downloaded-mark)
3277                 (t
3278                  gnus-no-mark)))
3279          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3280          (gnus-tmp-name
3281           (cond
3282            ((string-match "<[^>]+> *$" gnus-tmp-from)
3283             (let ((beg (match-beginning 0)))
3284               (or (and (string-match "^\".+\"" gnus-tmp-from)
3285                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3286                   (substring gnus-tmp-from 0 beg))))
3287            ((string-match "(.+)" gnus-tmp-from)
3288             (substring gnus-tmp-from
3289                        (1+ (match-beginning 0)) (1- (match-end 0))))
3290            (t gnus-tmp-from)))
3291          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3292          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3293          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3294          (buffer-read-only nil))
3295     (when (string= gnus-tmp-name "")
3296       (setq gnus-tmp-name gnus-tmp-from))
3297     (unless (numberp gnus-tmp-lines)
3298       (setq gnus-tmp-lines -1))
3299     (if (= gnus-tmp-lines -1)
3300         (setq gnus-tmp-lines "?")
3301       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3302     (gnus-put-text-property-excluding-characters-with-faces
3303      (point)
3304      (progn (eval gnus-summary-line-format-spec) (point))
3305      'gnus-number gnus-tmp-number)
3306     (when (gnus-visual-p 'summary-highlight 'highlight)
3307       (forward-line -1)
3308       (gnus-run-hooks 'gnus-summary-update-hook)
3309       (forward-line 1))))
3310
3311 (defun gnus-summary-update-line (&optional dont-update)
3312   "Update summary line after change."
3313   (when (and gnus-summary-default-score
3314              (not gnus-summary-inhibit-highlight))
3315     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3316            (article (gnus-summary-article-number))
3317            (score (gnus-summary-article-score article)))
3318       (unless dont-update
3319         (if (and gnus-summary-mark-below
3320                  (< (gnus-summary-article-score)
3321                     gnus-summary-mark-below))
3322             ;; This article has a low score, so we mark it as read.
3323             (when (memq article gnus-newsgroup-unreads)
3324               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3325           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3326             ;; This article was previously marked as read on account
3327             ;; of a low score, but now it has risen, so we mark it as
3328             ;; unread.
3329             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3330         (gnus-summary-update-mark
3331          (if (or (null gnus-summary-default-score)
3332                  (<= (abs (- score gnus-summary-default-score))
3333                      gnus-summary-zcore-fuzz))
3334              ?\ ;;;Whitespace
3335            (if (< score gnus-summary-default-score)
3336                gnus-score-below-mark gnus-score-over-mark))
3337          'score))
3338       ;; Do visual highlighting.
3339       (when (gnus-visual-p 'summary-highlight 'highlight)
3340         (gnus-run-hooks 'gnus-summary-update-hook)))))
3341
3342 (defvar gnus-tmp-new-adopts nil)
3343
3344 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3345   "Return the number of articles in THREAD.
3346 This may be 0 in some cases -- if none of the articles in
3347 the thread are to be displayed."
3348   (let* ((number
3349           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3350           (cond
3351            ((not (listp thread))
3352             1)
3353            ((and (consp thread) (cdr thread))
3354             (apply
3355              '+ 1 (mapcar
3356                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3357            ((null thread)
3358             1)
3359            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3360             1)
3361            (t 0))))
3362     (when (and level (zerop level) gnus-tmp-new-adopts)
3363       (incf number
3364             (apply '+ (mapcar
3365                        'gnus-summary-number-of-articles-in-thread
3366                        gnus-tmp-new-adopts))))
3367     (if char
3368         (if (> number 1) gnus-not-empty-thread-mark
3369           gnus-empty-thread-mark)
3370       number)))
3371
3372 (defsubst gnus-summary-line-message-size (head)
3373   "Return pretty-printed version of message size.
3374 This function is intended to be used in
3375 `gnus-summary-line-format-alist', which see."
3376   (let ((c (or (mail-header-chars head) -1)))
3377     (cond ((< c 0) "n/a")               ; chars not available
3378           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3379           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3380           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3381           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3382
3383
3384 (defun gnus-summary-set-local-parameters (group)
3385   "Go through the local params of GROUP and set all variable specs in that list."
3386   (let ((params (gnus-group-find-parameter group))
3387         (vars '(quit-config))           ; Ignore quit-config.
3388         elem)
3389     (while params
3390       (setq elem (car params)
3391             params (cdr params))
3392       (and (consp elem)                 ; Has to be a cons.
3393            (consp (cdr elem))           ; The cdr has to be a list.
3394            (symbolp (car elem))         ; Has to be a symbol in there.
3395            (not (memq (car elem) vars))
3396            (ignore-errors               ; So we set it.
3397              (push (car elem) vars)
3398              (make-local-variable (car elem))
3399              (set (car elem) (eval (nth 1 elem))))))))
3400
3401 (defun gnus-summary-read-group (group &optional show-all no-article
3402                                       kill-buffer no-display backward
3403                                       select-articles)
3404   "Start reading news in newsgroup GROUP.
3405 If SHOW-ALL is non-nil, already read articles are also listed.
3406 If NO-ARTICLE is non-nil, no article is selected initially.
3407 If NO-DISPLAY, don't generate a summary buffer."
3408   (let (result)
3409     (while (and group
3410                 (null (setq result
3411                             (let ((gnus-auto-select-next nil))
3412                               (or (gnus-summary-read-group-1
3413                                    group show-all no-article
3414                                    kill-buffer no-display
3415                                    select-articles)
3416                                   (setq show-all nil
3417                                         select-articles nil)))))
3418                 (eq gnus-auto-select-next 'quietly))
3419       (set-buffer gnus-group-buffer)
3420       ;; The entry function called above goes to the next
3421       ;; group automatically, so we go two groups back
3422       ;; if we are searching for the previous group.
3423       (when backward
3424         (gnus-group-prev-unread-group 2))
3425       (if (not (equal group (gnus-group-group-name)))
3426           (setq group (gnus-group-group-name))
3427         (setq group nil)))
3428     result))
3429
3430 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3431   "Directly jump to the other GROUP from summary buffer.
3432 If SHOW-ALL is non-nil, already read articles are also listed."
3433   (interactive
3434    (if (eq gnus-summary-buffer (current-buffer))
3435        (list (completing-read
3436               "Group: " gnus-active-hashtb nil t
3437               (when (and gnus-newsgroup-name
3438                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3439                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3440               'gnus-group-history)
3441              current-prefix-arg)
3442      (error "%s must be invoked from a gnus summary buffer." this-command)))
3443   (unless (or (zerop (length group))
3444               (and gnus-newsgroup-name
3445                    (string-equal gnus-newsgroup-name group)))
3446     (gnus-summary-exit)
3447     (gnus-summary-read-group group show-all
3448                              gnus-dont-select-after-jump-to-other-group)))
3449
3450 (defun gnus-summary-read-group-1 (group show-all no-article
3451                                         kill-buffer no-display
3452                                         &optional select-articles)
3453   ;; Killed foreign groups can't be entered.
3454   ;;  (when (and (not (gnus-group-native-p group))
3455   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3456   ;;    (error "Dead non-native groups can't be entered"))
3457   (gnus-message 5 "Retrieving newsgroup: %s..."
3458                 (gnus-group-decoded-name group))
3459   (let* ((new-group (gnus-summary-setup-buffer group))
3460          (quit-config (gnus-group-quit-config group))
3461          (did-select (and new-group (gnus-select-newsgroup
3462                                      group show-all select-articles))))
3463     (cond
3464      ;; This summary buffer exists already, so we just select it.
3465      ((not new-group)
3466       (gnus-set-global-variables)
3467       (when kill-buffer
3468         (gnus-kill-or-deaden-summary kill-buffer))
3469       (gnus-configure-windows 'summary 'force)
3470       (gnus-set-mode-line 'summary)
3471       (gnus-summary-position-point)
3472       (message "")
3473       t)
3474      ;; We couldn't select this group.
3475      ((null did-select)
3476       (when (and (eq major-mode 'gnus-summary-mode)
3477                  (not (equal (current-buffer) kill-buffer)))
3478         (kill-buffer (current-buffer))
3479         (if (not quit-config)
3480             (progn
3481               ;; Update the info -- marks might need to be removed,
3482               ;; for instance.
3483               (gnus-summary-update-info)
3484               (set-buffer gnus-group-buffer)
3485               (gnus-group-jump-to-group group)
3486               (gnus-group-next-unread-group 1))
3487           (gnus-handle-ephemeral-exit quit-config)))
3488       (let ((grpinfo (gnus-get-info group)))
3489         (if (null (gnus-info-read grpinfo))
3490             (gnus-message 3 "Group %s contains no messages"
3491                           (gnus-group-decoded-name group))
3492           (gnus-message 3 "Can't select group")))
3493       nil)
3494      ;; The user did a `C-g' while prompting for number of articles,
3495      ;; so we exit this group.
3496      ((eq did-select 'quit)
3497       (and (eq major-mode 'gnus-summary-mode)
3498            (not (equal (current-buffer) kill-buffer))
3499            (kill-buffer (current-buffer)))
3500       (when kill-buffer
3501         (gnus-kill-or-deaden-summary kill-buffer))
3502       (if (not quit-config)
3503           (progn
3504             (set-buffer gnus-group-buffer)
3505             (gnus-group-jump-to-group group)
3506             (gnus-group-next-unread-group 1)
3507             (gnus-configure-windows 'group 'force))
3508         (gnus-handle-ephemeral-exit quit-config))
3509       ;; Finally signal the quit.
3510       (signal 'quit nil))
3511      ;; The group was successfully selected.
3512      (t
3513       (gnus-set-global-variables)
3514       ;; Save the active value in effect when the group was entered.
3515       (setq gnus-newsgroup-active
3516             (gnus-copy-sequence
3517              (gnus-active gnus-newsgroup-name)))
3518       ;; You can change the summary buffer in some way with this hook.
3519       (gnus-run-hooks 'gnus-select-group-hook)
3520       (gnus-update-format-specifications
3521        nil 'summary 'summary-mode 'summary-dummy)
3522       (gnus-update-summary-mark-positions)
3523       ;; Do score processing.
3524       (when gnus-use-scoring
3525         (gnus-possibly-score-headers))
3526       ;; Check whether to fill in the gaps in the threads.
3527       (when gnus-build-sparse-threads
3528         (gnus-build-sparse-threads))
3529       ;; Find the initial limit.
3530       (if gnus-show-threads
3531           (if show-all
3532               (let ((gnus-newsgroup-dormant nil))
3533                 (gnus-summary-initial-limit show-all))
3534             (gnus-summary-initial-limit show-all))
3535         ;; When unthreaded, all articles are always shown.
3536         (setq gnus-newsgroup-limit
3537               (mapcar
3538                (lambda (header) (mail-header-number header))
3539                gnus-newsgroup-headers)))
3540       ;; Generate the summary buffer.
3541       (unless no-display
3542         (gnus-summary-prepare))
3543       (when gnus-use-trees
3544         (gnus-tree-open group)
3545         (setq gnus-summary-highlight-line-function
3546               'gnus-tree-highlight-article))
3547       ;; If the summary buffer is empty, but there are some low-scored
3548       ;; articles or some excluded dormants, we include these in the
3549       ;; buffer.
3550       (when (and (zerop (buffer-size))
3551                  (not no-display))
3552         (cond (gnus-newsgroup-dormant
3553                (gnus-summary-limit-include-dormant))
3554               ((and gnus-newsgroup-scored show-all)
3555                (gnus-summary-limit-include-expunged t))))
3556       ;; Function `gnus-apply-kill-file' must be called in this hook.
3557       (gnus-run-hooks 'gnus-apply-kill-hook)
3558       (if (and (zerop (buffer-size))
3559                (not no-display))
3560           (progn
3561             ;; This newsgroup is empty.
3562             (gnus-summary-catchup-and-exit nil t)
3563             (gnus-message 6 "No unread news")
3564             (when kill-buffer
3565               (gnus-kill-or-deaden-summary kill-buffer))
3566             ;; Return nil from this function.
3567             nil)
3568         ;; Hide conversation thread subtrees.  We cannot do this in
3569         ;; gnus-summary-prepare-hook since kill processing may not
3570         ;; work with hidden articles.
3571         (gnus-summary-maybe-hide-threads)
3572         (when kill-buffer
3573           (gnus-kill-or-deaden-summary kill-buffer))
3574         (gnus-summary-auto-select-subject)
3575         ;; Show first unread article if requested.
3576         (if (and (not no-article)
3577                  (not no-display)
3578                  gnus-newsgroup-unreads
3579                  gnus-auto-select-first)
3580             (progn
3581               (gnus-configure-windows 'summary)
3582               (let ((art (gnus-summary-article-number)))
3583                 (unless (and (not gnus-plugged)
3584                              (or (memq art gnus-newsgroup-undownloaded)
3585                                  (memq art gnus-newsgroup-downloadable)))
3586                   (gnus-summary-goto-article art))))
3587           ;; Don't select any articles.
3588           (gnus-summary-position-point)
3589           (gnus-configure-windows 'summary 'force)
3590           (gnus-set-mode-line 'summary))
3591         (when (and gnus-auto-center-group
3592                    (get-buffer-window gnus-group-buffer t))
3593           ;; Gotta use windows, because recenter does weird stuff if
3594           ;; the current buffer ain't the displayed window.
3595           (let ((owin (selected-window)))
3596             (select-window (get-buffer-window gnus-group-buffer t))
3597             (when (gnus-group-goto-group group)
3598               (recenter))
3599             (select-window owin)))
3600         ;; Mark this buffer as "prepared".
3601         (setq gnus-newsgroup-prepared t)
3602         (gnus-run-hooks 'gnus-summary-prepared-hook)
3603         (unless (gnus-ephemeral-group-p group)
3604           (gnus-group-update-group group))
3605         t)))))
3606
3607 (defun gnus-summary-auto-select-subject ()
3608   "Select the subject line on initial group entry."
3609   (goto-char (point-min))
3610   (cond
3611    ((eq gnus-auto-select-subject 'best)
3612     (gnus-summary-best-unread-subject))
3613    ((eq gnus-auto-select-subject 'unread)
3614     (gnus-summary-first-unread-subject))
3615    ((eq gnus-auto-select-subject 'unseen)
3616     (gnus-summary-first-unseen-subject))
3617    ((eq gnus-auto-select-subject 'unseen-or-unread)
3618     (gnus-summary-first-unseen-or-unread-subject))
3619    ((eq gnus-auto-select-subject 'first)
3620     ;; Do nothing.
3621     )
3622    ((gnus-functionp gnus-auto-select-subject)
3623     (funcall gnus-auto-select-subject))))
3624
3625 (defun gnus-summary-prepare ()
3626   "Generate the summary buffer."
3627   (interactive)
3628   (let ((buffer-read-only nil))
3629     (erase-buffer)
3630     (setq gnus-newsgroup-data nil
3631           gnus-newsgroup-data-reverse nil)
3632     (gnus-run-hooks 'gnus-summary-generate-hook)
3633     ;; Generate the buffer, either with threads or without.
3634     (when gnus-newsgroup-headers
3635       (gnus-summary-prepare-threads
3636        (if gnus-show-threads
3637            (gnus-sort-gathered-threads
3638             (funcall gnus-summary-thread-gathering-function
3639                      (gnus-sort-threads
3640                       (gnus-cut-threads (gnus-make-threads)))))
3641          ;; Unthreaded display.
3642          (gnus-sort-articles gnus-newsgroup-headers))))
3643     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3644     ;; Call hooks for modifying summary buffer.
3645     (goto-char (point-min))
3646     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3647
3648 (defsubst gnus-general-simplify-subject (subject)
3649   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3650   (setq subject
3651         (cond
3652          ;; Truncate the subject.
3653          (gnus-simplify-subject-functions
3654           (gnus-map-function gnus-simplify-subject-functions subject))
3655          ((numberp gnus-summary-gather-subject-limit)
3656           (setq subject (gnus-simplify-subject-re subject))
3657           (if (> (length subject) gnus-summary-gather-subject-limit)
3658               (substring subject 0 gnus-summary-gather-subject-limit)
3659             subject))
3660          ;; Fuzzily simplify it.
3661          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3662           (gnus-simplify-subject-fuzzy subject))
3663          ;; Just remove the leading "Re:".
3664          (t
3665           (gnus-simplify-subject-re subject))))
3666
3667   (if (and gnus-summary-gather-exclude-subject
3668            (string-match gnus-summary-gather-exclude-subject subject))
3669       nil                               ; This article shouldn't be gathered
3670     subject))
3671
3672 (defun gnus-summary-simplify-subject-query ()
3673   "Query where the respool algorithm would put this article."
3674   (interactive)
3675   (gnus-summary-select-article)
3676   (message "%s"
3677            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3678
3679 (defun gnus-gather-threads-by-subject (threads)
3680   "Gather threads by looking at Subject headers."
3681   (if (not gnus-summary-make-false-root)
3682       threads
3683     (let ((hashtb (gnus-make-hashtable 1024))
3684           (prev threads)
3685           (result threads)
3686           subject hthread whole-subject)
3687       (while threads
3688         (setq subject (gnus-general-simplify-subject
3689                        (setq whole-subject (mail-header-subject
3690                                             (caar threads)))))
3691         (when subject
3692           (if (setq hthread (gnus-gethash subject hashtb))
3693               (progn
3694                 ;; We enter a dummy root into the thread, if we
3695                 ;; haven't done that already.
3696                 (unless (stringp (caar hthread))
3697                   (setcar hthread (list whole-subject (car hthread))))
3698                 ;; We add this new gathered thread to this gathered
3699                 ;; thread.
3700                 (setcdr (car hthread)
3701                         (nconc (cdar hthread) (list (car threads))))
3702                 ;; Remove it from the list of threads.
3703                 (setcdr prev (cdr threads))
3704                 (setq threads prev))
3705             ;; Enter this thread into the hash table.
3706             (gnus-sethash subject
3707                           (if gnus-summary-make-false-root-always
3708                               (progn
3709                                 ;; If you want a dummy root above all
3710                                 ;; threads...
3711                                 (setcar threads (list whole-subject
3712                                                       (car threads)))
3713                                 threads)
3714                             threads)
3715                           hashtb)))
3716         (setq prev threads)
3717         (setq threads (cdr threads)))
3718       result)))
3719
3720 (defun gnus-gather-threads-by-references (threads)
3721   "Gather threads by looking at References headers."
3722   (let ((idhashtb (gnus-make-hashtable 1024))
3723         (thhashtb (gnus-make-hashtable 1024))
3724         (prev threads)
3725         (result threads)
3726         ids references id gthread gid entered ref)
3727     (while threads
3728       (when (setq references (mail-header-references (caar threads)))
3729         (setq id (mail-header-id (caar threads))
3730               ids (inline (gnus-split-references references))
3731               entered nil)
3732         (while (setq ref (pop ids))
3733           (setq ids (delete ref ids))
3734           (if (not (setq gid (gnus-gethash ref idhashtb)))
3735               (progn
3736                 (gnus-sethash ref id idhashtb)
3737                 (gnus-sethash id threads thhashtb))
3738             (setq gthread (gnus-gethash gid thhashtb))
3739             (unless entered
3740               ;; We enter a dummy root into the thread, if we
3741               ;; haven't done that already.
3742               (unless (stringp (caar gthread))
3743                 (setcar gthread (list (mail-header-subject (caar gthread))
3744                                       (car gthread))))
3745               ;; We add this new gathered thread to this gathered
3746               ;; thread.
3747               (setcdr (car gthread)
3748                       (nconc (cdar gthread) (list (car threads)))))
3749             ;; Add it into the thread hash table.
3750             (gnus-sethash id gthread thhashtb)
3751             (setq entered t)
3752             ;; Remove it from the list of threads.
3753             (setcdr prev (cdr threads))
3754             (setq threads prev))))
3755       (setq prev threads)
3756       (setq threads (cdr threads)))
3757     result))
3758
3759 (defun gnus-sort-gathered-threads (threads)
3760   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3761   (let ((result threads))
3762     (while threads
3763       (when (stringp (caar threads))
3764         (setcdr (car threads)
3765                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3766       (setq threads (cdr threads)))
3767     result))
3768
3769 (defun gnus-thread-loop-p (root thread)
3770   "Say whether ROOT is in THREAD."
3771   (let ((stack (list thread))
3772         (infloop 0)
3773         th)
3774     (while (setq thread (pop stack))
3775       (setq th (cdr thread))
3776       (while (and th
3777                   (not (eq (caar th) root)))
3778         (pop th))
3779       (if th
3780           ;; We have found a loop.
3781           (let (ref-dep)
3782             (setcdr thread (delq (car th) (cdr thread)))
3783             (if (boundp (setq ref-dep (intern "none"
3784                                               gnus-newsgroup-dependencies)))
3785                 (setcdr (symbol-value ref-dep)
3786                         (nconc (cdr (symbol-value ref-dep))
3787                                (list (car th))))
3788               (set ref-dep (list nil (car th))))
3789             (setq infloop 1
3790                   stack nil))
3791         ;; Push all the subthreads onto the stack.
3792         (push (cdr thread) stack)))
3793     infloop))
3794
3795 (defun gnus-make-threads ()
3796   "Go through the dependency hashtb and find the roots.  Return all threads."
3797   (let (threads)
3798     (while (catch 'infloop
3799              (mapatoms
3800               (lambda (refs)
3801                 ;; Deal with self-referencing References loops.
3802                 (when (and (car (symbol-value refs))
3803                            (not (zerop
3804                                  (apply
3805                                   '+
3806                                   (mapcar
3807                                    (lambda (thread)
3808                                      (gnus-thread-loop-p
3809                                       (car (symbol-value refs)) thread))
3810                                    (cdr (symbol-value refs)))))))
3811                   (setq threads nil)
3812                   (throw 'infloop t))
3813                 (unless (car (symbol-value refs))
3814                   ;; These threads do not refer back to any other articles,
3815                   ;; so they're roots.
3816                   (setq threads (append (cdr (symbol-value refs)) threads))))
3817               gnus-newsgroup-dependencies)))
3818     threads))
3819
3820 ;; Build the thread tree.
3821 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3822   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3823
3824 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3825 if it was already present.
3826
3827 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3828 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3829 Message-IDs will be renamed to a unique Message-ID before being
3830 entered.
3831
3832 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3833   (let* ((id (mail-header-id header))
3834          (id-dep (and id (intern id dependencies)))
3835          parent-id ref ref-dep ref-header replaced)
3836     ;; Enter this `header' in the `dependencies' table.
3837     (cond
3838      ((not id-dep)
3839       (setq header nil))
3840      ;; The first two cases do the normal part: enter a new `header'
3841      ;; in the `dependencies' table.
3842      ((not (boundp id-dep))
3843       (set id-dep (list header)))
3844      ((null (car (symbol-value id-dep)))
3845       (setcar (symbol-value id-dep) header))
3846
3847      ;; From here the `header' was already present in the
3848      ;; `dependencies' table.
3849      (force-new
3850       ;; Overrides an existing entry;
3851       ;; just set the header part of the entry.
3852       (setcar (symbol-value id-dep) header)
3853       (setq replaced t))
3854
3855      ;; Renames the existing `header' to a unique Message-ID.
3856      ((not gnus-summary-ignore-duplicates)
3857       ;; An article with this Message-ID has already been seen.
3858       ;; We rename the Message-ID.
3859       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3860            (list header))
3861       (mail-header-set-id header id))
3862
3863      ;; The last case ignores an existing entry, except it adds any
3864      ;; additional Xrefs (in case the two articles came from different
3865      ;; servers.
3866      ;; Also sets `header' to `nil' meaning that the `dependencies'
3867      ;; table was *not* modified.
3868      (t
3869       (mail-header-set-xref
3870        (car (symbol-value id-dep))
3871        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3872                    "")
3873                (or (mail-header-xref header) "")))
3874       (setq header nil)))
3875
3876     (when (and header (not replaced))
3877       ;; First check that we are not creating a References loop.
3878       (setq parent-id (gnus-parent-id (mail-header-references header)))
3879       (setq ref parent-id)
3880       (while (and ref
3881                   (setq ref-dep (intern-soft ref dependencies))
3882                   (boundp ref-dep)
3883                   (setq ref-header (car (symbol-value ref-dep))))
3884         (if (string= id ref)
3885             ;; Yuk!  This is a reference loop.  Make the article be a
3886             ;; root article.
3887             (progn
3888               (mail-header-set-references (car (symbol-value id-dep)) "none")
3889               (setq ref nil)
3890               (setq parent-id nil))
3891           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3892       (setq ref-dep (intern (or parent-id "none") dependencies))
3893       (if (boundp ref-dep)
3894           (setcdr (symbol-value ref-dep)
3895                   (nconc (cdr (symbol-value ref-dep))
3896                          (list (symbol-value id-dep))))
3897         (set ref-dep (list nil (symbol-value id-dep)))))
3898     header))
3899
3900 (defun gnus-extract-message-id-from-in-reply-to (string)
3901   (if (string-match "<[^>]+>" string)
3902       (substring string (match-beginning 0) (match-end 0))
3903     nil))
3904
3905 (defun gnus-build-sparse-threads ()
3906   (let ((headers gnus-newsgroup-headers)
3907         (mail-parse-charset gnus-newsgroup-charset)
3908         (gnus-summary-ignore-duplicates t)
3909         header references generation relations
3910         subject child end new-child date)
3911     ;; First we create an alist of generations/relations, where
3912     ;; generations is how much we trust the relation, and the relation
3913     ;; is parent/child.
3914     (gnus-message 7 "Making sparse threads...")
3915     (save-excursion
3916       (nnheader-set-temp-buffer " *gnus sparse threads*")
3917       (while (setq header (pop headers))
3918         (when (and (setq references (mail-header-references header))
3919                    (not (string= references "")))
3920           (insert references)
3921           (setq child (mail-header-id header)
3922                 subject (mail-header-subject header)
3923                 date (mail-header-date header)
3924                 generation 0)
3925           (while (search-backward ">" nil t)
3926             (setq end (1+ (point)))
3927             (when (search-backward "<" nil t)
3928               (setq new-child (buffer-substring (point) end))
3929               (push (list (incf generation)
3930                           child (setq child new-child)
3931                           subject date)
3932                     relations)))
3933           (when child
3934             (push (list (1+ generation) child nil subject) relations))
3935           (erase-buffer)))
3936       (kill-buffer (current-buffer)))
3937     ;; Sort over trustworthiness.
3938     (mapcar
3939      (lambda (relation)
3940        (when (gnus-dependencies-add-header
3941               (make-full-mail-header-from-decoded-header
3942                gnus-reffed-article-number
3943                (nth 3 relation) "" (or (nth 4 relation) "")
3944                (nth 1 relation)
3945                (or (nth 2 relation) "") 0 0 "")
3946               gnus-newsgroup-dependencies nil)
3947          (push gnus-reffed-article-number gnus-newsgroup-limit)
3948          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3949          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3950                gnus-newsgroup-reads)
3951          (decf gnus-reffed-article-number)))
3952      (sort relations 'car-less-than-car))
3953     (gnus-message 7 "Making sparse threads...done")))
3954
3955 (defun gnus-build-old-threads ()
3956   ;; Look at all the articles that refer back to old articles, and
3957   ;; fetch the headers for the articles that aren't there.  This will
3958   ;; build complete threads - if the roots haven't been expired by the
3959   ;; server, that is.
3960   (let ((mail-parse-charset gnus-newsgroup-charset)
3961         id heads)
3962     (mapatoms
3963      (lambda (refs)
3964        (when (not (car (symbol-value refs)))
3965          (setq heads (cdr (symbol-value refs)))
3966          (while heads
3967            (if (memq (mail-header-number (caar heads))
3968                      gnus-newsgroup-dormant)
3969                (setq heads (cdr heads))
3970              (setq id (symbol-name refs))
3971              (while (and (setq id (gnus-build-get-header id))
3972                          (not (car (gnus-id-to-thread id)))))
3973              (setq heads nil)))))
3974      gnus-newsgroup-dependencies)))
3975
3976 ;; This function has to be called with point after the article number
3977 ;; on the beginning of the line.
3978 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3979   (let ((eol (gnus-point-at-eol))
3980         (buffer (current-buffer))
3981         header references in-reply-to)
3982
3983     ;; overview: [num subject from date id refs chars lines misc]
3984     (unwind-protect
3985         (progn
3986           (narrow-to-region (point) eol)
3987           (unless (eobp)
3988             (forward-char))
3989
3990           (setq header
3991                 (make-full-mail-header
3992                  number                         ; number
3993                  (nnheader-nov-field)           ; subject
3994                  (nnheader-nov-field)           ; from
3995                  (nnheader-nov-field)           ; date
3996                  (nnheader-nov-read-message-id) ; id
3997                  (nnheader-nov-field)           ; refs
3998                  (nnheader-nov-read-integer)    ; chars
3999                  (nnheader-nov-read-integer)    ; lines
4000                  (unless (eobp)
4001                    (if (looking-at "Xref: ")
4002                        (goto-char (match-end 0)))
4003                    (nnheader-nov-field))        ; Xref
4004                  (nnheader-nov-parse-extra))))  ; extra
4005
4006       (widen))
4007
4008     (when (and (string= references "")
4009                (setq in-reply-to (mail-header-extra header))
4010                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4011       (mail-header-set-references
4012        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4013
4014     (when gnus-alter-header-function
4015       (funcall gnus-alter-header-function header))
4016     (gnus-dependencies-add-header header dependencies force-new)))
4017
4018 (defun gnus-build-get-header (id)
4019   "Look through the buffer of NOV lines and find the header to ID.
4020 Enter this line into the dependencies hash table, and return
4021 the id of the parent article (if any)."
4022   (let ((deps gnus-newsgroup-dependencies)
4023         found header)
4024     (prog1
4025         (save-excursion
4026           (set-buffer nntp-server-buffer)
4027           (let ((case-fold-search nil))
4028             (goto-char (point-min))
4029             (while (and (not found)
4030                         (search-forward id nil t))
4031               (beginning-of-line)
4032               (setq found (looking-at
4033                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4034                                    (regexp-quote id))))
4035               (or found (beginning-of-line 2)))
4036             (when found
4037               (beginning-of-line)
4038               (and
4039                (setq header (gnus-nov-parse-line
4040                              (read (current-buffer)) deps))
4041                (gnus-parent-id (mail-header-references header))))))
4042       (when header
4043         (let ((number (mail-header-number header)))
4044           (push number gnus-newsgroup-limit)
4045           (push header gnus-newsgroup-headers)
4046           (if (memq number gnus-newsgroup-unselected)
4047               (progn
4048                 (setq gnus-newsgroup-unreads
4049                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4050                                                number))
4051                 (setq gnus-newsgroup-unselected
4052                       (delq number gnus-newsgroup-unselected)))
4053             (push number gnus-newsgroup-ancient)))))))
4054
4055 (defun gnus-build-all-threads ()
4056   "Read all the headers."
4057   (let ((gnus-summary-ignore-duplicates t)
4058         (mail-parse-charset gnus-newsgroup-charset)
4059         (dependencies gnus-newsgroup-dependencies)
4060         header article)
4061     (save-excursion
4062       (set-buffer nntp-server-buffer)
4063       (let ((case-fold-search nil))
4064         (goto-char (point-min))
4065         (while (not (eobp))
4066           (ignore-errors
4067             (setq article (read (current-buffer))
4068                   header (gnus-nov-parse-line article dependencies)))
4069           (when header
4070             (save-excursion
4071               (set-buffer gnus-summary-buffer)
4072               (push header gnus-newsgroup-headers)
4073               (if (memq (setq article (mail-header-number header))
4074                         gnus-newsgroup-unselected)
4075                   (progn
4076                     (setq gnus-newsgroup-unreads
4077                           (gnus-add-to-sorted-list
4078                            gnus-newsgroup-unreads article))
4079                     (setq gnus-newsgroup-unselected
4080                           (delq article gnus-newsgroup-unselected)))
4081                 (push article gnus-newsgroup-ancient)))
4082             (forward-line 1)))))))
4083
4084 (defun gnus-summary-update-article-line (article header)
4085   "Update the line for ARTICLE using HEADERS."
4086   (let* ((id (mail-header-id header))
4087          (thread (gnus-id-to-thread id)))
4088     (unless thread
4089       (error "Article in no thread"))
4090     ;; Update the thread.
4091     (setcar thread header)
4092     (gnus-summary-goto-subject article)
4093     (let* ((datal (gnus-data-find-list article))
4094            (data (car datal))
4095            (buffer-read-only nil)
4096            (level (gnus-summary-thread-level)))
4097       (gnus-delete-line)
4098       (let ((inserted (- (point)
4099                          (progn
4100                            (gnus-summary-insert-line
4101                             header level nil 
4102                             (memq article gnus-newsgroup-undownloaded)
4103                             (gnus-article-mark article)
4104                             (memq article gnus-newsgroup-replied)
4105                             (memq article gnus-newsgroup-expirable)
4106                             ;; Only insert the Subject string when it's different
4107                             ;; from the previous Subject string.
4108                             (if (and
4109                                  gnus-show-threads
4110                                  (gnus-subject-equal
4111                                   (condition-case ()
4112                                       (mail-header-subject
4113                                        (gnus-data-header
4114                                         (cadr
4115                                          (gnus-data-find-list
4116                                           article
4117                                           (gnus-data-list t)))))
4118                                     ;; Error on the side of excessive subjects.
4119                                     (error ""))
4120                                   (mail-header-subject header)))
4121                                 ""
4122                               (mail-header-subject header))
4123                             nil (cdr (assq article gnus-newsgroup-scored))
4124                             (memq article gnus-newsgroup-processable))
4125                            (point)))))
4126         (when (cdr datal)
4127           (gnus-data-update-list
4128            (cdr datal) 
4129            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4130
4131 (defun gnus-summary-update-article (article &optional iheader)
4132   "Update ARTICLE in the summary buffer."
4133   (set-buffer gnus-summary-buffer)
4134   (let* ((header (gnus-summary-article-header article))
4135          (id (mail-header-id header))
4136          (data (gnus-data-find article))
4137          (thread (gnus-id-to-thread id))
4138          (references (mail-header-references header))
4139          (parent
4140           (gnus-id-to-thread
4141            (or (gnus-parent-id
4142                 (when (and references
4143                            (not (equal "" references)))
4144                   references))
4145                "none")))
4146          (buffer-read-only nil)
4147          (old (car thread)))
4148     (when thread
4149       (unless iheader
4150         (setcar thread nil)
4151         (when parent
4152           (delq thread parent)))
4153       (if (gnus-summary-insert-subject id header)
4154           ;; Set the (possibly) new article number in the data structure.
4155           (gnus-data-set-number data (gnus-id-to-article id))
4156         (setcar thread old)
4157         nil))))
4158
4159 (defun gnus-rebuild-thread (id &optional line)
4160   "Rebuild the thread containing ID.
4161 If LINE, insert the rebuilt thread starting on line LINE."
4162   (let ((buffer-read-only nil)
4163         old-pos current thread data)
4164     (if (not gnus-show-threads)
4165         (setq thread (list (car (gnus-id-to-thread id))))
4166       ;; Get the thread this article is part of.
4167       (setq thread (gnus-remove-thread id)))
4168     (setq old-pos (gnus-point-at-bol))
4169     (setq current (save-excursion
4170                     (and (re-search-backward "[\r\n]" nil t)
4171                          (gnus-summary-article-number))))
4172     ;; If this is a gathered thread, we have to go some re-gathering.
4173     (when (stringp (car thread))
4174       (let ((subject (car thread))
4175             roots thr)
4176         (setq thread (cdr thread))
4177         (while thread
4178           (unless (memq (setq thr (gnus-id-to-thread
4179                                    (gnus-root-id
4180                                     (mail-header-id (caar thread)))))
4181                         roots)
4182             (push thr roots))
4183           (setq thread (cdr thread)))
4184         ;; We now have all (unique) roots.
4185         (if (= (length roots) 1)
4186             ;; All the loose roots are now one solid root.
4187             (setq thread (car roots))
4188           (setq thread (cons subject (gnus-sort-threads roots))))))
4189     (let (threads)
4190       ;; We then insert this thread into the summary buffer.
4191       (when line
4192         (goto-char (point-min))
4193         (forward-line (1- line)))
4194       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4195         (if gnus-show-threads
4196             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4197           (gnus-summary-prepare-unthreaded thread))
4198         (setq data (nreverse gnus-newsgroup-data))
4199         (setq threads gnus-newsgroup-threads))
4200       ;; We splice the new data into the data structure.
4201       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4202       ;;!!! then we want to insert at the beginning of the buffer.
4203       ;;!!! That happens to be true with Gnus now, but that may
4204       ;;!!! change in the future.  Perhaps.
4205       (gnus-data-enter-list
4206        (if line nil current) data (- (point) old-pos))
4207       (setq gnus-newsgroup-threads
4208             (nconc threads gnus-newsgroup-threads))
4209       (gnus-data-compute-positions))))
4210
4211 (defun gnus-number-to-header (number)
4212   "Return the header for article NUMBER."
4213   (let ((headers gnus-newsgroup-headers))
4214     (while (and headers
4215                 (not (= number (mail-header-number (car headers)))))
4216       (pop headers))
4217     (when headers
4218       (car headers))))
4219
4220 (defun gnus-parent-headers (in-headers &optional generation)
4221   "Return the headers of the GENERATIONeth parent of HEADERS."
4222   (unless generation
4223     (setq generation 1))
4224   (let ((parent t)
4225         (headers in-headers)
4226         references)
4227     (while (and parent
4228                 (not (zerop generation))
4229                 (setq references (mail-header-references headers)))
4230       (setq headers (if (and references
4231                              (setq parent (gnus-parent-id references)))
4232                         (car (gnus-id-to-thread parent))
4233                       nil))
4234       (decf generation))
4235     (and (not (eq headers in-headers))
4236          headers)))
4237
4238 (defun gnus-id-to-thread (id)
4239   "Return the (sub-)thread where ID appears."
4240   (gnus-gethash id gnus-newsgroup-dependencies))
4241
4242 (defun gnus-id-to-article (id)
4243   "Return the article number of ID."
4244   (let ((thread (gnus-id-to-thread id)))
4245     (when (and thread
4246                (car thread))
4247       (mail-header-number (car thread)))))
4248
4249 (defun gnus-id-to-header (id)
4250   "Return the article headers of ID."
4251   (car (gnus-id-to-thread id)))
4252
4253 (defun gnus-article-displayed-root-p (article)
4254   "Say whether ARTICLE is a root(ish) article."
4255   (let ((level (gnus-summary-thread-level article))
4256         (refs (mail-header-references  (gnus-summary-article-header article)))
4257         particle)
4258     (cond
4259      ((null level) nil)
4260      ((zerop level) t)
4261      ((null refs) t)
4262      ((null (gnus-parent-id refs)) t)
4263      ((and (= 1 level)
4264            (null (setq particle (gnus-id-to-article
4265                                  (gnus-parent-id refs))))
4266            (null (gnus-summary-thread-level particle)))))))
4267
4268 (defun gnus-root-id (id)
4269   "Return the id of the root of the thread where ID appears."
4270   (let (last-id prev)
4271     (while (and id (setq prev (car (gnus-id-to-thread id))))
4272       (setq last-id id
4273             id (gnus-parent-id (mail-header-references prev))))
4274     last-id))
4275
4276 (defun gnus-articles-in-thread (thread)
4277   "Return the list of articles in THREAD."
4278   (cons (mail-header-number (car thread))
4279         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4280
4281 (defun gnus-remove-thread (id &optional dont-remove)
4282   "Remove the thread that has ID in it."
4283   (let (headers thread last-id)
4284     ;; First go up in this thread until we find the root.
4285     (setq last-id (gnus-root-id id)
4286           headers (message-flatten-list (gnus-id-to-thread last-id)))
4287     ;; We have now found the real root of this thread.  It might have
4288     ;; been gathered into some loose thread, so we have to search
4289     ;; through the threads to find the thread we wanted.
4290     (let ((threads gnus-newsgroup-threads)
4291           sub)
4292       (while threads
4293         (setq sub (car threads))
4294         (if (stringp (car sub))
4295             ;; This is a gathered thread, so we look at the roots
4296             ;; below it to find whether this article is in this
4297             ;; gathered root.
4298             (progn
4299               (setq sub (cdr sub))
4300               (while sub
4301                 (when (member (caar sub) headers)
4302                   (setq thread (car threads)
4303                         threads nil
4304                         sub nil))
4305                 (setq sub (cdr sub))))
4306           ;; It's an ordinary thread, so we check it.
4307           (when (eq (car sub) (car headers))
4308             (setq thread sub
4309                   threads nil)))
4310         (setq threads (cdr threads)))
4311       ;; If this article is in no thread, then it's a root.
4312       (if thread
4313           (unless dont-remove
4314             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4315         (setq thread (gnus-id-to-thread last-id)))
4316       (when thread
4317         (prog1
4318             thread                      ; We return this thread.
4319           (unless dont-remove
4320             (if (stringp (car thread))
4321                 (progn
4322                   ;; If we use dummy roots, then we have to remove the
4323                   ;; dummy root as well.
4324                   (when (eq gnus-summary-make-false-root 'dummy)
4325                     ;; We go to the dummy root by going to
4326                     ;; the first sub-"thread", and then one line up.
4327                     (gnus-summary-goto-article
4328                      (mail-header-number (caadr thread)))
4329                     (forward-line -1)
4330                     (gnus-delete-line)
4331                     (gnus-data-compute-positions))
4332                   (setq thread (cdr thread))
4333                   (while thread
4334                     (gnus-remove-thread-1 (car thread))
4335                     (setq thread (cdr thread))))
4336               (gnus-remove-thread-1 thread))))))))
4337
4338 (defun gnus-remove-thread-1 (thread)
4339   "Remove the thread THREAD recursively."
4340   (let ((number (mail-header-number (pop thread)))
4341         d)
4342     (setq thread (reverse thread))
4343     (while thread
4344       (gnus-remove-thread-1 (pop thread)))
4345     (when (setq d (gnus-data-find number))
4346       (goto-char (gnus-data-pos d))
4347       (gnus-summary-show-thread)
4348       (gnus-data-remove
4349        number
4350        (- (gnus-point-at-bol)
4351           (prog1
4352               (1+ (gnus-point-at-eol))
4353             (gnus-delete-line)))))))
4354
4355 (defun gnus-sort-threads-1 (threads func)
4356   (sort (mapcar (lambda (thread)
4357                   (cons (car thread)
4358                         (and (cdr thread)
4359                              (gnus-sort-threads-1 (cdr thread) func))))
4360                 threads) func))
4361
4362 (defun gnus-sort-threads (threads)
4363   "Sort THREADS."
4364   (if (not gnus-thread-sort-functions)
4365       threads
4366     (gnus-message 8 "Sorting threads...")
4367     (let ((max-lisp-eval-depth 5000))
4368       (prog1 (gnus-sort-threads-1
4369          threads
4370          (gnus-make-sort-function gnus-thread-sort-functions))
4371         (gnus-message 8 "Sorting threads...done")))))
4372
4373 (defun gnus-sort-articles (articles)
4374   "Sort ARTICLES."
4375   (when gnus-article-sort-functions
4376     (gnus-message 7 "Sorting articles...")
4377     (prog1
4378         (setq gnus-newsgroup-headers
4379               (sort articles (gnus-make-sort-function
4380                               gnus-article-sort-functions)))
4381       (gnus-message 7 "Sorting articles...done"))))
4382
4383 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4384 (defmacro gnus-thread-header (thread)
4385   "Return header of first article in THREAD.
4386 Note that THREAD must never, ever be anything else than a variable -
4387 using some other form will lead to serious barfage."
4388   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4389   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4390   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4391         (vector thread) 2))
4392
4393 (defsubst gnus-article-sort-by-number (h1 h2)
4394   "Sort articles by article number."
4395   (< (mail-header-number h1)
4396      (mail-header-number h2)))
4397
4398 (defun gnus-thread-sort-by-number (h1 h2)
4399   "Sort threads by root article number."
4400   (gnus-article-sort-by-number
4401    (gnus-thread-header h1) (gnus-thread-header h2)))
4402
4403 (defsubst gnus-article-sort-by-random (h1 h2)
4404   "Sort articles by article number."
4405   (zerop (random 2)))
4406
4407 (defun gnus-thread-sort-by-random (h1 h2)
4408   "Sort threads by root article number."
4409   (gnus-article-sort-by-random
4410    (gnus-thread-header h1) (gnus-thread-header h2)))
4411
4412 (defsubst gnus-article-sort-by-lines (h1 h2)
4413   "Sort articles by article Lines header."
4414   (< (mail-header-lines h1)
4415      (mail-header-lines h2)))
4416
4417 (defun gnus-thread-sort-by-lines (h1 h2)
4418   "Sort threads by root article Lines header."
4419   (gnus-article-sort-by-lines
4420    (gnus-thread-header h1) (gnus-thread-header h2)))
4421
4422 (defsubst gnus-article-sort-by-chars (h1 h2)
4423   "Sort articles by octet length."
4424   (< (mail-header-chars h1)
4425      (mail-header-chars h2)))
4426
4427 (defun gnus-thread-sort-by-chars (h1 h2)
4428   "Sort threads by root article octet length."
4429   (gnus-article-sort-by-chars
4430    (gnus-thread-header h1) (gnus-thread-header h2)))
4431
4432 (defsubst gnus-article-sort-by-author (h1 h2)
4433   "Sort articles by root author."
4434   (string-lessp
4435    (let ((addr (car (mime-entity-read-field h1 'From))))
4436      (or (std11-full-name-string addr)
4437          (std11-address-string addr)
4438          ""))
4439    (let ((addr (car (mime-entity-read-field h2 'From))))
4440      (or (std11-full-name-string addr)
4441          (std11-address-string addr)
4442          ""))
4443    ))
4444
4445 (defun gnus-thread-sort-by-author (h1 h2)
4446   "Sort threads by root author."
4447   (gnus-article-sort-by-author
4448    (gnus-thread-header h1)  (gnus-thread-header h2)))
4449
4450 (defsubst gnus-article-sort-by-subject (h1 h2)
4451   "Sort articles by root subject."
4452   (string-lessp
4453    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4454    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4455
4456 (defun gnus-thread-sort-by-subject (h1 h2)
4457   "Sort threads by root subject."
4458   (gnus-article-sort-by-subject
4459    (gnus-thread-header h1) (gnus-thread-header h2)))
4460
4461 (defsubst gnus-article-sort-by-date (h1 h2)
4462   "Sort articles by root article date."
4463   (time-less-p
4464    (gnus-date-get-time (mail-header-date h1))
4465    (gnus-date-get-time (mail-header-date h2))))
4466
4467 (defun gnus-thread-sort-by-date (h1 h2)
4468   "Sort threads by root article date."
4469   (gnus-article-sort-by-date
4470    (gnus-thread-header h1) (gnus-thread-header h2)))
4471
4472 (defsubst gnus-article-sort-by-score (h1 h2)
4473   "Sort articles by root article score.
4474 Unscored articles will be counted as having a score of zero."
4475   (> (or (cdr (assq (mail-header-number h1)
4476                     gnus-newsgroup-scored))
4477          gnus-summary-default-score 0)
4478      (or (cdr (assq (mail-header-number h2)
4479                     gnus-newsgroup-scored))
4480          gnus-summary-default-score 0)))
4481
4482 (defun gnus-thread-sort-by-score (h1 h2)
4483   "Sort threads by root article score."
4484   (gnus-article-sort-by-score
4485    (gnus-thread-header h1) (gnus-thread-header h2)))
4486
4487 (defun gnus-thread-sort-by-total-score (h1 h2)
4488   "Sort threads by the sum of all scores in the thread.
4489 Unscored articles will be counted as having a score of zero."
4490   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4491
4492 (defun gnus-thread-total-score (thread)
4493   ;; This function find the total score of THREAD.
4494   (cond
4495    ((null thread)
4496     0)
4497    ((consp thread)
4498     (if (stringp (car thread))
4499         (apply gnus-thread-score-function 0
4500                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4501       (gnus-thread-total-score-1 thread)))
4502    (t
4503     (gnus-thread-total-score-1 (list thread)))))
4504
4505 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4506   "Sort threads such that the thread with the most recently arrived article comes first."
4507   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4508
4509 (defun gnus-thread-highest-number (thread)
4510   "Return the highest article number in THREAD."
4511   (apply 'max (mapcar (lambda (header)
4512                         (mail-header-number header))
4513                       (message-flatten-list thread))))
4514
4515 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4516   "Sort threads such that the thread with the most recently dated article comes first."
4517   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4518
4519 (defun gnus-thread-latest-date (thread)
4520   "Return the highest article date in THREAD."
4521   (let ((previous-time 0))
4522     (apply 'max
4523            (mapcar
4524             (lambda (header)
4525               (setq previous-time
4526                     (time-to-seconds
4527                      (condition-case ()
4528                          (mail-header-parse-date (mail-header-date header))
4529                        (error previous-time)))))
4530             (sort
4531              (message-flatten-list thread)
4532              (lambda (h1 h2)
4533                (< (mail-header-number h1)
4534                   (mail-header-number h2))))))))
4535
4536 (defun gnus-thread-total-score-1 (root)
4537   ;; This function find the total score of the thread below ROOT.
4538   (setq root (car root))
4539   (apply gnus-thread-score-function
4540          (or (append
4541               (mapcar 'gnus-thread-total-score
4542                       (cdr (gnus-id-to-thread (mail-header-id root))))
4543               (when (> (mail-header-number root) 0)
4544                 (list (or (cdr (assq (mail-header-number root)
4545                                      gnus-newsgroup-scored))
4546                           gnus-summary-default-score 0))))
4547              (list gnus-summary-default-score)
4548              '(0))))
4549
4550 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4551 (defvar gnus-tmp-prev-subject nil)
4552 (defvar gnus-tmp-false-parent nil)
4553 (defvar gnus-tmp-root-expunged nil)
4554 (defvar gnus-tmp-dummy-line nil)
4555
4556 (eval-when-compile (defvar gnus-tmp-header))
4557 (defun gnus-extra-header (type &optional header)
4558   "Return the extra header of TYPE."
4559   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4560       ""))
4561
4562 (defvar gnus-tmp-thread-tree-header-string "")
4563
4564 (defcustom gnus-sum-thread-tree-root "> "
4565   "With %B spec, used for the root of a thread.
4566 If nil, use subject instead."
4567   :type 'string
4568   :group 'gnus-thread)
4569 (defcustom gnus-sum-thread-tree-single-indent ""
4570   "With %B spec, used for a thread with just one message.
4571 If nil, use subject instead."
4572   :type 'string
4573   :group 'gnus-thread)
4574 (defcustom gnus-sum-thread-tree-vertical "| "
4575   "With %B spec, used for drawing a vertical line."
4576   :type 'string
4577   :group 'gnus-thread)
4578 (defcustom gnus-sum-thread-tree-indent "  "
4579   "With %B spec, used for indenting."
4580   :type 'string
4581   :group 'gnus-thread)
4582 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4583   "With %B spec, used for a leaf with brothers."
4584   :type 'string
4585   :group 'gnus-thread)
4586 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4587   "With %B spec, used for a leaf without brothers."
4588   :type 'string
4589   :group 'gnus-thread)
4590
4591 (defun gnus-summary-prepare-threads (threads)
4592   "Prepare summary buffer from THREADS and indentation LEVEL.
4593 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4594 or a straight list of headers."
4595   (gnus-message 7 "Generating summary...")
4596
4597   (setq gnus-newsgroup-threads threads)
4598   (beginning-of-line)
4599
4600   (let ((gnus-tmp-level 0)
4601         (default-score (or gnus-summary-default-score 0))
4602         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4603         (building-line-count gnus-summary-display-while-building)
4604         (building-count (integerp gnus-summary-display-while-building))
4605         thread number subject stack state gnus-tmp-gathered beg-match
4606         new-roots gnus-tmp-new-adopts thread-end simp-subject
4607         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4608         gnus-tmp-replied gnus-tmp-subject-or-nil
4609         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4610         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4611         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4612         tree-stack)
4613
4614     (setq gnus-tmp-prev-subject nil
4615           gnus-tmp-thread-tree-header-string "")
4616
4617     (if (vectorp (car threads))
4618         ;; If this is a straight (sic) list of headers, then a
4619         ;; threaded summary display isn't required, so we just create
4620         ;; an unthreaded one.
4621         (gnus-summary-prepare-unthreaded threads)
4622
4623       ;; Do the threaded display.
4624
4625       (if gnus-summary-display-while-building
4626           (switch-to-buffer (buffer-name)))
4627       (while (or threads stack gnus-tmp-new-adopts new-roots)
4628
4629         (if (and (= gnus-tmp-level 0)
4630                  (or (not stack)
4631                      (= (caar stack) 0))
4632                  (not gnus-tmp-false-parent)
4633                  (or gnus-tmp-new-adopts new-roots))
4634             (if gnus-tmp-new-adopts
4635                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4636                       thread (list (car gnus-tmp-new-adopts))
4637                       gnus-tmp-header (caar thread)
4638                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4639               (when new-roots
4640                 (setq thread (list (car new-roots))
4641                       gnus-tmp-header (caar thread)
4642                       new-roots (cdr new-roots))))
4643
4644           (if threads
4645               ;; If there are some threads, we do them before the
4646               ;; threads on the stack.
4647               (setq thread threads
4648                     gnus-tmp-header (caar thread))
4649             ;; There were no current threads, so we pop something off
4650             ;; the stack.
4651             (setq state (car stack)
4652                   gnus-tmp-level (car state)
4653                   tree-stack (cadr state)
4654                   thread (caddr state)
4655                   stack (cdr stack)
4656                   gnus-tmp-header (caar thread))))
4657
4658         (setq gnus-tmp-false-parent nil)
4659         (setq gnus-tmp-root-expunged nil)
4660         (setq thread-end nil)
4661
4662         (if (stringp gnus-tmp-header)
4663             ;; The header is a dummy root.
4664             (cond
4665              ((eq gnus-summary-make-false-root 'adopt)
4666               ;; We let the first article adopt the rest.
4667               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4668                                                (cddar thread)))
4669               (setq gnus-tmp-gathered
4670                     (nconc (mapcar
4671                             (lambda (h) (mail-header-number (car h)))
4672                             (cddar thread))
4673                            gnus-tmp-gathered))
4674               (setq thread (cons (list (caar thread)
4675                                        (cadar thread))
4676                                  (cdr thread)))
4677               (setq gnus-tmp-level -1
4678                     gnus-tmp-false-parent t))
4679              ((eq gnus-summary-make-false-root 'empty)
4680               ;; We print adopted articles with empty subject fields.
4681               (setq gnus-tmp-gathered
4682                     (nconc (mapcar
4683                             (lambda (h) (mail-header-number (car h)))
4684                             (cddar thread))
4685                            gnus-tmp-gathered))
4686               (setq gnus-tmp-level -1))
4687              ((eq gnus-summary-make-false-root 'dummy)
4688               ;; We remember that we probably want to output a dummy
4689               ;; root.
4690               (setq gnus-tmp-dummy-line gnus-tmp-header)
4691               (setq gnus-tmp-prev-subject gnus-tmp-header))
4692              (t
4693               ;; We do not make a root for the gathered
4694               ;; sub-threads at all.
4695               (setq gnus-tmp-level -1)))
4696
4697           (setq number (mail-header-number gnus-tmp-header)
4698                 subject (mail-header-subject gnus-tmp-header)
4699                 simp-subject (gnus-simplify-subject-fully subject))
4700
4701           (cond
4702            ;; If the thread has changed subject, we might want to make
4703            ;; this subthread into a root.
4704            ((and (null gnus-thread-ignore-subject)
4705                  (not (zerop gnus-tmp-level))
4706                  gnus-tmp-prev-subject
4707                  (not (string= gnus-tmp-prev-subject simp-subject)))
4708             (setq new-roots (nconc new-roots (list (car thread)))
4709                   thread-end t
4710                   gnus-tmp-header nil))
4711            ;; If the article lies outside the current limit,
4712            ;; then we do not display it.
4713            ((not (memq number gnus-newsgroup-limit))
4714             (setq gnus-tmp-gathered
4715                   (nconc (mapcar
4716                           (lambda (h) (mail-header-number (car h)))
4717                           (cdar thread))
4718                          gnus-tmp-gathered))
4719             (setq gnus-tmp-new-adopts (if (cdar thread)
4720                                           (append gnus-tmp-new-adopts
4721                                                   (cdar thread))
4722                                         gnus-tmp-new-adopts)
4723                   thread-end t
4724                   gnus-tmp-header nil)
4725             (when (zerop gnus-tmp-level)
4726               (setq gnus-tmp-root-expunged t)))
4727            ;; Perhaps this article is to be marked as read?
4728            ((and gnus-summary-mark-below
4729                  (< (or (cdr (assq number gnus-newsgroup-scored))
4730                         default-score)
4731                     gnus-summary-mark-below)
4732                  ;; Don't touch sparse articles.
4733                  (not (gnus-summary-article-sparse-p number))
4734                  (not (gnus-summary-article-ancient-p number)))
4735             (setq gnus-newsgroup-unreads
4736                   (delq number gnus-newsgroup-unreads))
4737             (if gnus-newsgroup-auto-expire
4738                 (setq gnus-newsgroup-expirable
4739                       (gnus-add-to-sorted-list
4740                        gnus-newsgroup-expirable number))
4741               (push (cons number gnus-low-score-mark)
4742                     gnus-newsgroup-reads))))
4743
4744           (when gnus-tmp-header
4745             ;; We may have an old dummy line to output before this
4746             ;; article.
4747             (when (and gnus-tmp-dummy-line
4748                        (gnus-subject-equal
4749                         gnus-tmp-dummy-line
4750                         (mail-header-subject gnus-tmp-header)))
4751               (gnus-summary-insert-dummy-line
4752                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4753               (setq gnus-tmp-dummy-line nil))
4754
4755             ;; Compute the mark.
4756             (setq gnus-tmp-unread (gnus-article-mark number))
4757
4758             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4759                                   gnus-tmp-header gnus-tmp-level)
4760                   gnus-newsgroup-data)
4761
4762             ;; Actually insert the line.
4763             (setq
4764              gnus-tmp-subject-or-nil
4765              (cond
4766               ((and gnus-thread-ignore-subject
4767                     gnus-tmp-prev-subject
4768                     (not (string= gnus-tmp-prev-subject simp-subject)))
4769                subject)
4770               ((zerop gnus-tmp-level)
4771                (if (and (eq gnus-summary-make-false-root 'empty)
4772                         (memq number gnus-tmp-gathered)
4773                         gnus-tmp-prev-subject
4774                         (string= gnus-tmp-prev-subject simp-subject))
4775                    gnus-summary-same-subject
4776                  subject))
4777               (t gnus-summary-same-subject)))
4778             (if (and (eq gnus-summary-make-false-root 'adopt)
4779                      (= gnus-tmp-level 1)
4780                      (memq number gnus-tmp-gathered))
4781                 (setq gnus-tmp-opening-bracket ?\<
4782                       gnus-tmp-closing-bracket ?\>)
4783               (setq gnus-tmp-opening-bracket ?\[
4784                     gnus-tmp-closing-bracket ?\]))
4785             (setq
4786              gnus-tmp-indentation
4787              (aref gnus-thread-indent-array gnus-tmp-level)
4788              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4789              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4790                                 gnus-summary-default-score 0)
4791              gnus-tmp-score-char
4792              (if (or (null gnus-summary-default-score)
4793                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4794                          gnus-summary-zcore-fuzz))
4795                  ?\ ;;;Whitespace
4796                (if (< gnus-tmp-score gnus-summary-default-score)
4797                    gnus-score-below-mark gnus-score-over-mark))
4798              gnus-tmp-replied
4799              (cond ((memq number gnus-newsgroup-processable)
4800                     gnus-process-mark)
4801                    ((memq number gnus-newsgroup-cached)
4802                     gnus-cached-mark)
4803                    ((memq number gnus-newsgroup-replied)
4804                     gnus-replied-mark)
4805                    ((memq number gnus-newsgroup-forwarded)
4806                     gnus-forwarded-mark)
4807                    ((memq number gnus-newsgroup-saved)
4808                     gnus-saved-mark)
4809                    ((memq number gnus-newsgroup-recent)
4810                     gnus-recent-mark)
4811                    ((memq number gnus-newsgroup-unseen)
4812                     gnus-unseen-mark)
4813                    (t gnus-no-mark))
4814              gnus-tmp-downloaded
4815              (cond ((memq number gnus-newsgroup-undownloaded) 
4816                     gnus-undownloaded-mark)
4817                    (gnus-newsgroup-agentized
4818                     gnus-downloaded-mark)
4819                    (t
4820                     gnus-no-mark))
4821              gnus-tmp-from (mail-header-from gnus-tmp-header)
4822              gnus-tmp-name
4823              (cond
4824               ((string-match "<[^>]+> *$" gnus-tmp-from)
4825                (setq beg-match (match-beginning 0))
4826                (or (and (string-match "^\".+\"" gnus-tmp-from)
4827                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4828                    (substring gnus-tmp-from 0 beg-match)))
4829               ((string-match "(.+)" gnus-tmp-from)
4830                (substring gnus-tmp-from
4831                           (1+ (match-beginning 0)) (1- (match-end 0))))
4832               (t gnus-tmp-from))
4833
4834              ;; Do the %B string
4835              gnus-tmp-thread-tree-header-string
4836              (cond
4837               ((not gnus-show-threads) "")
4838               ((zerop gnus-tmp-level)
4839                (if (cdar thread)
4840                    (or gnus-sum-thread-tree-root subject)
4841                  (or gnus-sum-thread-tree-single-indent subject)))
4842               (t
4843                (concat (apply 'concat
4844                               (mapcar (lambda (item)
4845                                         (if (= item 1)
4846                                             gnus-sum-thread-tree-vertical
4847                                           gnus-sum-thread-tree-indent))
4848                                       (cdr (reverse tree-stack))))
4849                        (if (nth 1 thread)
4850                            gnus-sum-thread-tree-leaf-with-other
4851                          gnus-sum-thread-tree-single-leaf)))))
4852             (when (string= gnus-tmp-name "")
4853               (setq gnus-tmp-name gnus-tmp-from))
4854             (unless (numberp gnus-tmp-lines)
4855               (setq gnus-tmp-lines -1))
4856             (if (= gnus-tmp-lines -1)
4857                 (setq gnus-tmp-lines "?")
4858               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4859               (gnus-put-text-property
4860              (point)
4861              (progn (eval gnus-summary-line-format-spec) (point))
4862                'gnus-number number)
4863             (when gnus-visual-p
4864               (forward-line -1)
4865               (gnus-run-hooks 'gnus-summary-update-hook)
4866               (forward-line 1))
4867
4868             (setq gnus-tmp-prev-subject simp-subject)))
4869
4870         (when (nth 1 thread)
4871           (push (list (max 0 gnus-tmp-level)
4872                       (copy-list tree-stack)
4873                       (nthcdr 1 thread))
4874                 stack))
4875         (push (if (nth 1 thread) 1 0) tree-stack)
4876         (incf gnus-tmp-level)
4877         (setq threads (if thread-end nil (cdar thread)))
4878         (if gnus-summary-display-while-building
4879             (if building-count
4880                 (progn
4881                   ;; use a set frequency
4882                   (setq building-line-count (1- building-line-count))
4883                   (when (= building-line-count 0)
4884                     (sit-for 0)
4885                     (setq building-line-count
4886                           gnus-summary-display-while-building)))
4887               ;; always
4888               (sit-for 0)))
4889         (unless threads
4890           (setq gnus-tmp-level 0)))))
4891   (gnus-message 7 "Generating summary...done"))
4892
4893 (defun gnus-summary-prepare-unthreaded (headers)
4894   "Generate an unthreaded summary buffer based on HEADERS."
4895   (let (header number mark)
4896
4897     (beginning-of-line)
4898
4899     (while headers
4900       ;; We may have to root out some bad articles...
4901       (when (memq (setq number (mail-header-number
4902                                 (setq header (pop headers))))
4903                   gnus-newsgroup-limit)
4904         ;; Mark article as read when it has a low score.
4905         (when (and gnus-summary-mark-below
4906                    (< (or (cdr (assq number gnus-newsgroup-scored))
4907                           gnus-summary-default-score 0)
4908                       gnus-summary-mark-below)
4909                    (not (gnus-summary-article-ancient-p number)))
4910           (setq gnus-newsgroup-unreads
4911                 (delq number gnus-newsgroup-unreads))
4912           (if gnus-newsgroup-auto-expire
4913               (push number gnus-newsgroup-expirable)
4914             (push (cons number gnus-low-score-mark)
4915                   gnus-newsgroup-reads)))
4916
4917         (setq mark (gnus-article-mark number))
4918         (push (gnus-data-make number mark (1+ (point)) header 0)
4919               gnus-newsgroup-data)
4920         (gnus-summary-insert-line
4921          header 0 number
4922          (memq number gnus-newsgroup-undownloaded)
4923          mark (memq number gnus-newsgroup-replied)
4924          (memq number gnus-newsgroup-expirable)
4925          (mail-header-subject header) nil
4926          (cdr (assq number gnus-newsgroup-scored))
4927          (memq number gnus-newsgroup-processable))))))
4928
4929 (defun gnus-summary-remove-list-identifiers ()
4930   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4931   (let ((regexp (if (consp gnus-list-identifiers)
4932                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4933                   gnus-list-identifiers))
4934         changed subject)
4935     (when regexp
4936       (dolist (header gnus-newsgroup-headers)
4937         (setq subject (mail-header-subject header)
4938               changed nil)
4939         (while (string-match
4940                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4941                 subject)
4942           (setq subject
4943                 (concat (substring subject 0 (match-beginning 2))
4944                         (substring subject (match-end 0)))
4945                 changed t))
4946         (when (and changed
4947                    (string-match
4948                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4949           (setq subject
4950                 (concat (substring subject 0 (match-beginning 1))
4951                         (substring subject (match-end 1)))))
4952         (when changed
4953           (mail-header-set-subject header subject))))))
4954
4955 (defun gnus-fetch-headers (articles)
4956   "Fetch headers of ARTICLES."
4957   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4958     (gnus-message 5 "Fetching headers for %s..." name)
4959     (prog1
4960         (if (eq 'nov
4961                 (setq gnus-headers-retrieved-by
4962                       (gnus-retrieve-headers
4963                        articles gnus-newsgroup-name
4964                        ;; We might want to fetch old headers, but
4965                        ;; not if there is only 1 article.
4966                        (and (or (and
4967                                  (not (eq gnus-fetch-old-headers 'some))
4968                                  (not (numberp gnus-fetch-old-headers)))
4969                                 (> (length articles) 1))
4970                             gnus-fetch-old-headers))))
4971             (gnus-get-newsgroup-headers-xover
4972              articles nil nil gnus-newsgroup-name t)
4973           (gnus-get-newsgroup-headers))
4974       (gnus-message 5 "Fetching headers for %s...done" name))))
4975
4976 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4977   "Select newsgroup GROUP.
4978 If READ-ALL is non-nil, all articles in the group are selected.
4979 If SELECT-ARTICLES, only select those articles from GROUP."
4980   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4981          ;;!!! Dirty hack; should be removed.
4982          (gnus-summary-ignore-duplicates
4983           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4984               t
4985             gnus-summary-ignore-duplicates))
4986          (info (nth 2 entry))
4987          articles fetched-articles cached)
4988
4989     (unless (gnus-check-server
4990              (set (make-local-variable 'gnus-current-select-method)
4991                   (gnus-find-method-for-group group)))
4992       (error "Couldn't open server"))
4993
4994     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4995         (gnus-activate-group group)     ; Or we can activate it...
4996         (progn                          ; Or we bug out.
4997           (when (equal major-mode 'gnus-summary-mode)
4998             (gnus-kill-buffer (current-buffer)))
4999           (error "Couldn't activate group %s: %s"
5000                  group (gnus-status-message group))))
5001
5002     (unless (gnus-request-group group t)
5003       (when (equal major-mode 'gnus-summary-mode)
5004         (gnus-kill-buffer (current-buffer)))
5005       (error "Couldn't request group %s: %s"
5006              group (gnus-status-message group)))
5007
5008     (setq gnus-newsgroup-name group
5009           gnus-newsgroup-unselected nil
5010           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5011
5012     (let ((display (gnus-group-find-parameter group 'display)))
5013       (setq gnus-newsgroup-display
5014             (cond
5015              ((not (zerop (or (car-safe read-all) 0)))
5016               ;; The user entered the group with C-u SPC/RET, let's show
5017               ;; all articles.
5018               'gnus-not-ignore)
5019              ((eq display 'all)
5020               'gnus-not-ignore)
5021              ((arrayp display)
5022               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5023              ((numberp display)
5024               ;; The following is probably the "correct" solution, but
5025               ;; it makes Gnus fetch all headers and then limit the
5026               ;; articles (which is slow), so instead we hack the
5027               ;; select-articles parameter instead. -- Simon Josefsson
5028               ;; <jas@kth.se>
5029               ;;
5030               ;; (gnus-byte-compile
5031               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5032               ;;                         display)))))
5033               (setq select-articles
5034                     (gnus-uncompress-range
5035                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5036                              (if (> tmp 0)
5037                                  tmp
5038                                1))
5039                            (cdr (gnus-active group)))))
5040               nil)
5041              (t
5042               nil))))
5043
5044     (gnus-summary-setup-default-charset)
5045
5046     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5047     (when (gnus-virtual-group-p group)
5048       (setq cached gnus-newsgroup-cached))
5049
5050     (setq gnus-newsgroup-unreads
5051           (gnus-sorted-ndifference
5052            (gnus-sorted-ndifference gnus-newsgroup-unreads
5053                                     gnus-newsgroup-marked)
5054            gnus-newsgroup-dormant))
5055
5056     (setq gnus-newsgroup-processable nil)
5057
5058     (gnus-update-read-articles group gnus-newsgroup-unreads)
5059
5060     ;; Adjust and set lists of article marks.
5061     (when info
5062       (gnus-adjust-marked-articles info))
5063     (if (setq articles select-articles)
5064         (setq gnus-newsgroup-unselected
5065               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5066       (setq articles (gnus-articles-to-read group read-all)))
5067
5068     (cond
5069      ((null articles)
5070       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5071       'quit)
5072      ((eq articles 0) nil)
5073      (t
5074       ;; Init the dependencies hash table.
5075       (setq gnus-newsgroup-dependencies
5076             (gnus-make-hashtable (length articles)))
5077       (gnus-set-global-variables)
5078       ;; Retrieve the headers and read them in.
5079
5080       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5081
5082       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5083       (when cached
5084         (setq gnus-newsgroup-cached cached))
5085
5086       ;; Suppress duplicates?
5087       (when gnus-suppress-duplicates
5088         (gnus-dup-suppress-articles))
5089
5090       ;; Set the initial limit.
5091       (setq gnus-newsgroup-limit (copy-sequence articles))
5092       ;; Remove canceled articles from the list of unread articles.
5093       (setq fetched-articles
5094             (mapcar (lambda (headers) (mail-header-number headers))
5095                     gnus-newsgroup-headers))
5096       (setq gnus-newsgroup-articles fetched-articles)
5097       (setq gnus-newsgroup-unreads
5098             (gnus-sorted-nintersection
5099              gnus-newsgroup-unreads fetched-articles))
5100       (gnus-compute-unseen-list)
5101
5102       ;; Removed marked articles that do not exist.
5103       (gnus-update-missing-marks
5104        (gnus-sorted-difference articles fetched-articles))
5105       ;; We might want to build some more threads first.
5106       (when (and gnus-fetch-old-headers
5107                  (eq gnus-headers-retrieved-by 'nov))
5108         (if (eq gnus-fetch-old-headers 'invisible)
5109             (gnus-build-all-threads)
5110           (gnus-build-old-threads)))
5111       ;; Let the Gnus agent mark articles as read.
5112       (when gnus-agent
5113         (gnus-agent-get-undownloaded-list))
5114       ;; Remove list identifiers from subject
5115       (when gnus-list-identifiers
5116         (gnus-summary-remove-list-identifiers))
5117       ;; Check whether auto-expire is to be done in this group.
5118       (setq gnus-newsgroup-auto-expire
5119             (gnus-group-auto-expirable-p group))
5120       ;; Set up the article buffer now, if necessary.
5121       (unless gnus-single-article-buffer
5122         (gnus-article-setup-buffer))
5123       ;; First and last article in this newsgroup.
5124       (when gnus-newsgroup-headers
5125         (setq gnus-newsgroup-begin
5126               (mail-header-number (car gnus-newsgroup-headers))
5127               gnus-newsgroup-end
5128               (mail-header-number
5129                (gnus-last-element gnus-newsgroup-headers))))
5130       ;; GROUP is successfully selected.
5131       (or gnus-newsgroup-headers t)))))
5132
5133 (defun gnus-compute-unseen-list ()
5134   ;; The `seen' marks are treated specially.
5135   (if (not gnus-newsgroup-seen)
5136       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5137     (setq gnus-newsgroup-unseen
5138           (gnus-inverse-list-range-intersection
5139            gnus-newsgroup-articles gnus-newsgroup-seen))))
5140
5141 (defun gnus-summary-display-make-predicate (display)
5142   (require 'gnus-agent)
5143   (when (= (length display) 1)
5144     (setq display (car display)))
5145   (unless gnus-summary-display-cache
5146     (dolist (elem (append '((unread . unread)
5147                             (read . read)
5148                             (unseen . unseen))
5149                           gnus-article-mark-lists))
5150       (push (cons (cdr elem)
5151                   (gnus-byte-compile
5152                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5153             gnus-summary-display-cache)))
5154   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5155         (gnus-category-predicate-cache gnus-summary-display-cache))
5156     (gnus-get-predicate display)))
5157
5158 ;; Uses the dynamically bound `number' variable.
5159 (eval-when-compile
5160   (defvar number))
5161 (defun gnus-article-marked-p (type &optional article)
5162   (let ((article (or article number)))
5163     (cond
5164      ((eq type 'tick)
5165       (memq article gnus-newsgroup-marked))
5166      ((eq type 'spam)
5167       (memq article gnus-newsgroup-spam-marked))
5168      ((eq type 'unsend)
5169       (memq article gnus-newsgroup-unsendable))
5170      ((eq type 'undownload)
5171       (memq article gnus-newsgroup-undownloaded))
5172      ((eq type 'download)
5173       (memq article gnus-newsgroup-downloadable))
5174      ((eq type 'unread)
5175       (memq article gnus-newsgroup-unreads))
5176      ((eq type 'read)
5177       (memq article gnus-newsgroup-reads))
5178      ((eq type 'dormant)
5179       (memq article gnus-newsgroup-dormant) )
5180      ((eq type 'expire)
5181       (memq article gnus-newsgroup-expirable))
5182      ((eq type 'reply)
5183       (memq article gnus-newsgroup-replied))
5184      ((eq type 'killed)
5185       (memq article gnus-newsgroup-killed))
5186      ((eq type 'bookmark)
5187       (assq article gnus-newsgroup-bookmarks))
5188      ((eq type 'score)
5189       (assq article gnus-newsgroup-scored))
5190      ((eq type 'save)
5191       (memq article gnus-newsgroup-saved))
5192      ((eq type 'cache)
5193       (memq article gnus-newsgroup-cached))
5194      ((eq type 'forward)
5195       (memq article gnus-newsgroup-forwarded))
5196      ((eq type 'seen)
5197       (not (memq article gnus-newsgroup-unseen)))
5198      ((eq type 'recent)
5199       (memq article gnus-newsgroup-recent))
5200      (t t))))
5201
5202 (defun gnus-articles-to-read (group &optional read-all)
5203   "Find out what articles the user wants to read."
5204   (let* ((display (gnus-group-find-parameter group 'display))
5205          (articles
5206           ;; Select all articles if `read-all' is non-nil, or if there
5207           ;; are no unread articles.
5208           (if (or read-all
5209                   (and (zerop (length gnus-newsgroup-marked))
5210                        (zerop (length gnus-newsgroup-unreads)))
5211                   ;; Fetch all if the predicate is non-nil.
5212                   gnus-newsgroup-display)
5213               ;; We want to select the headers for all the articles in
5214               ;; the group, so we select either all the active
5215               ;; articles in the group, or (if that's nil), the
5216               ;; articles in the cache.
5217               (or
5218                (gnus-uncompress-range (gnus-active group))
5219                (gnus-cache-articles-in-group group))
5220             ;; Select only the "normal" subset of articles.
5221             (gnus-sorted-nunion
5222              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5223              gnus-newsgroup-unreads)))
5224          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5225          (scored (length scored-list))
5226          (number (length articles))
5227          (marked (+ (length gnus-newsgroup-marked)
5228                     (length gnus-newsgroup-dormant)))
5229          (select
5230           (cond
5231            ((numberp read-all)
5232             read-all)
5233            ((numberp gnus-newsgroup-display)
5234             gnus-newsgroup-display)
5235            (t
5236             (condition-case ()
5237                 (cond
5238                  ((and (or (<= scored marked) (= scored number))
5239                        (numberp gnus-large-newsgroup)
5240                        (> number gnus-large-newsgroup))
5241                   (let* ((cursor-in-echo-area nil)
5242                          (initial (gnus-parameter-large-newsgroup-initial
5243                                    gnus-newsgroup-name))
5244                          (input
5245                           (read-string
5246                            (format
5247                             "How many articles from %s (%s %d): "
5248                             (gnus-limit-string
5249                              (gnus-group-decoded-name gnus-newsgroup-name)
5250                              35)
5251                             (if initial "max" "default")
5252                             number)
5253                            (if initial
5254                                (cons (number-to-string initial)
5255                                      0)))))
5256                     (if (string-match "^[ \t]*$" input) number input)))
5257                  ((and (> scored marked) (< scored number)
5258                        (> (- scored number) 20))
5259                   (let ((input
5260                          (read-string
5261                           (format "%s %s (%d scored, %d total): "
5262                                   "How many articles from"
5263                                   (gnus-group-decoded-name group)
5264                                   scored number))))
5265                     (if (string-match "^[ \t]*$" input)
5266                         number input)))
5267                  (t number))
5268               (quit
5269                (message "Quit getting the articles to read")
5270                nil))))))
5271     (setq select (if (stringp select) (string-to-number select) select))
5272     (if (or (null select) (zerop select))
5273         select
5274       (if (and (not (zerop scored)) (<= (abs select) scored))
5275           (progn
5276             (setq articles (sort scored-list '<))
5277             (setq number (length articles)))
5278         (setq articles (copy-sequence articles)))
5279
5280       (when (< (abs select) number)
5281         (if (< select 0)
5282             ;; Select the N oldest articles.
5283             (setcdr (nthcdr (1- (abs select)) articles) nil)
5284           ;; Select the N most recent articles.
5285           (setq articles (nthcdr (- number select) articles))))
5286       (setq gnus-newsgroup-unselected
5287             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5288       (when gnus-alter-articles-to-read-function
5289         (setq articles
5290               (sort
5291                (funcall gnus-alter-articles-to-read-function
5292                         gnus-newsgroup-name articles)
5293                '<)))
5294       articles)))
5295
5296 (defun gnus-killed-articles (killed articles)
5297   (let (out)
5298     (while articles
5299       (when (inline (gnus-member-of-range (car articles) killed))
5300         (push (car articles) out))
5301       (setq articles (cdr articles)))
5302     out))
5303
5304 (defun gnus-uncompress-marks (marks)
5305   "Uncompress the mark ranges in MARKS."
5306   (let ((uncompressed '(score bookmark))
5307         out)
5308     (while marks
5309       (if (memq (caar marks) uncompressed)
5310           (push (car marks) out)
5311         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5312       (setq marks (cdr marks)))
5313     out))
5314
5315 (defun gnus-article-mark-to-type (mark)
5316   "Return the type of MARK."
5317   (or (cadr (assq mark gnus-article-special-mark-lists))
5318       'list))
5319
5320 (defun gnus-article-unpropagatable-p (mark)
5321   "Return whether MARK should be propagated to backend."
5322   (memq mark gnus-article-unpropagated-mark-lists))
5323
5324 (defun gnus-adjust-marked-articles (info)
5325   "Set all article lists and remove all marks that are no longer valid."
5326   (let* ((marked-lists (gnus-info-marks info))
5327          (active (gnus-active (gnus-info-group info)))
5328          (min (car active))
5329          (max (cdr active))
5330          (types gnus-article-mark-lists)
5331          marks var articles article mark mark-type)
5332
5333     (dolist (marks marked-lists)
5334       (setq mark (car marks)
5335             mark-type (gnus-article-mark-to-type mark)
5336             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5337
5338       ;; We set the variable according to the type of the marks list,
5339       ;; and then adjust the marks to a subset of the active articles.
5340       (cond
5341        ;; Adjust "simple" lists.
5342        ((eq mark-type 'list)
5343         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5344         (when (memq mark '(tick dormant expire reply save))
5345           (while articles
5346             (when (or (< (setq article (pop articles)) min) (> article max))
5347               (set var (delq article (symbol-value var)))))))
5348        ;; Adjust assocs.
5349        ((eq mark-type 'tuple)
5350         (set var (setq articles (cdr marks)))
5351         (when (not (listp (cdr (symbol-value var))))
5352           (set var (list (symbol-value var))))
5353         (when (not (listp (cdr articles)))
5354           (setq articles (list articles)))
5355         (while articles
5356           (when (or (not (consp (setq article (pop articles))))
5357                     (< (car article) min)
5358                     (> (car article) max))
5359             (set var (delq article (symbol-value var))))))
5360        ;; Adjust ranges (sloppily).
5361        ((eq mark-type 'range)
5362         (cond
5363          ((eq mark 'seen)
5364           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5365           ;; It should be (seen (NUM1 . NUM2)).
5366           (when (numberp (cddr marks))
5367             (setcdr marks (list (cdr marks))))
5368           (setq articles (cdr marks))
5369           (while (and articles
5370                       (or (and (consp (car articles))
5371                                (> min (cdar articles)))
5372                           (and (numberp (car articles))
5373                                (> min (car articles)))))
5374             (pop articles))
5375           (set var articles))))))))
5376
5377 (defun gnus-update-missing-marks (missing)
5378   "Go through the list of MISSING articles and remove them from the mark lists."
5379   (when missing
5380     (let (var m)
5381       ;; Go through all types.
5382       (dolist (elem gnus-article-mark-lists)
5383         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5384           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5385           (when (symbol-value var)
5386             ;; This list has articles.  So we delete all missing
5387             ;; articles from it.
5388             (setq m missing)
5389             (while m
5390               (set var (delq (pop m) (symbol-value var))))))))))
5391
5392 (defun gnus-update-marks ()
5393   "Enter the various lists of marked articles into the newsgroup info list."
5394   (let ((types gnus-article-mark-lists)
5395         (info (gnus-get-info gnus-newsgroup-name))
5396         type list newmarked symbol delta-marks)
5397     (when info
5398       ;; Add all marks lists to the list of marks lists.
5399       (while (setq type (pop types))
5400         (setq list (symbol-value
5401                     (setq symbol
5402                           (intern (format "gnus-newsgroup-%s" (car type))))))
5403
5404         (when list
5405           ;; Get rid of the entries of the articles that have the
5406           ;; default score.
5407           (when (and (eq (cdr type) 'score)
5408                      gnus-save-score
5409                      list)
5410             (let* ((arts list)
5411                    (prev (cons nil list))
5412                    (all prev))
5413               (while arts
5414                 (if (or (not (consp (car arts)))
5415                         (= (cdar arts) gnus-summary-default-score))
5416                     (setcdr prev (cdr arts))
5417                   (setq prev arts))
5418                 (setq arts (cdr arts)))
5419               (setq list (cdr all)))))
5420
5421         (when (eq (cdr type) 'seen)
5422           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5423
5424         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5425           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5426
5427         (when (and (gnus-check-backend-function
5428                     'request-set-mark gnus-newsgroup-name)
5429                    (not (gnus-article-unpropagatable-p (cdr type))))
5430           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5431                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5432                  (add (gnus-remove-from-range
5433                        (gnus-copy-sequence list) old)))
5434             (when add
5435               (push (list add 'add (list (cdr type))) delta-marks))
5436             (when del
5437               (push (list del 'del (list (cdr type))) delta-marks))))
5438
5439         (when list
5440           (push (cons (cdr type) list) newmarked)))
5441
5442       (when delta-marks
5443         (unless (gnus-check-group gnus-newsgroup-name)
5444           (error "Can't open server for %s" gnus-newsgroup-name))
5445         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5446
5447       ;; Enter these new marks into the info of the group.
5448       (if (nthcdr 3 info)
5449           (setcar (nthcdr 3 info) newmarked)
5450         ;; Add the marks lists to the end of the info.
5451         (when newmarked
5452           (setcdr (nthcdr 2 info) (list newmarked))))
5453
5454       ;; Cut off the end of the info if there's nothing else there.
5455       (let ((i 5))
5456         (while (and (> i 2)
5457                     (not (nth i info)))
5458           (when (nthcdr (decf i) info)
5459             (setcdr (nthcdr i info) nil)))))))
5460
5461 (defun gnus-set-mode-line (where)
5462   "Set the mode line of the article or summary buffers.
5463 If WHERE is `summary', the summary mode line format will be used."
5464   ;; Is this mode line one we keep updated?
5465   (when (and (memq where gnus-updated-mode-lines)
5466              (symbol-value
5467               (intern (format "gnus-%s-mode-line-format-spec" where))))
5468     (let (mode-string)
5469       (save-excursion
5470         ;; We evaluate this in the summary buffer since these
5471         ;; variables are buffer-local to that buffer.
5472         (set-buffer gnus-summary-buffer)
5473         ;; We bind all these variables that are used in the `eval' form
5474         ;; below.
5475         (let* ((mformat (symbol-value
5476                          (intern
5477                           (format "gnus-%s-mode-line-format-spec" where))))
5478                (gnus-tmp-group-name (gnus-group-decoded-name
5479                                      gnus-newsgroup-name))
5480                (gnus-tmp-article-number (or gnus-current-article 0))
5481                (gnus-tmp-unread gnus-newsgroup-unreads)
5482                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5483                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5484                (gnus-tmp-unread-and-unselected
5485                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5486                             (zerop gnus-tmp-unselected))
5487                        "")
5488                       ((zerop gnus-tmp-unselected)
5489                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5490                       (t (format "{%d(+%d) more}"
5491                                  gnus-tmp-unread-and-unticked
5492                                  gnus-tmp-unselected))))
5493                (gnus-tmp-subject
5494                 (if (and gnus-current-headers
5495                          (vectorp gnus-current-headers))
5496                     (gnus-mode-string-quote
5497                      (mail-header-subject gnus-current-headers))
5498                   ""))
5499                bufname-length max-len
5500                gnus-tmp-header);; passed as argument to any user-format-funcs
5501           (setq mode-string (eval mformat))
5502           (setq bufname-length (if (string-match "%b" mode-string)
5503                                    (- (length
5504                                        (buffer-name
5505                                         (if (eq where 'summary)
5506                                             nil
5507                                           (get-buffer gnus-article-buffer))))
5508                                       2)
5509                                  0))
5510           (setq max-len (max 4 (if gnus-mode-non-string-length
5511                                    (- (window-width)
5512                                       gnus-mode-non-string-length
5513                                       bufname-length)
5514                                  (length mode-string))))
5515           ;; We might have to chop a bit of the string off...
5516           (when (> (length mode-string) max-len)
5517             (setq mode-string
5518                   (concat (gnus-truncate-string mode-string (- max-len 3))
5519                           "...")))
5520           ;; Pad the mode string a bit.
5521           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5522       ;; Update the mode line.
5523       (setq mode-line-buffer-identification
5524             (gnus-mode-line-buffer-identification (list mode-string)))
5525       (set-buffer-modified-p t))))
5526
5527 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5528   "Go through the HEADERS list and add all Xrefs to a hash table.
5529 The resulting hash table is returned, or nil if no Xrefs were found."
5530   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5531          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5532          (xref-hashtb (gnus-make-hashtable))
5533          start group entry number xrefs header)
5534     (while headers
5535       (setq header (pop headers))
5536       (when (and (setq xrefs (mail-header-xref header))
5537                  (not (memq (setq number (mail-header-number header))
5538                             unreads)))
5539         (setq start 0)
5540         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5541           (setq start (match-end 0))
5542           (setq group (if prefix
5543                           (concat prefix (substring xrefs (match-beginning 1)
5544                                                     (match-end 1)))
5545                         (substring xrefs (match-beginning 1) (match-end 1))))
5546           (setq number
5547                 (string-to-int (substring xrefs (match-beginning 2)
5548                                           (match-end 2))))
5549           (if (setq entry (gnus-gethash group xref-hashtb))
5550               (setcdr entry (cons number (cdr entry)))
5551             (gnus-sethash group (cons number nil) xref-hashtb)))))
5552     (and start xref-hashtb)))
5553
5554 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5555   "Look through all the headers and mark the Xrefs as read."
5556   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5557         name entry info xref-hashtb idlist method nth4)
5558     (save-excursion
5559       (set-buffer gnus-group-buffer)
5560       (when (setq xref-hashtb
5561                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5562         (mapatoms
5563          (lambda (group)
5564            (unless (string= from-newsgroup (setq name (symbol-name group)))
5565              (setq idlist (symbol-value group))
5566              ;; Dead groups are not updated.
5567              (and (prog1
5568                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5569                             info (nth 2 entry))
5570                     (when (stringp (setq nth4 (gnus-info-method info)))
5571                       (setq nth4 (gnus-server-to-method nth4))))
5572                   ;; Only do the xrefs if the group has the same
5573                   ;; select method as the group we have just read.
5574                   (or (gnus-methods-equal-p
5575                        nth4 (gnus-find-method-for-group from-newsgroup))
5576                       virtual
5577                       (equal nth4 (setq method (gnus-find-method-for-group
5578                                                 from-newsgroup)))
5579                       (and (equal (car nth4) (car method))
5580                            (equal (nth 1 nth4) (nth 1 method))))
5581                   gnus-use-cross-reference
5582                   (or (not (eq gnus-use-cross-reference t))
5583                       virtual
5584                       ;; Only do cross-references on subscribed
5585                       ;; groups, if that is what is wanted.
5586                       (<= (gnus-info-level info) gnus-level-subscribed))
5587                   (gnus-group-make-articles-read name idlist))))
5588          xref-hashtb)))))
5589
5590 (defun gnus-compute-read-articles (group articles)
5591   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5592          (info (nth 2 entry))
5593          (active (gnus-active group))
5594          ninfo)
5595     (when entry
5596       ;; First peel off all invalid article numbers.
5597       (when active
5598         (let ((ids articles)
5599               id first)
5600           (while (setq id (pop ids))
5601             (when (and first (> id (cdr active)))
5602               ;; We'll end up in this situation in one particular
5603               ;; obscure situation.  If you re-scan a group and get
5604               ;; a new article that is cross-posted to a different
5605               ;; group that has not been re-scanned, you might get
5606               ;; crossposted article that has a higher number than
5607               ;; Gnus believes possible.  So we re-activate this
5608               ;; group as well.  This might mean doing the
5609               ;; crossposting thingy will *increase* the number
5610               ;; of articles in some groups.  Tsk, tsk.
5611               (setq active (or (gnus-activate-group group) active)))
5612             (when (or (> id (cdr active))
5613                       (< id (car active)))
5614               (setq articles (delq id articles))))))
5615       ;; If the read list is nil, we init it.
5616       (if (and active
5617                (null (gnus-info-read info))
5618                (> (car active) 1))
5619           (setq ninfo (cons 1 (1- (car active))))
5620         (setq ninfo (gnus-info-read info)))
5621       ;; Then we add the read articles to the range.
5622       (gnus-add-to-range
5623        ninfo (setq articles (sort articles '<))))))
5624
5625 (defun gnus-group-make-articles-read (group articles)
5626   "Update the info of GROUP to say that ARTICLES are read."
5627   (let* ((num 0)
5628          (entry (gnus-gethash group gnus-newsrc-hashtb))
5629          (info (nth 2 entry))
5630          (active (gnus-active group))
5631          range)
5632     (when entry
5633       (setq range (gnus-compute-read-articles group articles))
5634       (save-excursion
5635         (set-buffer gnus-group-buffer)
5636         (gnus-undo-register
5637           `(progn
5638              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5639              (gnus-info-set-read ',info ',(gnus-info-read info))
5640              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5641              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5642              (gnus-group-update-group ,group t))))
5643       ;; Add the read articles to the range.
5644       (gnus-info-set-read info range)
5645       (gnus-request-set-mark group (list (list range 'add '(read))))
5646       ;; Then we have to re-compute how many unread
5647       ;; articles there are in this group.
5648       (when active
5649         (cond
5650          ((not range)
5651           (setq num (- (1+ (cdr active)) (car active))))
5652          ((not (listp (cdr range)))
5653           (setq num (- (cdr active) (- (1+ (cdr range))
5654                                        (car range)))))
5655          (t
5656           (while range
5657             (if (numberp (car range))
5658                 (setq num (1+ num))
5659               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5660             (setq range (cdr range)))
5661           (setq num (- (cdr active) num))))
5662         ;; Update the number of unread articles.
5663         (setcar entry num)
5664         ;; Update the group buffer.
5665         (unless (gnus-ephemeral-group-p group)
5666           (gnus-group-update-group group t))))))
5667
5668 (defvar gnus-newsgroup-none-id 0)
5669
5670 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5671   (let ((cur nntp-server-buffer)
5672         (dependencies
5673          (or dependencies
5674              (save-excursion (set-buffer gnus-summary-buffer)
5675                              gnus-newsgroup-dependencies)))
5676         headers id end ref
5677         (mail-parse-charset gnus-newsgroup-charset)
5678         (mail-parse-ignored-charsets
5679          (save-excursion (condition-case nil
5680                              (set-buffer gnus-summary-buffer)
5681                            (error))
5682                          gnus-newsgroup-ignored-charsets)))
5683     (save-excursion
5684       (set-buffer nntp-server-buffer)
5685       ;; Translate all TAB characters into SPACE characters.
5686       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5687       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5688       (gnus-run-hooks 'gnus-parse-headers-hook)
5689       (let ((case-fold-search t)
5690             in-reply-to header p lines chars ctype)
5691         (goto-char (point-min))
5692         ;; Search to the beginning of the next header.  Error messages
5693         ;; do not begin with 2 or 3.
5694         (while (re-search-forward "^[23][0-9]+ " nil t)
5695           (setq id nil
5696                 ref nil)
5697           ;; This implementation of this function, with nine
5698           ;; search-forwards instead of the one re-search-forward and
5699           ;; a case (which basically was the old function) is actually
5700           ;; about twice as fast, even though it looks messier.  You
5701           ;; can't have everything, I guess.  Speed and elegance
5702           ;; doesn't always go hand in hand.
5703           (setq
5704            header
5705            (make-full-mail-header
5706             ;; Number.
5707             (prog1
5708                 (read cur)
5709               (end-of-line)
5710               (setq p (point))
5711               (narrow-to-region (point)
5712                                 (or (and (search-forward "\n.\n" nil t)
5713                                          (- (point) 2))
5714                                     (point))))
5715             ;; Subject.
5716             (progn
5717               (goto-char p)
5718               (if (search-forward "\nsubject:" nil t)
5719                   (nnheader-header-value)
5720                 "(none)"))
5721             ;; From.
5722             (progn
5723               (goto-char p)
5724               (if (search-forward "\nfrom:" nil t)
5725                   (nnheader-header-value)
5726                 "(nobody)"))
5727             ;; Date.
5728             (progn
5729               (goto-char p)
5730               (if (search-forward "\ndate:" nil t)
5731                   (nnheader-header-value) ""))
5732             ;; Message-ID.
5733             (progn
5734               (goto-char p)
5735               (setq id (if (re-search-forward
5736                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5737                            ;; We do it this way to make sure the Message-ID
5738                            ;; is (somewhat) syntactically valid.
5739                            (buffer-substring (match-beginning 1)
5740                                              (match-end 1))
5741                          ;; If there was no message-id, we just fake one
5742                          ;; to make subsequent routines simpler.
5743                          (nnheader-generate-fake-message-id))))
5744             ;; References.
5745             (progn
5746               (goto-char p)
5747               (if (search-forward "\nreferences:" nil t)
5748                   (progn
5749                     (setq end (point))
5750                     (prog1
5751                         (nnheader-header-value)
5752                       (setq ref
5753                             (buffer-substring
5754                              (progn
5755                                ;; (end-of-line)
5756                                (search-backward ">" end t)
5757                                (1+ (point)))
5758                              (progn
5759                                (search-backward "<" end t)
5760                                (point))))))
5761                 ;; Get the references from the in-reply-to header if there
5762                 ;; were no references and the in-reply-to header looks
5763                 ;; promising.
5764                 (if (and (search-forward "\nin-reply-to:" nil t)
5765                          (setq in-reply-to (nnheader-header-value))
5766                          (string-match "<[^>]+>" in-reply-to))
5767                     (let (ref2)
5768                       (setq ref (substring in-reply-to (match-beginning 0)
5769                                            (match-end 0)))
5770                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5771                         (setq ref2 (substring in-reply-to (match-beginning 0)
5772                                               (match-end 0)))
5773                         (when (> (length ref2) (length ref))
5774                           (setq ref ref2)))
5775                       ref)
5776                   (setq ref nil))))
5777             ;; Chars.
5778             (progn
5779               (goto-char p)
5780               (if (search-forward "\nchars: " nil t)
5781                   (if (numberp (setq chars (ignore-errors (read cur))))
5782                       chars -1)
5783                 -1))
5784             ;; Lines.
5785             (progn
5786               (goto-char p)
5787               (if (search-forward "\nlines: " nil t)
5788                   (if (numberp (setq lines (ignore-errors (read cur))))
5789                       lines -1)
5790                 -1))
5791             ;; Xref.
5792             (progn
5793               (goto-char p)
5794               (and (search-forward "\nxref:" nil t)
5795                    (nnheader-header-value)))
5796             ;; Extra.
5797             (when gnus-extra-headers
5798               (let ((extra gnus-extra-headers)
5799                     out)
5800                 (while extra
5801                   (goto-char p)
5802                   (when (search-forward
5803                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5804                     (push (cons (car extra) (nnheader-header-value)) out))
5805                   (pop extra))
5806                 out))))
5807           (goto-char p)
5808           (if (and (search-forward "\ncontent-type: " nil t)
5809                    (setq ctype (nnheader-header-value)))
5810               (mime-entity-set-content-type-internal
5811                header (mime-parse-Content-Type ctype)))
5812           (when (equal id ref)
5813             (setq ref nil))
5814
5815           (when gnus-alter-header-function
5816             (funcall gnus-alter-header-function header)
5817             (setq id (mail-header-id header)
5818                   ref (gnus-parent-id (mail-header-references header))))
5819
5820           (when (setq header
5821                       (gnus-dependencies-add-header
5822                        header dependencies force-new))
5823             (push header headers))
5824           (goto-char (point-max))
5825           (widen))
5826         (nreverse headers)))))
5827
5828 ;; Goes through the xover lines and returns a list of vectors
5829 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5830                                                   force-new dependencies
5831                                                   group also-fetch-heads)
5832   "Parse the news overview data in the server buffer.
5833 Return a list of headers that match SEQUENCE (see
5834 `nntp-retrieve-headers')."
5835   ;; Get the Xref when the users reads the articles since most/some
5836   ;; NNTP servers do not include Xrefs when using XOVER.
5837   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5838   (let ((mail-parse-charset gnus-newsgroup-charset)
5839         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5840         (cur nntp-server-buffer)
5841         (dependencies (or dependencies gnus-newsgroup-dependencies))
5842         (allp (cond
5843                ((eq gnus-read-all-available-headers t)
5844                 t)
5845                ((stringp gnus-read-all-available-headers)
5846                 (string-match gnus-read-all-available-headers group))
5847                (t
5848                 nil)))
5849         number headers header)
5850     (save-excursion
5851       (set-buffer nntp-server-buffer)
5852       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5853       ;; Allow the user to mangle the headers before parsing them.
5854       (gnus-run-hooks 'gnus-parse-headers-hook)
5855       (goto-char (point-min))
5856       (gnus-parse-without-error
5857         (while (and (or sequence allp)
5858                     (not (eobp)))
5859           (setq number (read cur))
5860           (when (not allp)
5861             (while (and sequence
5862                         (< (car sequence) number))
5863               (setq sequence (cdr sequence))))
5864           (when (and (or allp
5865                          (and sequence
5866                               (eq number (car sequence))))
5867                      (progn
5868                        (setq sequence (cdr sequence))
5869                        (setq header (inline
5870                                       (gnus-nov-parse-line
5871                                        number dependencies force-new)))))
5872             (push header headers))
5873           (forward-line 1)))
5874       ;; A common bug in inn is that if you have posted an article and
5875       ;; then retrieves the active file, it will answer correctly --
5876       ;; the new article is included.  However, a NOV entry for the
5877       ;; article may not have been generated yet, so this may fail.
5878       ;; We work around this problem by retrieving the last few
5879       ;; headers using HEAD.
5880       (if (or (not also-fetch-heads)
5881               (not sequence))
5882           ;; We (probably) got all the headers.
5883           (nreverse headers)
5884         (let ((gnus-nov-is-evil t))
5885           (nconc
5886            (nreverse headers)
5887            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5888              (gnus-get-newsgroup-headers))))))))
5889
5890 (defun gnus-article-get-xrefs ()
5891   "Fill in the Xref value in `gnus-current-headers', if necessary.
5892 This is meant to be called in `gnus-article-internal-prepare-hook'."
5893   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5894                                  gnus-current-headers)))
5895     (or (not gnus-use-cross-reference)
5896         (not headers)
5897         (and (mail-header-xref headers)
5898              (not (string= (mail-header-xref headers) "")))
5899         (let ((case-fold-search t)
5900               xref)
5901           (save-restriction
5902             (nnheader-narrow-to-headers)
5903             (goto-char (point-min))
5904             (when (or (and (not (eobp))
5905                            (eq (downcase (char-after)) ?x)
5906                            (looking-at "Xref:"))
5907                       (search-forward "\nXref:" nil t))
5908               (goto-char (1+ (match-end 0)))
5909               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5910               (mail-header-set-xref headers xref)))))))
5911
5912 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5913   "Find article ID and insert the summary line for that article.
5914 OLD-HEADER can either be a header or a line number to insert
5915 the subject line on."
5916   (let* ((line (and (numberp old-header) old-header))
5917          (old-header (and (vectorp old-header) old-header))
5918          (header (cond ((and old-header use-old-header)
5919                         old-header)
5920                        ((and (numberp id)
5921                              (gnus-number-to-header id))
5922                         (gnus-number-to-header id))
5923                        (t
5924                         (gnus-read-header id))))
5925          (number (and (numberp id) id))
5926          d)
5927     (when header
5928       ;; Rebuild the thread that this article is part of and go to the
5929       ;; article we have fetched.
5930       (when (and (not gnus-show-threads)
5931                  old-header)
5932         (when (and number
5933                    (setq d (gnus-data-find (mail-header-number old-header))))
5934           (goto-char (gnus-data-pos d))
5935           (gnus-data-remove
5936            number
5937            (- (gnus-point-at-bol)
5938               (prog1
5939                   (1+ (gnus-point-at-eol))
5940                 (gnus-delete-line))))))
5941       (when old-header
5942         (mail-header-set-number header (mail-header-number old-header)))
5943       (setq gnus-newsgroup-sparse
5944             (delq (setq number (mail-header-number header))
5945                   gnus-newsgroup-sparse))
5946       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5947       (push number gnus-newsgroup-limit)
5948       (gnus-rebuild-thread (mail-header-id header) line)
5949       (gnus-summary-goto-subject number nil t))
5950     (when (and (numberp number)
5951                (> number 0))
5952       ;; We have to update the boundaries even if we can't fetch the
5953       ;; article if ID is a number -- so that the next `P' or `N'
5954       ;; command will fetch the previous (or next) article even
5955       ;; if the one we tried to fetch this time has been canceled.
5956       (when (> number gnus-newsgroup-end)
5957         (setq gnus-newsgroup-end number))
5958       (when (< number gnus-newsgroup-begin)
5959         (setq gnus-newsgroup-begin number))
5960       (setq gnus-newsgroup-unselected
5961             (delq number gnus-newsgroup-unselected)))
5962     ;; Report back a success?
5963     (and header (mail-header-number header))))
5964
5965 ;;; Process/prefix in the summary buffer
5966
5967 (defun gnus-summary-work-articles (n)
5968   "Return a list of articles to be worked upon.
5969 The prefix argument, the list of process marked articles, and the
5970 current article will be taken into consideration."
5971   (save-excursion
5972     (set-buffer gnus-summary-buffer)
5973     (cond
5974      (n
5975       ;; A numerical prefix has been given.
5976       (setq n (prefix-numeric-value n))
5977       (let ((backward (< n 0))
5978             (n (abs (prefix-numeric-value n)))
5979             articles article)
5980         (save-excursion
5981           (while
5982               (and (> n 0)
5983                    (push (setq article (gnus-summary-article-number))
5984                          articles)
5985                    (if backward
5986                        (gnus-summary-find-prev nil article)
5987                      (gnus-summary-find-next nil article)))
5988             (decf n)))
5989         (nreverse articles)))
5990      ((and (gnus-region-active-p) (mark))
5991       (message "region active")
5992       ;; Work on the region between point and mark.
5993       (let ((max (max (point) (mark)))
5994             articles article)
5995         (save-excursion
5996           (goto-char (min (point) (mark)))
5997           (while
5998               (and
5999                (push (setq article (gnus-summary-article-number)) articles)
6000                (gnus-summary-find-next nil article)
6001                (< (point) max)))
6002           (nreverse articles))))
6003      (gnus-newsgroup-processable
6004       ;; There are process-marked articles present.
6005       ;; Save current state.
6006       (gnus-summary-save-process-mark)
6007       ;; Return the list.
6008       (reverse gnus-newsgroup-processable))
6009      (t
6010       ;; Just return the current article.
6011       (list (gnus-summary-article-number))))))
6012
6013 (defmacro gnus-summary-iterate (arg &rest forms)
6014   "Iterate over the process/prefixed articles and do FORMS.
6015 ARG is the interactive prefix given to the command.  FORMS will be
6016 executed with point over the summary line of the articles."
6017   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6018     `(let ((,articles (gnus-summary-work-articles ,arg)))
6019        (while ,articles
6020          (gnus-summary-goto-subject (car ,articles))
6021          ,@forms
6022          (pop ,articles)))))
6023
6024 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6025 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6026
6027 (defun gnus-summary-save-process-mark ()
6028   "Push the current set of process marked articles on the stack."
6029   (interactive)
6030   (push (copy-sequence gnus-newsgroup-processable)
6031         gnus-newsgroup-process-stack))
6032
6033 (defun gnus-summary-kill-process-mark ()
6034   "Push the current set of process marked articles on the stack and unmark."
6035   (interactive)
6036   (gnus-summary-save-process-mark)
6037   (gnus-summary-unmark-all-processable))
6038
6039 (defun gnus-summary-yank-process-mark ()
6040   "Pop the last process mark state off the stack and restore it."
6041   (interactive)
6042   (unless gnus-newsgroup-process-stack
6043     (error "Empty mark stack"))
6044   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6045
6046 (defun gnus-summary-process-mark-set (set)
6047   "Make SET into the current process marked articles."
6048   (gnus-summary-unmark-all-processable)
6049   (while set
6050     (gnus-summary-set-process-mark (pop set))))
6051
6052 ;;; Searching and stuff
6053
6054 (defun gnus-summary-search-group (&optional backward use-level)
6055   "Search for next unread newsgroup.
6056 If optional argument BACKWARD is non-nil, search backward instead."
6057   (save-excursion
6058     (set-buffer gnus-group-buffer)
6059     (when (gnus-group-search-forward
6060            backward nil (if use-level (gnus-group-group-level) nil))
6061       (gnus-group-group-name))))
6062
6063 (defun gnus-summary-best-group (&optional exclude-group)
6064   "Find the name of the best unread group.
6065 If EXCLUDE-GROUP, do not go to this group."
6066   (save-excursion
6067     (set-buffer gnus-group-buffer)
6068     (save-excursion
6069       (gnus-group-best-unread-group exclude-group))))
6070
6071 (defun gnus-summary-find-next (&optional unread article backward)
6072   (if backward (gnus-summary-find-prev unread article)
6073     (let* ((dummy (gnus-summary-article-intangible-p))
6074            (article (or article (gnus-summary-article-number)))
6075            (data (gnus-data-find-list article))
6076            result)
6077       (when (and (not dummy)
6078                  (or (not gnus-summary-check-current)
6079                      (not unread)
6080                      (not (gnus-data-unread-p (car data)))))
6081         (setq data (cdr data)))
6082       (when (setq result
6083                   (if unread
6084                       (progn
6085                         (while data
6086                           (unless (memq (gnus-data-number (car data)) 
6087                                         (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6088                                                gnus-newsgroup-undownloaded)
6089                                               (gnus-plugged
6090                                                nil)
6091                                               ((eq gnus-auto-goto-ignores 'unfetched)
6092                                                gnus-newsgroup-unfetched)
6093                                               ((eq gnus-auto-goto-ignores 'undownloaded)
6094                                                gnus-newsgroup-undownloaded)))
6095                             (when (gnus-data-unread-p (car data))
6096                               (setq result (car data)
6097                                     data nil)))
6098                           (setq data (cdr data)))
6099                         result)
6100                     (car data)))
6101         (goto-char (gnus-data-pos result))
6102         (gnus-data-number result)))))
6103
6104 (defun gnus-summary-find-prev (&optional unread article)
6105   (let* ((eobp (eobp))
6106          (article (or article (gnus-summary-article-number)))
6107          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6108          result)
6109     (when (and (not eobp)
6110                (or (not gnus-summary-check-current)
6111                    (not unread)
6112                    (not (gnus-data-unread-p (car data)))))
6113       (setq data (cdr data)))
6114     (when (setq result
6115                 (if unread
6116                     (progn
6117                       (while data
6118                         (unless (memq (gnus-data-number (car data))
6119                                       (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6120                                              gnus-newsgroup-undownloaded)
6121                                             (gnus-plugged
6122                                              nil)
6123                                             ((eq gnus-auto-goto-ignores 'unfetched)
6124                                              gnus-newsgroup-unfetched)
6125                                             ((eq gnus-auto-goto-ignores 'undownloaded)
6126                                              gnus-newsgroup-undownloaded)))
6127                           (when (gnus-data-unread-p (car data))
6128                             (setq result (car data)
6129                                   data nil)))
6130                         (setq data (cdr data)))
6131                       result)
6132                   (car data)))
6133       (goto-char (gnus-data-pos result))
6134       (gnus-data-number result))))
6135
6136 (defun gnus-summary-find-subject (subject &optional unread backward article)
6137   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6138          (article (or article (gnus-summary-article-number)))
6139          (articles (gnus-data-list backward))
6140          (arts (gnus-data-find-list article articles))
6141          result)
6142     (when (or (not gnus-summary-check-current)
6143               (not unread)
6144               (not (gnus-data-unread-p (car arts))))
6145       (setq arts (cdr arts)))
6146     (while arts
6147       (and (or (not unread)
6148                (gnus-data-unread-p (car arts)))
6149            (vectorp (gnus-data-header (car arts)))
6150            (gnus-subject-equal
6151             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6152            (setq result (car arts)
6153                  arts nil))
6154       (setq arts (cdr arts)))
6155     (and result
6156          (goto-char (gnus-data-pos result))
6157          (gnus-data-number result))))
6158
6159 (defun gnus-summary-search-forward (&optional unread subject backward)
6160   "Search forward for an article.
6161 If UNREAD, look for unread articles.  If SUBJECT, look for
6162 articles with that subject.  If BACKWARD, search backward instead."
6163   (cond (subject (gnus-summary-find-subject subject unread backward))
6164         (backward (gnus-summary-find-prev unread))
6165         (t (gnus-summary-find-next unread))))
6166
6167 (defun gnus-recenter (&optional n)
6168   "Center point in window and redisplay frame.
6169 Also do horizontal recentering."
6170   (interactive "P")
6171   (when (and gnus-auto-center-summary
6172              (not (eq gnus-auto-center-summary 'vertical)))
6173     (gnus-horizontal-recenter))
6174   (recenter n))
6175
6176 (defun gnus-summary-recenter ()
6177   "Center point in the summary window.
6178 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6179 displayed, no centering will be performed."
6180   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6181   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6182   (interactive)
6183   ;; The user has to want it.
6184   (when gnus-auto-center-summary
6185     (let* ((top (cond ((< (window-height) 4) 0)
6186                       ((< (window-height) 7) 1)
6187                       (t (if (numberp gnus-auto-center-summary)
6188                              gnus-auto-center-summary
6189                            2))))
6190            (height (1- (window-height)))
6191            (bottom (save-excursion (goto-char (point-max))
6192                                    (forward-line (- height))
6193                                    (point)))
6194            (window (get-buffer-window (current-buffer))))
6195       (when (get-buffer-window gnus-article-buffer)
6196         ;; Only do recentering when the article buffer is displayed,
6197         ;; Set the window start to either `bottom', which is the biggest
6198         ;; possible valid number, or the second line from the top,
6199         ;; whichever is the least.
6200         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6201           (if (> bottom top-pos)
6202               ;; Keep the second line from the top visible
6203               (set-window-start window top-pos t)
6204             ;; Try to keep the bottom line visible; if it's partially
6205             ;; obscured, either scroll one more line to make it fully
6206             ;; visible, or revert to using TOP-POS.
6207             (save-excursion
6208               (goto-char (point-max))
6209               (forward-line -1)
6210               (let ((last-line-start (point)))
6211                 (goto-char bottom)
6212                 (set-window-start window (point) t)
6213                 (when (not (pos-visible-in-window-p last-line-start window))
6214                   (forward-line 1)
6215                   (set-window-start window (min (point) top-pos) t)))))))
6216       ;; Do horizontal recentering while we're at it.
6217       (when (and (get-buffer-window (current-buffer) t)
6218                  (not (eq gnus-auto-center-summary 'vertical)))
6219         (let ((selected (selected-window)))
6220           (select-window (get-buffer-window (current-buffer) t))
6221           (gnus-summary-position-point)
6222           (gnus-horizontal-recenter)
6223           (select-window selected))))))
6224
6225 (defun gnus-summary-jump-to-group (newsgroup)
6226   "Move point to NEWSGROUP in group mode buffer."
6227   ;; Keep update point of group mode buffer if visible.
6228   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6229       (save-window-excursion
6230         ;; Take care of tree window mode.
6231         (when (get-buffer-window gnus-group-buffer)
6232           (pop-to-buffer gnus-group-buffer))
6233         (gnus-group-jump-to-group newsgroup))
6234     (save-excursion
6235       ;; Take care of tree window mode.
6236       (if (get-buffer-window gnus-group-buffer)
6237           (pop-to-buffer gnus-group-buffer)
6238         (set-buffer gnus-group-buffer))
6239       (gnus-group-jump-to-group newsgroup))))
6240
6241 ;; This function returns a list of article numbers based on the
6242 ;; difference between the ranges of read articles in this group and
6243 ;; the range of active articles.
6244 (defun gnus-list-of-unread-articles (group)
6245   (let* ((read (gnus-info-read (gnus-get-info group)))
6246          (active (or (gnus-active group) (gnus-activate-group group)))
6247          (last (cdr active))
6248          first nlast unread)
6249     ;; If none are read, then all are unread.
6250     (if (not read)
6251         (setq first (car active))
6252       ;; If the range of read articles is a single range, then the
6253       ;; first unread article is the article after the last read
6254       ;; article.  Sounds logical, doesn't it?
6255       (if (and (not (listp (cdr read)))
6256                (or (< (car read) (car active))
6257                    (progn (setq read (list read))
6258                           nil)))
6259           (setq first (max (car active) (1+ (cdr read))))
6260         ;; `read' is a list of ranges.
6261         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6262                                   (caar read)))
6263                   1)
6264           (setq first (car active)))
6265         (while read
6266           (when first
6267             (while (< first nlast)
6268               (push first unread)
6269               (setq first (1+ first))))
6270           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6271           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6272           (setq read (cdr read)))))
6273     ;; And add the last unread articles.
6274     (while (<= first last)
6275       (push first unread)
6276       (setq first (1+ first)))
6277     ;; Return the list of unread articles.
6278     (delq 0 (nreverse unread))))
6279
6280 (defun gnus-list-of-read-articles (group)
6281   "Return a list of unread, unticked and non-dormant articles."
6282   (let* ((info (gnus-get-info group))
6283          (marked (gnus-info-marks info))
6284          (active (gnus-active group)))
6285     (and info active
6286          (gnus-list-range-difference
6287           (gnus-list-range-difference
6288            (gnus-sorted-complement
6289             (gnus-uncompress-range active)
6290             (gnus-list-of-unread-articles group))
6291            (cdr (assq 'dormant marked)))
6292           (cdr (assq 'tick marked))))))
6293
6294 ;; Various summary commands
6295
6296 (defun gnus-summary-select-article-buffer ()
6297   "Reconfigure windows to show article buffer."
6298   (interactive)
6299   (if (not (gnus-buffer-live-p gnus-article-buffer))
6300       (error "There is no article buffer for this summary buffer")
6301     (gnus-configure-windows 'article)
6302     (select-window (get-buffer-window gnus-article-buffer))))
6303
6304 (defun gnus-summary-universal-argument (arg)
6305   "Perform any operation on all articles that are process/prefixed."
6306   (interactive "P")
6307   (let ((articles (gnus-summary-work-articles arg))
6308         func article)
6309     (if (eq
6310          (setq
6311           func
6312           (key-binding
6313            (read-key-sequence
6314             (substitute-command-keys
6315              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6316          'undefined)
6317         (gnus-error 1 "Undefined key")
6318       (save-excursion
6319         (while articles
6320           (gnus-summary-goto-subject (setq article (pop articles)))
6321           (let (gnus-newsgroup-processable)
6322             (command-execute func))
6323           (gnus-summary-remove-process-mark article)))))
6324   (gnus-summary-position-point))
6325
6326 (defun gnus-summary-toggle-truncation (&optional arg)
6327   "Toggle truncation of summary lines.
6328 With arg, turn line truncation on if arg is positive."
6329   (interactive "P")
6330   (setq truncate-lines
6331         (if (null arg) (not truncate-lines)
6332           (> (prefix-numeric-value arg) 0)))
6333   (redraw-display))
6334
6335 (defun gnus-summary-find-for-reselect ()
6336   "Return the number of an article to stay on across a reselect.
6337 The current article is considered, then following articles, then previous
6338 articles.  An article is sought which is not cancelled and isn't a temporary
6339 insertion from another group.  If there's no such then return a dummy 0."
6340   (let (found)
6341     (dolist (rev '(nil t))
6342       (unless found      ; don't demand the reverse list if we don't need it
6343         (let ((data (gnus-data-find-list
6344                      (gnus-summary-article-number) (gnus-data-list rev))))
6345           (while (and data (not found))
6346             (if (and (< 0 (gnus-data-number (car data)))
6347                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6348                 (setq found (gnus-data-number (car data))))
6349             (setq data (cdr data))))))
6350     (or found 0)))
6351
6352 (defun gnus-summary-reselect-current-group (&optional all rescan)
6353   "Exit and then reselect the current newsgroup.
6354 The prefix argument ALL means to select all articles."
6355   (interactive "P")
6356   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6357     (error "Ephemeral groups can't be reselected"))
6358   (let ((current-subject (gnus-summary-find-for-reselect))
6359         (group gnus-newsgroup-name))
6360     (setq gnus-newsgroup-begin nil)
6361     (gnus-summary-exit)
6362     ;; We have to adjust the point of group mode buffer because
6363     ;; point was moved to the next unread newsgroup by exiting.
6364     (gnus-summary-jump-to-group group)
6365     (when rescan
6366       (save-excursion
6367         (save-window-excursion
6368           ;; Don't show group contents.
6369           (set-window-start (selected-window) (point-max))
6370           (gnus-group-get-new-news-this-group 1))))
6371     (gnus-group-read-group all t)
6372     (gnus-summary-goto-subject current-subject nil t)))
6373
6374 (defun gnus-summary-rescan-group (&optional all)
6375   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6376   (interactive "P")
6377   (gnus-summary-reselect-current-group all t))
6378
6379 (defun gnus-summary-update-info (&optional non-destructive)
6380   (save-excursion
6381     (let ((group gnus-newsgroup-name))
6382       (when group
6383         (when gnus-newsgroup-kill-headers
6384           (setq gnus-newsgroup-killed
6385                 (gnus-compress-sequence
6386                  (gnus-sorted-union
6387                   (gnus-list-range-intersection
6388                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6389                   gnus-newsgroup-unreads)
6390                  t)))
6391         (unless (listp (cdr gnus-newsgroup-killed))
6392           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6393         (let ((headers gnus-newsgroup-headers))
6394           ;; Set the new ranges of read articles.
6395           (save-excursion
6396             (set-buffer gnus-group-buffer)
6397             (gnus-undo-force-boundary))
6398           (gnus-update-read-articles
6399            group (gnus-sorted-union
6400                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6401           ;; Set the current article marks.
6402           (let ((gnus-newsgroup-scored
6403                  (if (and (not gnus-save-score)
6404                           (not non-destructive))
6405                      nil
6406                    gnus-newsgroup-scored)))
6407             (save-excursion
6408               (gnus-update-marks)))
6409           ;; Do the cross-ref thing.
6410           (when gnus-use-cross-reference
6411             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6412           ;; Do not switch windows but change the buffer to work.
6413           (set-buffer gnus-group-buffer)
6414           (unless (gnus-ephemeral-group-p group)
6415             (gnus-group-update-group group)))))))
6416
6417 (defun gnus-summary-save-newsrc (&optional force)
6418   "Save the current number of read/marked articles in the dribble buffer.
6419 The dribble buffer will then be saved.
6420 If FORCE (the prefix), also save the .newsrc file(s)."
6421   (interactive "P")
6422   (gnus-summary-update-info t)
6423   (if force
6424       (gnus-save-newsrc-file)
6425     (gnus-dribble-save)))
6426
6427 (defun gnus-summary-exit (&optional temporary)
6428   "Exit reading current newsgroup, and then return to group selection mode.
6429 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6430   (interactive)
6431   (gnus-set-global-variables)
6432   (gnus-kill-save-kill-buffer)
6433   (gnus-async-halt-prefetch)
6434   (let* ((group gnus-newsgroup-name)
6435          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6436          (gnus-group-is-exiting-p t)
6437          (mode major-mode)
6438          (group-point nil)
6439          (buf (current-buffer)))
6440     (unless quit-config
6441       ;; Do adaptive scoring, and possibly save score files.
6442       (when gnus-newsgroup-adaptive
6443         (gnus-score-adaptive))
6444       (when gnus-use-scoring
6445         (gnus-score-save)))
6446     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6447     ;; If we have several article buffers, we kill them at exit.
6448     (unless gnus-single-article-buffer
6449       (gnus-kill-buffer gnus-original-article-buffer)
6450       (setq gnus-article-current nil))
6451     (when gnus-use-cache
6452       (gnus-cache-possibly-remove-articles)
6453       (gnus-cache-save-buffers))
6454     (gnus-async-prefetch-remove-group group)
6455     (when gnus-suppress-duplicates
6456       (gnus-dup-enter-articles))
6457     (when gnus-use-trees
6458       (gnus-tree-close group))
6459     (when gnus-use-cache
6460       (gnus-cache-write-active))
6461     ;; Remove entries for this group.
6462     (nnmail-purge-split-history (gnus-group-real-name group))
6463     ;; Make all changes in this group permanent.
6464     (unless quit-config
6465       (gnus-run-hooks 'gnus-exit-group-hook)
6466       (gnus-summary-update-info))
6467     (gnus-close-group group)
6468     ;; Make sure where we were, and go to next newsgroup.
6469     (set-buffer gnus-group-buffer)
6470     (unless quit-config
6471       (gnus-group-jump-to-group group))
6472     (gnus-run-hooks 'gnus-summary-exit-hook)
6473     (unless (or quit-config
6474                 ;; If this group has disappeared from the summary
6475                 ;; buffer, don't skip forwards.
6476                 (not (string= group (gnus-group-group-name))))
6477       (gnus-group-next-unread-group 1))
6478     (setq group-point (point))
6479     (if temporary
6480         nil                             ;Nothing to do.
6481       ;; If we have several article buffers, we kill them at exit.
6482       (unless gnus-single-article-buffer
6483         (gnus-kill-buffer gnus-article-buffer)
6484         (gnus-kill-buffer gnus-original-article-buffer)
6485         (setq gnus-article-current nil))
6486       (set-buffer buf)
6487       (if (not gnus-kill-summary-on-exit)
6488           (progn
6489             (gnus-deaden-summary)
6490             (setq mode nil))
6491         ;; We set all buffer-local variables to nil.  It is unclear why
6492         ;; this is needed, but if we don't, buffer-local variables are
6493         ;; not garbage-collected, it seems.  This would the lead to en
6494         ;; ever-growing Emacs.
6495         (gnus-summary-clear-local-variables)
6496         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6497           (gnus-summary-clear-local-variables))
6498         (when (get-buffer gnus-article-buffer)
6499           (bury-buffer gnus-article-buffer))
6500         ;; We clear the global counterparts of the buffer-local
6501         ;; variables as well, just to be on the safe side.
6502         (set-buffer gnus-group-buffer)
6503         (gnus-summary-clear-local-variables)
6504         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6505           (gnus-summary-clear-local-variables))
6506         ;; Return to group mode buffer.
6507         (when (eq mode 'gnus-summary-mode)
6508           (gnus-kill-buffer buf)))
6509       (setq gnus-current-select-method gnus-select-method)
6510       (pop-to-buffer gnus-group-buffer)
6511       (if (not quit-config)
6512           (progn
6513             (goto-char group-point)
6514             (gnus-configure-windows 'group 'force)
6515             (unless (pos-visible-in-window-p)
6516               (forward-line (/ (static-if (featurep 'xemacs)
6517                                    (window-displayed-height)
6518                                  (1- (window-height)))
6519                                -2))
6520               (set-window-start (selected-window) (point))
6521               (goto-char group-point)))
6522         (gnus-handle-ephemeral-exit quit-config))
6523       ;; Clear the current group name.
6524       (unless quit-config
6525         (setq gnus-newsgroup-name nil)))))
6526
6527 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6528 (defun gnus-summary-exit-no-update (&optional no-questions)
6529   "Quit reading current newsgroup without updating read article info."
6530   (interactive)
6531   (let* ((group gnus-newsgroup-name)
6532          (gnus-group-is-exiting-p t)
6533          (gnus-group-is-exiting-without-update-p t)
6534          (quit-config (gnus-group-quit-config group)))
6535     (when (or no-questions
6536               gnus-expert-user
6537               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6538       (gnus-async-halt-prefetch)
6539       (run-hooks 'gnus-summary-prepare-exit-hook)
6540       ;; If we have several article buffers, we kill them at exit.
6541       (unless gnus-single-article-buffer
6542         (gnus-kill-buffer gnus-article-buffer)
6543         (gnus-kill-buffer gnus-original-article-buffer)
6544         (setq gnus-article-current nil))
6545       (if (not gnus-kill-summary-on-exit)
6546           (gnus-deaden-summary)
6547         (gnus-close-group group)
6548         (gnus-summary-clear-local-variables)
6549         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6550           (gnus-summary-clear-local-variables))
6551         (set-buffer gnus-group-buffer)
6552         (gnus-summary-clear-local-variables)
6553         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6554           (gnus-summary-clear-local-variables))
6555         (gnus-kill-buffer gnus-summary-buffer))
6556       (unless gnus-single-article-buffer
6557         (setq gnus-article-current nil))
6558       (when gnus-use-trees
6559         (gnus-tree-close group))
6560       (gnus-async-prefetch-remove-group group)
6561       (when (get-buffer gnus-article-buffer)
6562         (bury-buffer gnus-article-buffer))
6563       ;; Return to the group buffer.
6564       (gnus-configure-windows 'group 'force)
6565       ;; Clear the current group name.
6566       (setq gnus-newsgroup-name nil)
6567       (unless (gnus-ephemeral-group-p group)
6568         (gnus-group-update-group group))
6569       (when (equal (gnus-group-group-name) group)
6570         (gnus-group-next-unread-group 1))
6571       (when quit-config
6572         (gnus-handle-ephemeral-exit quit-config)))))
6573
6574 (defun gnus-handle-ephemeral-exit (quit-config)
6575   "Handle movement when leaving an ephemeral group.
6576 The state which existed when entering the ephemeral is reset."
6577   (if (not (buffer-name (car quit-config)))
6578       (gnus-configure-windows 'group 'force)
6579     (set-buffer (car quit-config))
6580     (cond ((eq major-mode 'gnus-summary-mode)
6581            (gnus-set-global-variables))
6582           ((eq major-mode 'gnus-article-mode)
6583            (save-excursion
6584              ;; The `gnus-summary-buffer' variable may point
6585              ;; to the old summary buffer when using a single
6586              ;; article buffer.
6587              (unless (gnus-buffer-live-p gnus-summary-buffer)
6588                (set-buffer gnus-group-buffer))
6589              (set-buffer gnus-summary-buffer)
6590              (gnus-set-global-variables))))
6591     (if (or (eq (cdr quit-config) 'article)
6592             (eq (cdr quit-config) 'pick))
6593         (progn
6594           ;; The current article may be from the ephemeral group
6595           ;; thus it is best that we reload this article
6596           (gnus-summary-show-article)
6597           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6598               (gnus-configure-windows 'pick 'force)
6599             (gnus-configure-windows (cdr quit-config) 'force)))
6600       (gnus-configure-windows (cdr quit-config) 'force))
6601     (when (eq major-mode 'gnus-summary-mode)
6602       (gnus-summary-next-subject 1 nil t)
6603       (gnus-summary-recenter)
6604       (gnus-summary-position-point))))
6605
6606 (defun gnus-summary-preview-mime-message ()
6607   "MIME decode and play this message."
6608   (interactive)
6609   (let ((gnus-break-pages nil)
6610         (gnus-show-mime t))
6611     (gnus-summary-select-article gnus-show-all-headers t))
6612   (let ((w (get-buffer-window gnus-article-buffer)))
6613     (when w
6614       (select-window (get-buffer-window gnus-article-buffer)))))
6615
6616 ;;; Dead summaries.
6617
6618 (defvar gnus-dead-summary-mode-map nil)
6619
6620 (unless gnus-dead-summary-mode-map
6621   (setq gnus-dead-summary-mode-map (make-keymap))
6622   (suppress-keymap gnus-dead-summary-mode-map)
6623   (substitute-key-definition
6624    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6625   (dolist (key '("\C-d" "\r" "\177" [delete]))
6626     (define-key gnus-dead-summary-mode-map
6627       key 'gnus-summary-wake-up-the-dead))
6628   (dolist (key '("q" "Q"))
6629     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6630
6631 (defvar gnus-dead-summary-mode nil
6632   "Minor mode for Gnus summary buffers.")
6633
6634 (defun gnus-dead-summary-mode (&optional arg)
6635   "Minor mode for Gnus summary buffers."
6636   (interactive "P")
6637   (when (eq major-mode 'gnus-summary-mode)
6638     (make-local-variable 'gnus-dead-summary-mode)
6639     (setq gnus-dead-summary-mode
6640           (if (null arg) (not gnus-dead-summary-mode)
6641             (> (prefix-numeric-value arg) 0)))
6642     (when gnus-dead-summary-mode
6643       (gnus-add-minor-mode
6644        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6645
6646 (defun gnus-deaden-summary ()
6647   "Make the current summary buffer into a dead summary buffer."
6648   ;; Kill any previous dead summary buffer.
6649   (when (and gnus-dead-summary
6650              (buffer-name gnus-dead-summary))
6651     (save-excursion
6652       (set-buffer gnus-dead-summary)
6653       (when gnus-dead-summary-mode
6654         (kill-buffer (current-buffer)))))
6655   ;; Make this the current dead summary.
6656   (setq gnus-dead-summary (current-buffer))
6657   (gnus-dead-summary-mode 1)
6658   (let ((name (buffer-name)))
6659     (when (string-match "Summary" name)
6660       (rename-buffer
6661        (concat (substring name 0 (match-beginning 0)) "Dead "
6662                (substring name (match-beginning 0)))
6663        t)
6664       (bury-buffer))))
6665
6666 (defun gnus-kill-or-deaden-summary (buffer)
6667   "Kill or deaden the summary BUFFER."
6668   (save-excursion
6669     (when (and (buffer-name buffer)
6670                (not gnus-single-article-buffer))
6671       (save-excursion
6672         (set-buffer buffer)
6673         (gnus-kill-buffer gnus-article-buffer)
6674         (gnus-kill-buffer gnus-original-article-buffer)))
6675     (cond
6676      ;; Kill the buffer.
6677      (gnus-kill-summary-on-exit
6678       (when (and gnus-use-trees
6679                  (gnus-buffer-exists-p buffer))
6680         (save-excursion
6681           (set-buffer buffer)
6682           (gnus-tree-close gnus-newsgroup-name)))
6683       (gnus-kill-buffer buffer))
6684      ;; Deaden the buffer.
6685      ((gnus-buffer-exists-p buffer)
6686       (save-excursion
6687         (set-buffer buffer)
6688         (gnus-deaden-summary))))))
6689
6690 (defun gnus-summary-wake-up-the-dead (&rest args)
6691   "Wake up the dead summary buffer."
6692   (interactive)
6693   (gnus-dead-summary-mode -1)
6694   (let ((name (buffer-name)))
6695     (when (string-match "Dead " name)
6696       (rename-buffer
6697        (concat (substring name 0 (match-beginning 0))
6698                (substring name (match-end 0)))
6699        t)))
6700   (gnus-message 3 "This dead summary is now alive again"))
6701
6702 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6703 (defun gnus-summary-fetch-faq (&optional faq-dir)
6704   "Fetch the FAQ for the current group.
6705 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6706 in."
6707   (interactive
6708    (list
6709     (when current-prefix-arg
6710       (completing-read
6711        "FAQ dir: " (and (listp gnus-group-faq-directory)
6712                         (mapcar (lambda (file) (list file))
6713                                 gnus-group-faq-directory))))))
6714   (let (gnus-faq-buffer)
6715     (when (setq gnus-faq-buffer
6716                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6717       (gnus-configure-windows 'summary-faq))))
6718
6719 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6720 (defun gnus-summary-describe-group (&optional force)
6721   "Describe the current newsgroup."
6722   (interactive "P")
6723   (gnus-group-describe-group force gnus-newsgroup-name))
6724
6725 (defun gnus-summary-describe-briefly ()
6726   "Describe summary mode commands briefly."
6727   (interactive)
6728   (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info        \\[gnus-summary-describe-briefly]:This help")))
6729
6730 ;; Walking around group mode buffer from summary mode.
6731
6732 (defun gnus-summary-next-group (&optional no-article target-group backward)
6733   "Exit current newsgroup and then select next unread newsgroup.
6734 If prefix argument NO-ARTICLE is non-nil, no article is selected
6735 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6736 previous group instead."
6737   (interactive "P")
6738   ;; Stop pre-fetching.
6739   (gnus-async-halt-prefetch)
6740   (let ((current-group gnus-newsgroup-name)
6741         (current-buffer (current-buffer))
6742         entered)
6743     ;; First we semi-exit this group to update Xrefs and all variables.
6744     ;; We can't do a real exit, because the window conf must remain
6745     ;; the same in case the user is prompted for info, and we don't
6746     ;; want the window conf to change before that...
6747     (gnus-summary-exit t)
6748     (while (not entered)
6749       ;; Then we find what group we are supposed to enter.
6750       (set-buffer gnus-group-buffer)
6751       (gnus-group-jump-to-group current-group)
6752       (setq target-group
6753             (or target-group
6754                 (if (eq gnus-keep-same-level 'best)
6755                     (gnus-summary-best-group gnus-newsgroup-name)
6756                   (gnus-summary-search-group backward gnus-keep-same-level))))
6757       (if (not target-group)
6758           ;; There are no further groups, so we return to the group
6759           ;; buffer.
6760           (progn
6761             (gnus-message 5 "Returning to the group buffer")
6762             (setq entered t)
6763             (when (gnus-buffer-live-p current-buffer)
6764               (set-buffer current-buffer)
6765               (gnus-summary-exit))
6766             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6767         ;; We try to enter the target group.
6768         (gnus-group-jump-to-group target-group)
6769         (let ((unreads (gnus-group-group-unread)))
6770           (if (and (or (eq t unreads)
6771                        (and unreads (not (zerop unreads))))
6772                    (gnus-summary-read-group
6773                     target-group nil no-article
6774                     (and (buffer-name current-buffer) current-buffer)
6775                     nil backward))
6776               (setq entered t)
6777             (setq current-group target-group
6778                   target-group nil)))))))
6779
6780 (defun gnus-summary-prev-group (&optional no-article)
6781   "Exit current newsgroup and then select previous unread newsgroup.
6782 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6783   (interactive "P")
6784   (gnus-summary-next-group no-article nil t))
6785
6786 ;; Walking around summary lines.
6787
6788 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6789   "Go to the first subject satisfying any non-nil constraint.
6790 If UNREAD is non-nil, the article should be unread.
6791 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6792 If UNSEED is non-nil, the article should be unseen.
6793 Returns the article selected or nil if there are no matching articles."
6794   (interactive "P")
6795   (cond
6796    ;; Empty summary.
6797    ((null gnus-newsgroup-data)
6798     (gnus-message 3 "No articles in the group")
6799     nil)
6800    ;; Pick the first article.
6801    ((not (or unread undownloaded unseen))
6802     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6803     (gnus-data-number (car gnus-newsgroup-data)))
6804    ;; Find the first unread article.
6805    (t
6806     (let ((data gnus-newsgroup-data))
6807       (while (and data
6808                   (let ((num (gnus-data-number (car data))))
6809                     (or (memq num gnus-newsgroup-unfetched)
6810                         (not (or (and unread
6811                                       (memq num gnus-newsgroup-unreads))
6812                                  (and undownloaded
6813                                       (memq num gnus-newsgroup-undownloaded))
6814                                  (and unseen
6815                                       (memq num gnus-newsgroup-unseen)))))))
6816         (setq data (cdr data)))
6817       (prog1 
6818           (if data
6819               (progn
6820                 (goto-char (gnus-data-pos (car data)))
6821                 (gnus-data-number (car data)))
6822             (gnus-message 3 "No more%s articles"
6823                           (let* ((r (when unread " unread"))
6824                                  (d (when undownloaded " undownloaded"))
6825                                  (s (when unseen " unseen"))
6826                                  (l (delq nil (list r d s))))
6827                             (cond ((= 3 (length l))
6828                                    (concat r "," d ", or" s))
6829                                   ((= 2 (length l))
6830                                    (concat (car l) ", or" (cadr l)))
6831                                   ((= 1 (length l))
6832                                    (car l))
6833                                   (t
6834                                    ""))))
6835             nil
6836             )
6837         (gnus-summary-position-point))))))
6838
6839 (defun gnus-summary-next-subject (n &optional unread dont-display)
6840   "Go to next N'th summary line.
6841 If N is negative, go to the previous N'th subject line.
6842 If UNREAD is non-nil, only unread articles are selected.
6843 The difference between N and the actual number of steps taken is
6844 returned."
6845   (interactive "p")
6846   (let ((backward (< n 0))
6847         (n (abs n)))
6848     (while (and (> n 0)
6849                 (if backward
6850                     (gnus-summary-find-prev unread)
6851                   (gnus-summary-find-next unread)))
6852       (unless (zerop (setq n (1- n)))
6853         (gnus-summary-show-thread)))
6854     (when (/= 0 n)
6855       (gnus-message 7 "No more%s articles"
6856                     (if unread " unread" "")))
6857     (unless dont-display
6858       (gnus-summary-recenter)
6859       (gnus-summary-position-point))
6860     n))
6861
6862 (defun gnus-summary-next-unread-subject (n)
6863   "Go to next N'th unread summary line."
6864   (interactive "p")
6865   (gnus-summary-next-subject n t))
6866
6867 (defun gnus-summary-prev-subject (n &optional unread)
6868   "Go to previous N'th summary line.
6869 If optional argument UNREAD is non-nil, only unread article is selected."
6870   (interactive "p")
6871   (gnus-summary-next-subject (- n) unread))
6872
6873 (defun gnus-summary-prev-unread-subject (n)
6874   "Go to previous N'th unread summary line."
6875   (interactive "p")
6876   (gnus-summary-next-subject (- n) t))
6877
6878 (defun gnus-summary-goto-subjects (articles)
6879   "Insert the subject header for ARTICLES in the current buffer."
6880   (save-excursion
6881     (dolist (article articles)
6882       (gnus-summary-goto-subject article t)))
6883   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6884   (gnus-summary-position-point))
6885  
6886 (defun gnus-summary-goto-subject (article &optional force silent)
6887   "Go the subject line of ARTICLE.
6888 If FORCE, also allow jumping to articles not currently shown."
6889   (interactive "nArticle number: ")
6890   (unless (numberp article)
6891     (error "Article %s is not a number" article))
6892   (let ((b (point))
6893         (data (gnus-data-find article)))
6894     ;; We read in the article if we have to.
6895     (and (not data)
6896          force
6897          (gnus-summary-insert-subject
6898           article
6899           (if (or (numberp force) (vectorp force)) force)
6900           t)
6901          (setq data (gnus-data-find article)))
6902     (goto-char b)
6903     (if (not data)
6904         (progn
6905           (unless silent
6906             (gnus-message 3 "Can't find article %d" article))
6907           nil)
6908       (let ((pt (gnus-data-pos data)))
6909         (goto-char pt)
6910         (gnus-summary-set-article-display-arrow pt))
6911       (gnus-summary-position-point)
6912       article)))
6913
6914 ;; Walking around summary lines with displaying articles.
6915
6916 (defun gnus-summary-expand-window (&optional arg)
6917   "Make the summary buffer take up the entire Emacs frame.
6918 Given a prefix, will force an `article' buffer configuration."
6919   (interactive "P")
6920   (if arg
6921       (gnus-configure-windows 'article 'force)
6922     (gnus-configure-windows 'summary 'force)))
6923
6924 (defun gnus-summary-display-article (article &optional all-header)
6925   "Display ARTICLE in article buffer."
6926   (when (gnus-buffer-live-p gnus-article-buffer)
6927     (with-current-buffer gnus-article-buffer
6928       (set-buffer-multibyte t)))
6929   (gnus-set-global-variables)
6930   (when (gnus-buffer-live-p gnus-article-buffer)
6931     (with-current-buffer gnus-article-buffer
6932       (setq gnus-article-charset gnus-newsgroup-charset)
6933       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6934       (set-buffer-multibyte t)))
6935   (if (null article)
6936       nil
6937     (prog1
6938         (if gnus-summary-display-article-function
6939             (funcall gnus-summary-display-article-function article all-header)
6940           (gnus-article-prepare article all-header))
6941       (with-current-buffer gnus-article-buffer
6942         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6943              nil))
6944       (gnus-run-hooks 'gnus-select-article-hook)
6945       (when (and gnus-current-article
6946                  (not (zerop gnus-current-article)))
6947         (gnus-summary-goto-subject gnus-current-article))
6948       (gnus-summary-recenter)
6949       (when (and gnus-use-trees gnus-show-threads)
6950         (gnus-possibly-generate-tree article)
6951         (gnus-highlight-selected-tree article))
6952       ;; Successfully display article.
6953       (gnus-article-set-window-start
6954        (cdr (assq article gnus-newsgroup-bookmarks))))))
6955
6956 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6957   "Select the current article.
6958 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6959 non-nil, the article will be re-fetched even if it already present in
6960 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6961 be displayed."
6962   ;; Make sure we are in the summary buffer to work around bbdb bug.
6963   (unless (eq major-mode 'gnus-summary-mode)
6964     (set-buffer gnus-summary-buffer))
6965   (let ((article (or article (gnus-summary-article-number)))
6966         (all-headers (not (not all-headers))) ;Must be T or NIL.
6967         gnus-summary-display-article-function)
6968     (and (not pseudo)
6969          (gnus-summary-article-pseudo-p article)
6970          (error "This is a pseudo-article"))
6971     (save-excursion
6972       (set-buffer gnus-summary-buffer)
6973       (if (or (and gnus-single-article-buffer
6974                    (or (null gnus-current-article)
6975                        (null gnus-article-current)
6976                        (null (get-buffer gnus-article-buffer))
6977                        (not (eq article (cdr gnus-article-current)))
6978                        (not (equal (car gnus-article-current)
6979                                    gnus-newsgroup-name))))
6980               (and (not gnus-single-article-buffer)
6981                    (or (null gnus-current-article)
6982                        (not (eq gnus-current-article article))))
6983               force)
6984           ;; The requested article is different from the current article.
6985           (progn
6986             (gnus-summary-display-article article all-headers)
6987             (gnus-article-set-window-start
6988              (cdr (assq article gnus-newsgroup-bookmarks)))
6989             article)
6990         'old))))
6991
6992 (defun gnus-summary-force-verify-and-decrypt ()
6993   "Display buttons for signed/encrypted parts and verify/decrypt them."
6994   (interactive)
6995   (let ((mm-verify-option 'known)
6996         (mm-decrypt-option 'known)
6997         (gnus-buttonized-mime-types (append (list "multipart/signed"
6998                                                   "multipart/encrypted")
6999                                             gnus-buttonized-mime-types)))
7000     (gnus-summary-select-article nil 'force)))
7001
7002 (defun gnus-summary-set-current-mark (&optional current-mark)
7003   "Obsolete function."
7004   nil)
7005
7006 (defun gnus-summary-next-article (&optional unread subject backward push)
7007   "Select the next article.
7008 If UNREAD, only unread articles are selected.
7009 If SUBJECT, only articles with SUBJECT are selected.
7010 If BACKWARD, the previous article is selected instead of the next."
7011   (interactive "P")
7012   (cond
7013    ;; Is there such an article?
7014    ((and (gnus-summary-search-forward unread subject backward)
7015          (or (gnus-summary-display-article (gnus-summary-article-number))
7016              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7017     (gnus-summary-position-point))
7018    ;; If not, we try the first unread, if that is wanted.
7019    ((and subject
7020          gnus-auto-select-same
7021          (gnus-summary-first-unread-article))
7022     (gnus-summary-position-point)
7023     (gnus-message 6 "Wrapped"))
7024    ;; Try to get next/previous article not displayed in this group.
7025    ((and gnus-auto-extend-newsgroup
7026          (not unread) (not subject))
7027     (gnus-summary-goto-article
7028      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7029      nil (count-lines (point-min) (point))))
7030    ;; Go to next/previous group.
7031    (t
7032     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7033       (gnus-summary-jump-to-group gnus-newsgroup-name))
7034     (let ((cmd last-command-char)
7035           (point
7036            (save-excursion
7037              (set-buffer gnus-group-buffer)
7038              (point)))
7039           (group
7040            (if (eq gnus-keep-same-level 'best)
7041                (gnus-summary-best-group gnus-newsgroup-name)
7042              (gnus-summary-search-group backward gnus-keep-same-level))))
7043       ;; For some reason, the group window gets selected.  We change
7044       ;; it back.
7045       (select-window (get-buffer-window (current-buffer)))
7046       ;; Select next unread newsgroup automagically.
7047       (cond
7048        ((or (not gnus-auto-select-next)
7049             (not cmd))
7050         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7051        ((or (eq gnus-auto-select-next 'quietly)
7052             (and (eq gnus-auto-select-next 'slightly-quietly)
7053                  push)
7054             (and (eq gnus-auto-select-next 'almost-quietly)
7055                  (gnus-summary-last-article-p)))
7056         ;; Select quietly.
7057         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7058             (gnus-summary-exit)
7059           (gnus-message 7 "No more%s articles (%s)..."
7060                         (if unread " unread" "")
7061                         (if group (concat "selecting " group)
7062                           "exiting"))
7063           (gnus-summary-next-group nil group backward)))
7064        (t
7065         (when (gnus-key-press-event-p last-input-event)
7066           (gnus-summary-walk-group-buffer
7067            gnus-newsgroup-name cmd unread backward point))))))))
7068
7069 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7070   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7071                       (?\C-p (gnus-group-prev-unread-group 1))))
7072         (cursor-in-echo-area t)
7073         keve key group ended prompt)
7074     (save-excursion
7075       (set-buffer gnus-group-buffer)
7076       (goto-char start)
7077       (setq group
7078             (if (eq gnus-keep-same-level 'best)
7079                 (gnus-summary-best-group gnus-newsgroup-name)
7080               (gnus-summary-search-group backward gnus-keep-same-level))))
7081     (while (not ended)
7082       (setq prompt
7083             (format
7084              "No more%s articles%s " (if unread " unread" "")
7085              (if (and group
7086                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7087                  (format " (Type %s for %s [%s])"
7088                          (single-key-description cmd) group
7089                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7090                (format " (Type %s to exit %s)"
7091                        (single-key-description cmd)
7092                        gnus-newsgroup-name))))
7093       ;; Confirm auto selection.
7094       (setq key (car (setq keve (gnus-read-event-char prompt)))
7095             ended t)
7096       (cond
7097        ((assq key keystrokes)
7098         (let ((obuf (current-buffer)))
7099           (switch-to-buffer gnus-group-buffer)
7100           (when group
7101             (gnus-group-jump-to-group group))
7102           (eval (cadr (assq key keystrokes)))
7103           (setq group (gnus-group-group-name))
7104           (switch-to-buffer obuf))
7105         (setq ended nil))
7106        ((equal key cmd)
7107         (if (or (not group)
7108                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7109             (gnus-summary-exit)
7110           (gnus-summary-next-group nil group backward)))
7111        (t
7112         (push (cdr keve) unread-command-events))))))
7113
7114 (defun gnus-summary-next-unread-article ()
7115   "Select unread article after current one."
7116   (interactive)
7117   (gnus-summary-next-article
7118    (or (not (eq gnus-summary-goto-unread 'never))
7119        (gnus-summary-last-article-p (gnus-summary-article-number)))
7120    (and gnus-auto-select-same
7121         (gnus-summary-article-subject))))
7122
7123 (defun gnus-summary-prev-article (&optional unread subject)
7124   "Select the article after the current one.
7125 If UNREAD is non-nil, only unread articles are selected."
7126   (interactive "P")
7127   (gnus-summary-next-article unread subject t))
7128
7129 (defun gnus-summary-prev-unread-article ()
7130   "Select unread article before current one."
7131   (interactive)
7132   (gnus-summary-prev-article
7133    (or (not (eq gnus-summary-goto-unread 'never))
7134        (gnus-summary-first-article-p (gnus-summary-article-number)))
7135    (and gnus-auto-select-same
7136         (gnus-summary-article-subject))))
7137
7138 (defun gnus-summary-next-page (&optional lines circular stop)
7139   "Show next page of the selected article.
7140 If at the end of the current article, select the next article.
7141 LINES says how many lines should be scrolled up.
7142
7143 If CIRCULAR is non-nil, go to the start of the article instead of
7144 selecting the next article when reaching the end of the current
7145 article.
7146
7147 If STOP is non-nil, just stop when reaching the end of the message."
7148   (interactive "P")
7149   (setq gnus-summary-buffer (current-buffer))
7150   (gnus-set-global-variables)
7151   (let ((article (gnus-summary-article-number))
7152         (article-window (get-buffer-window gnus-article-buffer t))
7153         endp)
7154     ;; If the buffer is empty, we have no article.
7155     (unless article
7156       (error "No article to select"))
7157     (gnus-configure-windows 'article)
7158     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7159         (if (and (eq gnus-summary-goto-unread 'never)
7160                  (not (gnus-summary-last-article-p article)))
7161             (gnus-summary-next-article)
7162           (gnus-summary-next-unread-article))
7163       (if (or (null gnus-current-article)
7164               (null gnus-article-current)
7165               (/= article (cdr gnus-article-current))
7166               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7167           ;; Selected subject is different from current article's.
7168           (gnus-summary-display-article article)
7169         (when article-window
7170           (gnus-eval-in-buffer-window gnus-article-buffer
7171             (setq endp (or (gnus-article-next-page lines)
7172                            (gnus-article-only-boring-p))))
7173           (when endp
7174             (cond (stop
7175                    (gnus-message 3 "End of message"))
7176                   (circular
7177                    (gnus-summary-beginning-of-article))
7178                   (lines
7179                    (gnus-message 3 "End of message"))
7180                   ((null lines)
7181                    (if (and (eq gnus-summary-goto-unread 'never)
7182                             (not (gnus-summary-last-article-p article)))
7183                        (gnus-summary-next-article)
7184                      (gnus-summary-next-unread-article))))))))
7185     (gnus-summary-recenter)
7186     (gnus-summary-position-point)))
7187
7188 (defun gnus-summary-prev-page (&optional lines move)
7189   "Show previous page of selected article.
7190 Argument LINES specifies lines to be scrolled down.
7191 If MOVE, move to the previous unread article if point is at
7192 the beginning of the buffer."
7193   (interactive "P")
7194   (let ((article (gnus-summary-article-number))
7195         (article-window (get-buffer-window gnus-article-buffer t))
7196         endp)
7197     (gnus-configure-windows 'article)
7198     (if (or (null gnus-current-article)
7199             (null gnus-article-current)
7200             (/= article (cdr gnus-article-current))
7201             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7202         ;; Selected subject is different from current article's.
7203         (gnus-summary-display-article article)
7204       (gnus-summary-recenter)
7205       (when article-window
7206         (gnus-eval-in-buffer-window gnus-article-buffer
7207           (setq endp (gnus-article-prev-page lines)))
7208         (when (and move endp)
7209           (cond (lines
7210                  (gnus-message 3 "Beginning of message"))
7211                 ((null lines)
7212                  (if (and (eq gnus-summary-goto-unread 'never)
7213                           (not (gnus-summary-first-article-p article)))
7214                      (gnus-summary-prev-article)
7215                    (gnus-summary-prev-unread-article))))))))
7216   (gnus-summary-position-point))
7217
7218 (defun gnus-summary-prev-page-or-article (&optional lines)
7219   "Show previous page of selected article.
7220 Argument LINES specifies lines to be scrolled down.
7221 If at the beginning of the article, go to the next article."
7222   (interactive "P")
7223   (gnus-summary-prev-page lines t))
7224
7225 (defun gnus-summary-scroll-up (lines)
7226   "Scroll up (or down) one line current article.
7227 Argument LINES specifies lines to be scrolled up (or down if negative)."
7228   (interactive "p")
7229   (gnus-configure-windows 'article)
7230   (gnus-summary-show-thread)
7231   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7232     (gnus-eval-in-buffer-window gnus-article-buffer
7233       (cond ((> lines 0)
7234              (when (gnus-article-next-page lines)
7235                (gnus-message 3 "End of message")))
7236             ((< lines 0)
7237              (gnus-article-prev-page (- lines))))))
7238   (gnus-summary-recenter)
7239   (gnus-summary-position-point))
7240
7241 (defun gnus-summary-scroll-down (lines)
7242   "Scroll down (or up) one line current article.
7243 Argument LINES specifies lines to be scrolled down (or up if negative)."
7244   (interactive "p")
7245   (gnus-summary-scroll-up (- lines)))
7246
7247 (defun gnus-summary-next-same-subject ()
7248   "Select next article which has the same subject as current one."
7249   (interactive)
7250   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7251
7252 (defun gnus-summary-prev-same-subject ()
7253   "Select previous article which has the same subject as current one."
7254   (interactive)
7255   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7256
7257 (defun gnus-summary-next-unread-same-subject ()
7258   "Select next unread article which has the same subject as current one."
7259   (interactive)
7260   (gnus-summary-next-article t (gnus-summary-article-subject)))
7261
7262 (defun gnus-summary-prev-unread-same-subject ()
7263   "Select previous unread article which has the same subject as current one."
7264   (interactive)
7265   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7266
7267 (defun gnus-summary-first-unread-article ()
7268   "Select the first unread article.
7269 Return nil if there are no unread articles."
7270   (interactive)
7271   (prog1
7272       (when (gnus-summary-first-subject t)
7273         (gnus-summary-show-thread)
7274         (gnus-summary-first-subject t)
7275         (gnus-summary-display-article (gnus-summary-article-number)))
7276     (gnus-summary-position-point)))
7277
7278 (defun gnus-summary-first-unread-subject ()
7279   "Place the point on the subject line of the first unread article.
7280 Return nil if there are no unread articles."
7281   (interactive)
7282   (prog1
7283       (when (gnus-summary-first-subject t)
7284         (gnus-summary-show-thread)
7285         (gnus-summary-first-subject t))
7286     (gnus-summary-position-point)))
7287
7288 (defun gnus-summary-first-unseen-subject ()
7289   "Place the point on the subject line of the first unseen article.
7290 Return nil if there are no unseen articles."
7291   (interactive)
7292   (prog1
7293       (when (gnus-summary-first-subject nil nil t)
7294         (gnus-summary-show-thread)
7295         (gnus-summary-first-subject nil nil t))
7296     (gnus-summary-position-point)))
7297
7298 (defun gnus-summary-first-unseen-or-unread-subject ()
7299   "Place the point on the subject line of the first unseen article or,
7300 if all article have been seen, on the subject line of the first unread
7301 article."
7302   (interactive)
7303   (prog1
7304       (unless (when (gnus-summary-first-subject nil nil t)
7305                 (gnus-summary-show-thread)
7306                 (gnus-summary-first-subject nil nil t))
7307         (when (gnus-summary-first-subject t)
7308           (gnus-summary-show-thread)
7309           (gnus-summary-first-subject t)))
7310     (gnus-summary-position-point)))
7311
7312 (defun gnus-summary-first-article ()
7313   "Select the first article.
7314 Return nil if there are no articles."
7315   (interactive)
7316   (prog1
7317       (when (gnus-summary-first-subject)
7318         (gnus-summary-show-thread)
7319         (gnus-summary-first-subject)
7320         (gnus-summary-display-article (gnus-summary-article-number)))
7321     (gnus-summary-position-point)))
7322
7323 (defun gnus-summary-best-unread-article (&optional arg)
7324   "Select the unread article with the highest score.
7325 If given a prefix argument, select the next unread article that has a
7326 score higher than the default score."
7327   (interactive "P")
7328   (let ((article (if arg
7329                      (gnus-summary-better-unread-subject)
7330                    (gnus-summary-best-unread-subject))))
7331     (if article
7332         (gnus-summary-goto-article article)
7333       (error "No unread articles"))))
7334
7335 (defun gnus-summary-best-unread-subject ()
7336   "Select the unread subject with the highest score."
7337   (interactive)
7338   (let ((best -1000000)
7339         (data gnus-newsgroup-data)
7340         article score)
7341     (while data
7342       (and (gnus-data-unread-p (car data))
7343            (> (setq score
7344                     (gnus-summary-article-score (gnus-data-number (car data))))
7345               best)
7346            (setq best score
7347                  article (gnus-data-number (car data))))
7348       (setq data (cdr data)))
7349     (when article
7350       (gnus-summary-goto-subject article))
7351     (gnus-summary-position-point)
7352     article))
7353
7354 (defun gnus-summary-better-unread-subject ()
7355   "Select the first unread subject that has a score over the default score."
7356   (interactive)
7357   (let ((data gnus-newsgroup-data)
7358         article score)
7359     (while (and (setq article (gnus-data-number (car data)))
7360                 (or (gnus-data-read-p (car data))
7361                     (not (> (gnus-summary-article-score article)
7362                             gnus-summary-default-score))))
7363       (setq data (cdr data)))
7364     (when article
7365       (gnus-summary-goto-subject article))
7366     (gnus-summary-position-point)
7367     article))
7368
7369 (defun gnus-summary-last-subject ()
7370   "Go to the last displayed subject line in the group."
7371   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7372     (when article
7373       (gnus-summary-goto-subject article))))
7374
7375 (defun gnus-summary-goto-article (article &optional all-headers force)
7376   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7377 If ALL-HEADERS is non-nil, no header lines are hidden.
7378 If FORCE, go to the article even if it isn't displayed.  If FORCE
7379 is a number, it is the line the article is to be displayed on."
7380   (interactive
7381    (list
7382     (completing-read
7383      "Article number or Message-ID: "
7384      (mapcar (lambda (number) (list (int-to-string number)))
7385              gnus-newsgroup-limit))
7386     current-prefix-arg
7387     t))
7388   (prog1
7389       (if (and (stringp article)
7390                (string-match "@" article))
7391           (gnus-summary-refer-article article)
7392         (when (stringp article)
7393           (setq article (string-to-number article)))
7394         (if (gnus-summary-goto-subject article force)
7395             (gnus-summary-display-article article all-headers)
7396           (gnus-message 4 "Couldn't go to article %s" article) nil))
7397     (gnus-summary-position-point)))
7398
7399 (defun gnus-summary-goto-last-article ()
7400   "Go to the previously read article."
7401   (interactive)
7402   (prog1
7403       (when gnus-last-article
7404         (gnus-summary-goto-article gnus-last-article nil t))
7405     (gnus-summary-position-point)))
7406
7407 (defun gnus-summary-pop-article (number)
7408   "Pop one article off the history and go to the previous.
7409 NUMBER articles will be popped off."
7410   (interactive "p")
7411   (let (to)
7412     (setq gnus-newsgroup-history
7413           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7414     (if to
7415         (gnus-summary-goto-article (car to) nil t)
7416       (error "Article history empty")))
7417   (gnus-summary-position-point))
7418
7419 ;; Summary commands and functions for limiting the summary buffer.
7420
7421 (defun gnus-summary-limit-to-articles (n)
7422   "Limit the summary buffer to the next N articles.
7423 If not given a prefix, use the process marked articles instead."
7424   (interactive "P")
7425   (prog1
7426       (let ((articles (gnus-summary-work-articles n)))
7427         (setq gnus-newsgroup-processable nil)
7428         (gnus-summary-limit articles))
7429     (gnus-summary-position-point)))
7430
7431 (defun gnus-summary-pop-limit (&optional total)
7432   "Restore the previous limit.
7433 If given a prefix, remove all limits."
7434   (interactive "P")
7435   (when total
7436     (setq gnus-newsgroup-limits
7437           (list (mapcar (lambda (h) (mail-header-number h))
7438                         gnus-newsgroup-headers))))
7439   (unless gnus-newsgroup-limits
7440     (error "No limit to pop"))
7441   (prog1
7442       (gnus-summary-limit nil 'pop)
7443     (gnus-summary-position-point)))
7444
7445 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7446   "Limit the summary buffer to articles that have subjects that match a regexp.
7447 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7448   (interactive
7449    (list (read-string (if current-prefix-arg
7450                           "Exclude subject (regexp): "
7451                         "Limit to subject (regexp): "))
7452          nil current-prefix-arg))
7453   (unless header
7454     (setq header "subject"))
7455   (when (not (equal "" subject))
7456     (prog1
7457         (let ((articles (gnus-summary-find-matching
7458                          (or header "subject") subject 'all nil nil
7459                          not-matching)))
7460           (unless articles
7461             (error "Found no matches for \"%s\"" subject))
7462           (gnus-summary-limit articles))
7463       (gnus-summary-position-point))))
7464
7465 (defun gnus-summary-limit-to-author (from &optional not-matching)
7466   "Limit the summary buffer to articles that have authors that match a regexp.
7467 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7468   (interactive
7469    (list (read-string (if current-prefix-arg
7470                           "Exclude author (regexp): "
7471                         "Limit to author (regexp): "))
7472          current-prefix-arg))
7473   (gnus-summary-limit-to-subject from "from" not-matching))
7474
7475 (defun gnus-summary-limit-to-age (age &optional younger-p)
7476   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7477 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7478 articles that are younger than AGE days."
7479   (interactive
7480    (let ((younger current-prefix-arg)
7481          (days-got nil)
7482          days)
7483      (while (not days-got)
7484        (setq days (if younger
7485                       (read-string "Limit to articles younger than (in days, older when negative): ")
7486                     (read-string
7487                      "Limit to articles older than (in days, younger when negative): ")))
7488        (when (> (length days) 0)
7489          (setq days (read days)))
7490        (if (numberp days)
7491            (progn
7492              (setq days-got t)
7493              (if (< days 0)
7494                  (progn
7495                    (setq younger (not younger))
7496                    (setq days (* days -1)))))
7497          (message "Please enter a number.")
7498          (sleep-for 1)))
7499      (list days younger)))
7500   (prog1
7501       (let ((data gnus-newsgroup-data)
7502             (cutoff (days-to-time age))
7503             articles d date is-younger)
7504         (while (setq d (pop data))
7505           (when (and (vectorp (gnus-data-header d))
7506                      (setq date (mail-header-date (gnus-data-header d))))
7507             (setq is-younger (time-less-p
7508                               (time-since (condition-case ()
7509                                               (date-to-time date)
7510                                             (error '(0 0))))
7511                               cutoff))
7512             (when (if younger-p
7513                       is-younger
7514                     (not is-younger))
7515               (push (gnus-data-number d) articles))))
7516         (gnus-summary-limit (nreverse articles)))
7517     (gnus-summary-position-point)))
7518
7519 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7520   "Limit the summary buffer to articles that match an 'extra' header."
7521   (interactive
7522    (let ((header
7523           (intern
7524            (gnus-completing-read-with-default
7525             (symbol-name (car gnus-extra-headers))
7526             (if current-prefix-arg
7527                 "Exclude extra header:"
7528               "Limit extra header:")
7529             (mapcar (lambda (x)
7530                       (cons (symbol-name x) x))
7531                     gnus-extra-headers)
7532             nil
7533             t))))
7534      (list header
7535            (read-string (format "%s header %s (regexp): "
7536                                 (if current-prefix-arg "Exclude" "Limit to")
7537                                 header))
7538            current-prefix-arg)))
7539   (when (not (equal "" regexp))
7540     (prog1
7541         (let ((articles (gnus-summary-find-matching
7542                          (cons 'extra header) regexp 'all nil nil
7543                          not-matching)))
7544           (unless articles
7545             (error "Found no matches for \"%s\"" regexp))
7546           (gnus-summary-limit articles))
7547       (gnus-summary-position-point))))
7548
7549 (defun gnus-summary-limit-to-display-predicate ()
7550   "Limit the summary buffer to the predicated in the `display' group parameter."
7551   (interactive)
7552   (unless gnus-newsgroup-display
7553     (error "There is no `display' group parameter"))
7554   (let (articles)
7555     (dolist (number gnus-newsgroup-articles)
7556       (when (funcall gnus-newsgroup-display)
7557         (push number articles)))
7558     (gnus-summary-limit articles))
7559   (gnus-summary-position-point))
7560
7561 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7562 (make-obsolete
7563  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7564
7565 (defun gnus-summary-limit-to-unread (&optional all)
7566   "Limit the summary buffer to articles that are not marked as read.
7567 If ALL is non-nil, limit strictly to unread articles."
7568   (interactive "P")
7569   (if all
7570       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7571     (gnus-summary-limit-to-marks
7572      ;; Concat all the marks that say that an article is read and have
7573      ;; those removed.
7574      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7575            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7576            gnus-low-score-mark gnus-expirable-mark
7577            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7578            gnus-duplicate-mark gnus-souped-mark)
7579      'reverse)))
7580
7581 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7582 (make-obsolete 'gnus-summary-delete-marked-with
7583                'gnus-summary-limit-exclude-marks)
7584
7585 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7586   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7587 If REVERSE, limit the summary buffer to articles that are marked
7588 with MARKS.  MARKS can either be a string of marks or a list of marks.
7589 Returns how many articles were removed."
7590   (interactive "sMarks: ")
7591   (gnus-summary-limit-to-marks marks t))
7592
7593 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7594   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7595 If REVERSE (the prefix), limit the summary buffer to articles that are
7596 not marked with MARKS.  MARKS can either be a string of marks or a
7597 list of marks.
7598 Returns how many articles were removed."
7599   (interactive "sMarks: \nP")
7600   (prog1
7601       (let ((data gnus-newsgroup-data)
7602             (marks (if (listp marks) marks
7603                      (append marks nil))) ; Transform to list.
7604             articles)
7605         (while data
7606           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7607                   (memq (gnus-data-mark (car data)) marks))
7608             (push (gnus-data-number (car data)) articles))
7609           (setq data (cdr data)))
7610         (gnus-summary-limit articles))
7611     (gnus-summary-position-point)))
7612
7613 (defun gnus-summary-limit-to-score (score)
7614   "Limit to articles with score at or above SCORE."
7615   (interactive "NLimit to articles with score of at least: ")
7616   (let ((data gnus-newsgroup-data)
7617         articles)
7618     (while data
7619       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7620                 score)
7621         (push (gnus-data-number (car data)) articles))
7622       (setq data (cdr data)))
7623     (prog1
7624         (gnus-summary-limit articles)
7625       (gnus-summary-position-point))))
7626
7627 (defun gnus-summary-limit-to-unseen ()
7628   "Limit to unseen articles."
7629   (interactive)
7630   (prog1
7631       (gnus-summary-limit gnus-newsgroup-unseen)
7632     (gnus-summary-position-point)))
7633
7634 (defun gnus-summary-limit-include-thread (id)
7635   "Display all the hidden articles that is in the thread with ID in it.
7636 When called interactively, ID is the Message-ID of the current
7637 article."
7638   (interactive (list (mail-header-id (gnus-summary-article-header))))
7639   (let ((articles (gnus-articles-in-thread
7640                    (gnus-id-to-thread (gnus-root-id id)))))
7641     (prog1
7642         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7643       (gnus-summary-limit-include-matching-articles
7644        "subject"
7645        (regexp-quote (gnus-simplify-subject-re
7646                       (mail-header-subject (gnus-id-to-header id)))))
7647       (gnus-summary-position-point))))
7648
7649 (defun gnus-summary-limit-include-matching-articles (header regexp)
7650   "Display all the hidden articles that have HEADERs that match REGEXP."
7651   (interactive (list (read-string "Match on header: ")
7652                      (read-string "Regexp: ")))
7653   (let ((articles (gnus-find-matching-articles header regexp)))
7654     (prog1
7655         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7656       (gnus-summary-position-point))))
7657
7658 (defun gnus-summary-insert-dormant-articles ()
7659   "Insert all the dormat articles for this group into the current buffer."
7660   (interactive)
7661   (let ((gnus-verbose (max 6 gnus-verbose)))
7662     (if (not gnus-newsgroup-dormant)
7663         (gnus-message 3 "No cached articles for this group")
7664       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7665
7666 (defun gnus-summary-limit-include-dormant ()
7667   "Display all the hidden articles that are marked as dormant.
7668 Note that this command only works on a subset of the articles currently
7669 fetched for this group."
7670   (interactive)
7671   (unless gnus-newsgroup-dormant
7672     (error "There are no dormant articles in this group"))
7673   (prog1
7674       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7675     (gnus-summary-position-point)))
7676
7677 (defun gnus-summary-limit-exclude-dormant ()
7678   "Hide all dormant articles."
7679   (interactive)
7680   (prog1
7681       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7682     (gnus-summary-position-point)))
7683
7684 (defun gnus-summary-limit-exclude-childless-dormant ()
7685   "Hide all dormant articles that have no children."
7686   (interactive)
7687   (let ((data (gnus-data-list t))
7688         articles d children)
7689     ;; Find all articles that are either not dormant or have
7690     ;; children.
7691     (while (setq d (pop data))
7692       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7693                 (and (setq children
7694                            (gnus-article-children (gnus-data-number d)))
7695                      (let (found)
7696                        (while children
7697                          (when (memq (car children) articles)
7698                            (setq children nil
7699                                  found t))
7700                          (pop children))
7701                        found)))
7702         (push (gnus-data-number d) articles)))
7703     ;; Do the limiting.
7704     (prog1
7705         (gnus-summary-limit articles)
7706       (gnus-summary-position-point))))
7707
7708 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7709   "Mark all unread excluded articles as read.
7710 If ALL, mark even excluded ticked and dormants as read."
7711   (interactive "P")
7712   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7713   (let ((articles (gnus-sorted-ndifference
7714                    (sort
7715                     (mapcar (lambda (h) (mail-header-number h))
7716                             gnus-newsgroup-headers)
7717                     '<)
7718                    gnus-newsgroup-limit))
7719         article)
7720     (setq gnus-newsgroup-unreads
7721           (gnus-sorted-intersection gnus-newsgroup-unreads
7722                                     gnus-newsgroup-limit))
7723     (if all
7724         (setq gnus-newsgroup-dormant nil
7725               gnus-newsgroup-marked nil
7726               gnus-newsgroup-reads
7727               (nconc
7728                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7729                gnus-newsgroup-reads))
7730       (while (setq article (pop articles))
7731         (unless (or (memq article gnus-newsgroup-dormant)
7732                     (memq article gnus-newsgroup-marked))
7733           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7734
7735 (defun gnus-summary-limit (articles &optional pop)
7736   (if pop
7737       ;; We pop the previous limit off the stack and use that.
7738       (setq articles (car gnus-newsgroup-limits)
7739             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7740     ;; We use the new limit, so we push the old limit on the stack.
7741     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7742   ;; Set the limit.
7743   (setq gnus-newsgroup-limit articles)
7744   (let ((total (length gnus-newsgroup-data))
7745         (data (gnus-data-find-list (gnus-summary-article-number)))
7746         (gnus-summary-mark-below nil)   ; Inhibit this.
7747         found)
7748     ;; This will do all the work of generating the new summary buffer
7749     ;; according to the new limit.
7750     (gnus-summary-prepare)
7751     ;; Hide any threads, possibly.
7752     (gnus-summary-maybe-hide-threads)
7753     ;; Try to return to the article you were at, or one in the
7754     ;; neighborhood.
7755     (when data
7756       ;; We try to find some article after the current one.
7757       (while data
7758         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7759           (setq data nil
7760                 found t))
7761         (setq data (cdr data))))
7762     (unless found
7763       ;; If there is no data, that means that we were after the last
7764       ;; article.  The same goes when we can't find any articles
7765       ;; after the current one.
7766       (goto-char (point-max))
7767       (gnus-summary-find-prev))
7768     (gnus-set-mode-line 'summary)
7769     ;; We return how many articles were removed from the summary
7770     ;; buffer as a result of the new limit.
7771     (- total (length gnus-newsgroup-data))))
7772
7773 (defsubst gnus-invisible-cut-children (threads)
7774   (let ((num 0))
7775     (while threads
7776       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7777         (incf num))
7778       (pop threads))
7779     (< num 2)))
7780
7781 (defsubst gnus-cut-thread (thread)
7782   "Go forwards in the thread until we find an article that we want to display."
7783   (when (or (eq gnus-fetch-old-headers 'some)
7784             (eq gnus-fetch-old-headers 'invisible)
7785             (numberp gnus-fetch-old-headers)
7786             (eq gnus-build-sparse-threads 'some)
7787             (eq gnus-build-sparse-threads 'more))
7788     ;; Deal with old-fetched headers and sparse threads.
7789     (while (and
7790             thread
7791             (or
7792              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7793              (gnus-summary-article-ancient-p
7794               (mail-header-number (car thread))))
7795             (if (or (<= (length (cdr thread)) 1)
7796                     (eq gnus-fetch-old-headers 'invisible))
7797                 (setq gnus-newsgroup-limit
7798                       (delq (mail-header-number (car thread))
7799                             gnus-newsgroup-limit)
7800                       thread (cadr thread))
7801               (when (gnus-invisible-cut-children (cdr thread))
7802                 (let ((th (cdr thread)))
7803                   (while th
7804                     (if (memq (mail-header-number (caar th))
7805                               gnus-newsgroup-limit)
7806                         (setq thread (car th)
7807                               th nil)
7808                       (setq th (cdr th))))))))))
7809   thread)
7810
7811 (defun gnus-cut-threads (threads)
7812   "Cut off all uninteresting articles from the beginning of threads."
7813   (when (or (eq gnus-fetch-old-headers 'some)
7814             (eq gnus-fetch-old-headers 'invisible)
7815             (numberp gnus-fetch-old-headers)
7816             (eq gnus-build-sparse-threads 'some)
7817             (eq gnus-build-sparse-threads 'more))
7818     (let ((th threads))
7819       (while th
7820         (setcar th (gnus-cut-thread (car th)))
7821         (setq th (cdr th)))))
7822   ;; Remove nixed out threads.
7823   (delq nil threads))
7824
7825 (defun gnus-summary-initial-limit (&optional show-if-empty)
7826   "Figure out what the initial limit is supposed to be on group entry.
7827 This entails weeding out unwanted dormants, low-scored articles,
7828 fetch-old-headers verbiage, and so on."
7829   ;; Most groups have nothing to remove.
7830   (if (or gnus-inhibit-limiting
7831           (and (null gnus-newsgroup-dormant)
7832                (eq gnus-newsgroup-display 'gnus-not-ignore)
7833                (not (eq gnus-fetch-old-headers 'some))
7834                (not (numberp gnus-fetch-old-headers))
7835                (not (eq gnus-fetch-old-headers 'invisible))
7836                (null gnus-summary-expunge-below)
7837                (not (eq gnus-build-sparse-threads 'some))
7838                (not (eq gnus-build-sparse-threads 'more))
7839                (null gnus-thread-expunge-below)
7840                (not gnus-use-nocem)))
7841       ()                                ; Do nothing.
7842     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7843     (setq gnus-newsgroup-limit nil)
7844     (mapatoms
7845      (lambda (node)
7846        (unless (car (symbol-value node))
7847          ;; These threads have no parents -- they are roots.
7848          (let ((nodes (cdr (symbol-value node)))
7849                thread)
7850            (while nodes
7851              (if (and gnus-thread-expunge-below
7852                       (< (gnus-thread-total-score (car nodes))
7853                          gnus-thread-expunge-below))
7854                  (gnus-expunge-thread (pop nodes))
7855                (setq thread (pop nodes))
7856                (gnus-summary-limit-children thread))))))
7857      gnus-newsgroup-dependencies)
7858     ;; If this limitation resulted in an empty group, we might
7859     ;; pop the previous limit and use it instead.
7860     (when (and (not gnus-newsgroup-limit)
7861                show-if-empty)
7862       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7863     gnus-newsgroup-limit))
7864
7865 (defun gnus-summary-limit-children (thread)
7866   "Return 1 if this subthread is visible and 0 if it is not."
7867   ;; First we get the number of visible children to this thread.  This
7868   ;; is done by recursing down the thread using this function, so this
7869   ;; will really go down to a leaf article first, before slowly
7870   ;; working its way up towards the root.
7871   (when thread
7872     (let* ((max-lisp-eval-depth 5000)
7873            (children
7874            (if (cdr thread)
7875                (apply '+ (mapcar 'gnus-summary-limit-children
7876                                  (cdr thread)))
7877              0))
7878           (number (mail-header-number (car thread)))
7879           score)
7880       (if (and
7881            (not (memq number gnus-newsgroup-marked))
7882            (or
7883             ;; If this article is dormant and has absolutely no visible
7884             ;; children, then this article isn't visible.
7885             (and (memq number gnus-newsgroup-dormant)
7886                  (zerop children))
7887             ;; If this is "fetch-old-headered" and there is no
7888             ;; visible children, then we don't want this article.
7889             (and (or (eq gnus-fetch-old-headers 'some)
7890                      (numberp gnus-fetch-old-headers))
7891                  (gnus-summary-article-ancient-p number)
7892                  (zerop children))
7893             ;; If this is "fetch-old-headered" and `invisible', then
7894             ;; we don't want this article.
7895             (and (eq gnus-fetch-old-headers 'invisible)
7896                  (gnus-summary-article-ancient-p number))
7897             ;; If this is a sparsely inserted article with no children,
7898             ;; we don't want it.
7899             (and (eq gnus-build-sparse-threads 'some)
7900                  (gnus-summary-article-sparse-p number)
7901                  (zerop children))
7902             ;; If we use expunging, and this article is really
7903             ;; low-scored, then we don't want this article.
7904             (when (and gnus-summary-expunge-below
7905                        (< (setq score
7906                                 (or (cdr (assq number gnus-newsgroup-scored))
7907                                     gnus-summary-default-score))
7908                           gnus-summary-expunge-below))
7909               ;; We increase the expunge-tally here, but that has
7910               ;; nothing to do with the limits, really.
7911               (incf gnus-newsgroup-expunged-tally)
7912               ;; We also mark as read here, if that's wanted.
7913               (when (and gnus-summary-mark-below
7914                          (< score gnus-summary-mark-below))
7915                 (setq gnus-newsgroup-unreads
7916                       (delq number gnus-newsgroup-unreads))
7917                 (if gnus-newsgroup-auto-expire
7918                     (push number gnus-newsgroup-expirable)
7919                   (push (cons number gnus-low-score-mark)
7920                         gnus-newsgroup-reads)))
7921               t)
7922             ;; Do the `display' group parameter.
7923             (and gnus-newsgroup-display
7924                  (not (funcall gnus-newsgroup-display)))
7925             ;; Check NoCeM things.
7926             (if (and gnus-use-nocem
7927                      (gnus-nocem-unwanted-article-p
7928                       (mail-header-id (car thread))))
7929                 (progn
7930                   (setq gnus-newsgroup-unreads
7931                         (delq number gnus-newsgroup-unreads))
7932                   t))))
7933           ;; Nope, invisible article.
7934           0
7935         ;; Ok, this article is to be visible, so we add it to the limit
7936         ;; and return 1.
7937         (push number gnus-newsgroup-limit)
7938         1))))
7939
7940 (defun gnus-expunge-thread (thread)
7941   "Mark all articles in THREAD as read."
7942   (let* ((number (mail-header-number (car thread))))
7943     (incf gnus-newsgroup-expunged-tally)
7944     ;; We also mark as read here, if that's wanted.
7945     (setq gnus-newsgroup-unreads
7946           (delq number gnus-newsgroup-unreads))
7947     (if gnus-newsgroup-auto-expire
7948         (push number gnus-newsgroup-expirable)
7949       (push (cons number gnus-low-score-mark)
7950             gnus-newsgroup-reads)))
7951   ;; Go recursively through all subthreads.
7952   (mapcar 'gnus-expunge-thread (cdr thread)))
7953
7954 ;; Summary article oriented commands
7955
7956 (defun gnus-summary-refer-parent-article (n)
7957   "Refer parent article N times.
7958 If N is negative, go to ancestor -N instead.
7959 The difference between N and the number of articles fetched is returned."
7960   (interactive "p")
7961   (let ((skip 1)
7962         error header ref)
7963     (when (not (natnump n))
7964       (setq skip (abs n)
7965             n 1))
7966     (while (and (> n 0)
7967                 (not error))
7968       (setq header (gnus-summary-article-header))
7969       (if (and (eq (mail-header-number header)
7970                    (cdr gnus-article-current))
7971                (equal gnus-newsgroup-name
7972                       (car gnus-article-current)))
7973           ;; If we try to find the parent of the currently
7974           ;; displayed article, then we take a look at the actual
7975           ;; References header, since this is slightly more
7976           ;; reliable than the References field we got from the
7977           ;; server.
7978           (save-excursion
7979             (set-buffer gnus-original-article-buffer)
7980             (nnheader-narrow-to-headers)
7981             (unless (setq ref (message-fetch-field "references"))
7982               (setq ref (message-fetch-field "in-reply-to")))
7983             (widen))
7984         (setq ref
7985               ;; It's not the current article, so we take a bet on
7986               ;; the value we got from the server.
7987               (mail-header-references header)))
7988       (if (and ref
7989                (not (equal ref "")))
7990           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7991             (gnus-message 1 "Couldn't find parent"))
7992         (gnus-message 1 "No references in article %d"
7993                       (gnus-summary-article-number))
7994         (setq error t))
7995       (decf n))
7996     (gnus-summary-position-point)
7997     n))
7998
7999 (defun gnus-summary-refer-references ()
8000   "Fetch all articles mentioned in the References header.
8001 Return the number of articles fetched."
8002   (interactive)
8003   (let ((ref (mail-header-references (gnus-summary-article-header)))
8004         (current (gnus-summary-article-number))
8005         (n 0))
8006     (if (or (not ref)
8007             (equal ref ""))
8008         (error "No References in the current article")
8009       ;; For each Message-ID in the References header...
8010       (while (string-match "<[^>]*>" ref)
8011         (incf n)
8012         ;; ... fetch that article.
8013         (gnus-summary-refer-article
8014          (prog1 (match-string 0 ref)
8015            (setq ref (substring ref (match-end 0))))))
8016       (gnus-summary-goto-subject current)
8017       (gnus-summary-position-point)
8018       n)))
8019
8020 (defun gnus-summary-refer-thread (&optional limit)
8021   "Fetch all articles in the current thread.
8022 If LIMIT (the numerical prefix), fetch that many old headers instead
8023 of what's specified by the `gnus-refer-thread-limit' variable."
8024   (interactive "P")
8025   (let ((id (mail-header-id (gnus-summary-article-header)))
8026         (limit (if limit (prefix-numeric-value limit)
8027                  gnus-refer-thread-limit)))
8028     (unless (eq gnus-fetch-old-headers 'invisible)
8029       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8030       ;; Retrieve the headers and read them in.
8031       (if (eq (if (numberp limit)
8032                   (gnus-retrieve-headers
8033                    (list (min
8034                           (+ (mail-header-number
8035                               (gnus-summary-article-header))
8036                              limit)
8037                           gnus-newsgroup-end))
8038                    gnus-newsgroup-name (* limit 2))
8039                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8040                 ;; headers.
8041                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8042                                        gnus-newsgroup-name limit))
8043               'nov)
8044           (gnus-build-all-threads)
8045         (error "Can't fetch thread from backends that don't support NOV"))
8046       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8047     (gnus-summary-limit-include-thread id)))
8048
8049 (defun gnus-summary-refer-article (message-id)
8050   "Fetch an article specified by MESSAGE-ID."
8051   (interactive "sMessage-ID: ")
8052   (when (and (stringp message-id)
8053              (not (zerop (length message-id))))
8054     ;; Construct the correct Message-ID if necessary.
8055     ;; Suggested by tale@pawl.rpi.edu.
8056     (unless (string-match "^<" message-id)
8057       (setq message-id (concat "<" message-id)))
8058     (unless (string-match ">$" message-id)
8059       (setq message-id (concat message-id ">")))
8060     (let* ((header (gnus-id-to-header message-id))
8061            (sparse (and header
8062                         (gnus-summary-article-sparse-p
8063                          (mail-header-number header))
8064                         (memq (mail-header-number header)
8065                               gnus-newsgroup-limit)))
8066            number)
8067       (cond
8068        ;; If the article is present in the buffer we just go to it.
8069        ((and header
8070              (or (not (gnus-summary-article-sparse-p
8071                        (mail-header-number header)))
8072                  sparse))
8073         (prog1
8074             (gnus-summary-goto-article
8075              (mail-header-number header) nil t)
8076           (when sparse
8077             (gnus-summary-update-article (mail-header-number header)))))
8078        (t
8079         ;; We fetch the article.
8080         (catch 'found
8081           (dolist (gnus-override-method (gnus-refer-article-methods))
8082             (when (and (gnus-check-server gnus-override-method)
8083                        ;; Fetch the header,
8084                        (setq number (gnus-summary-insert-subject message-id)))
8085               ;; and display the article.
8086               (gnus-summary-select-article nil nil nil number)
8087               (throw 'found t)))
8088           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8089
8090 (defun gnus-refer-article-methods ()
8091   "Return a list of referable methods."
8092   (cond
8093    ;; No method, so we default to current and native.
8094    ((null gnus-refer-article-method)
8095     (list gnus-current-select-method gnus-select-method))
8096    ;; Current.
8097    ((eq 'current gnus-refer-article-method)
8098     (list gnus-current-select-method))
8099    ;; List of select methods.
8100    ((not (and (symbolp (car gnus-refer-article-method))
8101               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8102     (let (out)
8103       (dolist (method gnus-refer-article-method)
8104         (push (if (eq 'current method)
8105                   gnus-current-select-method
8106                 method)
8107               out))
8108       (nreverse out)))
8109    ;; One single select method.
8110    (t
8111     (list gnus-refer-article-method))))
8112
8113 (defun gnus-summary-edit-parameters ()
8114   "Edit the group parameters of the current group."
8115   (interactive)
8116   (gnus-group-edit-group gnus-newsgroup-name 'params))
8117
8118 (defun gnus-summary-customize-parameters ()
8119   "Customize the group parameters of the current group."
8120   (interactive)
8121   (gnus-group-customize gnus-newsgroup-name))
8122
8123 (defun gnus-summary-enter-digest-group (&optional force)
8124   "Enter an nndoc group based on the current article.
8125 If FORCE, force a digest interpretation.  If not, try
8126 to guess what the document format is."
8127   (interactive "P")
8128   (let ((conf gnus-current-window-configuration))
8129     (save-excursion
8130       (gnus-summary-select-article))
8131     (setq gnus-current-window-configuration conf)
8132     (let* ((name (format "%s-%d"
8133                          (gnus-group-prefixed-name
8134                           gnus-newsgroup-name (list 'nndoc ""))
8135                          (save-excursion
8136                            (set-buffer gnus-summary-buffer)
8137                            gnus-current-article)))
8138            (ogroup gnus-newsgroup-name)
8139            (params (append (gnus-info-params (gnus-get-info ogroup))
8140                            (list (cons 'to-group ogroup))
8141                            (list (cons 'save-article-group ogroup))))
8142            (case-fold-search t)
8143            (buf (current-buffer))
8144            dig to-address)
8145       (save-excursion
8146         (set-buffer gnus-original-article-buffer)
8147         ;; Have the digest group inherit the main mail address of
8148         ;; the parent article.
8149         (when (setq to-address (or (gnus-fetch-field "reply-to")
8150                                    (gnus-fetch-field "from")))
8151           (setq params (append
8152                         (list (cons 'to-address
8153                                     (funcall gnus-decode-encoded-word-function
8154                                              to-address))))))
8155         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8156         (insert-buffer-substring gnus-original-article-buffer)
8157         ;; Remove lines that may lead nndoc to misinterpret the
8158         ;; document type.
8159         (narrow-to-region
8160          (goto-char (point-min))
8161          (or (search-forward "\n\n" nil t) (point)))
8162         (goto-char (point-min))
8163         (delete-matching-lines "^Path:\\|^From ")
8164         (widen))
8165       (unwind-protect
8166           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8167                     (gnus-newsgroup-ephemeral-ignored-charsets
8168                      gnus-newsgroup-ignored-charsets))
8169                 (gnus-group-read-ephemeral-group
8170                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8171                               (nndoc-article-type
8172                                ,(if force 'mbox 'guess)))
8173                  t nil nil nil
8174                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8175                                                         "ADAPT")))))
8176               ;; Make all postings to this group go to the parent group.
8177               (nconc (gnus-info-params (gnus-get-info name))
8178                      params)
8179             ;; Couldn't select this doc group.
8180             (switch-to-buffer buf)
8181             (gnus-set-global-variables)
8182             (gnus-configure-windows 'summary)
8183             (gnus-message 3 "Article couldn't be entered?"))
8184         (kill-buffer dig)))))
8185
8186 (defun gnus-summary-read-document (n)
8187   "Open a new group based on the current article(s).
8188 This will allow you to read digests and other similar
8189 documents as newsgroups.
8190 Obeys the standard process/prefix convention."
8191   (interactive "P")
8192   (let* ((articles (gnus-summary-work-articles n))
8193          (ogroup gnus-newsgroup-name)
8194          (params (append (gnus-info-params (gnus-get-info ogroup))
8195                          (list (cons 'to-group ogroup))))
8196          article group egroup groups vgroup)
8197     (while (setq article (pop articles))
8198       (setq group (format "%s-%d" gnus-newsgroup-name article))
8199       (gnus-summary-remove-process-mark article)
8200       (when (gnus-summary-display-article article)
8201         (save-excursion
8202           (with-temp-buffer
8203             (insert-buffer-substring gnus-original-article-buffer)
8204             ;; Remove some headers that may lead nndoc to make
8205             ;; the wrong guess.
8206             (message-narrow-to-head)
8207             (goto-char (point-min))
8208             (delete-matching-lines "^\\(Path\\):\\|^From ")
8209             (widen)
8210             (if (setq egroup
8211                       (gnus-group-read-ephemeral-group
8212                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8213                                      (nndoc-article-type guess))
8214                        t nil t))
8215                 (progn
8216                   ;; Make all postings to this group go to the parent group.
8217                   (nconc (gnus-info-params (gnus-get-info egroup))
8218                          params)
8219                   (push egroup groups))
8220               ;; Couldn't select this doc group.
8221               (gnus-error 3 "Article couldn't be entered"))))))
8222     ;; Now we have selected all the documents.
8223     (cond
8224      ((not groups)
8225       (error "None of the articles could be interpreted as documents"))
8226      ((gnus-group-read-ephemeral-group
8227        (setq vgroup (format
8228                      "nnvirtual:%s-%s" gnus-newsgroup-name
8229                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8230        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8231        t
8232        (cons (current-buffer) 'summary)))
8233      (t
8234       (error "Couldn't select virtual nndoc group")))))
8235
8236 (defun gnus-summary-isearch-article (&optional regexp-p)
8237   "Do incremental search forward on the current article.
8238 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8239   (interactive "P")
8240   (let* ((gnus-inhibit-treatment t)
8241          (old (gnus-summary-select-article)))
8242     (gnus-configure-windows 'article)
8243     (gnus-eval-in-buffer-window gnus-article-buffer
8244       (save-restriction
8245         (widen)
8246         (when (eq 'old old)
8247           (gnus-article-show-all-headers))
8248         (goto-char (point-min))
8249         (isearch-forward regexp-p)))))
8250
8251 (defun gnus-summary-search-article-forward (regexp &optional backward)
8252   "Search for an article containing REGEXP forward.
8253 If BACKWARD, search backward instead."
8254   (interactive
8255    (list (read-string
8256           (format "Search article %s (regexp%s): "
8257                   (if current-prefix-arg "backward" "forward")
8258                   (if gnus-last-search-regexp
8259                       (concat ", default " gnus-last-search-regexp)
8260                     "")))
8261          current-prefix-arg))
8262   (if (string-equal regexp "")
8263       (setq regexp (or gnus-last-search-regexp ""))
8264     (setq gnus-last-search-regexp regexp)
8265     (setq gnus-article-before-search gnus-current-article))
8266   ;; Intentionally set gnus-last-article.
8267   (setq gnus-last-article gnus-article-before-search)
8268   (let ((gnus-last-article gnus-last-article))
8269     (if (gnus-summary-search-article regexp backward)
8270         (gnus-summary-show-thread)
8271       (error "Search failed: \"%s\"" regexp))))
8272
8273 (defun gnus-summary-search-article-backward (regexp)
8274   "Search for an article containing REGEXP backward."
8275   (interactive
8276    (list (read-string
8277           (format "Search article backward (regexp%s): "
8278                   (if gnus-last-search-regexp
8279                       (concat ", default " gnus-last-search-regexp)
8280                     "")))))
8281   (gnus-summary-search-article-forward regexp 'backward))
8282
8283 (eval-when-compile
8284   (defmacro gnus-summary-search-article-position-point (regexp backward)
8285     "Dehighlight the last matched text and goto the beginning position."
8286     (` (if (and gnus-summary-search-article-matched-data
8287                 (let ((text (caddr gnus-summary-search-article-matched-data))
8288                       (inhibit-read-only t)
8289                       buffer-read-only)
8290                   (delete-region
8291                    (goto-char (car gnus-summary-search-article-matched-data))
8292                    (cadr gnus-summary-search-article-matched-data))
8293                   (insert text)
8294                   (string-match (, regexp) text)))
8295            (if (, backward) (beginning-of-line) (end-of-line))
8296          (goto-char (if (, backward) (point-max) (point-min))))))
8297
8298   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8299     "Place point where X-Face image is displayed."
8300     (if (featurep 'xemacs)
8301         (` (let ((end (if (search-forward "\n\n" nil t)
8302                           (goto-char (1- (point)))
8303                         (point-min)))
8304                  extent)
8305              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8306              (unless (and (re-search-forward "^From:" end t)
8307                           (setq extent (extent-at (point)))
8308                           (extent-begin-glyph extent))
8309                (goto-char (, opoint)))))
8310       (` (let ((end (if (search-forward "\n\n" nil t)
8311                         (goto-char (1- (point)))
8312                       (point-min)))
8313                (start (or (search-backward "\n\n" nil t) (point-min))))
8314            (goto-char
8315             (or (text-property-any start end 'x-face-image t);; x-face-e21
8316                 (text-property-any start end 'x-face-mule-bitmap-image t)
8317                 (, opoint)))))))
8318
8319   (defmacro gnus-summary-search-article-highlight-matched-text
8320     (backward treated x-face)
8321     "Highlight matched text in the function `gnus-summary-search-article'."
8322     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8323              (end (set-marker (make-marker) (match-end 0)))
8324              (inhibit-read-only t)
8325              buffer-read-only)
8326          (unless treated
8327            (let ((,@
8328                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8329                     (mapcar
8330                      (lambda (item) (setq items (delq item items)))
8331                      '(gnus-treat-buttonize
8332                        gnus-treat-fill-article
8333                        gnus-treat-fill-long-lines
8334                        gnus-treat-emphasize
8335                        gnus-treat-highlight-headers
8336                        gnus-treat-highlight-citation
8337                        gnus-treat-highlight-signature
8338                        gnus-treat-overstrike
8339                        gnus-treat-display-xface
8340                        gnus-treat-buttonize-head
8341                        gnus-treat-decode-article-as-default-mime-charset))
8342                     (static-if (featurep 'xemacs)
8343                         items
8344                       (cons '(x-face-mule-delete-x-face-field
8345                               (quote never))
8346                             items))))
8347                  (gnus-treat-display-xface
8348                   (when (, x-face) gnus-treat-display-xface)))
8349              (gnus-article-prepare-mime-display)))
8350          (goto-char (if (, backward) start end))
8351          (when (, x-face)
8352            (gnus-summary-search-article-highlight-goto-x-face (point)))
8353          (setq gnus-summary-search-article-matched-data
8354                (list start end (buffer-substring start end)))
8355          (unless (eq start end);; matched text has been deleted. :-<
8356            (put-text-property start end 'face
8357                               (or (find-face 'isearch)
8358                                   'secondary-selection))))))
8359   )
8360
8361 (defun gnus-summary-search-article (regexp &optional backward)
8362   "Search for an article containing REGEXP.
8363 Optional argument BACKWARD means do search for backward.
8364 `gnus-select-article-hook' is not called during the search."
8365   ;; We have to require this here to make sure that the following
8366   ;; dynamic binding isn't shadowed by autoloading.
8367   (require 'gnus-async)
8368   (require 'gnus-art)
8369   (let ((gnus-select-article-hook nil)  ;Disable hook.
8370         (gnus-article-prepare-hook nil)
8371         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8372         (gnus-use-article-prefetch nil)
8373         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8374         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8375         (gnus-visual nil)
8376         (gnus-keep-backlog nil)
8377         (gnus-break-pages nil)
8378         (gnus-summary-display-arrow nil)
8379         (gnus-updated-mode-lines nil)
8380         (gnus-auto-center-summary nil)
8381         (sum (current-buffer))
8382         (found nil)
8383         point treated)
8384     (gnus-save-hidden-threads
8385       (static-if (featurep 'xemacs)
8386           (let ((gnus-inhibit-treatment t))
8387             (setq treated (eq 'old (gnus-summary-select-article)))
8388             (when (and treated
8389                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8390                                  (window-live-p (get-buffer-window
8391                                                  gnus-article-buffer t)))))
8392               (gnus-summary-select-article nil t)
8393               (setq treated nil)))
8394         (let ((gnus-inhibit-treatment t)
8395               (x-face-mule-delete-x-face-field 'never))
8396           (setq treated (eq 'old (gnus-summary-select-article)))
8397           (when (and treated
8398                      (not
8399                       (and (gnus-buffer-live-p gnus-article-buffer)
8400                            (window-live-p (get-buffer-window
8401                                            gnus-article-buffer t))
8402                            (or (not (string-match "^\\^X-Face:" regexp))
8403                                (with-current-buffer gnus-article-buffer
8404                                  gnus-summary-search-article-matched-data)))))
8405             (gnus-summary-select-article nil t)
8406             (setq treated nil))))
8407       (set-buffer gnus-article-buffer)
8408       (widen)
8409       (if treated
8410           (progn
8411             (gnus-article-show-all-headers)
8412             (gnus-summary-search-article-position-point regexp backward))
8413         (goto-char (if backward (point-max) (point-min))))
8414       (while (not found)
8415         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8416         (if (if backward
8417                 (re-search-backward regexp nil t)
8418               (re-search-forward regexp nil t))
8419             ;; We found the regexp.
8420             (progn
8421               (gnus-summary-search-article-highlight-matched-text
8422                backward treated (string-match "^\\^X-Face:" regexp))
8423               (setq found 'found)
8424               (forward-line
8425                (/ (- 2 (window-height
8426                         (get-buffer-window gnus-article-buffer t)))
8427                   2))
8428               (set-window-start
8429                (get-buffer-window (current-buffer))
8430                (point))
8431               (set-buffer sum)
8432               (setq point (point)))
8433           ;; We didn't find it, so we go to the next article.
8434           (set-buffer sum)
8435           (setq found 'not)
8436           (while (eq found 'not)
8437             (if (not (if backward (gnus-summary-find-prev)
8438                        (gnus-summary-find-next)))
8439                 ;; No more articles.
8440                 (setq found t)
8441               ;; Select the next article and adjust point.
8442               (unless (gnus-summary-article-sparse-p
8443                        (gnus-summary-article-number))
8444                 (setq found nil)
8445                 (let ((gnus-inhibit-treatment t))
8446                   (gnus-summary-select-article))
8447                 (setq treated nil)
8448                 (set-buffer gnus-article-buffer)
8449                 (widen)
8450                 (goto-char (if backward (point-max) (point-min))))))))
8451       (gnus-message 7 ""))
8452     ;; Return whether we found the regexp.
8453     (when (eq found 'found)
8454       (goto-char point)
8455       (gnus-summary-show-thread)
8456       (gnus-summary-goto-subject gnus-current-article)
8457       (gnus-summary-position-point)
8458       t)))
8459
8460 (defun gnus-find-matching-articles (header regexp)
8461   "Return a list of all articles that match REGEXP on HEADER.
8462 This search includes all articles in the current group that Gnus has
8463 fetched headers for, whether they are displayed or not."
8464   (let ((articles nil)
8465         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8466         (case-fold-search t))
8467     (dolist (header gnus-newsgroup-headers)
8468       (when (string-match regexp (funcall func header))
8469         (push (mail-header-number header) articles)))
8470     (nreverse articles)))
8471
8472 (defun gnus-summary-find-matching (header regexp &optional backward unread
8473                                           not-case-fold not-matching)
8474   "Return a list of all articles that match REGEXP on HEADER.
8475 The search stars on the current article and goes forwards unless
8476 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8477 If UNREAD is non-nil, only unread articles will
8478 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8479 in the comparisons. If NOT-MATCHING, return a list of all articles that
8480 not match REGEXP on HEADER."
8481   (let ((case-fold-search (not not-case-fold))
8482         articles d func)
8483     (if (consp header)
8484         (if (eq (car header) 'extra)
8485             (setq func
8486                   `(lambda (h)
8487                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8488                          "")))
8489           (error "%s is an invalid header" header))
8490       (unless (fboundp (intern (concat "mail-header-" header)))
8491         (error "%s is not a valid header" header))
8492       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8493     (dolist (d (if (eq backward 'all)
8494                    gnus-newsgroup-data
8495                  (gnus-data-find-list
8496                   (gnus-summary-article-number)
8497                   (gnus-data-list backward))))
8498       (when (and (or (not unread)       ; We want all articles...
8499                      (gnus-data-unread-p d)) ; Or just unreads.
8500                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8501                  (if not-matching
8502                      (not (string-match
8503                            regexp
8504                            (funcall func (gnus-data-header d))))
8505                    (string-match regexp
8506                                  (funcall func (gnus-data-header d)))))
8507         (push (gnus-data-number d) articles))) ; Success!
8508     (nreverse articles)))
8509
8510 (defun gnus-summary-execute-command (header regexp command &optional backward)
8511   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8512 If HEADER is an empty string (or nil), the match is done on the entire
8513 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8514   (interactive
8515    (list (let ((completion-ignore-case t))
8516            (completing-read
8517             "Header name: "
8518             (mapcar (lambda (header) (list (format "%s" header)))
8519                     (append
8520                      '("Number" "Subject" "From" "Lines" "Date"
8521                        "Message-ID" "Xref" "References" "Body")
8522                      gnus-extra-headers))
8523             nil 'require-match))
8524          (read-string "Regexp: ")
8525          (read-key-sequence "Command: ")
8526          current-prefix-arg))
8527   (when (equal header "Body")
8528     (setq header ""))
8529   ;; Hidden thread subtrees must be searched as well.
8530   (gnus-summary-show-all-threads)
8531   ;; We don't want to change current point nor window configuration.
8532   (save-excursion
8533     (save-window-excursion
8534       (let (gnus-visual
8535             gnus-treat-strip-trailing-blank-lines
8536             gnus-treat-strip-leading-blank-lines
8537             gnus-treat-strip-multiple-blank-lines
8538             gnus-treat-hide-boring-headers
8539             gnus-treat-fold-newsgroups
8540             gnus-article-prepare-hook)
8541         (gnus-message 6 "Executing %s..." (key-description command))
8542         ;; We'd like to execute COMMAND interactively so as to give arguments.
8543         (gnus-execute header regexp
8544                       `(call-interactively ',(key-binding command))
8545                       backward)
8546         (gnus-message 6 "Executing %s...done" (key-description command))))))
8547
8548 (defun gnus-summary-beginning-of-article ()
8549   "Scroll the article back to the beginning."
8550   (interactive)
8551   (gnus-summary-select-article)
8552   (gnus-configure-windows 'article)
8553   (gnus-eval-in-buffer-window gnus-article-buffer
8554     (widen)
8555     (goto-char (point-min))
8556     (when gnus-page-broken
8557       (gnus-narrow-to-page))))
8558
8559 (defun gnus-summary-end-of-article ()
8560   "Scroll to the end of the article."
8561   (interactive)
8562   (gnus-summary-select-article)
8563   (gnus-configure-windows 'article)
8564   (gnus-eval-in-buffer-window gnus-article-buffer
8565     (widen)
8566     (goto-char (point-max))
8567     (recenter -3)
8568     (when gnus-page-broken
8569       (gnus-narrow-to-page))))
8570
8571 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8572   "Truncate to LEN and quote all \"(\"'s in STRING."
8573   (gnus-replace-in-string (if (and len (> (length string) len))
8574                               (substring string 0 len)
8575                             string)
8576                           "[()]" "\\\\\\&"))
8577
8578 (defun gnus-summary-print-article (&optional filename n)
8579   "Generate and print a PostScript image of the N next (mail) articles.
8580
8581 If N is negative, print the N previous articles.  If N is nil and articles
8582 have been marked with the process mark, print these instead.
8583
8584 If the optional first argument FILENAME is nil, send the image to the
8585 printer.  If FILENAME is a string, save the PostScript image in a file with
8586 that name.  If FILENAME is a number, prompt the user for the name of the file
8587 to save in."
8588   (interactive (list (ps-print-preprint current-prefix-arg)))
8589   (dolist (article (gnus-summary-work-articles n))
8590     (gnus-summary-select-article nil nil 'pseudo article)
8591     (gnus-eval-in-buffer-window gnus-article-buffer
8592       (gnus-print-buffer))
8593     (gnus-summary-remove-process-mark article))
8594   (ps-despool filename))
8595
8596 (defun gnus-print-buffer ()
8597   (let ((buffer (generate-new-buffer " *print*")))
8598     (unwind-protect
8599         (progn
8600           (copy-to-buffer buffer (point-min) (point-max))
8601           (set-buffer buffer)
8602           (gnus-article-delete-invisible-text)
8603           (gnus-remove-text-with-property 'gnus-decoration)
8604           (when (gnus-visual-p 'article-highlight 'highlight)
8605             ;; Copy-to-buffer doesn't copy overlay.  So redo
8606             ;; highlight.
8607             (let ((gnus-article-buffer buffer))
8608               (gnus-article-highlight-citation t)
8609               (gnus-article-highlight-signature)))
8610           (let ((ps-left-header
8611                  (list
8612                   (concat "("
8613                           (gnus-summary-print-truncate-and-quote
8614                            (mail-header-subject gnus-current-headers)
8615                            66) ")")
8616                   (concat "("
8617                           (gnus-summary-print-truncate-and-quote
8618                            (mail-header-from gnus-current-headers)
8619                            45) ")")))
8620                 (ps-right-header
8621                  (list
8622                   "/pagenumberstring load"
8623                   (concat "("
8624                           (mail-header-date gnus-current-headers) ")"))))
8625             (gnus-run-hooks 'gnus-ps-print-hook)
8626             (save-excursion
8627               (if window-system
8628                   (ps-spool-buffer-with-faces)
8629                 (ps-spool-buffer)))))
8630       (kill-buffer buffer))))
8631
8632 (defun gnus-summary-show-article (&optional arg)
8633   "Force redisplaying of the current article.
8634 If ARG (the prefix) is a number, show the article with the charset
8635 defined in `gnus-summary-show-article-charset-alist', or the charset
8636 input.
8637 If ARG (the prefix) is non-nil and not a number, show the raw article
8638 without any article massaging functions being run.  Normally, the key strokes
8639 are `C-u g'."
8640   (interactive "P")
8641   (cond
8642    ((numberp arg)
8643     (gnus-summary-show-article t)
8644     (let* ((gnus-newsgroup-charset
8645             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8646                 (mm-read-coding-system
8647                  "View as charset: " ;; actually it is coding system.
8648                  (save-excursion
8649                    (set-buffer gnus-article-buffer)
8650                    (mm-detect-coding-region (point) (point-max))))))
8651            (default-mime-charset gnus-newsgroup-charset)
8652            (gnus-newsgroup-ignored-charsets 'gnus-all))
8653       (gnus-summary-select-article nil 'force)
8654       (let ((deps gnus-newsgroup-dependencies)
8655             head header lines)
8656         (save-excursion
8657           (set-buffer gnus-original-article-buffer)
8658           (save-restriction
8659             (message-narrow-to-head)
8660             (setq head (buffer-string))
8661             (goto-char (point-min))
8662             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8663               (goto-char (point-max))
8664               (widen)
8665               (setq lines (1- (count-lines (point) (point-max))))))
8666           (with-temp-buffer
8667             (insert (format "211 %d Article retrieved.\n"
8668                             (cdr gnus-article-current)))
8669             (insert head)
8670             (if lines (insert (format "Lines: %d\n" lines)))
8671             (insert ".\n")
8672             (let ((nntp-server-buffer (current-buffer)))
8673               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8674         (gnus-data-set-header
8675          (gnus-data-find (cdr gnus-article-current))
8676          header)
8677         (gnus-summary-update-article-line
8678          (cdr gnus-article-current) header)
8679         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8680           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8681    ((not arg)
8682     ;; Select the article the normal way.
8683     (gnus-summary-select-article nil 'force))
8684    (t
8685     ;; We have to require this here to make sure that the following
8686     ;; dynamic binding isn't shadowed by autoloading.
8687     (require 'gnus-async)
8688     (require 'gnus-art)
8689     ;; Bind the article treatment functions to nil.
8690     (let ((gnus-have-all-headers t)
8691           gnus-article-prepare-hook
8692           gnus-article-decode-hook
8693           gnus-break-pages
8694           gnus-show-mime
8695           (gnus-inhibit-treatment t))
8696       (gnus-summary-select-article nil 'force))))
8697   (gnus-summary-goto-subject gnus-current-article)
8698   (gnus-summary-position-point))
8699
8700 (defun gnus-summary-show-raw-article ()
8701   "Show the raw article without any article massaging functions being run."
8702   (interactive)
8703   (gnus-summary-show-article t))
8704
8705 (defun gnus-summary-verbose-headers (&optional arg)
8706   "Toggle permanent full header display.
8707 If ARG is a positive number, turn header display on.
8708 If ARG is a negative number, turn header display off."
8709   (interactive "P")
8710   (setq gnus-show-all-headers
8711         (cond ((or (not (numberp arg))
8712                    (zerop arg))
8713                (not gnus-show-all-headers))
8714               ((natnump arg)
8715                t)))
8716   (gnus-summary-show-article))
8717
8718 (defun gnus-summary-toggle-header (&optional arg)
8719   "Show the headers if they are hidden, or hide them if they are shown.
8720 If ARG is a positive number, show the entire header.
8721 If ARG is a negative number, hide the unwanted header lines."
8722   (interactive "P")
8723   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8724                      (get-buffer-window gnus-article-buffer t))))
8725     (with-current-buffer gnus-article-buffer
8726       (widen)
8727       (article-narrow-to-head)
8728       (let* ((buffer-read-only nil)
8729              (inhibit-point-motion-hooks t)
8730              (hidden (if (numberp arg)
8731                          (>= arg 0)
8732                        (gnus-article-hidden-text-p 'headers)))
8733              s e)
8734         (delete-region (point-min) (point-max))
8735         (with-current-buffer gnus-original-article-buffer
8736           (goto-char (setq s (point-min)))
8737           (setq e (if (search-forward "\n\n" nil t)
8738                       (1- (point))
8739                     (point-max))))
8740         (insert-buffer-substring gnus-original-article-buffer s e)
8741         (run-hooks 'gnus-article-decode-hook)
8742         (if hidden
8743             (let ((gnus-treat-hide-headers nil)
8744                   (gnus-treat-hide-boring-headers nil))
8745               (gnus-delete-wash-type 'headers)
8746               (gnus-treat-article 'head))
8747           (gnus-treat-article 'head))
8748         (widen)
8749         (if window
8750             (set-window-start window (goto-char (point-min))))
8751         (setq gnus-page-broken
8752               (when gnus-break-pages
8753                 (gnus-narrow-to-page)
8754                 t))
8755         (gnus-set-mode-line 'article)))))
8756
8757 (defun gnus-summary-show-all-headers ()
8758   "Make all header lines visible."
8759   (interactive)
8760   (gnus-summary-toggle-header 1))
8761
8762 (defun gnus-summary-toggle-mime (&optional arg)
8763   "Toggle MIME processing.
8764 If ARG is a positive number, turn MIME processing on."
8765   (interactive "P")
8766   (setq gnus-show-mime
8767         (if (null arg)
8768             (not gnus-show-mime)
8769           (> (prefix-numeric-value arg) 0)))
8770   (gnus-summary-select-article t 'force))
8771
8772 (defun gnus-summary-caesar-message (&optional arg)
8773   "Caesar rotate the current article by 13.
8774 The numerical prefix specifies how many places to rotate each letter
8775 forward."
8776   (interactive "P")
8777   (gnus-summary-select-article)
8778   (let ((mail-header-separator ""))
8779     (gnus-eval-in-buffer-window gnus-article-buffer
8780       (save-restriction
8781         (widen)
8782         (let ((start (window-start))
8783               buffer-read-only)
8784           (message-caesar-buffer-body arg)
8785           (set-window-start (get-buffer-window (current-buffer)) start))))))
8786
8787 (autoload 'unmorse-region "morse"
8788   "Convert morse coded text in region to ordinary ASCII text."
8789   t)
8790
8791 (defun gnus-summary-morse-message (&optional arg)
8792   "Morse decode the current article."
8793   (interactive "P")
8794   (gnus-summary-select-article)
8795   (let ((mail-header-separator ""))
8796     (gnus-eval-in-buffer-window gnus-article-buffer
8797       (save-excursion
8798         (save-restriction
8799           (widen)
8800           (let ((pos (window-start))
8801                 buffer-read-only)
8802             (goto-char (point-min))
8803             (when (message-goto-body)
8804               (gnus-narrow-to-body))
8805             (goto-char (point-min))
8806             (while (re-search-forward "·" (point-max) t)
8807               (replace-match "."))
8808             (unmorse-region (point-min) (point-max))
8809             (widen)
8810             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8811
8812 (defun gnus-summary-stop-page-breaking ()
8813   "Stop page breaking in the current article."
8814   (interactive)
8815   (gnus-summary-select-article)
8816   (gnus-eval-in-buffer-window gnus-article-buffer
8817     (widen)
8818     (when (gnus-visual-p 'page-marker)
8819       (let ((buffer-read-only nil))
8820         (gnus-remove-text-with-property 'gnus-prev)
8821         (gnus-remove-text-with-property 'gnus-next))
8822       (setq gnus-page-broken nil))))
8823
8824 (defun gnus-summary-move-article (&optional n to-newsgroup
8825                                             select-method action)
8826   "Move the current article to a different newsgroup.
8827 If N is a positive number, move the N next articles.
8828 If N is a negative number, move the N previous articles.
8829 If N is nil and any articles have been marked with the process mark,
8830 move those articles instead.
8831 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8832 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8833 re-spool using this method.
8834
8835 When called interactively with TO-NEWSGROUP being nil, the value of
8836 the variable `gnus-move-split-methods' is used for finding a default
8837 for the target newsgroup.
8838
8839 For this function to work, both the current newsgroup and the
8840 newsgroup that you want to move to have to support the `request-move'
8841 and `request-accept' functions.
8842
8843 ACTION can be either `move' (the default), `crosspost' or `copy'."
8844   (interactive "P")
8845   (unless action
8846     (setq action 'move))
8847   ;; Check whether the source group supports the required functions.
8848   (cond ((and (eq action 'move)
8849               (not (gnus-check-backend-function
8850                     'request-move-article gnus-newsgroup-name)))
8851          (error "The current group does not support article moving"))
8852         ((and (eq action 'crosspost)
8853               (not (gnus-check-backend-function
8854                     'request-replace-article gnus-newsgroup-name)))
8855          (error "The current group does not support article editing")))
8856   (let ((articles (gnus-summary-work-articles n))
8857         (prefix (if (gnus-check-backend-function
8858                      'request-move-article gnus-newsgroup-name)
8859                     (gnus-group-real-prefix gnus-newsgroup-name)
8860                   ""))
8861         (names '((move "Move" "Moving")
8862                  (copy "Copy" "Copying")
8863                  (crosspost "Crosspost" "Crossposting")))
8864         (copy-buf (save-excursion
8865                     (nnheader-set-temp-buffer " *copy article*")))
8866         (default-marks gnus-article-mark-lists)
8867         (no-expire-marks (delete '(expirable . expire)
8868                                  (copy-sequence gnus-article-mark-lists)))
8869         art-group to-method new-xref article to-groups)
8870     (unless (assq action names)
8871       (error "Unknown action %s" action))
8872     ;; Read the newsgroup name.
8873     (when (and (not to-newsgroup)
8874                (not select-method))
8875       (if (and gnus-move-split-methods
8876                (not
8877                 (and (memq gnus-current-article articles)
8878                      (gnus-buffer-live-p gnus-original-article-buffer))))
8879           ;; When `gnus-move-split-methods' is non-nil, we have to
8880           ;; select an article to give `gnus-read-move-group-name' an
8881           ;; opportunity to suggest an appropriate default.  However,
8882           ;; we needn't render or mark the article.
8883           (let ((gnus-display-mime-function nil)
8884                 (gnus-article-prepare-hook nil)
8885                 (gnus-mark-article-hook nil))
8886             (gnus-summary-select-article nil nil nil (car articles))))
8887       (setq to-newsgroup
8888             (gnus-read-move-group-name
8889              (cadr (assq action names))
8890              (symbol-value (intern (format "gnus-current-%s-group" action)))
8891              articles prefix))
8892       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8893     (setq to-method (or select-method
8894                         (gnus-server-to-method
8895                          (gnus-group-method to-newsgroup))))
8896     ;; Check the method we are to move this article to...
8897     (unless (gnus-check-backend-function
8898              'request-accept-article (car to-method))
8899       (error "%s does not support article copying" (car to-method)))
8900     (unless (gnus-check-server to-method)
8901       (error "Can't open server %s" (car to-method)))
8902     (gnus-message 6 "%s to %s: %s..."
8903                   (caddr (assq action names))
8904                   (or (car select-method) to-newsgroup) articles)
8905     (while articles
8906       (setq article (pop articles))
8907       (setq
8908        art-group
8909        (cond
8910         ;; Move the article.
8911         ((eq action 'move)
8912          ;; Remove this article from future suppression.
8913          (gnus-dup-unsuppress-article article)
8914          (gnus-request-move-article
8915           article                       ; Article to move
8916           gnus-newsgroup-name           ; From newsgroup
8917           (nth 1 (gnus-find-method-for-group
8918                   gnus-newsgroup-name)) ; Server
8919           (list 'gnus-request-accept-article
8920                 to-newsgroup (list 'quote select-method)
8921                 (not articles) t)       ; Accept form
8922           (not articles)))              ; Only save nov last time
8923         ;; Copy the article.
8924         ((eq action 'copy)
8925          (save-excursion
8926            (set-buffer copy-buf)
8927            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8928              (gnus-request-accept-article
8929               to-newsgroup select-method (not articles) t))))
8930         ;; Crosspost the article.
8931         ((eq action 'crosspost)
8932          (let ((xref (message-tokenize-header
8933                       (mail-header-xref (gnus-summary-article-header article))
8934                       " ")))
8935            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8936                                   ":" (number-to-string article)))
8937            (unless xref
8938              (setq xref (list (system-name))))
8939            (setq new-xref
8940                  (concat
8941                   (mapconcat 'identity
8942                              (delete "Xref:" (delete new-xref xref))
8943                              " ")
8944                   " " new-xref))
8945            (save-excursion
8946              (set-buffer copy-buf)
8947              ;; First put the article in the destination group.
8948              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8949              (when (consp (setq art-group
8950                                 (gnus-request-accept-article
8951                                  to-newsgroup select-method (not articles))))
8952                (setq new-xref (concat new-xref " " (car art-group)
8953                                       ":"
8954                                       (number-to-string (cdr art-group))))
8955                ;; Now we have the new Xrefs header, so we insert
8956                ;; it and replace the new article.
8957                (nnheader-replace-header "Xref" new-xref)
8958                (gnus-request-replace-article
8959                 (cdr art-group) to-newsgroup (current-buffer))
8960                art-group))))))
8961       (cond
8962        ((not art-group)
8963         (gnus-message 1 "Couldn't %s article %s: %s"
8964                       (cadr (assq action names)) article
8965                       (nnheader-get-report (car to-method))))
8966        ((eq art-group 'junk)
8967         (when (eq action 'move)
8968           (gnus-summary-mark-article article gnus-canceled-mark)
8969           (gnus-message 4 "Deleted article %s" article)
8970           ;; run the delete hook
8971           (run-hook-with-args 'gnus-summary-article-delete-hook
8972                               action
8973                               (gnus-data-header
8974                                (assoc article (gnus-data-list nil)))
8975                               gnus-newsgroup-name nil
8976                               select-method)))
8977        (t
8978         (let* ((pto-group (gnus-group-prefixed-name
8979                            (car art-group) to-method))
8980                (entry
8981                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8982                (info (nth 2 entry))
8983                (to-group (gnus-info-group info))
8984                to-marks)
8985           ;; Update the group that has been moved to.
8986           (when (and info
8987                      (memq action '(move copy)))
8988             (unless (member to-group to-groups)
8989               (push to-group to-groups))
8990
8991             (unless (memq article gnus-newsgroup-unreads)
8992               (push 'read to-marks)
8993               (gnus-info-set-read
8994                info (gnus-add-to-range (gnus-info-read info)
8995                                        (list (cdr art-group)))))
8996
8997             ;; See whether the article is to be put in the cache.
8998             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8999                              default-marks
9000                            no-expire-marks))
9001                   (to-article (cdr art-group)))
9002
9003               ;; Enter the article into the cache in the new group,
9004               ;; if that is required.
9005               (when gnus-use-cache
9006                 (gnus-cache-possibly-enter-article
9007                  to-group to-article
9008                  (let ((header (copy-sequence
9009                                 (gnus-summary-article-header article))))
9010                    (mail-header-set-number header to-article)
9011                    header)
9012                  (memq article gnus-newsgroup-marked)
9013                  (memq article gnus-newsgroup-dormant)
9014                  (memq article gnus-newsgroup-unreads)))
9015
9016               (when gnus-preserve-marks
9017                 ;; Copy any marks over to the new group.
9018                 (when (and (equal to-group gnus-newsgroup-name)
9019                            (not (memq article gnus-newsgroup-unreads)))
9020                   ;; Mark this article as read in this group.
9021                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9022                   (setcdr (gnus-active to-group) to-article)
9023                   (setcdr gnus-newsgroup-active to-article))
9024
9025                 (while marks
9026                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9027                     (when (memq article (symbol-value
9028                                          (intern (format "gnus-newsgroup-%s"
9029                                                          (caar marks)))))
9030                       (push (cdar marks) to-marks)
9031                       ;; If the other group is the same as this group,
9032                       ;; then we have to add the mark to the list.
9033                       (when (equal to-group gnus-newsgroup-name)
9034                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9035                              (cons to-article
9036                                    (symbol-value
9037                                     (intern (format "gnus-newsgroup-%s"
9038                                                     (caar marks)))))))
9039                       ;; Copy the marks to other group.
9040                       (gnus-add-marked-articles
9041                        to-group (cdar marks) (list to-article) info)))
9042                   (setq marks (cdr marks)))
9043
9044                 (gnus-request-set-mark
9045                  to-group (list (list (list to-article) 'add to-marks))))
9046
9047               (gnus-dribble-enter
9048                (concat "(gnus-group-set-info '"
9049                        (gnus-prin1-to-string (gnus-get-info to-group))
9050                        ")"))))
9051
9052           ;; Update the Xref header in this article to point to
9053           ;; the new crossposted article we have just created.
9054           (when (eq action 'crosspost)
9055             (save-excursion
9056               (set-buffer copy-buf)
9057               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9058               (nnheader-replace-header "Xref" new-xref)
9059               (gnus-request-replace-article
9060                article gnus-newsgroup-name (current-buffer))))
9061
9062           ;; run the move/copy/crosspost/respool hook
9063           (run-hook-with-args 'gnus-summary-article-move-hook 
9064                               action
9065                               (gnus-data-header 
9066                                (assoc article (gnus-data-list nil)))
9067                               gnus-newsgroup-name
9068                               to-newsgroup
9069                               select-method))
9070
9071         ;;;!!!Why is this necessary?
9072         (set-buffer gnus-summary-buffer)
9073         
9074         (gnus-summary-goto-subject article)
9075         (when (eq action 'move)
9076           (gnus-summary-mark-article article gnus-canceled-mark))))
9077       (gnus-summary-remove-process-mark article))
9078     ;; Re-activate all groups that have been moved to.
9079     (save-excursion
9080       (set-buffer gnus-group-buffer)
9081       (let ((gnus-group-marked to-groups))
9082         (gnus-group-get-new-news-this-group nil t)))
9083
9084     (gnus-kill-buffer copy-buf)
9085     (gnus-summary-position-point)
9086     (gnus-set-mode-line 'summary)))
9087
9088 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9089   "Move the current article to a different newsgroup.
9090 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9091 When called interactively, if TO-NEWSGROUP is nil, use the value of
9092 the variable `gnus-move-split-methods' for finding a default target
9093 newsgroup.
9094 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9095 re-spool using this method."
9096   (interactive "P")
9097   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9098
9099 (defun gnus-summary-crosspost-article (&optional n)
9100   "Crosspost the current article to some other group."
9101   (interactive "P")
9102   (gnus-summary-move-article n nil nil 'crosspost))
9103
9104 (defcustom gnus-summary-respool-default-method nil
9105   "Default method type for respooling an article.
9106 If nil, use to the current newsgroup method."
9107   :type 'symbol
9108   :group 'gnus-summary-mail)
9109
9110 (defcustom gnus-summary-display-while-building nil
9111   "If not-nil, show and update the summary buffer as it's being built.
9112 If the value is t, update the buffer after every line is inserted.  If
9113 the value is an integer (N), update the display every N lines."
9114   :group 'gnus-thread
9115   :type '(choice (const :tag "off" nil)
9116                  number
9117                  (const :tag "frequently" t)))
9118
9119 (defun gnus-summary-respool-article (&optional n method)
9120   "Respool the current article.
9121 The article will be squeezed through the mail spooling process again,
9122 which means that it will be put in some mail newsgroup or other
9123 depending on `nnmail-split-methods'.
9124 If N is a positive number, respool the N next articles.
9125 If N is a negative number, respool the N previous articles.
9126 If N is nil and any articles have been marked with the process mark,
9127 respool those articles instead.
9128
9129 Respooling can be done both from mail groups and \"real\" newsgroups.
9130 In the former case, the articles in question will be moved from the
9131 current group into whatever groups they are destined to.  In the
9132 latter case, they will be copied into the relevant groups."
9133   (interactive
9134    (list current-prefix-arg
9135          (let* ((methods (gnus-methods-using 'respool))
9136                 (methname
9137                  (symbol-name (or gnus-summary-respool-default-method
9138                                   (car (gnus-find-method-for-group
9139                                         gnus-newsgroup-name)))))
9140                 (method
9141                  (gnus-completing-read-with-default
9142                   methname "What backend do you want to use when respooling?"
9143                   methods nil t nil 'gnus-mail-method-history))
9144                 ms)
9145            (cond
9146             ((zerop (length (setq ms (gnus-servers-using-backend
9147                                       (intern method)))))
9148              (list (intern method) ""))
9149             ((= 1 (length ms))
9150              (car ms))
9151             (t
9152              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9153                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9154                            ms-alist))))))))
9155   (unless method
9156     (error "No method given for respooling"))
9157   (if (assoc (symbol-name
9158               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9159              (gnus-methods-using 'respool))
9160       (gnus-summary-move-article n nil method)
9161     (gnus-summary-copy-article n nil method)))
9162
9163 (defun gnus-summary-import-article (file &optional edit)
9164   "Import an arbitrary file into a mail newsgroup."
9165   (interactive "fImport file: \nP")
9166   (let ((group gnus-newsgroup-name)
9167         (now (current-time))
9168         atts lines group-art)
9169     (unless (gnus-check-backend-function 'request-accept-article group)
9170       (error "%s does not support article importing" group))
9171     (or (file-readable-p file)
9172         (not (file-regular-p file))
9173         (error "Can't read %s" file))
9174     (save-excursion
9175       (set-buffer (gnus-get-buffer-create " *import file*"))
9176       (erase-buffer)
9177       (nnheader-insert-file-contents file)
9178       (goto-char (point-min))
9179       (if (nnheader-article-p)
9180           (save-restriction
9181             (goto-char (point-min))
9182             (search-forward "\n\n" nil t)
9183             (narrow-to-region (point-min) (1- (point)))
9184             (goto-char (point-min))
9185             (unless (re-search-forward "^date:" nil t)
9186               (goto-char (point-max))
9187               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9188         ;; This doesn't look like an article, so we fudge some headers.
9189         (setq atts (file-attributes file)
9190               lines (count-lines (point-min) (point-max)))
9191         (insert "From: " (read-string "From: ") "\n"
9192                 "Subject: " (read-string "Subject: ") "\n"
9193                 "Date: " (message-make-date (nth 5 atts)) "\n"
9194                 "Message-ID: " (message-make-message-id) "\n"
9195                 "Lines: " (int-to-string lines) "\n"
9196                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9197       (setq group-art (gnus-request-accept-article group nil t))
9198       (kill-buffer (current-buffer)))
9199     (setq gnus-newsgroup-active (gnus-activate-group group))
9200     (forward-line 1)
9201     (gnus-summary-goto-article (cdr group-art) nil t)
9202     (when edit
9203       (gnus-summary-edit-article))))
9204
9205 (defun gnus-summary-create-article ()
9206   "Create an article in a mail newsgroup."
9207   (interactive)
9208   (let ((group gnus-newsgroup-name)
9209         (now (current-time))
9210         group-art)
9211     (unless (gnus-check-backend-function 'request-accept-article group)
9212       (error "%s does not support article importing" group))
9213     (save-excursion
9214       (set-buffer (gnus-get-buffer-create " *import file*"))
9215       (erase-buffer)
9216       (goto-char (point-min))
9217       ;; This doesn't look like an article, so we fudge some headers.
9218       (insert "From: " (read-string "From: ") "\n"
9219               "Subject: " (read-string "Subject: ") "\n"
9220               "Date: " (message-make-date now) "\n"
9221               "Message-ID: " (message-make-message-id) "\n")
9222       (setq group-art (gnus-request-accept-article group nil t))
9223       (kill-buffer (current-buffer)))
9224     (setq gnus-newsgroup-active (gnus-activate-group group))
9225     (forward-line 1)
9226     (gnus-summary-goto-article (cdr group-art) nil t)
9227     (gnus-summary-edit-article)))
9228
9229 (defun gnus-summary-article-posted-p ()
9230   "Say whether the current (mail) article is available from news as well.
9231 This will be the case if the article has both been mailed and posted."
9232   (interactive)
9233   (let ((id (mail-header-references (gnus-summary-article-header)))
9234         (gnus-override-method (car (gnus-refer-article-methods))))
9235     (if (gnus-request-head id "")
9236         (gnus-message 2 "The current message was found on %s"
9237                       gnus-override-method)
9238       (gnus-message 2 "The current message couldn't be found on %s"
9239                     gnus-override-method)
9240       nil)))
9241
9242 (defun gnus-summary-expire-articles (&optional now)
9243   "Expire all articles that are marked as expirable in the current group."
9244   (interactive)
9245   (when (and (not gnus-group-is-exiting-without-update-p)
9246              (gnus-check-backend-function
9247               'request-expire-articles gnus-newsgroup-name))
9248     ;; This backend supports expiry.
9249     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9250            (expirable (if total
9251                           (progn
9252                             ;; We need to update the info for
9253                             ;; this group for `gnus-list-of-read-articles'
9254                             ;; to give us the right answer.
9255                             (gnus-run-hooks 'gnus-exit-group-hook)
9256                             (gnus-summary-update-info)
9257                             (gnus-list-of-read-articles gnus-newsgroup-name))
9258                         (setq gnus-newsgroup-expirable
9259                               (sort gnus-newsgroup-expirable '<))))
9260            (expiry-wait (if now 'immediate
9261                           (gnus-group-find-parameter
9262                            gnus-newsgroup-name 'expiry-wait)))
9263            (nnmail-expiry-target
9264             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9265                 nnmail-expiry-target))
9266            es)
9267       (when expirable
9268         ;; There are expirable articles in this group, so we run them
9269         ;; through the expiry process.
9270         (gnus-message 6 "Expiring articles...")
9271         (unless (gnus-check-group gnus-newsgroup-name)
9272           (error "Can't open server for %s" gnus-newsgroup-name))
9273         ;; The list of articles that weren't expired is returned.
9274         (save-excursion
9275           (if expiry-wait
9276               (let ((nnmail-expiry-wait-function nil)
9277                     (nnmail-expiry-wait expiry-wait))
9278                 (setq es (gnus-request-expire-articles
9279                           expirable gnus-newsgroup-name)))
9280             (setq es (gnus-request-expire-articles
9281                       expirable gnus-newsgroup-name)))
9282           (unless total
9283             (setq gnus-newsgroup-expirable es))
9284           ;; We go through the old list of expirable, and mark all
9285           ;; really expired articles as nonexistent.
9286           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9287             (let ((gnus-use-cache nil))
9288               (dolist (article expirable)
9289                 (when (and (not (memq article es))
9290                            (gnus-data-find article))
9291                   (gnus-summary-mark-article article gnus-canceled-mark)
9292                   (run-hook-with-args 'gnus-summary-article-expire-hook
9293                                       'delete
9294                                       (gnus-data-header
9295                                        (assoc article (gnus-data-list nil)))
9296                                       gnus-newsgroup-name
9297                                       nil
9298                                       nil))))))
9299         (gnus-message 6 "Expiring articles...done")))))
9300
9301 (defun gnus-summary-expire-articles-now ()
9302   "Expunge all expirable articles in the current group.
9303 This means that *all* articles that are marked as expirable will be
9304 deleted forever, right now."
9305   (interactive)
9306   (or gnus-expert-user
9307       (gnus-yes-or-no-p
9308        "Are you really, really, really sure you want to delete all these messages? ")
9309       (error "Phew!"))
9310   (gnus-summary-expire-articles t))
9311
9312 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9313 (defun gnus-summary-delete-article (&optional n)
9314   "Delete the N next (mail) articles.
9315 This command actually deletes articles.  This is not a marking
9316 command.  The article will disappear forever from your life, never to
9317 return.
9318 If N is negative, delete backwards.
9319 If N is nil and articles have been marked with the process mark,
9320 delete these instead."
9321   (interactive "P")
9322   (unless (gnus-check-backend-function 'request-expire-articles
9323                                        gnus-newsgroup-name)
9324     (error "The current newsgroup does not support article deletion"))
9325   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9326     (error "Couldn't open server"))
9327   ;; Compute the list of articles to delete.
9328   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9329         (nnmail-expiry-target 'delete)
9330         not-deleted)
9331     (if (and gnus-novice-user
9332              (not (gnus-yes-or-no-p
9333                    (format "Do you really want to delete %s forever? "
9334                            (if (> (length articles) 1)
9335                                (format "these %s articles" (length articles))
9336                              "this article")))))
9337         ()
9338       ;; Delete the articles.
9339       (setq not-deleted (gnus-request-expire-articles
9340                          articles gnus-newsgroup-name 'force))
9341       (while articles
9342         (gnus-summary-remove-process-mark (car articles))
9343         ;; The backend might not have been able to delete the article
9344         ;; after all.
9345         (unless (memq (car articles) not-deleted)
9346           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9347         (let* ((article (car articles))
9348                (id (mail-header-id (gnus-data-header 
9349                                     (assoc article (gnus-data-list nil))))))
9350           (run-hook-with-args 'gnus-summary-article-delete-hook
9351                               'delete id gnus-newsgroup-name nil
9352                               nil))
9353         (setq articles (cdr articles)))
9354       (when not-deleted
9355         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9356     (gnus-summary-position-point)
9357     (gnus-set-mode-line 'summary)
9358     not-deleted))
9359
9360 (defun gnus-summary-edit-article (&optional force)
9361   "Edit the current article.
9362 This will have permanent effect only in mail groups.
9363 If FORCE is non-nil, allow editing of articles even in read-only
9364 groups."
9365   (interactive "P")
9366   (save-excursion
9367     (set-buffer gnus-summary-buffer)
9368     (let ((mail-parse-charset gnus-newsgroup-charset)
9369           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9370       (gnus-set-global-variables)
9371       (when (and (not force)
9372                  (gnus-group-read-only-p))
9373         (error "The current newsgroup does not support article editing"))
9374       (gnus-summary-show-article t)
9375       (gnus-article-edit-article
9376        'ignore
9377        `(lambda (no-highlight)
9378           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9379                 (message-options message-options)
9380                 (message-options-set-recipient)
9381                 (mail-parse-ignored-charsets
9382                  ',gnus-newsgroup-ignored-charsets))
9383             (gnus-summary-edit-article-done
9384              ,(or (mail-header-references gnus-current-headers) "")
9385              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9386
9387 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9388
9389 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9390                                                  no-highlight)
9391   "Make edits to the current article permanent."
9392   (interactive)
9393   (save-excursion
9394     ;; The buffer restriction contains the entire article if it exists.
9395     (when (article-goto-body)
9396       (let ((lines (count-lines (point) (point-max)))
9397             (length (- (point-max) (point)))
9398             (case-fold-search t)
9399             (body (copy-marker (point))))
9400         (goto-char (point-min))
9401         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9402           (delete-region (match-beginning 1) (match-end 1))
9403           (insert (number-to-string length)))
9404         (goto-char (point-min))
9405         (when (re-search-forward
9406                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9407           (delete-region (match-beginning 1) (match-end 1))
9408           (insert (number-to-string length)))
9409         (goto-char (point-min))
9410         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9411           (delete-region (match-beginning 1) (match-end 1))
9412           (insert (number-to-string lines))))))
9413   ;; Replace the article.
9414   (let ((buf (current-buffer)))
9415     (with-temp-buffer
9416       (insert-buffer-substring buf)
9417
9418       (if (and (not read-only)
9419                (not (gnus-request-replace-article
9420                      (cdr gnus-article-current) (car gnus-article-current)
9421                      (current-buffer) t)))
9422           (error "Couldn't replace article")
9423         ;; Update the summary buffer.
9424         (if (and references
9425                  (equal (message-tokenize-header references " ")
9426                         (message-tokenize-header
9427                          (or (message-fetch-field "references") "") " ")))
9428             ;; We only have to update this line.
9429             (save-excursion
9430               (save-restriction
9431                 (message-narrow-to-head)
9432                 (let ((head (buffer-string))
9433                       header)
9434                   (with-temp-buffer
9435                     (insert (format "211 %d Article retrieved.\n"
9436                                     (cdr gnus-article-current)))
9437                     (insert head)
9438                     (insert ".\n")
9439                     (let ((nntp-server-buffer (current-buffer)))
9440                       (setq header (car (gnus-get-newsgroup-headers
9441                                          nil t))))
9442                     (save-excursion
9443                       (set-buffer gnus-summary-buffer)
9444                       (gnus-data-set-header
9445                        (gnus-data-find (cdr gnus-article-current))
9446                        header)
9447                       (gnus-summary-update-article-line
9448                        (cdr gnus-article-current) header)
9449                       (if (gnus-summary-goto-subject
9450                            (cdr gnus-article-current) nil t)
9451                           (gnus-summary-update-secondary-mark
9452                            (cdr gnus-article-current))))))))
9453           ;; Update threads.
9454           (set-buffer (or buffer gnus-summary-buffer))
9455           (gnus-summary-update-article (cdr gnus-article-current))
9456           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9457               (gnus-summary-update-secondary-mark
9458                (cdr gnus-article-current))))
9459         ;; Prettify the article buffer again.
9460         (unless no-highlight
9461           (save-excursion
9462             (set-buffer gnus-article-buffer)
9463             ;;;!!! Fix this -- article should be rehighlighted.
9464             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9465             (set-buffer gnus-original-article-buffer)
9466             (gnus-request-article
9467              (cdr gnus-article-current)
9468              (car gnus-article-current) (current-buffer))))
9469         ;; Prettify the summary buffer line.
9470         (when (gnus-visual-p 'summary-highlight 'highlight)
9471           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9472
9473 (defun gnus-summary-edit-wash (key)
9474   "Perform editing command KEY in the article buffer."
9475   (interactive
9476    (list
9477     (progn
9478       (message "%s" (concat (this-command-keys) "- "))
9479       (read-char))))
9480   (message "")
9481   (gnus-summary-edit-article)
9482   (execute-kbd-macro (concat (this-command-keys) key))
9483   (gnus-article-edit-done))
9484
9485 ;;; Respooling
9486
9487 (defun gnus-summary-respool-query (&optional silent trace)
9488   "Query where the respool algorithm would put this article."
9489   (interactive)
9490   (let (gnus-mark-article-hook)
9491     (gnus-summary-select-article)
9492     (save-excursion
9493       (set-buffer gnus-original-article-buffer)
9494       (save-restriction
9495         (message-narrow-to-head)
9496         (let ((groups (nnmail-article-group 'identity trace)))
9497           (unless silent
9498             (if groups
9499                 (message "This message would go to %s"
9500                          (mapconcat 'car groups ", "))
9501               (message "This message would go to no groups"))
9502             groups))))))
9503
9504 (defun gnus-summary-respool-trace ()
9505   "Trace where the respool algorithm would put this article.
9506 Display a buffer showing all fancy splitting patterns which matched."
9507   (interactive)
9508   (gnus-summary-respool-query nil t))
9509
9510 ;; Summary marking commands.
9511
9512 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9513   "Mark articles which has the same subject as read, and then select the next.
9514 If UNMARK is positive, remove any kind of mark.
9515 If UNMARK is negative, tick articles."
9516   (interactive "P")
9517   (when unmark
9518     (setq unmark (prefix-numeric-value unmark)))
9519   (let ((count
9520          (gnus-summary-mark-same-subject
9521           (gnus-summary-article-subject) unmark)))
9522     ;; Select next unread article.  If auto-select-same mode, should
9523     ;; select the first unread article.
9524     (gnus-summary-next-article t (and gnus-auto-select-same
9525                                       (gnus-summary-article-subject)))
9526     (gnus-message 7 "%d article%s marked as %s"
9527                   count (if (= count 1) " is" "s are")
9528                   (if unmark "unread" "read"))))
9529
9530 (defun gnus-summary-kill-same-subject (&optional unmark)
9531   "Mark articles which has the same subject as read.
9532 If UNMARK is positive, remove any kind of mark.
9533 If UNMARK is negative, tick articles."
9534   (interactive "P")
9535   (when unmark
9536     (setq unmark (prefix-numeric-value unmark)))
9537   (let ((count
9538          (gnus-summary-mark-same-subject
9539           (gnus-summary-article-subject) unmark)))
9540     ;; If marked as read, go to next unread subject.
9541     (when (null unmark)
9542       ;; Go to next unread subject.
9543       (gnus-summary-next-subject 1 t))
9544     (gnus-message 7 "%d articles are marked as %s"
9545                   count (if unmark "unread" "read"))))
9546
9547 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9548   "Mark articles with same SUBJECT as read, and return marked number.
9549 If optional argument UNMARK is positive, remove any kinds of marks.
9550 If optional argument UNMARK is negative, mark articles as unread instead."
9551   (let ((count 1))
9552     (save-excursion
9553       (cond
9554        ((null unmark)                   ; Mark as read.
9555         (while (and
9556                 (progn
9557                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9558                   (gnus-summary-show-thread) t)
9559                 (gnus-summary-find-subject subject))
9560           (setq count (1+ count))))
9561        ((> unmark 0)                    ; Tick.
9562         (while (and
9563                 (progn
9564                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9565                   (gnus-summary-show-thread) t)
9566                 (gnus-summary-find-subject subject))
9567           (setq count (1+ count))))
9568        (t                               ; Mark as unread.
9569         (while (and
9570                 (progn
9571                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9572                   (gnus-summary-show-thread) t)
9573                 (gnus-summary-find-subject subject))
9574           (setq count (1+ count)))))
9575       (gnus-set-mode-line 'summary)
9576       ;; Return the number of marked articles.
9577       count)))
9578
9579 (defun gnus-summary-mark-as-processable (n &optional unmark)
9580   "Set the process mark on the next N articles.
9581 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9582 the process mark instead.  The difference between N and the actual
9583 number of articles marked is returned."
9584   (interactive "P")
9585   (if (and (null n) (gnus-region-active-p))
9586       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9587     (setq n (prefix-numeric-value n))
9588     (let ((backward (< n 0))
9589           (n (abs n)))
9590       (while (and
9591               (> n 0)
9592               (if unmark
9593                   (gnus-summary-remove-process-mark
9594                    (gnus-summary-article-number))
9595                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9596               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9597         (setq n (1- n)))
9598       (when (/= 0 n)
9599         (gnus-message 7 "No more articles"))
9600       (gnus-summary-recenter)
9601       (gnus-summary-position-point)
9602       n)))
9603
9604 (defun gnus-summary-unmark-as-processable (n)
9605   "Remove the process mark from the next N articles.
9606 If N is negative, unmark backward instead.  The difference between N and
9607 the actual number of articles unmarked is returned."
9608   (interactive "P")
9609   (gnus-summary-mark-as-processable n t))
9610
9611 (defun gnus-summary-unmark-all-processable ()
9612   "Remove the process mark from all articles."
9613   (interactive)
9614   (save-excursion
9615     (while gnus-newsgroup-processable
9616       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9617   (gnus-summary-position-point))
9618
9619 (defun gnus-summary-add-mark (article type)
9620   "Mark ARTICLE with a mark of TYPE."
9621   (let ((vtype (car (assq type gnus-article-mark-lists)))
9622         var)
9623     (if (not vtype)
9624         (error "No such mark type: %s" type)
9625       (setq var (intern (format "gnus-newsgroup-%s" type)))
9626       (set var (cons article (symbol-value var)))
9627       (if (memq type '(processable cached replied forwarded recent saved))
9628           (gnus-summary-update-secondary-mark article)
9629         ;;; !!! This is bogus.  We should find out what primary
9630         ;;; !!! mark we want to set.
9631         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9632
9633 (defun gnus-summary-mark-as-expirable (n)
9634   "Mark N articles forward as expirable.
9635 If N is negative, mark backward instead.  The difference between N and
9636 the actual number of articles marked is returned."
9637   (interactive "p")
9638   (gnus-summary-mark-forward n gnus-expirable-mark))
9639
9640 (defun gnus-summary-mark-as-spam (n)
9641   "Mark N articles forward as spam.
9642 If N is negative, mark backward instead.  The difference between N and
9643 the actual number of articles marked is returned."
9644   (interactive "p")
9645   (gnus-summary-mark-forward n gnus-spam-mark))
9646
9647 (defun gnus-summary-mark-article-as-replied (article)
9648   "Mark ARTICLE as replied to and update the summary line.
9649 ARTICLE can also be a list of articles."
9650   (interactive (list (gnus-summary-article-number)))
9651   (let ((articles (if (listp article) article (list article))))
9652     (dolist (article articles)
9653       (unless (numberp article)
9654         (error "%s is not a number" article))
9655       (push article gnus-newsgroup-replied)
9656       (let ((buffer-read-only nil))
9657         (when (gnus-summary-goto-subject article nil t)
9658           (gnus-summary-update-secondary-mark article))))))
9659
9660 (defun gnus-summary-mark-article-as-forwarded (article)
9661   "Mark ARTICLE as forwarded and update the summary line.
9662 ARTICLE can also be a list of articles."
9663   (let ((articles (if (listp article) article (list article))))
9664     (dolist (article articles)
9665       (push article gnus-newsgroup-forwarded)
9666       (let ((buffer-read-only nil))
9667         (when (gnus-summary-goto-subject article nil t)
9668           (gnus-summary-update-secondary-mark article))))))
9669
9670 (defun gnus-summary-set-bookmark (article)
9671   "Set a bookmark in current article."
9672   (interactive (list (gnus-summary-article-number)))
9673   (when (or (not (get-buffer gnus-article-buffer))
9674             (not gnus-current-article)
9675             (not gnus-article-current)
9676             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9677     (error "No current article selected"))
9678   ;; Remove old bookmark, if one exists.
9679   (gnus-pull article gnus-newsgroup-bookmarks)
9680   ;; Set the new bookmark, which is on the form
9681   ;; (article-number . line-number-in-body).
9682   (push
9683    (cons article
9684          (save-excursion
9685            (set-buffer gnus-article-buffer)
9686            (count-lines
9687             (min (point)
9688                  (save-excursion
9689                    (article-goto-body)
9690                    (point)))
9691             (point))))
9692    gnus-newsgroup-bookmarks)
9693   (gnus-message 6 "A bookmark has been added to the current article."))
9694
9695 (defun gnus-summary-remove-bookmark (article)
9696   "Remove the bookmark from the current article."
9697   (interactive (list (gnus-summary-article-number)))
9698   ;; Remove old bookmark, if one exists.
9699   (if (not (assq article gnus-newsgroup-bookmarks))
9700       (gnus-message 6 "No bookmark in current article.")
9701     (gnus-pull article gnus-newsgroup-bookmarks)
9702     (gnus-message 6 "Removed bookmark.")))
9703
9704 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9705 (defun gnus-summary-mark-as-dormant (n)
9706   "Mark N articles forward as dormant.
9707 If N is negative, mark backward instead.  The difference between N and
9708 the actual number of articles marked is returned."
9709   (interactive "p")
9710   (gnus-summary-mark-forward n gnus-dormant-mark))
9711
9712 (defun gnus-summary-set-process-mark (article)
9713   "Set the process mark on ARTICLE and update the summary line."
9714   (setq gnus-newsgroup-processable
9715         (cons article
9716               (delq article gnus-newsgroup-processable)))
9717   (when (gnus-summary-goto-subject article)
9718     (gnus-summary-show-thread)
9719     (gnus-summary-goto-subject article)
9720     (gnus-summary-update-secondary-mark article)))
9721
9722 (defun gnus-summary-remove-process-mark (article)
9723   "Remove the process mark from ARTICLE and update the summary line."
9724   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9725   (when (gnus-summary-goto-subject article)
9726     (gnus-summary-show-thread)
9727     (gnus-summary-goto-subject article)
9728     (gnus-summary-update-secondary-mark article)))
9729
9730 (defun gnus-summary-set-saved-mark (article)
9731   "Set the process mark on ARTICLE and update the summary line."
9732   (push article gnus-newsgroup-saved)
9733   (when (gnus-summary-goto-subject article)
9734     (gnus-summary-update-secondary-mark article)))
9735
9736 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9737   "Mark N articles as read forwards.
9738 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9739 The difference between N and the actual number of articles marked is
9740 returned.
9741 If NO-EXPIRE, auto-expiry will be inhibited."
9742   (interactive "p")
9743   (gnus-summary-show-thread)
9744   (let ((backward (< n 0))
9745         (gnus-summary-goto-unread
9746          (and gnus-summary-goto-unread
9747               (not (eq gnus-summary-goto-unread 'never))
9748               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9749                                     gnus-ticked-mark gnus-dormant-mark)))))
9750         (n (abs n))
9751         (mark (or mark gnus-del-mark)))
9752     (while (and (> n 0)
9753                 (gnus-summary-mark-article nil mark no-expire)
9754                 (zerop (gnus-summary-next-subject
9755                         (if backward -1 1)
9756                         (and gnus-summary-goto-unread
9757                              (not (eq gnus-summary-goto-unread 'never)))
9758                         t)))
9759       (setq n (1- n)))
9760     (when (/= 0 n)
9761       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9762     (gnus-summary-recenter)
9763     (gnus-summary-position-point)
9764     (gnus-set-mode-line 'summary)
9765     n))
9766
9767 (defun gnus-summary-mark-article-as-read (mark)
9768   "Mark the current article quickly as read with MARK."
9769   (let ((article (gnus-summary-article-number)))
9770     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9771     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9772     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9773     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9774     (push (cons article mark) gnus-newsgroup-reads)
9775     ;; Possibly remove from cache, if that is used.
9776     (when gnus-use-cache
9777       (gnus-cache-enter-remove-article article))
9778     ;; Allow the backend to change the mark.
9779     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9780     ;; Check for auto-expiry.
9781     (when (and gnus-newsgroup-auto-expire
9782                (memq mark gnus-auto-expirable-marks))
9783       (setq mark gnus-expirable-mark)
9784       ;; Let the backend know about the mark change.
9785       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9786       (push article gnus-newsgroup-expirable))
9787     ;; Set the mark in the buffer.
9788     (gnus-summary-update-mark mark 'unread)
9789     t))
9790
9791 (defun gnus-summary-mark-article-as-unread (mark)
9792   "Mark the current article quickly as unread with MARK."
9793   (let* ((article (gnus-summary-article-number))
9794          (old-mark (gnus-summary-article-mark article)))
9795     ;; Allow the backend to change the mark.
9796     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9797     (if (eq mark old-mark)
9798         t
9799       (if (<= article 0)
9800           (progn
9801             (gnus-error 1 "Can't mark negative article numbers")
9802             nil)
9803         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9804         (setq gnus-newsgroup-spam-marked
9805               (delq article gnus-newsgroup-spam-marked))
9806         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9807         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9808         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9809         (cond ((= mark gnus-ticked-mark)
9810                (setq gnus-newsgroup-marked
9811                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9812                                               article)))
9813               ((= mark gnus-spam-mark)
9814                (setq gnus-newsgroup-spam-marked
9815                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9816                                               article)))
9817               ((= mark gnus-dormant-mark)
9818                (setq gnus-newsgroup-dormant
9819                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9820                                               article)))
9821               (t
9822                (setq gnus-newsgroup-unreads
9823                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9824                                               article))))
9825         (gnus-pull article gnus-newsgroup-reads)
9826
9827         ;; See whether the article is to be put in the cache.
9828         (and gnus-use-cache
9829              (vectorp (gnus-summary-article-header article))
9830              (save-excursion
9831                (gnus-cache-possibly-enter-article
9832                 gnus-newsgroup-name article
9833                 (gnus-summary-article-header article)
9834                 (= mark gnus-ticked-mark)
9835                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9836
9837         ;; Fix the mark.
9838         (gnus-summary-update-mark mark 'unread)
9839         t))))
9840
9841 (defun gnus-summary-mark-article (&optional article mark no-expire)
9842   "Mark ARTICLE with MARK.  MARK can be any character.
9843 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9844 `??' (dormant) and `?E' (expirable).
9845 If MARK is nil, then the default character `?r' is used.
9846 If ARTICLE is nil, then the article on the current line will be
9847 marked.
9848 If NO-EXPIRE, auto-expiry will be inhibited."
9849   ;; The mark might be a string.
9850   (when (stringp mark)
9851     (setq mark (aref mark 0)))
9852   ;; If no mark is given, then we check auto-expiring.
9853   (when (null mark)
9854     (setq mark gnus-del-mark))
9855   (when (and (not no-expire)
9856              gnus-newsgroup-auto-expire
9857              (memq mark gnus-auto-expirable-marks))
9858     (setq mark gnus-expirable-mark))
9859   (let ((article (or article (gnus-summary-article-number)))
9860         (old-mark (gnus-summary-article-mark article)))
9861     ;; Allow the backend to change the mark.
9862     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9863     (if (eq mark old-mark)
9864         t
9865       (unless article
9866         (error "No article on current line"))
9867       (if (not (if (or (= mark gnus-unread-mark)
9868                        (= mark gnus-ticked-mark)
9869                        (= mark gnus-spam-mark)
9870                        (= mark gnus-dormant-mark))
9871                    (gnus-mark-article-as-unread article mark)
9872                  (gnus-mark-article-as-read article mark)))
9873           t
9874         ;; See whether the article is to be put in the cache.
9875         (and gnus-use-cache
9876              (not (= mark gnus-canceled-mark))
9877              (vectorp (gnus-summary-article-header article))
9878              (save-excursion
9879                (gnus-cache-possibly-enter-article
9880                 gnus-newsgroup-name article
9881                 (gnus-summary-article-header article)
9882                 (= mark gnus-ticked-mark)
9883                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9884
9885         (when (gnus-summary-goto-subject article nil t)
9886           (let ((buffer-read-only nil))
9887             (gnus-summary-show-thread)
9888             ;; Fix the mark.
9889             (gnus-summary-update-mark mark 'unread)
9890             t))))))
9891
9892 (defun gnus-summary-update-secondary-mark (article)
9893   "Update the secondary (read, process, cache) mark."
9894   (gnus-summary-update-mark
9895    (cond ((memq article gnus-newsgroup-processable)
9896           gnus-process-mark)
9897          ((memq article gnus-newsgroup-cached)
9898           gnus-cached-mark)
9899          ((memq article gnus-newsgroup-replied)
9900           gnus-replied-mark)
9901          ((memq article gnus-newsgroup-forwarded)
9902           gnus-forwarded-mark)
9903          ((memq article gnus-newsgroup-saved)
9904           gnus-saved-mark)
9905          ((memq article gnus-newsgroup-recent)
9906           gnus-recent-mark)
9907          ((memq article gnus-newsgroup-unseen)
9908           gnus-unseen-mark)
9909          (t gnus-no-mark))
9910    'replied)
9911   (when (gnus-visual-p 'summary-highlight 'highlight)
9912     (gnus-run-hooks 'gnus-summary-update-hook))
9913   t)
9914
9915 (defun gnus-summary-update-download-mark (article)
9916   "Update the download mark."
9917   (gnus-summary-update-mark
9918    (cond ((memq article gnus-newsgroup-undownloaded) 
9919           gnus-undownloaded-mark)
9920          (gnus-newsgroup-agentized
9921           gnus-downloaded-mark)
9922          (t
9923           gnus-no-mark))
9924    'download)
9925   (gnus-summary-update-line t)
9926   t)
9927
9928 (defun gnus-summary-update-mark (mark type)
9929   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9930         (buffer-read-only nil))
9931     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9932     (when forward
9933       (when (looking-at "\r")
9934         (incf forward))
9935       (when (<= (+ forward (point)) (point-max))
9936         ;; Go to the right position on the line.
9937         (goto-char (+ forward (point)))
9938         ;; Replace the old mark with the new mark.
9939         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9940         ;; Optionally update the marks by some user rule.
9941         (when (eq type 'unread)
9942           (gnus-data-set-mark
9943            (gnus-data-find (gnus-summary-article-number)) mark)
9944           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9945
9946 (defun gnus-mark-article-as-read (article &optional mark)
9947   "Enter ARTICLE in the pertinent lists and remove it from others."
9948   ;; Make the article expirable.
9949   (let ((mark (or mark gnus-del-mark)))
9950     (setq gnus-newsgroup-expirable
9951           (if (= mark gnus-expirable-mark)
9952               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9953             (delq article gnus-newsgroup-expirable)))
9954     ;; Remove from unread and marked lists.
9955     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9956     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9957     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9958     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9959     (push (cons article mark) gnus-newsgroup-reads)
9960     ;; Possibly remove from cache, if that is used.
9961     (when gnus-use-cache
9962       (gnus-cache-enter-remove-article article))
9963     t))
9964
9965 (defun gnus-mark-article-as-unread (article &optional mark)
9966   "Enter ARTICLE in the pertinent lists and remove it from others."
9967   (let ((mark (or mark gnus-ticked-mark)))
9968     (if (<= article 0)
9969         (progn
9970           (gnus-error 1 "Can't mark negative article numbers")
9971           nil)
9972       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9973             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9974             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9975             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9976             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9977
9978       ;; Unsuppress duplicates?
9979       (when gnus-suppress-duplicates
9980         (gnus-dup-unsuppress-article article))
9981
9982       (cond ((= mark gnus-ticked-mark)
9983              (setq gnus-newsgroup-marked
9984                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9985             ((= mark gnus-spam-mark)
9986              (setq gnus-newsgroup-spam-marked
9987                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9988                                             article)))
9989             ((= mark gnus-dormant-mark)
9990              (setq gnus-newsgroup-dormant
9991                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9992             (t
9993              (setq gnus-newsgroup-unreads
9994                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9995       (gnus-pull article gnus-newsgroup-reads)
9996       t)))
9997
9998 (defalias 'gnus-summary-mark-as-unread-forward
9999   'gnus-summary-tick-article-forward)
10000 (make-obsolete 'gnus-summary-mark-as-unread-forward
10001                'gnus-summary-tick-article-forward)
10002 (defun gnus-summary-tick-article-forward (n)
10003   "Tick N articles forwards.
10004 If N is negative, tick backwards instead.
10005 The difference between N and the number of articles ticked is returned."
10006   (interactive "p")
10007   (gnus-summary-mark-forward n gnus-ticked-mark))
10008
10009 (defalias 'gnus-summary-mark-as-unread-backward
10010   'gnus-summary-tick-article-backward)
10011 (make-obsolete 'gnus-summary-mark-as-unread-backward
10012                'gnus-summary-tick-article-backward)
10013 (defun gnus-summary-tick-article-backward (n)
10014   "Tick N articles backwards.
10015 The difference between N and the number of articles ticked is returned."
10016   (interactive "p")
10017   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10018
10019 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10020 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10021 (defun gnus-summary-tick-article (&optional article clear-mark)
10022   "Mark current article as unread.
10023 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10024 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10025   (interactive)
10026   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10027                                        gnus-ticked-mark)))
10028
10029 (defun gnus-summary-mark-as-read-forward (n)
10030   "Mark N articles as read forwards.
10031 If N is negative, mark backwards instead.
10032 The difference between N and the actual number of articles marked is
10033 returned."
10034   (interactive "p")
10035   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10036
10037 (defun gnus-summary-mark-as-read-backward (n)
10038   "Mark the N articles as read backwards.
10039 The difference between N and the actual number of articles marked is
10040 returned."
10041   (interactive "p")
10042   (gnus-summary-mark-forward
10043    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10044
10045 (defun gnus-summary-mark-as-read (&optional article mark)
10046   "Mark current article as read.
10047 ARTICLE specifies the article to be marked as read.
10048 MARK specifies a string to be inserted at the beginning of the line."
10049   (gnus-summary-mark-article article mark))
10050
10051 (defun gnus-summary-clear-mark-forward (n)
10052   "Clear marks from N articles forward.
10053 If N is negative, clear backward instead.
10054 The difference between N and the number of marks cleared is returned."
10055   (interactive "p")
10056   (gnus-summary-mark-forward n gnus-unread-mark))
10057
10058 (defun gnus-summary-clear-mark-backward (n)
10059   "Clear marks from N articles backward.
10060 The difference between N and the number of marks cleared is returned."
10061   (interactive "p")
10062   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10063
10064 (defun gnus-summary-mark-unread-as-read ()
10065   "Intended to be used by `gnus-summary-mark-article-hook'."
10066   (when (memq gnus-current-article gnus-newsgroup-unreads)
10067     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10068
10069 (defun gnus-summary-mark-read-and-unread-as-read ()
10070   "Intended to be used by `gnus-summary-mark-article-hook'."
10071   (let ((mark (gnus-summary-article-mark)))
10072     (when (or (gnus-unread-mark-p mark)
10073               (gnus-read-mark-p mark))
10074       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
10075
10076 (defun gnus-summary-mark-unread-as-ticked ()
10077   "Intended to be used by `gnus-summary-mark-article-hook'."
10078   (when (memq gnus-current-article gnus-newsgroup-unreads)
10079     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10080
10081 (defun gnus-summary-mark-region-as-read (point mark all)
10082   "Mark all unread articles between point and mark as read.
10083 If given a prefix, mark all articles between point and mark as read,
10084 even ticked and dormant ones."
10085   (interactive "r\nP")
10086   (save-excursion
10087     (let (article)
10088       (goto-char point)
10089       (beginning-of-line)
10090       (while (and
10091               (< (point) mark)
10092               (progn
10093                 (when (or all
10094                           (memq (setq article (gnus-summary-article-number))
10095                                 gnus-newsgroup-unreads))
10096                   (gnus-summary-mark-article article gnus-del-mark))
10097                 t)
10098               (gnus-summary-find-next))))))
10099
10100 (defun gnus-summary-mark-below (score mark)
10101   "Mark articles with score less than SCORE with MARK."
10102   (interactive "P\ncMark: ")
10103   (setq score (if score
10104                   (prefix-numeric-value score)
10105                 (or gnus-summary-default-score 0)))
10106   (save-excursion
10107     (set-buffer gnus-summary-buffer)
10108     (goto-char (point-min))
10109     (while
10110         (progn
10111           (and (< (gnus-summary-article-score) score)
10112                (gnus-summary-mark-article nil mark))
10113           (gnus-summary-find-next)))))
10114
10115 (defun gnus-summary-kill-below (&optional score)
10116   "Mark articles with score below SCORE as read."
10117   (interactive "P")
10118   (gnus-summary-mark-below score gnus-killed-mark))
10119
10120 (defun gnus-summary-clear-above (&optional score)
10121   "Clear all marks from articles with score above SCORE."
10122   (interactive "P")
10123   (gnus-summary-mark-above score gnus-unread-mark))
10124
10125 (defun gnus-summary-tick-above (&optional score)
10126   "Tick all articles with score above SCORE."
10127   (interactive "P")
10128   (gnus-summary-mark-above score gnus-ticked-mark))
10129
10130 (defun gnus-summary-mark-above (score mark)
10131   "Mark articles with score over SCORE with MARK."
10132   (interactive "P\ncMark: ")
10133   (setq score (if score
10134                   (prefix-numeric-value score)
10135                 (or gnus-summary-default-score 0)))
10136   (save-excursion
10137     (set-buffer gnus-summary-buffer)
10138     (goto-char (point-min))
10139     (while (and (progn
10140                   (when (> (gnus-summary-article-score) score)
10141                     (gnus-summary-mark-article nil mark))
10142                   t)
10143                 (gnus-summary-find-next)))))
10144
10145 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10146 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10147 (defun gnus-summary-limit-include-expunged (&optional no-error)
10148   "Display all the hidden articles that were expunged for low scores."
10149   (interactive)
10150   (let ((buffer-read-only nil))
10151     (let ((scored gnus-newsgroup-scored)
10152           headers h)
10153       (while scored
10154         (unless (gnus-summary-article-header (caar scored))
10155           (and (setq h (gnus-number-to-header (caar scored)))
10156                (< (cdar scored) gnus-summary-expunge-below)
10157                (push h headers)))
10158         (setq scored (cdr scored)))
10159       (if (not headers)
10160           (when (not no-error)
10161             (error "No expunged articles hidden"))
10162         (goto-char (point-min))
10163         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10164         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10165         (mapcar (lambda (x) (push (mail-header-number x)
10166                                   gnus-newsgroup-limit))
10167                 headers)
10168         (gnus-summary-prepare-unthreaded (nreverse headers))
10169         (goto-char (point-min))
10170         (gnus-summary-position-point)
10171         t))))
10172
10173 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10174   "Mark all unread articles in this newsgroup as read.
10175 If prefix argument ALL is non-nil, ticked and dormant articles will
10176 also be marked as read.
10177 If QUIETLY is non-nil, no questions will be asked.
10178 If TO-HERE is non-nil, it should be a point in the buffer.  All
10179 articles before (after, if REVERSE is set) this point will be marked as read.
10180 Note that this function will only catch up the unread article
10181 in the current summary buffer limitation.
10182 The number of articles marked as read is returned."
10183   (interactive "P")
10184   (prog1
10185       (save-excursion
10186         (when (or quietly
10187                   (not gnus-interactive-catchup) ;Without confirmation?
10188                   gnus-expert-user
10189                   (gnus-y-or-n-p
10190                    (if all
10191                        "Mark absolutely all articles as read? "
10192                      "Mark all unread articles as read? ")))
10193           (if (and not-mark
10194                    (not gnus-newsgroup-adaptive)
10195                    (not gnus-newsgroup-auto-expire)
10196                    (not gnus-suppress-duplicates)
10197                    (or (not gnus-use-cache)
10198                        (eq gnus-use-cache 'passive)))
10199               (progn
10200                 (when all
10201                   (setq gnus-newsgroup-marked nil
10202                         gnus-newsgroup-spam-marked nil
10203                         gnus-newsgroup-dormant nil))
10204                 (setq gnus-newsgroup-unreads
10205                       (gnus-sorted-nunion
10206                        (gnus-intersection gnus-newsgroup-unreads
10207                                           gnus-newsgroup-downloadable)
10208                        gnus-newsgroup-unfetched)))
10209             ;; We actually mark all articles as canceled, which we
10210             ;; have to do when using auto-expiry or adaptive scoring.
10211             (gnus-summary-show-all-threads)
10212             (if (and to-here reverse)
10213                 (progn
10214                   (goto-char to-here)
10215                   (while (and
10216                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10217                           (gnus-summary-find-next (not all)))))
10218               (when (gnus-summary-first-subject (not all))
10219                 (while (and
10220                         (if to-here (< (point) to-here) t)
10221                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10222                         (gnus-summary-find-next (not all))))))
10223             (gnus-set-mode-line 'summary))
10224           t))
10225     (gnus-summary-position-point)))
10226
10227 (defun gnus-summary-catchup-to-here (&optional all)
10228   "Mark all unticked articles before the current one as read.
10229 If ALL is non-nil, also mark ticked and dormant articles as read."
10230   (interactive "P")
10231   (save-excursion
10232     (gnus-save-hidden-threads
10233       (let ((beg (point)))
10234         ;; We check that there are unread articles.
10235         (when (or all (gnus-summary-find-prev))
10236           (gnus-summary-catchup all t beg)))))
10237   (gnus-summary-position-point))
10238
10239 (defun gnus-summary-catchup-from-here (&optional all)
10240   "Mark all unticked articles after the current one as read.
10241 If ALL is non-nil, also mark ticked and dormant articles as read."
10242   (interactive "P")
10243   (save-excursion
10244     (gnus-save-hidden-threads
10245       (let ((beg (point)))
10246         ;; We check that there are unread articles.
10247         (when (or all (gnus-summary-find-next))
10248           (gnus-summary-catchup all t beg nil t)))))
10249   (gnus-summary-position-point))
10250
10251 (defun gnus-summary-catchup-all (&optional quietly)
10252   "Mark all articles in this newsgroup as read.
10253 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10254 instead, which marks only unread articles as read."
10255   (interactive "P")
10256   (gnus-summary-catchup t quietly))
10257
10258 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10259   "Mark all unread articles in this group as read, then exit.
10260 If prefix argument ALL is non-nil, all articles are marked as read.
10261 If QUIETLY is non-nil, no questions will be asked."
10262   (interactive "P")
10263   (when (gnus-summary-catchup all quietly nil 'fast)
10264     ;; Select next newsgroup or exit.
10265     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10266              (eq gnus-auto-select-next 'quietly))
10267         (gnus-summary-next-group nil)
10268       (gnus-summary-exit))))
10269
10270 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10271   "Mark all articles in this newsgroup as read, and then exit.
10272 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10273 instead, which marks only unread articles as read."
10274   (interactive "P")
10275   (gnus-summary-catchup-and-exit t quietly))
10276
10277 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10278   "Mark all articles in this group as read and select the next group.
10279 If given a prefix, mark all articles, unread as well as ticked, as
10280 read."
10281   (interactive "P")
10282   (save-excursion
10283     (gnus-summary-catchup all))
10284   (gnus-summary-next-group))
10285
10286 ;;;
10287 ;;; with article
10288 ;;;
10289
10290 (defmacro gnus-with-article (article &rest forms)
10291   "Select ARTICLE and perform FORMS in the original article buffer.
10292 Then replace the article with the result."
10293   `(progn
10294      ;; We don't want the article to be marked as read.
10295      (let (gnus-mark-article-hook)
10296        (gnus-summary-select-article t t nil ,article))
10297      (set-buffer gnus-original-article-buffer)
10298      ,@forms
10299      (if (not (gnus-check-backend-function
10300                'request-replace-article (car gnus-article-current)))
10301          (gnus-message 5 "Read-only group; not replacing")
10302        (unless (gnus-request-replace-article
10303                 ,article (car gnus-article-current)
10304                 (current-buffer) t)
10305          (error "Couldn't replace article")))
10306      ;; The cache and backlog have to be flushed somewhat.
10307      (when gnus-keep-backlog
10308        (gnus-backlog-remove-article
10309         (car gnus-article-current) (cdr gnus-article-current)))
10310      (when gnus-use-cache
10311        (gnus-cache-update-article
10312         (car gnus-article-current) (cdr gnus-article-current)))))
10313
10314 (put 'gnus-with-article 'lisp-indent-function 1)
10315 (put 'gnus-with-article 'edebug-form-spec '(form body))
10316
10317 ;; Thread-based commands.
10318
10319 (defun gnus-summary-articles-in-thread (&optional article)
10320   "Return a list of all articles in the current thread.
10321 If ARTICLE is non-nil, return all articles in the thread that starts
10322 with that article."
10323   (let* ((article (or article (gnus-summary-article-number)))
10324          (data (gnus-data-find-list article))
10325          (top-level (gnus-data-level (car data)))
10326          (top-subject
10327           (cond ((null gnus-thread-operation-ignore-subject)
10328                  (gnus-simplify-subject-re
10329                   (mail-header-subject (gnus-data-header (car data)))))
10330                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10331                  (gnus-simplify-subject-fuzzy
10332                   (mail-header-subject (gnus-data-header (car data)))))
10333                 (t nil)))
10334          (end-point (save-excursion
10335                       (if (gnus-summary-go-to-next-thread)
10336                           (point) (point-max))))
10337          articles)
10338     (while (and data
10339                 (< (gnus-data-pos (car data)) end-point))
10340       (when (or (not top-subject)
10341                 (string= top-subject
10342                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10343                              (gnus-simplify-subject-fuzzy
10344                               (mail-header-subject
10345                                (gnus-data-header (car data))))
10346                            (gnus-simplify-subject-re
10347                             (mail-header-subject
10348                              (gnus-data-header (car data)))))))
10349         (push (gnus-data-number (car data)) articles))
10350       (unless (and (setq data (cdr data))
10351                    (> (gnus-data-level (car data)) top-level))
10352         (setq data nil)))
10353     ;; Return the list of articles.
10354     (nreverse articles)))
10355
10356 (defun gnus-summary-rethread-current ()
10357   "Rethread the thread the current article is part of."
10358   (interactive)
10359   (let* ((gnus-show-threads t)
10360          (article (gnus-summary-article-number))
10361          (id (mail-header-id (gnus-summary-article-header)))
10362          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10363     (unless id
10364       (error "No article on the current line"))
10365     (gnus-rebuild-thread id)
10366     (gnus-summary-goto-subject article)))
10367
10368 (defun gnus-summary-reparent-thread ()
10369   "Make the current article child of the marked (or previous) article.
10370
10371 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10372 is non-nil or the Subject: of both articles are the same."
10373   (interactive)
10374   (unless (not (gnus-group-read-only-p))
10375     (error "The current newsgroup does not support article editing"))
10376   (unless (<= (length gnus-newsgroup-processable) 1)
10377     (error "No more than one article may be marked"))
10378   (save-window-excursion
10379     (let ((gnus-article-buffer " *reparent*")
10380           (current-article (gnus-summary-article-number))
10381           ;; First grab the marked article, otherwise one line up.
10382           (parent-article (if (not (null gnus-newsgroup-processable))
10383                               (car gnus-newsgroup-processable)
10384                             (save-excursion
10385                               (if (eq (forward-line -1) 0)
10386                                   (gnus-summary-article-number)
10387                                 (error "Beginning of summary buffer"))))))
10388       (unless (not (eq current-article parent-article))
10389         (error "An article may not be self-referential"))
10390       (let ((message-id (mail-header-id
10391                          (gnus-summary-article-header parent-article))))
10392         (unless (and message-id (not (equal message-id "")))
10393           (error "No message-id in desired parent"))
10394         (gnus-with-article current-article
10395           (save-restriction
10396             (goto-char (point-min))
10397             (message-narrow-to-head)
10398             (if (re-search-forward "^References: " nil t)
10399                 (progn
10400                   (re-search-forward "^[^ \t]" nil t)
10401                   (forward-line -1)
10402                   (end-of-line)
10403                   (insert " " message-id))
10404               (insert "References: " message-id "\n"))))
10405         (set-buffer gnus-summary-buffer)
10406         (gnus-summary-unmark-all-processable)
10407         (gnus-summary-update-article current-article)
10408         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10409             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10410         (gnus-summary-rethread-current)
10411         (gnus-message 3 "Article %d is now the child of article %d"
10412                       current-article parent-article)))))
10413
10414 (defun gnus-summary-toggle-threads (&optional arg)
10415   "Toggle showing conversation threads.
10416 If ARG is positive number, turn showing conversation threads on."
10417   (interactive "P")
10418   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10419     (setq gnus-show-threads
10420           (if (null arg) (not gnus-show-threads)
10421             (> (prefix-numeric-value arg) 0)))
10422     (gnus-summary-prepare)
10423     (gnus-summary-goto-subject current)
10424     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10425     (gnus-summary-position-point)))
10426
10427 (defun gnus-summary-show-all-threads ()
10428   "Show all threads."
10429   (interactive)
10430   (save-excursion
10431     (let ((buffer-read-only nil))
10432       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10433   (gnus-summary-position-point))
10434
10435 (defun gnus-summary-show-thread ()
10436   "Show thread subtrees.
10437 Returns nil if no thread was there to be shown."
10438   (interactive)
10439   (let ((buffer-read-only nil)
10440         (orig (point))
10441         (end (gnus-point-at-eol))
10442         ;; Leave point at bol
10443         (beg (progn (beginning-of-line) (point))))
10444     (prog1
10445         ;; Any hidden lines here?
10446         (search-forward "\r" end t)
10447       (subst-char-in-region beg end ?\^M ?\n t)
10448       (goto-char orig)
10449       (gnus-summary-position-point))))
10450
10451 (defun gnus-summary-maybe-hide-threads ()
10452   "If requested, hide the threads that should be hidden."
10453   (when (and gnus-show-threads
10454              gnus-thread-hide-subtree)
10455     (gnus-summary-hide-all-threads
10456      (if (or (consp gnus-thread-hide-subtree)
10457              (gnus-functionp gnus-thread-hide-subtree))
10458          (gnus-make-predicate gnus-thread-hide-subtree)
10459        nil))))
10460
10461 ;;; Hiding predicates.
10462
10463 (defun gnus-article-unread-p (header)
10464   (memq (mail-header-number header) gnus-newsgroup-unreads))
10465
10466 (defun gnus-article-unseen-p (header)
10467   (memq (mail-header-number header) gnus-newsgroup-unseen))
10468
10469 (defun gnus-map-articles (predicate articles)
10470   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10471   (apply 'gnus-or (mapcar predicate
10472                           (mapcar 'gnus-summary-article-header articles))))
10473
10474 (defun gnus-summary-hide-all-threads (&optional predicate)
10475   "Hide all thread subtrees.
10476 If PREDICATE is supplied, threads that satisfy this predicate
10477 will not be hidden."
10478   (interactive)
10479   (save-excursion
10480     (goto-char (point-min))
10481     (let ((end nil))
10482       (while (not end)
10483         (when (or (not predicate)
10484                   (gnus-map-articles
10485                    predicate (gnus-summary-article-children)))
10486             (gnus-summary-hide-thread))
10487         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10488   (gnus-summary-position-point))
10489
10490 (defun gnus-summary-hide-thread ()
10491   "Hide thread subtrees.
10492 If PREDICATE is supplied, threads that satisfy this predicate
10493 will not be hidden.
10494 Returns nil if no threads were there to be hidden."
10495   (interactive)
10496   (let ((buffer-read-only nil)
10497         (start (point))
10498         (article (gnus-summary-article-number)))
10499     (goto-char start)
10500     ;; Go forward until either the buffer ends or the subthread
10501     ;; ends.
10502     (when (and (not (eobp))
10503                (or (zerop (gnus-summary-next-thread 1 t))
10504                    (goto-char (point-max))))
10505       (prog1
10506           (if (and (> (point) start)
10507                    (search-backward "\n" start t))
10508               (progn
10509                 (subst-char-in-region start (point) ?\n ?\^M)
10510                 (gnus-summary-goto-subject article))
10511             (goto-char start)
10512             nil)))))
10513
10514 (defun gnus-summary-go-to-next-thread (&optional previous)
10515   "Go to the same level (or less) next thread.
10516 If PREVIOUS is non-nil, go to previous thread instead.
10517 Return the article number moved to, or nil if moving was impossible."
10518   (let ((level (gnus-summary-thread-level))
10519         (way (if previous -1 1))
10520         (beg (point)))
10521     (forward-line way)
10522     (while (and (not (eobp))
10523                 (< level (gnus-summary-thread-level)))
10524       (forward-line way))
10525     (if (eobp)
10526         (progn
10527           (goto-char beg)
10528           nil)
10529       (setq beg (point))
10530       (prog1
10531           (gnus-summary-article-number)
10532         (goto-char beg)))))
10533
10534 (defun gnus-summary-next-thread (n &optional silent)
10535   "Go to the same level next N'th thread.
10536 If N is negative, search backward instead.
10537 Returns the difference between N and the number of skips actually
10538 done.
10539
10540 If SILENT, don't output messages."
10541   (interactive "p")
10542   (let ((backward (< n 0))
10543         (n (abs n)))
10544     (while (and (> n 0)
10545                 (gnus-summary-go-to-next-thread backward))
10546       (decf n))
10547     (unless silent
10548       (gnus-summary-position-point))
10549     (when (and (not silent) (/= 0 n))
10550       (gnus-message 7 "No more threads"))
10551     n))
10552
10553 (defun gnus-summary-prev-thread (n)
10554   "Go to the same level previous N'th thread.
10555 Returns the difference between N and the number of skips actually
10556 done."
10557   (interactive "p")
10558   (gnus-summary-next-thread (- n)))
10559
10560 (defun gnus-summary-go-down-thread ()
10561   "Go down one level in the current thread."
10562   (let ((children (gnus-summary-article-children)))
10563     (when children
10564       (gnus-summary-goto-subject (car children)))))
10565
10566 (defun gnus-summary-go-up-thread ()
10567   "Go up one level in the current thread."
10568   (let ((parent (gnus-summary-article-parent)))
10569     (when parent
10570       (gnus-summary-goto-subject parent))))
10571
10572 (defun gnus-summary-down-thread (n)
10573   "Go down thread N steps.
10574 If N is negative, go up instead.
10575 Returns the difference between N and how many steps down that were
10576 taken."
10577   (interactive "p")
10578   (let ((up (< n 0))
10579         (n (abs n)))
10580     (while (and (> n 0)
10581                 (if up (gnus-summary-go-up-thread)
10582                   (gnus-summary-go-down-thread)))
10583       (setq n (1- n)))
10584     (gnus-summary-position-point)
10585     (when (/= 0 n)
10586       (gnus-message 7 "Can't go further"))
10587     n))
10588
10589 (defun gnus-summary-up-thread (n)
10590   "Go up thread N steps.
10591 If N is negative, go down instead.
10592 Returns the difference between N and how many steps down that were
10593 taken."
10594   (interactive "p")
10595   (gnus-summary-down-thread (- n)))
10596
10597 (defun gnus-summary-top-thread ()
10598   "Go to the top of the thread."
10599   (interactive)
10600   (while (gnus-summary-go-up-thread))
10601   (gnus-summary-article-number))
10602
10603 (defun gnus-summary-kill-thread (&optional unmark)
10604   "Mark articles under current thread as read.
10605 If the prefix argument is positive, remove any kinds of marks.
10606 If the prefix argument is negative, tick articles instead."
10607   (interactive "P")
10608   (when unmark
10609     (setq unmark (prefix-numeric-value unmark)))
10610   (let ((articles (gnus-summary-articles-in-thread)))
10611     (save-excursion
10612       ;; Expand the thread.
10613       (gnus-summary-show-thread)
10614       ;; Mark all the articles.
10615       (while articles
10616         (gnus-summary-goto-subject (car articles))
10617         (cond ((null unmark)
10618                (gnus-summary-mark-article-as-read gnus-killed-mark))
10619               ((> unmark 0)
10620                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10621               (t
10622                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10623         (setq articles (cdr articles))))
10624     ;; Hide killed subtrees.
10625     (and (null unmark)
10626          gnus-thread-hide-killed
10627          (gnus-summary-hide-thread))
10628     ;; If marked as read, go to next unread subject.
10629     (when (null unmark)
10630       ;; Go to next unread subject.
10631       (gnus-summary-next-subject 1 t)))
10632   (gnus-set-mode-line 'summary))
10633
10634 ;; Summary sorting commands
10635
10636 (defun gnus-summary-sort-by-number (&optional reverse)
10637   "Sort the summary buffer by article number.
10638 Argument REVERSE means reverse order."
10639   (interactive "P")
10640   (gnus-summary-sort 'number reverse))
10641
10642 (defun gnus-summary-sort-by-random (&optional reverse)
10643   "Randomize the order in the summary buffer.
10644 Argument REVERSE means to randomize in reverse order."
10645   (interactive "P")
10646   (gnus-summary-sort 'random reverse))
10647
10648 (defun gnus-summary-sort-by-author (&optional reverse)
10649   "Sort the summary buffer by author name alphabetically.
10650 If `case-fold-search' is non-nil, case of letters is ignored.
10651 Argument REVERSE means reverse order."
10652   (interactive "P")
10653   (gnus-summary-sort 'author reverse))
10654
10655 (defun gnus-summary-sort-by-subject (&optional reverse)
10656   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10657 If `case-fold-search' is non-nil, case of letters is ignored.
10658 Argument REVERSE means reverse order."
10659   (interactive "P")
10660   (gnus-summary-sort 'subject reverse))
10661
10662 (defun gnus-summary-sort-by-date (&optional reverse)
10663   "Sort the summary buffer by date.
10664 Argument REVERSE means reverse order."
10665   (interactive "P")
10666   (gnus-summary-sort 'date reverse))
10667
10668 (defun gnus-summary-sort-by-score (&optional reverse)
10669   "Sort the summary buffer by score.
10670 Argument REVERSE means reverse order."
10671   (interactive "P")
10672   (gnus-summary-sort 'score reverse))
10673
10674 (defun gnus-summary-sort-by-lines (&optional reverse)
10675   "Sort the summary buffer by the number of lines.
10676 Argument REVERSE means reverse order."
10677   (interactive "P")
10678   (gnus-summary-sort 'lines reverse))
10679
10680 (defun gnus-summary-sort-by-chars (&optional reverse)
10681   "Sort the summary buffer by article length.
10682 Argument REVERSE means reverse order."
10683   (interactive "P")
10684   (gnus-summary-sort 'chars reverse))
10685
10686 (defun gnus-summary-sort-by-original (&optional reverse)
10687   "Sort the summary buffer using the default sorting method.
10688 Argument REVERSE means reverse order."
10689   (interactive "P")
10690   (let* ((buffer-read-only)
10691          (gnus-summary-prepare-hook nil))
10692     ;; We do the sorting by regenerating the threads.
10693     (gnus-summary-prepare)
10694     ;; Hide subthreads if needed.
10695     (gnus-summary-maybe-hide-threads)))
10696
10697 (defun gnus-summary-sort (predicate reverse)
10698   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10699   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10700          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10701          (gnus-thread-sort-functions
10702           (if (not reverse)
10703               thread
10704             `(lambda (t1 t2)
10705                (,thread t2 t1))))
10706          (gnus-sort-gathered-threads-function
10707           gnus-thread-sort-functions)
10708          (gnus-article-sort-functions
10709           (if (not reverse)
10710               article
10711             `(lambda (t1 t2)
10712                (,article t2 t1))))
10713          (buffer-read-only)
10714          (gnus-summary-prepare-hook nil))
10715     ;; We do the sorting by regenerating the threads.
10716     (gnus-summary-prepare)
10717     ;; Hide subthreads if needed.
10718     (gnus-summary-maybe-hide-threads)))
10719
10720 ;; Summary saving commands.
10721
10722 (defun gnus-summary-save-article (&optional n not-saved)
10723   "Save the current article using the default saver function.
10724 If N is a positive number, save the N next articles.
10725 If N is a negative number, save the N previous articles.
10726 If N is nil and any articles have been marked with the process mark,
10727 save those articles instead.
10728 The variable `gnus-default-article-saver' specifies the saver function."
10729   (interactive "P")
10730   (let* ((articles (gnus-summary-work-articles n))
10731          (save-buffer (save-excursion
10732                         (nnheader-set-temp-buffer " *Gnus Save*")))
10733          (num (length articles))
10734          header file)
10735     (dolist (article articles)
10736       (setq header (gnus-summary-article-header article))
10737       (if (not (vectorp header))
10738           ;; This is a pseudo-article.
10739           (if (assq 'name header)
10740               (gnus-copy-file (cdr (assq 'name header)))
10741             (gnus-message 1 "Article %d is unsaveable" article))
10742         ;; This is a real article.
10743         (save-window-excursion
10744           (let ((gnus-display-mime-function nil)
10745                 (gnus-article-prepare-hook nil))
10746             (gnus-summary-select-article t nil nil article)))
10747         (save-excursion
10748           (set-buffer save-buffer)
10749           (erase-buffer)
10750           (insert-buffer-substring gnus-original-article-buffer))
10751         (setq file (gnus-article-save save-buffer file num))
10752         (gnus-summary-remove-process-mark article)
10753         (unless not-saved
10754           (gnus-summary-set-saved-mark article))))
10755     (gnus-kill-buffer save-buffer)
10756     (gnus-summary-position-point)
10757     (gnus-set-mode-line 'summary)
10758     n))
10759
10760 (defun gnus-summary-pipe-output (&optional arg headers)
10761   "Pipe the current article to a subprocess.
10762 If N is a positive number, pipe the N next articles.
10763 If N is a negative number, pipe the N previous articles.
10764 If N is nil and any articles have been marked with the process mark,
10765 pipe those articles instead.
10766 If HEADERS (the symbolic prefix), include the headers, too."
10767   (interactive (gnus-interactive "P\ny"))
10768   (require 'gnus-art)
10769   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10770         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10771     (gnus-summary-save-article arg t))
10772   (let ((buffer (get-buffer "*Shell Command Output*")))
10773     (when (and buffer
10774                (not (zerop (buffer-size buffer))))
10775       (gnus-configure-windows 'pipe))))
10776
10777 (defun gnus-summary-save-article-mail (&optional arg)
10778   "Append the current article to an mail file.
10779 If N is a positive number, save the N next articles.
10780 If N is a negative number, save the N previous articles.
10781 If N is nil and any articles have been marked with the process mark,
10782 save those articles instead."
10783   (interactive "P")
10784   (require 'gnus-art)
10785   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10786     (gnus-summary-save-article arg)))
10787
10788 (defun gnus-summary-save-article-rmail (&optional arg)
10789   "Append the current article to an rmail file.
10790 If N is a positive number, save the N next articles.
10791 If N is a negative number, save the N previous articles.
10792 If N is nil and any articles have been marked with the process mark,
10793 save those articles instead."
10794   (interactive "P")
10795   (require 'gnus-art)
10796   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10797     (gnus-summary-save-article arg)))
10798
10799 (defun gnus-summary-save-article-file (&optional arg)
10800   "Append the current article to a file.
10801 If N is a positive number, save the N next articles.
10802 If N is a negative number, save the N previous articles.
10803 If N is nil and any articles have been marked with the process mark,
10804 save those articles instead."
10805   (interactive "P")
10806   (require 'gnus-art)
10807   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10808     (gnus-summary-save-article arg)))
10809
10810 (defun gnus-summary-write-article-file (&optional arg)
10811   "Write the current article to a file, deleting the previous file.
10812 If N is a positive number, save the N next articles.
10813 If N is a negative number, save the N previous articles.
10814 If N is nil and any articles have been marked with the process mark,
10815 save those articles instead."
10816   (interactive "P")
10817   (require 'gnus-art)
10818   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10819     (gnus-summary-save-article arg)))
10820
10821 (defun gnus-summary-save-article-body-file (&optional arg)
10822   "Append the current article body to a file.
10823 If N is a positive number, save the N next articles.
10824 If N is a negative number, save the N previous articles.
10825 If N is nil and any articles have been marked with the process mark,
10826 save those articles instead."
10827   (interactive "P")
10828   (require 'gnus-art)
10829   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10830     (gnus-summary-save-article arg)))
10831
10832 (defun gnus-summary-muttprint (&optional arg)
10833   "Print the current article using Muttprint.
10834 If N is a positive number, save the N next articles.
10835 If N is a negative number, save the N previous articles.
10836 If N is nil and any articles have been marked with the process mark,
10837 save those articles instead."
10838   (interactive "P")
10839   (require 'gnus-art)
10840   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10841     (gnus-summary-save-article arg t)))
10842
10843 (defun gnus-summary-pipe-message (program)
10844   "Pipe the current article through PROGRAM."
10845   (interactive "sProgram: ")
10846   (gnus-summary-select-article)
10847   (let ((mail-header-separator ""))
10848     (gnus-eval-in-buffer-window gnus-article-buffer
10849       (save-restriction
10850         (widen)
10851         (let ((start (window-start))
10852               buffer-read-only)
10853           (message-pipe-buffer-body program)
10854           (set-window-start (get-buffer-window (current-buffer)) start))))))
10855
10856 (defun gnus-get-split-value (methods)
10857   "Return a value based on the split METHODS."
10858   (let (split-name method result match)
10859     (when methods
10860       (save-excursion
10861         (set-buffer gnus-original-article-buffer)
10862         (save-restriction
10863           (nnheader-narrow-to-headers)
10864           (while (and methods (not split-name))
10865             (goto-char (point-min))
10866             (setq method (pop methods))
10867             (setq match (car method))
10868             (when (cond
10869                    ((stringp match)
10870                     ;; Regular expression.
10871                     (ignore-errors
10872                       (re-search-forward match nil t)))
10873                    ((gnus-functionp match)
10874                     ;; Function.
10875                     (save-restriction
10876                       (widen)
10877                       (setq result (funcall match gnus-newsgroup-name))))
10878                    ((consp match)
10879                     ;; Form.
10880                     (save-restriction
10881                       (widen)
10882                       (setq result (eval match)))))
10883               (setq split-name (cdr method))
10884               (cond ((stringp result)
10885                      (push (expand-file-name
10886                             result gnus-article-save-directory)
10887                            split-name))
10888                     ((consp result)
10889                      (setq split-name (append result split-name)))))))))
10890     (nreverse split-name)))
10891
10892 (defun gnus-valid-move-group-p (group)
10893   (and (boundp group)
10894        (symbol-name group)
10895        (symbol-value group)
10896        (gnus-get-function (gnus-find-method-for-group
10897                            (symbol-name group)) 'request-accept-article t)))
10898
10899 (defun gnus-read-move-group-name (prompt default articles prefix)
10900   "Read a group name."
10901   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10902          (minibuffer-confirm-incomplete nil) ; XEmacs
10903          (prom
10904           (format "%s %s to:"
10905                   prompt
10906                   (if (> (length articles) 1)
10907                       (format "these %d articles" (length articles))
10908                     "this article")))
10909          (to-newsgroup
10910           (cond
10911            ((null split-name)
10912             (gnus-completing-read-with-default
10913              default prom
10914              gnus-active-hashtb
10915              'gnus-valid-move-group-p
10916              nil prefix
10917              'gnus-group-history))
10918            ((= 1 (length split-name))
10919             (gnus-completing-read-with-default
10920              (car split-name) prom
10921              gnus-active-hashtb
10922              'gnus-valid-move-group-p
10923              nil nil
10924              'gnus-group-history))
10925            (t
10926             (gnus-completing-read-with-default
10927              nil prom
10928              (mapcar (lambda (el) (list el))
10929                      (nreverse split-name))
10930              nil nil nil
10931              'gnus-group-history))))
10932          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10933     (when to-newsgroup
10934       (if (or (string= to-newsgroup "")
10935               (string= to-newsgroup prefix))
10936           (setq to-newsgroup default))
10937       (unless to-newsgroup
10938         (error "No group name entered"))
10939       (or (gnus-active to-newsgroup)
10940           (gnus-activate-group to-newsgroup nil nil to-method)
10941           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10942                                      to-newsgroup))
10943               (or (and (gnus-request-create-group to-newsgroup to-method)
10944                        (gnus-activate-group
10945                         to-newsgroup nil nil to-method)
10946                        (gnus-subscribe-group to-newsgroup))
10947                   (error "Couldn't create group %s" to-newsgroup)))
10948           (error "No such group: %s" to-newsgroup)))
10949     to-newsgroup))
10950
10951 (defun gnus-summary-save-parts (type dir n &optional reverse)
10952   "Save parts matching TYPE to DIR.
10953 If REVERSE, save parts that do not match TYPE."
10954   (interactive
10955    (list (read-string "Save parts of type: "
10956                       (or (car gnus-summary-save-parts-type-history)
10957                           gnus-summary-save-parts-default-mime)
10958                       'gnus-summary-save-parts-type-history)
10959          (setq gnus-summary-save-parts-last-directory
10960                (read-file-name "Save to directory: "
10961                                gnus-summary-save-parts-last-directory
10962                                nil t))
10963          current-prefix-arg))
10964   (gnus-summary-iterate n
10965     (let ((gnus-display-mime-function nil)
10966           (gnus-inhibit-treatment t))
10967       (gnus-summary-select-article))
10968     (save-excursion
10969       (set-buffer gnus-article-buffer)
10970       (let ((handles (or gnus-article-mime-handles
10971                          (mm-dissect-buffer nil gnus-article-loose-mime)
10972                          (and gnus-article-emulate-mime
10973                               (mm-uu-dissect)))))
10974         (when handles
10975           (gnus-summary-save-parts-1 type dir handles reverse)
10976           (unless gnus-article-mime-handles ;; Don't destroy this case.
10977             (mm-destroy-parts handles)))))))
10978
10979 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10980   (if (stringp (car handle))
10981       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10982               (cdr handle))
10983     (when (if reverse
10984               (not (string-match type (mm-handle-media-type handle)))
10985             (string-match type (mm-handle-media-type handle)))
10986       (let ((file (expand-file-name
10987                    (file-name-nondirectory
10988                     (or
10989                      (mail-content-type-get
10990                       (mm-handle-disposition handle) 'filename)
10991                      (concat gnus-newsgroup-name
10992                              "." (number-to-string
10993                                   (cdr gnus-article-current)))))
10994                    dir)))
10995         (unless (file-exists-p file)
10996           (mm-save-part-to-file handle file))))))
10997
10998 ;; Summary extract commands
10999
11000 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11001   (let ((buffer-read-only nil)
11002         (article (gnus-summary-article-number))
11003         after-article b e)
11004     (unless (gnus-summary-goto-subject article)
11005       (error "No such article: %d" article))
11006     (gnus-summary-position-point)
11007     ;; If all commands are to be bunched up on one line, we collect
11008     ;; them here.
11009     (unless gnus-view-pseudos-separately
11010       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11011             files action)
11012         (while ps
11013           (setq action (cdr (assq 'action (car ps))))
11014           (setq files (list (cdr (assq 'name (car ps)))))
11015           (while (and ps (cdr ps)
11016                       (string= (or action "1")
11017                                (or (cdr (assq 'action (cadr ps))) "2")))
11018             (push (cdr (assq 'name (cadr ps))) files)
11019             (setcdr ps (cddr ps)))
11020           (when files
11021             (when (not (string-match "%s" action))
11022               (push " " files))
11023             (push " " files)
11024             (when (assq 'execute (car ps))
11025               (setcdr (assq 'execute (car ps))
11026                       (funcall (if (string-match "%s" action)
11027                                    'format 'concat)
11028                                action
11029                                (mapconcat
11030                                 (lambda (f)
11031                                   (if (equal f " ")
11032                                       f
11033                                     (gnus-quote-arg-for-sh-or-csh f)))
11034                                 files " ")))))
11035           (setq ps (cdr ps)))))
11036     (if (and gnus-view-pseudos (not not-view))
11037         (while pslist
11038           (when (assq 'execute (car pslist))
11039             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11040                                   (eq gnus-view-pseudos 'not-confirm)))
11041           (setq pslist (cdr pslist)))
11042       (save-excursion
11043         (while pslist
11044           (setq after-article (or (cdr (assq 'article (car pslist)))
11045                                   (gnus-summary-article-number)))
11046           (gnus-summary-goto-subject after-article)
11047           (forward-line 1)
11048           (setq b (point))
11049           (insert "    " (file-name-nondirectory
11050                           (cdr (assq 'name (car pslist))))
11051                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11052           (setq e (point))
11053           (forward-line -1)             ; back to `b'
11054           (gnus-add-text-properties
11055            b (1- e) (list 'gnus-number gnus-reffed-article-number
11056                           gnus-mouse-face-prop gnus-mouse-face))
11057           (gnus-data-enter
11058            after-article gnus-reffed-article-number
11059            gnus-unread-mark b (car pslist) 0 (- e b))
11060           (setq gnus-newsgroup-unreads
11061                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11062                                          gnus-reffed-article-number))
11063           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11064           (setq pslist (cdr pslist)))))))
11065
11066 (defun gnus-pseudos< (p1 p2)
11067   (let ((c1 (cdr (assq 'action p1)))
11068         (c2 (cdr (assq 'action p2))))
11069     (and c1 c2 (string< c1 c2))))
11070
11071 (defun gnus-request-pseudo-article (props)
11072   (cond ((assq 'execute props)
11073          (gnus-execute-command (cdr (assq 'execute props)))))
11074   (let ((gnus-current-article (gnus-summary-article-number)))
11075     (gnus-run-hooks 'gnus-mark-article-hook)))
11076
11077 (defun gnus-execute-command (command &optional automatic)
11078   (save-excursion
11079     (gnus-article-setup-buffer)
11080     (set-buffer gnus-article-buffer)
11081     (setq buffer-read-only nil)
11082     (let ((command (if automatic command
11083                      (read-string "Command: " (cons command 0)))))
11084       (erase-buffer)
11085       (insert "$ " command "\n\n")
11086       (if gnus-view-pseudo-asynchronously
11087           (start-process "gnus-execute" (current-buffer) shell-file-name
11088                          shell-command-switch command)
11089         (call-process shell-file-name nil t nil
11090                       shell-command-switch command)))))
11091
11092 ;; Summary kill commands.
11093
11094 (defun gnus-summary-edit-global-kill (article)
11095   "Edit the \"global\" kill file."
11096   (interactive (list (gnus-summary-article-number)))
11097   (gnus-group-edit-global-kill article))
11098
11099 (defun gnus-summary-edit-local-kill ()
11100   "Edit a local kill file applied to the current newsgroup."
11101   (interactive)
11102   (setq gnus-current-headers (gnus-summary-article-header))
11103   (gnus-group-edit-local-kill
11104    (gnus-summary-article-number) gnus-newsgroup-name))
11105
11106 ;;; Header reading.
11107
11108 (defun gnus-read-header (id &optional header)
11109   "Read the headers of article ID and enter them into the Gnus system."
11110   (let ((group gnus-newsgroup-name)
11111         (gnus-override-method
11112          (or
11113           gnus-override-method
11114           (and (gnus-news-group-p gnus-newsgroup-name)
11115                (car (gnus-refer-article-methods)))))
11116         where)
11117     ;; First we check to see whether the header in question is already
11118     ;; fetched.
11119     (if (stringp id)
11120         ;; This is a Message-ID.
11121         (setq header (or header (gnus-id-to-header id)))
11122       ;; This is an article number.
11123       (setq header (or header (gnus-summary-article-header id))))
11124     (if (and header
11125              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11126         ;; We have found the header.
11127         header
11128       ;; If this is a sparse article, we have to nix out its
11129       ;; previous entry in the thread hashtb.
11130       (when (and header
11131                  (gnus-summary-article-sparse-p (mail-header-number header)))
11132         (let* ((parent (gnus-parent-id (mail-header-references header)))
11133                (thread (and parent (gnus-id-to-thread parent))))
11134           (when thread
11135             (delq (assq header thread) thread))))
11136       ;; We have to really fetch the header to this article.
11137       (save-excursion
11138         (set-buffer nntp-server-buffer)
11139         (when (setq where (gnus-request-head id group))
11140           (nnheader-fold-continuation-lines)
11141           (goto-char (point-max))
11142           (insert ".\n")
11143           (goto-char (point-min))
11144           (insert "211 ")
11145           (princ (cond
11146                   ((numberp id) id)
11147                   ((cdr where) (cdr where))
11148                   (header (mail-header-number header))
11149                   (t gnus-reffed-article-number))
11150                  (current-buffer))
11151           (insert " Article retrieved.\n"))
11152         (if (or (not where)
11153                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11154             ()                          ; Malformed head.
11155           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11156             (when (and (stringp id)
11157                        (not (string= (gnus-group-real-name group)
11158                                      (car where))))
11159               ;; If we fetched by Message-ID and the article came
11160               ;; from a different group, we fudge some bogus article
11161               ;; numbers for this article.
11162               (mail-header-set-number header gnus-reffed-article-number))
11163             (save-excursion
11164               (set-buffer gnus-summary-buffer)
11165               (decf gnus-reffed-article-number)
11166               (gnus-remove-header (mail-header-number header))
11167               (push header gnus-newsgroup-headers)
11168               (setq gnus-current-headers header)
11169               (push (mail-header-number header) gnus-newsgroup-limit)))
11170           header)))))
11171
11172 (defun gnus-remove-header (number)
11173   "Remove header NUMBER from `gnus-newsgroup-headers'."
11174   (if (and gnus-newsgroup-headers
11175            (= number (mail-header-number (car gnus-newsgroup-headers))))
11176       (pop gnus-newsgroup-headers)
11177     (let ((headers gnus-newsgroup-headers))
11178       (while (and (cdr headers)
11179                   (not (= number (mail-header-number (cadr headers)))))
11180         (pop headers))
11181       (when (cdr headers)
11182         (setcdr headers (cddr headers))))))
11183
11184 ;;;
11185 ;;; summary highlights
11186 ;;;
11187
11188 (defun gnus-highlight-selected-summary ()
11189   "Highlight selected article in summary buffer."
11190   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11191   (when gnus-summary-selected-face
11192     (save-excursion
11193       (let* ((beg (gnus-point-at-bol))
11194              (end (gnus-point-at-eol))
11195              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11196              (from (if (get-text-property beg gnus-mouse-face-prop)
11197                        beg
11198                      (or (next-single-property-change
11199                           beg gnus-mouse-face-prop nil end)
11200                          beg)))
11201              (to
11202               (if (= from end)
11203                   (- from 2)
11204                 (or (next-single-property-change
11205                      from gnus-mouse-face-prop nil end)
11206                     end))))
11207         ;; If no mouse-face prop on line we will have to = from = end,
11208         ;; so we highlight the entire line instead.
11209         (when (= (+ to 2) from)
11210           (setq from beg)
11211           (setq to end))
11212         (if gnus-newsgroup-selected-overlay
11213             ;; Move old overlay.
11214             (gnus-move-overlay
11215              gnus-newsgroup-selected-overlay from to (current-buffer))
11216           ;; Create new overlay.
11217           (gnus-overlay-put
11218            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11219            'face gnus-summary-selected-face))))))
11220
11221 (defvar gnus-summary-highlight-line-cached nil)
11222 (defvar gnus-summary-highlight-line-trigger nil)
11223
11224 (defun gnus-summary-highlight-line-0 ()
11225   (if (and (eq gnus-summary-highlight-line-trigger 
11226                gnus-summary-highlight)
11227            gnus-summary-highlight-line-cached)
11228       gnus-summary-highlight-line-cached
11229     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11230           gnus-summary-highlight-line-cached
11231           (let* ((cond (list 'cond))
11232                  (c cond)
11233                  (list gnus-summary-highlight))
11234             (while list
11235               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11236                               nil))
11237               (setq c (cdr c)
11238                     list (cdr list)))
11239             (gnus-byte-compile (list 'lambda nil cond))))))
11240
11241 (defun gnus-summary-highlight-line ()
11242   "Highlight current line according to `gnus-summary-highlight'."
11243   (let* ((beg (gnus-point-at-bol))
11244          (article (or (gnus-summary-article-number) gnus-current-article))
11245          (score (or (cdr (assq article
11246                                gnus-newsgroup-scored))
11247                     gnus-summary-default-score 0))
11248          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11249          (inhibit-read-only t)
11250          (default gnus-summary-default-score)
11251          (default-high gnus-summary-default-high-score)
11252          (default-low gnus-summary-default-low-score)
11253          (uncached (memq article gnus-newsgroup-undownloaded))
11254          (downloaded (not uncached)))
11255     (let ((face (funcall (gnus-summary-highlight-line-0))))
11256       (unless (eq face (get-text-property beg 'face))
11257         (gnus-put-text-property-excluding-characters-with-faces
11258          beg (gnus-point-at-eol) 'face
11259          (setq face (if (boundp face) (symbol-value face) face)))
11260         (when gnus-summary-highlight-line-function
11261           (funcall gnus-summary-highlight-line-function article face))))))
11262
11263 (defun gnus-update-read-articles (group unread &optional compute)
11264   "Update the list of read articles in GROUP.
11265 UNREAD is a sorted list."
11266   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11267          (entry (gnus-gethash group gnus-newsrc-hashtb))
11268          (info (nth 2 entry))
11269          (prev 1)
11270          read)
11271     (if (or (not info) (not active))
11272         ;; There is no info on this group if it was, in fact,
11273         ;; killed.  Gnus stores no information on killed groups, so
11274         ;; there's nothing to be done.
11275         ;; One could store the information somewhere temporarily,
11276         ;; perhaps...  Hmmm...
11277         ()
11278       ;; Remove any negative articles numbers.
11279       (while (and unread (< (car unread) 0))
11280         (setq unread (cdr unread)))
11281       ;; Remove any expired article numbers
11282       (while (and unread (< (car unread) (car active)))
11283         (setq unread (cdr unread)))
11284       ;; Compute the ranges of read articles by looking at the list of
11285       ;; unread articles.
11286       (while unread
11287         (when (/= (car unread) prev)
11288           (push (if (= prev (1- (car unread))) prev
11289                   (cons prev (1- (car unread))))
11290                 read))
11291         (setq prev (1+ (car unread)))
11292         (setq unread (cdr unread)))
11293       (when (<= prev (cdr active))
11294         (push (cons prev (cdr active)) read))
11295       (setq read (if (> (length read) 1) (nreverse read) read))
11296       (if compute
11297           read
11298         (save-excursion
11299           (let (setmarkundo)
11300             ;; Propagate the read marks to the backend.
11301             (when (gnus-check-backend-function 'request-set-mark group)
11302               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11303                     (add (gnus-remove-from-range read (gnus-info-read info))))
11304                 (when (or add del)
11305                   (unless (gnus-check-group group)
11306                     (error "Can't open server for %s" group))
11307                   (gnus-request-set-mark
11308                    group (delq nil (list (if add (list add 'add '(read)))
11309                                          (if del (list del 'del '(read))))))
11310                   (setq setmarkundo
11311                         `(gnus-request-set-mark
11312                           ,group
11313                           ',(delq nil (list
11314                                        (if del (list del 'add '(read)))
11315                                        (if add (list add 'del '(read))))))))))
11316             (set-buffer gnus-group-buffer)
11317             (gnus-undo-register
11318               `(progn
11319                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11320                  (gnus-info-set-read ',info ',(gnus-info-read info))
11321                  (gnus-get-unread-articles-in-group ',info
11322                                                     (gnus-active ,group))
11323                  (gnus-group-update-group ,group t)
11324                  ,setmarkundo))))
11325         ;; Enter this list into the group info.
11326         (gnus-info-set-read info read)
11327         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11328         (gnus-get-unread-articles-in-group info (gnus-active group))
11329         t))))
11330
11331 (defun gnus-offer-save-summaries ()
11332   "Offer to save all active summary buffers."
11333   (let (buffers)
11334     ;; Go through all buffers and find all summaries.
11335     (dolist (buffer (buffer-list))
11336       (when (and (setq buffer (buffer-name buffer))
11337                  (string-match "Summary" buffer)
11338                  (save-excursion
11339                    (set-buffer buffer)
11340                    ;; We check that this is, indeed, a summary buffer.
11341                    (and (eq major-mode 'gnus-summary-mode)
11342                         ;; Also make sure this isn't bogus.
11343                         gnus-newsgroup-prepared
11344                         ;; Also make sure that this isn't a
11345                         ;; dead summary buffer.
11346                         (not gnus-dead-summary-mode))))
11347         (push buffer buffers)))
11348     ;; Go through all these summary buffers and offer to save them.
11349     (when buffers
11350       (save-excursion
11351         (map-y-or-n-p
11352          "Update summary buffer %s? "
11353          (lambda (buf)
11354            (switch-to-buffer buf)
11355            (gnus-summary-exit))
11356          buffers)))))
11357
11358
11359 ;;; @ for mime-partial
11360 ;;;
11361
11362 (defun gnus-request-partial-message ()
11363   (save-excursion
11364     (let ((number (gnus-summary-article-number))
11365           (group gnus-newsgroup-name)
11366           (mother gnus-article-buffer))
11367       (set-buffer (get-buffer-create " *Partial Article*"))
11368       (erase-buffer)
11369       (setq mime-preview-buffer mother)
11370       (gnus-request-article-this-buffer number group)
11371       (mime-parse-buffer)
11372       )))
11373
11374 (autoload 'mime-combine-message/partial-pieces-automatically
11375   "mime-partial"
11376   "Internal method to combine message/partial messages automatically.")
11377
11378 (mime-add-condition
11379  'action '((type . message)(subtype . partial)
11380            (major-mode . gnus-original-article-mode)
11381            (method . mime-combine-message/partial-pieces-automatically)
11382            (summary-buffer-exp . gnus-summary-buffer)
11383            (request-partial-message-method . gnus-request-partial-message)
11384            ))
11385
11386
11387 ;;; @ for message/rfc822
11388 ;;;
11389
11390 (defun gnus-mime-extract-message/rfc822 (entity situation)
11391   "Burst a forwarded article."
11392   (save-excursion
11393     (set-buffer gnus-summary-buffer)
11394     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11395                                    gnus-newsgroup-name 'gnus-group-history))
11396            (gnus-group-marked (list group))
11397            article info)
11398       (with-temp-buffer
11399         (mime-insert-entity-content entity)
11400         (setq article (gnus-request-accept-article group)))
11401       (when (and (consp article)
11402                  (numberp (setq article (cdr article))))
11403         (setq info (gnus-get-info group))
11404         (gnus-info-set-read info
11405                             (gnus-remove-from-range (gnus-info-read info)
11406                                                     (list article)))
11407         (when (string-equal group gnus-newsgroup-name)
11408           (forward-line 1)
11409           (let (gnus-show-threads)
11410             (gnus-summary-goto-subject article t))
11411           (gnus-summary-clear-mark-forward 1))
11412         (set-buffer gnus-group-buffer)
11413         (gnus-group-get-new-news-this-group nil t)))))
11414
11415 (mime-add-condition
11416  'action '((type . message)(subtype . rfc822)
11417            (major-mode . gnus-original-article-mode)
11418            (method . gnus-mime-extract-message/rfc822)
11419            (mode . "extract")
11420            ))
11421
11422 (mime-add-condition
11423  'action '((type . message)(subtype . news)
11424            (major-mode . gnus-original-article-mode)
11425            (method . gnus-mime-extract-message/rfc822)
11426            (mode . "extract")
11427            ))
11428
11429 (defun gnus-mime-extract-multipart (entity situation)
11430   (let ((children (mime-entity-children entity))
11431         mime-acting-situation-to-override
11432         f)
11433     (while children
11434       (mime-play-entity (car children)
11435                         (cons (assq 'mode situation)
11436                               mime-acting-situation-to-override))
11437       (setq children (cdr children)))
11438     (if (setq f (cdr (assq 'after-method
11439                            mime-acting-situation-to-override)))
11440         (eval f)
11441       )))
11442
11443 (mime-add-condition
11444  'action '((type . multipart)
11445            (method . gnus-mime-extract-multipart)
11446            (mode . "extract")
11447            )
11448  'with-default)
11449
11450
11451 ;;; @ end
11452 ;;;
11453
11454 (defun gnus-summary-inherit-default-charset ()
11455   "Import `default-mime-charset' from summary buffer.
11456 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11457 of FLIM is used."
11458   (if (buffer-live-p gnus-summary-buffer)
11459       (let (d-m-c d-m-c-u)
11460         (with-current-buffer gnus-summary-buffer
11461           (setq d-m-c (if (local-variable-p 'default-mime-charset
11462                                             gnus-summary-buffer)
11463                           default-mime-charset
11464                         t)
11465                 ;; LIMIT
11466                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11467                                               gnus-summary-buffer)
11468                             (symbol-value 'default-mime-charset-unlimited)
11469                           t)))
11470         (if (eq t d-m-c)
11471             (kill-local-variable 'default-mime-charset)
11472           (set (make-local-variable 'default-mime-charset) d-m-c))
11473         (if (eq t d-m-c-u)
11474             (kill-local-variable 'default-mime-charset-unlimited)
11475           (set (make-local-variable 'default-mime-charset-unlimited)
11476                d-m-c-u)))))
11477
11478 (defun gnus-summary-setup-default-charset ()
11479   "Setup newsgroup default charset."
11480   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11481       (progn
11482         (setq gnus-newsgroup-charset nil)
11483         (set (make-local-variable 'default-mime-charset) nil)
11484         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11485           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11486     (let ((ignored-charsets
11487            (or gnus-newsgroup-ephemeral-ignored-charsets
11488                (append
11489                 (and gnus-newsgroup-name
11490                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11491                 gnus-newsgroup-ignored-charsets)))
11492           charset)
11493       (setq gnus-newsgroup-charset
11494             (or gnus-newsgroup-ephemeral-charset
11495                 (when (and gnus-newsgroup-name
11496                            (setq charset (gnus-parameter-charset
11497                                           gnus-newsgroup-name)))
11498                   (make-local-variable 'default-mime-charset)
11499                   (setq default-mime-charset charset))
11500                 gnus-default-charset))
11501       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11502            ignored-charsets))))
11503
11504 ;;;
11505 ;;; Mime Commands
11506 ;;;
11507
11508 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11509   "Display the current article buffer fully MIME-buttonized.
11510 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11511 treated as multipart/mixed."
11512   (interactive "P")
11513   (require 'gnus-art)
11514   (let ((gnus-unbuttonized-mime-types nil)
11515         (gnus-mime-display-multipart-as-mixed show-all-parts))
11516     (gnus-summary-show-article)))
11517
11518 (defun gnus-summary-repair-multipart (article)
11519   "Add a Content-Type header to a multipart article without one."
11520   (interactive (list (gnus-summary-article-number)))
11521   (gnus-with-article article
11522     (message-narrow-to-head)
11523     (message-remove-header "Mime-Version")
11524     (goto-char (point-max))
11525     (insert "Mime-Version: 1.0\n")
11526     (widen)
11527     (when (search-forward "\n--" nil t)
11528       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11529         (message-narrow-to-head)
11530         (message-remove-header "Content-Type")
11531         (goto-char (point-max))
11532         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11533                         separator))
11534         (widen))))
11535   (let (gnus-mark-article-hook)
11536     (gnus-summary-select-article t t nil article)))
11537
11538 (defun gnus-summary-toggle-display-buttonized ()
11539   "Toggle the buttonizing of the article buffer."
11540   (interactive)
11541   (require 'gnus-art)
11542   (if (setq gnus-inhibit-mime-unbuttonizing
11543             (not gnus-inhibit-mime-unbuttonizing))
11544       (let ((gnus-unbuttonized-mime-types nil))
11545         (gnus-summary-show-article))
11546     (gnus-summary-show-article)))
11547
11548 ;;;
11549 ;;; Intelli-mouse commmands
11550 ;;;
11551
11552 (defun gnus-wheel-summary-scroll (event)
11553   (interactive "e")
11554   (let ((amount (if (memq 'shift (event-modifiers event))
11555                     (car gnus-wheel-scroll-amount)
11556                   (cdr gnus-wheel-scroll-amount)))
11557         (direction (- (* (static-if (featurep 'xemacs)
11558                              (event-button event)
11559                            (cond ((eq 'mouse-4 (event-basic-type event))
11560                                   4)
11561                                  ((eq 'mouse-5 (event-basic-type event))
11562                                   5)))
11563                          2) 9))
11564         edge)
11565     (gnus-summary-scroll-up (* amount direction))
11566     (when (gnus-eval-in-buffer-window gnus-article-buffer
11567             (save-restriction
11568               (widen)
11569               (and (if (< 0 direction)
11570                        (gnus-article-next-page 0)
11571                      (gnus-article-prev-page 0)
11572                      (bobp))
11573                    (if (setq edge (get-text-property
11574                                    (point-min) 'gnus-wheel-edge))
11575                        (setq edge (* edge direction))
11576                      (setq edge -1))
11577                    (or (plusp edge)
11578                        (let ((buffer-read-only nil)
11579                              (inhibit-read-only t))
11580                          (put-text-property (point-min) (point-max)
11581                                             'gnus-wheel-edge direction)
11582                          nil))
11583                    (or (> edge gnus-wheel-edge-resistance)
11584                        (let ((buffer-read-only nil)
11585                              (inhibit-read-only t))
11586                          (put-text-property (point-min) (point-max)
11587                                             'gnus-wheel-edge
11588                                             (* (1+ edge) direction))
11589                          nil))
11590                    (eq last-command 'gnus-wheel-summary-scroll))))
11591       (gnus-summary-next-article nil nil (minusp direction)))))
11592
11593 (defun gnus-wheel-install ()
11594   "Enable mouse wheel support on summary window."
11595   (when gnus-use-wheel
11596     (let ((keys
11597            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11598       (dolist (key keys)
11599         (define-key gnus-summary-mode-map key
11600           'gnus-wheel-summary-scroll)))))
11601
11602 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11603
11604 ;;;
11605 ;;; Traditional PGP commmands
11606 ;;;
11607
11608 (defun gnus-summary-decrypt-article (&optional force)
11609   "Decrypt the current article in traditional PGP way.
11610 This will have permanent effect only in mail groups.
11611 If FORCE is non-nil, allow editing of articles even in read-only
11612 groups."
11613   (interactive "P")
11614   (gnus-summary-select-article t)
11615   (gnus-eval-in-buffer-window gnus-article-buffer
11616     (save-excursion
11617       (save-restriction
11618         (widen)
11619         (goto-char (point-min))
11620         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11621           (error "Not a traditional PGP message!"))
11622         (let ((armor-start (match-beginning 0)))
11623           (if (and (pgg-decrypt-region armor-start (point-max))
11624                    (or force (not (gnus-group-read-only-p))))
11625               (let ((inhibit-read-only t)
11626                     buffer-read-only)
11627                 (delete-region armor-start
11628                                (progn
11629                                  (re-search-forward "^-+END PGP" nil t)
11630                                  (beginning-of-line 2)
11631                                  (point)))
11632                 (insert-buffer-substring pgg-output-buffer))))))))
11633
11634 (defun gnus-summary-verify-article ()
11635   "Verify the current article in traditional PGP way."
11636   (interactive)
11637   (save-excursion
11638     (set-buffer gnus-original-article-buffer)
11639     (goto-char (point-min))
11640     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11641       (error "Not a traditional PGP message!"))
11642     (re-search-forward "^-+END PGP" nil t)
11643     (beginning-of-line 2)
11644     (call-interactively (function pgg-verify-region))))
11645
11646 ;;;
11647 ;;; Generic summary marking commands
11648 ;;;
11649
11650 (defvar gnus-summary-marking-alist
11651   '((read gnus-del-mark "d")
11652     (unread gnus-unread-mark "u")
11653     (ticked gnus-ticked-mark "!")
11654     (dormant gnus-dormant-mark "?")
11655     (expirable gnus-expirable-mark "e"))
11656   "An alist of names/marks/keystrokes.")
11657
11658 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11659 (defvar gnus-summary-mark-map)
11660
11661 (defun gnus-summary-make-all-marking-commands ()
11662   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11663   (dolist (elem gnus-summary-marking-alist)
11664     (apply 'gnus-summary-make-marking-command elem)))
11665
11666 (defun gnus-summary-make-marking-command (name mark keystroke)
11667   (let ((map (make-sparse-keymap)))
11668     (define-key gnus-summary-generic-mark-map keystroke map)
11669     (dolist (lway `((next "next" next nil "n")
11670                     (next-unread "next unread" next t "N")
11671                     (prev "previous" prev nil "p")
11672                     (prev-unread "previous unread" prev t "P")
11673                     (nomove "" nil nil ,keystroke)))
11674       (let ((func (gnus-summary-make-marking-command-1
11675                    mark (car lway) lway name)))
11676         (setq func (eval func))
11677         (define-key map (nth 4 lway) func)))))
11678
11679 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11680   `(defun ,(intern
11681             (format "gnus-summary-put-mark-as-%s%s"
11682                     name (if (eq way 'nomove)
11683                              ""
11684                            (concat "-" (symbol-name way)))))
11685      (n)
11686      ,(format
11687        "Mark the current article as %s%s.
11688 If N, the prefix, then repeat N times.
11689 If N is negative, move in reverse order.
11690 The difference between N and the actual number of articles marked is
11691 returned."
11692        name (car (cdr lway)))
11693      (interactive "p")
11694      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11695
11696 (defun gnus-summary-generic-mark (n mark move unread)
11697   "Mark N articles with MARK."
11698   (unless (eq major-mode 'gnus-summary-mode)
11699     (error "This command can only be used in the summary buffer"))
11700   (gnus-summary-show-thread)
11701   (let ((nummove
11702          (cond
11703           ((eq move 'next) 1)
11704           ((eq move 'prev) -1)
11705           (t 0))))
11706     (if (zerop nummove)
11707         (setq n 1)
11708       (when (< n 0)
11709         (setq n (abs n)
11710               nummove (* -1 nummove))))
11711     (while (and (> n 0)
11712                 (gnus-summary-mark-article nil mark)
11713                 (zerop (gnus-summary-next-subject nummove unread t)))
11714       (setq n (1- n)))
11715     (when (/= 0 n)
11716       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11717     (gnus-summary-recenter)
11718     (gnus-summary-position-point)
11719     (gnus-set-mode-line 'summary)
11720     n))
11721
11722 (defun gnus-summary-insert-articles (articles)
11723   (when (setq articles
11724               (gnus-sorted-difference articles
11725                                       (mapcar (lambda (h)
11726                                                 (mail-header-number h))
11727                                               gnus-newsgroup-headers)))
11728     (setq gnus-newsgroup-headers
11729           (merge 'list
11730                  gnus-newsgroup-headers
11731                  (gnus-fetch-headers articles)
11732                  'gnus-article-sort-by-number))
11733     ;; Suppress duplicates?
11734     (when gnus-suppress-duplicates
11735       (gnus-dup-suppress-articles))
11736
11737     ;; We might want to build some more threads first.
11738     (when (and gnus-fetch-old-headers
11739                (eq gnus-headers-retrieved-by 'nov))
11740       (if (eq gnus-fetch-old-headers 'invisible)
11741           (gnus-build-all-threads)
11742         (gnus-build-old-threads)))
11743     ;; Let the Gnus agent mark articles as read.
11744     (when gnus-agent
11745       (gnus-agent-get-undownloaded-list))
11746     ;; Remove list identifiers from subject
11747     (when gnus-list-identifiers
11748       (gnus-summary-remove-list-identifiers))
11749     ;; First and last article in this newsgroup.
11750     (when gnus-newsgroup-headers
11751       (setq gnus-newsgroup-begin
11752             (mail-header-number (car gnus-newsgroup-headers))
11753             gnus-newsgroup-end
11754             (mail-header-number
11755              (gnus-last-element gnus-newsgroup-headers))))
11756     (when gnus-use-scoring
11757       (gnus-possibly-score-headers))))
11758
11759 (defun gnus-summary-insert-old-articles (&optional all)
11760   "Insert all old articles in this group.
11761 If ALL is non-nil, already read articles become readable.
11762 If ALL is a number, fetch this number of articles."
11763   (interactive "P")
11764   (prog1
11765       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11766             older len)
11767         (setq older
11768               ;; Some nntp servers lie about their active range.  When
11769               ;; this happens, the active range can be in the millions.
11770               ;; Use a compressed range to avoid creating a huge list.
11771               (gnus-range-difference (list gnus-newsgroup-active) old))
11772         (setq len (gnus-range-length older))
11773         (cond
11774          ((null older) nil)
11775          ((numberp all)
11776           (if (< all len)
11777               (let ((older-range (nreverse older)))
11778                 (setq older nil)
11779
11780                 (while (> all 0)
11781                   (let* ((r (pop older-range))
11782                          (min (if (numberp r) r (car r)))
11783                          (max (if (numberp r) r (cdr r))))
11784                     (while (and (<= min max)
11785                                 (> all 0))
11786                       (push max older)
11787                       (setq all (1- all)
11788                             max (1- max))))))
11789             (setq older (gnus-uncompress-range older))))
11790          (all
11791           (setq older (gnus-uncompress-range older)))
11792          (t
11793           (when (and (numberp gnus-large-newsgroup)
11794                    (> len gnus-large-newsgroup))
11795               (let* ((cursor-in-echo-area nil)
11796                      (initial (gnus-parameter-large-newsgroup-initial
11797                                gnus-newsgroup-name))
11798                      (input
11799                       (read-string
11800                        (format
11801                         "How many articles from %s (%s %d): "
11802                         (gnus-limit-string
11803                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11804                         (if initial "max" "default")
11805                         len)
11806                        (if initial
11807                            (cons (number-to-string initial)
11808                                  0)))))
11809                 (unless (string-match "^[ \t]*$" input)
11810                   (setq all (string-to-number input))
11811                   (if (< all len)
11812                       (let ((older-range (nreverse older)))
11813                         (setq older nil)
11814
11815                         (while (> all 0)
11816                           (let* ((r (pop older-range))
11817                                  (min (if (numberp r) r (car r)))
11818                                  (max (if (numberp r) r (cdr r))))
11819                             (while (and (<= min max)
11820                                         (> all 0))
11821                               (push max older)
11822                               (setq all (1- all)
11823                                     max (1- max))))))))))
11824           (setq older (gnus-uncompress-range older))))
11825         (if (not older)
11826             (message "No old news.")
11827           (gnus-summary-insert-articles older)
11828           (gnus-summary-limit (gnus-sorted-nunion old older))))
11829     (gnus-summary-position-point)))
11830
11831 (defun gnus-summary-insert-new-articles ()
11832   "Insert all new articles in this group."
11833   (interactive)
11834   (prog1
11835       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11836             (old-active gnus-newsgroup-active)
11837             (nnmail-fetched-sources (list t))
11838             i new)
11839         (setq gnus-newsgroup-active
11840               (gnus-activate-group gnus-newsgroup-name 'scan))
11841         (setq i (cdr gnus-newsgroup-active))
11842         (while (> i (cdr old-active))
11843           (push i new)
11844           (decf i))
11845         (if (not new)
11846             (message "No gnus is bad news.")
11847           (gnus-summary-insert-articles new)
11848           (setq gnus-newsgroup-unreads
11849                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11850           (gnus-summary-limit (gnus-sorted-nunion old new))))
11851     (gnus-summary-position-point)))
11852
11853 (gnus-summary-make-all-marking-commands)
11854
11855 (gnus-ems-redefine)
11856
11857 (provide 'gnus-sum)
11858
11859 (run-hooks 'gnus-sum-load-hook)
11860
11861 ;;; gnus-sum.el ends here