c3331e39fd6dce4d70da128a63b176c4e7bb4ded
[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
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify" 
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61
62 (defcustom gnus-kill-summary-on-exit t
63   "*If non-nil, kill the summary buffer when you exit from it.
64 If nil, the summary will become a \"*Dead Summary*\" buffer, and
65 it will be killed sometime later."
66   :group 'gnus-summary-exit
67   :type 'boolean)
68
69 (defcustom gnus-fetch-old-headers nil
70   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
71 If an unread article in the group refers to an older, already read (or
72 just marked as read) article, the old article will not normally be
73 displayed in the Summary buffer.  If this variable is non-nil, Gnus
74 will attempt to grab the headers to the old articles, and thereby
75 build complete threads.  If it has the value `some', only enough
76 headers to connect otherwise loose threads will be displayed.  This
77 variable can also be a number.  In that case, no more than that number
78 of old headers will be fetched.  If it has the value `invisible', all
79 old headers will be fetched, but none will be displayed.
80
81 The server has to support NOV for any of this to work."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const some)
85                  number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-refer-thread-limit 200
89   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
90 If t, fetch all the available old headers."
91   :group 'gnus-thread
92   :type '(choice number
93                  (sexp :menu-tag "other" t)))
94
95 (defcustom gnus-summary-make-false-root 'adopt
96   "*nil means that Gnus won't gather loose threads.
97 If the root of a thread has expired or been read in a previous
98 session, the information necessary to build a complete thread has been
99 lost.  Instead of having many small sub-threads from this original thread
100 scattered all over the summary buffer, Gnus can gather them.
101
102 If non-nil, Gnus will try to gather all loose sub-threads from an
103 original thread into one large thread.
104
105 If this variable is non-nil, it should be one of `none', `adopt',
106 `dummy' or `empty'.
107
108 If this variable is `none', Gnus will not make a false root, but just
109 present the sub-threads after another.
110 If this variable is `dummy', Gnus will create a dummy root that will
111 have all the sub-threads as children.
112 If this variable is `adopt', Gnus will make one of the \"children\"
113 the parent and mark all the step-children as such.
114 If this variable is `empty', the \"children\" are printed with empty
115 subject fields.  (Or rather, they will be printed with a string
116 given by the `gnus-summary-same-subject' variable.)"
117   :group 'gnus-thread
118   :type '(choice (const :tag "off" nil)
119                  (const none)
120                  (const dummy)
121                  (const adopt)
122                  (const empty)))
123
124 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
125   "*A regexp to match subjects to be excluded from loose thread gathering.
126 As loose thread gathering is done on subjects only, that means that
127 there can be many false gatherings performed.  By rooting out certain
128 common subjects, gathering might become saner."
129   :group 'gnus-thread
130   :type 'regexp)
131
132 (defcustom gnus-summary-gather-subject-limit nil
133   "*Maximum length of subject comparisons when gathering loose threads.
134 Use nil to compare full subjects.  Setting this variable to a low
135 number will help gather threads that have been corrupted by
136 newsreaders chopping off subject lines, but it might also mean that
137 unrelated articles that have subject that happen to begin with the
138 same few characters will be incorrectly gathered.
139
140 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
141 comparing subjects."
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const fuzzy)
145                  (sexp :menu-tag "on" t)))
146
147 (defcustom gnus-simplify-subject-functions nil
148   "List of functions taking a string argument that simplify subjects.
149 The functions are applied recursively.
150
151 Useful functions to put in this list include: `gnus-simplify-subject-re',
152 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 (they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-killed t
260   "*If non-nil, hide killed threads automatically."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-ignore-subject t
265   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
266 If nil, articles that have different subjects from their parents will
267 start separate threads."
268   :group 'gnus-thread
269   :type 'boolean)
270
271 (defcustom gnus-thread-operation-ignore-subject t
272   "*If non-nil, subjects will be ignored when doing thread commands.
273 This affects commands like `gnus-summary-kill-thread' and
274 `gnus-summary-lower-thread'.
275
276 If this variable is nil, articles in the same thread with different
277 subjects will not be included in the operation in question.  If this
278 variable is `fuzzy', only articles that have subjects that are fuzzily
279 equal will be included."
280   :group 'gnus-thread
281   :type '(choice (const :tag "off" nil)
282                  (const fuzzy)
283                  (sexp :tag "on" t)))
284
285 (defcustom gnus-thread-indent-level 4
286   "*Number that says how much each sub-thread should be indented."
287   :group 'gnus-thread
288   :type 'integer)
289
290 (defcustom gnus-auto-extend-newsgroup t
291   "*If non-nil, extend newsgroup forward and backward when requested."
292   :group 'gnus-summary-choose
293   :type 'boolean)
294
295 (defcustom gnus-auto-select-first t
296   "*If non-nil, select the article under point.
297 Which article this is is controlled by the `gnus-auto-select-subject'
298 variable.
299
300 If you want to prevent automatic selection of articles in some
301 newsgroups, set the variable to nil in `gnus-select-group-hook'."
302   :group 'gnus-group-select
303   :type '(choice (const :tag "none" nil)
304                  (sexp :menu-tag "first" t)))
305
306 (defcustom gnus-auto-select-subject 'unread
307   "*Says what subject to place under point when entering a group.
308
309 This variable can either be the symbols `first' (place point on the
310 first subject), `unread' (place point on the subject line of the first
311 unread article), `best' (place point on the subject line of the
312 higest-scored article), `unseen' (place point on the subject line of
313 the first unseen article), 'unseen-or-unread' (place point on the subject
314 line of the first unseen article or, if all article have been seen, on the
315 subject line of the first unread article), or a function to be called to
316 place point on some subject line."
317   :group 'gnus-group-select
318   :type '(choice (const best)
319                  (const unread)
320                  (const first)
321                  (const unseen)
322                  (const unseen-or-unread)))
323
324 (defcustom gnus-dont-select-after-jump-to-other-group nil
325   "If non-nil, don't select the first unread article after entering the
326 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
327 it is depend on the value of `gnus-auto-select-first' whether to select
328 or not."
329   :group 'gnus-group-select
330   :type 'boolean)
331
332 (defcustom gnus-auto-select-next t
333   "*If non-nil, offer to go to the next group from the end of the previous.
334 If the value is t and the next newsgroup is empty, Gnus will exit
335 summary mode and go back to group mode.  If the value is neither nil
336 nor t, Gnus will select the following unread newsgroup.  In
337 particular, if the value is the symbol `quietly', the next unread
338 newsgroup will be selected without any confirmation, and if it is
339 `almost-quietly', the next group will be selected without any
340 confirmation if you are located on the last article in the group.
341 Finally, if this variable is `slightly-quietly', the `Z n' command
342 will go to the next group without confirmation."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "off" nil)
345                  (const quietly)
346                  (const almost-quietly)
347                  (const slightly-quietly)
348                  (sexp :menu-tag "on" t)))
349
350 (defcustom gnus-auto-select-same nil
351   "*If non-nil, select the next article with the same subject.
352 If there are no more articles with the same subject, go to
353 the first unread article."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-summary-check-current nil
358   "*If non-nil, consider the current article when moving.
359 The \"unread\" movement commands will stay on the same line if the
360 current article is unread."
361   :group 'gnus-summary-maneuvering
362   :type 'boolean)
363
364 (defcustom gnus-auto-center-summary t
365   "*If non-nil, always center the current summary buffer.
366 In particular, if `vertical' do only vertical recentering.  If non-nil
367 and non-`vertical', do both horizontal and vertical recentering."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "none" nil)
370                  (const vertical)
371                  (integer :tag "height")
372                  (sexp :menu-tag "both" t)))
373
374 (defcustom gnus-show-all-headers nil
375   "*If non-nil, don't hide any headers."
376   :group 'gnus-article-hiding
377   :group 'gnus-article-headers
378   :type 'boolean)
379
380 (defcustom gnus-summary-ignore-duplicates nil
381   "*If non-nil, ignore articles with identical Message-ID headers."
382   :group 'gnus-summary
383   :type 'boolean)
384
385 (defcustom gnus-single-article-buffer t
386   "*If non-nil, display all articles in the same buffer.
387 If nil, each group will get its own article buffer."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-break-pages t
392   "*If non-nil, do page breaking on articles.
393 The page delimiter is specified by the `gnus-page-delimiter'
394 variable."
395   :group 'gnus-article-various
396   :type 'boolean)
397
398 (defcustom gnus-show-mime t
399   "*If non-nil, do mime processing of articles.
400 The articles will simply be fed to the function given by
401 `gnus-article-display-method-for-mime'."
402   :group 'gnus-article-mime
403   :type 'boolean)
404
405 (defcustom gnus-move-split-methods nil
406   "*Variable used to suggest where articles are to be moved to.
407 It uses the same syntax as the `gnus-split-methods' variable.
408 However, whereas `gnus-split-methods' specifies file names as targets,
409 this variable specifies group names."
410   :group 'gnus-summary-mail
411   :type '(repeat (choice (list :value (fun) function)
412                          (cons :value ("" "") regexp (repeat string))
413                          (sexp :value nil))))
414
415 (defcustom gnus-unread-mark ?\ ;;;Whitespace
416   "*Mark used for unread articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-ticked-mark ?!
421   "*Mark used for ticked articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-dormant-mark ??
426   "*Mark used for dormant articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-del-mark ?r
431   "*Mark used for del'd articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-read-mark ?R
436   "*Mark used for read articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-expirable-mark ?E
441   "*Mark used for expirable articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-killed-mark ?K
446   "*Mark used for killed articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-souped-mark ?F
451   "*Mark used for souped articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-kill-file-mark ?X
456   "*Mark used for articles killed by kill files."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-low-score-mark ?Y
461   "*Mark used for articles with a low score."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-catchup-mark ?C
466   "*Mark used for articles that are caught up."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-replied-mark ?A
471   "*Mark used for articles that have been replied to."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-forwarded-mark ?F
476   "*Mark used for articles that have been forwarded."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-recent-mark ?N
481   "*Mark used for articles that are recent."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-cached-mark ?*
486   "*Mark used for articles that are in the cache."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-saved-mark ?S
491   "*Mark used for articles that have been saved."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-unseen-mark ?.
496   "*Mark used for articles that haven't been seen."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-no-mark ?\ ;;;Whitespace
501   "*Mark used for articles that have no other secondary mark."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ancient-mark ?O
506   "*Mark used for ancient articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-sparse-mark ?Q
511   "*Mark used for sparsely reffed articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-canceled-mark ?G
516   "*Mark used for canceled articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-duplicate-mark ?M
521   "*Mark used for duplicate articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-undownloaded-mark ?@
526   "*Mark used for articles that weren't downloaded."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-downloadable-mark ?%
531   "*Mark used for articles that are to be downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unsendable-mark ?=
536   "*Mark used for articles that won't be sent."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-score-over-mark ?+
541   "*Score mark used for articles with high scores."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-below-mark ?-
546   "*Score mark used for articles with low scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
551   "*There is no thread under the article."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-not-empty-thread-mark ?=
556   "*There is a thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-view-pseudo-asynchronously nil
561   "*If non-nil, Gnus will view pseudo-articles asynchronously."
562   :group 'gnus-extract-view
563   :type 'boolean)
564
565 (defcustom gnus-auto-expirable-marks
566   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
567         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
568         gnus-souped-mark gnus-duplicate-mark)
569   "*The list of marks converted into expiration if a group is auto-expirable."
570   :version "21.1"
571   :group 'gnus-summary
572   :type '(repeat character))
573
574 (defcustom gnus-inhibit-user-auto-expire t
575   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
576   :version "21.1"
577   :group 'gnus-summary
578   :type 'boolean)
579
580 (defcustom gnus-view-pseudos nil
581   "*If `automatic', pseudo-articles will be viewed automatically.
582 If `not-confirm', pseudos will be viewed automatically, and the user
583 will not be asked to confirm the command."
584   :group 'gnus-extract-view
585   :type '(choice (const :tag "off" nil)
586                  (const automatic)
587                  (const not-confirm)))
588
589 (defcustom gnus-view-pseudos-separately t
590   "*If non-nil, one pseudo-article will be created for each file to be viewed.
591 If nil, all files that use the same viewing command will be given as a
592 list of parameters to that command."
593   :group 'gnus-extract-view
594   :type 'boolean)
595
596 (defcustom gnus-insert-pseudo-articles t
597   "*If non-nil, insert pseudo-articles when decoding articles."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-summary-dummy-line-format
602   "  %(:                          :%) %S\n"
603   "*The format specification for the dummy roots in the summary buffer.
604 It works along the same lines as a normal formatting string,
605 with some simple extensions.
606
607 %S  The subject
608
609 General format specifiers can also be used.
610 See (gnus)Formatting Variables."
611   :link '(custom-manual "(gnus)Formatting Variables")
612   :group 'gnus-threading
613   :type 'string)
614
615 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
616   "*The format specification for the summary mode line.
617 It works along the same lines as a normal formatting string,
618 with some simple extensions:
619
620 %G  Group name
621 %p  Unprefixed group name
622 %A  Current article number
623 %z  Current article score
624 %V  Gnus version
625 %U  Number of unread articles in the group
626 %e  Number of unselected articles in the group
627 %Z  A string with unread/unselected article counts
628 %g  Shortish group name
629 %S  Subject of the current article
630 %u  User-defined spec
631 %s  Current score file name
632 %d  Number of dormant articles
633 %r  Number of articles that have been marked as read in this session
634 %E  Number of articles expunged by the score files"
635   :group 'gnus-summary-format
636   :type 'string)
637
638 (defcustom gnus-list-identifiers nil
639   "Regexp that matches list identifiers to be removed from subject.
640 This can also be a list of regexps."
641   :version "21.1"
642   :group 'gnus-summary-format
643   :group 'gnus-article-hiding
644   :type '(choice (const :tag "none" nil)
645                  (regexp :value ".*")
646                  (repeat :value (".*") regexp)))
647
648 (defcustom gnus-summary-mark-below 0
649   "*Mark all articles with a score below this variable as read.
650 This variable is local to each summary buffer and usually set by the
651 score file."
652   :group 'gnus-score-default
653   :type 'integer)
654
655 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
656   "*List of functions used for sorting articles in the summary buffer.
657
658 Each function takes two articles and returns non-nil if the first
659 article should be sorted before the other.  If you use more than one
660 function, the primary sort function should be the last.  You should
661 probably always include `gnus-article-sort-by-number' in the list of
662 sorting functions -- preferably first.  Also note that sorting by date
663 is often much slower than sorting by number, and the sorting order is
664 very similar.  (Sorting by date means sorting by the time the message
665 was sent, sorting by number means sorting by arrival time.)
666
667 Ready-made functions include `gnus-article-sort-by-number',
668 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
669 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
670
671 When threading is turned on, the variable `gnus-thread-sort-functions'
672 controls how articles are sorted."
673   :group 'gnus-summary-sort
674   :type '(repeat (choice (function-item gnus-article-sort-by-number)
675                          (function-item gnus-article-sort-by-author)
676                          (function-item gnus-article-sort-by-subject)
677                          (function-item gnus-article-sort-by-date)
678                          (function-item gnus-article-sort-by-score)
679                          (function :tag "other"))))
680
681 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
682   "*List of functions used for sorting threads in the summary buffer.
683 By default, threads are sorted by article number.
684
685 Each function takes two threads and returns non-nil if the first
686 thread should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-thread-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-thread-sort-by-number',
695 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
696 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
697 `gnus-thread-sort-by-most-recent-number',
698 `gnus-thread-sort-by-most-recent-date', and
699 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
700
701 When threading is turned off, the variable
702 `gnus-article-sort-functions' controls how articles are sorted."
703   :group 'gnus-summary-sort
704   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
705                          (function-item gnus-thread-sort-by-author)
706                          (function-item gnus-thread-sort-by-subject)
707                          (function-item gnus-thread-sort-by-date)
708                          (function-item gnus-thread-sort-by-score)
709                          (function-item gnus-thread-sort-by-total-score)
710                          (function :tag "other"))))
711
712 (defcustom gnus-thread-score-function '+
713   "*Function used for calculating the total score of a thread.
714
715 The function is called with the scores of the article and each
716 subthread and should then return the score of the thread.
717
718 Some functions you can use are `+', `max', or `min'."
719   :group 'gnus-summary-sort
720   :type 'function)
721
722 (defcustom gnus-summary-expunge-below nil
723   "All articles that have a score less than this variable will be expunged.
724 This variable is local to the summary buffers."
725   :group 'gnus-score-default
726   :type '(choice (const :tag "off" nil)
727                  integer))
728
729 (defcustom gnus-thread-expunge-below nil
730   "All threads that have a total score less than this variable will be expunged.
731 See `gnus-thread-score-function' for en explanation of what a
732 \"thread score\" is.
733
734 This variable is local to the summary buffers."
735   :group 'gnus-threading
736   :group 'gnus-score-default
737   :type '(choice (const :tag "off" nil)
738                  integer))
739
740 (defcustom gnus-summary-mode-hook nil
741   "*A hook for Gnus summary mode.
742 This hook is run before any variables are set in the summary buffer."
743   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
748 (when (featurep 'xemacs)
749   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
750   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
751   (add-hook 'gnus-summary-mode-hook
752             'gnus-xmas-switch-horizontal-scrollbar-off))
753
754 (defcustom gnus-summary-menu-hook nil
755   "*Hook run after the creation of the summary mode menu."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-summary-exit-hook nil
760   "*A hook called on exit from the summary buffer.
761 It will be called with point in the group buffer."
762   :group 'gnus-summary-exit
763   :type 'hook)
764
765 (defcustom gnus-summary-prepare-hook nil
766   "*A hook called after the summary buffer has been generated.
767 If you want to modify the summary buffer, you can use this hook."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-summary-prepared-hook nil
772   "*A hook called as the last thing after the summary buffer has been generated."
773   :group 'gnus-summary-various
774   :type 'hook)
775
776 (defcustom gnus-summary-generate-hook nil
777   "*A hook run just before generating the summary buffer.
778 This hook is commonly used to customize threading variables and the
779 like."
780   :group 'gnus-summary-various
781   :type 'hook)
782
783 (defcustom gnus-select-group-hook nil
784   "*A hook called when a newsgroup is selected.
785
786 If you'd like to simplify subjects like the
787 `gnus-summary-next-same-subject' command does, you can use the
788 following hook:
789
790  (add-hook gnus-select-group-hook
791            (lambda ()
792              (mapcar (lambda (header)
793                        (mail-header-set-subject
794                         header
795                         (gnus-simplify-subject
796                          (mail-header-subject header) 're-only)))
797                      gnus-newsgroup-headers)))"
798   :group 'gnus-group-select
799   :type 'hook)
800
801 (defcustom gnus-select-article-hook nil
802   "*A hook called when an article is selected."
803   :group 'gnus-summary-choose
804   :type 'hook)
805
806 (defcustom gnus-visual-mark-article-hook
807   (list 'gnus-highlight-selected-summary)
808   "*Hook run after selecting an article in the summary buffer.
809 It is meant to be used for highlighting the article in some way.  It
810 is not run if `gnus-visual' is nil."
811   :group 'gnus-summary-visual
812   :type 'hook)
813
814 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
815   "*A hook called before parsing the headers."
816   :group 'gnus-various
817   :type 'hook)
818
819 (defcustom gnus-exit-group-hook nil
820   "*A hook called when exiting summary mode.
821 This hook is not called from the non-updating exit commands like `Q'."
822   :group 'gnus-various
823   :type 'hook)
824
825 (defcustom gnus-summary-update-hook
826   (list 'gnus-summary-highlight-line)
827   "*A hook called when a summary line is changed.
828 The hook will not be called if `gnus-visual' is nil.
829
830 The default function `gnus-summary-highlight-line' will
831 highlight the line according to the `gnus-summary-highlight'
832 variable."
833   :group 'gnus-summary-visual
834   :type 'hook)
835
836 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
837   "*A hook called when an article is selected for the first time.
838 The hook is intended to mark an article as read (or unread)
839 automatically when it is selected."
840   :group 'gnus-summary-choose
841   :type 'hook)
842
843 (defcustom gnus-group-no-more-groups-hook nil
844   "*A hook run when returning to group mode having no more (unread) groups."
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-ps-print-hook nil
849   "*A hook run before ps-printing something from Gnus."
850   :group 'gnus-summary
851   :type 'hook)
852
853 (defcustom gnus-summary-display-arrow
854   (and (fboundp 'display-graphic-p)
855        (display-graphic-p))
856   "*If non-nil, display an arrow highlighting the current article."
857   :version "21.1"
858   :group 'gnus-summary
859   :type 'boolean)
860
861 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
862   "Face used for highlighting the current article in the summary buffer."
863   :group 'gnus-summary-visual
864   :type 'face)
865
866 (defcustom gnus-summary-highlight
867   '(((= mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (= mark gnus-dormant-mark)
871               (= mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (= mark gnus-dormant-mark)
875               (= mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (= mark gnus-dormant-mark)
878          (= mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (= mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (= mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((= mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (= mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (= mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((= mark gnus-unread-mark)
891      . gnus-summary-normal-unread-face)
892     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
893                                                   gnus-undownloaded-mark)))
894      . gnus-summary-high-unread-face)
895     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
896                                                  gnus-undownloaded-mark)))
897      . gnus-summary-low-unread-face)
898     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899           (memq article gnus-newsgroup-unreads))
900      . gnus-summary-normal-unread-face)
901     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
902      . gnus-summary-normal-read-face)
903     ((> score default-high)
904      . gnus-summary-high-read-face)
905     ((< score default-low)
906      . gnus-summary-low-read-face)
907     (t
908      . gnus-summary-normal-read-face))
909   "*Controls the highlighting of summary buffer lines.
910
911 A list of (FORM . FACE) pairs.  When deciding how a a particular
912 summary line should be displayed, each form is evaluated.  The content
913 of the face field after the first true form is used.  You can change
914 how those summary lines are displayed, by editing the face field.
915
916 You can use the following variables in the FORM field.
917
918 score:        The article's score
919 default:      The default article score.
920 default-high: The default score for high scored articles.
921 default-low:  The default score for low scored articles.
922 below:        The score below which articles are automatically marked as read.
923 mark:         The articles mark."
924   :group 'gnus-summary-visual
925   :type '(repeat (cons (sexp :tag "Form" nil)
926                        face)))
927
928 (defcustom gnus-alter-header-function nil
929   "Function called to allow alteration of article header structures.
930 The function is called with one parameter, the article header vector,
931 which it may alter in any way.")
932
933 (defvar gnus-decode-encoded-word-function
934   (mime-find-field-decoder 'From 'nov)
935   "Variable that says which function should be used to decode a string with encoded words.")
936
937 (defcustom gnus-extra-headers '(To Newsgroups)
938   "*Extra headers to parse."
939   :version "21.1"
940   :group 'gnus-summary
941   :type '(repeat symbol))
942
943 (defcustom gnus-ignored-from-addresses
944   (and user-mail-address (regexp-quote user-mail-address))
945   "*Regexp of From headers that may be suppressed in favor of To headers."
946   :version "21.1"
947   :group 'gnus-summary
948   :type 'regexp)
949
950 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
951   "List of charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954   :version "21.1"
955   :type '(repeat symbol)
956   :group 'gnus-charset)
957
958 (gnus-define-group-parameter
959  ignored-charsets
960  :type list
961  :function-document
962  "Return the ignored charsets of GROUP."
963  :variable gnus-group-ignored-charsets-alist
964  :variable-default
965  '(("alt\\.chinese\\.text" iso-8859-1))
966  :variable-document
967  "Alist of regexps (to match group names) and charsets that should be ignored.
968 When these charsets are used in the \"charset\" parameter, the
969 default charset will be used instead."
970  :variable-group gnus-charset
971  :variable-type '(repeat (cons (regexp :tag "Group")
972                                (repeat symbol)))
973  :parameter-type '(choice :tag "Ignored charsets"
974                           :value nil
975                           (repeat (symbol)))
976  :parameter-document       "\
977 List of charsets that should be ignored.
978
979 When these charsets are used in the \"charset\" parameter, the
980 default charset will be used instead.")
981
982 (defcustom gnus-group-highlight-words-alist nil
983   "Alist of group regexps and highlight regexps.
984 This variable uses the same syntax as `gnus-emphasis-alist'."
985   :version "21.1"
986   :type '(repeat (cons (regexp :tag "Group")
987                        (repeat (list (regexp :tag "Highlight regexp")
988                                      (number :tag "Group for entire word" 0)
989                                      (number :tag "Group for displayed part" 0)
990                                      (symbol :tag "Face"
991                                              gnus-emphasis-highlight-words)))))
992   :group 'gnus-summary-visual)
993
994 (defcustom gnus-use-wheel nil
995   "Use Intelli-mouse on summary movement"
996   :type 'boolean
997   :group 'gnus-summary-maneuvering)
998
999 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1000   "Amount to scroll messages by spinning the mouse wheel.
1001 This is actually a cons cell, where the first item is the amount to scroll
1002 on a normal wheel event, and the second is the amount to scroll when the
1003 wheel is moved with the shift key depressed."
1004   :type '(cons (integer :tag "Shift") integer)
1005   :group 'gnus-summary-maneuvering)
1006
1007 (defcustom gnus-wheel-edge-resistance 2
1008   "How hard it should be to change the current article
1009 by moving the mouse over the edge of the article window."
1010   :type 'integer
1011   :group 'gnus-summary-maneuvering)
1012
1013 (defcustom gnus-summary-show-article-charset-alist
1014   nil
1015   "Alist of number and charset.
1016 The article will be shown with the charset corresponding to the
1017 numbered argument.
1018 For example: ((1 . cn-gb-2312) (2 . big5))."
1019   :version "21.1"
1020   :type '(repeat (cons (number :tag "Argument" 1)
1021                        (symbol :tag "Charset")))
1022   :group 'gnus-charset)
1023
1024 (defcustom gnus-preserve-marks t
1025   "Whether marks are preserved when moving, copying and respooling messages."
1026   :version "21.1"
1027   :type 'boolean
1028   :group 'gnus-summary-marks)
1029
1030 (defcustom gnus-alter-articles-to-read-function nil
1031   "Function to be called to alter the list of articles to be selected."
1032   :type '(choice (const nil) function)
1033   :group 'gnus-summary)
1034
1035 (defcustom gnus-orphan-score nil
1036   "*All orphans get this score added.  Set in the score file."
1037   :group 'gnus-score-default
1038   :type '(choice (const nil)
1039                  integer))
1040
1041 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1042   "*A regexp to match MIME parts when saving multiple parts of a message
1043 with gnus-summary-save-parts (X m). This regexp will be used by default
1044 when prompting the user for which type of files to save."
1045   :group 'gnus-summary
1046   :type 'regexp)
1047
1048 (defcustom gnus-read-all-available-headers nil
1049   "Whether Gnus should parse all headers made available to it.
1050 This is mostly relevant for slow backends where the user may
1051 wish to widen the summary buffer to include all headers
1052 that were fetched.  Say, for nnultimate groups."
1053   :group 'gnus-summary
1054   :type '(choice boolean regexp))
1055
1056 (defcustom gnus-summary-muttprint-program "muttprint"
1057   "Command (and optional arguments) used to run Muttprint."
1058   :version "21.3"
1059   :group 'gnus-summary
1060   :type 'string)
1061
1062 (defcustom gnus-article-loose-mime nil
1063   "If non-nil, don't require MIME-Version header.
1064 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1065 supply the MIME-Version header or deliberately strip it From the mail.
1066 Set it to non-nil, Gnus will treat some articles as MIME even if
1067 the MIME-Version header is missed."
1068   :version "21.3"
1069   :type 'boolean
1070   :group 'gnus-article)
1071
1072 ;;; Internal variables
1073
1074 (defvar gnus-summary-display-cache nil)
1075 (defvar gnus-article-mime-handles nil)
1076 (defvar gnus-article-decoded-p nil)
1077 (defvar gnus-article-charset nil)
1078 (defvar gnus-article-ignored-charsets nil)
1079 (defvar gnus-scores-exclude-files nil)
1080 (defvar gnus-page-broken nil)
1081 (defvar gnus-inhibit-mime-unbuttonizing nil)
1082
1083 (defvar gnus-original-article nil)
1084 (defvar gnus-article-internal-prepare-hook nil)
1085 (defvar gnus-newsgroup-process-stack nil)
1086
1087 (defvar gnus-thread-indent-array nil)
1088 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1089 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1090   "Function called to sort the articles within a thread after it has been gathered together.")
1091
1092 (defvar gnus-summary-save-parts-type-history nil)
1093 (defvar gnus-summary-save-parts-last-directory nil)
1094
1095 ;; Avoid highlighting in kill files.
1096 (defvar gnus-summary-inhibit-highlight nil)
1097 (defvar gnus-newsgroup-selected-overlay nil)
1098 (defvar gnus-inhibit-limiting nil)
1099 (defvar gnus-newsgroup-adaptive-score-file nil)
1100 (defvar gnus-current-score-file nil)
1101 (defvar gnus-current-move-group nil)
1102 (defvar gnus-current-copy-group nil)
1103 (defvar gnus-current-crosspost-group nil)
1104 (defvar gnus-newsgroup-display nil)
1105
1106 (defvar gnus-newsgroup-dependencies nil)
1107 (defvar gnus-newsgroup-adaptive nil)
1108 (defvar gnus-summary-display-article-function nil)
1109 (defvar gnus-summary-highlight-line-function nil
1110   "Function called after highlighting a summary line.")
1111
1112 (defvar gnus-summary-line-format-alist
1113   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1114     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1115     (?s gnus-tmp-subject-or-nil ?s)
1116     (?n gnus-tmp-name ?s)
1117     (?A (std11-address-string
1118          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1119     (?a (or (std11-full-name-string
1120              (car (mime-entity-read-field gnus-tmp-header 'From)))
1121             gnus-tmp-from) ?s)
1122     (?F gnus-tmp-from ?s)
1123     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1124     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1125     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1126     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1127     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1128     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1129     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1130     (?L gnus-tmp-lines ?s)
1131     (?I gnus-tmp-indentation ?s)
1132     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1133     (?R gnus-tmp-replied ?c)
1134     (?\[ gnus-tmp-opening-bracket ?c)
1135     (?\] gnus-tmp-closing-bracket ?c)
1136     (?\> (make-string gnus-tmp-level ? ) ?s)
1137     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1138     (?i gnus-tmp-score ?d)
1139     (?z gnus-tmp-score-char ?c)
1140     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1141     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1142     (?U gnus-tmp-unread ?c)
1143     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1144         ?s)
1145     (?t (gnus-summary-number-of-articles-in-thread
1146          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1147         ?d)
1148     (?e (gnus-summary-number-of-articles-in-thread
1149          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1150         ?c)
1151     (?u gnus-tmp-user-defined ?s)
1152     (?P (gnus-pick-line-number) ?d)
1153     (?B gnus-tmp-thread-tree-header-string ?s)
1154     (user-date (gnus-user-date
1155                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1156   "An alist of format specifications that can appear in summary lines.
1157 These are paired with what variables they correspond with, along with
1158 the type of the variable (string, integer, character, etc).")
1159
1160 (defvar gnus-summary-dummy-line-format-alist
1161   `((?S gnus-tmp-subject ?s)
1162     (?N gnus-tmp-number ?d)
1163     (?u gnus-tmp-user-defined ?s)))
1164
1165 (defvar gnus-summary-mode-line-format-alist
1166   `((?G gnus-tmp-group-name ?s)
1167     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1168     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1169     (?A gnus-tmp-article-number ?d)
1170     (?Z gnus-tmp-unread-and-unselected ?s)
1171     (?V gnus-version ?s)
1172     (?U gnus-tmp-unread-and-unticked ?d)
1173     (?S gnus-tmp-subject ?s)
1174     (?e gnus-tmp-unselected ?d)
1175     (?u gnus-tmp-user-defined ?s)
1176     (?d (length gnus-newsgroup-dormant) ?d)
1177     (?t (length gnus-newsgroup-marked) ?d)
1178     (?r (length gnus-newsgroup-reads) ?d)
1179     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1180     (?E gnus-newsgroup-expunged-tally ?d)
1181     (?s (gnus-current-score-file-nondirectory) ?s)))
1182
1183 (defvar gnus-last-search-regexp nil
1184   "Default regexp for article search command.")
1185
1186 (defvar gnus-summary-search-article-matched-data nil
1187   "Last matched data of article search command.  It is the local variable
1188 in `gnus-article-buffer' which consists of the list of start position,
1189 end position and text.")
1190
1191 (defvar gnus-last-shell-command nil
1192   "Default shell command on article.")
1193
1194 (defvar gnus-newsgroup-begin nil)
1195 (defvar gnus-newsgroup-end nil)
1196 (defvar gnus-newsgroup-last-rmail nil)
1197 (defvar gnus-newsgroup-last-mail nil)
1198 (defvar gnus-newsgroup-last-folder nil)
1199 (defvar gnus-newsgroup-last-file nil)
1200 (defvar gnus-newsgroup-auto-expire nil)
1201 (defvar gnus-newsgroup-active nil)
1202
1203 (defvar gnus-newsgroup-data nil)
1204 (defvar gnus-newsgroup-data-reverse nil)
1205 (defvar gnus-newsgroup-limit nil)
1206 (defvar gnus-newsgroup-limits nil)
1207
1208 (defvar gnus-newsgroup-unreads nil
1209   "Sorted list of unread articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-unselected nil
1212   "Sorted list of unselected unread articles in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-reads nil
1215   "Alist of read articles and article marks in the current newsgroup.")
1216
1217 (defvar gnus-newsgroup-expunged-tally nil)
1218
1219 (defvar gnus-newsgroup-marked nil
1220   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1221
1222 (defvar gnus-newsgroup-killed nil
1223   "List of ranges of articles that have been through the scoring process.")
1224
1225 (defvar gnus-newsgroup-cached nil
1226   "Sorted list of articles that come from the article cache.")
1227
1228 (defvar gnus-newsgroup-saved nil
1229   "List of articles that have been saved.")
1230
1231 (defvar gnus-newsgroup-kill-headers nil)
1232
1233 (defvar gnus-newsgroup-replied nil
1234   "List of articles that have been replied to in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-forwarded nil
1237   "List of articles that have been forwarded in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-recent nil
1240   "List of articles that have are recent in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-expirable nil
1243   "Sorted list of articles in the current newsgroup that can be expired.")
1244
1245 (defvar gnus-newsgroup-processable nil
1246   "List of articles in the current newsgroup that can be processed.")
1247
1248 (defvar gnus-newsgroup-downloadable nil
1249   "Sorted list of articles in the current newsgroup that can be processed.")
1250
1251 (defvar gnus-newsgroup-undownloaded nil
1252   "List of articles in the current newsgroup that haven't been downloaded..")
1253
1254 (defvar gnus-newsgroup-unsendable nil
1255   "List of articles in the current newsgroup that won't be sent.")
1256
1257 (defvar gnus-newsgroup-bookmarks nil
1258   "List of articles in the current newsgroup that have bookmarks.")
1259
1260 (defvar gnus-newsgroup-dormant nil
1261   "Sorted list of dormant articles in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-unseen nil
1264   "List of unseen articles in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-seen nil
1267   "Range of seen articles in the current newsgroup.")
1268
1269 (defvar gnus-newsgroup-articles nil
1270   "List of articles in the current newsgroup.")
1271
1272 (defvar gnus-newsgroup-scored nil
1273   "List of scored articles in the current newsgroup.")
1274
1275 (defvar gnus-newsgroup-incorporated nil
1276   "List of incorporated articles in the current newsgroup.")
1277
1278 (defvar gnus-newsgroup-headers nil
1279   "List of article headers in the current newsgroup.")
1280
1281 (defvar gnus-newsgroup-threads nil)
1282
1283 (defvar gnus-newsgroup-prepared nil
1284   "Whether the current group has been prepared properly.")
1285
1286 (defvar gnus-newsgroup-ancient nil
1287   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-sparse nil)
1290
1291 (defvar gnus-current-article nil)
1292 (defvar gnus-article-current nil)
1293 (defvar gnus-current-headers nil)
1294 (defvar gnus-have-all-headers nil)
1295 (defvar gnus-last-article nil)
1296 (defvar gnus-newsgroup-history nil)
1297 (defvar gnus-newsgroup-charset nil)
1298 (defvar gnus-newsgroup-ephemeral-charset nil)
1299 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1300
1301 (defvar gnus-article-before-search nil)
1302
1303 (defconst gnus-summary-local-variables
1304   '(gnus-newsgroup-name
1305     gnus-newsgroup-begin gnus-newsgroup-end
1306     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1307     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1308     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1309     gnus-newsgroup-unselected gnus-newsgroup-marked
1310     gnus-newsgroup-reads gnus-newsgroup-saved
1311     gnus-newsgroup-replied gnus-newsgroup-forwarded
1312     gnus-newsgroup-recent
1313     gnus-newsgroup-expirable
1314     gnus-newsgroup-processable gnus-newsgroup-killed
1315     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1316     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1317     gnus-newsgroup-seen gnus-newsgroup-articles
1318     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1319     gnus-newsgroup-headers gnus-newsgroup-threads
1320     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1321     gnus-current-article gnus-current-headers gnus-have-all-headers
1322     gnus-last-article gnus-article-internal-prepare-hook
1323     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1324     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1325     gnus-thread-expunge-below
1326     gnus-score-alist gnus-current-score-file
1327     (gnus-summary-expunge-below . global)
1328     (gnus-summary-mark-below . global)
1329     (gnus-orphan-score . global)
1330     gnus-newsgroup-active gnus-scores-exclude-files
1331     gnus-newsgroup-history gnus-newsgroup-ancient
1332     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1333     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1334     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1335     (gnus-newsgroup-expunged-tally . 0)
1336     gnus-cache-removable-articles gnus-newsgroup-cached
1337     gnus-newsgroup-data gnus-newsgroup-data-reverse
1338     gnus-newsgroup-limit gnus-newsgroup-limits
1339     gnus-newsgroup-charset gnus-newsgroup-display
1340     gnus-newsgroup-incorporated)
1341   "Variables that are buffer-local to the summary buffers.")
1342
1343 (defvar gnus-newsgroup-variables nil
1344   "A list of variables that have separate values in different newsgroups.
1345 A list of newsgroup (summary buffer) local variables, or cons of
1346 variables and their default values (when the default values are not
1347 nil), that should be made global while the summary buffer is active.
1348 These variables can be used to set variables in the group parameters
1349 while still allowing them to affect operations done in other
1350 buffers. For example:
1351
1352 \(setq gnus-newsgroup-variables
1353      '(message-use-followup-to
1354        (gnus-visible-headers .
1355          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1356 ")
1357
1358 ;; Byte-compiler warning.
1359 (eval-when-compile (defvar gnus-article-mode-map))
1360
1361 ;; Subject simplification.
1362
1363 (defun gnus-simplify-whitespace (str)
1364   "Remove excessive whitespace from STR."
1365   (let ((mystr str))
1366     ;; Multiple spaces.
1367     (while (string-match "[ \t][ \t]+" mystr)
1368       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1369                           " "
1370                           (substring mystr (match-end 0)))))
1371     ;; Leading spaces.
1372     (when (string-match "^[ \t]+" mystr)
1373       (setq mystr (substring mystr (match-end 0))))
1374     ;; Trailing spaces.
1375     (when (string-match "[ \t]+$" mystr)
1376       (setq mystr (substring mystr 0 (match-beginning 0))))
1377     mystr))
1378
1379 (defsubst gnus-simplify-subject-re (subject)
1380   "Remove \"Re:\" from subject lines."
1381   (if (string-match message-subject-re-regexp subject)
1382       (substring subject (match-end 0))
1383     subject))
1384
1385 (defun gnus-simplify-subject (subject &optional re-only)
1386   "Remove `Re:' and words in parentheses.
1387 If RE-ONLY is non-nil, strip leading `Re:'s only."
1388   (let ((case-fold-search t))           ;Ignore case.
1389     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1390     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1391       (setq subject (substring subject (match-end 0))))
1392     ;; Remove uninteresting prefixes.
1393     (when (and (not re-only)
1394                gnus-simplify-ignored-prefixes
1395                (string-match gnus-simplify-ignored-prefixes subject))
1396       (setq subject (substring subject (match-end 0))))
1397     ;; Remove words in parentheses from end.
1398     (unless re-only
1399       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1400         (setq subject (substring subject 0 (match-beginning 0)))))
1401     ;; Return subject string.
1402     subject))
1403
1404 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1405 ;; all whitespace.
1406 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1407   (goto-char (point-min))
1408   (while (re-search-forward regexp nil t)
1409     (replace-match (or newtext ""))))
1410
1411 (defun gnus-simplify-buffer-fuzzy ()
1412   "Simplify string in the buffer fuzzily.
1413 The string in the accessible portion of the current buffer is simplified.
1414 It is assumed to be a single-line subject.
1415 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1416 matter is removed.  Additional things can be deleted by setting
1417 `gnus-simplify-subject-fuzzy-regexp'."
1418   (let ((case-fold-search t)
1419         (modified-tick))
1420     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1421
1422     (while (not (eq modified-tick (buffer-modified-tick)))
1423       (setq modified-tick (buffer-modified-tick))
1424       (cond
1425        ((listp gnus-simplify-subject-fuzzy-regexp)
1426         (mapcar 'gnus-simplify-buffer-fuzzy-step
1427                 gnus-simplify-subject-fuzzy-regexp))
1428        (gnus-simplify-subject-fuzzy-regexp
1429         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1430       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1431       (gnus-simplify-buffer-fuzzy-step
1432        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1433       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1434
1435     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1436     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1437     (gnus-simplify-buffer-fuzzy-step " $")
1438     (gnus-simplify-buffer-fuzzy-step "^ +")))
1439
1440 (defun gnus-simplify-subject-fuzzy (subject)
1441   "Simplify a subject string fuzzily.
1442 See `gnus-simplify-buffer-fuzzy' for details."
1443   (save-excursion
1444     (gnus-set-work-buffer)
1445     (let ((case-fold-search t))
1446       ;; Remove uninteresting prefixes.
1447       (when (and gnus-simplify-ignored-prefixes
1448                  (string-match gnus-simplify-ignored-prefixes subject))
1449         (setq subject (substring subject (match-end 0))))
1450       (insert subject)
1451       (inline (gnus-simplify-buffer-fuzzy))
1452       (buffer-string))))
1453
1454 (defsubst gnus-simplify-subject-fully (subject)
1455   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1456   (cond
1457    (gnus-simplify-subject-functions
1458     (gnus-map-function gnus-simplify-subject-functions subject))
1459    ((null gnus-summary-gather-subject-limit)
1460     (gnus-simplify-subject-re subject))
1461    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1462     (gnus-simplify-subject-fuzzy subject))
1463    ((numberp gnus-summary-gather-subject-limit)
1464     (gnus-limit-string (gnus-simplify-subject-re subject)
1465                        gnus-summary-gather-subject-limit))
1466    (t
1467     subject)))
1468
1469 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1470   "Check whether two subjects are equal.
1471 If optional argument simple-first is t, first argument is already
1472 simplified."
1473   (cond
1474    ((null simple-first)
1475     (equal (gnus-simplify-subject-fully s1)
1476            (gnus-simplify-subject-fully s2)))
1477    (t
1478     (equal s1
1479            (gnus-simplify-subject-fully s2)))))
1480
1481 (defun gnus-summary-bubble-group ()
1482   "Increase the score of the current group.
1483 This is a handy function to add to `gnus-summary-exit-hook' to
1484 increase the score of each group you read."
1485   (gnus-group-add-score gnus-newsgroup-name))
1486
1487 \f
1488 ;;;
1489 ;;; Gnus summary mode
1490 ;;;
1491
1492 (put 'gnus-summary-mode 'mode-class 'special)
1493
1494 (defvar gnus-article-commands-menu)
1495
1496 (when t
1497   ;; Non-orthogonal keys
1498
1499   (gnus-define-keys gnus-summary-mode-map
1500     " " gnus-summary-next-page
1501     "\177" gnus-summary-prev-page
1502     [delete] gnus-summary-prev-page
1503     [backspace] gnus-summary-prev-page
1504     "\r" gnus-summary-scroll-up
1505     "\M-\r" gnus-summary-scroll-down
1506     "n" gnus-summary-next-unread-article
1507     "p" gnus-summary-prev-unread-article
1508     "N" gnus-summary-next-article
1509     "P" gnus-summary-prev-article
1510     "\M-\C-n" gnus-summary-next-same-subject
1511     "\M-\C-p" gnus-summary-prev-same-subject
1512     "\M-n" gnus-summary-next-unread-subject
1513     "\M-p" gnus-summary-prev-unread-subject
1514     "." gnus-summary-first-unread-article
1515     "," gnus-summary-best-unread-article
1516     "\M-s" gnus-summary-search-article-forward
1517     "\M-r" gnus-summary-search-article-backward
1518     "<" gnus-summary-beginning-of-article
1519     ">" gnus-summary-end-of-article
1520     "j" gnus-summary-goto-article
1521     "^" gnus-summary-refer-parent-article
1522     "\M-^" gnus-summary-refer-article
1523     "u" gnus-summary-tick-article-forward
1524     "!" gnus-summary-tick-article-forward
1525     "U" gnus-summary-tick-article-backward
1526     "d" gnus-summary-mark-as-read-forward
1527     "D" gnus-summary-mark-as-read-backward
1528     "E" gnus-summary-mark-as-expirable
1529     "\M-u" gnus-summary-clear-mark-forward
1530     "\M-U" gnus-summary-clear-mark-backward
1531     "k" gnus-summary-kill-same-subject-and-select
1532     "\C-k" gnus-summary-kill-same-subject
1533     "\M-\C-k" gnus-summary-kill-thread
1534     "\M-\C-l" gnus-summary-lower-thread
1535     "e" gnus-summary-edit-article
1536     "#" gnus-summary-mark-as-processable
1537     "\M-#" gnus-summary-unmark-as-processable
1538     "\M-\C-t" gnus-summary-toggle-threads
1539     "\M-\C-s" gnus-summary-show-thread
1540     "\M-\C-h" gnus-summary-hide-thread
1541     "\M-\C-f" gnus-summary-next-thread
1542     "\M-\C-b" gnus-summary-prev-thread
1543     [(meta down)] gnus-summary-next-thread
1544     [(meta up)] gnus-summary-prev-thread
1545     "\M-\C-u" gnus-summary-up-thread
1546     "\M-\C-d" gnus-summary-down-thread
1547     "&" gnus-summary-execute-command
1548     "c" gnus-summary-catchup-and-exit
1549     "\C-w" gnus-summary-mark-region-as-read
1550     "\C-t" gnus-summary-toggle-truncation
1551     "?" gnus-summary-mark-as-dormant
1552     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1553     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1554     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1555     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1556     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1557     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1558     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1559     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1560     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1561     "=" gnus-summary-expand-window
1562     "\C-x\C-s" gnus-summary-reselect-current-group
1563     "\M-g" gnus-summary-rescan-group
1564     "w" gnus-summary-stop-page-breaking
1565     "\C-c\C-r" gnus-summary-caesar-message
1566     "\M-t" gnus-summary-toggle-mime
1567     "f" gnus-summary-followup
1568     "F" gnus-summary-followup-with-original
1569     "C" gnus-summary-cancel-article
1570     "r" gnus-summary-reply
1571     "R" gnus-summary-reply-with-original
1572     "\C-c\C-f" gnus-summary-mail-forward
1573     "o" gnus-summary-save-article
1574     "\C-o" gnus-summary-save-article-mail
1575     "|" gnus-summary-pipe-output
1576     "\M-k" gnus-summary-edit-local-kill
1577     "\M-K" gnus-summary-edit-global-kill
1578     ;; "V" gnus-version
1579     "\C-c\C-d" gnus-summary-describe-group
1580     "q" gnus-summary-exit
1581     "Q" gnus-summary-exit-no-update
1582     "\C-c\C-i" gnus-info-find-node
1583     gnus-mouse-2 gnus-mouse-pick-article
1584     "m" gnus-summary-mail-other-window
1585     "a" gnus-summary-post-news
1586     "i" gnus-summary-news-other-window
1587     "x" gnus-summary-limit-to-unread
1588     "s" gnus-summary-isearch-article
1589     "t" gnus-article-toggle-headers
1590     "g" gnus-summary-show-article
1591     "l" gnus-summary-goto-last-article
1592     "v" gnus-summary-preview-mime-message
1593     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1594     "\C-d" gnus-summary-enter-digest-group
1595     "\M-\C-d" gnus-summary-read-document
1596     "\M-\C-e" gnus-summary-edit-parameters
1597     "\M-\C-a" gnus-summary-customize-parameters
1598     "\C-c\C-b" gnus-bug
1599     "\C-c\C-n" gnus-namazu-search
1600     "*" gnus-cache-enter-article
1601     "\M-*" gnus-cache-remove-article
1602     "\M-&" gnus-summary-universal-argument
1603     "\C-l" gnus-recenter
1604     "I" gnus-summary-increase-score
1605     "L" gnus-summary-lower-score
1606     "\M-i" gnus-symbolic-argument
1607     "h" gnus-summary-select-article-buffer
1608
1609     "V" gnus-summary-score-map
1610     "X" gnus-uu-extract-map
1611     "S" gnus-summary-send-map)
1612
1613   ;; Sort of orthogonal keymap
1614   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1615     "t" gnus-summary-tick-article-forward
1616     "!" gnus-summary-tick-article-forward
1617     "d" gnus-summary-mark-as-read-forward
1618     "r" gnus-summary-mark-as-read-forward
1619     "c" gnus-summary-clear-mark-forward
1620     " " gnus-summary-clear-mark-forward
1621     "e" gnus-summary-mark-as-expirable
1622     "x" gnus-summary-mark-as-expirable
1623     "?" gnus-summary-mark-as-dormant
1624     "b" gnus-summary-set-bookmark
1625     "B" gnus-summary-remove-bookmark
1626     "#" gnus-summary-mark-as-processable
1627     "\M-#" gnus-summary-unmark-as-processable
1628     "S" gnus-summary-limit-include-expunged
1629     "C" gnus-summary-catchup
1630     "H" gnus-summary-catchup-to-here
1631     "h" gnus-summary-catchup-from-here
1632     "\C-c" gnus-summary-catchup-all
1633     "k" gnus-summary-kill-same-subject-and-select
1634     "K" gnus-summary-kill-same-subject
1635     "P" gnus-uu-mark-map)
1636
1637   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1638     "c" gnus-summary-clear-above
1639     "u" gnus-summary-tick-above
1640     "m" gnus-summary-mark-above
1641     "k" gnus-summary-kill-below)
1642
1643   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1644     "/" gnus-summary-limit-to-subject
1645     "n" gnus-summary-limit-to-articles
1646     "w" gnus-summary-pop-limit
1647     "s" gnus-summary-limit-to-subject
1648     "a" gnus-summary-limit-to-author
1649     "u" gnus-summary-limit-to-unread
1650     "m" gnus-summary-limit-to-marks
1651     "M" gnus-summary-limit-exclude-marks
1652     "v" gnus-summary-limit-to-score
1653     "*" gnus-summary-limit-include-cached
1654     "D" gnus-summary-limit-include-dormant
1655     "T" gnus-summary-limit-include-thread
1656     "d" gnus-summary-limit-exclude-dormant
1657     "t" gnus-summary-limit-to-age
1658     "x" gnus-summary-limit-to-extra
1659     "p" gnus-summary-limit-to-display-predicate
1660     "E" gnus-summary-limit-include-expunged
1661     "c" gnus-summary-limit-exclude-childless-dormant
1662     "C" gnus-summary-limit-mark-excluded-as-read
1663     "o" gnus-summary-insert-old-articles
1664     "N" gnus-summary-insert-new-articles)
1665
1666   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1667     "n" gnus-summary-next-unread-article
1668     "p" gnus-summary-prev-unread-article
1669     "N" gnus-summary-next-article
1670     "P" gnus-summary-prev-article
1671     "\C-n" gnus-summary-next-same-subject
1672     "\C-p" gnus-summary-prev-same-subject
1673     "\M-n" gnus-summary-next-unread-subject
1674     "\M-p" gnus-summary-prev-unread-subject
1675     "f" gnus-summary-first-unread-article
1676     "b" gnus-summary-best-unread-article
1677     "j" gnus-summary-goto-article
1678     "g" gnus-summary-goto-subject
1679     "l" gnus-summary-goto-last-article
1680     "o" gnus-summary-pop-article)
1681
1682   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1683     "k" gnus-summary-kill-thread
1684     "l" gnus-summary-lower-thread
1685     "i" gnus-summary-raise-thread
1686     "T" gnus-summary-toggle-threads
1687     "t" gnus-summary-rethread-current
1688     "^" gnus-summary-reparent-thread
1689     "s" gnus-summary-show-thread
1690     "S" gnus-summary-show-all-threads
1691     "h" gnus-summary-hide-thread
1692     "H" gnus-summary-hide-all-threads
1693     "n" gnus-summary-next-thread
1694     "p" gnus-summary-prev-thread
1695     "u" gnus-summary-up-thread
1696     "o" gnus-summary-top-thread
1697     "d" gnus-summary-down-thread
1698     "#" gnus-uu-mark-thread
1699     "\M-#" gnus-uu-unmark-thread)
1700
1701   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1702     "g" gnus-summary-prepare
1703     "c" gnus-summary-insert-cached-articles)
1704
1705   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1706     "c" gnus-summary-catchup-and-exit
1707     "C" gnus-summary-catchup-all-and-exit
1708     "E" gnus-summary-exit-no-update
1709     "J" gnus-summary-jump-to-other-group
1710     "Q" gnus-summary-exit
1711     "Z" gnus-summary-exit
1712     "n" gnus-summary-catchup-and-goto-next-group
1713     "R" gnus-summary-reselect-current-group
1714     "G" gnus-summary-rescan-group
1715     "N" gnus-summary-next-group
1716     "s" gnus-summary-save-newsrc
1717     "P" gnus-summary-prev-group)
1718
1719   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1720     " " gnus-summary-next-page
1721     "n" gnus-summary-next-page
1722     "\177" gnus-summary-prev-page
1723     [delete] gnus-summary-prev-page
1724     "p" gnus-summary-prev-page
1725     "\r" gnus-summary-scroll-up
1726     "\M-\r" gnus-summary-scroll-down
1727     "<" gnus-summary-beginning-of-article
1728     ">" gnus-summary-end-of-article
1729     "b" gnus-summary-beginning-of-article
1730     "e" gnus-summary-end-of-article
1731     "^" gnus-summary-refer-parent-article
1732     "r" gnus-summary-refer-parent-article
1733     "D" gnus-summary-enter-digest-group
1734     "R" gnus-summary-refer-references
1735     "T" gnus-summary-refer-thread
1736     "g" gnus-summary-show-article
1737     "s" gnus-summary-isearch-article
1738     "P" gnus-summary-print-article
1739     "M" gnus-mailing-list-insinuate
1740     "t" gnus-article-babel)
1741
1742   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1743     "b" gnus-article-add-buttons
1744     "B" gnus-article-add-buttons-to-head
1745     "o" gnus-article-treat-overstrike
1746     "e" gnus-article-emphasize
1747     "w" gnus-article-fill-cited-article
1748     "Q" gnus-article-fill-long-lines
1749     "C" gnus-article-capitalize-sentences
1750     "c" gnus-article-remove-cr
1751     "Z" gnus-article-decode-HZ
1752     "h" gnus-article-wash-html
1753     "u" gnus-article-unsplit-urls
1754     "f" gnus-article-display-x-face
1755     "l" gnus-summary-stop-page-breaking
1756     "r" gnus-summary-caesar-message
1757     "t" gnus-article-toggle-headers
1758     "g" gnus-treat-smiley
1759     "v" gnus-summary-verbose-headers
1760     "m" gnus-summary-toggle-mime
1761     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1762     "p" gnus-article-verify-x-pgp-sig
1763     "d" gnus-article-treat-dumbquotes
1764     "k" gnus-article-outlook-deuglify-article)
1765
1766   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1767     "a" gnus-article-hide
1768     "h" gnus-article-toggle-headers
1769     "b" gnus-article-hide-boring-headers
1770     "s" gnus-article-hide-signature
1771     "c" gnus-article-hide-citation
1772     "C" gnus-article-hide-citation-in-followups
1773     "l" gnus-article-hide-list-identifiers
1774     "p" gnus-article-hide-pgp
1775     "B" gnus-article-strip-banner
1776     "P" gnus-article-hide-pem
1777     "\C-c" gnus-article-hide-citation-maybe)
1778
1779   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1780     "a" gnus-article-highlight
1781     "h" gnus-article-highlight-headers
1782     "c" gnus-article-highlight-citation
1783     "s" gnus-article-highlight-signature)
1784
1785   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1786     "f" gnus-article-treat-fold-headers
1787     "u" gnus-article-treat-unfold-headers
1788     "n" gnus-article-treat-fold-newsgroups)
1789
1790   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1791     "x" gnus-article-display-x-face
1792     "s" gnus-treat-smiley
1793     "D" gnus-article-remove-images
1794     "f" gnus-treat-from-picon
1795     "m" gnus-treat-mail-picon
1796     "n" gnus-treat-newsgroups-picon)
1797
1798   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1799     "z" gnus-article-date-ut
1800     "u" gnus-article-date-ut
1801     "l" gnus-article-date-local
1802     "p" gnus-article-date-english
1803     "e" gnus-article-date-lapsed
1804     "o" gnus-article-date-original
1805     "i" gnus-article-date-iso8601
1806     "s" gnus-article-date-user)
1807
1808   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1809     "t" gnus-article-remove-trailing-blank-lines
1810     "l" gnus-article-strip-leading-blank-lines
1811     "m" gnus-article-strip-multiple-blank-lines
1812     "a" gnus-article-strip-blank-lines
1813     "A" gnus-article-strip-all-blank-lines
1814     "s" gnus-article-strip-leading-space
1815     "e" gnus-article-strip-trailing-space
1816     "w" gnus-article-remove-leading-whitespace)
1817
1818   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1819     "v" gnus-version
1820     "f" gnus-summary-fetch-faq
1821     "d" gnus-summary-describe-group
1822     "h" gnus-summary-describe-briefly
1823     "i" gnus-info-find-node)
1824
1825   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1826     "e" gnus-summary-expire-articles
1827     "\M-\C-e" gnus-summary-expire-articles-now
1828     "\177" gnus-summary-delete-article
1829     [delete] gnus-summary-delete-article
1830     [backspace] gnus-summary-delete-article
1831     "m" gnus-summary-move-article
1832     "r" gnus-summary-respool-article
1833     "w" gnus-summary-edit-article
1834     "c" gnus-summary-copy-article
1835     "B" gnus-summary-crosspost-article
1836     "q" gnus-summary-respool-query
1837     "t" gnus-summary-respool-trace
1838     "i" gnus-summary-import-article
1839     "I" gnus-summary-create-article
1840     "p" gnus-summary-article-posted-p)
1841
1842   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1843     "o" gnus-summary-save-article
1844     "m" gnus-summary-save-article-mail
1845     "F" gnus-summary-write-article-file
1846     "r" gnus-summary-save-article-rmail
1847     "f" gnus-summary-save-article-file
1848     "b" gnus-summary-save-article-body-file
1849     "h" gnus-summary-save-article-folder
1850     "v" gnus-summary-save-article-vm
1851     "p" gnus-summary-pipe-output
1852     "P" gnus-summary-muttprint
1853     "s" gnus-soup-add-article)
1854
1855   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1856     "b" gnus-summary-display-buttonized
1857     "m" gnus-summary-repair-multipart
1858     "v" gnus-article-view-part
1859     "o" gnus-article-save-part
1860     "c" gnus-article-copy-part
1861     "C" gnus-article-view-part-as-charset
1862     "e" gnus-article-view-part-externally
1863     "E" gnus-article-encrypt-body
1864     "i" gnus-article-inline-part
1865     "|" gnus-article-pipe-part)
1866
1867   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1868     "p" gnus-summary-mark-as-processable
1869     "u" gnus-summary-unmark-as-processable
1870     "U" gnus-summary-unmark-all-processable
1871     "v" gnus-uu-mark-over
1872     "s" gnus-uu-mark-series
1873     "r" gnus-uu-mark-region
1874     "g" gnus-uu-unmark-region
1875     "R" gnus-uu-mark-by-regexp
1876     "G" gnus-uu-unmark-by-regexp
1877     "t" gnus-uu-mark-thread
1878     "T" gnus-uu-unmark-thread
1879     "a" gnus-uu-mark-all
1880     "b" gnus-uu-mark-buffer
1881     "S" gnus-uu-mark-sparse
1882     "k" gnus-summary-kill-process-mark
1883     "y" gnus-summary-yank-process-mark
1884     "w" gnus-summary-save-process-mark
1885     "i" gnus-uu-invert-processable)
1886
1887   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1888     ;;"x" gnus-uu-extract-any
1889     "m" gnus-summary-save-parts
1890     "u" gnus-uu-decode-uu
1891     "U" gnus-uu-decode-uu-and-save
1892     "s" gnus-uu-decode-unshar
1893     "S" gnus-uu-decode-unshar-and-save
1894     "o" gnus-uu-decode-save
1895     "O" gnus-uu-decode-save
1896     "b" gnus-uu-decode-binhex
1897     "B" gnus-uu-decode-binhex
1898     "p" gnus-uu-decode-postscript
1899     "P" gnus-uu-decode-postscript-and-save)
1900
1901   (gnus-define-keys
1902       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1903     "u" gnus-uu-decode-uu-view
1904     "U" gnus-uu-decode-uu-and-save-view
1905     "s" gnus-uu-decode-unshar-view
1906     "S" gnus-uu-decode-unshar-and-save-view
1907     "o" gnus-uu-decode-save-view
1908     "O" gnus-uu-decode-save-view
1909     "b" gnus-uu-decode-binhex-view
1910     "B" gnus-uu-decode-binhex-view
1911     "p" gnus-uu-decode-postscript-view
1912     "P" gnus-uu-decode-postscript-and-save-view))
1913
1914 (defvar gnus-article-post-menu nil)
1915
1916 (defun gnus-summary-make-menu-bar ()
1917   (gnus-turn-off-edit-menu 'summary)
1918
1919   (unless (boundp 'gnus-summary-misc-menu)
1920
1921     (easy-menu-define
1922      gnus-summary-kill-menu gnus-summary-mode-map ""
1923      (cons
1924       "Score"
1925       (nconc
1926        (list
1927         ["Customize" gnus-score-customize t])
1928        (gnus-make-score-map 'increase)
1929        (gnus-make-score-map 'lower)
1930        '(("Mark"
1931           ["Kill below" gnus-summary-kill-below t]
1932           ["Mark above" gnus-summary-mark-above t]
1933           ["Tick above" gnus-summary-tick-above t]
1934           ["Clear above" gnus-summary-clear-above t])
1935          ["Current score" gnus-summary-current-score t]
1936          ["Set score" gnus-summary-set-score t]
1937          ["Switch current score file..." gnus-score-change-score-file t]
1938          ["Set mark below..." gnus-score-set-mark-below t]
1939          ["Set expunge below..." gnus-score-set-expunge-below t]
1940          ["Edit current score file" gnus-score-edit-current-scores t]
1941          ["Edit score file" gnus-score-edit-file t]
1942          ["Trace score" gnus-score-find-trace t]
1943          ["Find words" gnus-score-find-favourite-words t]
1944          ["Rescore buffer" gnus-summary-rescore t]
1945          ["Increase score..." gnus-summary-increase-score t]
1946          ["Lower score..." gnus-summary-lower-score t]))))
1947
1948     ;; Define both the Article menu in the summary buffer and the
1949     ;; equivalent Commands menu in the article buffer here for
1950     ;; consistency.
1951     (let ((innards
1952            `(("Hide"
1953               ["All" gnus-article-hide t]
1954               ["Headers" gnus-article-toggle-headers t]
1955               ["Signature" gnus-article-hide-signature t]
1956               ["Citation" gnus-article-hide-citation t]
1957               ["List identifiers" gnus-article-hide-list-identifiers t]
1958               ["PGP" gnus-article-hide-pgp t]
1959               ["Banner" gnus-article-strip-banner t]
1960               ["Boring headers" gnus-article-hide-boring-headers t])
1961              ("Highlight"
1962               ["All" gnus-article-highlight t]
1963               ["Headers" gnus-article-highlight-headers t]
1964               ["Signature" gnus-article-highlight-signature t]
1965               ["Citation" gnus-article-highlight-citation t])
1966              ("Date"
1967               ["Local" gnus-article-date-local t]
1968               ["ISO8601" gnus-article-date-iso8601 t]
1969               ["UT" gnus-article-date-ut t]
1970               ["Original" gnus-article-date-original t]
1971               ["Lapsed" gnus-article-date-lapsed t]
1972               ["User-defined" gnus-article-date-user t])
1973              ("Display"
1974               ["Remove images" gnus-article-remove-images t]
1975               ["Toggle smiley" gnus-treat-smiley t]
1976               ["Show X-Face" gnus-article-display-x-face t]
1977               ["Show picons in From" gnus-treat-from-picon t]
1978               ["Show picons in mail headers" gnus-treat-mail-picon t]
1979               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
1980               ("View as different encoding"
1981                ,@(mapcar
1982                   (lambda (cs)
1983                     ;; Since easymenu under FSF Emacs doesn't allow lambda
1984                     ;; forms for menu commands, we should provide intern'ed
1985                     ;; function symbols.
1986                     (let ((command (intern (format "\
1987 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
1988                       (fset command
1989                             `(lambda ()
1990                                (interactive)
1991                                (let ((gnus-summary-show-article-charset-alist
1992                                       '((1 . ,cs))))
1993                                  (gnus-summary-show-article 1))))
1994                       `[,(symbol-name cs) ,command t]))
1995                   (sort (if (fboundp 'coding-system-list)
1996                             (coding-system-list)
1997                           (mapcar 'car mm-mime-mule-charset-alist))
1998                         (lambda (a b)
1999                           (string< (symbol-name a)
2000                                    (symbol-name b)))))))
2001              ("Washing"
2002               ("Remove Blanks"
2003                ["Leading" gnus-article-strip-leading-blank-lines t]
2004                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2005                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2006                ["All of the above" gnus-article-strip-blank-lines t]
2007                ["All" gnus-article-strip-all-blank-lines t]
2008                ["Leading space" gnus-article-strip-leading-space t]
2009                ["Trailing space" gnus-article-strip-trailing-space t]
2010                ["Leading space in headers"
2011                 gnus-article-remove-leading-whitespace t])
2012               ["Overstrike" gnus-article-treat-overstrike t]
2013               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2014               ["Emphasis" gnus-article-emphasize t]
2015               ["Word wrap" gnus-article-fill-cited-article t]
2016               ["Fill long lines" gnus-article-fill-long-lines t]
2017               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2018               ["CR" gnus-article-remove-cr t]
2019               ["Rot 13" gnus-summary-caesar-message
2020                ,@(if (featurep 'xemacs) '(t)
2021                    '(:help "\"Caesar rotate\" article by 13"))]
2022               ["Unix pipe" gnus-summary-pipe-message t]
2023               ["Add buttons" gnus-article-add-buttons t]
2024               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2025               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2026               ["Toggle MIME" gnus-summary-toggle-mime t]
2027               ["Verbose header" gnus-summary-verbose-headers t]
2028               ["Toggle header" gnus-summary-toggle-header t]
2029               ["Unfold headers" gnus-article-treat-unfold-headers t]
2030               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2031               ["Html" gnus-article-wash-html t]
2032               ["URLs" gnus-article-unsplit-urls t]
2033               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2034               ["HZ" gnus-article-decode-HZ t]
2035               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2036               )
2037              ("Output"
2038               ["Save in default format" gnus-summary-save-article
2039                ,@(if (featurep 'xemacs) '(t)
2040                    '(:help "Save article using default method"))]
2041               ["Save in file" gnus-summary-save-article-file
2042                ,@(if (featurep 'xemacs) '(t)
2043                    '(:help "Save article in file"))]
2044               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2045               ["Save in MH folder" gnus-summary-save-article-folder t]
2046               ["Save in VM folder" gnus-summary-save-article-vm t]
2047               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2048               ["Save body in file" gnus-summary-save-article-body-file t]
2049               ["Pipe through a filter" gnus-summary-pipe-output t]
2050               ["Add to SOUP packet" gnus-soup-add-article t]
2051               ["Print with Muttprint" gnus-summary-muttprint t]
2052               ["Print" gnus-summary-print-article t])
2053              ("Backend"
2054               ["Respool article..." gnus-summary-respool-article t]
2055               ["Move article..." gnus-summary-move-article
2056                (gnus-check-backend-function
2057                 'request-move-article gnus-newsgroup-name)]
2058               ["Copy article..." gnus-summary-copy-article t]
2059               ["Crosspost article..." gnus-summary-crosspost-article
2060                (gnus-check-backend-function
2061                 'request-replace-article gnus-newsgroup-name)]
2062               ["Import file..." gnus-summary-import-article t]
2063               ["Create article..." gnus-summary-create-article t]
2064               ["Check if posted" gnus-summary-article-posted-p t]
2065               ["Edit article" gnus-summary-edit-article
2066                (not (gnus-group-read-only-p))]
2067               ["Delete article" gnus-summary-delete-article
2068                (gnus-check-backend-function
2069                 'request-expire-articles gnus-newsgroup-name)]
2070               ["Query respool" gnus-summary-respool-query t]
2071               ["Trace respool" gnus-summary-respool-trace t]
2072               ["Delete expirable articles" gnus-summary-expire-articles-now
2073                (gnus-check-backend-function
2074                 'request-expire-articles gnus-newsgroup-name)])
2075              ("Extract"
2076               ["Uudecode" gnus-uu-decode-uu
2077                ,@(if (featurep 'xemacs) '(t)
2078                    '(:help "Decode uuencoded article(s)"))]
2079               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2080               ["Unshar" gnus-uu-decode-unshar t]
2081               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2082               ["Save" gnus-uu-decode-save t]
2083               ["Binhex" gnus-uu-decode-binhex t]
2084               ["Postscript" gnus-uu-decode-postscript t])
2085              ("Cache"
2086               ["Enter article" gnus-cache-enter-article t]
2087               ["Remove article" gnus-cache-remove-article t])
2088              ["Translate" gnus-article-babel t]
2089              ["Select article buffer" gnus-summary-select-article-buffer t]
2090              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2091              ["Isearch article..." gnus-summary-isearch-article t]
2092              ["Beginning of the article" gnus-summary-beginning-of-article t]
2093              ["End of the article" gnus-summary-end-of-article t]
2094              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2095              ["Fetch referenced articles" gnus-summary-refer-references t]
2096              ["Fetch current thread" gnus-summary-refer-thread t]
2097              ["Fetch article with id..." gnus-summary-refer-article t]
2098              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2099              ["Redisplay" gnus-summary-show-article t]
2100              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2101       (easy-menu-define
2102        gnus-summary-article-menu gnus-summary-mode-map ""
2103        (cons "Article" innards))
2104
2105       (if (not (keymapp gnus-summary-article-menu))
2106           (easy-menu-define
2107            gnus-article-commands-menu gnus-article-mode-map ""
2108            (cons "Commands" innards))
2109         ;; in Emacs, don't share menu.
2110         (setq gnus-article-commands-menu
2111               (copy-keymap gnus-summary-article-menu))
2112         (define-key gnus-article-mode-map [menu-bar commands]
2113           (cons "Commands" gnus-article-commands-menu))))
2114
2115     (easy-menu-define
2116      gnus-summary-thread-menu gnus-summary-mode-map ""
2117      '("Threads"
2118        ["Toggle threading" gnus-summary-toggle-threads t]
2119        ["Hide threads" gnus-summary-hide-all-threads t]
2120        ["Show threads" gnus-summary-show-all-threads t]
2121        ["Hide thread" gnus-summary-hide-thread t]
2122        ["Show thread" gnus-summary-show-thread t]
2123        ["Go to next thread" gnus-summary-next-thread t]
2124        ["Go to previous thread" gnus-summary-prev-thread t]
2125        ["Go down thread" gnus-summary-down-thread t]
2126        ["Go up thread" gnus-summary-up-thread t]
2127        ["Top of thread" gnus-summary-top-thread t]
2128        ["Mark thread as read" gnus-summary-kill-thread t]
2129        ["Lower thread score" gnus-summary-lower-thread t]
2130        ["Raise thread score" gnus-summary-raise-thread t]
2131        ["Rethread current" gnus-summary-rethread-current t]))
2132
2133     (easy-menu-define
2134      gnus-summary-post-menu gnus-summary-mode-map ""
2135      `("Post"
2136        ["Send a message (mail or news)" gnus-summary-post-news
2137         ,@(if (featurep 'xemacs) '(t)
2138             '(:help "Post an article"))]
2139        ["Followup" gnus-summary-followup
2140         ,@(if (featurep 'xemacs) '(t)
2141             '(:help "Post followup to this article"))]
2142        ["Followup and yank" gnus-summary-followup-with-original
2143         ,@(if (featurep 'xemacs) '(t)
2144             '(:help "Post followup to this article, quoting its contents"))]
2145        ["Supersede article" gnus-summary-supersede-article t]
2146        ["Cancel article" gnus-summary-cancel-article
2147         ,@(if (featurep 'xemacs) '(t)
2148             '(:help "Cancel an article you posted"))]
2149        ["Reply" gnus-summary-reply t]
2150        ["Reply and yank" gnus-summary-reply-with-original t]
2151        ["Wide reply" gnus-summary-wide-reply t]
2152        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2153         ,@(if (featurep 'xemacs) '(t)
2154             '(:help "Mail a reply, quoting this article"))]
2155        ["Very wide reply" gnus-summary-very-wide-reply t]
2156        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2157         ,@(if (featurep 'xemacs) '(t)
2158             '(:help "Mail a very wide reply, quoting this article"))]
2159        ["Mail forward" gnus-summary-mail-forward t]
2160        ["Post forward" gnus-summary-post-forward t]
2161        ["Digest and mail" gnus-summary-digest-mail-forward t]
2162        ["Digest and post" gnus-summary-digest-post-forward t]
2163        ["Resend message" gnus-summary-resend-message t]
2164        ["Resend message edit" gnus-summary-resend-message-edit t]
2165        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2166        ["Send a mail" gnus-summary-mail-other-window t]
2167        ["Create a local message" gnus-summary-news-other-window t]
2168        ["Uuencode and post" gnus-uu-post-news
2169         ,@(if (featurep 'xemacs) '(t)
2170             '(:help "Post a uuencoded article"))]
2171        ["Followup via news" gnus-summary-followup-to-mail t]
2172        ["Followup via news and yank"
2173         gnus-summary-followup-to-mail-with-original t]
2174        ;;("Draft"
2175        ;;["Send" gnus-summary-send-draft t]
2176        ;;["Send bounced" gnus-resend-bounced-mail t])
2177        ))
2178
2179     (cond
2180      ((not (keymapp gnus-summary-post-menu))
2181       (setq gnus-article-post-menu gnus-summary-post-menu))
2182      ((not gnus-article-post-menu)
2183       ;; Don't share post menu.
2184       (setq gnus-article-post-menu
2185             (copy-keymap gnus-summary-post-menu))))
2186     (define-key gnus-article-mode-map [menu-bar post]
2187       (cons "Post" gnus-article-post-menu))
2188
2189     (easy-menu-define
2190      gnus-summary-misc-menu gnus-summary-mode-map ""
2191      `("Gnus"
2192        ("Mark Read"
2193         ["Mark as read" gnus-summary-mark-as-read-forward t]
2194         ["Mark same subject and select"
2195          gnus-summary-kill-same-subject-and-select t]
2196         ["Mark same subject" gnus-summary-kill-same-subject t]
2197         ["Catchup" gnus-summary-catchup
2198          ,@(if (featurep 'xemacs) '(t)
2199              '(:help "Mark unread articles in this group as read"))]
2200         ["Catchup all" gnus-summary-catchup-all t]
2201         ["Catchup to here" gnus-summary-catchup-to-here t]
2202         ["Catchup from here" gnus-summary-catchup-from-here t]
2203         ["Catchup region" gnus-summary-mark-region-as-read t]
2204         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2205        ("Mark Various"
2206         ["Tick" gnus-summary-tick-article-forward t]
2207         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2208         ["Remove marks" gnus-summary-clear-mark-forward t]
2209         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2210         ["Set bookmark" gnus-summary-set-bookmark t]
2211         ["Remove bookmark" gnus-summary-remove-bookmark t])
2212        ("Limit to"
2213         ["Marks..." gnus-summary-limit-to-marks t]
2214         ["Subject..." gnus-summary-limit-to-subject t]
2215         ["Author..." gnus-summary-limit-to-author t]
2216         ["Age..." gnus-summary-limit-to-age t]
2217         ["Extra..." gnus-summary-limit-to-extra t]
2218         ["Score" gnus-summary-limit-to-score t]
2219         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2220         ["Unread" gnus-summary-limit-to-unread t]
2221         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2222         ["Articles" gnus-summary-limit-to-articles t]
2223         ["Pop limit" gnus-summary-pop-limit t]
2224         ["Show dormant" gnus-summary-limit-include-dormant t]
2225         ["Hide childless dormant"
2226          gnus-summary-limit-exclude-childless-dormant t]
2227         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2228         ["Hide marked" gnus-summary-limit-exclude-marks t]
2229         ["Show expunged" gnus-summary-limit-include-expunged t])
2230        ("Process Mark"
2231         ["Set mark" gnus-summary-mark-as-processable t]
2232         ["Remove mark" gnus-summary-unmark-as-processable t]
2233         ["Remove all marks" gnus-summary-unmark-all-processable t]
2234         ["Mark above" gnus-uu-mark-over t]
2235         ["Mark series" gnus-uu-mark-series t]
2236         ["Mark region" gnus-uu-mark-region t]
2237         ["Unmark region" gnus-uu-unmark-region t]
2238         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2239         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2240         ["Mark all" gnus-uu-mark-all t]
2241         ["Mark buffer" gnus-uu-mark-buffer t]
2242         ["Mark sparse" gnus-uu-mark-sparse t]
2243         ["Mark thread" gnus-uu-mark-thread t]
2244         ["Unmark thread" gnus-uu-unmark-thread t]
2245         ("Process Mark Sets"
2246          ["Kill" gnus-summary-kill-process-mark t]
2247          ["Yank" gnus-summary-yank-process-mark
2248           gnus-newsgroup-process-stack]
2249          ["Save" gnus-summary-save-process-mark t]))
2250        ("Scroll article"
2251         ["Page forward" gnus-summary-next-page
2252          ,@(if (featurep 'xemacs) '(t)
2253              '(:help "Show next page of article"))]
2254         ["Page backward" gnus-summary-prev-page
2255          ,@(if (featurep 'xemacs) '(t)
2256              '(:help "Show previous page of article"))]
2257         ["Line forward" gnus-summary-scroll-up t])
2258        ("Move"
2259         ["Next unread article" gnus-summary-next-unread-article t]
2260         ["Previous unread article" gnus-summary-prev-unread-article t]
2261         ["Next article" gnus-summary-next-article t]
2262         ["Previous article" gnus-summary-prev-article t]
2263         ["Next unread subject" gnus-summary-next-unread-subject t]
2264         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2265         ["Next article same subject" gnus-summary-next-same-subject t]
2266         ["Previous article same subject" gnus-summary-prev-same-subject t]
2267         ["First unread article" gnus-summary-first-unread-article t]
2268         ["Best unread article" gnus-summary-best-unread-article t]
2269         ["Go to subject number..." gnus-summary-goto-subject t]
2270         ["Go to article number..." gnus-summary-goto-article t]
2271         ["Go to the last article" gnus-summary-goto-last-article t]
2272         ["Pop article off history" gnus-summary-pop-article t])
2273        ("Sort"
2274         ["Sort by number" gnus-summary-sort-by-number t]
2275         ["Sort by author" gnus-summary-sort-by-author t]
2276         ["Sort by subject" gnus-summary-sort-by-subject t]
2277         ["Sort by date" gnus-summary-sort-by-date t]
2278         ["Sort by score" gnus-summary-sort-by-score t]
2279         ["Sort by lines" gnus-summary-sort-by-lines t]
2280         ["Sort by characters" gnus-summary-sort-by-chars t]
2281         ["Original sort" gnus-summary-sort-by-original t])
2282        ("Help"
2283         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2284         ["Describe group" gnus-summary-describe-group t]
2285         ["Read manual" gnus-info-find-node t])
2286        ("Modes"
2287         ["Pick and read" gnus-pick-mode t]
2288         ["Binary" gnus-binary-mode t])
2289        ("Regeneration"
2290         ["Regenerate" gnus-summary-prepare t]
2291         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2292         ["Toggle threading" gnus-summary-toggle-threads t])
2293        ["See old articles" gnus-summary-insert-old-articles t]
2294        ["See new articles" gnus-summary-insert-new-articles t]
2295        ["Filter articles..." gnus-summary-execute-command t]
2296        ["Run command on subjects..." gnus-summary-universal-argument t]
2297        ["Search articles forward..." gnus-summary-search-article-forward t]
2298        ["Search articles backward..." gnus-summary-search-article-backward t]
2299        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2300        ["Expand window" gnus-summary-expand-window t]
2301        ["Expire expirable articles" gnus-summary-expire-articles
2302         (gnus-check-backend-function
2303          'request-expire-articles gnus-newsgroup-name)]
2304        ["Edit local kill file" gnus-summary-edit-local-kill t]
2305        ["Edit main kill file" gnus-summary-edit-global-kill t]
2306        ["Edit group parameters" gnus-summary-edit-parameters t]
2307        ["Customize group parameters" gnus-summary-customize-parameters t]
2308        ["Send a bug report" gnus-bug t]
2309        ("Exit"
2310         ["Catchup and exit" gnus-summary-catchup-and-exit
2311          ,@(if (featurep 'xemacs) '(t)
2312              '(:help "Mark unread articles in this group as read, then exit"))]
2313         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2314         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2315         ["Exit group" gnus-summary-exit
2316          ,@(if (featurep 'xemacs) '(t)
2317              '(:help "Exit current group, return to group selection mode"))]
2318         ["Exit group without updating" gnus-summary-exit-no-update t]
2319         ["Exit and goto next group" gnus-summary-next-group t]
2320         ["Exit and goto prev group" gnus-summary-prev-group t]
2321         ["Reselect group" gnus-summary-reselect-current-group t]
2322         ["Rescan group" gnus-summary-rescan-group t]
2323         ["Update dribble" gnus-summary-save-newsrc t])))
2324
2325     (gnus-run-hooks 'gnus-summary-menu-hook)))
2326
2327 (defvar gnus-summary-tool-bar-map nil)
2328
2329 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2330 (defun gnus-summary-make-tool-bar ()
2331   (if (and (fboundp 'tool-bar-add-item-from-menu)
2332            (default-value 'tool-bar-mode)
2333            (not gnus-summary-tool-bar-map))
2334       (setq gnus-summary-tool-bar-map
2335             (let ((tool-bar-map (make-sparse-keymap))
2336                   (load-path (mm-image-load-path)))
2337               (tool-bar-add-item-from-menu
2338                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2339               (tool-bar-add-item-from-menu
2340                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2341               (tool-bar-add-item-from-menu
2342                'gnus-summary-post-news "post" gnus-summary-mode-map)
2343               (tool-bar-add-item-from-menu
2344                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2345               (tool-bar-add-item-from-menu
2346                'gnus-summary-followup "followup" gnus-summary-mode-map)
2347               (tool-bar-add-item-from-menu
2348                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2349               (tool-bar-add-item-from-menu
2350                'gnus-summary-reply "reply" gnus-summary-mode-map)
2351               (tool-bar-add-item-from-menu
2352                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2353               (tool-bar-add-item-from-menu
2354                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2355               (tool-bar-add-item-from-menu
2356                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2357               (tool-bar-add-item-from-menu
2358                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2359               (tool-bar-add-item-from-menu
2360                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2361               (tool-bar-add-item-from-menu
2362                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2363               (tool-bar-add-item-from-menu
2364                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2365               (tool-bar-add-item-from-menu
2366                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2367               tool-bar-map)))
2368   (if gnus-summary-tool-bar-map
2369       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2370
2371 (defun gnus-score-set-default (var value)
2372   "A version of set that updates the GNU Emacs menu-bar."
2373   (set var value)
2374   ;; It is the message that forces the active status to be updated.
2375   (message ""))
2376
2377 (defun gnus-make-score-map (type)
2378   "Make a summary score map of type TYPE."
2379   (if t
2380       nil
2381     (let ((headers '(("author" "from" string)
2382                      ("subject" "subject" string)
2383                      ("article body" "body" string)
2384                      ("article head" "head" string)
2385                      ("xref" "xref" string)
2386                      ("extra header" "extra" string)
2387                      ("lines" "lines" number)
2388                      ("followups to author" "followup" string)))
2389           (types '((number ("less than" <)
2390                            ("greater than" >)
2391                            ("equal" =))
2392                    (string ("substring" s)
2393                            ("exact string" e)
2394                            ("fuzzy string" f)
2395                            ("regexp" r))))
2396           (perms '(("temporary" (current-time-string))
2397                    ("permanent" nil)
2398                    ("immediate" now)))
2399           header)
2400       (list
2401        (apply
2402         'nconc
2403         (list
2404          (if (eq type 'lower)
2405              "Lower score"
2406            "Increase score"))
2407         (let (outh)
2408           (while headers
2409             (setq header (car headers))
2410             (setq outh
2411                   (cons
2412                    (apply
2413                     'nconc
2414                     (list (car header))
2415                     (let ((ts (cdr (assoc (nth 2 header) types)))
2416                           outt)
2417                       (while ts
2418                         (setq outt
2419                               (cons
2420                                (apply
2421                                 'nconc
2422                                 (list (caar ts))
2423                                 (let ((ps perms)
2424                                       outp)
2425                                   (while ps
2426                                     (setq outp
2427                                           (cons
2428                                            (vector
2429                                             (caar ps)
2430                                             (list
2431                                              'gnus-summary-score-entry
2432                                              (nth 1 header)
2433                                              (if (or (string= (nth 1 header)
2434                                                               "head")
2435                                                      (string= (nth 1 header)
2436                                                               "body"))
2437                                                  ""
2438                                                (list 'gnus-summary-header
2439                                                      (nth 1 header)))
2440                                              (list 'quote (nth 1 (car ts)))
2441                                              (list 'gnus-score-delta-default
2442                                                    nil)
2443                                              (nth 1 (car ps))
2444                                              t)
2445                                             t)
2446                                            outp))
2447                                     (setq ps (cdr ps)))
2448                                   (list (nreverse outp))))
2449                                outt))
2450                         (setq ts (cdr ts)))
2451                       (list (nreverse outt))))
2452                    outh))
2453             (setq headers (cdr headers)))
2454           (list (nreverse outh))))))))
2455
2456 \f
2457
2458 (defun gnus-summary-mode (&optional group)
2459   "Major mode for reading articles.
2460
2461 All normal editing commands are switched off.
2462 \\<gnus-summary-mode-map>
2463 Each line in this buffer represents one article.  To read an
2464 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2465 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2466 respectively.
2467
2468 You can also post articles and send mail from this buffer.  To
2469 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2470 of an article, type `\\[gnus-summary-reply]'.
2471
2472 There are approx. one gazillion commands you can execute in this
2473 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2474
2475 The following commands are available:
2476
2477 \\{gnus-summary-mode-map}"
2478   (interactive)
2479   (kill-all-local-variables)
2480   (when (gnus-visual-p 'summary-menu 'menu)
2481     (gnus-summary-make-menu-bar)
2482     (gnus-summary-make-tool-bar))
2483   (gnus-summary-make-local-variables)
2484   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2485     (gnus-summary-make-local-variables))
2486   (gnus-make-thread-indent-array)
2487   (gnus-simplify-mode-line)
2488   (setq major-mode 'gnus-summary-mode)
2489   (setq mode-name "Summary")
2490   (make-local-variable 'minor-mode-alist)
2491   (use-local-map gnus-summary-mode-map)
2492   (buffer-disable-undo)
2493   (setq buffer-read-only t)             ;Disable modification
2494   (setq truncate-lines t)
2495   (setq selective-display t)
2496   (setq selective-display-ellipses t)   ;Display `...'
2497   (gnus-summary-set-display-table)
2498   (gnus-set-default-directory)
2499   (setq gnus-newsgroup-name group)
2500   (unless (gnus-news-group-p group)
2501     (setq gnus-newsgroup-incorporated
2502           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2503   (make-local-variable 'gnus-summary-line-format)
2504   (make-local-variable 'gnus-summary-line-format-spec)
2505   (make-local-variable 'gnus-summary-dummy-line-format)
2506   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2507   (make-local-variable 'gnus-summary-mark-positions)
2508   (make-local-hook 'pre-command-hook)
2509   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2510   (gnus-run-hooks 'gnus-summary-mode-hook)
2511   (turn-on-gnus-mailing-list-mode)
2512   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2513   (gnus-update-summary-mark-positions))
2514
2515 (defun gnus-summary-make-local-variables ()
2516   "Make all the local summary buffer variables."
2517   (let (global)
2518     (dolist (local gnus-summary-local-variables)
2519       (if (consp local)
2520           (progn
2521             (if (eq (cdr local) 'global)
2522                 ;; Copy the global value of the variable.
2523                 (setq global (symbol-value (car local)))
2524               ;; Use the value from the list.
2525               (setq global (eval (cdr local))))
2526             (set (make-local-variable (car local)) global))
2527         ;; Simple nil-valued local variable.
2528         (set (make-local-variable local) nil)))))
2529
2530 (defun gnus-summary-clear-local-variables ()
2531   (let ((locals gnus-summary-local-variables))
2532     (while locals
2533       (if (consp (car locals))
2534           (and (vectorp (caar locals))
2535                (set (caar locals) nil))
2536         (and (vectorp (car locals))
2537              (set (car locals) nil)))
2538       (setq locals (cdr locals)))))
2539
2540 ;; Summary data functions.
2541
2542 (defmacro gnus-data-number (data)
2543   `(car ,data))
2544
2545 (defmacro gnus-data-set-number (data number)
2546   `(setcar ,data ,number))
2547
2548 (defmacro gnus-data-mark (data)
2549   `(nth 1 ,data))
2550
2551 (defmacro gnus-data-set-mark (data mark)
2552   `(setcar (nthcdr 1 ,data) ,mark))
2553
2554 (defmacro gnus-data-pos (data)
2555   `(nth 2 ,data))
2556
2557 (defmacro gnus-data-set-pos (data pos)
2558   `(setcar (nthcdr 2 ,data) ,pos))
2559
2560 (defmacro gnus-data-header (data)
2561   `(nth 3 ,data))
2562
2563 (defmacro gnus-data-set-header (data header)
2564   `(setcar (nthcdr 3 ,data) ,header))
2565
2566 (defmacro gnus-data-level (data)
2567   `(nth 4 ,data))
2568
2569 (defmacro gnus-data-unread-p (data)
2570   `(= (nth 1 ,data) gnus-unread-mark))
2571
2572 (defmacro gnus-data-read-p (data)
2573   `(/= (nth 1 ,data) gnus-unread-mark))
2574
2575 (defmacro gnus-data-pseudo-p (data)
2576   `(consp (nth 3 ,data)))
2577
2578 (defmacro gnus-data-find (number)
2579   `(assq ,number gnus-newsgroup-data))
2580
2581 (defmacro gnus-data-find-list (number &optional data)
2582   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2583      (memq (assq ,number bdata)
2584            bdata)))
2585
2586 (defmacro gnus-data-make (number mark pos header level)
2587   `(list ,number ,mark ,pos ,header ,level))
2588
2589 (defun gnus-data-enter (after-article number mark pos header level offset)
2590   (let ((data (gnus-data-find-list after-article)))
2591     (unless data
2592       (error "No such article: %d" after-article))
2593     (setcdr data (cons (gnus-data-make number mark pos header level)
2594                        (cdr data)))
2595     (setq gnus-newsgroup-data-reverse nil)
2596     (gnus-data-update-list (cddr data) offset)))
2597
2598 (defun gnus-data-enter-list (after-article list &optional offset)
2599   (when list
2600     (let ((data (and after-article (gnus-data-find-list after-article)))
2601           (ilist list))
2602       (if (not (or data
2603                    after-article))
2604           (let ((odata gnus-newsgroup-data))
2605             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2606             (when offset
2607               (gnus-data-update-list odata offset)))
2608         ;; Find the last element in the list to be spliced into the main
2609         ;; list.
2610         (while (cdr list)
2611           (setq list (cdr list)))
2612         (if (not data)
2613             (progn
2614               (setcdr list gnus-newsgroup-data)
2615               (setq gnus-newsgroup-data ilist)
2616               (when offset
2617                 (gnus-data-update-list (cdr list) offset)))
2618           (setcdr list (cdr data))
2619           (setcdr data ilist)
2620           (when offset
2621             (gnus-data-update-list (cdr list) offset))))
2622       (setq gnus-newsgroup-data-reverse nil))))
2623
2624 (defun gnus-data-remove (article &optional offset)
2625   (let ((data gnus-newsgroup-data))
2626     (if (= (gnus-data-number (car data)) article)
2627         (progn
2628           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2629                 gnus-newsgroup-data-reverse nil)
2630           (when offset
2631             (gnus-data-update-list gnus-newsgroup-data offset)))
2632       (while (cdr data)
2633         (when (= (gnus-data-number (cadr data)) article)
2634           (setcdr data (cddr data))
2635           (when offset
2636             (gnus-data-update-list (cdr data) offset))
2637           (setq data nil
2638                 gnus-newsgroup-data-reverse nil))
2639         (setq data (cdr data))))))
2640
2641 (defmacro gnus-data-list (backward)
2642   `(if ,backward
2643        (or gnus-newsgroup-data-reverse
2644            (setq gnus-newsgroup-data-reverse
2645                  (reverse gnus-newsgroup-data)))
2646      gnus-newsgroup-data))
2647
2648 (defun gnus-data-update-list (data offset)
2649   "Add OFFSET to the POS of all data entries in DATA."
2650   (setq gnus-newsgroup-data-reverse nil)
2651   (while data
2652     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2653     (setq data (cdr data))))
2654
2655 (defun gnus-summary-article-pseudo-p (article)
2656   "Say whether this article is a pseudo article or not."
2657   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2658
2659 (defmacro gnus-summary-article-sparse-p (article)
2660   "Say whether this article is a sparse article or not."
2661   `(memq ,article gnus-newsgroup-sparse))
2662
2663 (defmacro gnus-summary-article-ancient-p (article)
2664   "Say whether this article is a sparse article or not."
2665   `(memq ,article gnus-newsgroup-ancient))
2666
2667 (defun gnus-article-parent-p (number)
2668   "Say whether this article is a parent or not."
2669   (let ((data (gnus-data-find-list number)))
2670     (and (cdr data)                     ; There has to be an article after...
2671          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2672             (gnus-data-level (nth 1 data))))))
2673
2674 (defun gnus-article-children (number)
2675   "Return a list of all children to NUMBER."
2676   (let* ((data (gnus-data-find-list number))
2677          (level (gnus-data-level (car data)))
2678          children)
2679     (setq data (cdr data))
2680     (while (and data
2681                 (= (gnus-data-level (car data)) (1+ level)))
2682       (push (gnus-data-number (car data)) children)
2683       (setq data (cdr data)))
2684     children))
2685
2686 (defmacro gnus-summary-skip-intangible ()
2687   "If the current article is intangible, then jump to a different article."
2688   '(let ((to (get-text-property (point) 'gnus-intangible)))
2689      (and to (gnus-summary-goto-subject to))))
2690
2691 (defmacro gnus-summary-article-intangible-p ()
2692   "Say whether this article is intangible or not."
2693   '(get-text-property (point) 'gnus-intangible))
2694
2695 (defun gnus-article-read-p (article)
2696   "Say whether ARTICLE is read or not."
2697   (not (or (memq article gnus-newsgroup-marked)
2698            (memq article gnus-newsgroup-unreads)
2699            (memq article gnus-newsgroup-unselected)
2700            (memq article gnus-newsgroup-dormant))))
2701
2702 ;; Some summary mode macros.
2703
2704 (defmacro gnus-summary-article-number ()
2705   "The article number of the article on the current line.
2706 If there isn's an article number here, then we return the current
2707 article number."
2708   '(progn
2709      (gnus-summary-skip-intangible)
2710      (or (get-text-property (point) 'gnus-number)
2711          (gnus-summary-last-subject))))
2712
2713 (defmacro gnus-summary-article-header (&optional number)
2714   "Return the header of article NUMBER."
2715   `(gnus-data-header (gnus-data-find
2716                       ,(or number '(gnus-summary-article-number)))))
2717
2718 (defmacro gnus-summary-thread-level (&optional number)
2719   "Return the level of thread that starts with article NUMBER."
2720   `(if (and (eq gnus-summary-make-false-root 'dummy)
2721             (get-text-property (point) 'gnus-intangible))
2722        0
2723      (gnus-data-level (gnus-data-find
2724                        ,(or number '(gnus-summary-article-number))))))
2725
2726 (defmacro gnus-summary-article-mark (&optional number)
2727   "Return the mark of article NUMBER."
2728   `(gnus-data-mark (gnus-data-find
2729                     ,(or number '(gnus-summary-article-number)))))
2730
2731 (defmacro gnus-summary-article-pos (&optional number)
2732   "Return the position of the line of article NUMBER."
2733   `(gnus-data-pos (gnus-data-find
2734                    ,(or number '(gnus-summary-article-number)))))
2735
2736 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2737 (defmacro gnus-summary-article-subject (&optional number)
2738   "Return current subject string or nil if nothing."
2739   `(let ((headers
2740           ,(if number
2741                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2742              '(gnus-data-header (assq (gnus-summary-article-number)
2743                                       gnus-newsgroup-data)))))
2744      (and headers
2745           (vectorp headers)
2746           (mail-header-subject headers))))
2747
2748 (defmacro gnus-summary-article-score (&optional number)
2749   "Return current article score."
2750   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2751                   gnus-newsgroup-scored))
2752        gnus-summary-default-score 0))
2753
2754 (defun gnus-summary-article-children (&optional number)
2755   "Return a list of article numbers that are children of article NUMBER."
2756   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2757          (level (gnus-data-level (car data)))
2758          l children)
2759     (while (and (setq data (cdr data))
2760                 (> (setq l (gnus-data-level (car data))) level))
2761       (and (= (1+ level) l)
2762            (push (gnus-data-number (car data))
2763                  children)))
2764     (nreverse children)))
2765
2766 (defun gnus-summary-article-parent (&optional number)
2767   "Return the article number of the parent of article NUMBER."
2768   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2769                                     (gnus-data-list t)))
2770          (level (gnus-data-level (car data))))
2771     (if (zerop level)
2772         ()                              ; This is a root.
2773       ;; We search until we find an article with a level less than
2774       ;; this one.  That function has to be the parent.
2775       (while (and (setq data (cdr data))
2776                   (not (< (gnus-data-level (car data)) level))))
2777       (and data (gnus-data-number (car data))))))
2778
2779 (defun gnus-unread-mark-p (mark)
2780   "Say whether MARK is the unread mark."
2781   (= mark gnus-unread-mark))
2782
2783 (defun gnus-read-mark-p (mark)
2784   "Say whether MARK is one of the marks that mark as read.
2785 This is all marks except unread, ticked, dormant, and expirable."
2786   (not (or (= mark gnus-unread-mark)
2787            (= mark gnus-ticked-mark)
2788            (= mark gnus-dormant-mark)
2789            (= mark gnus-expirable-mark))))
2790
2791 (defmacro gnus-article-mark (number)
2792   "Return the MARK of article NUMBER.
2793 This macro should only be used when computing the mark the \"first\"
2794 time; i.e., when generating the summary lines.  After that,
2795 `gnus-summary-article-mark' should be used to examine the
2796 marks of articles."
2797   `(cond
2798     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2799     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2800     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2801     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2802     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2803     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2804     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2805     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2806            gnus-ancient-mark))))
2807
2808 ;; Saving hidden threads.
2809
2810 (defmacro gnus-save-hidden-threads (&rest forms)
2811   "Save hidden threads, eval FORMS, and restore the hidden threads."
2812   (let ((config (make-symbol "config")))
2813     `(let ((,config (gnus-hidden-threads-configuration)))
2814        (unwind-protect
2815            (save-excursion
2816              ,@forms)
2817          (gnus-restore-hidden-threads-configuration ,config)))))
2818 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2819 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2820
2821 (defun gnus-data-compute-positions ()
2822   "Compute the positions of all articles."
2823   (setq gnus-newsgroup-data-reverse nil)
2824   (let ((data gnus-newsgroup-data))
2825     (save-excursion
2826       (gnus-save-hidden-threads
2827         (gnus-summary-show-all-threads)
2828         (goto-char (point-min))
2829         (while data
2830           (while (get-text-property (point) 'gnus-intangible)
2831             (forward-line 1))
2832           (gnus-data-set-pos (car data) (+ (point) 3))
2833           (setq data (cdr data))
2834           (forward-line 1))))))
2835
2836 (defun gnus-hidden-threads-configuration ()
2837   "Return the current hidden threads configuration."
2838   (save-excursion
2839     (let (config)
2840       (goto-char (point-min))
2841       (while (search-forward "\r" nil t)
2842         (push (1- (point)) config))
2843       config)))
2844
2845 (defun gnus-restore-hidden-threads-configuration (config)
2846   "Restore hidden threads configuration from CONFIG."
2847   (save-excursion
2848     (let (point buffer-read-only)
2849       (while (setq point (pop config))
2850         (when (and (< point (point-max))
2851                    (goto-char point)
2852                    (eq (char-after) ?\n))
2853           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2854
2855 ;; Various summary mode internalish functions.
2856
2857 (defun gnus-mouse-pick-article (e)
2858   (interactive "e")
2859   (mouse-set-point e)
2860   (gnus-summary-next-page nil t))
2861
2862 (defun gnus-summary-set-display-table ()
2863   "Change the display table.
2864 Odd characters have a tendency to mess
2865 up nicely formatted displays - we make all possible glyphs
2866 display only a single character."
2867
2868   ;; We start from the standard display table, if any.
2869   (let ((table (or (copy-sequence standard-display-table)
2870                    (make-display-table)))
2871         (i 32))
2872     ;; Nix out all the control chars...
2873     (while (>= (setq i (1- i)) 0)
2874       (aset table i [??]))
2875     ;; ... but not newline and cr, of course.  (cr is necessary for the
2876     ;; selective display).
2877     (aset table ?\n nil)
2878     (aset table ?\r nil)
2879     ;; We keep TAB as well.
2880     (aset table ?\t nil)
2881     ;; We nix out any glyphs over 126 that are not set already.
2882     (let ((i 256))
2883       (while (>= (setq i (1- i)) 127)
2884         ;; Only modify if the entry is nil.
2885         (unless (aref table i)
2886           (aset table i [??]))))
2887     (setq buffer-display-table table)))
2888
2889 (defun gnus-summary-set-article-display-arrow (pos)
2890   "Update the overlay arrow to point to line at position POS."
2891   (when (and gnus-summary-display-arrow
2892              (boundp 'overlay-arrow-position)
2893              (boundp 'overlay-arrow-string))
2894     (save-excursion
2895       (goto-char pos)
2896       (beginning-of-line)
2897       (unless overlay-arrow-position
2898         (setq overlay-arrow-position (make-marker)))
2899       (setq overlay-arrow-string "=>"
2900             overlay-arrow-position (set-marker overlay-arrow-position
2901                                                (point)
2902                                                (current-buffer))))))
2903
2904 (defun gnus-summary-buffer-name (group)
2905   "Return the summary buffer name of GROUP."
2906   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2907
2908 (defun gnus-summary-setup-buffer (group)
2909   "Initialize summary buffer."
2910   (let ((buffer (gnus-summary-buffer-name group))
2911         (dead-name (concat "*Dead Summary "
2912                            (gnus-group-decoded-name group) "*")))
2913     ;; If a dead summary buffer exists, we kill it.
2914     (when (gnus-buffer-live-p dead-name)
2915       (gnus-kill-buffer dead-name))
2916     (if (get-buffer buffer)
2917         (progn
2918           (set-buffer buffer)
2919           (setq gnus-summary-buffer (current-buffer))
2920           (not gnus-newsgroup-prepared))
2921       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2922       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2923       (gnus-summary-mode group)
2924       (when gnus-carpal
2925         (gnus-carpal-setup-buffer 'summary))
2926       (unless gnus-single-article-buffer
2927         (make-local-variable 'gnus-article-buffer)
2928         (make-local-variable 'gnus-article-current)
2929         (make-local-variable 'gnus-original-article-buffer))
2930       (setq gnus-newsgroup-name group)
2931       ;; Set any local variables in the group parameters.
2932       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2933       t)))
2934
2935 (defun gnus-set-global-variables ()
2936   "Set the global equivalents of the buffer-local variables.
2937 They are set to the latest values they had.  These reflect the summary
2938 buffer that was in action when the last article was fetched."
2939   (when (eq major-mode 'gnus-summary-mode)
2940     (setq gnus-summary-buffer (current-buffer))
2941     (let ((name gnus-newsgroup-name)
2942           (marked gnus-newsgroup-marked)
2943           (unread gnus-newsgroup-unreads)
2944           (headers gnus-current-headers)
2945           (data gnus-newsgroup-data)
2946           (summary gnus-summary-buffer)
2947           (article-buffer gnus-article-buffer)
2948           (original gnus-original-article-buffer)
2949           (gac gnus-article-current)
2950           (reffed gnus-reffed-article-number)
2951           (score-file gnus-current-score-file)
2952           (default-charset gnus-newsgroup-charset)
2953           vlist)
2954       (let ((locals gnus-newsgroup-variables))
2955         (while locals
2956           (if (consp (car locals))
2957               (push (eval (caar locals)) vlist)
2958             (push (eval (car locals)) vlist))
2959           (setq locals (cdr locals)))
2960         (setq vlist (nreverse vlist)))
2961       (save-excursion
2962         (set-buffer gnus-group-buffer)
2963         (setq gnus-newsgroup-name name
2964               gnus-newsgroup-marked marked
2965               gnus-newsgroup-unreads unread
2966               gnus-current-headers headers
2967               gnus-newsgroup-data data
2968               gnus-article-current gac
2969               gnus-summary-buffer summary
2970               gnus-article-buffer article-buffer
2971               gnus-original-article-buffer original
2972               gnus-reffed-article-number reffed
2973               gnus-current-score-file score-file
2974               gnus-newsgroup-charset default-charset)
2975         (let ((locals gnus-newsgroup-variables))
2976           (while locals
2977             (if (consp (car locals))
2978                 (set (caar locals) (pop vlist))
2979               (set (car locals) (pop vlist)))
2980             (setq locals (cdr locals))))
2981         ;; The article buffer also has local variables.
2982         (when (gnus-buffer-live-p gnus-article-buffer)
2983           (set-buffer gnus-article-buffer)
2984           (setq gnus-summary-buffer summary))))))
2985
2986 (defun gnus-summary-article-unread-p (article)
2987   "Say whether ARTICLE is unread or not."
2988   (memq article gnus-newsgroup-unreads))
2989
2990 (defun gnus-summary-first-article-p (&optional article)
2991   "Return whether ARTICLE is the first article in the buffer."
2992   (if (not (setq article (or article (gnus-summary-article-number))))
2993       nil
2994     (eq article (caar gnus-newsgroup-data))))
2995
2996 (defun gnus-summary-last-article-p (&optional article)
2997   "Return whether ARTICLE is the last article in the buffer."
2998   (if (not (setq article (or article (gnus-summary-article-number))))
2999       ;; All non-existent numbers are the last article.  :-)
3000       t
3001     (not (cdr (gnus-data-find-list article)))))
3002
3003 (defun gnus-make-thread-indent-array ()
3004   (let ((n 200))
3005     (unless (and gnus-thread-indent-array
3006                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3007       (setq gnus-thread-indent-array (make-vector 201 "")
3008             gnus-thread-indent-array-level gnus-thread-indent-level)
3009       (while (>= n 0)
3010         (aset gnus-thread-indent-array n
3011               (make-string (* n gnus-thread-indent-level) ? ))
3012         (setq n (1- n))))))
3013
3014 (defun gnus-update-summary-mark-positions ()
3015   "Compute where the summary marks are to go."
3016   (save-excursion
3017     (when (gnus-buffer-exists-p gnus-summary-buffer)
3018       (set-buffer gnus-summary-buffer))
3019     (let ((gnus-replied-mark 129)
3020           (gnus-score-below-mark 130)
3021           (gnus-score-over-mark 130)
3022           (gnus-download-mark 131)
3023           (spec gnus-summary-line-format-spec)
3024           gnus-visual pos)
3025       (save-excursion
3026         (gnus-set-work-buffer)
3027         (let ((gnus-summary-line-format-spec spec)
3028               (gnus-newsgroup-downloadable '((0 . t))))
3029           (gnus-summary-insert-line
3030            (make-full-mail-header 0 "" "nobody"
3031                                   "05 Apr 2001 23:33:09 +0400"
3032                                   "" "" 0 0 "" nil)
3033            0 nil 128 t nil "" nil 1)
3034           (goto-char (point-min))
3035           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3036                                              (- (point) 2)))))
3037           (goto-char (point-min))
3038           (push (cons 'replied (and (search-forward "\201" nil t)
3039                                     (- (point) 2)))
3040                 pos)
3041           (goto-char (point-min))
3042           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3043                 pos)
3044           (goto-char (point-min))
3045           (push (cons 'download
3046                       (and (search-forward "\203" nil t) (- (point) 2)))
3047                 pos)))
3048       (setq gnus-summary-mark-positions pos))))
3049
3050 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3051   "Insert a dummy root in the summary buffer."
3052   (beginning-of-line)
3053   (gnus-add-text-properties
3054    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3055    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3056
3057 (defun gnus-summary-extract-address-component (from)
3058   (or (car (funcall gnus-extract-address-components from))
3059       from))
3060
3061 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3062   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3063                                 default-mime-charset)))
3064     ;; Is it really necessary to do this next part for each summary line?
3065     ;; Luckily, doesn't seem to slow things down much.
3066     (or
3067      (and gnus-ignored-from-addresses
3068           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3069           (let ((extra-headers (mail-header-extra header))
3070                 to
3071                 newsgroups)
3072             (cond
3073              ((setq to (cdr (assq 'To extra-headers)))
3074               (concat "-> "
3075                       (inline
3076                         (gnus-summary-extract-address-component
3077                          (funcall gnus-decode-encoded-word-function to)))))
3078              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3079               (concat "=> " newsgroups)))))
3080      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3081
3082 (defun gnus-summary-insert-line (gnus-tmp-header
3083                                  gnus-tmp-level gnus-tmp-current
3084                                  gnus-tmp-unread gnus-tmp-replied
3085                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3086                                  &optional gnus-tmp-dummy gnus-tmp-score
3087                                  gnus-tmp-process)
3088   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3089          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3090          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3091          (gnus-tmp-score-char
3092           (if (or (null gnus-summary-default-score)
3093                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3094                       gnus-summary-zcore-fuzz))
3095               ?\ ;;;Whitespace
3096             (if (< gnus-tmp-score gnus-summary-default-score)
3097                 gnus-score-below-mark gnus-score-over-mark)))
3098          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3099          (gnus-tmp-replied
3100           (cond (gnus-tmp-process gnus-process-mark)
3101                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3102                  gnus-cached-mark)
3103                 (gnus-tmp-replied gnus-replied-mark)
3104                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3105                  gnus-forwarded-mark)
3106                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3107                  gnus-saved-mark)
3108                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3109                  gnus-recent-mark)
3110                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3111                  gnus-unseen-mark)
3112                 (t gnus-no-mark)))
3113          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3114          (gnus-tmp-name
3115           (cond
3116            ((string-match "<[^>]+> *$" gnus-tmp-from)
3117             (let ((beg (match-beginning 0)))
3118               (or (and (string-match "^\".+\"" gnus-tmp-from)
3119                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3120                   (substring gnus-tmp-from 0 beg))))
3121            ((string-match "(.+)" gnus-tmp-from)
3122             (substring gnus-tmp-from
3123                        (1+ (match-beginning 0)) (1- (match-end 0))))
3124            (t gnus-tmp-from)))
3125          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3126          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3127          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3128          (buffer-read-only nil))
3129     (when (string= gnus-tmp-name "")
3130       (setq gnus-tmp-name gnus-tmp-from))
3131     (unless (numberp gnus-tmp-lines)
3132       (setq gnus-tmp-lines -1))
3133     (if (= gnus-tmp-lines -1)
3134         (setq gnus-tmp-lines "?")
3135       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3136     (gnus-put-text-property-excluding-characters-with-faces
3137      (point)
3138      (progn (eval gnus-summary-line-format-spec) (point))
3139      'gnus-number gnus-tmp-number)
3140     (when (gnus-visual-p 'summary-highlight 'highlight)
3141       (forward-line -1)
3142       (gnus-run-hooks 'gnus-summary-update-hook)
3143       (forward-line 1))))
3144
3145 (defun gnus-summary-update-line (&optional dont-update)
3146   "Update summary line after change."
3147   (when (and gnus-summary-default-score
3148              (not gnus-summary-inhibit-highlight))
3149     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3150            (article (gnus-summary-article-number))
3151            (score (gnus-summary-article-score article)))
3152       (unless dont-update
3153         (if (and gnus-summary-mark-below
3154                  (< (gnus-summary-article-score)
3155                     gnus-summary-mark-below))
3156             ;; This article has a low score, so we mark it as read.
3157             (when (memq article gnus-newsgroup-unreads)
3158               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3159           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3160             ;; This article was previously marked as read on account
3161             ;; of a low score, but now it has risen, so we mark it as
3162             ;; unread.
3163             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3164         (gnus-summary-update-mark
3165          (if (or (null gnus-summary-default-score)
3166                  (<= (abs (- score gnus-summary-default-score))
3167                      gnus-summary-zcore-fuzz))
3168              ?\ ;;;Whitespace
3169            (if (< score gnus-summary-default-score)
3170                gnus-score-below-mark gnus-score-over-mark))
3171          'score))
3172       ;; Do visual highlighting.
3173       (when (gnus-visual-p 'summary-highlight 'highlight)
3174         (gnus-run-hooks 'gnus-summary-update-hook)))))
3175
3176 (defvar gnus-tmp-new-adopts nil)
3177
3178 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3179   "Return the number of articles in THREAD.
3180 This may be 0 in some cases -- if none of the articles in
3181 the thread are to be displayed."
3182   (let* ((number
3183           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3184           (cond
3185            ((not (listp thread))
3186             1)
3187            ((and (consp thread) (cdr thread))
3188             (apply
3189              '+ 1 (mapcar
3190                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3191            ((null thread)
3192             1)
3193            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3194             1)
3195            (t 0))))
3196     (when (and level (zerop level) gnus-tmp-new-adopts)
3197       (incf number
3198             (apply '+ (mapcar
3199                        'gnus-summary-number-of-articles-in-thread
3200                        gnus-tmp-new-adopts))))
3201     (if char
3202         (if (> number 1) gnus-not-empty-thread-mark
3203           gnus-empty-thread-mark)
3204       number)))
3205
3206 (defun gnus-summary-set-local-parameters (group)
3207   "Go through the local params of GROUP and set all variable specs in that list."
3208   (let ((params (gnus-group-find-parameter group))
3209         (vars '(quit-config))           ; Ignore quit-config.
3210         elem)
3211     (while params
3212       (setq elem (car params)
3213             params (cdr params))
3214       (and (consp elem)                 ; Has to be a cons.
3215            (consp (cdr elem))           ; The cdr has to be a list.
3216            (symbolp (car elem))         ; Has to be a symbol in there.
3217            (not (memq (car elem) vars))
3218            (ignore-errors               ; So we set it.
3219              (push (car elem) vars)
3220              (make-local-variable (car elem))
3221              (set (car elem) (eval (nth 1 elem))))))))
3222
3223 (defun gnus-summary-read-group (group &optional show-all no-article
3224                                       kill-buffer no-display backward
3225                                       select-articles)
3226   "Start reading news in newsgroup GROUP.
3227 If SHOW-ALL is non-nil, already read articles are also listed.
3228 If NO-ARTICLE is non-nil, no article is selected initially.
3229 If NO-DISPLAY, don't generate a summary buffer."
3230   (let (result)
3231     (while (and group
3232                 (null (setq result
3233                             (let ((gnus-auto-select-next nil))
3234                               (or (gnus-summary-read-group-1
3235                                    group show-all no-article
3236                                    kill-buffer no-display
3237                                    select-articles)
3238                                   (setq show-all nil
3239                                         select-articles nil)))))
3240                 (eq gnus-auto-select-next 'quietly))
3241       (set-buffer gnus-group-buffer)
3242       ;; The entry function called above goes to the next
3243       ;; group automatically, so we go two groups back
3244       ;; if we are searching for the previous group.
3245       (when backward
3246         (gnus-group-prev-unread-group 2))
3247       (if (not (equal group (gnus-group-group-name)))
3248           (setq group (gnus-group-group-name))
3249         (setq group nil)))
3250     result))
3251
3252 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3253   "Directly jump to the other GROUP from summary buffer.
3254 If SHOW-ALL is non-nil, already read articles are also listed."
3255   (interactive
3256    (if (eq gnus-summary-buffer (current-buffer))
3257        (list (completing-read
3258               "Group: " gnus-active-hashtb nil t
3259               (when (and gnus-newsgroup-name
3260                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3261                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3262               'gnus-group-history)
3263              current-prefix-arg)
3264      (error "%s must be invoked from a gnus summary buffer." this-command)))
3265   (unless (or (zerop (length group))
3266               (and gnus-newsgroup-name
3267                    (string-equal gnus-newsgroup-name group)))
3268     (gnus-summary-exit)
3269     (gnus-summary-read-group group show-all
3270                              gnus-dont-select-after-jump-to-other-group)))
3271
3272 (defun gnus-summary-read-group-1 (group show-all no-article
3273                                         kill-buffer no-display
3274                                         &optional select-articles)
3275   ;; Killed foreign groups can't be entered.
3276   ;;  (when (and (not (gnus-group-native-p group))
3277   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3278   ;;    (error "Dead non-native groups can't be entered"))
3279   (gnus-message 5 "Retrieving newsgroup: %s..."
3280                 (gnus-group-decoded-name group))
3281   (let* ((new-group (gnus-summary-setup-buffer group))
3282          (quit-config (gnus-group-quit-config group))
3283          (did-select (and new-group (gnus-select-newsgroup
3284                                      group show-all select-articles))))
3285     (cond
3286      ;; This summary buffer exists already, so we just select it.
3287      ((not new-group)
3288       (gnus-set-global-variables)
3289       (when kill-buffer
3290         (gnus-kill-or-deaden-summary kill-buffer))
3291       (gnus-configure-windows 'summary 'force)
3292       (gnus-set-mode-line 'summary)
3293       (gnus-summary-position-point)
3294       (message "")
3295       t)
3296      ;; We couldn't select this group.
3297      ((null did-select)
3298       (when (and (eq major-mode 'gnus-summary-mode)
3299                  (not (equal (current-buffer) kill-buffer)))
3300         (kill-buffer (current-buffer))
3301         (if (not quit-config)
3302             (progn
3303               ;; Update the info -- marks might need to be removed,
3304               ;; for instance.
3305               (gnus-summary-update-info)
3306               (set-buffer gnus-group-buffer)
3307               (gnus-group-jump-to-group group)
3308               (gnus-group-next-unread-group 1))
3309           (gnus-handle-ephemeral-exit quit-config)))
3310       (let ((grpinfo (gnus-get-info group)))
3311         (if (null (gnus-info-read grpinfo))
3312             (gnus-message 3 "Group %s contains no messages"
3313                           (gnus-group-decoded-name group))
3314           (gnus-message 3 "Can't select group")))
3315       nil)
3316      ;; The user did a `C-g' while prompting for number of articles,
3317      ;; so we exit this group.
3318      ((eq did-select 'quit)
3319       (and (eq major-mode 'gnus-summary-mode)
3320            (not (equal (current-buffer) kill-buffer))
3321            (kill-buffer (current-buffer)))
3322       (when kill-buffer
3323         (gnus-kill-or-deaden-summary kill-buffer))
3324       (if (not quit-config)
3325           (progn
3326             (set-buffer gnus-group-buffer)
3327             (gnus-group-jump-to-group group)
3328             (gnus-group-next-unread-group 1)
3329             (gnus-configure-windows 'group 'force))
3330         (gnus-handle-ephemeral-exit quit-config))
3331       ;; Finally signal the quit.
3332       (signal 'quit nil))
3333      ;; The group was successfully selected.
3334      (t
3335       (gnus-set-global-variables)
3336       ;; Save the active value in effect when the group was entered.
3337       (setq gnus-newsgroup-active
3338             (gnus-copy-sequence
3339              (gnus-active gnus-newsgroup-name)))
3340       ;; You can change the summary buffer in some way with this hook.
3341       (gnus-run-hooks 'gnus-select-group-hook)
3342       (gnus-update-format-specifications
3343        nil 'summary 'summary-mode 'summary-dummy)
3344       (gnus-update-summary-mark-positions)
3345       ;; Do score processing.
3346       (when gnus-use-scoring
3347         (gnus-possibly-score-headers))
3348       ;; Check whether to fill in the gaps in the threads.
3349       (when gnus-build-sparse-threads
3350         (gnus-build-sparse-threads))
3351       ;; Find the initial limit.
3352       (if gnus-show-threads
3353           (if show-all
3354               (let ((gnus-newsgroup-dormant nil))
3355                 (gnus-summary-initial-limit show-all))
3356             (gnus-summary-initial-limit show-all))
3357         ;; When untreaded, all articles are always shown.
3358         (setq gnus-newsgroup-limit
3359               (mapcar
3360                (lambda (header) (mail-header-number header))
3361                gnus-newsgroup-headers)))
3362       ;; Generate the summary buffer.
3363       (unless no-display
3364         (gnus-summary-prepare))
3365       (when gnus-use-trees
3366         (gnus-tree-open group)
3367         (setq gnus-summary-highlight-line-function
3368               'gnus-tree-highlight-article))
3369       ;; If the summary buffer is empty, but there are some low-scored
3370       ;; articles or some excluded dormants, we include these in the
3371       ;; buffer.
3372       (when (and (zerop (buffer-size))
3373                  (not no-display))
3374         (cond (gnus-newsgroup-dormant
3375                (gnus-summary-limit-include-dormant))
3376               ((and gnus-newsgroup-scored show-all)
3377                (gnus-summary-limit-include-expunged t))))
3378       ;; Function `gnus-apply-kill-file' must be called in this hook.
3379       (gnus-run-hooks 'gnus-apply-kill-hook)
3380       (if (and (zerop (buffer-size))
3381                (not no-display))
3382           (progn
3383             ;; This newsgroup is empty.
3384             (gnus-summary-catchup-and-exit nil t)
3385             (gnus-message 6 "No unread news")
3386             (when kill-buffer
3387               (gnus-kill-or-deaden-summary kill-buffer))
3388             ;; Return nil from this function.
3389             nil)
3390         ;; Hide conversation thread subtrees.  We cannot do this in
3391         ;; gnus-summary-prepare-hook since kill processing may not
3392         ;; work with hidden articles.
3393         (gnus-summary-maybe-hide-threads)
3394         (when kill-buffer
3395           (gnus-kill-or-deaden-summary kill-buffer))
3396         (gnus-summary-auto-select-subject)
3397         ;; Show first unread article if requested.
3398         (if (and (not no-article)
3399                  (not no-display)
3400                  gnus-newsgroup-unreads
3401                  gnus-auto-select-first)
3402             (progn
3403               (gnus-configure-windows 'summary)
3404               (let ((art (gnus-summary-article-number)))
3405                 (unless (or (memq art gnus-newsgroup-undownloaded)
3406                             (memq art gnus-newsgroup-downloadable))
3407                   (gnus-summary-goto-article art))))
3408           ;; Don't select any articles.
3409           (gnus-summary-position-point)
3410           (gnus-configure-windows 'summary 'force)
3411           (gnus-set-mode-line 'summary))
3412         (when (get-buffer-window gnus-group-buffer t)
3413           ;; Gotta use windows, because recenter does weird stuff if
3414           ;; the current buffer ain't the displayed window.
3415           (let ((owin (selected-window)))
3416             (select-window (get-buffer-window gnus-group-buffer t))
3417             (when (gnus-group-goto-group group)
3418               (recenter))
3419             (select-window owin)))
3420         ;; Mark this buffer as "prepared".
3421         (setq gnus-newsgroup-prepared t)
3422         (gnus-run-hooks 'gnus-summary-prepared-hook)
3423         t)))))
3424
3425 (defun gnus-summary-auto-select-subject ()
3426   "Select the subject line on initial group entry."
3427   (goto-char (point-min))
3428   (cond
3429    ((eq gnus-auto-select-subject 'best)
3430     (gnus-summary-best-unread-subject))
3431    ((eq gnus-auto-select-subject 'unread)
3432     (gnus-summary-first-unread-subject))
3433    ((eq gnus-auto-select-subject 'unseen)
3434     (gnus-summary-first-unseen-subject))
3435    ((eq gnus-auto-select-subject 'unseen-or-unread)
3436     (gnus-summary-first-unseen-or-unread-subject))
3437    ((eq gnus-auto-select-subject 'first)
3438     ;; Do nothing.
3439     )
3440    ((gnus-functionp gnus-auto-select-subject)
3441     (funcall gnus-auto-select-subject))))
3442
3443 (defun gnus-summary-prepare ()
3444   "Generate the summary buffer."
3445   (interactive)
3446   (let ((buffer-read-only nil))
3447     (erase-buffer)
3448     (setq gnus-newsgroup-data nil
3449           gnus-newsgroup-data-reverse nil)
3450     (gnus-run-hooks 'gnus-summary-generate-hook)
3451     ;; Generate the buffer, either with threads or without.
3452     (when gnus-newsgroup-headers
3453       (gnus-summary-prepare-threads
3454        (if gnus-show-threads
3455            (gnus-sort-gathered-threads
3456             (funcall gnus-summary-thread-gathering-function
3457                      (gnus-sort-threads
3458                       (gnus-cut-threads (gnus-make-threads)))))
3459          ;; Unthreaded display.
3460          (gnus-sort-articles gnus-newsgroup-headers))))
3461     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3462     ;; Call hooks for modifying summary buffer.
3463     (goto-char (point-min))
3464     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3465
3466 (defsubst gnus-general-simplify-subject (subject)
3467   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3468   (setq subject
3469         (cond
3470          ;; Truncate the subject.
3471          (gnus-simplify-subject-functions
3472           (gnus-map-function gnus-simplify-subject-functions subject))
3473          ((numberp gnus-summary-gather-subject-limit)
3474           (setq subject (gnus-simplify-subject-re subject))
3475           (if (> (length subject) gnus-summary-gather-subject-limit)
3476               (substring subject 0 gnus-summary-gather-subject-limit)
3477             subject))
3478          ;; Fuzzily simplify it.
3479          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3480           (gnus-simplify-subject-fuzzy subject))
3481          ;; Just remove the leading "Re:".
3482          (t
3483           (gnus-simplify-subject-re subject))))
3484
3485   (if (and gnus-summary-gather-exclude-subject
3486            (string-match gnus-summary-gather-exclude-subject subject))
3487       nil                               ; This article shouldn't be gathered
3488     subject))
3489
3490 (defun gnus-summary-simplify-subject-query ()
3491   "Query where the respool algorithm would put this article."
3492   (interactive)
3493   (gnus-summary-select-article)
3494   (message "%s"
3495            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3496
3497 (defun gnus-gather-threads-by-subject (threads)
3498   "Gather threads by looking at Subject headers."
3499   (if (not gnus-summary-make-false-root)
3500       threads
3501     (let ((hashtb (gnus-make-hashtable 1024))
3502           (prev threads)
3503           (result threads)
3504           subject hthread whole-subject)
3505       (while threads
3506         (setq subject (gnus-general-simplify-subject
3507                        (setq whole-subject (mail-header-subject
3508                                             (caar threads)))))
3509         (when subject
3510           (if (setq hthread (gnus-gethash subject hashtb))
3511               (progn
3512                 ;; We enter a dummy root into the thread, if we
3513                 ;; haven't done that already.
3514                 (unless (stringp (caar hthread))
3515                   (setcar hthread (list whole-subject (car hthread))))
3516                 ;; We add this new gathered thread to this gathered
3517                 ;; thread.
3518                 (setcdr (car hthread)
3519                         (nconc (cdar hthread) (list (car threads))))
3520                 ;; Remove it from the list of threads.
3521                 (setcdr prev (cdr threads))
3522                 (setq threads prev))
3523             ;; Enter this thread into the hash table.
3524             (gnus-sethash subject threads hashtb)))
3525         (setq prev threads)
3526         (setq threads (cdr threads)))
3527       result)))
3528
3529 (defun gnus-gather-threads-by-references (threads)
3530   "Gather threads by looking at References headers."
3531   (let ((idhashtb (gnus-make-hashtable 1024))
3532         (thhashtb (gnus-make-hashtable 1024))
3533         (prev threads)
3534         (result threads)
3535         ids references id gthread gid entered ref)
3536     (while threads
3537       (when (setq references (mail-header-references (caar threads)))
3538         (setq id (mail-header-id (caar threads))
3539               ids (inline (gnus-split-references references))
3540               entered nil)
3541         (while (setq ref (pop ids))
3542           (setq ids (delete ref ids))
3543           (if (not (setq gid (gnus-gethash ref idhashtb)))
3544               (progn
3545                 (gnus-sethash ref id idhashtb)
3546                 (gnus-sethash id threads thhashtb))
3547             (setq gthread (gnus-gethash gid thhashtb))
3548             (unless entered
3549               ;; We enter a dummy root into the thread, if we
3550               ;; haven't done that already.
3551               (unless (stringp (caar gthread))
3552                 (setcar gthread (list (mail-header-subject (caar gthread))
3553                                       (car gthread))))
3554               ;; We add this new gathered thread to this gathered
3555               ;; thread.
3556               (setcdr (car gthread)
3557                       (nconc (cdar gthread) (list (car threads)))))
3558             ;; Add it into the thread hash table.
3559             (gnus-sethash id gthread thhashtb)
3560             (setq entered t)
3561             ;; Remove it from the list of threads.
3562             (setcdr prev (cdr threads))
3563             (setq threads prev))))
3564       (setq prev threads)
3565       (setq threads (cdr threads)))
3566     result))
3567
3568 (defun gnus-sort-gathered-threads (threads)
3569   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3570   (let ((result threads))
3571     (while threads
3572       (when (stringp (caar threads))
3573         (setcdr (car threads)
3574                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3575       (setq threads (cdr threads)))
3576     result))
3577
3578 (defun gnus-thread-loop-p (root thread)
3579   "Say whether ROOT is in THREAD."
3580   (let ((stack (list thread))
3581         (infloop 0)
3582         th)
3583     (while (setq thread (pop stack))
3584       (setq th (cdr thread))
3585       (while (and th
3586                   (not (eq (caar th) root)))
3587         (pop th))
3588       (if th
3589           ;; We have found a loop.
3590           (let (ref-dep)
3591             (setcdr thread (delq (car th) (cdr thread)))
3592             (if (boundp (setq ref-dep (intern "none"
3593                                               gnus-newsgroup-dependencies)))
3594                 (setcdr (symbol-value ref-dep)
3595                         (nconc (cdr (symbol-value ref-dep))
3596                                (list (car th))))
3597               (set ref-dep (list nil (car th))))
3598             (setq infloop 1
3599                   stack nil))
3600         ;; Push all the subthreads onto the stack.
3601         (push (cdr thread) stack)))
3602     infloop))
3603
3604 (defun gnus-make-threads ()
3605   "Go through the dependency hashtb and find the roots.  Return all threads."
3606   (let (threads)
3607     (while (catch 'infloop
3608              (mapatoms
3609               (lambda (refs)
3610                 ;; Deal with self-referencing References loops.
3611                 (when (and (car (symbol-value refs))
3612                            (not (zerop
3613                                  (apply
3614                                   '+
3615                                   (mapcar
3616                                    (lambda (thread)
3617                                      (gnus-thread-loop-p
3618                                       (car (symbol-value refs)) thread))
3619                                    (cdr (symbol-value refs)))))))
3620                   (setq threads nil)
3621                   (throw 'infloop t))
3622                 (unless (car (symbol-value refs))
3623                   ;; These threads do not refer back to any other articles,
3624                   ;; so they're roots.
3625                   (setq threads (append (cdr (symbol-value refs)) threads))))
3626               gnus-newsgroup-dependencies)))
3627     threads))
3628
3629 ;; Build the thread tree.
3630 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3631   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3632
3633 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3634 if it was already present.
3635
3636 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3637 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3638 Message-IDs will be renamed to a unique Message-ID before being
3639 entered.
3640
3641 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3642   (let* ((id (mail-header-id header))
3643          (id-dep (and id (intern id dependencies)))
3644          ref ref-dep ref-header replaced)
3645     ;; Enter this `header' in the `dependencies' table.
3646     (cond
3647      ((not id-dep)
3648       (setq header nil))
3649      ;; The first two cases do the normal part: enter a new `header'
3650      ;; in the `dependencies' table.
3651      ((not (boundp id-dep))
3652       (set id-dep (list header)))
3653      ((null (car (symbol-value id-dep)))
3654       (setcar (symbol-value id-dep) header))
3655
3656      ;; From here the `header' was already present in the
3657      ;; `dependencies' table.
3658      (force-new
3659       ;; Overrides an existing entry;
3660       ;; just set the header part of the entry.
3661       (setcar (symbol-value id-dep) header)
3662       (setq replaced t))
3663
3664      ;; Renames the existing `header' to a unique Message-ID.
3665      ((not gnus-summary-ignore-duplicates)
3666       ;; An article with this Message-ID has already been seen.
3667       ;; We rename the Message-ID.
3668       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3669            (list header))
3670       (mail-header-set-id header id))
3671
3672      ;; The last case ignores an existing entry, except it adds any
3673      ;; additional Xrefs (in case the two articles came from different
3674      ;; servers.
3675      ;; Also sets `header' to `nil' meaning that the `dependencies'
3676      ;; table was *not* modified.
3677      (t
3678       (mail-header-set-xref
3679        (car (symbol-value id-dep))
3680        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3681                    "")
3682                (or (mail-header-xref header) "")))
3683       (setq header nil)))
3684
3685     (when (and header (not replaced))
3686       ;; First check that we are not creating a References loop.
3687       (setq ref (gnus-parent-id (mail-header-references header)))
3688       (while (and ref
3689                   (setq ref-dep (intern-soft ref dependencies))
3690                   (boundp ref-dep)
3691                   (setq ref-header (car (symbol-value ref-dep))))
3692         (if (string= id ref)
3693             ;; Yuk!  This is a reference loop.  Make the article be a
3694             ;; root article.
3695             (progn
3696               (mail-header-set-references (car (symbol-value id-dep)) "none")
3697               (setq ref nil))
3698           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3699       (setq ref (gnus-parent-id (mail-header-references header)))
3700       (setq ref-dep (intern (or ref "none") dependencies))
3701       (if (boundp ref-dep)
3702           (setcdr (symbol-value ref-dep)
3703                   (nconc (cdr (symbol-value ref-dep))
3704                          (list (symbol-value id-dep))))
3705         (set ref-dep (list nil (symbol-value id-dep)))))
3706     header))
3707
3708 (defun gnus-extract-message-id-from-in-reply-to (string)
3709   (if (string-match "<[^>]+>" string)
3710       (substring string (match-beginning 0) (match-end 0))
3711     nil))
3712
3713 (defun gnus-build-sparse-threads ()
3714   (let ((headers gnus-newsgroup-headers)
3715         (mail-parse-charset gnus-newsgroup-charset)
3716         (gnus-summary-ignore-duplicates t)
3717         header references generation relations
3718         subject child end new-child date)
3719     ;; First we create an alist of generations/relations, where
3720     ;; generations is how much we trust the relation, and the relation
3721     ;; is parent/child.
3722     (gnus-message 7 "Making sparse threads...")
3723     (save-excursion
3724       (nnheader-set-temp-buffer " *gnus sparse threads*")
3725       (while (setq header (pop headers))
3726         (when (and (setq references (mail-header-references header))
3727                    (not (string= references "")))
3728           (insert references)
3729           (setq child (mail-header-id header)
3730                 subject (mail-header-subject header)
3731                 date (mail-header-date header)
3732                 generation 0)
3733           (while (search-backward ">" nil t)
3734             (setq end (1+ (point)))
3735             (when (search-backward "<" nil t)
3736               (setq new-child (buffer-substring (point) end))
3737               (push (list (incf generation)
3738                           child (setq child new-child)
3739                           subject date)
3740                     relations)))
3741           (when child
3742             (push (list (1+ generation) child nil subject) relations))
3743           (erase-buffer)))
3744       (kill-buffer (current-buffer)))
3745     ;; Sort over trustworthiness.
3746     (mapcar
3747      (lambda (relation)
3748        (when (gnus-dependencies-add-header
3749               (make-full-mail-header-from-decoded-header
3750                gnus-reffed-article-number
3751                (nth 3 relation) "" (or (nth 4 relation) "")
3752                (nth 1 relation)
3753                (or (nth 2 relation) "") 0 0 "")
3754               gnus-newsgroup-dependencies nil)
3755          (push gnus-reffed-article-number gnus-newsgroup-limit)
3756          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3757          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3758                gnus-newsgroup-reads)
3759          (decf gnus-reffed-article-number)))
3760      (sort relations 'car-less-than-car))
3761     (gnus-message 7 "Making sparse threads...done")))
3762
3763 (defun gnus-build-old-threads ()
3764   ;; Look at all the articles that refer back to old articles, and
3765   ;; fetch the headers for the articles that aren't there.  This will
3766   ;; build complete threads - if the roots haven't been expired by the
3767   ;; server, that is.
3768   (let ((mail-parse-charset gnus-newsgroup-charset)
3769         id heads)
3770     (mapatoms
3771      (lambda (refs)
3772        (when (not (car (symbol-value refs)))
3773          (setq heads (cdr (symbol-value refs)))
3774          (while heads
3775            (if (memq (mail-header-number (caar heads))
3776                      gnus-newsgroup-dormant)
3777                (setq heads (cdr heads))
3778              (setq id (symbol-name refs))
3779              (while (and (setq id (gnus-build-get-header id))
3780                          (not (car (gnus-id-to-thread id)))))
3781              (setq heads nil)))))
3782      gnus-newsgroup-dependencies)))
3783
3784 ;; This function has to be called with point after the article number
3785 ;; on the beginning of the line.
3786 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3787   (let ((eol (gnus-point-at-eol))
3788         (buffer (current-buffer))
3789         header references in-reply-to)
3790
3791     ;; overview: [num subject from date id refs chars lines misc]
3792     (unwind-protect
3793         (progn
3794           (narrow-to-region (point) eol)
3795           (unless (eobp)
3796             (forward-char))
3797
3798           (setq header
3799                 (make-full-mail-header
3800                  number                         ; number
3801                  (nnheader-nov-field)           ; subject
3802                  (nnheader-nov-field)           ; from
3803                  (nnheader-nov-field)           ; date
3804                  (nnheader-nov-read-message-id) ; id
3805                  (nnheader-nov-field)           ; refs
3806                  (nnheader-nov-read-integer)    ; chars
3807                  (nnheader-nov-read-integer)    ; lines
3808                  (unless (eobp)
3809                    (if (looking-at "Xref: ")
3810                        (goto-char (match-end 0)))
3811                    (nnheader-nov-field))        ; Xref
3812                  (nnheader-nov-parse-extra))))  ; extra
3813
3814       (widen))
3815
3816     (when (and (string= references "")
3817                (setq in-reply-to (mail-header-extra header))
3818                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3819       (mail-header-set-references
3820        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3821
3822     (when gnus-alter-header-function
3823       (funcall gnus-alter-header-function header))
3824     (gnus-dependencies-add-header header dependencies force-new)))
3825
3826 (defun gnus-build-get-header (id)
3827   "Look through the buffer of NOV lines and find the header to ID.
3828 Enter this line into the dependencies hash table, and return
3829 the id of the parent article (if any)."
3830   (let ((deps gnus-newsgroup-dependencies)
3831         found header)
3832     (prog1
3833         (save-excursion
3834           (set-buffer nntp-server-buffer)
3835           (let ((case-fold-search nil))
3836             (goto-char (point-min))
3837             (while (and (not found)
3838                         (search-forward id nil t))
3839               (beginning-of-line)
3840               (setq found (looking-at
3841                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3842                                    (regexp-quote id))))
3843               (or found (beginning-of-line 2)))
3844             (when found
3845               (beginning-of-line)
3846               (and
3847                (setq header (gnus-nov-parse-line
3848                              (read (current-buffer)) deps))
3849                (gnus-parent-id (mail-header-references header))))))
3850       (when header
3851         (let ((number (mail-header-number header)))
3852           (push number gnus-newsgroup-limit)
3853           (push header gnus-newsgroup-headers)
3854           (if (memq number gnus-newsgroup-unselected)
3855               (progn
3856                 (setq gnus-newsgroup-unreads
3857                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3858                                                number))
3859                 (setq gnus-newsgroup-unselected
3860                       (delq number gnus-newsgroup-unselected)))
3861             (push number gnus-newsgroup-ancient)))))))
3862
3863 (defun gnus-build-all-threads ()
3864   "Read all the headers."
3865   (let ((gnus-summary-ignore-duplicates t)
3866         (mail-parse-charset gnus-newsgroup-charset)
3867         (dependencies gnus-newsgroup-dependencies)
3868         header article)
3869     (save-excursion
3870       (set-buffer nntp-server-buffer)
3871       (let ((case-fold-search nil))
3872         (goto-char (point-min))
3873         (while (not (eobp))
3874           (ignore-errors
3875             (setq article (read (current-buffer))
3876                   header (gnus-nov-parse-line article dependencies)))
3877           (when header
3878             (save-excursion
3879               (set-buffer gnus-summary-buffer)
3880               (push header gnus-newsgroup-headers)
3881               (if (memq (setq article (mail-header-number header))
3882                         gnus-newsgroup-unselected)
3883                   (progn
3884                     (setq gnus-newsgroup-unreads
3885                           (gnus-add-to-sorted-list
3886                            gnus-newsgroup-unreads article))
3887                     (setq gnus-newsgroup-unselected
3888                           (delq article gnus-newsgroup-unselected)))
3889                 (push article gnus-newsgroup-ancient)))
3890             (forward-line 1)))))))
3891
3892 (defun gnus-summary-update-article-line (article header)
3893   "Update the line for ARTICLE using HEADERS."
3894   (let* ((id (mail-header-id header))
3895          (thread (gnus-id-to-thread id)))
3896     (unless thread
3897       (error "Article in no thread"))
3898     ;; Update the thread.
3899     (setcar thread header)
3900     (gnus-summary-goto-subject article)
3901     (let* ((datal (gnus-data-find-list article))
3902            (data (car datal))
3903            (length (when (cdr datal)
3904                      (- (gnus-data-pos data)
3905                         (gnus-data-pos (cadr datal)))))
3906            (buffer-read-only nil)
3907            (level (gnus-summary-thread-level)))
3908       (gnus-delete-line)
3909       (gnus-summary-insert-line
3910        header level nil (gnus-article-mark article)
3911        (memq article gnus-newsgroup-replied)
3912        (memq article gnus-newsgroup-expirable)
3913        ;; Only insert the Subject string when it's different
3914        ;; from the previous Subject string.
3915        (if (and
3916             gnus-show-threads
3917             (gnus-subject-equal
3918              (condition-case ()
3919                  (mail-header-subject
3920                   (gnus-data-header
3921                    (cadr
3922                     (gnus-data-find-list
3923                      article
3924                      (gnus-data-list t)))))
3925                ;; Error on the side of excessive subjects.
3926                (error ""))
3927              (mail-header-subject header)))
3928            ""
3929          (mail-header-subject header))
3930        nil (cdr (assq article gnus-newsgroup-scored))
3931        (memq article gnus-newsgroup-processable))
3932       (when length
3933         (gnus-data-update-list
3934          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3935
3936 (defun gnus-summary-update-article (article &optional iheader)
3937   "Update ARTICLE in the summary buffer."
3938   (set-buffer gnus-summary-buffer)
3939   (let* ((header (gnus-summary-article-header article))
3940          (id (mail-header-id header))
3941          (data (gnus-data-find article))
3942          (thread (gnus-id-to-thread id))
3943          (references (mail-header-references header))
3944          (parent
3945           (gnus-id-to-thread
3946            (or (gnus-parent-id
3947                 (when (and references
3948                            (not (equal "" references)))
3949                   references))
3950                "none")))
3951          (buffer-read-only nil)
3952          (old (car thread)))
3953     (when thread
3954       (unless iheader
3955         (setcar thread nil)
3956         (when parent
3957           (delq thread parent)))
3958       (if (gnus-summary-insert-subject id header)
3959           ;; Set the (possibly) new article number in the data structure.
3960           (gnus-data-set-number data (gnus-id-to-article id))
3961         (setcar thread old)
3962         nil))))
3963
3964 (defun gnus-rebuild-thread (id &optional line)
3965   "Rebuild the thread containing ID.
3966 If LINE, insert the rebuilt thread starting on line LINE."
3967   (let ((buffer-read-only nil)
3968         old-pos current thread data)
3969     (if (not gnus-show-threads)
3970         (setq thread (list (car (gnus-id-to-thread id))))
3971       ;; Get the thread this article is part of.
3972       (setq thread (gnus-remove-thread id)))
3973     (setq old-pos (gnus-point-at-bol))
3974     (setq current (save-excursion
3975                     (and (re-search-backward "[\r\n]" nil t)
3976                          (gnus-summary-article-number))))
3977     ;; If this is a gathered thread, we have to go some re-gathering.
3978     (when (stringp (car thread))
3979       (let ((subject (car thread))
3980             roots thr)
3981         (setq thread (cdr thread))
3982         (while thread
3983           (unless (memq (setq thr (gnus-id-to-thread
3984                                    (gnus-root-id
3985                                     (mail-header-id (caar thread)))))
3986                         roots)
3987             (push thr roots))
3988           (setq thread (cdr thread)))
3989         ;; We now have all (unique) roots.
3990         (if (= (length roots) 1)
3991             ;; All the loose roots are now one solid root.
3992             (setq thread (car roots))
3993           (setq thread (cons subject (gnus-sort-threads roots))))))
3994     (let (threads)
3995       ;; We then insert this thread into the summary buffer.
3996       (when line
3997         (goto-char (point-min))
3998         (forward-line (1- line)))
3999       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4000         (if gnus-show-threads
4001             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4002           (gnus-summary-prepare-unthreaded thread))
4003         (setq data (nreverse gnus-newsgroup-data))
4004         (setq threads gnus-newsgroup-threads))
4005       ;; We splice the new data into the data structure.
4006       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4007       ;;!!! then we want to insert at the beginning of the buffer.
4008       ;;!!! That happens to be true with Gnus now, but that may
4009       ;;!!! change in the future.  Perhaps.
4010       (gnus-data-enter-list
4011        (if line nil current) data (- (point) old-pos))
4012       (setq gnus-newsgroup-threads
4013             (nconc threads gnus-newsgroup-threads))
4014       (gnus-data-compute-positions))))
4015
4016 (defun gnus-number-to-header (number)
4017   "Return the header for article NUMBER."
4018   (let ((headers gnus-newsgroup-headers))
4019     (while (and headers
4020                 (not (= number (mail-header-number (car headers)))))
4021       (pop headers))
4022     (when headers
4023       (car headers))))
4024
4025 (defun gnus-parent-headers (in-headers &optional generation)
4026   "Return the headers of the GENERATIONeth parent of HEADERS."
4027   (unless generation
4028     (setq generation 1))
4029   (let ((parent t)
4030         (headers in-headers)
4031         references)
4032     (while (and parent
4033                 (not (zerop generation))
4034                 (setq references (mail-header-references headers)))
4035       (setq headers (if (and references
4036                              (setq parent (gnus-parent-id references)))
4037                         (car (gnus-id-to-thread parent))
4038                       nil))
4039       (decf generation))
4040     (and (not (eq headers in-headers))
4041          headers)))
4042
4043 (defun gnus-id-to-thread (id)
4044   "Return the (sub-)thread where ID appears."
4045   (gnus-gethash id gnus-newsgroup-dependencies))
4046
4047 (defun gnus-id-to-article (id)
4048   "Return the article number of ID."
4049   (let ((thread (gnus-id-to-thread id)))
4050     (when (and thread
4051                (car thread))
4052       (mail-header-number (car thread)))))
4053
4054 (defun gnus-id-to-header (id)
4055   "Return the article headers of ID."
4056   (car (gnus-id-to-thread id)))
4057
4058 (defun gnus-article-displayed-root-p (article)
4059   "Say whether ARTICLE is a root(ish) article."
4060   (let ((level (gnus-summary-thread-level article))
4061         (refs (mail-header-references  (gnus-summary-article-header article)))
4062         particle)
4063     (cond
4064      ((null level) nil)
4065      ((zerop level) t)
4066      ((null refs) t)
4067      ((null (gnus-parent-id refs)) t)
4068      ((and (= 1 level)
4069            (null (setq particle (gnus-id-to-article
4070                                  (gnus-parent-id refs))))
4071            (null (gnus-summary-thread-level particle)))))))
4072
4073 (defun gnus-root-id (id)
4074   "Return the id of the root of the thread where ID appears."
4075   (let (last-id prev)
4076     (while (and id (setq prev (car (gnus-id-to-thread id))))
4077       (setq last-id id
4078             id (gnus-parent-id (mail-header-references prev))))
4079     last-id))
4080
4081 (defun gnus-articles-in-thread (thread)
4082   "Return the list of articles in THREAD."
4083   (cons (mail-header-number (car thread))
4084         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4085
4086 (defun gnus-remove-thread (id &optional dont-remove)
4087   "Remove the thread that has ID in it."
4088   (let (headers thread last-id)
4089     ;; First go up in this thread until we find the root.
4090     (setq last-id (gnus-root-id id)
4091           headers (message-flatten-list (gnus-id-to-thread last-id)))
4092     ;; We have now found the real root of this thread.  It might have
4093     ;; been gathered into some loose thread, so we have to search
4094     ;; through the threads to find the thread we wanted.
4095     (let ((threads gnus-newsgroup-threads)
4096           sub)
4097       (while threads
4098         (setq sub (car threads))
4099         (if (stringp (car sub))
4100             ;; This is a gathered thread, so we look at the roots
4101             ;; below it to find whether this article is in this
4102             ;; gathered root.
4103             (progn
4104               (setq sub (cdr sub))
4105               (while sub
4106                 (when (member (caar sub) headers)
4107                   (setq thread (car threads)
4108                         threads nil
4109                         sub nil))
4110                 (setq sub (cdr sub))))
4111           ;; It's an ordinary thread, so we check it.
4112           (when (eq (car sub) (car headers))
4113             (setq thread sub
4114                   threads nil)))
4115         (setq threads (cdr threads)))
4116       ;; If this article is in no thread, then it's a root.
4117       (if thread
4118           (unless dont-remove
4119             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4120         (setq thread (gnus-id-to-thread last-id)))
4121       (when thread
4122         (prog1
4123             thread                      ; We return this thread.
4124           (unless dont-remove
4125             (if (stringp (car thread))
4126                 (progn
4127                   ;; If we use dummy roots, then we have to remove the
4128                   ;; dummy root as well.
4129                   (when (eq gnus-summary-make-false-root 'dummy)
4130                     ;; We go to the dummy root by going to
4131                     ;; the first sub-"thread", and then one line up.
4132                     (gnus-summary-goto-article
4133                      (mail-header-number (caadr thread)))
4134                     (forward-line -1)
4135                     (gnus-delete-line)
4136                     (gnus-data-compute-positions))
4137                   (setq thread (cdr thread))
4138                   (while thread
4139                     (gnus-remove-thread-1 (car thread))
4140                     (setq thread (cdr thread))))
4141               (gnus-remove-thread-1 thread))))))))
4142
4143 (defun gnus-remove-thread-1 (thread)
4144   "Remove the thread THREAD recursively."
4145   (let ((number (mail-header-number (pop thread)))
4146         d)
4147     (setq thread (reverse thread))
4148     (while thread
4149       (gnus-remove-thread-1 (pop thread)))
4150     (when (setq d (gnus-data-find number))
4151       (goto-char (gnus-data-pos d))
4152       (gnus-summary-show-thread)
4153       (gnus-data-remove
4154        number
4155        (- (gnus-point-at-bol)
4156           (prog1
4157               (1+ (gnus-point-at-eol))
4158             (gnus-delete-line)))))))
4159
4160 (defun gnus-sort-threads-1 (threads func)
4161   (sort (mapcar (lambda (thread)
4162                   (cons (car thread)
4163                         (and (cdr thread)
4164                              (gnus-sort-threads-1 (cdr thread) func))))
4165                 threads) func))
4166
4167 (defun gnus-sort-threads (threads)
4168   "Sort THREADS."
4169   (if (not gnus-thread-sort-functions)
4170       threads
4171     (gnus-message 8 "Sorting threads...")
4172     (prog1
4173         (gnus-sort-threads-1
4174          threads
4175          (gnus-make-sort-function gnus-thread-sort-functions))
4176       (gnus-message 8 "Sorting threads...done"))))
4177
4178 (defun gnus-sort-articles (articles)
4179   "Sort ARTICLES."
4180   (when gnus-article-sort-functions
4181     (gnus-message 7 "Sorting articles...")
4182     (prog1
4183         (setq gnus-newsgroup-headers
4184               (sort articles (gnus-make-sort-function
4185                               gnus-article-sort-functions)))
4186       (gnus-message 7 "Sorting articles...done"))))
4187
4188 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4189 (defmacro gnus-thread-header (thread)
4190   "Return header of first article in THREAD.
4191 Note that THREAD must never, ever be anything else than a variable -
4192 using some other form will lead to serious barfage."
4193   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4194   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4195   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4196         (vector thread) 2))
4197
4198 (defsubst gnus-article-sort-by-number (h1 h2)
4199   "Sort articles by article number."
4200   (< (mail-header-number h1)
4201      (mail-header-number h2)))
4202
4203 (defun gnus-thread-sort-by-number (h1 h2)
4204   "Sort threads by root article number."
4205   (gnus-article-sort-by-number
4206    (gnus-thread-header h1) (gnus-thread-header h2)))
4207
4208 (defsubst gnus-article-sort-by-lines (h1 h2)
4209   "Sort articles by article Lines header."
4210   (< (mail-header-lines h1)
4211      (mail-header-lines h2)))
4212
4213 (defun gnus-thread-sort-by-lines (h1 h2)
4214   "Sort threads by root article Lines header."
4215   (gnus-article-sort-by-lines
4216    (gnus-thread-header h1) (gnus-thread-header h2)))
4217
4218 (defsubst gnus-article-sort-by-chars (h1 h2)
4219   "Sort articles by octet length."
4220   (< (mail-header-chars h1)
4221      (mail-header-chars h2)))
4222
4223 (defun gnus-thread-sort-by-chars (h1 h2)
4224   "Sort threads by root article octet length."
4225   (gnus-article-sort-by-chars
4226    (gnus-thread-header h1) (gnus-thread-header h2)))
4227
4228 (defsubst gnus-article-sort-by-author (h1 h2)
4229   "Sort articles by root author."
4230   (string-lessp
4231    (let ((addr (car (mime-entity-read-field h1 'From))))
4232      (or (std11-full-name-string addr)
4233          (std11-address-string addr)
4234          ""))
4235    (let ((addr (car (mime-entity-read-field h2 'From))))
4236      (or (std11-full-name-string addr)
4237          (std11-address-string addr)
4238          ""))
4239    ))
4240
4241 (defun gnus-thread-sort-by-author (h1 h2)
4242   "Sort threads by root author."
4243   (gnus-article-sort-by-author
4244    (gnus-thread-header h1)  (gnus-thread-header h2)))
4245
4246 (defsubst gnus-article-sort-by-subject (h1 h2)
4247   "Sort articles by root subject."
4248   (string-lessp
4249    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4250    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4251
4252 (defun gnus-thread-sort-by-subject (h1 h2)
4253   "Sort threads by root subject."
4254   (gnus-article-sort-by-subject
4255    (gnus-thread-header h1) (gnus-thread-header h2)))
4256
4257 (defsubst gnus-article-sort-by-date (h1 h2)
4258   "Sort articles by root article date."
4259   (time-less-p
4260    (gnus-date-get-time (mail-header-date h1))
4261    (gnus-date-get-time (mail-header-date h2))))
4262
4263 (defun gnus-thread-sort-by-date (h1 h2)
4264   "Sort threads by root article date."
4265   (gnus-article-sort-by-date
4266    (gnus-thread-header h1) (gnus-thread-header h2)))
4267
4268 (defsubst gnus-article-sort-by-score (h1 h2)
4269   "Sort articles by root article score.
4270 Unscored articles will be counted as having a score of zero."
4271   (> (or (cdr (assq (mail-header-number h1)
4272                     gnus-newsgroup-scored))
4273          gnus-summary-default-score 0)
4274      (or (cdr (assq (mail-header-number h2)
4275                     gnus-newsgroup-scored))
4276          gnus-summary-default-score 0)))
4277
4278 (defun gnus-thread-sort-by-score (h1 h2)
4279   "Sort threads by root article score."
4280   (gnus-article-sort-by-score
4281    (gnus-thread-header h1) (gnus-thread-header h2)))
4282
4283 (defun gnus-thread-sort-by-total-score (h1 h2)
4284   "Sort threads by the sum of all scores in the thread.
4285 Unscored articles will be counted as having a score of zero."
4286   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4287
4288 (defun gnus-thread-total-score (thread)
4289   ;; This function find the total score of THREAD.
4290   (cond
4291    ((null thread)
4292     0)
4293    ((consp thread)
4294     (if (stringp (car thread))
4295         (apply gnus-thread-score-function 0
4296                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4297       (gnus-thread-total-score-1 thread)))
4298    (t
4299     (gnus-thread-total-score-1 (list thread)))))
4300
4301 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4302   "Sort threads such that the thread with the most recently arrived article comes first."
4303   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4304
4305 (defun gnus-thread-highest-number (thread)
4306   "Return the highest article number in THREAD."
4307   (apply 'max (mapcar (lambda (header)
4308                         (mail-header-number header))
4309                       (message-flatten-list thread))))
4310
4311 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4312   "Sort threads such that the thread with the most recently dated article comes first."
4313   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4314
4315 (defun gnus-thread-latest-date (thread)
4316   "Return the highest article date in THREAD."
4317   (let ((previous-time 0))
4318     (apply 'max (mapcar
4319                  (lambda (header)
4320                    (setq previous-time
4321                          (time-to-seconds
4322                           (mail-header-parse-date
4323                            (condition-case ()
4324                                (mail-header-date header)
4325                              (error previous-time))))))
4326                  (sort
4327                   (message-flatten-list thread)
4328                   (lambda (h1 h2)
4329                     (< (mail-header-number h1)
4330                        (mail-header-number h2))))))))
4331
4332 (defun gnus-thread-total-score-1 (root)
4333   ;; This function find the total score of the thread below ROOT.
4334   (setq root (car root))
4335   (apply gnus-thread-score-function
4336          (or (append
4337               (mapcar 'gnus-thread-total-score
4338                       (cdr (gnus-id-to-thread (mail-header-id root))))
4339               (when (> (mail-header-number root) 0)
4340                 (list (or (cdr (assq (mail-header-number root)
4341                                      gnus-newsgroup-scored))
4342                           gnus-summary-default-score 0))))
4343              (list gnus-summary-default-score)
4344              '(0))))
4345
4346 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4347 (defvar gnus-tmp-prev-subject nil)
4348 (defvar gnus-tmp-false-parent nil)
4349 (defvar gnus-tmp-root-expunged nil)
4350 (defvar gnus-tmp-dummy-line nil)
4351
4352 (eval-when-compile (defvar gnus-tmp-header))
4353 (defun gnus-extra-header (type &optional header)
4354   "Return the extra header of TYPE."
4355   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4356       ""))
4357
4358 (defvar gnus-tmp-thread-tree-header-string "")
4359
4360 (defcustom gnus-sum-thread-tree-root "> "
4361   "With %B spec, used for the root of a thread.
4362 If nil, use subject instead."
4363   :type 'string
4364   :group 'gnus-thread)
4365 (defcustom gnus-sum-thread-tree-single-indent ""
4366   "With %B spec, used for a thread with just one message.
4367 If nil, use subject instead."
4368   :type 'string
4369   :group 'gnus-thread)
4370 (defcustom gnus-sum-thread-tree-vertical "| "
4371   "With %B spec, used for drawing a vertical line."
4372   :type 'string
4373   :group 'gnus-thread)
4374 (defcustom gnus-sum-thread-tree-indent "  "
4375   "With %B spec, used for indenting."
4376   :type 'string
4377   :group 'gnus-thread)
4378 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4379   "With %B spec, used for a leaf with brothers."
4380   :type 'string
4381   :group 'gnus-thread)
4382 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4383   "With %B spec, used for a leaf without brothers."
4384   :type 'string
4385   :group 'gnus-thread)
4386
4387 (defun gnus-summary-prepare-threads (threads)
4388   "Prepare summary buffer from THREADS and indentation LEVEL.
4389 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4390 or a straight list of headers."
4391   (gnus-message 7 "Generating summary...")
4392
4393   (setq gnus-newsgroup-threads threads)
4394   (beginning-of-line)
4395
4396   (let ((gnus-tmp-level 0)
4397         (default-score (or gnus-summary-default-score 0))
4398         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4399         thread number subject stack state gnus-tmp-gathered beg-match
4400         new-roots gnus-tmp-new-adopts thread-end
4401         gnus-tmp-header gnus-tmp-unread
4402         gnus-tmp-replied gnus-tmp-subject-or-nil
4403         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4404         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4405         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4406         tree-stack)
4407
4408     (setq gnus-tmp-prev-subject nil)
4409
4410     (if (vectorp (car threads))
4411         ;; If this is a straight (sic) list of headers, then a
4412         ;; threaded summary display isn't required, so we just create
4413         ;; an unthreaded one.
4414         (gnus-summary-prepare-unthreaded threads)
4415
4416       ;; Do the threaded display.
4417
4418       (while (or threads stack gnus-tmp-new-adopts new-roots)
4419
4420         (if (and (= gnus-tmp-level 0)
4421                  (or (not stack)
4422                      (= (caar stack) 0))
4423                  (not gnus-tmp-false-parent)
4424                  (or gnus-tmp-new-adopts new-roots))
4425             (if gnus-tmp-new-adopts
4426                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4427                       thread (list (car gnus-tmp-new-adopts))
4428                       gnus-tmp-header (caar thread)
4429                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4430               (when new-roots
4431                 (setq thread (list (car new-roots))
4432                       gnus-tmp-header (caar thread)
4433                       new-roots (cdr new-roots))))
4434
4435           (if threads
4436               ;; If there are some threads, we do them before the
4437               ;; threads on the stack.
4438               (setq thread threads
4439                     gnus-tmp-header (caar thread))
4440             ;; There were no current threads, so we pop something off
4441             ;; the stack.
4442             (setq state (car stack)
4443                   gnus-tmp-level (car state)
4444                   tree-stack (cadr state)
4445                   thread (caddr state)
4446                   stack (cdr stack)
4447                   gnus-tmp-header (caar thread))))
4448
4449         (setq gnus-tmp-false-parent nil)
4450         (setq gnus-tmp-root-expunged nil)
4451         (setq thread-end nil)
4452
4453         (if (stringp gnus-tmp-header)
4454             ;; The header is a dummy root.
4455             (cond
4456              ((eq gnus-summary-make-false-root 'adopt)
4457               ;; We let the first article adopt the rest.
4458               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4459                                                (cddar thread)))
4460               (setq gnus-tmp-gathered
4461                     (nconc (mapcar
4462                             (lambda (h) (mail-header-number (car h)))
4463                             (cddar thread))
4464                            gnus-tmp-gathered))
4465               (setq thread (cons (list (caar thread)
4466                                        (cadar thread))
4467                                  (cdr thread)))
4468               (setq gnus-tmp-level -1
4469                     gnus-tmp-false-parent t))
4470              ((eq gnus-summary-make-false-root 'empty)
4471               ;; We print adopted articles with empty subject fields.
4472               (setq gnus-tmp-gathered
4473                     (nconc (mapcar
4474                             (lambda (h) (mail-header-number (car h)))
4475                             (cddar thread))
4476                            gnus-tmp-gathered))
4477               (setq gnus-tmp-level -1))
4478              ((eq gnus-summary-make-false-root 'dummy)
4479               ;; We remember that we probably want to output a dummy
4480               ;; root.
4481               (setq gnus-tmp-dummy-line gnus-tmp-header)
4482               (setq gnus-tmp-prev-subject gnus-tmp-header))
4483              (t
4484               ;; We do not make a root for the gathered
4485               ;; sub-threads at all.
4486               (setq gnus-tmp-level -1)))
4487
4488           (setq number (mail-header-number gnus-tmp-header)
4489                 subject (mail-header-subject gnus-tmp-header))
4490
4491           (cond
4492            ;; If the thread has changed subject, we might want to make
4493            ;; this subthread into a root.
4494            ((and (null gnus-thread-ignore-subject)
4495                  (not (zerop gnus-tmp-level))
4496                  gnus-tmp-prev-subject
4497                  (not (inline
4498                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4499             (setq new-roots (nconc new-roots (list (car thread)))
4500                   thread-end t
4501                   gnus-tmp-header nil))
4502            ;; If the article lies outside the current limit,
4503            ;; then we do not display it.
4504            ((not (memq number gnus-newsgroup-limit))
4505             (setq gnus-tmp-gathered
4506                   (nconc (mapcar
4507                           (lambda (h) (mail-header-number (car h)))
4508                           (cdar thread))
4509                          gnus-tmp-gathered))
4510             (setq gnus-tmp-new-adopts (if (cdar thread)
4511                                           (append gnus-tmp-new-adopts
4512                                                   (cdar thread))
4513                                         gnus-tmp-new-adopts)
4514                   thread-end t
4515                   gnus-tmp-header nil)
4516             (when (zerop gnus-tmp-level)
4517               (setq gnus-tmp-root-expunged t)))
4518            ;; Perhaps this article is to be marked as read?
4519            ((and gnus-summary-mark-below
4520                  (< (or (cdr (assq number gnus-newsgroup-scored))
4521                         default-score)
4522                     gnus-summary-mark-below)
4523                  ;; Don't touch sparse articles.
4524                  (not (gnus-summary-article-sparse-p number))
4525                  (not (gnus-summary-article-ancient-p number)))
4526             (setq gnus-newsgroup-unreads
4527                   (delq number gnus-newsgroup-unreads))
4528             (if gnus-newsgroup-auto-expire
4529                 (setq gnus-newsgroup-expirable
4530                       (gnus-add-to-sorted-list
4531                        gnus-newsgroup-expirable number))
4532               (push (cons number gnus-low-score-mark)
4533                     gnus-newsgroup-reads))))
4534
4535           (when gnus-tmp-header
4536             ;; We may have an old dummy line to output before this
4537             ;; article.
4538             (when (and gnus-tmp-dummy-line
4539                        (gnus-subject-equal
4540                         gnus-tmp-dummy-line
4541                         (mail-header-subject gnus-tmp-header)))
4542               (gnus-summary-insert-dummy-line
4543                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4544               (setq gnus-tmp-dummy-line nil))
4545
4546             ;; Compute the mark.
4547             (setq gnus-tmp-unread (gnus-article-mark number))
4548
4549             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4550                                   gnus-tmp-header gnus-tmp-level)
4551                   gnus-newsgroup-data)
4552
4553             ;; Actually insert the line.
4554             (setq
4555              gnus-tmp-subject-or-nil
4556              (cond
4557               ((and gnus-thread-ignore-subject
4558                     gnus-tmp-prev-subject
4559                     (not (inline (gnus-subject-equal
4560                                   gnus-tmp-prev-subject subject))))
4561                subject)
4562               ((zerop gnus-tmp-level)
4563                (if (and (eq gnus-summary-make-false-root 'empty)
4564                         (memq number gnus-tmp-gathered)
4565                         gnus-tmp-prev-subject
4566                         (inline (gnus-subject-equal
4567                                  gnus-tmp-prev-subject subject)))
4568                    gnus-summary-same-subject
4569                  subject))
4570               (t gnus-summary-same-subject)))
4571             (if (and (eq gnus-summary-make-false-root 'adopt)
4572                      (= gnus-tmp-level 1)
4573                      (memq number gnus-tmp-gathered))
4574                 (setq gnus-tmp-opening-bracket ?\<
4575                       gnus-tmp-closing-bracket ?\>)
4576               (setq gnus-tmp-opening-bracket ?\[
4577                     gnus-tmp-closing-bracket ?\]))
4578             (setq
4579              gnus-tmp-indentation
4580              (aref gnus-thread-indent-array gnus-tmp-level)
4581              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4582              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4583                                 gnus-summary-default-score 0)
4584              gnus-tmp-score-char
4585              (if (or (null gnus-summary-default-score)
4586                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4587                          gnus-summary-zcore-fuzz))
4588                  ?\ ;;;Whitespace
4589                (if (< gnus-tmp-score gnus-summary-default-score)
4590                    gnus-score-below-mark gnus-score-over-mark))
4591              gnus-tmp-replied
4592              (cond ((memq number gnus-newsgroup-processable)
4593                     gnus-process-mark)
4594                    ((memq number gnus-newsgroup-cached)
4595                     gnus-cached-mark)
4596                    ((memq number gnus-newsgroup-replied)
4597                     gnus-replied-mark)
4598                    ((memq number gnus-newsgroup-forwarded)
4599                     gnus-forwarded-mark)
4600                    ((memq number gnus-newsgroup-saved)
4601                     gnus-saved-mark)
4602                    ((memq number gnus-newsgroup-recent)
4603                     gnus-recent-mark)
4604                    ((memq number gnus-newsgroup-unseen)
4605                     gnus-unseen-mark)
4606                    (t gnus-no-mark))
4607              gnus-tmp-from (mail-header-from gnus-tmp-header)
4608              gnus-tmp-name
4609              (cond
4610               ((string-match "<[^>]+> *$" gnus-tmp-from)
4611                (setq beg-match (match-beginning 0))
4612                (or (and (string-match "^\".+\"" gnus-tmp-from)
4613                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4614                    (substring gnus-tmp-from 0 beg-match)))
4615               ((string-match "(.+)" gnus-tmp-from)
4616                (substring gnus-tmp-from
4617                           (1+ (match-beginning 0)) (1- (match-end 0))))
4618               (t gnus-tmp-from))
4619              gnus-tmp-thread-tree-header-string
4620              (cond
4621               ((not gnus-show-threads) "")
4622               ((zerop gnus-tmp-level)
4623                (if (cdar thread)
4624                    (or gnus-sum-thread-tree-root subject)
4625                  (or gnus-sum-thread-tree-single-indent subject)))
4626               (t
4627                (concat (apply 'concat
4628                               (mapcar (lambda (item)
4629                                         (if (= item 1)
4630                                             gnus-sum-thread-tree-vertical
4631                                           gnus-sum-thread-tree-indent))
4632                                       (cdr (reverse tree-stack))))
4633                        (if (nth 1 thread)
4634                            gnus-sum-thread-tree-leaf-with-other
4635                          gnus-sum-thread-tree-single-leaf)))))
4636             (when (string= gnus-tmp-name "")
4637               (setq gnus-tmp-name gnus-tmp-from))
4638             (unless (numberp gnus-tmp-lines)
4639               (setq gnus-tmp-lines -1))
4640             (if (= gnus-tmp-lines -1)
4641                 (setq gnus-tmp-lines "?")
4642               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4643             (gnus-put-text-property
4644              (point)
4645              (progn (eval gnus-summary-line-format-spec) (point))
4646              'gnus-number number)
4647             (when gnus-visual-p
4648               (forward-line -1)
4649               (gnus-run-hooks 'gnus-summary-update-hook)
4650               (forward-line 1))
4651
4652             (setq gnus-tmp-prev-subject subject)))
4653
4654         (when (nth 1 thread)
4655           (push (list (max 0 gnus-tmp-level)
4656                       (copy-list tree-stack)
4657                       (nthcdr 1 thread))
4658                 stack))
4659         (push (if (nth 1 thread) 1 0) tree-stack)
4660         (incf gnus-tmp-level)
4661         (setq threads (if thread-end nil (cdar thread)))
4662         (unless threads
4663           (setq gnus-tmp-level 0)))))
4664   (gnus-message 7 "Generating summary...done"))
4665
4666 (defun gnus-summary-prepare-unthreaded (headers)
4667   "Generate an unthreaded summary buffer based on HEADERS."
4668   (let (header number mark)
4669
4670     (beginning-of-line)
4671
4672     (while headers
4673       ;; We may have to root out some bad articles...
4674       (when (memq (setq number (mail-header-number
4675                                 (setq header (pop headers))))
4676                   gnus-newsgroup-limit)
4677         ;; Mark article as read when it has a low score.
4678         (when (and gnus-summary-mark-below
4679                    (< (or (cdr (assq number gnus-newsgroup-scored))
4680                           gnus-summary-default-score 0)
4681                       gnus-summary-mark-below)
4682                    (not (gnus-summary-article-ancient-p number)))
4683           (setq gnus-newsgroup-unreads
4684                 (delq number gnus-newsgroup-unreads))
4685           (if gnus-newsgroup-auto-expire
4686               (push number gnus-newsgroup-expirable)
4687             (push (cons number gnus-low-score-mark)
4688                   gnus-newsgroup-reads)))
4689
4690         (setq mark (gnus-article-mark number))
4691         (push (gnus-data-make number mark (1+ (point)) header 0)
4692               gnus-newsgroup-data)
4693         (gnus-summary-insert-line
4694          header 0 number
4695          mark (memq number gnus-newsgroup-replied)
4696          (memq number gnus-newsgroup-expirable)
4697          (mail-header-subject header) nil
4698          (cdr (assq number gnus-newsgroup-scored))
4699          (memq number gnus-newsgroup-processable))))))
4700
4701 (defun gnus-summary-remove-list-identifiers ()
4702   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4703   (let ((regexp (if (consp gnus-list-identifiers)
4704                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4705                   gnus-list-identifiers))
4706         changed subject)
4707     (when regexp
4708       (dolist (header gnus-newsgroup-headers)
4709         (setq subject (mail-header-subject header)
4710               changed nil)
4711         (while (string-match
4712                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4713                 subject)
4714           (setq subject
4715                 (concat (substring subject 0 (match-beginning 2))
4716                         (substring subject (match-end 0)))
4717                 changed t))
4718         (when (and changed
4719                    (string-match
4720                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4721           (setq subject
4722                 (concat (substring subject 0 (match-beginning 1))
4723                         (substring subject (match-end 1)))))
4724         (when changed
4725           (mail-header-set-subject header subject))))))
4726
4727 (defun gnus-fetch-headers (articles)
4728   "Fetch headers of ARTICLES."
4729   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4730     (gnus-message 5 "Fetching headers for %s..." name)
4731     (prog1
4732         (if (eq 'nov
4733                 (setq gnus-headers-retrieved-by
4734                       (gnus-retrieve-headers
4735                        articles gnus-newsgroup-name
4736                        ;; We might want to fetch old headers, but
4737                        ;; not if there is only 1 article.
4738                        (and (or (and
4739                                  (not (eq gnus-fetch-old-headers 'some))
4740                                  (not (numberp gnus-fetch-old-headers)))
4741                                 (> (length articles) 1))
4742                             gnus-fetch-old-headers))))
4743             (gnus-get-newsgroup-headers-xover
4744              articles nil nil gnus-newsgroup-name t)
4745           (gnus-get-newsgroup-headers))
4746       (gnus-message 5 "Fetching headers for %s...done" name))))
4747
4748 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4749   "Select newsgroup GROUP.
4750 If READ-ALL is non-nil, all articles in the group are selected.
4751 If SELECT-ARTICLES, only select those articles from GROUP."
4752   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4753          ;;!!! Dirty hack; should be removed.
4754          (gnus-summary-ignore-duplicates
4755           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4756               t
4757             gnus-summary-ignore-duplicates))
4758          (info (nth 2 entry))
4759          articles fetched-articles cached)
4760
4761     (unless (gnus-check-server
4762              (set (make-local-variable 'gnus-current-select-method)
4763                   (gnus-find-method-for-group group)))
4764       (error "Couldn't open server"))
4765
4766     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4767         (gnus-activate-group group)     ; Or we can activate it...
4768         (progn                          ; Or we bug out.
4769           (when (equal major-mode 'gnus-summary-mode)
4770             (kill-buffer (current-buffer)))
4771           (error "Couldn't activate group %s: %s"
4772                  group (gnus-status-message group))))
4773
4774     (unless (gnus-request-group group t)
4775       (when (equal major-mode 'gnus-summary-mode)
4776         (kill-buffer (current-buffer)))
4777       (error "Couldn't request group %s: %s"
4778              group (gnus-status-message group)))
4779
4780     (setq gnus-newsgroup-name group
4781           gnus-newsgroup-unselected nil
4782           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4783
4784     (let ((display (gnus-group-find-parameter group 'display)))
4785       (setq gnus-newsgroup-display
4786             (cond
4787              ((not (zerop (or (car-safe read-all) 0)))
4788               ;; The user entered the group with C-u SPC/RET, let's show
4789               ;; all articles.
4790               'gnus-not-ignore)
4791              ((eq display 'all)
4792               'gnus-not-ignore)
4793              ((arrayp display)
4794               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4795              ((numberp display)
4796               ;; The following is probably the "correct" solution, but
4797               ;; it makes Gnus fetch all headers and then limit the
4798               ;; articles (which is slow), so instead we hack the
4799               ;; select-articles parameter instead. -- Simon Josefsson
4800               ;; <jas@kth.se>
4801               ;;
4802               ;; (gnus-byte-compile
4803               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4804               ;;                         display)))))
4805               (setq select-articles
4806                     (gnus-uncompress-range
4807                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4808                              (if (> tmp 0)
4809                                  tmp
4810                                1))
4811                            (cdr (gnus-active group)))))
4812               nil)
4813              (t
4814               nil))))
4815
4816     (gnus-summary-setup-default-charset)
4817
4818     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4819     (when (gnus-virtual-group-p group)
4820       (setq cached gnus-newsgroup-cached))
4821
4822     (setq gnus-newsgroup-unreads
4823           (gnus-sorted-ndifference
4824            (gnus-sorted-ndifference gnus-newsgroup-unreads
4825                                     gnus-newsgroup-marked)
4826            gnus-newsgroup-dormant))
4827
4828     (setq gnus-newsgroup-processable nil)
4829
4830     (gnus-update-read-articles group gnus-newsgroup-unreads)
4831
4832     ;; Adjust and set lists of article marks.
4833     (when info
4834       (gnus-adjust-marked-articles info))
4835
4836     (if (setq articles select-articles)
4837         (setq gnus-newsgroup-unselected
4838               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4839       (setq articles (gnus-articles-to-read group read-all)))
4840
4841     (cond
4842      ((null articles)
4843       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4844       'quit)
4845      ((eq articles 0) nil)
4846      (t
4847       ;; Init the dependencies hash table.
4848       (setq gnus-newsgroup-dependencies
4849             (gnus-make-hashtable (length articles)))
4850       (gnus-set-global-variables)
4851       ;; Retrieve the headers and read them in.
4852       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4853
4854       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4855       (when cached
4856         (setq gnus-newsgroup-cached cached))
4857
4858       ;; Suppress duplicates?
4859       (when gnus-suppress-duplicates
4860         (gnus-dup-suppress-articles))
4861
4862       ;; Set the initial limit.
4863       (setq gnus-newsgroup-limit (copy-sequence articles))
4864       ;; Remove canceled articles from the list of unread articles.
4865       (setq fetched-articles
4866             (mapcar (lambda (headers) (mail-header-number headers))
4867                     gnus-newsgroup-headers))
4868       (setq gnus-newsgroup-articles fetched-articles)
4869       (setq gnus-newsgroup-unreads
4870             (gnus-sorted-nintersection
4871              gnus-newsgroup-unreads fetched-articles))
4872       (gnus-compute-unseen-list)
4873
4874       ;; Removed marked articles that do not exist.
4875       (gnus-update-missing-marks
4876        (gnus-sorted-difference articles fetched-articles))
4877       ;; We might want to build some more threads first.
4878       (when (and gnus-fetch-old-headers
4879                  (eq gnus-headers-retrieved-by 'nov))
4880         (if (eq gnus-fetch-old-headers 'invisible)
4881             (gnus-build-all-threads)
4882           (gnus-build-old-threads)))
4883       ;; Let the Gnus agent mark articles as read.
4884       (when gnus-agent
4885         (gnus-agent-get-undownloaded-list))
4886       ;; Remove list identifiers from subject
4887       (when gnus-list-identifiers
4888         (gnus-summary-remove-list-identifiers))
4889       ;; Check whether auto-expire is to be done in this group.
4890       (setq gnus-newsgroup-auto-expire
4891             (gnus-group-auto-expirable-p group))
4892       ;; Set up the article buffer now, if necessary.
4893       (unless gnus-single-article-buffer
4894         (gnus-article-setup-buffer))
4895       ;; First and last article in this newsgroup.
4896       (when gnus-newsgroup-headers
4897         (setq gnus-newsgroup-begin
4898               (mail-header-number (car gnus-newsgroup-headers))
4899               gnus-newsgroup-end
4900               (mail-header-number
4901                (gnus-last-element gnus-newsgroup-headers))))
4902       ;; GROUP is successfully selected.
4903       (or gnus-newsgroup-headers t)))))
4904
4905 (defun gnus-compute-unseen-list ()
4906   ;; The `seen' marks are treated specially.
4907   (if (not gnus-newsgroup-seen)
4908       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4909     (setq gnus-newsgroup-unseen
4910           (gnus-inverse-list-range-intersection
4911            gnus-newsgroup-articles gnus-newsgroup-seen))))
4912
4913 (defun gnus-summary-display-make-predicate (display)
4914   (require 'gnus-agent)
4915   (when (= (length display) 1)
4916     (setq display (car display)))
4917   (unless gnus-summary-display-cache
4918     (dolist (elem (append '((unread . unread)
4919                             (read . read)
4920                             (unseen . unseen))
4921                           gnus-article-mark-lists))
4922       (push (cons (cdr elem)
4923                   (gnus-byte-compile
4924                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4925             gnus-summary-display-cache)))
4926   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4927         (gnus-category-predicate-cache gnus-summary-display-cache))
4928     (gnus-get-predicate display)))
4929
4930 ;; Uses the dynamically bound `number' variable.
4931 (defvar number)
4932 (defun gnus-article-marked-p (type &optional article)
4933   (let ((article (or article number)))
4934     (cond
4935      ((eq type 'tick)
4936       (memq article gnus-newsgroup-marked))
4937      ((eq type 'unsend)
4938       (memq article gnus-newsgroup-unsendable))
4939      ((eq type 'undownload)
4940       (memq article gnus-newsgroup-undownloaded))
4941      ((eq type 'download)
4942       (memq article gnus-newsgroup-downloadable))
4943      ((eq type 'unread)
4944       (memq article gnus-newsgroup-unreads))
4945      ((eq type 'read)
4946       (memq article gnus-newsgroup-reads))
4947      ((eq type 'dormant)
4948       (memq article gnus-newsgroup-dormant) )
4949      ((eq type 'expire)
4950       (memq article gnus-newsgroup-expirable))
4951      ((eq type 'reply)
4952       (memq article gnus-newsgroup-replied))
4953      ((eq type 'killed)
4954       (memq article gnus-newsgroup-killed))
4955      ((eq type 'bookmark)
4956       (assq article gnus-newsgroup-bookmarks))
4957      ((eq type 'score)
4958       (assq article gnus-newsgroup-scored))
4959      ((eq type 'save)
4960       (memq article gnus-newsgroup-saved))
4961      ((eq type 'cache)
4962       (memq article gnus-newsgroup-cached))
4963      ((eq type 'forward)
4964       (memq article gnus-newsgroup-forwarded))
4965      ((eq type 'seen)
4966       (not (memq article gnus-newsgroup-unseen)))
4967      ((eq type 'recent)
4968       (memq article gnus-newsgroup-recent))
4969      (t t))))
4970
4971 (defun gnus-articles-to-read (group &optional read-all)
4972   "Find out what articles the user wants to read."
4973   (let* ((articles
4974           ;; Select all articles if `read-all' is non-nil, or if there
4975           ;; are no unread articles.
4976           (if (or read-all
4977                   (and (zerop (length gnus-newsgroup-marked))
4978                        (zerop (length gnus-newsgroup-unreads)))
4979                   ;; Fetch all if the predicate is non-nil.
4980                   gnus-newsgroup-display)
4981               ;; We want to select the headers for all the articles in
4982               ;; the group, so we select either all the active
4983               ;; articles in the group, or (if that's nil), the
4984               ;; articles in the cache.
4985               (or
4986                (gnus-uncompress-range (gnus-active group))
4987                (gnus-cache-articles-in-group group))
4988             ;; Select only the "normal" subset of articles.
4989             (gnus-sorted-nunion
4990              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4991              gnus-newsgroup-unreads)))
4992          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4993          (scored (length scored-list))
4994          (number (length articles))
4995          (marked (+ (length gnus-newsgroup-marked)
4996                     (length gnus-newsgroup-dormant)))
4997          (select
4998           (cond
4999            ((numberp read-all)
5000             read-all)
5001            ((numberp gnus-newsgroup-display)
5002             gnus-newsgroup-display)
5003            (t
5004             (condition-case ()
5005                 (cond
5006                  ((and (or (<= scored marked) (= scored number))
5007                        (numberp gnus-large-newsgroup)
5008                        (> number gnus-large-newsgroup))
5009                   (let* ((cursor-in-echo-area nil)
5010                          (initial (gnus-parameter-large-newsgroup-initial
5011                                    gnus-newsgroup-name))
5012                          (input
5013                           (read-string
5014                            (format
5015                             "How many articles from %s (%s %d): "
5016                             (gnus-limit-string
5017                              (gnus-group-decoded-name gnus-newsgroup-name)
5018                              35)
5019                             (if initial "max" "default")
5020                             number)
5021                            (if initial
5022                                (cons (number-to-string initial)
5023                                      0)))))
5024                     (if (string-match "^[ \t]*$" input) number input)))
5025                  ((and (> scored marked) (< scored number)
5026                        (> (- scored number) 20))
5027                   (let ((input
5028                          (read-string
5029                           (format "%s %s (%d scored, %d total): "
5030                                   "How many articles from"
5031                                   (gnus-group-decoded-name group)
5032                                   scored number))))
5033                     (if (string-match "^[ \t]*$" input)
5034                         number input)))
5035                  (t number))
5036               (quit
5037                (message "Quit getting the articles to read")
5038                nil))))))
5039     (setq select (if (stringp select) (string-to-number select) select))
5040     (if (or (null select) (zerop select))
5041         select
5042       (if (and (not (zerop scored)) (<= (abs select) scored))
5043           (progn
5044             (setq articles (sort scored-list '<))
5045             (setq number (length articles)))
5046         (setq articles (copy-sequence articles)))
5047
5048       (when (< (abs select) number)
5049         (if (< select 0)
5050             ;; Select the N oldest articles.
5051             (setcdr (nthcdr (1- (abs select)) articles) nil)
5052           ;; Select the N most recent articles.
5053           (setq articles (nthcdr (- number select) articles))))
5054       (setq gnus-newsgroup-unselected
5055             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5056       (when gnus-alter-articles-to-read-function
5057         (setq gnus-newsgroup-unreads
5058               (sort
5059                (funcall gnus-alter-articles-to-read-function
5060                         gnus-newsgroup-name gnus-newsgroup-unreads)
5061                '<)))
5062       articles)))
5063
5064 (defun gnus-killed-articles (killed articles)
5065   (let (out)
5066     (while articles
5067       (when (inline (gnus-member-of-range (car articles) killed))
5068         (push (car articles) out))
5069       (setq articles (cdr articles)))
5070     out))
5071
5072 (defun gnus-uncompress-marks (marks)
5073   "Uncompress the mark ranges in MARKS."
5074   (let ((uncompressed '(score bookmark))
5075         out)
5076     (while marks
5077       (if (memq (caar marks) uncompressed)
5078           (push (car marks) out)
5079         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5080       (setq marks (cdr marks)))
5081     out))
5082
5083 (defun gnus-article-mark-to-type (mark)
5084   "Return the type of MARK."
5085   (or (cadr (assq mark gnus-article-special-mark-lists))
5086       'list))
5087
5088 (defun gnus-article-unpropagatable-p (mark)
5089   "Return whether MARK should be propagated to backend."
5090   (memq mark gnus-article-unpropagated-mark-lists))
5091
5092 (defun gnus-adjust-marked-articles (info)
5093   "Set all article lists and remove all marks that are no longer valid."
5094   (let* ((marked-lists (gnus-info-marks info))
5095          (active (gnus-active (gnus-info-group info)))
5096          (min (car active))
5097          (max (cdr active))
5098          (types gnus-article-mark-lists)
5099          marks var articles article mark mark-type)
5100
5101     (dolist (marks marked-lists)
5102       (setq mark (car marks)
5103             mark-type (gnus-article-mark-to-type mark)
5104             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5105
5106       ;; We set the variable according to the type of the marks list,
5107       ;; and then adjust the marks to a subset of the active articles.
5108       (cond
5109        ;; Adjust "simple" lists.
5110        ((eq mark-type 'list)
5111         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5112         (when (memq mark '(tick dormant expire reply save))
5113           (while articles
5114             (when (or (< (setq article (pop articles)) min) (> article max))
5115               (set var (delq article (symbol-value var)))))))
5116        ;; Adjust assocs.
5117        ((eq mark-type 'tuple)
5118         (set var (setq articles (cdr marks)))
5119         (when (not (listp (cdr (symbol-value var))))
5120           (set var (list (symbol-value var))))
5121         (when (not (listp (cdr articles)))
5122           (setq articles (list articles)))
5123         (while articles
5124           (when (or (not (consp (setq article (pop articles))))
5125                     (< (car article) min)
5126                     (> (car article) max))
5127             (set var (delq article (symbol-value var))))))
5128        ;; Adjust ranges (sloppily).
5129        ((eq mark-type 'range)
5130         (cond
5131          ((eq mark 'seen)
5132           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5133           ;; It should be (seen (NUM1 . NUM2)).
5134           (when (numberp (cddr marks))
5135             (setcdr marks (list (cdr marks))))
5136           (setq articles (cdr marks))
5137           (while (and articles
5138                       (or (and (consp (car articles))
5139                                (> min (cdar articles)))
5140                           (and (numberp (car articles))
5141                                (> min (car articles)))))
5142             (pop articles))
5143           (set var articles))))))))
5144
5145 (defun gnus-update-missing-marks (missing)
5146   "Go through the list of MISSING articles and remove them from the mark lists."
5147   (when missing
5148     (let (var m)
5149       ;; Go through all types.
5150       (dolist (elem gnus-article-mark-lists)
5151         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5152           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5153           (when (symbol-value var)
5154             ;; This list has articles.  So we delete all missing
5155             ;; articles from it.
5156             (setq m missing)
5157             (while m
5158               (set var (delq (pop m) (symbol-value var))))))))))
5159
5160 (defun gnus-update-marks ()
5161   "Enter the various lists of marked articles into the newsgroup info list."
5162   (let ((types gnus-article-mark-lists)
5163         (info (gnus-get-info gnus-newsgroup-name))
5164         type list newmarked symbol delta-marks)
5165     (when info
5166       ;; Add all marks lists to the list of marks lists.
5167       (while (setq type (pop types))
5168         (setq list (symbol-value
5169                     (setq symbol
5170                           (intern (format "gnus-newsgroup-%s" (car type))))))
5171
5172         (when list
5173           ;; Get rid of the entries of the articles that have the
5174           ;; default score.
5175           (when (and (eq (cdr type) 'score)
5176                      gnus-save-score
5177                      list)
5178             (let* ((arts list)
5179                    (prev (cons nil list))
5180                    (all prev))
5181               (while arts
5182                 (if (or (not (consp (car arts)))
5183                         (= (cdar arts) gnus-summary-default-score))
5184                     (setcdr prev (cdr arts))
5185                   (setq prev arts))
5186                 (setq arts (cdr arts)))
5187               (setq list (cdr all)))))
5188
5189         (when (eq (cdr type) 'seen)
5190           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5191
5192         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5193           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5194
5195         (when (and (gnus-check-backend-function
5196                     'request-set-mark gnus-newsgroup-name)
5197                    (not (gnus-article-unpropagatable-p (cdr type))))
5198           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5199                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5200                  (add (gnus-remove-from-range
5201                        (gnus-copy-sequence list) old)))
5202             (when add
5203               (push (list add 'add (list (cdr type))) delta-marks))
5204             (when del
5205               (push (list del 'del (list (cdr type))) delta-marks))))
5206
5207         (when list
5208           (push (cons (cdr type) list) newmarked)))
5209
5210       (when delta-marks
5211         (unless (gnus-check-group gnus-newsgroup-name)
5212           (error "Can't open server for %s" gnus-newsgroup-name))
5213         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5214
5215       ;; Enter these new marks into the info of the group.
5216       (if (nthcdr 3 info)
5217           (setcar (nthcdr 3 info) newmarked)
5218         ;; Add the marks lists to the end of the info.
5219         (when newmarked
5220           (setcdr (nthcdr 2 info) (list newmarked))))
5221
5222       ;; Cut off the end of the info if there's nothing else there.
5223       (let ((i 5))
5224         (while (and (> i 2)
5225                     (not (nth i info)))
5226           (when (nthcdr (decf i) info)
5227             (setcdr (nthcdr i info) nil)))))))
5228
5229 (defun gnus-set-mode-line (where)
5230   "Set the mode line of the article or summary buffers.
5231 If WHERE is `summary', the summary mode line format will be used."
5232   ;; Is this mode line one we keep updated?
5233   (when (and (memq where gnus-updated-mode-lines)
5234              (symbol-value
5235               (intern (format "gnus-%s-mode-line-format-spec" where))))
5236     (let (mode-string)
5237       (save-excursion
5238         ;; We evaluate this in the summary buffer since these
5239         ;; variables are buffer-local to that buffer.
5240         (set-buffer gnus-summary-buffer)
5241         ;; We bind all these variables that are used in the `eval' form
5242         ;; below.
5243         (let* ((mformat (symbol-value
5244                          (intern
5245                           (format "gnus-%s-mode-line-format-spec" where))))
5246                (gnus-tmp-group-name (gnus-group-decoded-name
5247                                      gnus-newsgroup-name))
5248                (gnus-tmp-article-number (or gnus-current-article 0))
5249                (gnus-tmp-unread gnus-newsgroup-unreads)
5250                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5251                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5252                (gnus-tmp-unread-and-unselected
5253                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5254                             (zerop gnus-tmp-unselected))
5255                        "")
5256                       ((zerop gnus-tmp-unselected)
5257                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5258                       (t (format "{%d(+%d) more}"
5259                                  gnus-tmp-unread-and-unticked
5260                                  gnus-tmp-unselected))))
5261                (gnus-tmp-subject
5262                 (if (and gnus-current-headers
5263                          (vectorp gnus-current-headers))
5264                     (gnus-mode-string-quote
5265                      (mail-header-subject gnus-current-headers))
5266                   ""))
5267                bufname-length max-len
5268                gnus-tmp-header);; passed as argument to any user-format-funcs
5269           (setq mode-string (eval mformat))
5270           (setq bufname-length (if (string-match "%b" mode-string)
5271                                    (- (length
5272                                        (buffer-name
5273                                         (if (eq where 'summary)
5274                                             nil
5275                                           (get-buffer gnus-article-buffer))))
5276                                       2)
5277                                  0))
5278           (setq max-len (max 4 (if gnus-mode-non-string-length
5279                                    (- (window-width)
5280                                       gnus-mode-non-string-length
5281                                       bufname-length)
5282                                  (length mode-string))))
5283           ;; We might have to chop a bit of the string off...
5284           (when (> (length mode-string) max-len)
5285             (setq mode-string
5286                   (concat (gnus-truncate-string mode-string (- max-len 3))
5287                           "...")))
5288           ;; Pad the mode string a bit.
5289           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5290       ;; Update the mode line.
5291       (setq mode-line-buffer-identification
5292             (gnus-mode-line-buffer-identification (list mode-string)))
5293       (set-buffer-modified-p t))))
5294
5295 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5296   "Go through the HEADERS list and add all Xrefs to a hash table.
5297 The resulting hash table is returned, or nil if no Xrefs were found."
5298   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5299          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5300          (xref-hashtb (gnus-make-hashtable))
5301          start group entry number xrefs header)
5302     (while headers
5303       (setq header (pop headers))
5304       (when (and (setq xrefs (mail-header-xref header))
5305                  (not (memq (setq number (mail-header-number header))
5306                             unreads)))
5307         (setq start 0)
5308         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5309           (setq start (match-end 0))
5310           (setq group (if prefix
5311                           (concat prefix (substring xrefs (match-beginning 1)
5312                                                     (match-end 1)))
5313                         (substring xrefs (match-beginning 1) (match-end 1))))
5314           (setq number
5315                 (string-to-int (substring xrefs (match-beginning 2)
5316                                           (match-end 2))))
5317           (if (setq entry (gnus-gethash group xref-hashtb))
5318               (setcdr entry (cons number (cdr entry)))
5319             (gnus-sethash group (cons number nil) xref-hashtb)))))
5320     (and start xref-hashtb)))
5321
5322 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5323   "Look through all the headers and mark the Xrefs as read."
5324   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5325         name entry info xref-hashtb idlist method nth4)
5326     (save-excursion
5327       (set-buffer gnus-group-buffer)
5328       (when (setq xref-hashtb
5329                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5330         (mapatoms
5331          (lambda (group)
5332            (unless (string= from-newsgroup (setq name (symbol-name group)))
5333              (setq idlist (symbol-value group))
5334              ;; Dead groups are not updated.
5335              (and (prog1
5336                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5337                             info (nth 2 entry))
5338                     (when (stringp (setq nth4 (gnus-info-method info)))
5339                       (setq nth4 (gnus-server-to-method nth4))))
5340                   ;; Only do the xrefs if the group has the same
5341                   ;; select method as the group we have just read.
5342                   (or (gnus-methods-equal-p
5343                        nth4 (gnus-find-method-for-group from-newsgroup))
5344                       virtual
5345                       (equal nth4 (setq method (gnus-find-method-for-group
5346                                                 from-newsgroup)))
5347                       (and (equal (car nth4) (car method))
5348                            (equal (nth 1 nth4) (nth 1 method))))
5349                   gnus-use-cross-reference
5350                   (or (not (eq gnus-use-cross-reference t))
5351                       virtual
5352                       ;; Only do cross-references on subscribed
5353                       ;; groups, if that is what is wanted.
5354                       (<= (gnus-info-level info) gnus-level-subscribed))
5355                   (gnus-group-make-articles-read name idlist))))
5356          xref-hashtb)))))
5357
5358 (defun gnus-compute-read-articles (group articles)
5359   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5360          (info (nth 2 entry))
5361          (active (gnus-active group))
5362          ninfo)
5363     (when entry
5364       ;; First peel off all invalid article numbers.
5365       (when active
5366         (let ((ids articles)
5367               id first)
5368           (while (setq id (pop ids))
5369             (when (and first (> id (cdr active)))
5370               ;; We'll end up in this situation in one particular
5371               ;; obscure situation.  If you re-scan a group and get
5372               ;; a new article that is cross-posted to a different
5373               ;; group that has not been re-scanned, you might get
5374               ;; crossposted article that has a higher number than
5375               ;; Gnus believes possible.  So we re-activate this
5376               ;; group as well.  This might mean doing the
5377               ;; crossposting thingy will *increase* the number
5378               ;; of articles in some groups.  Tsk, tsk.
5379               (setq active (or (gnus-activate-group group) active)))
5380             (when (or (> id (cdr active))
5381                       (< id (car active)))
5382               (setq articles (delq id articles))))))
5383       ;; If the read list is nil, we init it.
5384       (if (and active
5385                (null (gnus-info-read info))
5386                (> (car active) 1))
5387           (setq ninfo (cons 1 (1- (car active))))
5388         (setq ninfo (gnus-info-read info)))
5389       ;; Then we add the read articles to the range.
5390       (gnus-add-to-range
5391        ninfo (setq articles (sort articles '<))))))
5392
5393 (defun gnus-group-make-articles-read (group articles)
5394   "Update the info of GROUP to say that ARTICLES are read."
5395   (let* ((num 0)
5396          (entry (gnus-gethash group gnus-newsrc-hashtb))
5397          (info (nth 2 entry))
5398          (active (gnus-active group))
5399          range)
5400     (when entry
5401       (setq range (gnus-compute-read-articles group articles))
5402       (save-excursion
5403         (set-buffer gnus-group-buffer)
5404         (gnus-undo-register
5405           `(progn
5406              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5407              (gnus-info-set-read ',info ',(gnus-info-read info))
5408              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5409              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5410              (gnus-group-update-group ,group t))))
5411       ;; Add the read articles to the range.
5412       (gnus-info-set-read info range)
5413       (gnus-request-set-mark group (list (list range 'add '(read))))
5414       ;; Then we have to re-compute how many unread
5415       ;; articles there are in this group.
5416       (when active
5417         (cond
5418          ((not range)
5419           (setq num (- (1+ (cdr active)) (car active))))
5420          ((not (listp (cdr range)))
5421           (setq num (- (cdr active) (- (1+ (cdr range))
5422                                        (car range)))))
5423          (t
5424           (while range
5425             (if (numberp (car range))
5426                 (setq num (1+ num))
5427               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5428             (setq range (cdr range)))
5429           (setq num (- (cdr active) num))))
5430         ;; Update the number of unread articles.
5431         (setcar entry num)
5432         ;; Update the group buffer.
5433         (gnus-group-update-group group t)))))
5434
5435 (defvar gnus-newsgroup-none-id 0)
5436
5437 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5438   (let ((cur nntp-server-buffer)
5439         (dependencies
5440          (or dependencies
5441              (save-excursion (set-buffer gnus-summary-buffer)
5442                              gnus-newsgroup-dependencies)))
5443         headers id end ref
5444         (mail-parse-charset gnus-newsgroup-charset)
5445         (mail-parse-ignored-charsets
5446          (save-excursion (condition-case nil
5447                              (set-buffer gnus-summary-buffer)
5448                            (error))
5449                          gnus-newsgroup-ignored-charsets)))
5450     (save-excursion
5451       (set-buffer nntp-server-buffer)
5452       ;; Translate all TAB characters into SPACE characters.
5453       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5454       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5455       (gnus-run-hooks 'gnus-parse-headers-hook)
5456       (let ((case-fold-search t)
5457             in-reply-to header p lines chars ctype)
5458         (goto-char (point-min))
5459         ;; Search to the beginning of the next header.  Error messages
5460         ;; do not begin with 2 or 3.
5461         (while (re-search-forward "^[23][0-9]+ " nil t)
5462           (setq id nil
5463                 ref nil)
5464           ;; This implementation of this function, with nine
5465           ;; search-forwards instead of the one re-search-forward and
5466           ;; a case (which basically was the old function) is actually
5467           ;; about twice as fast, even though it looks messier.  You
5468           ;; can't have everything, I guess.  Speed and elegance
5469           ;; doesn't always go hand in hand.
5470           (setq
5471            header
5472            (make-full-mail-header
5473             ;; Number.
5474             (prog1
5475                 (read cur)
5476               (end-of-line)
5477               (setq p (point))
5478               (narrow-to-region (point)
5479                                 (or (and (search-forward "\n.\n" nil t)
5480                                          (- (point) 2))
5481                                     (point))))
5482             ;; Subject.
5483             (progn
5484               (goto-char p)
5485               (if (search-forward "\nsubject:" nil t)
5486                   (nnheader-header-value)
5487                 "(none)"))
5488             ;; From.
5489             (progn
5490               (goto-char p)
5491               (if (search-forward "\nfrom:" nil t)
5492                   (nnheader-header-value)
5493                 "(nobody)"))
5494             ;; Date.
5495             (progn
5496               (goto-char p)
5497               (if (search-forward "\ndate:" nil t)
5498                   (nnheader-header-value) ""))
5499             ;; Message-ID.
5500             (progn
5501               (goto-char p)
5502               (setq id (if (re-search-forward
5503                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5504                            ;; We do it this way to make sure the Message-ID
5505                            ;; is (somewhat) syntactically valid.
5506                            (buffer-substring (match-beginning 1)
5507                                              (match-end 1))
5508                          ;; If there was no message-id, we just fake one
5509                          ;; to make subsequent routines simpler.
5510                          (nnheader-generate-fake-message-id))))
5511             ;; References.
5512             (progn
5513               (goto-char p)
5514               (if (search-forward "\nreferences:" nil t)
5515                   (progn
5516                     (setq end (point))
5517                     (prog1
5518                         (nnheader-header-value)
5519                       (setq ref
5520                             (buffer-substring
5521                              (progn
5522                                ;; (end-of-line)
5523                                (search-backward ">" end t)
5524                                (1+ (point)))
5525                              (progn
5526                                (search-backward "<" end t)
5527                                (point))))))
5528                 ;; Get the references from the in-reply-to header if there
5529                 ;; were no references and the in-reply-to header looks
5530                 ;; promising.
5531                 (if (and (search-forward "\nin-reply-to:" nil t)
5532                          (setq in-reply-to (nnheader-header-value))
5533                          (string-match "<[^>]+>" in-reply-to))
5534                     (let (ref2)
5535                       (setq ref (substring in-reply-to (match-beginning 0)
5536                                            (match-end 0)))
5537                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5538                         (setq ref2 (substring in-reply-to (match-beginning 0)
5539                                               (match-end 0)))
5540                         (when (> (length ref2) (length ref))
5541                           (setq ref ref2)))
5542                       ref)
5543                   (setq ref nil))))
5544             ;; Chars.
5545             (progn
5546               (goto-char p)
5547               (if (search-forward "\nchars: " nil t)
5548                   (if (numberp (setq chars (ignore-errors (read cur))))
5549                       chars -1)
5550                 -1))
5551             ;; Lines.
5552             (progn
5553               (goto-char p)
5554               (if (search-forward "\nlines: " nil t)
5555                   (if (numberp (setq lines (ignore-errors (read cur))))
5556                       lines -1)
5557                 -1))
5558             ;; Xref.
5559             (progn
5560               (goto-char p)
5561               (and (search-forward "\nxref:" nil t)
5562                    (nnheader-header-value)))
5563             ;; Extra.
5564             (when gnus-extra-headers
5565               (let ((extra gnus-extra-headers)
5566                     out)
5567                 (while extra
5568                   (goto-char p)
5569                   (when (search-forward
5570                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5571                     (push (cons (car extra) (nnheader-header-value)) out))
5572                   (pop extra))
5573                 out))))
5574           (goto-char p)
5575           (if (and (search-forward "\ncontent-type: " nil t)
5576                    (setq ctype (nnheader-header-value)))
5577               (mime-entity-set-content-type-internal
5578                header (mime-parse-Content-Type ctype)))
5579           (when (equal id ref)
5580             (setq ref nil))
5581
5582           (when gnus-alter-header-function
5583             (funcall gnus-alter-header-function header)
5584             (setq id (mail-header-id header)
5585                   ref (gnus-parent-id (mail-header-references header))))
5586
5587           (when (setq header
5588                       (gnus-dependencies-add-header
5589                        header dependencies force-new))
5590             (push header headers))
5591           (goto-char (point-max))
5592           (widen))
5593         (nreverse headers)))))
5594
5595 ;; Goes through the xover lines and returns a list of vectors
5596 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5597                                                   force-new dependencies
5598                                                   group also-fetch-heads)
5599   "Parse the news overview data in the server buffer.
5600 Return a list of headers that match SEQUENCE (see
5601 `nntp-retrieve-headers')."
5602   ;; Get the Xref when the users reads the articles since most/some
5603   ;; NNTP servers do not include Xrefs when using XOVER.
5604   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5605   (let ((mail-parse-charset gnus-newsgroup-charset)
5606         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5607         (cur nntp-server-buffer)
5608         (dependencies (or dependencies gnus-newsgroup-dependencies))
5609         (allp (cond
5610                ((eq gnus-read-all-available-headers t)
5611                 t)
5612                ((stringp gnus-read-all-available-headers)
5613                 (string-match gnus-read-all-available-headers group))
5614                (t
5615                 nil)))
5616         number headers header)
5617     (save-excursion
5618       (set-buffer nntp-server-buffer)
5619       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5620       ;; Allow the user to mangle the headers before parsing them.
5621       (gnus-run-hooks 'gnus-parse-headers-hook)
5622       (goto-char (point-min))
5623       (gnus-parse-without-error
5624         (while (and (or sequence allp)
5625                     (not (eobp)))
5626           (setq number (read cur))
5627           (when (not allp)
5628             (while (and sequence
5629                         (< (car sequence) number))
5630               (setq sequence (cdr sequence))))
5631           (when (and (or allp
5632                          (and sequence
5633                               (eq number (car sequence))))
5634                      (progn
5635                        (setq sequence (cdr sequence))
5636                        (setq header (inline
5637                                       (gnus-nov-parse-line
5638                                        number dependencies force-new)))))
5639             (push header headers))
5640           (forward-line 1)))
5641       ;; A common bug in inn is that if you have posted an article and
5642       ;; then retrieves the active file, it will answer correctly --
5643       ;; the new article is included.  However, a NOV entry for the
5644       ;; article may not have been generated yet, so this may fail.
5645       ;; We work around this problem by retrieving the last few
5646       ;; headers using HEAD.
5647       (if (or (not also-fetch-heads)
5648               (not sequence))
5649           ;; We (probably) got all the headers.
5650           (nreverse headers)
5651         (let ((gnus-nov-is-evil t))
5652           (nconc
5653            (nreverse headers)
5654            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5655              (gnus-get-newsgroup-headers))))))))
5656
5657 (defun gnus-article-get-xrefs ()
5658   "Fill in the Xref value in `gnus-current-headers', if necessary.
5659 This is meant to be called in `gnus-article-internal-prepare-hook'."
5660   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5661                                  gnus-current-headers)))
5662     (or (not gnus-use-cross-reference)
5663         (not headers)
5664         (and (mail-header-xref headers)
5665              (not (string= (mail-header-xref headers) "")))
5666         (let ((case-fold-search t)
5667               xref)
5668           (save-restriction
5669             (nnheader-narrow-to-headers)
5670             (goto-char (point-min))
5671             (when (or (and (not (eobp))
5672                            (eq (downcase (char-after)) ?x)
5673                            (looking-at "Xref:"))
5674                       (search-forward "\nXref:" nil t))
5675               (goto-char (1+ (match-end 0)))
5676               (setq xref (buffer-substring (point)
5677                                            (progn (end-of-line) (point))))
5678               (mail-header-set-xref headers xref)))))))
5679
5680 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5681   "Find article ID and insert the summary line for that article.
5682 OLD-HEADER can either be a header or a line number to insert
5683 the subject line on."
5684   (let* ((line (and (numberp old-header) old-header))
5685          (old-header (and (vectorp old-header) old-header))
5686          (header (cond ((and old-header use-old-header)
5687                         old-header)
5688                        ((and (numberp id)
5689                              (gnus-number-to-header id))
5690                         (gnus-number-to-header id))
5691                        (t
5692                         (gnus-read-header id))))
5693          (number (and (numberp id) id))
5694          d)
5695     (when header
5696       ;; Rebuild the thread that this article is part of and go to the
5697       ;; article we have fetched.
5698       (when (and (not gnus-show-threads)
5699                  old-header)
5700         (when (and number
5701                    (setq d (gnus-data-find (mail-header-number old-header))))
5702           (goto-char (gnus-data-pos d))
5703           (gnus-data-remove
5704            number
5705            (- (gnus-point-at-bol)
5706               (prog1
5707                   (1+ (gnus-point-at-eol))
5708                 (gnus-delete-line))))))
5709       (when old-header
5710         (mail-header-set-number header (mail-header-number old-header)))
5711       (setq gnus-newsgroup-sparse
5712             (delq (setq number (mail-header-number header))
5713                   gnus-newsgroup-sparse))
5714       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5715       (push number gnus-newsgroup-limit)
5716       (gnus-rebuild-thread (mail-header-id header) line)
5717       (gnus-summary-goto-subject number nil t))
5718     (when (and (numberp number)
5719                (> number 0))
5720       ;; We have to update the boundaries even if we can't fetch the
5721       ;; article if ID is a number -- so that the next `P' or `N'
5722       ;; command will fetch the previous (or next) article even
5723       ;; if the one we tried to fetch this time has been canceled.
5724       (when (> number gnus-newsgroup-end)
5725         (setq gnus-newsgroup-end number))
5726       (when (< number gnus-newsgroup-begin)
5727         (setq gnus-newsgroup-begin number))
5728       (setq gnus-newsgroup-unselected
5729             (delq number gnus-newsgroup-unselected)))
5730     ;; Report back a success?
5731     (and header (mail-header-number header))))
5732
5733 ;;; Process/prefix in the summary buffer
5734
5735 (defun gnus-summary-work-articles (n)
5736   "Return a list of articles to be worked upon.
5737 The prefix argument, the list of process marked articles, and the
5738 current article will be taken into consideration."
5739   (save-excursion
5740     (set-buffer gnus-summary-buffer)
5741     (cond
5742      (n
5743       ;; A numerical prefix has been given.
5744       (setq n (prefix-numeric-value n))
5745       (let ((backward (< n 0))
5746             (n (abs (prefix-numeric-value n)))
5747             articles article)
5748         (save-excursion
5749           (while
5750               (and (> n 0)
5751                    (push (setq article (gnus-summary-article-number))
5752                          articles)
5753                    (if backward
5754                        (gnus-summary-find-prev nil article)
5755                      (gnus-summary-find-next nil article)))
5756             (decf n)))
5757         (nreverse articles)))
5758      ((and (gnus-region-active-p) (mark))
5759       (message "region active")
5760       ;; Work on the region between point and mark.
5761       (let ((max (max (point) (mark)))
5762             articles article)
5763         (save-excursion
5764           (goto-char (min (point) (mark)))
5765           (while
5766               (and
5767                (push (setq article (gnus-summary-article-number)) articles)
5768                (gnus-summary-find-next nil article)
5769                (< (point) max)))
5770           (nreverse articles))))
5771      (gnus-newsgroup-processable
5772       ;; There are process-marked articles present.
5773       ;; Save current state.
5774       (gnus-summary-save-process-mark)
5775       ;; Return the list.
5776       (reverse gnus-newsgroup-processable))
5777      (t
5778       ;; Just return the current article.
5779       (list (gnus-summary-article-number))))))
5780
5781 (defmacro gnus-summary-iterate (arg &rest forms)
5782   "Iterate over the process/prefixed articles and do FORMS.
5783 ARG is the interactive prefix given to the command.  FORMS will be
5784 executed with point over the summary line of the articles."
5785   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5786     `(let ((,articles (gnus-summary-work-articles ,arg)))
5787        (while ,articles
5788          (gnus-summary-goto-subject (car ,articles))
5789          ,@forms
5790          (pop ,articles)))))
5791
5792 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5793 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5794
5795 (defun gnus-summary-save-process-mark ()
5796   "Push the current set of process marked articles on the stack."
5797   (interactive)
5798   (push (copy-sequence gnus-newsgroup-processable)
5799         gnus-newsgroup-process-stack))
5800
5801 (defun gnus-summary-kill-process-mark ()
5802   "Push the current set of process marked articles on the stack and unmark."
5803   (interactive)
5804   (gnus-summary-save-process-mark)
5805   (gnus-summary-unmark-all-processable))
5806
5807 (defun gnus-summary-yank-process-mark ()
5808   "Pop the last process mark state off the stack and restore it."
5809   (interactive)
5810   (unless gnus-newsgroup-process-stack
5811     (error "Empty mark stack"))
5812   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5813
5814 (defun gnus-summary-process-mark-set (set)
5815   "Make SET into the current process marked articles."
5816   (gnus-summary-unmark-all-processable)
5817   (while set
5818     (gnus-summary-set-process-mark (pop set))))
5819
5820 ;;; Searching and stuff
5821
5822 (defun gnus-summary-search-group (&optional backward use-level)
5823   "Search for next unread newsgroup.
5824 If optional argument BACKWARD is non-nil, search backward instead."
5825   (save-excursion
5826     (set-buffer gnus-group-buffer)
5827     (when (gnus-group-search-forward
5828            backward nil (if use-level (gnus-group-group-level) nil))
5829       (gnus-group-group-name))))
5830
5831 (defun gnus-summary-best-group (&optional exclude-group)
5832   "Find the name of the best unread group.
5833 If EXCLUDE-GROUP, do not go to this group."
5834   (save-excursion
5835     (set-buffer gnus-group-buffer)
5836     (save-excursion
5837       (gnus-group-best-unread-group exclude-group))))
5838
5839 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5840   (if backward (gnus-summary-find-prev)
5841     (let* ((dummy (gnus-summary-article-intangible-p))
5842            (article (or article (gnus-summary-article-number)))
5843            (arts (gnus-data-find-list article))
5844            result)
5845       (when (and (not dummy)
5846                  (or (not gnus-summary-check-current)
5847                      (not unread)
5848                      (not (gnus-data-unread-p (car arts)))))
5849         (setq arts (cdr arts)))
5850       (when (setq result
5851                   (if unread
5852                       (progn
5853                         (while arts
5854                           (when (or (and undownloaded
5855                                          (eq gnus-undownloaded-mark
5856                                              (gnus-data-mark (car arts))))
5857                                     (gnus-data-unread-p (car arts)))
5858                             (setq result (car arts)
5859                                   arts nil))
5860                           (setq arts (cdr arts)))
5861                         result)
5862                     (car arts)))
5863         (goto-char (gnus-data-pos result))
5864         (gnus-data-number result)))))
5865
5866 (defun gnus-summary-find-prev (&optional unread article)
5867   (let* ((eobp (eobp))
5868          (article (or article (gnus-summary-article-number)))
5869          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5870          result)
5871     (when (and (not eobp)
5872                (or (not gnus-summary-check-current)
5873                    (not unread)
5874                    (not (gnus-data-unread-p (car arts)))))
5875       (setq arts (cdr arts)))
5876     (when (setq result
5877                 (if unread
5878                     (progn
5879                       (while arts
5880                         (when (gnus-data-unread-p (car arts))
5881                           (setq result (car arts)
5882                                 arts nil))
5883                         (setq arts (cdr arts)))
5884                       result)
5885                   (car arts)))
5886       (goto-char (gnus-data-pos result))
5887       (gnus-data-number result))))
5888
5889 (defun gnus-summary-find-subject (subject &optional unread backward article)
5890   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5891          (article (or article (gnus-summary-article-number)))
5892          (articles (gnus-data-list backward))
5893          (arts (gnus-data-find-list article articles))
5894          result)
5895     (when (or (not gnus-summary-check-current)
5896               (not unread)
5897               (not (gnus-data-unread-p (car arts))))
5898       (setq arts (cdr arts)))
5899     (while arts
5900       (and (or (not unread)
5901                (gnus-data-unread-p (car arts)))
5902            (vectorp (gnus-data-header (car arts)))
5903            (gnus-subject-equal
5904             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5905            (setq result (car arts)
5906                  arts nil))
5907       (setq arts (cdr arts)))
5908     (and result
5909          (goto-char (gnus-data-pos result))
5910          (gnus-data-number result))))
5911
5912 (defun gnus-summary-search-forward (&optional unread subject backward)
5913   "Search forward for an article.
5914 If UNREAD, look for unread articles.  If SUBJECT, look for
5915 articles with that subject.  If BACKWARD, search backward instead."
5916   (cond (subject (gnus-summary-find-subject subject unread backward))
5917         (backward (gnus-summary-find-prev unread))
5918         (t (gnus-summary-find-next unread))))
5919
5920 (defun gnus-recenter (&optional n)
5921   "Center point in window and redisplay frame.
5922 Also do horizontal recentering."
5923   (interactive "P")
5924   (when (and gnus-auto-center-summary
5925              (not (eq gnus-auto-center-summary 'vertical)))
5926     (gnus-horizontal-recenter))
5927   (recenter n))
5928
5929 (defun gnus-summary-recenter ()
5930   "Center point in the summary window.
5931 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5932 displayed, no centering will be performed."
5933   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5934   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5935   (interactive)
5936   (let* ((top (cond ((< (window-height) 4) 0)
5937                     ((< (window-height) 7) 1)
5938                     (t (if (numberp gnus-auto-center-summary)
5939                            gnus-auto-center-summary
5940                          2))))
5941          (height (1- (window-height)))
5942          (bottom (save-excursion (goto-char (point-max))
5943                                  (forward-line (- height))
5944                                  (point)))
5945          (window (get-buffer-window (current-buffer))))
5946     ;; The user has to want it.
5947     (when gnus-auto-center-summary
5948       (when (get-buffer-window gnus-article-buffer)
5949         ;; Only do recentering when the article buffer is displayed,
5950         ;; Set the window start to either `bottom', which is the biggest
5951         ;; possible valid number, or the second line from the top,
5952         ;; whichever is the least.
5953         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5954           (if (> bottom top-pos)
5955               ;; Keep the second line from the top visible
5956               (set-window-start window top-pos t)
5957             ;; Try to keep the bottom line visible; if it's partially
5958             ;; obscured, either scroll one more line to make it fully
5959             ;; visible, or revert to using TOP-POS.
5960             (save-excursion
5961               (goto-char (point-max))
5962               (forward-line -1)
5963               (let ((last-line-start (point)))
5964                 (goto-char bottom)
5965                 (set-window-start window (point) t)
5966                 (when (not (pos-visible-in-window-p last-line-start window))
5967                   (forward-line 1)
5968                   (set-window-start window (min (point) top-pos) t)))))))
5969       ;; Do horizontal recentering while we're at it.
5970       (when (and (get-buffer-window (current-buffer) t)
5971                  (not (eq gnus-auto-center-summary 'vertical)))
5972         (let ((selected (selected-window)))
5973           (select-window (get-buffer-window (current-buffer) t))
5974           (gnus-summary-position-point)
5975           (gnus-horizontal-recenter)
5976           (select-window selected))))))
5977
5978 (defun gnus-summary-jump-to-group (newsgroup)
5979   "Move point to NEWSGROUP in group mode buffer."
5980   ;; Keep update point of group mode buffer if visible.
5981   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5982       (save-window-excursion
5983         ;; Take care of tree window mode.
5984         (when (get-buffer-window gnus-group-buffer)
5985           (pop-to-buffer gnus-group-buffer))
5986         (gnus-group-jump-to-group newsgroup))
5987     (save-excursion
5988       ;; Take care of tree window mode.
5989       (if (get-buffer-window gnus-group-buffer)
5990           (pop-to-buffer gnus-group-buffer)
5991         (set-buffer gnus-group-buffer))
5992       (gnus-group-jump-to-group newsgroup))))
5993
5994 ;; This function returns a list of article numbers based on the
5995 ;; difference between the ranges of read articles in this group and
5996 ;; the range of active articles.
5997 (defun gnus-list-of-unread-articles (group)
5998   (let* ((read (gnus-info-read (gnus-get-info group)))
5999          (active (or (gnus-active group) (gnus-activate-group group)))
6000          (last (cdr active))
6001          first nlast unread)
6002     ;; If none are read, then all are unread.
6003     (if (not read)
6004         (setq first (car active))
6005       ;; If the range of read articles is a single range, then the
6006       ;; first unread article is the article after the last read
6007       ;; article.  Sounds logical, doesn't it?
6008       (if (and (not (listp (cdr read)))
6009                (or (< (car read) (car active))
6010                    (progn (setq read (list read))
6011                           nil)))
6012           (setq first (max (car active) (1+ (cdr read))))
6013         ;; `read' is a list of ranges.
6014         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6015                                   (caar read)))
6016                   1)
6017           (setq first (car active)))
6018         (while read
6019           (when first
6020             (while (< first nlast)
6021               (push first unread)
6022               (setq first (1+ first))))
6023           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6024           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6025           (setq read (cdr read)))))
6026     ;; And add the last unread articles.
6027     (while (<= first last)
6028       (push first unread)
6029       (setq first (1+ first)))
6030     ;; Return the list of unread articles.
6031     (delq 0 (nreverse unread))))
6032
6033 (defun gnus-list-of-read-articles (group)
6034   "Return a list of unread, unticked and non-dormant articles."
6035   (let* ((info (gnus-get-info group))
6036          (marked (gnus-info-marks info))
6037          (active (gnus-active group)))
6038     (and info active
6039          (gnus-list-range-difference
6040           (gnus-list-range-difference
6041            (gnus-sorted-complement
6042             (gnus-uncompress-range active)
6043             (gnus-list-of-unread-articles group))
6044            (cdr (assq 'dormant marked)))
6045           (cdr (assq 'tick marked))))))
6046
6047 ;; Various summary commands
6048
6049 (defun gnus-summary-select-article-buffer ()
6050   "Reconfigure windows to show article buffer."
6051   (interactive)
6052   (if (not (gnus-buffer-live-p gnus-article-buffer))
6053       (error "There is no article buffer for this summary buffer")
6054     (gnus-configure-windows 'article)
6055     (select-window (get-buffer-window gnus-article-buffer))))
6056
6057 (defun gnus-summary-universal-argument (arg)
6058   "Perform any operation on all articles that are process/prefixed."
6059   (interactive "P")
6060   (let ((articles (gnus-summary-work-articles arg))
6061         func article)
6062     (if (eq
6063          (setq
6064           func
6065           (key-binding
6066            (read-key-sequence
6067             (substitute-command-keys
6068              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6069          'undefined)
6070         (gnus-error 1 "Undefined key")
6071       (save-excursion
6072         (while articles
6073           (gnus-summary-goto-subject (setq article (pop articles)))
6074           (let (gnus-newsgroup-processable)
6075             (command-execute func))
6076           (gnus-summary-remove-process-mark article)))))
6077   (gnus-summary-position-point))
6078
6079 (defun gnus-summary-toggle-truncation (&optional arg)
6080   "Toggle truncation of summary lines.
6081 With arg, turn line truncation on iff arg is positive."
6082   (interactive "P")
6083   (setq truncate-lines
6084         (if (null arg) (not truncate-lines)
6085           (> (prefix-numeric-value arg) 0)))
6086   (redraw-display))
6087
6088 (defun gnus-summary-reselect-current-group (&optional all rescan)
6089   "Exit and then reselect the current newsgroup.
6090 The prefix argument ALL means to select all articles."
6091   (interactive "P")
6092   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6093     (error "Ephemeral groups can't be reselected"))
6094   (let ((current-subject (gnus-summary-article-number))
6095         (group gnus-newsgroup-name))
6096     (setq gnus-newsgroup-begin nil)
6097     (gnus-summary-exit)
6098     ;; We have to adjust the point of group mode buffer because
6099     ;; point was moved to the next unread newsgroup by exiting.
6100     (gnus-summary-jump-to-group group)
6101     (when rescan
6102       (save-excursion
6103         (save-window-excursion
6104           ;; Don't show group contents.
6105           (set-window-start (selected-window) (point-max))
6106           (gnus-group-get-new-news-this-group 1))))
6107     (gnus-group-read-group all t)
6108     (gnus-summary-goto-subject current-subject nil t)))
6109
6110 (defun gnus-summary-rescan-group (&optional all)
6111   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6112   (interactive "P")
6113   (gnus-summary-reselect-current-group all t))
6114
6115 (defun gnus-summary-update-info (&optional non-destructive)
6116   (save-excursion
6117     (let ((group gnus-newsgroup-name))
6118       (when group
6119         (when gnus-newsgroup-kill-headers
6120           (setq gnus-newsgroup-killed
6121                 (gnus-compress-sequence
6122                  (gnus-sorted-union
6123                   (gnus-list-range-intersection
6124                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6125                   gnus-newsgroup-unreads)
6126                  t)))
6127         (unless (listp (cdr gnus-newsgroup-killed))
6128           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6129         (let ((headers gnus-newsgroup-headers))
6130           ;; Set the new ranges of read articles.
6131           (save-excursion
6132             (set-buffer gnus-group-buffer)
6133             (gnus-undo-force-boundary))
6134           (gnus-update-read-articles
6135            group (gnus-sorted-union
6136                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6137           ;; Set the current article marks.
6138           (let ((gnus-newsgroup-scored
6139                  (if (and (not gnus-save-score)
6140                           (not non-destructive))
6141                      nil
6142                    gnus-newsgroup-scored)))
6143             (save-excursion
6144               (gnus-update-marks)))
6145           ;; Do the cross-ref thing.
6146           (when gnus-use-cross-reference
6147             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6148           ;; Do not switch windows but change the buffer to work.
6149           (set-buffer gnus-group-buffer)
6150           (unless (gnus-ephemeral-group-p group)
6151             (gnus-group-update-group group)))))))
6152
6153 (defun gnus-summary-save-newsrc (&optional force)
6154   "Save the current number of read/marked articles in the dribble buffer.
6155 The dribble buffer will then be saved.
6156 If FORCE (the prefix), also save the .newsrc file(s)."
6157   (interactive "P")
6158   (gnus-summary-update-info t)
6159   (if force
6160       (gnus-save-newsrc-file)
6161     (gnus-dribble-save)))
6162
6163 (defun gnus-summary-exit (&optional temporary)
6164   "Exit reading current newsgroup, and then return to group selection mode.
6165 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6166   (interactive)
6167   (gnus-set-global-variables)
6168   (gnus-kill-save-kill-buffer)
6169   (gnus-async-halt-prefetch)
6170   (let* ((group gnus-newsgroup-name)
6171          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6172          (mode major-mode)
6173          (group-point nil)
6174          (buf (current-buffer)))
6175     (unless quit-config
6176       ;; Do adaptive scoring, and possibly save score files.
6177       (when gnus-newsgroup-adaptive
6178         (gnus-score-adaptive))
6179       (when gnus-use-scoring
6180         (gnus-score-save)))
6181     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6182     ;; If we have several article buffers, we kill them at exit.
6183     (unless gnus-single-article-buffer
6184       (gnus-kill-buffer gnus-original-article-buffer)
6185       (setq gnus-article-current nil))
6186     (when gnus-use-cache
6187       (gnus-cache-possibly-remove-articles)
6188       (gnus-cache-save-buffers))
6189     (gnus-async-prefetch-remove-group group)
6190     (when gnus-suppress-duplicates
6191       (gnus-dup-enter-articles))
6192     (when gnus-use-trees
6193       (gnus-tree-close group))
6194     (when gnus-use-cache
6195       (gnus-cache-write-active))
6196     ;; Remove entries for this group.
6197     (nnmail-purge-split-history (gnus-group-real-name group))
6198     ;; Make all changes in this group permanent.
6199     (unless quit-config
6200       (gnus-run-hooks 'gnus-exit-group-hook)
6201       (gnus-summary-update-info))
6202     (gnus-close-group group)
6203     ;; Make sure where we were, and go to next newsgroup.
6204     (set-buffer gnus-group-buffer)
6205     (unless quit-config
6206       (gnus-group-jump-to-group group))
6207     (gnus-run-hooks 'gnus-summary-exit-hook)
6208     (unless (or quit-config
6209                 ;; If this group has disappeared from the summary
6210                 ;; buffer, don't skip forwards.
6211                 (not (string= group (gnus-group-group-name))))
6212       (gnus-group-next-unread-group 1))
6213     (setq group-point (point))
6214     (if temporary
6215         nil                             ;Nothing to do.
6216       ;; If we have several article buffers, we kill them at exit.
6217       (unless gnus-single-article-buffer
6218         (gnus-kill-buffer gnus-article-buffer)
6219         (gnus-kill-buffer gnus-original-article-buffer)
6220         (setq gnus-article-current nil))
6221       (set-buffer buf)
6222       (if (not gnus-kill-summary-on-exit)
6223           (progn
6224             (gnus-deaden-summary)
6225             (setq mode nil))
6226         ;; We set all buffer-local variables to nil.  It is unclear why
6227         ;; this is needed, but if we don't, buffer-local variables are
6228         ;; not garbage-collected, it seems.  This would the lead to en
6229         ;; ever-growing Emacs.
6230         (gnus-summary-clear-local-variables)
6231         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6232           (gnus-summary-clear-local-variables))
6233         (when (get-buffer gnus-article-buffer)
6234           (bury-buffer gnus-article-buffer))
6235         ;; We clear the global counterparts of the buffer-local
6236         ;; variables as well, just to be on the safe side.
6237         (set-buffer gnus-group-buffer)
6238         (gnus-summary-clear-local-variables)
6239         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6240           (gnus-summary-clear-local-variables)))
6241       (setq gnus-current-select-method gnus-select-method)
6242       (pop-to-buffer gnus-group-buffer)
6243       (if (not quit-config)
6244           (progn
6245             (goto-char group-point)
6246             (gnus-configure-windows 'group 'force)
6247             (unless (pos-visible-in-window-p)
6248               (forward-line (/ (static-if (featurep 'xemacs)
6249                                    (window-displayed-height)
6250                                  (1- (window-height)))
6251                                -2))
6252               (set-window-start (selected-window) (point))
6253               (goto-char group-point)))
6254         (gnus-handle-ephemeral-exit quit-config))
6255       ;; Return to group mode buffer.
6256       (when (eq mode 'gnus-summary-mode)
6257         (gnus-kill-buffer buf))
6258       ;; Clear the current group name.
6259       (unless quit-config
6260         (setq gnus-newsgroup-name nil)))))
6261
6262 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6263 (defun gnus-summary-exit-no-update (&optional no-questions)
6264   "Quit reading current newsgroup without updating read article info."
6265   (interactive)
6266   (let* ((group gnus-newsgroup-name)
6267          (quit-config (gnus-group-quit-config group)))
6268     (when (or no-questions
6269               gnus-expert-user
6270               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6271       (gnus-async-halt-prefetch)
6272       (mapcar 'funcall
6273               (delq 'gnus-summary-expire-articles
6274                     (copy-sequence gnus-summary-prepare-exit-hook)))
6275       ;; If we have several article buffers, we kill them at exit.
6276       (unless gnus-single-article-buffer
6277         (gnus-kill-buffer gnus-article-buffer)
6278         (gnus-kill-buffer gnus-original-article-buffer)
6279         (setq gnus-article-current nil))
6280       (if (not gnus-kill-summary-on-exit)
6281           (gnus-deaden-summary)
6282         (gnus-close-group group)
6283         (gnus-summary-clear-local-variables)
6284         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6285           (gnus-summary-clear-local-variables))
6286         (set-buffer gnus-group-buffer)
6287         (gnus-summary-clear-local-variables)
6288         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6289           (gnus-summary-clear-local-variables))
6290         (when (get-buffer gnus-summary-buffer)
6291           (kill-buffer gnus-summary-buffer)))
6292       (unless gnus-single-article-buffer
6293         (setq gnus-article-current nil))
6294       (when gnus-use-trees
6295         (gnus-tree-close group))
6296       (gnus-async-prefetch-remove-group group)
6297       (when (get-buffer gnus-article-buffer)
6298         (bury-buffer gnus-article-buffer))
6299       ;; Return to the group buffer.
6300       (gnus-configure-windows 'group 'force)
6301       ;; Clear the current group name.
6302       (setq gnus-newsgroup-name nil)
6303       (when (equal (gnus-group-group-name) group)
6304         (gnus-group-next-unread-group 1))
6305       (when quit-config
6306         (gnus-handle-ephemeral-exit quit-config)))))
6307
6308 (defun gnus-handle-ephemeral-exit (quit-config)
6309   "Handle movement when leaving an ephemeral group.
6310 The state which existed when entering the ephemeral is reset."
6311   (if (not (buffer-name (car quit-config)))
6312       (gnus-configure-windows 'group 'force)
6313     (set-buffer (car quit-config))
6314     (cond ((eq major-mode 'gnus-summary-mode)
6315            (gnus-set-global-variables))
6316           ((eq major-mode 'gnus-article-mode)
6317            (save-excursion
6318              ;; The `gnus-summary-buffer' variable may point
6319              ;; to the old summary buffer when using a single
6320              ;; article buffer.
6321              (unless (gnus-buffer-live-p gnus-summary-buffer)
6322                (set-buffer gnus-group-buffer))
6323              (set-buffer gnus-summary-buffer)
6324              (gnus-set-global-variables))))
6325     (if (or (eq (cdr quit-config) 'article)
6326             (eq (cdr quit-config) 'pick))
6327         (progn
6328           ;; The current article may be from the ephemeral group
6329           ;; thus it is best that we reload this article
6330           (gnus-summary-show-article)
6331           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6332               (gnus-configure-windows 'pick 'force)
6333             (gnus-configure-windows (cdr quit-config) 'force)))
6334       (gnus-configure-windows (cdr quit-config) 'force))
6335     (when (eq major-mode 'gnus-summary-mode)
6336       (gnus-summary-next-subject 1 nil t)
6337       (gnus-summary-recenter)
6338       (gnus-summary-position-point))))
6339
6340 (defun gnus-summary-preview-mime-message ()
6341   "MIME decode and play this message."
6342   (interactive)
6343   (let ((gnus-break-pages nil)
6344         (gnus-show-mime t))
6345     (gnus-summary-select-article gnus-show-all-headers t))
6346   (let ((w (get-buffer-window gnus-article-buffer)))
6347     (when w
6348       (select-window (get-buffer-window gnus-article-buffer)))))
6349
6350 ;;; Dead summaries.
6351
6352 (defvar gnus-dead-summary-mode-map nil)
6353
6354 (unless gnus-dead-summary-mode-map
6355   (setq gnus-dead-summary-mode-map (make-keymap))
6356   (suppress-keymap gnus-dead-summary-mode-map)
6357   (substitute-key-definition
6358    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6359   (dolist (key '("\C-d" "\r" "\177" [delete]))
6360     (define-key gnus-dead-summary-mode-map
6361       key 'gnus-summary-wake-up-the-dead))
6362   (dolist (key '("q" "Q"))
6363     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6364
6365 (defvar gnus-dead-summary-mode nil
6366   "Minor mode for Gnus summary buffers.")
6367
6368 (defun gnus-dead-summary-mode (&optional arg)
6369   "Minor mode for Gnus summary buffers."
6370   (interactive "P")
6371   (when (eq major-mode 'gnus-summary-mode)
6372     (make-local-variable 'gnus-dead-summary-mode)
6373     (setq gnus-dead-summary-mode
6374           (if (null arg) (not gnus-dead-summary-mode)
6375             (> (prefix-numeric-value arg) 0)))
6376     (when gnus-dead-summary-mode
6377       (gnus-add-minor-mode
6378        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6379
6380 (defun gnus-deaden-summary ()
6381   "Make the current summary buffer into a dead summary buffer."
6382   ;; Kill any previous dead summary buffer.
6383   (when (and gnus-dead-summary
6384              (buffer-name gnus-dead-summary))
6385     (save-excursion
6386       (set-buffer gnus-dead-summary)
6387       (when gnus-dead-summary-mode
6388         (kill-buffer (current-buffer)))))
6389   ;; Make this the current dead summary.
6390   (setq gnus-dead-summary (current-buffer))
6391   (gnus-dead-summary-mode 1)
6392   (let ((name (buffer-name)))
6393     (when (string-match "Summary" name)
6394       (rename-buffer
6395        (concat (substring name 0 (match-beginning 0)) "Dead "
6396                (substring name (match-beginning 0)))
6397        t)
6398       (bury-buffer))))
6399
6400 (defun gnus-kill-or-deaden-summary (buffer)
6401   "Kill or deaden the summary BUFFER."
6402   (save-excursion
6403     (when (and (buffer-name buffer)
6404                (not gnus-single-article-buffer))
6405       (save-excursion
6406         (set-buffer buffer)
6407         (gnus-kill-buffer gnus-article-buffer)
6408         (gnus-kill-buffer gnus-original-article-buffer)))
6409     (cond
6410      ;; Kill the buffer.
6411      (gnus-kill-summary-on-exit
6412       (when (and gnus-use-trees
6413                  (gnus-buffer-exists-p buffer))
6414         (save-excursion
6415           (set-buffer buffer)
6416           (gnus-tree-close gnus-newsgroup-name)))
6417       (gnus-kill-buffer buffer))
6418      ;; Deaden the buffer.
6419      ((gnus-buffer-exists-p buffer)
6420       (save-excursion
6421         (set-buffer buffer)
6422         (gnus-deaden-summary))))))
6423
6424 (defun gnus-summary-wake-up-the-dead (&rest args)
6425   "Wake up the dead summary buffer."
6426   (interactive)
6427   (gnus-dead-summary-mode -1)
6428   (let ((name (buffer-name)))
6429     (when (string-match "Dead " name)
6430       (rename-buffer
6431        (concat (substring name 0 (match-beginning 0))
6432                (substring name (match-end 0)))
6433        t)))
6434   (gnus-message 3 "This dead summary is now alive again"))
6435
6436 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6437 (defun gnus-summary-fetch-faq (&optional faq-dir)
6438   "Fetch the FAQ for the current group.
6439 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6440 in."
6441   (interactive
6442    (list
6443     (when current-prefix-arg
6444       (completing-read
6445        "Faq dir: " (and (listp gnus-group-faq-directory)
6446                         (mapcar (lambda (file) (list file))
6447                                 gnus-group-faq-directory))))))
6448   (let (gnus-faq-buffer)
6449     (when (setq gnus-faq-buffer
6450                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6451       (gnus-configure-windows 'summary-faq))))
6452
6453 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6454 (defun gnus-summary-describe-group (&optional force)
6455   "Describe the current newsgroup."
6456   (interactive "P")
6457   (gnus-group-describe-group force gnus-newsgroup-name))
6458
6459 (defun gnus-summary-describe-briefly ()
6460   "Describe summary mode commands briefly."
6461   (interactive)
6462   (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")))
6463
6464 ;; Walking around group mode buffer from summary mode.
6465
6466 (defun gnus-summary-next-group (&optional no-article target-group backward)
6467   "Exit current newsgroup and then select next unread newsgroup.
6468 If prefix argument NO-ARTICLE is non-nil, no article is selected
6469 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6470 previous group instead."
6471   (interactive "P")
6472   ;; Stop pre-fetching.
6473   (gnus-async-halt-prefetch)
6474   (let ((current-group gnus-newsgroup-name)
6475         (current-buffer (current-buffer))
6476         entered)
6477     ;; First we semi-exit this group to update Xrefs and all variables.
6478     ;; We can't do a real exit, because the window conf must remain
6479     ;; the same in case the user is prompted for info, and we don't
6480     ;; want the window conf to change before that...
6481     (gnus-summary-exit t)
6482     (while (not entered)
6483       ;; Then we find what group we are supposed to enter.
6484       (set-buffer gnus-group-buffer)
6485       (gnus-group-jump-to-group current-group)
6486       (setq target-group
6487             (or target-group
6488                 (if (eq gnus-keep-same-level 'best)
6489                     (gnus-summary-best-group gnus-newsgroup-name)
6490                   (gnus-summary-search-group backward gnus-keep-same-level))))
6491       (if (not target-group)
6492           ;; There are no further groups, so we return to the group
6493           ;; buffer.
6494           (progn
6495             (gnus-message 5 "Returning to the group buffer")
6496             (setq entered t)
6497             (when (gnus-buffer-live-p current-buffer)
6498               (set-buffer current-buffer)
6499               (gnus-summary-exit))
6500             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6501         ;; We try to enter the target group.
6502         (gnus-group-jump-to-group target-group)
6503         (let ((unreads (gnus-group-group-unread)))
6504           (if (and (or (eq t unreads)
6505                        (and unreads (not (zerop unreads))))
6506                    (gnus-summary-read-group
6507                     target-group nil no-article
6508                     (and (buffer-name current-buffer) current-buffer)
6509                     nil backward))
6510               (setq entered t)
6511             (setq current-group target-group
6512                   target-group nil)))))))
6513
6514 (defun gnus-summary-prev-group (&optional no-article)
6515   "Exit current newsgroup and then select previous unread newsgroup.
6516 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6517   (interactive "P")
6518   (gnus-summary-next-group no-article nil t))
6519
6520 ;; Walking around summary lines.
6521
6522 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6523   "Go to the first unread subject.
6524 If UNREAD is non-nil, go to the first unread article.
6525 Returns the article selected or nil if there are no unread articles."
6526   (interactive "P")
6527   (prog1
6528       (cond
6529        ;; Empty summary.
6530        ((null gnus-newsgroup-data)
6531         (gnus-message 3 "No articles in the group")
6532         nil)
6533        ;; Pick the first article.
6534        ((not unread)
6535         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6536         (gnus-data-number (car gnus-newsgroup-data)))
6537        ;; No unread articles.
6538        ((null gnus-newsgroup-unreads)
6539         (gnus-message 3 "No more unread articles")
6540         nil)
6541        ;; Find the first unread article.
6542        (t
6543         (let ((data gnus-newsgroup-data))
6544           (while (and data
6545                       (and (not (and undownloaded
6546                                      (eq gnus-undownloaded-mark
6547                                          (gnus-data-mark (car data)))))
6548                            (if unseen
6549                                (or (not (memq
6550                                          (gnus-data-number (car data))
6551                                          gnus-newsgroup-unseen))
6552                                    (not (gnus-data-unread-p (car data))))
6553                              (not (gnus-data-unread-p (car data))))))
6554             (setq data (cdr data)))
6555           (when data
6556             (goto-char (gnus-data-pos (car data)))
6557             (gnus-data-number (car data))))))
6558     (gnus-summary-position-point)))
6559
6560 (defun gnus-summary-next-subject (n &optional unread dont-display)
6561   "Go to next N'th summary line.
6562 If N is negative, go to the previous N'th subject line.
6563 If UNREAD is non-nil, only unread articles are selected.
6564 The difference between N and the actual number of steps taken is
6565 returned."
6566   (interactive "p")
6567   (let ((backward (< n 0))
6568         (n (abs n)))
6569     (while (and (> n 0)
6570                 (if backward
6571                     (gnus-summary-find-prev unread)
6572                   (gnus-summary-find-next unread)))
6573       (unless (zerop (setq n (1- n)))
6574         (gnus-summary-show-thread)))
6575     (when (/= 0 n)
6576       (gnus-message 7 "No more%s articles"
6577                     (if unread " unread" "")))
6578     (unless dont-display
6579       (gnus-summary-recenter)
6580       (gnus-summary-position-point))
6581     n))
6582
6583 (defun gnus-summary-next-unread-subject (n)
6584   "Go to next N'th unread summary line."
6585   (interactive "p")
6586   (gnus-summary-next-subject n t))
6587
6588 (defun gnus-summary-prev-subject (n &optional unread)
6589   "Go to previous N'th summary line.
6590 If optional argument UNREAD is non-nil, only unread article is selected."
6591   (interactive "p")
6592   (gnus-summary-next-subject (- n) unread))
6593
6594 (defun gnus-summary-prev-unread-subject (n)
6595   "Go to previous N'th unread summary line."
6596   (interactive "p")
6597   (gnus-summary-next-subject (- n) t))
6598
6599 (defun gnus-summary-goto-subject (article &optional force silent)
6600   "Go the subject line of ARTICLE.
6601 If FORCE, also allow jumping to articles not currently shown."
6602   (interactive "nArticle number: ")
6603   (unless (numberp article)
6604     (error "Article %s is not a number" article))
6605   (let ((b (point))
6606         (data (gnus-data-find article)))
6607     ;; We read in the article if we have to.
6608     (and (not data)
6609          force
6610          (gnus-summary-insert-subject
6611           article
6612           (if (or (numberp force) (vectorp force)) force)
6613           t)
6614          (setq data (gnus-data-find article)))
6615     (goto-char b)
6616     (if (not data)
6617         (progn
6618           (unless silent
6619             (gnus-message 3 "Can't find article %d" article))
6620           nil)
6621       (let ((pt (gnus-data-pos data)))
6622         (goto-char pt)
6623         (gnus-summary-set-article-display-arrow pt))
6624       (gnus-summary-position-point)
6625       article)))
6626
6627 ;; Walking around summary lines with displaying articles.
6628
6629 (defun gnus-summary-expand-window (&optional arg)
6630   "Make the summary buffer take up the entire Emacs frame.
6631 Given a prefix, will force an `article' buffer configuration."
6632   (interactive "P")
6633   (if arg
6634       (gnus-configure-windows 'article 'force)
6635     (gnus-configure-windows 'summary 'force)))
6636
6637 (defun gnus-summary-display-article (article &optional all-header)
6638   "Display ARTICLE in article buffer."
6639   (when (gnus-buffer-live-p gnus-article-buffer)
6640     (with-current-buffer gnus-article-buffer
6641       (set-buffer-multibyte t)))
6642   (gnus-set-global-variables)
6643   (when (gnus-buffer-live-p gnus-article-buffer)
6644     (with-current-buffer gnus-article-buffer
6645       (setq gnus-article-charset gnus-newsgroup-charset)
6646       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6647       (set-buffer-multibyte t)))
6648   (if (null article)
6649       nil
6650     (prog1
6651         (if gnus-summary-display-article-function
6652             (funcall gnus-summary-display-article-function article all-header)
6653           (gnus-article-prepare article all-header))
6654       (with-current-buffer gnus-article-buffer
6655         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6656              nil))
6657       (gnus-run-hooks 'gnus-select-article-hook)
6658       (when (and gnus-current-article
6659                  (not (zerop gnus-current-article)))
6660         (gnus-summary-goto-subject gnus-current-article))
6661       (gnus-summary-recenter)
6662       (when (and gnus-use-trees gnus-show-threads)
6663         (gnus-possibly-generate-tree article)
6664         (gnus-highlight-selected-tree article))
6665       ;; Successfully display article.
6666       (gnus-article-set-window-start
6667        (cdr (assq article gnus-newsgroup-bookmarks))))))
6668
6669 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6670   "Select the current article.
6671 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6672 non-nil, the article will be re-fetched even if it already present in
6673 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6674 be displayed."
6675   ;; Make sure we are in the summary buffer to work around bbdb bug.
6676   (unless (eq major-mode 'gnus-summary-mode)
6677     (set-buffer gnus-summary-buffer))
6678   (let ((article (or article (gnus-summary-article-number)))
6679         (all-headers (not (not all-headers))) ;Must be T or NIL.
6680         gnus-summary-display-article-function)
6681     (and (not pseudo)
6682          (gnus-summary-article-pseudo-p article)
6683          (error "This is a pseudo-article"))
6684     (save-excursion
6685       (set-buffer gnus-summary-buffer)
6686       (if (or (and gnus-single-article-buffer
6687                    (or (null gnus-current-article)
6688                        (null gnus-article-current)
6689                        (null (get-buffer gnus-article-buffer))
6690                        (not (eq article (cdr gnus-article-current)))
6691                        (not (equal (car gnus-article-current)
6692                                    gnus-newsgroup-name))))
6693               (and (not gnus-single-article-buffer)
6694                    (or (null gnus-current-article)
6695                        (not (eq gnus-current-article article))))
6696               force)
6697           ;; The requested article is different from the current article.
6698           (progn
6699             (gnus-summary-display-article article all-headers)
6700             (gnus-article-set-window-start
6701              (cdr (assq article gnus-newsgroup-bookmarks)))
6702             article)
6703         'old))))
6704
6705 (defun gnus-summary-force-verify-and-decrypt ()
6706   (interactive)
6707   (let ((mm-verify-option 'known)
6708         (mm-decrypt-option 'known))
6709     (gnus-summary-select-article nil 'force)))
6710
6711 (defun gnus-summary-set-current-mark (&optional current-mark)
6712   "Obsolete function."
6713   nil)
6714
6715 (defun gnus-summary-next-article (&optional unread subject backward push)
6716   "Select the next article.
6717 If UNREAD, only unread articles are selected.
6718 If SUBJECT, only articles with SUBJECT are selected.
6719 If BACKWARD, the previous article is selected instead of the next."
6720   (interactive "P")
6721   (cond
6722    ;; Is there such an article?
6723    ((and (gnus-summary-search-forward unread subject backward)
6724          (or (gnus-summary-display-article (gnus-summary-article-number))
6725              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6726     (gnus-summary-position-point))
6727    ;; If not, we try the first unread, if that is wanted.
6728    ((and subject
6729          gnus-auto-select-same
6730          (gnus-summary-first-unread-article))
6731     (gnus-summary-position-point)
6732     (gnus-message 6 "Wrapped"))
6733    ;; Try to get next/previous article not displayed in this group.
6734    ((and gnus-auto-extend-newsgroup
6735          (not unread) (not subject))
6736     (gnus-summary-goto-article
6737      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6738      nil (count-lines (point-min) (point))))
6739    ;; Go to next/previous group.
6740    (t
6741     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6742       (gnus-summary-jump-to-group gnus-newsgroup-name))
6743     (let ((cmd last-command-char)
6744           (point
6745            (save-excursion
6746              (set-buffer gnus-group-buffer)
6747              (point)))
6748           (group
6749            (if (eq gnus-keep-same-level 'best)
6750                (gnus-summary-best-group gnus-newsgroup-name)
6751              (gnus-summary-search-group backward gnus-keep-same-level))))
6752       ;; For some reason, the group window gets selected.  We change
6753       ;; it back.
6754       (select-window (get-buffer-window (current-buffer)))
6755       ;; Select next unread newsgroup automagically.
6756       (cond
6757        ((or (not gnus-auto-select-next)
6758             (not cmd))
6759         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6760        ((or (eq gnus-auto-select-next 'quietly)
6761             (and (eq gnus-auto-select-next 'slightly-quietly)
6762                  push)
6763             (and (eq gnus-auto-select-next 'almost-quietly)
6764                  (gnus-summary-last-article-p)))
6765         ;; Select quietly.
6766         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6767             (gnus-summary-exit)
6768           (gnus-message 7 "No more%s articles (%s)..."
6769                         (if unread " unread" "")
6770                         (if group (concat "selecting " group)
6771                           "exiting"))
6772           (gnus-summary-next-group nil group backward)))
6773        (t
6774         (when (gnus-key-press-event-p last-input-event)
6775           (gnus-summary-walk-group-buffer
6776            gnus-newsgroup-name cmd unread backward point))))))))
6777
6778 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6779   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6780                       (?\C-p (gnus-group-prev-unread-group 1))))
6781         (cursor-in-echo-area t)
6782         keve key group ended)
6783     (save-excursion
6784       (set-buffer gnus-group-buffer)
6785       (goto-char start)
6786       (setq group
6787             (if (eq gnus-keep-same-level 'best)
6788                 (gnus-summary-best-group gnus-newsgroup-name)
6789               (gnus-summary-search-group backward gnus-keep-same-level))))
6790     (while (not ended)
6791       (gnus-message
6792        5 "No more%s articles%s" (if unread " unread" "")
6793        (if (and group
6794                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6795            (format " (Type %s for %s [%s])"
6796                    (single-key-description cmd) group
6797                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6798          (format " (Type %s to exit %s)"
6799                  (single-key-description cmd)
6800                  gnus-newsgroup-name)))
6801       ;; Confirm auto selection.
6802       (setq key (car (setq keve (gnus-read-event-char))))
6803       (setq ended t)
6804       (cond
6805        ((assq key keystrokes)
6806         (let ((obuf (current-buffer)))
6807           (switch-to-buffer gnus-group-buffer)
6808           (when group
6809             (gnus-group-jump-to-group group))
6810           (eval (cadr (assq key keystrokes)))
6811           (setq group (gnus-group-group-name))
6812           (switch-to-buffer obuf))
6813         (setq ended nil))
6814        ((equal key cmd)
6815         (if (or (not group)
6816                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6817             (gnus-summary-exit)
6818           (gnus-summary-next-group nil group backward)))
6819        (t
6820         (push (cdr keve) unread-command-events))))))
6821
6822 (defun gnus-summary-next-unread-article ()
6823   "Select unread article after current one."
6824   (interactive)
6825   (gnus-summary-next-article
6826    (or (not (eq gnus-summary-goto-unread 'never))
6827        (gnus-summary-last-article-p (gnus-summary-article-number)))
6828    (and gnus-auto-select-same
6829         (gnus-summary-article-subject))))
6830
6831 (defun gnus-summary-prev-article (&optional unread subject)
6832   "Select the article after the current one.
6833 If UNREAD is non-nil, only unread articles are selected."
6834   (interactive "P")
6835   (gnus-summary-next-article unread subject t))
6836
6837 (defun gnus-summary-prev-unread-article ()
6838   "Select unread article before current one."
6839   (interactive)
6840   (gnus-summary-prev-article
6841    (or (not (eq gnus-summary-goto-unread 'never))
6842        (gnus-summary-first-article-p (gnus-summary-article-number)))
6843    (and gnus-auto-select-same
6844         (gnus-summary-article-subject))))
6845
6846 (defun gnus-summary-next-page (&optional lines circular)
6847   "Show next page of the selected article.
6848 If at the end of the current article, select the next article.
6849 LINES says how many lines should be scrolled up.
6850
6851 If CIRCULAR is non-nil, go to the start of the article instead of
6852 selecting the next article when reaching the end of the current
6853 article."
6854   (interactive "P")
6855   (setq gnus-summary-buffer (current-buffer))
6856   (gnus-set-global-variables)
6857   (let ((article (gnus-summary-article-number))
6858         (article-window (get-buffer-window gnus-article-buffer t))
6859         endp)
6860     ;; If the buffer is empty, we have no article.
6861     (unless article
6862       (error "No article to select"))
6863     (gnus-configure-windows 'article)
6864     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6865         (if (and (eq gnus-summary-goto-unread 'never)
6866                  (not (gnus-summary-last-article-p article)))
6867             (gnus-summary-next-article)
6868           (gnus-summary-next-unread-article))
6869       (if (or (null gnus-current-article)
6870               (null gnus-article-current)
6871               (/= article (cdr gnus-article-current))
6872               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6873           ;; Selected subject is different from current article's.
6874           (gnus-summary-display-article article)
6875         (when article-window
6876           (gnus-eval-in-buffer-window gnus-article-buffer
6877             (setq endp (gnus-article-next-page lines)))
6878           (when endp
6879             (cond (circular
6880                    (gnus-summary-beginning-of-article))
6881                   (lines
6882                    (gnus-message 3 "End of message"))
6883                   ((null lines)
6884                    (if (and (eq gnus-summary-goto-unread 'never)
6885                             (not (gnus-summary-last-article-p article)))
6886                        (gnus-summary-next-article)
6887                      (gnus-summary-next-unread-article))))))))
6888     (gnus-summary-recenter)
6889     (gnus-summary-position-point)))
6890
6891 (defun gnus-summary-prev-page (&optional lines move)
6892   "Show previous page of selected article.
6893 Argument LINES specifies lines to be scrolled down.
6894 If MOVE, move to the previous unread article if point is at
6895 the beginning of the buffer."
6896   (interactive "P")
6897   (let ((article (gnus-summary-article-number))
6898         (article-window (get-buffer-window gnus-article-buffer t))
6899         endp)
6900     (gnus-configure-windows 'article)
6901     (if (or (null gnus-current-article)
6902             (null gnus-article-current)
6903             (/= article (cdr gnus-article-current))
6904             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6905         ;; Selected subject is different from current article's.
6906         (gnus-summary-display-article article)
6907       (gnus-summary-recenter)
6908       (when article-window
6909         (gnus-eval-in-buffer-window gnus-article-buffer
6910           (setq endp (gnus-article-prev-page lines)))
6911         (when (and move endp)
6912           (cond (lines
6913                  (gnus-message 3 "Beginning of message"))
6914                 ((null lines)
6915                  (if (and (eq gnus-summary-goto-unread 'never)
6916                           (not (gnus-summary-first-article-p article)))
6917                      (gnus-summary-prev-article)
6918                    (gnus-summary-prev-unread-article))))))))
6919   (gnus-summary-position-point))
6920
6921 (defun gnus-summary-prev-page-or-article (&optional lines)
6922   "Show previous page of selected article.
6923 Argument LINES specifies lines to be scrolled down.
6924 If at the beginning of the article, go to the next article."
6925   (interactive "P")
6926   (gnus-summary-prev-page lines t))
6927
6928 (defun gnus-summary-scroll-up (lines)
6929   "Scroll up (or down) one line current article.
6930 Argument LINES specifies lines to be scrolled up (or down if negative)."
6931   (interactive "p")
6932   (gnus-configure-windows 'article)
6933   (gnus-summary-show-thread)
6934   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6935     (gnus-eval-in-buffer-window gnus-article-buffer
6936       (cond ((> lines 0)
6937              (when (gnus-article-next-page lines)
6938                (gnus-message 3 "End of message")))
6939             ((< lines 0)
6940              (gnus-article-prev-page (- lines))))))
6941   (gnus-summary-recenter)
6942   (gnus-summary-position-point))
6943
6944 (defun gnus-summary-scroll-down (lines)
6945   "Scroll down (or up) one line current article.
6946 Argument LINES specifies lines to be scrolled down (or up if negative)."
6947   (interactive "p")
6948   (gnus-summary-scroll-up (- lines)))
6949
6950 (defun gnus-summary-next-same-subject ()
6951   "Select next article which has the same subject as current one."
6952   (interactive)
6953   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6954
6955 (defun gnus-summary-prev-same-subject ()
6956   "Select previous article which has the same subject as current one."
6957   (interactive)
6958   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6959
6960 (defun gnus-summary-next-unread-same-subject ()
6961   "Select next unread article which has the same subject as current one."
6962   (interactive)
6963   (gnus-summary-next-article t (gnus-summary-article-subject)))
6964
6965 (defun gnus-summary-prev-unread-same-subject ()
6966   "Select previous unread article which has the same subject as current one."
6967   (interactive)
6968   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6969
6970 (defun gnus-summary-first-unread-article ()
6971   "Select the first unread article.
6972 Return nil if there are no unread articles."
6973   (interactive)
6974   (prog1
6975       (when (gnus-summary-first-subject t)
6976         (gnus-summary-show-thread)
6977         (gnus-summary-first-subject t)
6978         (gnus-summary-display-article (gnus-summary-article-number)))
6979     (gnus-summary-position-point)))
6980
6981 (defun gnus-summary-first-unread-subject ()
6982   "Place the point on the subject line of the first unread article.
6983 Return nil if there are no unread articles."
6984   (interactive)
6985   (prog1
6986       (when (gnus-summary-first-subject t)
6987         (gnus-summary-show-thread)
6988         (gnus-summary-first-subject t))
6989     (gnus-summary-position-point)))
6990
6991 (defun gnus-summary-first-unseen-subject ()
6992   "Place the point on the subject line of the first unseen article.
6993 Return nil if there are no unseen articles."
6994   (interactive)
6995   (prog1
6996       (when (gnus-summary-first-subject t t t)
6997         (gnus-summary-show-thread)
6998         (gnus-summary-first-subject t t t))
6999     (gnus-summary-position-point)))
7000
7001 (defun gnus-summary-first-unseen-or-unread-subject ()
7002   "Place the point on the subject line of the first unseen article.
7003 Return nil if there are no unseen articles."
7004   (interactive)
7005   (prog1
7006       (unless (when (gnus-summary-first-subject t t t)
7007                 (gnus-summary-show-thread)
7008                 (gnus-summary-first-subject t t t))
7009         (when (gnus-summary-first-subject t)
7010           (gnus-summary-show-thread)
7011           (gnus-summary-first-subject t)))
7012     (gnus-summary-position-point)))
7013
7014 (defun gnus-summary-first-article ()
7015   "Select the first article.
7016 Return nil if there are no articles."
7017   (interactive)
7018   (prog1
7019       (when (gnus-summary-first-subject)
7020         (gnus-summary-show-thread)
7021         (gnus-summary-first-subject)
7022         (gnus-summary-display-article (gnus-summary-article-number)))
7023     (gnus-summary-position-point)))
7024
7025 (defun gnus-summary-best-unread-article (&optional arg)
7026   "Select the unread article with the highest score.
7027 If given a prefix argument, select the next unread article that has a
7028 score higher than the default score."
7029   (interactive "P")
7030   (let ((article (if arg
7031                      (gnus-summary-better-unread-subject)
7032                    (gnus-summary-best-unread-subject))))
7033     (if article
7034         (gnus-summary-goto-article article)
7035       (error "No unread articles"))))
7036
7037 (defun gnus-summary-best-unread-subject ()
7038   "Select the unread subject with the highest score."
7039   (interactive)
7040   (let ((best -1000000)
7041         (data gnus-newsgroup-data)
7042         article score)
7043     (while data
7044       (and (gnus-data-unread-p (car data))
7045            (> (setq score
7046                     (gnus-summary-article-score (gnus-data-number (car data))))
7047               best)
7048            (setq best score
7049                  article (gnus-data-number (car data))))
7050       (setq data (cdr data)))
7051     (when article
7052       (gnus-summary-goto-subject article))
7053     (gnus-summary-position-point)
7054     article))
7055
7056 (defun gnus-summary-better-unread-subject ()
7057   "Select the first unread subject that has a score over the default score."
7058   (interactive)
7059   (let ((data gnus-newsgroup-data)
7060         article score)
7061     (while (and (setq article (gnus-data-number (car data)))
7062                 (or (gnus-data-read-p (car data))
7063                     (not (> (gnus-summary-article-score article)
7064                             gnus-summary-default-score))))
7065       (setq data (cdr data)))
7066     (when article
7067       (gnus-summary-goto-subject article))
7068     (gnus-summary-position-point)
7069     article))
7070
7071 (defun gnus-summary-last-subject ()
7072   "Go to the last displayed subject line in the group."
7073   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7074     (when article
7075       (gnus-summary-goto-subject article))))
7076
7077 (defun gnus-summary-goto-article (article &optional all-headers force)
7078   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7079 If ALL-HEADERS is non-nil, no header lines are hidden.
7080 If FORCE, go to the article even if it isn't displayed.  If FORCE
7081 is a number, it is the line the article is to be displayed on."
7082   (interactive
7083    (list
7084     (completing-read
7085      "Article number or Message-ID: "
7086      (mapcar (lambda (number) (list (int-to-string number)))
7087              gnus-newsgroup-limit))
7088     current-prefix-arg
7089     t))
7090   (prog1
7091       (if (and (stringp article)
7092                (string-match "@" article))
7093           (gnus-summary-refer-article article)
7094         (when (stringp article)
7095           (setq article (string-to-number article)))
7096         (if (gnus-summary-goto-subject article force)
7097             (gnus-summary-display-article article all-headers)
7098           (gnus-message 4 "Couldn't go to article %s" article) nil))
7099     (gnus-summary-position-point)))
7100
7101 (defun gnus-summary-goto-last-article ()
7102   "Go to the previously read article."
7103   (interactive)
7104   (prog1
7105       (when gnus-last-article
7106         (gnus-summary-goto-article gnus-last-article nil t))
7107     (gnus-summary-position-point)))
7108
7109 (defun gnus-summary-pop-article (number)
7110   "Pop one article off the history and go to the previous.
7111 NUMBER articles will be popped off."
7112   (interactive "p")
7113   (let (to)
7114     (setq gnus-newsgroup-history
7115           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7116     (if to
7117         (gnus-summary-goto-article (car to) nil t)
7118       (error "Article history empty")))
7119   (gnus-summary-position-point))
7120
7121 ;; Summary commands and functions for limiting the summary buffer.
7122
7123 (defun gnus-summary-limit-to-articles (n)
7124   "Limit the summary buffer to the next N articles.
7125 If not given a prefix, use the process marked articles instead."
7126   (interactive "P")
7127   (prog1
7128       (let ((articles (gnus-summary-work-articles n)))
7129         (setq gnus-newsgroup-processable nil)
7130         (gnus-summary-limit articles))
7131     (gnus-summary-position-point)))
7132
7133 (defun gnus-summary-pop-limit (&optional total)
7134   "Restore the previous limit.
7135 If given a prefix, remove all limits."
7136   (interactive "P")
7137   (when total
7138     (setq gnus-newsgroup-limits
7139           (list (mapcar (lambda (h) (mail-header-number h))
7140                         gnus-newsgroup-headers))))
7141   (unless gnus-newsgroup-limits
7142     (error "No limit to pop"))
7143   (prog1
7144       (gnus-summary-limit nil 'pop)
7145     (gnus-summary-position-point)))
7146
7147 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7148   "Limit the summary buffer to articles that have subjects that match a regexp.
7149 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7150   (interactive
7151    (list (read-string (if current-prefix-arg
7152                           "Exclude subject (regexp): "
7153                         "Limit to subject (regexp): "))
7154          nil current-prefix-arg))
7155   (unless header
7156     (setq header "subject"))
7157   (when (not (equal "" subject))
7158     (prog1
7159         (let ((articles (gnus-summary-find-matching
7160                          (or header "subject") subject 'all nil nil
7161                          not-matching)))
7162           (unless articles
7163             (error "Found no matches for \"%s\"" subject))
7164           (gnus-summary-limit articles))
7165       (gnus-summary-position-point))))
7166
7167 (defun gnus-summary-limit-to-author (from &optional not-matching)
7168   "Limit the summary buffer to articles that have authors that match a regexp.
7169 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7170   (interactive
7171    (list (read-string (if current-prefix-arg
7172                           "Exclude author (regexp): "
7173                         "Limit to author (regexp): "))
7174          current-prefix-arg))
7175   (gnus-summary-limit-to-subject from "from" not-matching))
7176
7177 (defun gnus-summary-limit-to-age (age &optional younger-p)
7178   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7179 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7180 articles that are younger than AGE days."
7181   (interactive
7182    (let ((younger current-prefix-arg)
7183          (days-got nil)
7184          days)
7185      (while (not days-got)
7186        (setq days (if younger
7187                       (read-string "Limit to articles within (in days): ")
7188                     (read-string "Limit to articles older than (in days): ")))
7189        (when (> (length days) 0)
7190          (setq days (read days)))
7191        (if (numberp days)
7192            (progn
7193              (setq days-got t)
7194              (if (< days 0)
7195                  (progn
7196                    (setq younger (not younger))
7197                    (setq days (* days -1)))))
7198          (message "Please enter a number.")
7199          (sleep-for 1)))
7200      (list days younger)))
7201   (prog1
7202       (let ((data gnus-newsgroup-data)
7203             (cutoff (days-to-time age))
7204             articles d date is-younger)
7205         (while (setq d (pop data))
7206           (when (and (vectorp (gnus-data-header d))
7207                      (setq date (mail-header-date (gnus-data-header d))))
7208             (setq is-younger (time-less-p
7209                               (time-since (condition-case ()
7210                                               (date-to-time date)
7211                                             (error '(0 0))))
7212                               cutoff))
7213             (when (if younger-p
7214                       is-younger
7215                     (not is-younger))
7216               (push (gnus-data-number d) articles))))
7217         (gnus-summary-limit (nreverse articles)))
7218     (gnus-summary-position-point)))
7219
7220 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7221   "Limit the summary buffer to articles that match an 'extra' header."
7222   (interactive
7223    (let ((header
7224           (intern
7225            (gnus-completing-read-with-default
7226             (symbol-name (car gnus-extra-headers))
7227             (if current-prefix-arg
7228                 "Exclude extra header:"
7229               "Limit extra header:")
7230             (mapcar (lambda (x)
7231                       (cons (symbol-name x) x))
7232                     gnus-extra-headers)
7233             nil
7234             t))))
7235      (list header
7236            (read-string (format "%s header %s (regexp): "
7237                                 (if current-prefix-arg "Exclude" "Limit to")
7238                                 header))
7239            current-prefix-arg)))
7240   (when (not (equal "" regexp))
7241     (prog1
7242         (let ((articles (gnus-summary-find-matching
7243                          (cons 'extra header) regexp 'all nil nil
7244                          not-matching)))
7245           (unless articles
7246             (error "Found no matches for \"%s\"" regexp))
7247           (gnus-summary-limit articles))
7248       (gnus-summary-position-point))))
7249
7250 (defun gnus-summary-limit-to-display-predicate ()
7251   "Limit the summary buffer to the predicated in the `display' group parameter."
7252   (interactive)
7253   (unless gnus-newsgroup-display
7254     (error "There is no `display' group parameter"))
7255   (let (articles)
7256     (dolist (number gnus-newsgroup-articles)
7257       (when (funcall gnus-newsgroup-display)
7258         (push number articles)))
7259     (gnus-summary-limit articles))
7260   (gnus-summary-position-point))
7261
7262 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7263 (make-obsolete
7264  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7265
7266 (defun gnus-summary-limit-to-unread (&optional all)
7267   "Limit the summary buffer to articles that are not marked as read.
7268 If ALL is non-nil, limit strictly to unread articles."
7269   (interactive "P")
7270   (if all
7271       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7272     (gnus-summary-limit-to-marks
7273      ;; Concat all the marks that say that an article is read and have
7274      ;; those removed.
7275      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7276            gnus-killed-mark gnus-kill-file-mark
7277            gnus-low-score-mark gnus-expirable-mark
7278            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7279            gnus-duplicate-mark gnus-souped-mark)
7280      'reverse)))
7281
7282 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7283 (make-obsolete 'gnus-summary-delete-marked-with
7284                'gnus-summary-limit-exlude-marks)
7285
7286 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7287   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7288 If REVERSE, limit the summary buffer to articles that are marked
7289 with MARKS.  MARKS can either be a string of marks or a list of marks.
7290 Returns how many articles were removed."
7291   (interactive "sMarks: ")
7292   (gnus-summary-limit-to-marks marks t))
7293
7294 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7295   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7296 If REVERSE (the prefix), limit the summary buffer to articles that are
7297 not marked with MARKS.  MARKS can either be a string of marks or a
7298 list of marks.
7299 Returns how many articles were removed."
7300   (interactive "sMarks: \nP")
7301   (prog1
7302       (let ((data gnus-newsgroup-data)
7303             (marks (if (listp marks) marks
7304                      (append marks nil))) ; Transform to list.
7305             articles)
7306         (while data
7307           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7308                   (memq (gnus-data-mark (car data)) marks))
7309             (push (gnus-data-number (car data)) articles))
7310           (setq data (cdr data)))
7311         (gnus-summary-limit articles))
7312     (gnus-summary-position-point)))
7313
7314 (defun gnus-summary-limit-to-score (score)
7315   "Limit to articles with score at or above SCORE."
7316   (interactive "NLimit to articles with score of at least: ")
7317   (let ((data gnus-newsgroup-data)
7318         articles)
7319     (while data
7320       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7321                 score)
7322         (push (gnus-data-number (car data)) articles))
7323       (setq data (cdr data)))
7324     (prog1
7325         (gnus-summary-limit articles)
7326       (gnus-summary-position-point))))
7327
7328 (defun gnus-summary-limit-include-thread (id)
7329   "Display all the hidden articles that is in the thread with ID in it.
7330 When called interactively, ID is the Message-ID of the current
7331 article."
7332   (interactive (list (mail-header-id (gnus-summary-article-header))))
7333   (let ((articles (gnus-articles-in-thread
7334                    (gnus-id-to-thread (gnus-root-id id)))))
7335     (prog1
7336         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7337       (gnus-summary-limit-include-matching-articles
7338        "subject"
7339        (regexp-quote (gnus-simplify-subject-re
7340                       (mail-header-subject (gnus-id-to-header id)))))
7341       (gnus-summary-position-point))))
7342
7343 (defun gnus-summary-limit-include-matching-articles (header regexp)
7344   "Display all the hidden articles that have HEADERs that match REGEXP."
7345   (interactive (list (read-string "Match on header: ")
7346                      (read-string "Regexp: ")))
7347   (let ((articles (gnus-find-matching-articles header regexp)))
7348     (prog1
7349         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7350       (gnus-summary-position-point))))
7351
7352 (defun gnus-summary-limit-include-dormant ()
7353   "Display all the hidden articles that are marked as dormant.
7354 Note that this command only works on a subset of the articles currently
7355 fetched for this group."
7356   (interactive)
7357   (unless gnus-newsgroup-dormant
7358     (error "There are no dormant articles in this group"))
7359   (prog1
7360       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7361     (gnus-summary-position-point)))
7362
7363 (defun gnus-summary-limit-exclude-dormant ()
7364   "Hide all dormant articles."
7365   (interactive)
7366   (prog1
7367       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7368     (gnus-summary-position-point)))
7369
7370 (defun gnus-summary-limit-exclude-childless-dormant ()
7371   "Hide all dormant articles that have no children."
7372   (interactive)
7373   (let ((data (gnus-data-list t))
7374         articles d children)
7375     ;; Find all articles that are either not dormant or have
7376     ;; children.
7377     (while (setq d (pop data))
7378       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7379                 (and (setq children
7380                            (gnus-article-children (gnus-data-number d)))
7381                      (let (found)
7382                        (while children
7383                          (when (memq (car children) articles)
7384                            (setq children nil
7385                                  found t))
7386                          (pop children))
7387                        found)))
7388         (push (gnus-data-number d) articles)))
7389     ;; Do the limiting.
7390     (prog1
7391         (gnus-summary-limit articles)
7392       (gnus-summary-position-point))))
7393
7394 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7395   "Mark all unread excluded articles as read.
7396 If ALL, mark even excluded ticked and dormants as read."
7397   (interactive "P")
7398   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7399   (let ((articles (gnus-sorted-ndifference
7400                    (sort
7401                     (mapcar (lambda (h) (mail-header-number h))
7402                             gnus-newsgroup-headers)
7403                     '<)
7404                    gnus-newsgroup-limit))
7405         article)
7406     (setq gnus-newsgroup-unreads
7407           (gnus-sorted-intersection gnus-newsgroup-unreads
7408                                     gnus-newsgroup-limit))
7409     (if all
7410         (setq gnus-newsgroup-dormant nil
7411               gnus-newsgroup-marked nil
7412               gnus-newsgroup-reads
7413               (nconc
7414                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7415                gnus-newsgroup-reads))
7416       (while (setq article (pop articles))
7417         (unless (or (memq article gnus-newsgroup-dormant)
7418                     (memq article gnus-newsgroup-marked))
7419           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7420
7421 (defun gnus-summary-limit (articles &optional pop)
7422   (if pop
7423       ;; We pop the previous limit off the stack and use that.
7424       (setq articles (car gnus-newsgroup-limits)
7425             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7426     ;; We use the new limit, so we push the old limit on the stack.
7427     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7428   ;; Set the limit.
7429   (setq gnus-newsgroup-limit articles)
7430   (let ((total (length gnus-newsgroup-data))
7431         (data (gnus-data-find-list (gnus-summary-article-number)))
7432         (gnus-summary-mark-below nil)   ; Inhibit this.
7433         found)
7434     ;; This will do all the work of generating the new summary buffer
7435     ;; according to the new limit.
7436     (gnus-summary-prepare)
7437     ;; Hide any threads, possibly.
7438     (gnus-summary-maybe-hide-threads)
7439     ;; Try to return to the article you were at, or one in the
7440     ;; neighborhood.
7441     (when data
7442       ;; We try to find some article after the current one.
7443       (while data
7444         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7445           (setq data nil
7446                 found t))
7447         (setq data (cdr data))))
7448     (unless found
7449       ;; If there is no data, that means that we were after the last
7450       ;; article.  The same goes when we can't find any articles
7451       ;; after the current one.
7452       (goto-char (point-max))
7453       (gnus-summary-find-prev))
7454     (gnus-set-mode-line 'summary)
7455     ;; We return how many articles were removed from the summary
7456     ;; buffer as a result of the new limit.
7457     (- total (length gnus-newsgroup-data))))
7458
7459 (defsubst gnus-invisible-cut-children (threads)
7460   (let ((num 0))
7461     (while threads
7462       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7463         (incf num))
7464       (pop threads))
7465     (< num 2)))
7466
7467 (defsubst gnus-cut-thread (thread)
7468   "Go forwards in the thread until we find an article that we want to display."
7469   (when (or (eq gnus-fetch-old-headers 'some)
7470             (eq gnus-fetch-old-headers 'invisible)
7471             (numberp gnus-fetch-old-headers)
7472             (eq gnus-build-sparse-threads 'some)
7473             (eq gnus-build-sparse-threads 'more))
7474     ;; Deal with old-fetched headers and sparse threads.
7475     (while (and
7476             thread
7477             (or
7478              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7479              (gnus-summary-article-ancient-p
7480               (mail-header-number (car thread))))
7481             (if (or (<= (length (cdr thread)) 1)
7482                     (eq gnus-fetch-old-headers 'invisible))
7483                 (setq gnus-newsgroup-limit
7484                       (delq (mail-header-number (car thread))
7485                             gnus-newsgroup-limit)
7486                       thread (cadr thread))
7487               (when (gnus-invisible-cut-children (cdr thread))
7488                 (let ((th (cdr thread)))
7489                   (while th
7490                     (if (memq (mail-header-number (caar th))
7491                               gnus-newsgroup-limit)
7492                         (setq thread (car th)
7493                               th nil)
7494                       (setq th (cdr th))))))))))
7495   thread)
7496
7497 (defun gnus-cut-threads (threads)
7498   "Cut off all uninteresting articles from the beginning of threads."
7499   (when (or (eq gnus-fetch-old-headers 'some)
7500             (eq gnus-fetch-old-headers 'invisible)
7501             (numberp gnus-fetch-old-headers)
7502             (eq gnus-build-sparse-threads 'some)
7503             (eq gnus-build-sparse-threads 'more))
7504     (let ((th threads))
7505       (while th
7506         (setcar th (gnus-cut-thread (car th)))
7507         (setq th (cdr th)))))
7508   ;; Remove nixed out threads.
7509   (delq nil threads))
7510
7511 (defun gnus-summary-initial-limit (&optional show-if-empty)
7512   "Figure out what the initial limit is supposed to be on group entry.
7513 This entails weeding out unwanted dormants, low-scored articles,
7514 fetch-old-headers verbiage, and so on."
7515   ;; Most groups have nothing to remove.
7516   (if (or gnus-inhibit-limiting
7517           (and (null gnus-newsgroup-dormant)
7518                (eq gnus-newsgroup-display 'gnus-not-ignore)
7519                (not (eq gnus-fetch-old-headers 'some))
7520                (not (numberp gnus-fetch-old-headers))
7521                (not (eq gnus-fetch-old-headers 'invisible))
7522                (null gnus-summary-expunge-below)
7523                (not (eq gnus-build-sparse-threads 'some))
7524                (not (eq gnus-build-sparse-threads 'more))
7525                (null gnus-thread-expunge-below)
7526                (not gnus-use-nocem)))
7527       ()                                ; Do nothing.
7528     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7529     (setq gnus-newsgroup-limit nil)
7530     (mapatoms
7531      (lambda (node)
7532        (unless (car (symbol-value node))
7533          ;; These threads have no parents -- they are roots.
7534          (let ((nodes (cdr (symbol-value node)))
7535                thread)
7536            (while nodes
7537              (if (and gnus-thread-expunge-below
7538                       (< (gnus-thread-total-score (car nodes))
7539                          gnus-thread-expunge-below))
7540                  (gnus-expunge-thread (pop nodes))
7541                (setq thread (pop nodes))
7542                (gnus-summary-limit-children thread))))))
7543      gnus-newsgroup-dependencies)
7544     ;; If this limitation resulted in an empty group, we might
7545     ;; pop the previous limit and use it instead.
7546     (when (and (not gnus-newsgroup-limit)
7547                show-if-empty)
7548       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7549     gnus-newsgroup-limit))
7550
7551 (defun gnus-summary-limit-children (thread)
7552   "Return 1 if this subthread is visible and 0 if it is not."
7553   ;; First we get the number of visible children to this thread.  This
7554   ;; is done by recursing down the thread using this function, so this
7555   ;; will really go down to a leaf article first, before slowly
7556   ;; working its way up towards the root.
7557   (when thread
7558     (let ((children
7559            (if (cdr thread)
7560                (apply '+ (mapcar 'gnus-summary-limit-children
7561                                  (cdr thread)))
7562              0))
7563           (number (mail-header-number (car thread)))
7564           score)
7565       (if (and
7566            (not (memq number gnus-newsgroup-marked))
7567            (or
7568             ;; If this article is dormant and has absolutely no visible
7569             ;; children, then this article isn't visible.
7570             (and (memq number gnus-newsgroup-dormant)
7571                  (zerop children))
7572             ;; If this is "fetch-old-headered" and there is no
7573             ;; visible children, then we don't want this article.
7574             (and (or (eq gnus-fetch-old-headers 'some)
7575                      (numberp gnus-fetch-old-headers))
7576                  (gnus-summary-article-ancient-p number)
7577                  (zerop children))
7578             ;; If this is "fetch-old-headered" and `invisible', then
7579             ;; we don't want this article.
7580             (and (eq gnus-fetch-old-headers 'invisible)
7581                  (gnus-summary-article-ancient-p number))
7582             ;; If this is a sparsely inserted article with no children,
7583             ;; we don't want it.
7584             (and (eq gnus-build-sparse-threads 'some)
7585                  (gnus-summary-article-sparse-p number)
7586                  (zerop children))
7587             ;; If we use expunging, and this article is really
7588             ;; low-scored, then we don't want this article.
7589             (when (and gnus-summary-expunge-below
7590                        (< (setq score
7591                                 (or (cdr (assq number gnus-newsgroup-scored))
7592                                     gnus-summary-default-score))
7593                           gnus-summary-expunge-below))
7594               ;; We increase the expunge-tally here, but that has
7595               ;; nothing to do with the limits, really.
7596               (incf gnus-newsgroup-expunged-tally)
7597               ;; We also mark as read here, if that's wanted.
7598               (when (and gnus-summary-mark-below
7599                          (< score gnus-summary-mark-below))
7600                 (setq gnus-newsgroup-unreads
7601                       (delq number gnus-newsgroup-unreads))
7602                 (if gnus-newsgroup-auto-expire
7603                     (push number gnus-newsgroup-expirable)
7604                   (push (cons number gnus-low-score-mark)
7605                         gnus-newsgroup-reads)))
7606               t)
7607             ;; Do the `display' group parameter.
7608             (and gnus-newsgroup-display
7609                  (not (funcall gnus-newsgroup-display)))
7610             ;; Check NoCeM things.
7611             (if (and gnus-use-nocem
7612                      (gnus-nocem-unwanted-article-p
7613                       (mail-header-id (car thread))))
7614                 (progn
7615                   (setq gnus-newsgroup-unreads
7616                         (delq number gnus-newsgroup-unreads))
7617                   t))))
7618           ;; Nope, invisible article.
7619           0
7620         ;; Ok, this article is to be visible, so we add it to the limit
7621         ;; and return 1.
7622         (push number gnus-newsgroup-limit)
7623         1))))
7624
7625 (defun gnus-expunge-thread (thread)
7626   "Mark all articles in THREAD as read."
7627   (let* ((number (mail-header-number (car thread))))
7628     (incf gnus-newsgroup-expunged-tally)
7629     ;; We also mark as read here, if that's wanted.
7630     (setq gnus-newsgroup-unreads
7631           (delq number gnus-newsgroup-unreads))
7632     (if gnus-newsgroup-auto-expire
7633         (push number gnus-newsgroup-expirable)
7634       (push (cons number gnus-low-score-mark)
7635             gnus-newsgroup-reads)))
7636   ;; Go recursively through all subthreads.
7637   (mapcar 'gnus-expunge-thread (cdr thread)))
7638
7639 ;; Summary article oriented commands
7640
7641 (defun gnus-summary-refer-parent-article (n)
7642   "Refer parent article N times.
7643 If N is negative, go to ancestor -N instead.
7644 The difference between N and the number of articles fetched is returned."
7645   (interactive "p")
7646   (let ((skip 1)
7647         error header ref)
7648     (when (not (natnump n))
7649       (setq skip (abs n)
7650             n 1))
7651     (while (and (> n 0)
7652                 (not error))
7653       (setq header (gnus-summary-article-header))
7654       (if (and (eq (mail-header-number header)
7655                    (cdr gnus-article-current))
7656                (equal gnus-newsgroup-name
7657                       (car gnus-article-current)))
7658           ;; If we try to find the parent of the currently
7659           ;; displayed article, then we take a look at the actual
7660           ;; References header, since this is slightly more
7661           ;; reliable than the References field we got from the
7662           ;; server.
7663           (save-excursion
7664             (set-buffer gnus-original-article-buffer)
7665             (nnheader-narrow-to-headers)
7666             (unless (setq ref (message-fetch-field "references"))
7667               (setq ref (message-fetch-field "in-reply-to")))
7668             (widen))
7669         (setq ref
7670               ;; It's not the current article, so we take a bet on
7671               ;; the value we got from the server.
7672               (mail-header-references header)))
7673       (if (and ref
7674                (not (equal ref "")))
7675           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7676             (gnus-message 1 "Couldn't find parent"))
7677         (gnus-message 1 "No references in article %d"
7678                       (gnus-summary-article-number))
7679         (setq error t))
7680       (decf n))
7681     (gnus-summary-position-point)
7682     n))
7683
7684 (defun gnus-summary-refer-references ()
7685   "Fetch all articles mentioned in the References header.
7686 Return the number of articles fetched."
7687   (interactive)
7688   (let ((ref (mail-header-references (gnus-summary-article-header)))
7689         (current (gnus-summary-article-number))
7690         (n 0))
7691     (if (or (not ref)
7692             (equal ref ""))
7693         (error "No References in the current article")
7694       ;; For each Message-ID in the References header...
7695       (while (string-match "<[^>]*>" ref)
7696         (incf n)
7697         ;; ... fetch that article.
7698         (gnus-summary-refer-article
7699          (prog1 (match-string 0 ref)
7700            (setq ref (substring ref (match-end 0))))))
7701       (gnus-summary-goto-subject current)
7702       (gnus-summary-position-point)
7703       n)))
7704
7705 (defun gnus-summary-refer-thread (&optional limit)
7706   "Fetch all articles in the current thread.
7707 If LIMIT (the numerical prefix), fetch that many old headers instead
7708 of what's specified by the `gnus-refer-thread-limit' variable."
7709   (interactive "P")
7710   (let ((id (mail-header-id (gnus-summary-article-header)))
7711         (limit (if limit (prefix-numeric-value limit)
7712                  gnus-refer-thread-limit)))
7713     ;; We want to fetch LIMIT *old* headers, but we also have to
7714     ;; re-fetch all the headers in the current buffer, because many of
7715     ;; them may be undisplayed.  So we adjust LIMIT.
7716     (when (numberp limit)
7717       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7718     (unless (eq gnus-fetch-old-headers 'invisible)
7719       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7720       ;; Retrieve the headers and read them in.
7721       (if (eq (gnus-retrieve-headers
7722                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7723               'nov)
7724           (gnus-build-all-threads)
7725         (error "Can't fetch thread from backends that don't support NOV"))
7726       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7727     (gnus-summary-limit-include-thread id)))
7728
7729 (defun gnus-summary-refer-article (message-id)
7730   "Fetch an article specified by MESSAGE-ID."
7731   (interactive "sMessage-ID: ")
7732   (when (and (stringp message-id)
7733              (not (zerop (length message-id))))
7734     ;; Construct the correct Message-ID if necessary.
7735     ;; Suggested by tale@pawl.rpi.edu.
7736     (unless (string-match "^<" message-id)
7737       (setq message-id (concat "<" message-id)))
7738     (unless (string-match ">$" message-id)
7739       (setq message-id (concat message-id ">")))
7740     (let* ((header (gnus-id-to-header message-id))
7741            (sparse (and header
7742                         (gnus-summary-article-sparse-p
7743                          (mail-header-number header))
7744                         (memq (mail-header-number header)
7745                               gnus-newsgroup-limit)))
7746            number)
7747       (cond
7748        ;; If the article is present in the buffer we just go to it.
7749        ((and header
7750              (or (not (gnus-summary-article-sparse-p
7751                        (mail-header-number header)))
7752                  sparse))
7753         (prog1
7754             (gnus-summary-goto-article
7755              (mail-header-number header) nil t)
7756           (when sparse
7757             (gnus-summary-update-article (mail-header-number header)))))
7758        (t
7759         ;; We fetch the article.
7760         (catch 'found
7761           (dolist (gnus-override-method (gnus-refer-article-methods))
7762             (gnus-check-server gnus-override-method)
7763             ;; Fetch the header, and display the article.
7764             (when (setq number (gnus-summary-insert-subject message-id))
7765               (gnus-summary-select-article nil nil nil number)
7766               (throw 'found t)))
7767           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7768
7769 (defun gnus-refer-article-methods ()
7770   "Return a list of referrable methods."
7771   (cond
7772    ;; No method, so we default to current and native.
7773    ((null gnus-refer-article-method)
7774     (list gnus-current-select-method gnus-select-method))
7775    ;; Current.
7776    ((eq 'current gnus-refer-article-method)
7777     (list gnus-current-select-method))
7778    ;; List of select methods.
7779    ((not (and (symbolp (car gnus-refer-article-method))
7780               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7781     (let (out)
7782       (dolist (method gnus-refer-article-method)
7783         (push (if (eq 'current method)
7784                   gnus-current-select-method
7785                 method)
7786               out))
7787       (nreverse out)))
7788    ;; One single select method.
7789    (t
7790     (list gnus-refer-article-method))))
7791
7792 (defun gnus-summary-edit-parameters ()
7793   "Edit the group parameters of the current group."
7794   (interactive)
7795   (gnus-group-edit-group gnus-newsgroup-name 'params))
7796
7797 (defun gnus-summary-customize-parameters ()
7798   "Customize the group parameters of the current group."
7799   (interactive)
7800   (gnus-group-customize gnus-newsgroup-name))
7801
7802 (defun gnus-summary-enter-digest-group (&optional force)
7803   "Enter an nndoc group based on the current article.
7804 If FORCE, force a digest interpretation.  If not, try
7805 to guess what the document format is."
7806   (interactive "P")
7807   (let ((conf gnus-current-window-configuration))
7808     (save-excursion
7809       (gnus-summary-select-article))
7810     (setq gnus-current-window-configuration conf)
7811     (let* ((name (format "%s-%d"
7812                          (gnus-group-prefixed-name
7813                           gnus-newsgroup-name (list 'nndoc ""))
7814                          (save-excursion
7815                            (set-buffer gnus-summary-buffer)
7816                            gnus-current-article)))
7817            (ogroup gnus-newsgroup-name)
7818            (params (append (gnus-info-params (gnus-get-info ogroup))
7819                            (list (cons 'to-group ogroup))
7820                            (list (cons 'save-article-group ogroup))))
7821            (case-fold-search t)
7822            (buf (current-buffer))
7823            dig to-address)
7824       (save-excursion
7825         (set-buffer gnus-original-article-buffer)
7826         ;; Have the digest group inherit the main mail address of
7827         ;; the parent article.
7828         (when (setq to-address (or (message-fetch-field "reply-to")
7829                                    (message-fetch-field "from")))
7830           (setq params (append
7831                         (list (cons 'to-address
7832                                     (funcall gnus-decode-encoded-word-function
7833                                              to-address))))))
7834         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7835         (insert-buffer-substring gnus-original-article-buffer)
7836         ;; Remove lines that may lead nndoc to misinterpret the
7837         ;; document type.
7838         (narrow-to-region
7839          (goto-char (point-min))
7840          (or (search-forward "\n\n" nil t) (point)))
7841         (goto-char (point-min))
7842         (delete-matching-lines "^Path:\\|^From ")
7843         (widen))
7844       (unwind-protect
7845           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7846                     (gnus-newsgroup-ephemeral-ignored-charsets
7847                      gnus-newsgroup-ignored-charsets))
7848                 (gnus-group-read-ephemeral-group
7849                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7850                               (nndoc-article-type
7851                                ,(if force 'mbox 'guess)))
7852                  t nil nil nil
7853                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7854                                                         "ADAPT")))))
7855               ;; Make all postings to this group go to the parent group.
7856               (nconc (gnus-info-params (gnus-get-info name))
7857                      params)
7858             ;; Couldn't select this doc group.
7859             (switch-to-buffer buf)
7860             (gnus-set-global-variables)
7861             (gnus-configure-windows 'summary)
7862             (gnus-message 3 "Article couldn't be entered?"))
7863         (kill-buffer dig)))))
7864
7865 (defun gnus-summary-read-document (n)
7866   "Open a new group based on the current article(s).
7867 This will allow you to read digests and other similar
7868 documents as newsgroups.
7869 Obeys the standard process/prefix convention."
7870   (interactive "P")
7871   (let* ((articles (gnus-summary-work-articles n))
7872          (ogroup gnus-newsgroup-name)
7873          (params (append (gnus-info-params (gnus-get-info ogroup))
7874                          (list (cons 'to-group ogroup))))
7875          article group egroup groups vgroup)
7876     (while (setq article (pop articles))
7877       (setq group (format "%s-%d" gnus-newsgroup-name article))
7878       (gnus-summary-remove-process-mark article)
7879       (when (gnus-summary-display-article article)
7880         (save-excursion
7881           (with-temp-buffer
7882             (insert-buffer-substring gnus-original-article-buffer)
7883             ;; Remove some headers that may lead nndoc to make
7884             ;; the wrong guess.
7885             (message-narrow-to-head)
7886             (goto-char (point-min))
7887             (delete-matching-lines "^\\(Path\\):\\|^From ")
7888             (widen)
7889             (if (setq egroup
7890                       (gnus-group-read-ephemeral-group
7891                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7892                                      (nndoc-article-type guess))
7893                        t nil t))
7894                 (progn
7895                   ;; Make all postings to this group go to the parent group.
7896                   (nconc (gnus-info-params (gnus-get-info egroup))
7897                          params)
7898                   (push egroup groups))
7899               ;; Couldn't select this doc group.
7900               (gnus-error 3 "Article couldn't be entered"))))))
7901     ;; Now we have selected all the documents.
7902     (cond
7903      ((not groups)
7904       (error "None of the articles could be interpreted as documents"))
7905      ((gnus-group-read-ephemeral-group
7906        (setq vgroup (format
7907                      "nnvirtual:%s-%s" gnus-newsgroup-name
7908                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7909        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7910        t
7911        (cons (current-buffer) 'summary)))
7912      (t
7913       (error "Couldn't select virtual nndoc group")))))
7914
7915 (defun gnus-summary-isearch-article (&optional regexp-p)
7916   "Do incremental search forward on the current article.
7917 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7918   (interactive "P")
7919   (let* ((gnus-inhibit-treatment t)
7920          (old (gnus-summary-select-article)))
7921     (gnus-configure-windows 'article)
7922     (gnus-eval-in-buffer-window gnus-article-buffer
7923       (save-restriction
7924         (widen)
7925         (when (eq 'old old)
7926           (gnus-article-show-all-headers))
7927         (goto-char (point-min))
7928         (isearch-forward regexp-p)))))
7929
7930 (defun gnus-summary-search-article-forward (regexp &optional backward)
7931   "Search for an article containing REGEXP forward.
7932 If BACKWARD, search backward instead."
7933   (interactive
7934    (list (read-string
7935           (format "Search article %s (regexp%s): "
7936                   (if current-prefix-arg "backward" "forward")
7937                   (if gnus-last-search-regexp
7938                       (concat ", default " gnus-last-search-regexp)
7939                     "")))
7940          current-prefix-arg))
7941   (if (string-equal regexp "")
7942       (setq regexp (or gnus-last-search-regexp ""))
7943     (setq gnus-last-search-regexp regexp)
7944     (setq gnus-article-before-search gnus-current-article))
7945   ;; Intentionally set gnus-last-article.
7946   (setq gnus-last-article gnus-article-before-search)
7947   (let ((gnus-last-article gnus-last-article))
7948     (if (gnus-summary-search-article regexp backward)
7949         (gnus-summary-show-thread)
7950       (error "Search failed: \"%s\"" regexp))))
7951
7952 (defun gnus-summary-search-article-backward (regexp)
7953   "Search for an article containing REGEXP backward."
7954   (interactive
7955    (list (read-string
7956           (format "Search article backward (regexp%s): "
7957                   (if gnus-last-search-regexp
7958                       (concat ", default " gnus-last-search-regexp)
7959                     "")))))
7960   (gnus-summary-search-article-forward regexp 'backward))
7961
7962 (eval-when-compile
7963   (defmacro gnus-summary-search-article-position-point (regexp backward)
7964     "Dehighlight the last matched text and goto the beginning position."
7965     (` (if (and gnus-summary-search-article-matched-data
7966                 (let ((text (caddr gnus-summary-search-article-matched-data))
7967                       (inhibit-read-only t)
7968                       buffer-read-only)
7969                   (delete-region
7970                    (goto-char (car gnus-summary-search-article-matched-data))
7971                    (cadr gnus-summary-search-article-matched-data))
7972                   (insert text)
7973                   (string-match (, regexp) text)))
7974            (if (, backward) (beginning-of-line) (end-of-line))
7975          (goto-char (if (, backward) (point-max) (point-min))))))
7976
7977   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7978     "Place point where X-Face image is displayed."
7979     (if (featurep 'xemacs)
7980         (` (let ((end (if (search-forward "\n\n" nil t)
7981                           (goto-char (1- (point)))
7982                         (point-min)))
7983                  extent)
7984              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7985              (unless (and (re-search-forward "^From:" end t)
7986                           (setq extent (extent-at (point)))
7987                           (extent-begin-glyph extent))
7988                (goto-char (, opoint)))))
7989       (` (let ((end (if (search-forward "\n\n" nil t)
7990                         (goto-char (1- (point)))
7991                       (point-min)))
7992                (start (or (search-backward "\n\n" nil t) (point-min))))
7993            (goto-char
7994             (or (text-property-any start end 'x-face-image t);; x-face-e21
7995                 (text-property-any start end 'x-face-mule-bitmap-image t)
7996                 (, opoint)))))))
7997
7998   (defmacro gnus-summary-search-article-highlight-matched-text
7999     (backward treated x-face)
8000     "Highlight matched text in the function `gnus-summary-search-article'."
8001     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8002              (end (set-marker (make-marker) (match-end 0)))
8003              (inhibit-read-only t)
8004              buffer-read-only)
8005          (unless treated
8006            (let ((,@
8007                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8008                     (mapcar
8009                      (lambda (item) (setq items (delq item items)))
8010                      '(gnus-treat-buttonize
8011                        gnus-treat-fill-article
8012                        gnus-treat-fill-long-lines
8013                        gnus-treat-emphasize
8014                        gnus-treat-highlight-headers
8015                        gnus-treat-highlight-citation
8016                        gnus-treat-highlight-signature
8017                        gnus-treat-overstrike
8018                        gnus-treat-display-xface
8019                        gnus-treat-buttonize-head
8020                        gnus-treat-decode-article-as-default-mime-charset))
8021                     (static-if (featurep 'xemacs)
8022                         items
8023                       (cons '(x-face-mule-delete-x-face-field
8024                               (quote never))
8025                             items))))
8026                  (gnus-treat-display-xface
8027                   (when (, x-face) gnus-treat-display-xface)))
8028              (gnus-article-prepare-mime-display)))
8029          (goto-char (if (, backward) start end))
8030          (when (, x-face)
8031            (gnus-summary-search-article-highlight-goto-x-face (point)))
8032          (setq gnus-summary-search-article-matched-data
8033                (list start end (buffer-substring start end)))
8034          (unless (eq start end);; matched text has been deleted. :-<
8035            (put-text-property start end 'face
8036                               (or (find-face 'isearch)
8037                                   'secondary-selection))))))
8038   )
8039
8040 (defun gnus-summary-search-article (regexp &optional backward)
8041   "Search for an article containing REGEXP.
8042 Optional argument BACKWARD means do search for backward.
8043 `gnus-select-article-hook' is not called during the search."
8044   ;; We have to require this here to make sure that the following
8045   ;; dynamic binding isn't shadowed by autoloading.
8046   (require 'gnus-async)
8047   (require 'gnus-art)
8048   (let ((gnus-select-article-hook nil)  ;Disable hook.
8049         (gnus-article-prepare-hook nil)
8050         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8051         (gnus-use-article-prefetch nil)
8052         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8053         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8054         (sum (current-buffer))
8055         (found nil)
8056         point treated)
8057     (gnus-save-hidden-threads
8058       (static-if (featurep 'xemacs)
8059           (let ((gnus-inhibit-treatment t))
8060             (setq treated (eq 'old (gnus-summary-select-article)))
8061             (when (and treated
8062                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8063                                  (window-live-p (get-buffer-window
8064                                                  gnus-article-buffer t)))))
8065               (gnus-summary-select-article nil t)
8066               (setq treated nil)))
8067         (let ((gnus-inhibit-treatment t)
8068               (x-face-mule-delete-x-face-field 'never))
8069           (setq treated (eq 'old (gnus-summary-select-article)))
8070           (when (and treated
8071                      (not
8072                       (and (gnus-buffer-live-p gnus-article-buffer)
8073                            (window-live-p (get-buffer-window
8074                                            gnus-article-buffer t))
8075                            (or (not (string-match "^\\^X-Face:" regexp))
8076                                (with-current-buffer gnus-article-buffer
8077                                  gnus-summary-search-article-matched-data)))))
8078             (gnus-summary-select-article nil t)
8079             (setq treated nil))))
8080       (set-buffer gnus-article-buffer)
8081       (widen)
8082       (if treated
8083           (progn
8084             (gnus-article-show-all-headers)
8085             (gnus-summary-search-article-position-point regexp backward))
8086         (goto-char (if backward (point-max) (point-min))))
8087       (while (not found)
8088         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8089         (if (if backward
8090                 (re-search-backward regexp nil t)
8091               (re-search-forward regexp nil t))
8092             ;; We found the regexp.
8093             (progn
8094               (gnus-summary-search-article-highlight-matched-text
8095                backward treated (string-match "^\\^X-Face:" regexp))
8096               (setq found 'found)
8097               (forward-line
8098                (/ (- 2 (window-height
8099                         (get-buffer-window gnus-article-buffer t)))
8100                   2))
8101               (set-window-start
8102                (get-buffer-window (current-buffer))
8103                (point))
8104               (set-buffer sum)
8105               (setq point (point)))
8106           ;; We didn't find it, so we go to the next article.
8107           (set-buffer sum)
8108           (setq found 'not)
8109           (while (eq found 'not)
8110             (if (not (if backward (gnus-summary-find-prev)
8111                        (gnus-summary-find-next)))
8112                 ;; No more articles.
8113                 (setq found t)
8114               ;; Select the next article and adjust point.
8115               (unless (gnus-summary-article-sparse-p
8116                        (gnus-summary-article-number))
8117                 (setq found nil)
8118                 (let ((gnus-inhibit-treatment t))
8119                   (gnus-summary-select-article))
8120                 (setq treated nil)
8121                 (set-buffer gnus-article-buffer)
8122                 (widen)
8123                 (goto-char (if backward (point-max) (point-min))))))))
8124       (gnus-message 7 ""))
8125     ;; Return whether we found the regexp.
8126     (when (eq found 'found)
8127       (goto-char point)
8128       (gnus-summary-show-thread)
8129       (gnus-summary-goto-subject gnus-current-article)
8130       (gnus-summary-position-point)
8131       t)))
8132
8133 (defun gnus-find-matching-articles (header regexp)
8134   "Return a list of all articles that match REGEXP on HEADER.
8135 This search includes all articles in the current group that Gnus has
8136 fetched headers for, whether they are displayed or not."
8137   (let ((articles nil)
8138         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8139         (case-fold-search t))
8140     (dolist (header gnus-newsgroup-headers)
8141       (when (string-match regexp (funcall func header))
8142         (push (mail-header-number header) articles)))
8143     (nreverse articles)))
8144
8145 (defun gnus-summary-find-matching (header regexp &optional backward unread
8146                                           not-case-fold not-matching)
8147   "Return a list of all articles that match REGEXP on HEADER.
8148 The search stars on the current article and goes forwards unless
8149 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8150 If UNREAD is non-nil, only unread articles will
8151 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8152 in the comparisons. If NOT-MATCHING, return a list of all articles that
8153 not match REGEXP on HEADER."
8154   (let ((case-fold-search (not not-case-fold))
8155         articles d func)
8156     (if (consp header)
8157         (if (eq (car header) 'extra)
8158             (setq func
8159                   `(lambda (h)
8160                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8161                          "")))
8162           (error "%s is an invalid header" header))
8163       (unless (fboundp (intern (concat "mail-header-" header)))
8164         (error "%s is not a valid header" header))
8165       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8166     (dolist (d (if (eq backward 'all)
8167                    gnus-newsgroup-data
8168                  (gnus-data-find-list
8169                   (gnus-summary-article-number)
8170                   (gnus-data-list backward))))
8171       (when (and (or (not unread)       ; We want all articles...
8172                      (gnus-data-unread-p d)) ; Or just unreads.
8173                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8174                  (if not-matching
8175                      (not (string-match
8176                            regexp
8177                            (funcall func (gnus-data-header d))))
8178                    (string-match regexp
8179                                  (funcall func (gnus-data-header d)))))
8180         (push (gnus-data-number d) articles))) ; Success!
8181     (nreverse articles)))
8182
8183 (defun gnus-summary-execute-command (header regexp command &optional backward)
8184   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8185 If HEADER is an empty string (or nil), the match is done on the entire
8186 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8187   (interactive
8188    (list (let ((completion-ignore-case t))
8189            (completing-read
8190             "Header name: "
8191             (mapcar (lambda (header) (list (format "%s" header)))
8192                     (append
8193                      '("Number" "Subject" "From" "Lines" "Date"
8194                        "Message-ID" "Xref" "References" "Body")
8195                      gnus-extra-headers))
8196             nil 'require-match))
8197          (read-string "Regexp: ")
8198          (read-key-sequence "Command: ")
8199          current-prefix-arg))
8200   (when (equal header "Body")
8201     (setq header ""))
8202   ;; Hidden thread subtrees must be searched as well.
8203   (gnus-summary-show-all-threads)
8204   ;; We don't want to change current point nor window configuration.
8205   (save-excursion
8206     (save-window-excursion
8207       (gnus-message 6 "Executing %s..." (key-description command))
8208       ;; We'd like to execute COMMAND interactively so as to give arguments.
8209       (gnus-execute header regexp
8210                     `(call-interactively ',(key-binding command))
8211                     backward)
8212       (gnus-message 6 "Executing %s...done" (key-description command)))))
8213
8214 (defun gnus-summary-beginning-of-article ()
8215   "Scroll the article back to the beginning."
8216   (interactive)
8217   (gnus-summary-select-article)
8218   (gnus-configure-windows 'article)
8219   (gnus-eval-in-buffer-window gnus-article-buffer
8220     (widen)
8221     (goto-char (point-min))
8222     (when gnus-page-broken
8223       (gnus-narrow-to-page))))
8224
8225 (defun gnus-summary-end-of-article ()
8226   "Scroll to the end of the article."
8227   (interactive)
8228   (gnus-summary-select-article)
8229   (gnus-configure-windows 'article)
8230   (gnus-eval-in-buffer-window gnus-article-buffer
8231     (widen)
8232     (goto-char (point-max))
8233     (recenter -3)
8234     (when gnus-page-broken
8235       (gnus-narrow-to-page))))
8236
8237 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8238   "Truncate to LEN and quote all \"(\"'s in STRING."
8239   (gnus-replace-in-string (if (and len (> (length string) len))
8240                               (substring string 0 len)
8241                             string)
8242                           "[()]" "\\\\\\&"))
8243
8244 (defun gnus-summary-print-article (&optional filename n)
8245   "Generate and print a PostScript image of the N next (mail) articles.
8246
8247 If N is negative, print the N previous articles.  If N is nil and articles
8248 have been marked with the process mark, print these instead.
8249
8250 If the optional first argument FILENAME is nil, send the image to the
8251 printer.  If FILENAME is a string, save the PostScript image in a file with
8252 that name.  If FILENAME is a number, prompt the user for the name of the file
8253 to save in."
8254   (interactive (list (ps-print-preprint current-prefix-arg)))
8255   (dolist (article (gnus-summary-work-articles n))
8256     (gnus-summary-select-article nil nil 'pseudo article)
8257     (gnus-eval-in-buffer-window gnus-article-buffer
8258       (gnus-print-buffer))
8259     (gnus-summary-remove-process-mark article))
8260   (ps-despool filename))
8261
8262 (defun gnus-print-buffer ()
8263   (let ((buffer (generate-new-buffer " *print*")))
8264     (unwind-protect
8265         (progn
8266           (copy-to-buffer buffer (point-min) (point-max))
8267           (set-buffer buffer)
8268           (gnus-article-delete-invisible-text)
8269           (when (gnus-visual-p 'article-highlight 'highlight)
8270             ;; Copy-to-buffer doesn't copy overlay.  So redo
8271             ;; highlight.
8272             (let ((gnus-article-buffer buffer))
8273               (gnus-article-highlight-citation t)
8274               (gnus-article-highlight-signature)))
8275           (let ((ps-left-header
8276                  (list
8277                   (concat "("
8278                           (gnus-summary-print-truncate-and-quote
8279                            (mail-header-subject gnus-current-headers)
8280                            66) ")")
8281                   (concat "("
8282                           (gnus-summary-print-truncate-and-quote
8283                            (mail-header-from gnus-current-headers)
8284                            45) ")")))
8285                 (ps-right-header
8286                  (list
8287                   "/pagenumberstring load"
8288                   (concat "("
8289                           (mail-header-date gnus-current-headers) ")"))))
8290             (gnus-run-hooks 'gnus-ps-print-hook)
8291             (save-excursion
8292               (if window-system
8293                   (ps-spool-buffer-with-faces)
8294                 (ps-spool-buffer)))))
8295       (kill-buffer buffer))))
8296
8297 (defun gnus-summary-show-article (&optional arg)
8298   "Force redisplaying of the current article.
8299 If ARG (the prefix) is a number, show the article with the charset
8300 defined in `gnus-summary-show-article-charset-alist', or the charset
8301 input.
8302 If ARG (the prefix) is non-nil and not a number, show the raw article
8303 without any article massaging functions being run.  Normally, the key strokes
8304 are `C-u g'."
8305   (interactive "P")
8306   (cond
8307    ((numberp arg)
8308     (gnus-summary-show-article t)
8309     (let* ((gnus-newsgroup-charset
8310             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8311                 (mm-read-coding-system
8312                  "View as charset: " ;; actually it is coding system.
8313                  (save-excursion
8314                    (set-buffer gnus-article-buffer)
8315                    (mm-detect-coding-region (point) (point-max))))))
8316            (default-mime-charset gnus-newsgroup-charset)
8317            (gnus-newsgroup-ignored-charsets 'gnus-all))
8318       (gnus-summary-select-article nil 'force)
8319       (let ((deps gnus-newsgroup-dependencies)
8320             head header lines)
8321         (save-excursion
8322           (set-buffer gnus-original-article-buffer)
8323           (save-restriction
8324             (message-narrow-to-head)
8325             (setq head (buffer-string))
8326             (goto-char (point-min))
8327             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8328               (goto-char (point-max))
8329               (widen)
8330               (setq lines (1- (count-lines (point) (point-max))))))
8331           (with-temp-buffer
8332             (insert (format "211 %d Article retrieved.\n"
8333                             (cdr gnus-article-current)))
8334             (insert head)
8335             (if lines (insert (format "Lines: %d\n" lines)))
8336             (insert ".\n")
8337             (let ((nntp-server-buffer (current-buffer)))
8338               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8339         (gnus-data-set-header
8340          (gnus-data-find (cdr gnus-article-current))
8341          header)
8342         (gnus-summary-update-article-line
8343          (cdr gnus-article-current) header)
8344         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8345           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8346    ((not arg)
8347     ;; Select the article the normal way.
8348     (gnus-summary-select-article nil 'force))
8349    (t
8350     ;; We have to require this here to make sure that the following
8351     ;; dynamic binding isn't shadowed by autoloading.
8352     (require 'gnus-async)
8353     (require 'gnus-art)
8354     ;; Bind the article treatment functions to nil.
8355     (let ((gnus-have-all-headers t)
8356           gnus-article-prepare-hook
8357           gnus-article-decode-hook
8358           gnus-break-pages
8359           gnus-show-mime
8360           (gnus-inhibit-treatment t))
8361       (gnus-summary-select-article nil 'force))))
8362   (gnus-summary-goto-subject gnus-current-article)
8363   (gnus-summary-position-point))
8364
8365 (defun gnus-summary-show-raw-article ()
8366   "Show the raw article without any article massaging functions being run."
8367   (interactive)
8368   (gnus-summary-show-article t))
8369
8370 (defun gnus-summary-verbose-headers (&optional arg)
8371   "Toggle permanent full header display.
8372 If ARG is a positive number, turn header display on.
8373 If ARG is a negative number, turn header display off."
8374   (interactive "P")
8375   (setq gnus-show-all-headers
8376         (cond ((or (not (numberp arg))
8377                    (zerop arg))
8378                (not gnus-show-all-headers))
8379               ((natnump arg)
8380                t)))
8381   (gnus-summary-show-article))
8382
8383 (defun gnus-summary-toggle-header (&optional arg)
8384   "Show the headers if they are hidden, or hide them if they are shown.
8385 If ARG is a positive number, show the entire header.
8386 If ARG is a negative number, hide the unwanted header lines."
8387   (interactive "P")
8388   (save-excursion
8389     (set-buffer gnus-article-buffer)
8390     (save-restriction
8391       (let* ((buffer-read-only nil)
8392              (inhibit-point-motion-hooks t)
8393              hidden e)
8394         (save-restriction
8395           (article-narrow-to-head)
8396           (setq e (point-max)
8397                 hidden (if (numberp arg)
8398                            (>= arg 0)
8399                          (gnus-article-hidden-text-p 'headers))))
8400         (delete-region (point-min) e)
8401         (goto-char (point-min))
8402         (save-excursion
8403           (set-buffer gnus-original-article-buffer)
8404           (goto-char (point-min))
8405           (setq e (search-forward "\n\n" nil t)
8406                 e (if e (1- e) (point-max))))
8407         (insert-buffer-substring gnus-original-article-buffer 1 e)
8408         (save-restriction
8409           (narrow-to-region (point-min) (point))
8410           (article-decode-encoded-words)
8411           (if  hidden
8412               (let ((gnus-treat-hide-headers nil)
8413                     (gnus-treat-hide-boring-headers nil))
8414                 (gnus-delete-wash-type 'headers)
8415                 (gnus-treat-article 'head))
8416             (gnus-treat-article 'head)))
8417         (gnus-set-mode-line 'article)))))
8418
8419 (defun gnus-summary-show-all-headers ()
8420   "Make all header lines visible."
8421   (interactive)
8422   (gnus-summary-toggle-header 1))
8423
8424 (defun gnus-summary-toggle-mime (&optional arg)
8425   "Toggle MIME processing.
8426 If ARG is a positive number, turn MIME processing on."
8427   (interactive "P")
8428   (setq gnus-show-mime
8429         (if (null arg)
8430             (not gnus-show-mime)
8431           (> (prefix-numeric-value arg) 0)))
8432   (gnus-summary-select-article t 'force))
8433
8434 (defun gnus-summary-caesar-message (&optional arg)
8435   "Caesar rotate the current article by 13.
8436 The numerical prefix specifies how many places to rotate each letter
8437 forward."
8438   (interactive "P")
8439   (gnus-summary-select-article)
8440   (let ((mail-header-separator ""))
8441     (gnus-eval-in-buffer-window gnus-article-buffer
8442       (save-restriction
8443         (widen)
8444         (let ((start (window-start))
8445               buffer-read-only)
8446           (message-caesar-buffer-body arg)
8447           (set-window-start (get-buffer-window (current-buffer)) start))))))
8448
8449 (defun gnus-summary-stop-page-breaking ()
8450   "Stop page breaking in the current article."
8451   (interactive)
8452   (gnus-summary-select-article)
8453   (gnus-eval-in-buffer-window gnus-article-buffer
8454     (widen)
8455     (when (gnus-visual-p 'page-marker)
8456       (let ((buffer-read-only nil))
8457         (gnus-remove-text-with-property 'gnus-prev)
8458         (gnus-remove-text-with-property 'gnus-next))
8459       (setq gnus-page-broken nil))))
8460
8461 (defun gnus-summary-move-article (&optional n to-newsgroup
8462                                             select-method action)
8463   "Move the current article to a different newsgroup.
8464 If N is a positive number, move the N next articles.
8465 If N is a negative number, move the N previous articles.
8466 If N is nil and any articles have been marked with the process mark,
8467 move those articles instead.
8468 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8469 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8470 re-spool using this method.
8471
8472 For this function to work, both the current newsgroup and the
8473 newsgroup that you want to move to have to support the `request-move'
8474 and `request-accept' functions.
8475
8476 ACTION can be either `move' (the default), `crosspost' or `copy'."
8477   (interactive "P")
8478   (unless action
8479     (setq action 'move))
8480   ;; Check whether the source group supports the required functions.
8481   (cond ((and (eq action 'move)
8482               (not (gnus-check-backend-function
8483                     'request-move-article gnus-newsgroup-name)))
8484          (error "The current group does not support article moving"))
8485         ((and (eq action 'crosspost)
8486               (not (gnus-check-backend-function
8487                     'request-replace-article gnus-newsgroup-name)))
8488          (error "The current group does not support article editing")))
8489   (let ((articles (gnus-summary-work-articles n))
8490         (prefix (if (gnus-check-backend-function
8491                      'request-move-article gnus-newsgroup-name)
8492                     (gnus-group-real-prefix gnus-newsgroup-name)
8493                   ""))
8494         (names '((move "Move" "Moving")
8495                  (copy "Copy" "Copying")
8496                  (crosspost "Crosspost" "Crossposting")))
8497         (copy-buf (save-excursion
8498                     (nnheader-set-temp-buffer " *copy article*")))
8499         (default-marks gnus-article-mark-lists)
8500         (no-expire-marks (delete '(expirable . expire)
8501                                  (copy-sequence gnus-article-mark-lists)))
8502         art-group to-method new-xref article to-groups)
8503     (unless (assq action names)
8504       (error "Unknown action %s" action))
8505     ;; Read the newsgroup name.
8506     (when (and (not to-newsgroup)
8507                (not select-method))
8508       (if (and gnus-move-split-methods
8509                (not
8510                 (and (memq gnus-current-article articles)
8511                      (gnus-buffer-live-p gnus-original-article-buffer))))
8512           ;; When `gnus-move-split-methods' is non-nil, we have to
8513           ;; select an article to give `gnus-read-move-group-name' an
8514           ;; opportunity to suggest an appropriate default.  However,
8515           ;; we needn't render or mark the article.
8516           (let ((gnus-display-mime-function nil)
8517                 (gnus-article-prepare-hook nil)
8518                 (gnus-mark-article-hook nil))
8519             (gnus-summary-select-article nil nil nil (car articles))))
8520       (setq to-newsgroup
8521             (gnus-read-move-group-name
8522              (cadr (assq action names))
8523              (symbol-value (intern (format "gnus-current-%s-group" action)))
8524              articles prefix))
8525       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8526     (setq to-method (or select-method
8527                         (gnus-server-to-method
8528                          (gnus-group-method to-newsgroup))))
8529     ;; Check the method we are to move this article to...
8530     (unless (gnus-check-backend-function
8531              'request-accept-article (car to-method))
8532       (error "%s does not support article copying" (car to-method)))
8533     (unless (gnus-check-server to-method)
8534       (error "Can't open server %s" (car to-method)))
8535     (gnus-message 6 "%s to %s: %s..."
8536                   (caddr (assq action names))
8537                   (or (car select-method) to-newsgroup) articles)
8538     (while articles
8539       (setq article (pop articles))
8540       (setq
8541        art-group
8542        (cond
8543         ;; Move the article.
8544         ((eq action 'move)
8545          ;; Remove this article from future suppression.
8546          (gnus-dup-unsuppress-article article)
8547          (gnus-request-move-article
8548           article                       ; Article to move
8549           gnus-newsgroup-name           ; From newsgroup
8550           (nth 1 (gnus-find-method-for-group
8551                   gnus-newsgroup-name)) ; Server
8552           (list 'gnus-request-accept-article
8553                 to-newsgroup (list 'quote select-method)
8554                 (not articles) t)       ; Accept form
8555           (not articles)))              ; Only save nov last time
8556         ;; Copy the article.
8557         ((eq action 'copy)
8558          (save-excursion
8559            (set-buffer copy-buf)
8560            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8561              (gnus-request-accept-article
8562               to-newsgroup select-method (not articles) t))))
8563         ;; Crosspost the article.
8564         ((eq action 'crosspost)
8565          (let ((xref (message-tokenize-header
8566                       (mail-header-xref (gnus-summary-article-header article))
8567                       " ")))
8568            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8569                                   ":" (number-to-string article)))
8570            (unless xref
8571              (setq xref (list (system-name))))
8572            (setq new-xref
8573                  (concat
8574                   (mapconcat 'identity
8575                              (delete "Xref:" (delete new-xref xref))
8576                              " ")
8577                   " " new-xref))
8578            (save-excursion
8579              (set-buffer copy-buf)
8580              ;; First put the article in the destination group.
8581              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8582              (when (consp (setq art-group
8583                                 (gnus-request-accept-article
8584                                  to-newsgroup select-method (not articles))))
8585                (setq new-xref (concat new-xref " " (car art-group)
8586                                       ":"
8587                                       (number-to-string (cdr art-group))))
8588                ;; Now we have the new Xrefs header, so we insert
8589                ;; it and replace the new article.
8590                (nnheader-replace-header "Xref" new-xref)
8591                (gnus-request-replace-article
8592                 (cdr art-group) to-newsgroup (current-buffer))
8593                art-group))))))
8594       (cond
8595        ((not art-group)
8596         (gnus-message 1 "Couldn't %s article %s: %s"
8597                       (cadr (assq action names)) article
8598                       (nnheader-get-report (car to-method))))
8599        ((eq art-group 'junk)
8600         (when (eq action 'move)
8601           (gnus-summary-mark-article article gnus-canceled-mark)
8602           (gnus-message 4 "Deleted article %s" article)))
8603        (t
8604         (let* ((pto-group (gnus-group-prefixed-name
8605                            (car art-group) to-method))
8606                (entry
8607                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8608                (info (nth 2 entry))
8609                (to-group (gnus-info-group info))
8610                to-marks)
8611           ;; Update the group that has been moved to.
8612           (when (and info
8613                      (memq action '(move copy)))
8614             (unless (member to-group to-groups)
8615               (push to-group to-groups))
8616
8617             (unless (memq article gnus-newsgroup-unreads)
8618               (push 'read to-marks)
8619               (gnus-info-set-read
8620                info (gnus-add-to-range (gnus-info-read info)
8621                                        (list (cdr art-group)))))
8622
8623             ;; See whether the article is to be put in the cache.
8624             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8625                              default-marks
8626                            no-expire-marks))
8627                   (to-article (cdr art-group)))
8628
8629               ;; Enter the article into the cache in the new group,
8630               ;; if that is required.
8631               (when gnus-use-cache
8632                 (gnus-cache-possibly-enter-article
8633                  to-group to-article
8634                  (let ((header (copy-sequence
8635                                 (gnus-summary-article-header article))))
8636                    (mail-header-set-number header to-article)
8637                    header)
8638                  (memq article gnus-newsgroup-marked)
8639                  (memq article gnus-newsgroup-dormant)
8640                  (memq article gnus-newsgroup-unreads)))
8641
8642               (when gnus-preserve-marks
8643                 ;; Copy any marks over to the new group.
8644                 (when (and (equal to-group gnus-newsgroup-name)
8645                            (not (memq article gnus-newsgroup-unreads)))
8646                   ;; Mark this article as read in this group.
8647                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8648                   (setcdr (gnus-active to-group) to-article)
8649                   (setcdr gnus-newsgroup-active to-article))
8650
8651                 (while marks
8652                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8653                     (when (memq article (symbol-value
8654                                          (intern (format "gnus-newsgroup-%s"
8655                                                          (caar marks)))))
8656                       (push (cdar marks) to-marks)
8657                       ;; If the other group is the same as this group,
8658                       ;; then we have to add the mark to the list.
8659                       (when (equal to-group gnus-newsgroup-name)
8660                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8661                              (cons to-article
8662                                    (symbol-value
8663                                     (intern (format "gnus-newsgroup-%s"
8664                                                     (caar marks)))))))
8665                       ;; Copy the marks to other group.
8666                       (gnus-add-marked-articles
8667                        to-group (cdar marks) (list to-article) info)))
8668                   (setq marks (cdr marks)))
8669
8670                 (gnus-request-set-mark to-group (list (list (list to-article)
8671                                                             'add
8672                                                             to-marks))))
8673
8674               (gnus-dribble-enter
8675                (concat "(gnus-group-set-info '"
8676                        (gnus-prin1-to-string (gnus-get-info to-group))
8677                        ")"))))
8678
8679           ;; Update the Xref header in this article to point to
8680           ;; the new crossposted article we have just created.
8681           (when (eq action 'crosspost)
8682             (save-excursion
8683               (set-buffer copy-buf)
8684               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8685               (nnheader-replace-header "Xref" new-xref)
8686               (gnus-request-replace-article
8687                article gnus-newsgroup-name (current-buffer)))))
8688
8689         ;;;!!!Why is this necessary?
8690         (set-buffer gnus-summary-buffer)
8691
8692         (gnus-summary-goto-subject article)
8693         (when (eq action 'move)
8694           (gnus-summary-mark-article article gnus-canceled-mark))))
8695       (gnus-summary-remove-process-mark article))
8696     ;; Re-activate all groups that have been moved to.
8697     (save-excursion
8698       (set-buffer gnus-group-buffer)
8699       (let ((gnus-group-marked to-groups))
8700         (gnus-group-get-new-news-this-group nil t)))
8701
8702     (gnus-kill-buffer copy-buf)
8703     (gnus-summary-position-point)
8704     (gnus-set-mode-line 'summary)))
8705
8706 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8707   "Move the current article to a different newsgroup.
8708 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8709 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8710 re-spool using this method."
8711   (interactive "P")
8712   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8713
8714 (defun gnus-summary-crosspost-article (&optional n)
8715   "Crosspost the current article to some other group."
8716   (interactive "P")
8717   (gnus-summary-move-article n nil nil 'crosspost))
8718
8719 (defcustom gnus-summary-respool-default-method nil
8720   "Default method type for respooling an article.
8721 If nil, use to the current newsgroup method."
8722   :type 'symbol
8723   :group 'gnus-summary-mail)
8724
8725 (defun gnus-summary-respool-article (&optional n method)
8726   "Respool the current article.
8727 The article will be squeezed through the mail spooling process again,
8728 which means that it will be put in some mail newsgroup or other
8729 depending on `nnmail-split-methods'.
8730 If N is a positive number, respool the N next articles.
8731 If N is a negative number, respool the N previous articles.
8732 If N is nil and any articles have been marked with the process mark,
8733 respool those articles instead.
8734
8735 Respooling can be done both from mail groups and \"real\" newsgroups.
8736 In the former case, the articles in question will be moved from the
8737 current group into whatever groups they are destined to.  In the
8738 latter case, they will be copied into the relevant groups."
8739   (interactive
8740    (list current-prefix-arg
8741          (let* ((methods (gnus-methods-using 'respool))
8742                 (methname
8743                  (symbol-name (or gnus-summary-respool-default-method
8744                                   (car (gnus-find-method-for-group
8745                                         gnus-newsgroup-name)))))
8746                 (method
8747                  (gnus-completing-read-with-default
8748                   methname "What backend do you want to use when respooling?"
8749                   methods nil t nil 'gnus-mail-method-history))
8750                 ms)
8751            (cond
8752             ((zerop (length (setq ms (gnus-servers-using-backend
8753                                       (intern method)))))
8754              (list (intern method) ""))
8755             ((= 1 (length ms))
8756              (car ms))
8757             (t
8758              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8759                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8760                            ms-alist))))))))
8761   (unless method
8762     (error "No method given for respooling"))
8763   (if (assoc (symbol-name
8764               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8765              (gnus-methods-using 'respool))
8766       (gnus-summary-move-article n nil method)
8767     (gnus-summary-copy-article n nil method)))
8768
8769 (defun gnus-summary-import-article (file &optional edit)
8770   "Import an arbitrary file into a mail newsgroup."
8771   (interactive "fImport file: \nP")
8772   (let ((group gnus-newsgroup-name)
8773         (now (current-time))
8774         atts lines group-art)
8775     (unless (gnus-check-backend-function 'request-accept-article group)
8776       (error "%s does not support article importing" group))
8777     (or (file-readable-p file)
8778         (not (file-regular-p file))
8779         (error "Can't read %s" file))
8780     (save-excursion
8781       (set-buffer (gnus-get-buffer-create " *import file*"))
8782       (erase-buffer)
8783       (nnheader-insert-file-contents file)
8784       (goto-char (point-min))
8785       (if (nnheader-article-p)
8786           (save-restriction
8787             (goto-char (point-min))
8788             (search-forward "\n\n" nil t)
8789             (narrow-to-region (point-min) (1- (point)))
8790             (goto-char (point-min))
8791             (unless (re-search-forward "^date:" nil t)
8792               (goto-char (point-max))
8793               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8794         ;; This doesn't look like an article, so we fudge some headers.
8795         (setq atts (file-attributes file)
8796               lines (count-lines (point-min) (point-max)))
8797         (insert "From: " (read-string "From: ") "\n"
8798                 "Subject: " (read-string "Subject: ") "\n"
8799                 "Date: " (message-make-date (nth 5 atts)) "\n"
8800                 "Message-ID: " (message-make-message-id) "\n"
8801                 "Lines: " (int-to-string lines) "\n"
8802                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8803       (setq group-art (gnus-request-accept-article group nil t))
8804       (kill-buffer (current-buffer)))
8805     (setq gnus-newsgroup-active (gnus-activate-group group))
8806     (forward-line 1)
8807     (gnus-summary-goto-article (cdr group-art) nil t)
8808     (when edit
8809       (gnus-summary-edit-article))))
8810
8811 (defun gnus-summary-create-article ()
8812   "Create an article in a mail newsgroup."
8813   (interactive)
8814   (let ((group gnus-newsgroup-name)
8815         (now (current-time))
8816         group-art)
8817     (unless (gnus-check-backend-function 'request-accept-article group)
8818       (error "%s does not support article importing" group))
8819     (save-excursion
8820       (set-buffer (gnus-get-buffer-create " *import file*"))
8821       (erase-buffer)
8822       (goto-char (point-min))
8823       ;; This doesn't look like an article, so we fudge some headers.
8824       (insert "From: " (read-string "From: ") "\n"
8825               "Subject: " (read-string "Subject: ") "\n"
8826               "Date: " (message-make-date now) "\n"
8827               "Message-ID: " (message-make-message-id) "\n")
8828       (setq group-art (gnus-request-accept-article group nil t))
8829       (kill-buffer (current-buffer)))
8830     (setq gnus-newsgroup-active (gnus-activate-group group))
8831     (forward-line 1)
8832     (gnus-summary-goto-article (cdr group-art) nil t)
8833     (gnus-summary-edit-article)))
8834
8835 (defun gnus-summary-article-posted-p ()
8836   "Say whether the current (mail) article is available from news as well.
8837 This will be the case if the article has both been mailed and posted."
8838   (interactive)
8839   (let ((id (mail-header-references (gnus-summary-article-header)))
8840         (gnus-override-method (car (gnus-refer-article-methods))))
8841     (if (gnus-request-head id "")
8842         (gnus-message 2 "The current message was found on %s"
8843                       gnus-override-method)
8844       (gnus-message 2 "The current message couldn't be found on %s"
8845                     gnus-override-method)
8846       nil)))
8847
8848 (defun gnus-summary-expire-articles (&optional now)
8849   "Expire all articles that are marked as expirable in the current group."
8850   (interactive)
8851   (when (gnus-check-backend-function
8852          'request-expire-articles gnus-newsgroup-name)
8853     ;; This backend supports expiry.
8854     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8855            (expirable (if total
8856                           (progn
8857                             ;; We need to update the info for
8858                             ;; this group for `gnus-list-of-read-articles'
8859                             ;; to give us the right answer.
8860                             (gnus-run-hooks 'gnus-exit-group-hook)
8861                             (gnus-summary-update-info)
8862                             (gnus-list-of-read-articles gnus-newsgroup-name))
8863                         (setq gnus-newsgroup-expirable
8864                               (sort gnus-newsgroup-expirable '<))))
8865            (expiry-wait (if now 'immediate
8866                           (gnus-group-find-parameter
8867                            gnus-newsgroup-name 'expiry-wait)))
8868            (nnmail-expiry-target
8869             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8870                 nnmail-expiry-target))
8871            es)
8872       (when expirable
8873         ;; There are expirable articles in this group, so we run them
8874         ;; through the expiry process.
8875         (gnus-message 6 "Expiring articles...")
8876         (unless (gnus-check-group gnus-newsgroup-name)
8877           (error "Can't open server for %s" gnus-newsgroup-name))
8878         ;; The list of articles that weren't expired is returned.
8879         (save-excursion
8880           (if expiry-wait
8881               (let ((nnmail-expiry-wait-function nil)
8882                     (nnmail-expiry-wait expiry-wait))
8883                 (setq es (gnus-request-expire-articles
8884                           expirable gnus-newsgroup-name)))
8885             (setq es (gnus-request-expire-articles
8886                       expirable gnus-newsgroup-name)))
8887           (unless total
8888             (setq gnus-newsgroup-expirable es))
8889           ;; We go through the old list of expirable, and mark all
8890           ;; really expired articles as nonexistent.
8891           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8892             (let ((gnus-use-cache nil))
8893               (dolist (article expirable)
8894                 (when (and (not (memq article es))
8895                            (gnus-data-find article))
8896                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8897         (gnus-message 6 "Expiring articles...done")))))
8898
8899 (defun gnus-summary-expire-articles-now ()
8900   "Expunge all expirable articles in the current group.
8901 This means that *all* articles that are marked as expirable will be
8902 deleted forever, right now."
8903   (interactive)
8904   (or gnus-expert-user
8905       (gnus-yes-or-no-p
8906        "Are you really, really, really sure you want to delete all these messages? ")
8907       (error "Phew!"))
8908   (gnus-summary-expire-articles t))
8909
8910 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8911 (defun gnus-summary-delete-article (&optional n)
8912   "Delete the N next (mail) articles.
8913 This command actually deletes articles.  This is not a marking
8914 command.  The article will disappear forever from your life, never to
8915 return.
8916 If N is negative, delete backwards.
8917 If N is nil and articles have been marked with the process mark,
8918 delete these instead."
8919   (interactive "P")
8920   (unless (gnus-check-backend-function 'request-expire-articles
8921                                        gnus-newsgroup-name)
8922     (error "The current newsgroup does not support article deletion"))
8923   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8924     (error "Couldn't open server"))
8925   ;; Compute the list of articles to delete.
8926   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8927         not-deleted)
8928     (if (and gnus-novice-user
8929              (not (gnus-yes-or-no-p
8930                    (format "Do you really want to delete %s forever? "
8931                            (if (> (length articles) 1)
8932                                (format "these %s articles" (length articles))
8933                              "this article")))))
8934         ()
8935       ;; Delete the articles.
8936       (setq not-deleted (gnus-request-expire-articles
8937                          articles gnus-newsgroup-name 'force))
8938       (while articles
8939         (gnus-summary-remove-process-mark (car articles))
8940         ;; The backend might not have been able to delete the article
8941         ;; after all.
8942         (unless (memq (car articles) not-deleted)
8943           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8944         (setq articles (cdr articles)))
8945       (when not-deleted
8946         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8947     (gnus-summary-position-point)
8948     (gnus-set-mode-line 'summary)
8949     not-deleted))
8950
8951 (defun gnus-summary-edit-article (&optional force)
8952   "Edit the current article.
8953 This will have permanent effect only in mail groups.
8954 If FORCE is non-nil, allow editing of articles even in read-only
8955 groups."
8956   (interactive "P")
8957   (save-excursion
8958     (set-buffer gnus-summary-buffer)
8959     (let ((mail-parse-charset gnus-newsgroup-charset)
8960           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8961       (gnus-set-global-variables)
8962       (when (and (not force)
8963                  (gnus-group-read-only-p))
8964         (error "The current newsgroup does not support article editing"))
8965       (gnus-summary-show-article t)
8966       (gnus-article-edit-article
8967        'ignore
8968        `(lambda (no-highlight)
8969           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8970                 (message-options message-options)
8971                 (message-options-set-recipient)
8972                 (mail-parse-ignored-charsets
8973                  ',gnus-newsgroup-ignored-charsets))
8974             (gnus-summary-edit-article-done
8975              ,(or (mail-header-references gnus-current-headers) "")
8976              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8977
8978 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8979
8980 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8981                                                  no-highlight)
8982   "Make edits to the current article permanent."
8983   (interactive)
8984   (save-excursion
8985     ;; The buffer restriction contains the entire article if it exists.
8986     (when (article-goto-body)
8987       (let ((lines (count-lines (point) (point-max)))
8988             (length (- (point-max) (point)))
8989             (case-fold-search t)
8990             (body (copy-marker (point))))
8991         (goto-char (point-min))
8992         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8993           (delete-region (match-beginning 1) (match-end 1))
8994           (insert (number-to-string length)))
8995         (goto-char (point-min))
8996         (when (re-search-forward
8997                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8998           (delete-region (match-beginning 1) (match-end 1))
8999           (insert (number-to-string length)))
9000         (goto-char (point-min))
9001         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9002           (delete-region (match-beginning 1) (match-end 1))
9003           (insert (number-to-string lines))))))
9004   ;; Replace the article.
9005   (let ((buf (current-buffer)))
9006     (with-temp-buffer
9007       (insert-buffer-substring buf)
9008
9009       (if (and (not read-only)
9010                (not (gnus-request-replace-article
9011                      (cdr gnus-article-current) (car gnus-article-current)
9012                      (current-buffer) t)))
9013           (error "Couldn't replace article")
9014         ;; Update the summary buffer.
9015         (if (and references
9016                  (equal (message-tokenize-header references " ")
9017                         (message-tokenize-header
9018                          (or (message-fetch-field "references") "") " ")))
9019             ;; We only have to update this line.
9020             (save-excursion
9021               (save-restriction
9022                 (message-narrow-to-head)
9023                 (let ((head (buffer-string))
9024                       header)
9025                   (with-temp-buffer
9026                     (insert (format "211 %d Article retrieved.\n"
9027                                     (cdr gnus-article-current)))
9028                     (insert head)
9029                     (insert ".\n")
9030                     (let ((nntp-server-buffer (current-buffer)))
9031                       (setq header (car (gnus-get-newsgroup-headers
9032                                          nil t))))
9033                     (save-excursion
9034                       (set-buffer gnus-summary-buffer)
9035                       (gnus-data-set-header
9036                        (gnus-data-find (cdr gnus-article-current))
9037                        header)
9038                       (gnus-summary-update-article-line
9039                        (cdr gnus-article-current) header)
9040                       (if (gnus-summary-goto-subject
9041                            (cdr gnus-article-current) nil t)
9042                           (gnus-summary-update-secondary-mark
9043                            (cdr gnus-article-current))))))))
9044           ;; Update threads.
9045           (set-buffer (or buffer gnus-summary-buffer))
9046           (gnus-summary-update-article (cdr gnus-article-current))
9047           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9048               (gnus-summary-update-secondary-mark
9049                (cdr gnus-article-current))))
9050         ;; Prettify the article buffer again.
9051         (unless no-highlight
9052           (save-excursion
9053             (set-buffer gnus-article-buffer)
9054             ;;;!!! Fix this -- article should be rehighlighted.
9055             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9056             (set-buffer gnus-original-article-buffer)
9057             (gnus-request-article
9058              (cdr gnus-article-current)
9059              (car gnus-article-current) (current-buffer))))
9060         ;; Prettify the summary buffer line.
9061         (when (gnus-visual-p 'summary-highlight 'highlight)
9062           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9063
9064 (defun gnus-summary-edit-wash (key)
9065   "Perform editing command KEY in the article buffer."
9066   (interactive
9067    (list
9068     (progn
9069       (message "%s" (concat (this-command-keys) "- "))
9070       (read-char))))
9071   (message "")
9072   (gnus-summary-edit-article)
9073   (execute-kbd-macro (concat (this-command-keys) key))
9074   (gnus-article-edit-done))
9075
9076 ;;; Respooling
9077
9078 (defun gnus-summary-respool-query (&optional silent trace)
9079   "Query where the respool algorithm would put this article."
9080   (interactive)
9081   (let (gnus-mark-article-hook)
9082     (gnus-summary-select-article)
9083     (save-excursion
9084       (set-buffer gnus-original-article-buffer)
9085       (save-restriction
9086         (message-narrow-to-head)
9087         (let ((groups (nnmail-article-group 'identity trace)))
9088           (unless silent
9089             (if groups
9090                 (message "This message would go to %s"
9091                          (mapconcat 'car groups ", "))
9092               (message "This message would go to no groups"))
9093             groups))))))
9094
9095 (defun gnus-summary-respool-trace ()
9096   "Trace where the respool algorithm would put this article.
9097 Display a buffer showing all fancy splitting patterns which matched."
9098   (interactive)
9099   (gnus-summary-respool-query nil t))
9100
9101 ;; Summary marking commands.
9102
9103 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9104   "Mark articles which has the same subject as read, and then select the next.
9105 If UNMARK is positive, remove any kind of mark.
9106 If UNMARK is negative, tick articles."
9107   (interactive "P")
9108   (when unmark
9109     (setq unmark (prefix-numeric-value unmark)))
9110   (let ((count
9111          (gnus-summary-mark-same-subject
9112           (gnus-summary-article-subject) unmark)))
9113     ;; Select next unread article.  If auto-select-same mode, should
9114     ;; select the first unread article.
9115     (gnus-summary-next-article t (and gnus-auto-select-same
9116                                       (gnus-summary-article-subject)))
9117     (gnus-message 7 "%d article%s marked as %s"
9118                   count (if (= count 1) " is" "s are")
9119                   (if unmark "unread" "read"))))
9120
9121 (defun gnus-summary-kill-same-subject (&optional unmark)
9122   "Mark articles which has the same subject as read.
9123 If UNMARK is positive, remove any kind of mark.
9124 If UNMARK is negative, tick articles."
9125   (interactive "P")
9126   (when unmark
9127     (setq unmark (prefix-numeric-value unmark)))
9128   (let ((count
9129          (gnus-summary-mark-same-subject
9130           (gnus-summary-article-subject) unmark)))
9131     ;; If marked as read, go to next unread subject.
9132     (when (null unmark)
9133       ;; Go to next unread subject.
9134       (gnus-summary-next-subject 1 t))
9135     (gnus-message 7 "%d articles are marked as %s"
9136                   count (if unmark "unread" "read"))))
9137
9138 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9139   "Mark articles with same SUBJECT as read, and return marked number.
9140 If optional argument UNMARK is positive, remove any kinds of marks.
9141 If optional argument UNMARK is negative, mark articles as unread instead."
9142   (let ((count 1))
9143     (save-excursion
9144       (cond
9145        ((null unmark)                   ; Mark as read.
9146         (while (and
9147                 (progn
9148                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9149                   (gnus-summary-show-thread) t)
9150                 (gnus-summary-find-subject subject))
9151           (setq count (1+ count))))
9152        ((> unmark 0)                    ; Tick.
9153         (while (and
9154                 (progn
9155                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9156                   (gnus-summary-show-thread) t)
9157                 (gnus-summary-find-subject subject))
9158           (setq count (1+ count))))
9159        (t                               ; Mark as unread.
9160         (while (and
9161                 (progn
9162                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9163                   (gnus-summary-show-thread) t)
9164                 (gnus-summary-find-subject subject))
9165           (setq count (1+ count)))))
9166       (gnus-set-mode-line 'summary)
9167       ;; Return the number of marked articles.
9168       count)))
9169
9170 (defun gnus-summary-mark-as-processable (n &optional unmark)
9171   "Set the process mark on the next N articles.
9172 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9173 the process mark instead.  The difference between N and the actual
9174 number of articles marked is returned."
9175   (interactive "P")
9176   (if (and (null n) (gnus-region-active-p))
9177       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9178     (setq n (prefix-numeric-value n))
9179     (let ((backward (< n 0))
9180           (n (abs n)))
9181       (while (and
9182               (> n 0)
9183               (if unmark
9184                   (gnus-summary-remove-process-mark
9185                    (gnus-summary-article-number))
9186                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9187               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9188         (setq n (1- n)))
9189       (when (/= 0 n)
9190         (gnus-message 7 "No more articles"))
9191       (gnus-summary-recenter)
9192       (gnus-summary-position-point)
9193       n)))
9194
9195 (defun gnus-summary-unmark-as-processable (n)
9196   "Remove the process mark from the next N articles.
9197 If N is negative, unmark backward instead.  The difference between N and
9198 the actual number of articles unmarked is returned."
9199   (interactive "P")
9200   (gnus-summary-mark-as-processable n t))
9201
9202 (defun gnus-summary-unmark-all-processable ()
9203   "Remove the process mark from all articles."
9204   (interactive)
9205   (save-excursion
9206     (while gnus-newsgroup-processable
9207       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9208   (gnus-summary-position-point))
9209
9210 (defun gnus-summary-add-mark (article type)
9211   "Mark ARTICLE with a mark of TYPE."
9212   (let ((vtype (car (assq type gnus-article-mark-lists)))
9213         var)
9214     (if (not vtype)
9215         (error "No such mark type: %s" type)
9216       (setq var (intern (format "gnus-newsgroup-%s" type)))
9217       (set var (cons article (symbol-value var)))
9218       (if (memq type '(processable cached replied forwarded recent saved))
9219           (gnus-summary-update-secondary-mark article)
9220         ;;; !!! This is bogus.  We should find out what primary
9221         ;;; !!! mark we want to set.
9222         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9223
9224 (defun gnus-summary-mark-as-expirable (n)
9225   "Mark N articles forward as expirable.
9226 If N is negative, mark backward instead.  The difference between N and
9227 the actual number of articles marked is returned."
9228   (interactive "p")
9229   (gnus-summary-mark-forward n gnus-expirable-mark))
9230
9231 (defun gnus-summary-mark-article-as-replied (article)
9232   "Mark ARTICLE as replied to and update the summary line.
9233 ARTICLE can also be a list of articles."
9234   (interactive (list (gnus-summary-article-number)))
9235   (let ((articles (if (listp article) article (list article))))
9236     (dolist (article articles)
9237       (push article gnus-newsgroup-replied)
9238       (let ((buffer-read-only nil))
9239         (when (gnus-summary-goto-subject article nil t)
9240           (gnus-summary-update-secondary-mark article))))))
9241
9242 (defun gnus-summary-mark-article-as-forwarded (article)
9243   "Mark ARTICLE as forwarded and update the summary line.
9244 ARTICLE can also be a list of articles."
9245   (let ((articles (if (listp article) article (list article))))
9246     (dolist (article articles)
9247       (push article gnus-newsgroup-forwarded)
9248       (let ((buffer-read-only nil))
9249         (when (gnus-summary-goto-subject article nil t)
9250           (gnus-summary-update-secondary-mark article))))))
9251
9252 (defun gnus-summary-set-bookmark (article)
9253   "Set a bookmark in current article."
9254   (interactive (list (gnus-summary-article-number)))
9255   (when (or (not (get-buffer gnus-article-buffer))
9256             (not gnus-current-article)
9257             (not gnus-article-current)
9258             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9259     (error "No current article selected"))
9260   ;; Remove old bookmark, if one exists.
9261   (let ((old (assq article gnus-newsgroup-bookmarks)))
9262     (when old
9263       (setq gnus-newsgroup-bookmarks
9264             (delq old gnus-newsgroup-bookmarks))))
9265   ;; Set the new bookmark, which is on the form
9266   ;; (article-number . line-number-in-body).
9267   (push
9268    (cons article
9269          (save-excursion
9270            (set-buffer gnus-article-buffer)
9271            (count-lines
9272             (min (point)
9273                  (save-excursion
9274                    (goto-char (point-min))
9275                    (search-forward "\n\n" nil t)
9276                    (point)))
9277             (point))))
9278    gnus-newsgroup-bookmarks)
9279   (gnus-message 6 "A bookmark has been added to the current article."))
9280
9281 (defun gnus-summary-remove-bookmark (article)
9282   "Remove the bookmark from the current article."
9283   (interactive (list (gnus-summary-article-number)))
9284   ;; Remove old bookmark, if one exists.
9285   (let ((old (assq article gnus-newsgroup-bookmarks)))
9286     (if old
9287         (progn
9288           (setq gnus-newsgroup-bookmarks
9289                 (delq old gnus-newsgroup-bookmarks))
9290           (gnus-message 6 "Removed bookmark."))
9291       (gnus-message 6 "No bookmark in current article."))))
9292
9293 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9294 (defun gnus-summary-mark-as-dormant (n)
9295   "Mark N articles forward as dormant.
9296 If N is negative, mark backward instead.  The difference between N and
9297 the actual number of articles marked is returned."
9298   (interactive "p")
9299   (gnus-summary-mark-forward n gnus-dormant-mark))
9300
9301 (defun gnus-summary-set-process-mark (article)
9302   "Set the process mark on ARTICLE and update the summary line."
9303   (setq gnus-newsgroup-processable
9304         (cons article
9305               (delq article gnus-newsgroup-processable)))
9306   (when (gnus-summary-goto-subject article)
9307     (gnus-summary-show-thread)
9308     (gnus-summary-goto-subject article)
9309     (gnus-summary-update-secondary-mark article)))
9310
9311 (defun gnus-summary-remove-process-mark (article)
9312   "Remove the process mark from ARTICLE and update the summary line."
9313   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9314   (when (gnus-summary-goto-subject article)
9315     (gnus-summary-show-thread)
9316     (gnus-summary-goto-subject article)
9317     (gnus-summary-update-secondary-mark article)))
9318
9319 (defun gnus-summary-set-saved-mark (article)
9320   "Set the process mark on ARTICLE and update the summary line."
9321   (push article gnus-newsgroup-saved)
9322   (when (gnus-summary-goto-subject article)
9323     (gnus-summary-update-secondary-mark article)))
9324
9325 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9326   "Mark N articles as read forwards.
9327 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9328 The difference between N and the actual number of articles marked is
9329 returned.
9330 Iff NO-EXPIRE, auto-expiry will be inhibited."
9331   (interactive "p")
9332   (gnus-summary-show-thread)
9333   (let ((backward (< n 0))
9334         (gnus-summary-goto-unread
9335          (and gnus-summary-goto-unread
9336               (not (eq gnus-summary-goto-unread 'never))
9337               (not (memq mark (list gnus-unread-mark
9338                                     gnus-ticked-mark gnus-dormant-mark)))))
9339         (n (abs n))
9340         (mark (or mark gnus-del-mark)))
9341     (while (and (> n 0)
9342                 (gnus-summary-mark-article nil mark no-expire)
9343                 (zerop (gnus-summary-next-subject
9344                         (if backward -1 1)
9345                         (and gnus-summary-goto-unread
9346                              (not (eq gnus-summary-goto-unread 'never)))
9347                         t)))
9348       (setq n (1- n)))
9349     (when (/= 0 n)
9350       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9351     (gnus-summary-recenter)
9352     (gnus-summary-position-point)
9353     (gnus-set-mode-line 'summary)
9354     n))
9355
9356 (defun gnus-summary-mark-article-as-read (mark)
9357   "Mark the current article quickly as read with MARK."
9358   (let ((article (gnus-summary-article-number)))
9359     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9360     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9361     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9362     (push (cons article mark) gnus-newsgroup-reads)
9363     ;; Possibly remove from cache, if that is used.
9364     (when gnus-use-cache
9365       (gnus-cache-enter-remove-article article))
9366     ;; Allow the backend to change the mark.
9367     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9368     ;; Check for auto-expiry.
9369     (when (and gnus-newsgroup-auto-expire
9370                (memq mark gnus-auto-expirable-marks))
9371       (setq mark gnus-expirable-mark)
9372       ;; Let the backend know about the mark change.
9373       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9374       (push article gnus-newsgroup-expirable))
9375     ;; Set the mark in the buffer.
9376     (gnus-summary-update-mark mark 'unread)
9377     t))
9378
9379 (defun gnus-summary-mark-article-as-unread (mark)
9380   "Mark the current article quickly as unread with MARK."
9381   (let* ((article (gnus-summary-article-number))
9382          (old-mark (gnus-summary-article-mark article)))
9383     ;; Allow the backend to change the mark.
9384     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9385     (if (eq mark old-mark)
9386         t
9387       (if (<= article 0)
9388           (progn
9389             (gnus-error 1 "Can't mark negative article numbers")
9390             nil)
9391         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9392         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9393         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9394         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9395         (cond ((= mark gnus-ticked-mark)
9396                (setq gnus-newsgroup-marked
9397                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9398                                               article)))
9399               ((= mark gnus-dormant-mark)
9400                (setq gnus-newsgroup-dormant
9401                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9402                                               article)))
9403               (t
9404                (setq gnus-newsgroup-unreads
9405                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9406                                               article))))
9407         (gnus-pull article gnus-newsgroup-reads)
9408
9409         ;; See whether the article is to be put in the cache.
9410         (and gnus-use-cache
9411              (vectorp (gnus-summary-article-header article))
9412              (save-excursion
9413                (gnus-cache-possibly-enter-article
9414                 gnus-newsgroup-name article
9415                 (gnus-summary-article-header article)
9416                 (= mark gnus-ticked-mark)
9417                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9418
9419         ;; Fix the mark.
9420         (gnus-summary-update-mark mark 'unread)
9421         t))))
9422
9423 (defun gnus-summary-mark-article (&optional article mark no-expire)
9424   "Mark ARTICLE with MARK.  MARK can be any character.
9425 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9426 `??' (dormant) and `?E' (expirable).
9427 If MARK is nil, then the default character `?r' is used.
9428 If ARTICLE is nil, then the article on the current line will be
9429 marked.
9430 Iff NO-EXPIRE, auto-expiry will be inhibited."
9431   ;; The mark might be a string.
9432   (when (stringp mark)
9433     (setq mark (aref mark 0)))
9434   ;; If no mark is given, then we check auto-expiring.
9435   (when (null mark)
9436     (setq mark gnus-del-mark))
9437   (when (and (not no-expire)
9438              gnus-newsgroup-auto-expire
9439              (memq mark gnus-auto-expirable-marks))
9440     (setq mark gnus-expirable-mark))
9441   (let ((article (or article (gnus-summary-article-number)))
9442         (old-mark (gnus-summary-article-mark article)))
9443     ;; Allow the backend to change the mark.
9444     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9445     (if (eq mark old-mark)
9446         t
9447       (unless article
9448         (error "No article on current line"))
9449       (if (not (if (or (= mark gnus-unread-mark)
9450                        (= mark gnus-ticked-mark)
9451                        (= mark gnus-dormant-mark))
9452                    (gnus-mark-article-as-unread article mark)
9453                  (gnus-mark-article-as-read article mark)))
9454           t
9455         ;; See whether the article is to be put in the cache.
9456         (and gnus-use-cache
9457              (not (= mark gnus-canceled-mark))
9458              (vectorp (gnus-summary-article-header article))
9459              (save-excursion
9460                (gnus-cache-possibly-enter-article
9461                 gnus-newsgroup-name article
9462                 (gnus-summary-article-header article)
9463                 (= mark gnus-ticked-mark)
9464                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9465
9466         (when (gnus-summary-goto-subject article nil t)
9467           (let ((buffer-read-only nil))
9468             (gnus-summary-show-thread)
9469             ;; Fix the mark.
9470             (gnus-summary-update-mark mark 'unread)
9471             t))))))
9472
9473 (defun gnus-summary-update-secondary-mark (article)
9474   "Update the secondary (read, process, cache) mark."
9475   (gnus-summary-update-mark
9476    (cond ((memq article gnus-newsgroup-processable)
9477           gnus-process-mark)
9478          ((memq article gnus-newsgroup-cached)
9479           gnus-cached-mark)
9480          ((memq article gnus-newsgroup-replied)
9481           gnus-replied-mark)
9482          ((memq article gnus-newsgroup-forwarded)
9483           gnus-forwarded-mark)
9484          ((memq article gnus-newsgroup-saved)
9485           gnus-saved-mark)
9486          ((memq article gnus-newsgroup-recent)
9487           gnus-recent-mark)
9488          ((memq article gnus-newsgroup-unseen)
9489           gnus-unseen-mark)
9490          (t gnus-no-mark))
9491    'replied)
9492   (when (gnus-visual-p 'summary-highlight 'highlight)
9493     (gnus-run-hooks 'gnus-summary-update-hook))
9494   t)
9495
9496 (defun gnus-summary-update-mark (mark type)
9497   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9498         (buffer-read-only nil))
9499     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9500     (when forward
9501       (when (looking-at "\r")
9502         (incf forward))
9503       (when (<= (+ forward (point)) (point-max))
9504         ;; Go to the right position on the line.
9505         (goto-char (+ forward (point)))
9506         ;; Replace the old mark with the new mark.
9507         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9508         ;; Optionally update the marks by some user rule.
9509         (when (eq type 'unread)
9510           (gnus-data-set-mark
9511            (gnus-data-find (gnus-summary-article-number)) mark)
9512           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9513
9514 (defun gnus-mark-article-as-read (article &optional mark)
9515   "Enter ARTICLE in the pertinent lists and remove it from others."
9516   ;; Make the article expirable.
9517   (let ((mark (or mark gnus-del-mark)))
9518     (setq gnus-newsgroup-expirable
9519           (if (= mark gnus-expirable-mark)
9520               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9521             (delq article gnus-newsgroup-expirable)))
9522     ;; Remove from unread and marked lists.
9523     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9524     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9525     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9526     (push (cons article mark) gnus-newsgroup-reads)
9527     ;; Possibly remove from cache, if that is used.
9528     (when gnus-use-cache
9529       (gnus-cache-enter-remove-article article))
9530     t))
9531
9532 (defun gnus-mark-article-as-unread (article &optional mark)
9533   "Enter ARTICLE in the pertinent lists and remove it from others."
9534   (let ((mark (or mark gnus-ticked-mark)))
9535     (if (<= article 0)
9536         (progn
9537           (gnus-error 1 "Can't mark negative article numbers")
9538           nil)
9539       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9540             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9541             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9542             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9543
9544       ;; Unsuppress duplicates?
9545       (when gnus-suppress-duplicates
9546         (gnus-dup-unsuppress-article article))
9547
9548       (cond ((= mark gnus-ticked-mark)
9549              (setq gnus-newsgroup-marked
9550                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9551             ((= mark gnus-dormant-mark)
9552              (setq gnus-newsgroup-dormant
9553                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9554             (t
9555              (setq gnus-newsgroup-unreads
9556                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9557       (gnus-pull article gnus-newsgroup-reads)
9558       t)))
9559
9560 (defalias 'gnus-summary-mark-as-unread-forward
9561   'gnus-summary-tick-article-forward)
9562 (make-obsolete 'gnus-summary-mark-as-unread-forward
9563                'gnus-summary-tick-article-forward)
9564 (defun gnus-summary-tick-article-forward (n)
9565   "Tick N articles forwards.
9566 If N is negative, tick backwards instead.
9567 The difference between N and the number of articles ticked is returned."
9568   (interactive "p")
9569   (gnus-summary-mark-forward n gnus-ticked-mark))
9570
9571 (defalias 'gnus-summary-mark-as-unread-backward
9572   'gnus-summary-tick-article-backward)
9573 (make-obsolete 'gnus-summary-mark-as-unread-backward
9574                'gnus-summary-tick-article-backward)
9575 (defun gnus-summary-tick-article-backward (n)
9576   "Tick N articles backwards.
9577 The difference between N and the number of articles ticked is returned."
9578   (interactive "p")
9579   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9580
9581 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9582 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9583 (defun gnus-summary-tick-article (&optional article clear-mark)
9584   "Mark current article as unread.
9585 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9586 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9587   (interactive)
9588   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9589                                        gnus-ticked-mark)))
9590
9591 (defun gnus-summary-mark-as-read-forward (n)
9592   "Mark N articles as read forwards.
9593 If N is negative, mark backwards instead.
9594 The difference between N and the actual number of articles marked is
9595 returned."
9596   (interactive "p")
9597   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9598
9599 (defun gnus-summary-mark-as-read-backward (n)
9600   "Mark the N articles as read backwards.
9601 The difference between N and the actual number of articles marked is
9602 returned."
9603   (interactive "p")
9604   (gnus-summary-mark-forward
9605    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9606
9607 (defun gnus-summary-mark-as-read (&optional article mark)
9608   "Mark current article as read.
9609 ARTICLE specifies the article to be marked as read.
9610 MARK specifies a string to be inserted at the beginning of the line."
9611   (gnus-summary-mark-article article mark))
9612
9613 (defun gnus-summary-clear-mark-forward (n)
9614   "Clear marks from N articles forward.
9615 If N is negative, clear backward instead.
9616 The difference between N and the number of marks cleared is returned."
9617   (interactive "p")
9618   (gnus-summary-mark-forward n gnus-unread-mark))
9619
9620 (defun gnus-summary-clear-mark-backward (n)
9621   "Clear marks from N articles backward.
9622 The difference between N and the number of marks cleared is returned."
9623   (interactive "p")
9624   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9625
9626 (defun gnus-summary-mark-unread-as-read ()
9627   "Intended to be used by `gnus-summary-mark-article-hook'."
9628   (when (memq gnus-current-article gnus-newsgroup-unreads)
9629     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9630
9631 (defun gnus-summary-mark-read-and-unread-as-read ()
9632   "Intended to be used by `gnus-summary-mark-article-hook'."
9633   (let ((mark (gnus-summary-article-mark)))
9634     (when (or (gnus-unread-mark-p mark)
9635               (gnus-read-mark-p mark))
9636       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9637
9638 (defun gnus-summary-mark-unread-as-ticked ()
9639   "Intended to be used by `gnus-summary-mark-article-hook'."
9640   (when (memq gnus-current-article gnus-newsgroup-unreads)
9641     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9642
9643 (defun gnus-summary-mark-region-as-read (point mark all)
9644   "Mark all unread articles between point and mark as read.
9645 If given a prefix, mark all articles between point and mark as read,
9646 even ticked and dormant ones."
9647   (interactive "r\nP")
9648   (save-excursion
9649     (let (article)
9650       (goto-char point)
9651       (beginning-of-line)
9652       (while (and
9653               (< (point) mark)
9654               (progn
9655                 (when (or all
9656                           (memq (setq article (gnus-summary-article-number))
9657                                 gnus-newsgroup-unreads))
9658                   (gnus-summary-mark-article article gnus-del-mark))
9659                 t)
9660               (gnus-summary-find-next))))))
9661
9662 (defun gnus-summary-mark-below (score mark)
9663   "Mark articles with score less than SCORE with MARK."
9664   (interactive "P\ncMark: ")
9665   (setq score (if score
9666                   (prefix-numeric-value score)
9667                 (or gnus-summary-default-score 0)))
9668   (save-excursion
9669     (set-buffer gnus-summary-buffer)
9670     (goto-char (point-min))
9671     (while
9672         (progn
9673           (and (< (gnus-summary-article-score) score)
9674                (gnus-summary-mark-article nil mark))
9675           (gnus-summary-find-next)))))
9676
9677 (defun gnus-summary-kill-below (&optional score)
9678   "Mark articles with score below SCORE as read."
9679   (interactive "P")
9680   (gnus-summary-mark-below score gnus-killed-mark))
9681
9682 (defun gnus-summary-clear-above (&optional score)
9683   "Clear all marks from articles with score above SCORE."
9684   (interactive "P")
9685   (gnus-summary-mark-above score gnus-unread-mark))
9686
9687 (defun gnus-summary-tick-above (&optional score)
9688   "Tick all articles with score above SCORE."
9689   (interactive "P")
9690   (gnus-summary-mark-above score gnus-ticked-mark))
9691
9692 (defun gnus-summary-mark-above (score mark)
9693   "Mark articles with score over SCORE with MARK."
9694   (interactive "P\ncMark: ")
9695   (setq score (if score
9696                   (prefix-numeric-value score)
9697                 (or gnus-summary-default-score 0)))
9698   (save-excursion
9699     (set-buffer gnus-summary-buffer)
9700     (goto-char (point-min))
9701     (while (and (progn
9702                   (when (> (gnus-summary-article-score) score)
9703                     (gnus-summary-mark-article nil mark))
9704                   t)
9705                 (gnus-summary-find-next)))))
9706
9707 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9708 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9709 (defun gnus-summary-limit-include-expunged (&optional no-error)
9710   "Display all the hidden articles that were expunged for low scores."
9711   (interactive)
9712   (let ((buffer-read-only nil))
9713     (let ((scored gnus-newsgroup-scored)
9714           headers h)
9715       (while scored
9716         (unless (gnus-summary-article-header (caar scored))
9717           (and (setq h (gnus-number-to-header (caar scored)))
9718                (< (cdar scored) gnus-summary-expunge-below)
9719                (push h headers)))
9720         (setq scored (cdr scored)))
9721       (if (not headers)
9722           (when (not no-error)
9723             (error "No expunged articles hidden"))
9724         (goto-char (point-min))
9725         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9726         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9727         (mapcar (lambda (x) (push (mail-header-number x)
9728                                   gnus-newsgroup-limit))
9729                 headers)
9730         (gnus-summary-prepare-unthreaded (nreverse headers))
9731         (goto-char (point-min))
9732         (gnus-summary-position-point)
9733         t))))
9734
9735 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9736   "Mark all unread articles in this newsgroup as read.
9737 If prefix argument ALL is non-nil, ticked and dormant articles will
9738 also be marked as read.
9739 If QUIETLY is non-nil, no questions will be asked.
9740 If TO-HERE is non-nil, it should be a point in the buffer.  All
9741 articles before (after, if REVERSE is set) this point will be marked as read.
9742 Note that this function will only catch up the unread article
9743 in the current summary buffer limitation.
9744 The number of articles marked as read is returned."
9745   (interactive "P")
9746   (prog1
9747       (save-excursion
9748         (when (or quietly
9749                   (not gnus-interactive-catchup) ;Without confirmation?
9750                   gnus-expert-user
9751                   (gnus-y-or-n-p
9752                    (if all
9753                        "Mark absolutely all articles as read? "
9754                      "Mark all unread articles as read? ")))
9755           (if (and not-mark
9756                    (not gnus-newsgroup-adaptive)
9757                    (not gnus-newsgroup-auto-expire)
9758                    (not gnus-suppress-duplicates)
9759                    (or (not gnus-use-cache)
9760                        (eq gnus-use-cache 'passive)))
9761               (progn
9762                 (when all
9763                   (setq gnus-newsgroup-marked nil
9764                         gnus-newsgroup-dormant nil))
9765                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9766             ;; We actually mark all articles as canceled, which we
9767             ;; have to do when using auto-expiry or adaptive scoring.
9768             (gnus-summary-show-all-threads)
9769             (if (and to-here reverse)
9770                 (progn
9771                   (goto-char to-here)
9772                   (while (and
9773                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9774                           (gnus-summary-find-next (not all) nil nil t))))
9775               (when (gnus-summary-first-subject (not all) t)
9776                 (while (and
9777                         (if to-here (< (point) to-here) t)
9778                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9779                         (gnus-summary-find-next (not all) nil nil t)))))
9780             (gnus-set-mode-line 'summary))
9781           t))
9782     (gnus-summary-position-point)))
9783
9784 (defun gnus-summary-catchup-to-here (&optional all)
9785   "Mark all unticked articles before the current one as read.
9786 If ALL is non-nil, also mark ticked and dormant articles as read."
9787   (interactive "P")
9788   (save-excursion
9789     (gnus-save-hidden-threads
9790       (let ((beg (point)))
9791         ;; We check that there are unread articles.
9792         (when (or all (gnus-summary-find-prev))
9793           (gnus-summary-catchup all t beg)))))
9794   (gnus-summary-position-point))
9795
9796 (defun gnus-summary-catchup-from-here (&optional all)
9797   "Mark all unticked articles after the current one as read.
9798 If ALL is non-nil, also mark ticked and dormant articles as read."
9799   (interactive "P")
9800   (save-excursion
9801     (gnus-save-hidden-threads
9802       (let ((beg (point)))
9803         ;; We check that there are unread articles.
9804         (when (or all (gnus-summary-find-next))
9805           (gnus-summary-catchup all t beg nil t)))))
9806   (gnus-summary-position-point))
9807
9808 (defun gnus-summary-catchup-all (&optional quietly)
9809   "Mark all articles in this newsgroup as read."
9810   (interactive "P")
9811   (gnus-summary-catchup t quietly))
9812
9813 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9814   "Mark all unread articles in this group as read, then exit.
9815 If prefix argument ALL is non-nil, all articles are marked as read.
9816 If QUIETLY is non-nil, no questions will be asked."
9817   (interactive "P")
9818   (when (gnus-summary-catchup all quietly nil 'fast)
9819     ;; Select next newsgroup or exit.
9820     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9821              (eq gnus-auto-select-next 'quietly))
9822         (gnus-summary-next-group nil)
9823       (gnus-summary-exit))))
9824
9825 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9826   "Mark all articles in this newsgroup as read, and then exit."
9827   (interactive "P")
9828   (gnus-summary-catchup-and-exit t quietly))
9829
9830 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9831   "Mark all articles in this group as read and select the next group.
9832 If given a prefix, mark all articles, unread as well as ticked, as
9833 read."
9834   (interactive "P")
9835   (save-excursion
9836     (gnus-summary-catchup all))
9837   (gnus-summary-next-group))
9838
9839 ;;;
9840 ;;; with article
9841 ;;;
9842
9843 (defmacro gnus-with-article (article &rest forms)
9844   "Select ARTICLE and perform FORMS in the original article buffer.
9845 Then replace the article with the result."
9846   `(progn
9847      ;; We don't want the article to be marked as read.
9848      (let (gnus-mark-article-hook)
9849        (gnus-summary-select-article t t nil ,article))
9850      (set-buffer gnus-original-article-buffer)
9851      ,@forms
9852      (if (not (gnus-check-backend-function
9853                'request-replace-article (car gnus-article-current)))
9854          (gnus-message 5 "Read-only group; not replacing")
9855        (unless (gnus-request-replace-article
9856                 ,article (car gnus-article-current)
9857                 (current-buffer) t)
9858          (error "Couldn't replace article")))
9859      ;; The cache and backlog have to be flushed somewhat.
9860      (when gnus-keep-backlog
9861        (gnus-backlog-remove-article
9862         (car gnus-article-current) (cdr gnus-article-current)))
9863      (when gnus-use-cache
9864        (gnus-cache-update-article
9865         (car gnus-article-current) (cdr gnus-article-current)))))
9866
9867 (put 'gnus-with-article 'lisp-indent-function 1)
9868 (put 'gnus-with-article 'edebug-form-spec '(form body))
9869
9870 ;; Thread-based commands.
9871
9872 (defun gnus-summary-articles-in-thread (&optional article)
9873   "Return a list of all articles in the current thread.
9874 If ARTICLE is non-nil, return all articles in the thread that starts
9875 with that article."
9876   (let* ((article (or article (gnus-summary-article-number)))
9877          (data (gnus-data-find-list article))
9878          (top-level (gnus-data-level (car data)))
9879          (top-subject
9880           (cond ((null gnus-thread-operation-ignore-subject)
9881                  (gnus-simplify-subject-re
9882                   (mail-header-subject (gnus-data-header (car data)))))
9883                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9884                  (gnus-simplify-subject-fuzzy
9885                   (mail-header-subject (gnus-data-header (car data)))))
9886                 (t nil)))
9887          (end-point (save-excursion
9888                       (if (gnus-summary-go-to-next-thread)
9889                           (point) (point-max))))
9890          articles)
9891     (while (and data
9892                 (< (gnus-data-pos (car data)) end-point))
9893       (when (or (not top-subject)
9894                 (string= top-subject
9895                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9896                              (gnus-simplify-subject-fuzzy
9897                               (mail-header-subject
9898                                (gnus-data-header (car data))))
9899                            (gnus-simplify-subject-re
9900                             (mail-header-subject
9901                              (gnus-data-header (car data)))))))
9902         (push (gnus-data-number (car data)) articles))
9903       (unless (and (setq data (cdr data))
9904                    (> (gnus-data-level (car data)) top-level))
9905         (setq data nil)))
9906     ;; Return the list of articles.
9907     (nreverse articles)))
9908
9909 (defun gnus-summary-rethread-current ()
9910   "Rethread the thread the current article is part of."
9911   (interactive)
9912   (let* ((gnus-show-threads t)
9913          (article (gnus-summary-article-number))
9914          (id (mail-header-id (gnus-summary-article-header)))
9915          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9916     (unless id
9917       (error "No article on the current line"))
9918     (gnus-rebuild-thread id)
9919     (gnus-summary-goto-subject article)))
9920
9921 (defun gnus-summary-reparent-thread ()
9922   "Make the current article child of the marked (or previous) article.
9923
9924 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9925 is non-nil or the Subject: of both articles are the same."
9926   (interactive)
9927   (unless (not (gnus-group-read-only-p))
9928     (error "The current newsgroup does not support article editing"))
9929   (unless (<= (length gnus-newsgroup-processable) 1)
9930     (error "No more than one article may be marked"))
9931   (save-window-excursion
9932     (let ((gnus-article-buffer " *reparent*")
9933           (current-article (gnus-summary-article-number))
9934           ;; First grab the marked article, otherwise one line up.
9935           (parent-article (if (not (null gnus-newsgroup-processable))
9936                               (car gnus-newsgroup-processable)
9937                             (save-excursion
9938                               (if (eq (forward-line -1) 0)
9939                                   (gnus-summary-article-number)
9940                                 (error "Beginning of summary buffer"))))))
9941       (unless (not (eq current-article parent-article))
9942         (error "An article may not be self-referential"))
9943       (let ((message-id (mail-header-id
9944                          (gnus-summary-article-header parent-article))))
9945         (unless (and message-id (not (equal message-id "")))
9946           (error "No message-id in desired parent"))
9947         (gnus-with-article current-article
9948           (save-restriction
9949             (goto-char (point-min))
9950             (message-narrow-to-head)
9951             (if (re-search-forward "^References: " nil t)
9952                 (progn
9953                   (re-search-forward "^[^ \t]" nil t)
9954                   (forward-line -1)
9955                   (end-of-line)
9956                   (insert " " message-id))
9957               (insert "References: " message-id "\n"))))
9958         (set-buffer gnus-summary-buffer)
9959         (gnus-summary-unmark-all-processable)
9960         (gnus-summary-update-article current-article)
9961         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9962             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9963         (gnus-summary-rethread-current)
9964         (gnus-message 3 "Article %d is now the child of article %d"
9965                       current-article parent-article)))))
9966
9967 (defun gnus-summary-toggle-threads (&optional arg)
9968   "Toggle showing conversation threads.
9969 If ARG is positive number, turn showing conversation threads on."
9970   (interactive "P")
9971   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9972     (setq gnus-show-threads
9973           (if (null arg) (not gnus-show-threads)
9974             (> (prefix-numeric-value arg) 0)))
9975     (gnus-summary-prepare)
9976     (gnus-summary-goto-subject current)
9977     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9978     (gnus-summary-position-point)))
9979
9980 (defun gnus-summary-show-all-threads ()
9981   "Show all threads."
9982   (interactive)
9983   (save-excursion
9984     (let ((buffer-read-only nil))
9985       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9986   (gnus-summary-position-point))
9987
9988 (defun gnus-summary-show-thread ()
9989   "Show thread subtrees.
9990 Returns nil if no thread was there to be shown."
9991   (interactive)
9992   (let ((buffer-read-only nil)
9993         (orig (point))
9994         ;; first goto end then to beg, to have point at beg after let
9995         (end (progn (end-of-line) (point)))
9996         (beg (progn (beginning-of-line) (point))))
9997     (prog1
9998         ;; Any hidden lines here?
9999         (search-forward "\r" end t)
10000       (subst-char-in-region beg end ?\^M ?\n t)
10001       (goto-char orig)
10002       (gnus-summary-position-point))))
10003
10004 (defun gnus-summary-maybe-hide-threads ()
10005   "If requested, hide the threads that should be hidden."
10006   (when (and gnus-show-threads
10007              gnus-thread-hide-subtree)
10008     (gnus-summary-hide-all-threads
10009      (if (or (consp gnus-thread-hide-subtree)
10010              (gnus-functionp gnus-thread-hide-subtree))
10011          (gnus-make-predicate gnus-thread-hide-subtree)
10012        nil))))
10013
10014 ;;; Hiding predicates.
10015
10016 (defun gnus-article-unread-p (header)
10017   (memq (mail-header-number header) gnus-newsgroup-unreads))
10018
10019 (defun gnus-article-unseen-p (header)
10020   (memq (mail-header-number header) gnus-newsgroup-unseen))
10021
10022 (defun gnus-map-articles (predicate articles)
10023   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10024   (apply 'gnus-or (mapcar predicate
10025                           (mapcar 'gnus-summary-article-header articles))))
10026
10027 (defun gnus-summary-hide-all-threads (&optional predicate)
10028   "Hide all thread subtrees.
10029 If PREDICATE is supplied, threads that satisfy this predicate
10030 will not be hidden."
10031   (interactive)
10032   (save-excursion
10033     (goto-char (point-min))
10034     (let ((end nil))
10035       (while (not end)
10036         (when (or (not predicate)
10037                   (gnus-map-articles
10038                    predicate (gnus-summary-article-children)))
10039             (gnus-summary-hide-thread))
10040         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10041   (gnus-summary-position-point))
10042
10043 (defun gnus-summary-hide-thread ()
10044   "Hide thread subtrees.
10045 If PREDICATE is supplied, threads that satisfy this predicate
10046 will not be hidden.
10047 Returns nil if no threads were there to be hidden."
10048   (interactive)
10049   (let ((buffer-read-only nil)
10050         (start (point))
10051         (article (gnus-summary-article-number)))
10052     (goto-char start)
10053     ;; Go forward until either the buffer ends or the subthread
10054     ;; ends.
10055     (when (and (not (eobp))
10056                (or (zerop (gnus-summary-next-thread 1 t))
10057                    (goto-char (point-max))))
10058       (prog1
10059           (if (and (> (point) start)
10060                    (search-backward "\n" start t))
10061               (progn
10062                 (subst-char-in-region start (point) ?\n ?\^M)
10063                 (gnus-summary-goto-subject article))
10064             (goto-char start)
10065             nil)))))
10066
10067 (defun gnus-summary-go-to-next-thread (&optional previous)
10068   "Go to the same level (or less) next thread.
10069 If PREVIOUS is non-nil, go to previous thread instead.
10070 Return the article number moved to, or nil if moving was impossible."
10071   (let ((level (gnus-summary-thread-level))
10072         (way (if previous -1 1))
10073         (beg (point)))
10074     (forward-line way)
10075     (while (and (not (eobp))
10076                 (< level (gnus-summary-thread-level)))
10077       (forward-line way))
10078     (if (eobp)
10079         (progn
10080           (goto-char beg)
10081           nil)
10082       (setq beg (point))
10083       (prog1
10084           (gnus-summary-article-number)
10085         (goto-char beg)))))
10086
10087 (defun gnus-summary-next-thread (n &optional silent)
10088   "Go to the same level next N'th thread.
10089 If N is negative, search backward instead.
10090 Returns the difference between N and the number of skips actually
10091 done.
10092
10093 If SILENT, don't output messages."
10094   (interactive "p")
10095   (let ((backward (< n 0))
10096         (n (abs n)))
10097     (while (and (> n 0)
10098                 (gnus-summary-go-to-next-thread backward))
10099       (decf n))
10100     (unless silent
10101       (gnus-summary-position-point))
10102     (when (and (not silent) (/= 0 n))
10103       (gnus-message 7 "No more threads"))
10104     n))
10105
10106 (defun gnus-summary-prev-thread (n)
10107   "Go to the same level previous N'th thread.
10108 Returns the difference between N and the number of skips actually
10109 done."
10110   (interactive "p")
10111   (gnus-summary-next-thread (- n)))
10112
10113 (defun gnus-summary-go-down-thread ()
10114   "Go down one level in the current thread."
10115   (let ((children (gnus-summary-article-children)))
10116     (when children
10117       (gnus-summary-goto-subject (car children)))))
10118
10119 (defun gnus-summary-go-up-thread ()
10120   "Go up one level in the current thread."
10121   (let ((parent (gnus-summary-article-parent)))
10122     (when parent
10123       (gnus-summary-goto-subject parent))))
10124
10125 (defun gnus-summary-down-thread (n)
10126   "Go down thread N steps.
10127 If N is negative, go up instead.
10128 Returns the difference between N and how many steps down that were
10129 taken."
10130   (interactive "p")
10131   (let ((up (< n 0))
10132         (n (abs n)))
10133     (while (and (> n 0)
10134                 (if up (gnus-summary-go-up-thread)
10135                   (gnus-summary-go-down-thread)))
10136       (setq n (1- n)))
10137     (gnus-summary-position-point)
10138     (when (/= 0 n)
10139       (gnus-message 7 "Can't go further"))
10140     n))
10141
10142 (defun gnus-summary-up-thread (n)
10143   "Go up thread N steps.
10144 If N is negative, go down instead.
10145 Returns the difference between N and how many steps down that were
10146 taken."
10147   (interactive "p")
10148   (gnus-summary-down-thread (- n)))
10149
10150 (defun gnus-summary-top-thread ()
10151   "Go to the top of the thread."
10152   (interactive)
10153   (while (gnus-summary-go-up-thread))
10154   (gnus-summary-article-number))
10155
10156 (defun gnus-summary-kill-thread (&optional unmark)
10157   "Mark articles under current thread as read.
10158 If the prefix argument is positive, remove any kinds of marks.
10159 If the prefix argument is negative, tick articles instead."
10160   (interactive "P")
10161   (when unmark
10162     (setq unmark (prefix-numeric-value unmark)))
10163   (let ((articles (gnus-summary-articles-in-thread)))
10164     (save-excursion
10165       ;; Expand the thread.
10166       (gnus-summary-show-thread)
10167       ;; Mark all the articles.
10168       (while articles
10169         (gnus-summary-goto-subject (car articles))
10170         (cond ((null unmark)
10171                (gnus-summary-mark-article-as-read gnus-killed-mark))
10172               ((> unmark 0)
10173                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10174               (t
10175                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10176         (setq articles (cdr articles))))
10177     ;; Hide killed subtrees.
10178     (and (null unmark)
10179          gnus-thread-hide-killed
10180          (gnus-summary-hide-thread))
10181     ;; If marked as read, go to next unread subject.
10182     (when (null unmark)
10183       ;; Go to next unread subject.
10184       (gnus-summary-next-subject 1 t)))
10185   (gnus-set-mode-line 'summary))
10186
10187 ;; Summary sorting commands
10188
10189 (defun gnus-summary-sort-by-number (&optional reverse)
10190   "Sort the summary buffer by article number.
10191 Argument REVERSE means reverse order."
10192   (interactive "P")
10193   (gnus-summary-sort 'number reverse))
10194
10195 (defun gnus-summary-sort-by-author (&optional reverse)
10196   "Sort the summary buffer by author name alphabetically.
10197 If `case-fold-search' is non-nil, case of letters is ignored.
10198 Argument REVERSE means reverse order."
10199   (interactive "P")
10200   (gnus-summary-sort 'author reverse))
10201
10202 (defun gnus-summary-sort-by-subject (&optional reverse)
10203   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10204 If `case-fold-search' is non-nil, case of letters is ignored.
10205 Argument REVERSE means reverse order."
10206   (interactive "P")
10207   (gnus-summary-sort 'subject reverse))
10208
10209 (defun gnus-summary-sort-by-date (&optional reverse)
10210   "Sort the summary buffer by date.
10211 Argument REVERSE means reverse order."
10212   (interactive "P")
10213   (gnus-summary-sort 'date reverse))
10214
10215 (defun gnus-summary-sort-by-score (&optional reverse)
10216   "Sort the summary buffer by score.
10217 Argument REVERSE means reverse order."
10218   (interactive "P")
10219   (gnus-summary-sort 'score reverse))
10220
10221 (defun gnus-summary-sort-by-lines (&optional reverse)
10222   "Sort the summary buffer by the number of lines.
10223 Argument REVERSE means reverse order."
10224   (interactive "P")
10225   (gnus-summary-sort 'lines reverse))
10226
10227 (defun gnus-summary-sort-by-chars (&optional reverse)
10228   "Sort the summary buffer by article length.
10229 Argument REVERSE means reverse order."
10230   (interactive "P")
10231   (gnus-summary-sort 'chars reverse))
10232
10233 (defun gnus-summary-sort-by-original (&optional reverse)
10234   "Sort the summary buffer using the default sorting method.
10235 Argument REVERSE means reverse order."
10236   (interactive "P")
10237   (let* ((buffer-read-only)
10238          (gnus-summary-prepare-hook nil))
10239     ;; We do the sorting by regenerating the threads.
10240     (gnus-summary-prepare)
10241     ;; Hide subthreads if needed.
10242     (gnus-summary-maybe-hide-threads)))
10243
10244 (defun gnus-summary-sort (predicate reverse)
10245   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10246   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10247          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10248          (gnus-thread-sort-functions
10249           (if (not reverse)
10250               thread
10251             `(lambda (t1 t2)
10252                (,thread t2 t1))))
10253          (gnus-sort-gathered-threads-function
10254           gnus-thread-sort-functions)
10255          (gnus-article-sort-functions
10256           (if (not reverse)
10257               article
10258             `(lambda (t1 t2)
10259                (,article t2 t1))))
10260          (buffer-read-only)
10261          (gnus-summary-prepare-hook nil))
10262     ;; We do the sorting by regenerating the threads.
10263     (gnus-summary-prepare)
10264     ;; Hide subthreads if needed.
10265     (gnus-summary-maybe-hide-threads)))
10266
10267 ;; Summary saving commands.
10268
10269 (defun gnus-summary-save-article (&optional n not-saved)
10270   "Save the current article using the default saver function.
10271 If N is a positive number, save the N next articles.
10272 If N is a negative number, save the N previous articles.
10273 If N is nil and any articles have been marked with the process mark,
10274 save those articles instead.
10275 The variable `gnus-default-article-saver' specifies the saver function."
10276   (interactive "P")
10277   (let* ((articles (gnus-summary-work-articles n))
10278          (save-buffer (save-excursion
10279                         (nnheader-set-temp-buffer " *Gnus Save*")))
10280          (num (length articles))
10281          header file)
10282     (dolist (article articles)
10283       (setq header (gnus-summary-article-header article))
10284       (if (not (vectorp header))
10285           ;; This is a pseudo-article.
10286           (if (assq 'name header)
10287               (gnus-copy-file (cdr (assq 'name header)))
10288             (gnus-message 1 "Article %d is unsaveable" article))
10289         ;; This is a real article.
10290         (save-window-excursion
10291           (let ((gnus-display-mime-function nil)
10292                 (gnus-article-prepare-hook nil))
10293             (gnus-summary-select-article t nil nil article)))
10294         (save-excursion
10295           (set-buffer save-buffer)
10296           (erase-buffer)
10297           (insert-buffer-substring gnus-original-article-buffer))
10298         (setq file (gnus-article-save save-buffer file num))
10299         (gnus-summary-remove-process-mark article)
10300         (unless not-saved
10301           (gnus-summary-set-saved-mark article))))
10302     (gnus-kill-buffer save-buffer)
10303     (gnus-summary-position-point)
10304     (gnus-set-mode-line 'summary)
10305     n))
10306
10307 (defun gnus-summary-pipe-output (&optional arg)
10308   "Pipe the current article to a subprocess.
10309 If N is a positive number, pipe the N next articles.
10310 If N is a negative number, pipe the N previous articles.
10311 If N is nil and any articles have been marked with the process mark,
10312 pipe those articles instead."
10313   (interactive "P")
10314   (require 'gnus-art)
10315   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10316     (gnus-summary-save-article arg t))
10317   (let ((buffer (get-buffer "*Shell Command Output*")))
10318     (if (and buffer
10319              (with-current-buffer buffer (> (point-max) (point-min))))
10320         (gnus-configure-windows 'pipe))))
10321
10322 (defun gnus-summary-save-article-mail (&optional arg)
10323   "Append the current article to an mail file.
10324 If N is a positive number, save the N next articles.
10325 If N is a negative number, save the N previous articles.
10326 If N is nil and any articles have been marked with the process mark,
10327 save those articles instead."
10328   (interactive "P")
10329   (require 'gnus-art)
10330   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10331     (gnus-summary-save-article arg)))
10332
10333 (defun gnus-summary-save-article-rmail (&optional arg)
10334   "Append the current article to an rmail file.
10335 If N is a positive number, save the N next articles.
10336 If N is a negative number, save the N previous articles.
10337 If N is nil and any articles have been marked with the process mark,
10338 save those articles instead."
10339   (interactive "P")
10340   (require 'gnus-art)
10341   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10342     (gnus-summary-save-article arg)))
10343
10344 (defun gnus-summary-save-article-file (&optional arg)
10345   "Append the current article to a file.
10346 If N is a positive number, save the N next articles.
10347 If N is a negative number, save the N previous articles.
10348 If N is nil and any articles have been marked with the process mark,
10349 save those articles instead."
10350   (interactive "P")
10351   (require 'gnus-art)
10352   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10353     (gnus-summary-save-article arg)))
10354
10355 (defun gnus-summary-write-article-file (&optional arg)
10356   "Write the current article to a file, deleting the previous file.
10357 If N is a positive number, save the N next articles.
10358 If N is a negative number, save the N previous articles.
10359 If N is nil and any articles have been marked with the process mark,
10360 save those articles instead."
10361   (interactive "P")
10362   (require 'gnus-art)
10363   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10364     (gnus-summary-save-article arg)))
10365
10366 (defun gnus-summary-save-article-body-file (&optional arg)
10367   "Append the current article body to a file.
10368 If N is a positive number, save the N next articles.
10369 If N is a negative number, save the N previous articles.
10370 If N is nil and any articles have been marked with the process mark,
10371 save those articles instead."
10372   (interactive "P")
10373   (require 'gnus-art)
10374   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10375     (gnus-summary-save-article arg)))
10376
10377 (defun gnus-summary-muttprint (&optional arg)
10378   "Print the current article using Muttprint.
10379 If N is a positive number, save the N next articles.
10380 If N is a negative number, save the N previous articles.
10381 If N is nil and any articles have been marked with the process mark,
10382 save those articles instead."
10383   (interactive "P")
10384   (require 'gnus-art)
10385   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10386     (gnus-summary-save-article arg t)))
10387
10388 (defun gnus-summary-pipe-message (program)
10389   "Pipe the current article through PROGRAM."
10390   (interactive "sProgram: ")
10391   (gnus-summary-select-article)
10392   (let ((mail-header-separator ""))
10393     (gnus-eval-in-buffer-window gnus-article-buffer
10394       (save-restriction
10395         (widen)
10396         (let ((start (window-start))
10397               buffer-read-only)
10398           (message-pipe-buffer-body program)
10399           (set-window-start (get-buffer-window (current-buffer)) start))))))
10400
10401 (defun gnus-get-split-value (methods)
10402   "Return a value based on the split METHODS."
10403   (let (split-name method result match)
10404     (when methods
10405       (save-excursion
10406         (set-buffer gnus-original-article-buffer)
10407         (save-restriction
10408           (nnheader-narrow-to-headers)
10409           (while (and methods (not split-name))
10410             (goto-char (point-min))
10411             (setq method (pop methods))
10412             (setq match (car method))
10413             (when (cond
10414                    ((stringp match)
10415                     ;; Regular expression.
10416                     (ignore-errors
10417                       (re-search-forward match nil t)))
10418                    ((gnus-functionp match)
10419                     ;; Function.
10420                     (save-restriction
10421                       (widen)
10422                       (setq result (funcall match gnus-newsgroup-name))))
10423                    ((consp match)
10424                     ;; Form.
10425                     (save-restriction
10426                       (widen)
10427                       (setq result (eval match)))))
10428               (setq split-name (cdr method))
10429               (cond ((stringp result)
10430                      (push (expand-file-name
10431                             result gnus-article-save-directory)
10432                            split-name))
10433                     ((consp result)
10434                      (setq split-name (append result split-name)))))))))
10435     (nreverse split-name)))
10436
10437 (defun gnus-valid-move-group-p (group)
10438   (and (boundp group)
10439        (symbol-name group)
10440        (symbol-value group)
10441        (gnus-get-function (gnus-find-method-for-group
10442                            (symbol-name group)) 'request-accept-article t)))
10443
10444 (defun gnus-read-move-group-name (prompt default articles prefix)
10445   "Read a group name."
10446   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10447          (minibuffer-confirm-incomplete nil) ; XEmacs
10448          (prom
10449           (format "%s %s to:"
10450                   prompt
10451                   (if (> (length articles) 1)
10452                       (format "these %d articles" (length articles))
10453                     "this article")))
10454          (to-newsgroup
10455           (cond
10456            ((null split-name)
10457             (gnus-completing-read-with-default
10458              default prom
10459              gnus-active-hashtb
10460              'gnus-valid-move-group-p
10461              nil prefix
10462              'gnus-group-history))
10463            ((= 1 (length split-name))
10464             (gnus-completing-read-with-default
10465              (car split-name) prom
10466              gnus-active-hashtb
10467              'gnus-valid-move-group-p
10468              nil nil
10469              'gnus-group-history))
10470            (t
10471             (gnus-completing-read-with-default
10472              nil prom
10473              (mapcar (lambda (el) (list el))
10474                      (nreverse split-name))
10475              nil nil nil
10476              'gnus-group-history))))
10477          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10478     (when to-newsgroup
10479       (if (or (string= to-newsgroup "")
10480               (string= to-newsgroup prefix))
10481           (setq to-newsgroup default))
10482       (unless to-newsgroup
10483         (error "No group name entered"))
10484       (or (gnus-active to-newsgroup)
10485           (gnus-activate-group to-newsgroup nil nil to-method)
10486           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10487                                      to-newsgroup))
10488               (or (and (gnus-request-create-group to-newsgroup to-method)
10489                        (gnus-activate-group
10490                         to-newsgroup nil nil to-method)
10491                        (gnus-subscribe-group to-newsgroup))
10492                   (error "Couldn't create group %s" to-newsgroup)))
10493           (error "No such group: %s" to-newsgroup)))
10494     to-newsgroup))
10495
10496 (defun gnus-summary-save-parts (type dir n &optional reverse)
10497   "Save parts matching TYPE to DIR.
10498 If REVERSE, save parts that do not match TYPE."
10499   (interactive
10500    (list (read-string "Save parts of type: "
10501                       (or (car gnus-summary-save-parts-type-history)
10502                           gnus-summary-save-parts-default-mime)
10503                       'gnus-summary-save-parts-type-history)
10504          (setq gnus-summary-save-parts-last-directory
10505                (read-file-name "Save to directory: "
10506                                gnus-summary-save-parts-last-directory
10507                                nil t))
10508          current-prefix-arg))
10509   (gnus-summary-iterate n
10510     (let ((gnus-display-mime-function nil)
10511           (gnus-inhibit-treatment t))
10512       (gnus-summary-select-article))
10513     (save-excursion
10514       (set-buffer gnus-article-buffer)
10515       (let ((handles (or gnus-article-mime-handles
10516                          (mm-dissect-buffer nil gnus-article-loose-mime)
10517                          (mm-uu-dissect))))
10518         (when handles
10519           (gnus-summary-save-parts-1 type dir handles reverse)
10520           (unless gnus-article-mime-handles ;; Don't destroy this case.
10521             (mm-destroy-parts handles)))))))
10522
10523 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10524   (if (stringp (car handle))
10525       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10526               (cdr handle))
10527     (when (if reverse
10528               (not (string-match type (mm-handle-media-type handle)))
10529             (string-match type (mm-handle-media-type handle)))
10530       (let ((file (expand-file-name
10531                    (file-name-nondirectory
10532                     (or
10533                      (mail-content-type-get
10534                       (mm-handle-disposition handle) 'filename)
10535                      (concat gnus-newsgroup-name
10536                              "." (number-to-string
10537                                   (cdr gnus-article-current)))))
10538                    dir)))
10539         (unless (file-exists-p file)
10540           (mm-save-part-to-file handle file))))))
10541
10542 ;; Summary extract commands
10543
10544 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10545   (let ((buffer-read-only nil)
10546         (article (gnus-summary-article-number))
10547         after-article b e)
10548     (unless (gnus-summary-goto-subject article)
10549       (error "No such article: %d" article))
10550     (gnus-summary-position-point)
10551     ;; If all commands are to be bunched up on one line, we collect
10552     ;; them here.
10553     (unless gnus-view-pseudos-separately
10554       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10555             files action)
10556         (while ps
10557           (setq action (cdr (assq 'action (car ps))))
10558           (setq files (list (cdr (assq 'name (car ps)))))
10559           (while (and ps (cdr ps)
10560                       (string= (or action "1")
10561                                (or (cdr (assq 'action (cadr ps))) "2")))
10562             (push (cdr (assq 'name (cadr ps))) files)
10563             (setcdr ps (cddr ps)))
10564           (when files
10565             (when (not (string-match "%s" action))
10566               (push " " files))
10567             (push " " files)
10568             (when (assq 'execute (car ps))
10569               (setcdr (assq 'execute (car ps))
10570                       (funcall (if (string-match "%s" action)
10571                                    'format 'concat)
10572                                action
10573                                (mapconcat
10574                                 (lambda (f)
10575                                   (if (equal f " ")
10576                                       f
10577                                     (gnus-quote-arg-for-sh-or-csh f)))
10578                                 files " ")))))
10579           (setq ps (cdr ps)))))
10580     (if (and gnus-view-pseudos (not not-view))
10581         (while pslist
10582           (when (assq 'execute (car pslist))
10583             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10584                                   (eq gnus-view-pseudos 'not-confirm)))
10585           (setq pslist (cdr pslist)))
10586       (save-excursion
10587         (while pslist
10588           (setq after-article (or (cdr (assq 'article (car pslist)))
10589                                   (gnus-summary-article-number)))
10590           (gnus-summary-goto-subject after-article)
10591           (forward-line 1)
10592           (setq b (point))
10593           (insert "    " (file-name-nondirectory
10594                           (cdr (assq 'name (car pslist))))
10595                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10596           (setq e (point))
10597           (forward-line -1)             ; back to `b'
10598           (gnus-add-text-properties
10599            b (1- e) (list 'gnus-number gnus-reffed-article-number
10600                           gnus-mouse-face-prop gnus-mouse-face))
10601           (gnus-data-enter
10602            after-article gnus-reffed-article-number
10603            gnus-unread-mark b (car pslist) 0 (- e b))
10604           (setq gnus-newsgroup-unreads
10605                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10606                                          gnus-reffed-article-number))
10607           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10608           (setq pslist (cdr pslist)))))))
10609
10610 (defun gnus-pseudos< (p1 p2)
10611   (let ((c1 (cdr (assq 'action p1)))
10612         (c2 (cdr (assq 'action p2))))
10613     (and c1 c2 (string< c1 c2))))
10614
10615 (defun gnus-request-pseudo-article (props)
10616   (cond ((assq 'execute props)
10617          (gnus-execute-command (cdr (assq 'execute props)))))
10618   (let ((gnus-current-article (gnus-summary-article-number)))
10619     (gnus-run-hooks 'gnus-mark-article-hook)))
10620
10621 (defun gnus-execute-command (command &optional automatic)
10622   (save-excursion
10623     (gnus-article-setup-buffer)
10624     (set-buffer gnus-article-buffer)
10625     (setq buffer-read-only nil)
10626     (let ((command (if automatic command
10627                      (read-string "Command: " (cons command 0)))))
10628       (erase-buffer)
10629       (insert "$ " command "\n\n")
10630       (if gnus-view-pseudo-asynchronously
10631           (start-process "gnus-execute" (current-buffer) shell-file-name
10632                          shell-command-switch command)
10633         (call-process shell-file-name nil t nil
10634                       shell-command-switch command)))))
10635
10636 ;; Summary kill commands.
10637
10638 (defun gnus-summary-edit-global-kill (article)
10639   "Edit the \"global\" kill file."
10640   (interactive (list (gnus-summary-article-number)))
10641   (gnus-group-edit-global-kill article))
10642
10643 (defun gnus-summary-edit-local-kill ()
10644   "Edit a local kill file applied to the current newsgroup."
10645   (interactive)
10646   (setq gnus-current-headers (gnus-summary-article-header))
10647   (gnus-group-edit-local-kill
10648    (gnus-summary-article-number) gnus-newsgroup-name))
10649
10650 ;;; Header reading.
10651
10652 (defun gnus-read-header (id &optional header)
10653   "Read the headers of article ID and enter them into the Gnus system."
10654   (let ((group gnus-newsgroup-name)
10655         (gnus-override-method
10656          (or
10657           gnus-override-method
10658           (and (gnus-news-group-p gnus-newsgroup-name)
10659                (car (gnus-refer-article-methods)))))
10660         where)
10661     ;; First we check to see whether the header in question is already
10662     ;; fetched.
10663     (if (stringp id)
10664         ;; This is a Message-ID.
10665         (setq header (or header (gnus-id-to-header id)))
10666       ;; This is an article number.
10667       (setq header (or header (gnus-summary-article-header id))))
10668     (if (and header
10669              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10670         ;; We have found the header.
10671         header
10672       ;; If this is a sparse article, we have to nix out its
10673       ;; previous entry in the thread hashtb.
10674       (when (and header
10675                  (gnus-summary-article-sparse-p (mail-header-number header)))
10676         (let* ((parent (gnus-parent-id (mail-header-references header)))
10677                (thread (and parent (gnus-id-to-thread parent))))
10678           (when thread
10679             (delq (assq header thread) thread))))
10680       ;; We have to really fetch the header to this article.
10681       (save-excursion
10682         (set-buffer nntp-server-buffer)
10683         (when (setq where (gnus-request-head id group))
10684           (nnheader-fold-continuation-lines)
10685           (goto-char (point-max))
10686           (insert ".\n")
10687           (goto-char (point-min))
10688           (insert "211 ")
10689           (princ (cond
10690                   ((numberp id) id)
10691                   ((cdr where) (cdr where))
10692                   (header (mail-header-number header))
10693                   (t gnus-reffed-article-number))
10694                  (current-buffer))
10695           (insert " Article retrieved.\n"))
10696         (if (or (not where)
10697                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10698             ()                          ; Malformed head.
10699           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10700             (when (and (stringp id)
10701                        (not (string= (gnus-group-real-name group)
10702                                      (car where))))
10703               ;; If we fetched by Message-ID and the article came
10704               ;; from a different group, we fudge some bogus article
10705               ;; numbers for this article.
10706               (mail-header-set-number header gnus-reffed-article-number))
10707             (save-excursion
10708               (set-buffer gnus-summary-buffer)
10709               (decf gnus-reffed-article-number)
10710               (gnus-remove-header (mail-header-number header))
10711               (push header gnus-newsgroup-headers)
10712               (setq gnus-current-headers header)
10713               (push (mail-header-number header) gnus-newsgroup-limit)))
10714           header)))))
10715
10716 (defun gnus-remove-header (number)
10717   "Remove header NUMBER from `gnus-newsgroup-headers'."
10718   (if (and gnus-newsgroup-headers
10719            (= number (mail-header-number (car gnus-newsgroup-headers))))
10720       (pop gnus-newsgroup-headers)
10721     (let ((headers gnus-newsgroup-headers))
10722       (while (and (cdr headers)
10723                   (not (= number (mail-header-number (cadr headers)))))
10724         (pop headers))
10725       (when (cdr headers)
10726         (setcdr headers (cddr headers))))))
10727
10728 ;;;
10729 ;;; summary highlights
10730 ;;;
10731
10732 (defun gnus-highlight-selected-summary ()
10733   "Highlight selected article in summary buffer."
10734   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10735   (when gnus-summary-selected-face
10736     (save-excursion
10737       (let* ((beg (progn (beginning-of-line) (point)))
10738              (end (progn (end-of-line) (point)))
10739              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10740              (from (if (get-text-property beg gnus-mouse-face-prop)
10741                        beg
10742                      (or (next-single-property-change
10743                           beg gnus-mouse-face-prop nil end)
10744                          beg)))
10745              (to
10746               (if (= from end)
10747                   (- from 2)
10748                 (or (next-single-property-change
10749                      from gnus-mouse-face-prop nil end)
10750                     end))))
10751         ;; If no mouse-face prop on line we will have to = from = end,
10752         ;; so we highlight the entire line instead.
10753         (when (= (+ to 2) from)
10754           (setq from beg)
10755           (setq to end))
10756         (if gnus-newsgroup-selected-overlay
10757             ;; Move old overlay.
10758             (gnus-move-overlay
10759              gnus-newsgroup-selected-overlay from to (current-buffer))
10760           ;; Create new overlay.
10761           (gnus-overlay-put
10762            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10763            'face gnus-summary-selected-face))))))
10764
10765 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10766 (defun gnus-summary-highlight-line ()
10767   "Highlight current line according to `gnus-summary-highlight'."
10768   (let* ((list gnus-summary-highlight)
10769          (p (point))
10770          (end (progn (end-of-line) (point)))
10771          ;; now find out where the line starts and leave point there.
10772          (beg (progn (beginning-of-line) (point)))
10773          (article (gnus-summary-article-number))
10774          (score (or (cdr (assq (or article gnus-current-article)
10775                                gnus-newsgroup-scored))
10776                     gnus-summary-default-score 0))
10777          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10778          (inhibit-read-only t))
10779     ;; Eval the cars of the lists until we find a match.
10780     (let ((default gnus-summary-default-score)
10781           (default-high gnus-summary-default-high-score)
10782           (default-low gnus-summary-default-low-score))
10783       (while (and list
10784                   (not (eval (caar list))))
10785         (setq list (cdr list))))
10786     (let ((face (cdar list)))
10787       (unless (eq face (get-text-property beg 'face))
10788         (gnus-put-text-property-excluding-characters-with-faces
10789          beg end 'face
10790          (setq face (if (boundp face) (symbol-value face) face)))
10791         (when gnus-summary-highlight-line-function
10792           (funcall gnus-summary-highlight-line-function article face))))
10793     (goto-char p)))
10794
10795 (defun gnus-update-read-articles (group unread &optional compute)
10796   "Update the list of read articles in GROUP.
10797 UNREAD is a sorted list."
10798   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10799          (entry (gnus-gethash group gnus-newsrc-hashtb))
10800          (info (nth 2 entry))
10801          (prev 1)
10802          read)
10803     (if (or (not info) (not active))
10804         ;; There is no info on this group if it was, in fact,
10805         ;; killed.  Gnus stores no information on killed groups, so
10806         ;; there's nothing to be done.
10807         ;; One could store the information somewhere temporarily,
10808         ;; perhaps...  Hmmm...
10809         ()
10810       ;; Remove any negative articles numbers.
10811       (while (and unread (< (car unread) 0))
10812         (setq unread (cdr unread)))
10813       ;; Remove any expired article numbers
10814       (while (and unread (< (car unread) (car active)))
10815         (setq unread (cdr unread)))
10816       ;; Compute the ranges of read articles by looking at the list of
10817       ;; unread articles.
10818       (while unread
10819         (when (/= (car unread) prev)
10820           (push (if (= prev (1- (car unread))) prev
10821                   (cons prev (1- (car unread))))
10822                 read))
10823         (setq prev (1+ (car unread)))
10824         (setq unread (cdr unread)))
10825       (when (<= prev (cdr active))
10826         (push (cons prev (cdr active)) read))
10827       (setq read (if (> (length read) 1) (nreverse read) read))
10828       (if compute
10829           read
10830         (save-excursion
10831           (let (setmarkundo)
10832             ;; Propagate the read marks to the backend.
10833             (when (gnus-check-backend-function 'request-set-mark group)
10834               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10835                     (add (gnus-remove-from-range read (gnus-info-read info))))
10836                 (when (or add del)
10837                   (unless (gnus-check-group group)
10838                     (error "Can't open server for %s" group))
10839                   (gnus-request-set-mark
10840                    group (delq nil (list (if add (list add 'add '(read)))
10841                                          (if del (list del 'del '(read))))))
10842                   (setq setmarkundo
10843                         `(gnus-request-set-mark
10844                           ,group
10845                           ',(delq nil (list
10846                                        (if del (list del 'add '(read)))
10847                                        (if add (list add 'del '(read))))))))))
10848             (set-buffer gnus-group-buffer)
10849             (gnus-undo-register
10850               `(progn
10851                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10852                  (gnus-info-set-read ',info ',(gnus-info-read info))
10853                  (gnus-get-unread-articles-in-group ',info
10854                                                     (gnus-active ,group))
10855                  (gnus-group-update-group ,group t)
10856                  ,setmarkundo))))
10857         ;; Enter this list into the group info.
10858         (gnus-info-set-read info read)
10859         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10860         (gnus-get-unread-articles-in-group info (gnus-active group))
10861         t))))
10862
10863 (defun gnus-offer-save-summaries ()
10864   "Offer to save all active summary buffers."
10865   (let (buffers)
10866     ;; Go through all buffers and find all summaries.
10867     (dolist (buffer (buffer-list))
10868       (when (and (setq buffer (buffer-name buffer))
10869                  (string-match "Summary" buffer)
10870                  (save-excursion
10871                    (set-buffer buffer)
10872                    ;; We check that this is, indeed, a summary buffer.
10873                    (and (eq major-mode 'gnus-summary-mode)
10874                         ;; Also make sure this isn't bogus.
10875                         gnus-newsgroup-prepared
10876                         ;; Also make sure that this isn't a
10877                         ;; dead summary buffer.
10878                         (not gnus-dead-summary-mode))))
10879         (push buffer buffers)))
10880     ;; Go through all these summary buffers and offer to save them.
10881     (when buffers
10882       (save-excursion
10883         (map-y-or-n-p
10884          "Update summary buffer %s? "
10885          (lambda (buf)
10886            (switch-to-buffer buf)
10887            (gnus-summary-exit))
10888          buffers)))))
10889
10890
10891 ;;; @ for mime-partial
10892 ;;;
10893
10894 (defun gnus-request-partial-message ()
10895   (save-excursion
10896     (let ((number (gnus-summary-article-number))
10897           (group gnus-newsgroup-name)
10898           (mother gnus-article-buffer))
10899       (set-buffer (get-buffer-create " *Partial Article*"))
10900       (erase-buffer)
10901       (setq mime-preview-buffer mother)
10902       (gnus-request-article-this-buffer number group)
10903       (mime-parse-buffer)
10904       )))
10905
10906 (autoload 'mime-combine-message/partial-pieces-automatically
10907   "mime-partial"
10908   "Internal method to combine message/partial messages automatically.")
10909
10910 (mime-add-condition
10911  'action '((type . message)(subtype . partial)
10912            (major-mode . gnus-original-article-mode)
10913            (method . mime-combine-message/partial-pieces-automatically)
10914            (summary-buffer-exp . gnus-summary-buffer)
10915            (request-partial-message-method . gnus-request-partial-message)
10916            ))
10917
10918
10919 ;;; @ for message/rfc822
10920 ;;;
10921
10922 (defun gnus-mime-extract-message/rfc822 (entity situation)
10923   "Burst a forwarded article."
10924   (save-excursion
10925     (set-buffer gnus-summary-buffer)
10926     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10927                                    gnus-newsgroup-name 'gnus-group-history))
10928            (gnus-group-marked (list group))
10929            article info)
10930       (with-temp-buffer
10931         (mime-insert-entity-content entity)
10932         (setq article (gnus-request-accept-article group)))
10933       (when (and (consp article)
10934                  (numberp (setq article (cdr article))))
10935         (setq info (gnus-get-info group))
10936         (gnus-info-set-read info
10937                             (gnus-remove-from-range (gnus-info-read info)
10938                                                     (list article)))
10939         (when (string-equal group gnus-newsgroup-name)
10940           (forward-line 1)
10941           (let (gnus-show-threads)
10942             (gnus-summary-goto-subject article t))
10943           (gnus-summary-clear-mark-forward 1))
10944         (set-buffer gnus-group-buffer)
10945         (gnus-group-get-new-news-this-group nil t)))))
10946
10947 (mime-add-condition
10948  'action '((type . message)(subtype . rfc822)
10949            (major-mode . gnus-original-article-mode)
10950            (method . gnus-mime-extract-message/rfc822)
10951            (mode . "extract")
10952            ))
10953
10954 (mime-add-condition
10955  'action '((type . message)(subtype . news)
10956            (major-mode . gnus-original-article-mode)
10957            (method . gnus-mime-extract-message/rfc822)
10958            (mode . "extract")
10959            ))
10960
10961 (defun gnus-mime-extract-multipart (entity situation)
10962   (let ((children (mime-entity-children entity))
10963         mime-acting-situation-to-override
10964         f)
10965     (while children
10966       (mime-play-entity (car children)
10967                         (cons (assq 'mode situation)
10968                               mime-acting-situation-to-override))
10969       (setq children (cdr children)))
10970     (if (setq f (cdr (assq 'after-method
10971                            mime-acting-situation-to-override)))
10972         (eval f)
10973       )))
10974
10975 (mime-add-condition
10976  'action '((type . multipart)
10977            (method . gnus-mime-extract-multipart)
10978            (mode . "extract")
10979            )
10980  'with-default)
10981
10982
10983 ;;; @ end
10984 ;;;
10985
10986 (defun gnus-summary-setup-default-charset ()
10987   "Setup newsgroup default charset."
10988   (if (equal gnus-newsgroup-name "nndraft:drafts")
10989       (setq gnus-newsgroup-charset nil)
10990     (let* ((ignored-charsets
10991             (or gnus-newsgroup-ephemeral-ignored-charsets
10992                 (append
10993                  (and gnus-newsgroup-name
10994                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10995                  gnus-newsgroup-ignored-charsets))))
10996       (setq gnus-newsgroup-charset
10997             (or gnus-newsgroup-ephemeral-charset
10998                 (and gnus-newsgroup-name
10999                      (gnus-parameter-charset gnus-newsgroup-name))
11000                 gnus-default-charset))
11001       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11002            ignored-charsets))))
11003
11004 ;;;
11005 ;;; Mime Commands
11006 ;;;
11007
11008 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11009   "Display the current article buffer fully MIME-buttonized.
11010 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11011 treated as multipart/mixed."
11012   (interactive "P")
11013   (require 'gnus-art)
11014   (let ((gnus-unbuttonized-mime-types nil)
11015         (gnus-mime-display-multipart-as-mixed show-all-parts))
11016     (gnus-summary-show-article)))
11017
11018 (defun gnus-summary-repair-multipart (article)
11019   "Add a Content-Type header to a multipart article without one."
11020   (interactive (list (gnus-summary-article-number)))
11021   (gnus-with-article article
11022     (message-narrow-to-head)
11023     (message-remove-header "Mime-Version")
11024     (goto-char (point-max))
11025     (insert "Mime-Version: 1.0\n")
11026     (widen)
11027     (when (search-forward "\n--" nil t)
11028       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11029         (message-narrow-to-head)
11030         (message-remove-header "Content-Type")
11031         (goto-char (point-max))
11032         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11033                         separator))
11034         (widen))))
11035   (let (gnus-mark-article-hook)
11036     (gnus-summary-select-article t t nil article)))
11037
11038 (defun gnus-summary-toggle-display-buttonized ()
11039   "Toggle the buttonizing of the article buffer."
11040   (interactive)
11041   (require 'gnus-art)
11042   (if (setq gnus-inhibit-mime-unbuttonizing
11043             (not gnus-inhibit-mime-unbuttonizing))
11044       (let ((gnus-unbuttonized-mime-types nil))
11045         (gnus-summary-show-article))
11046     (gnus-summary-show-article)))
11047
11048 ;;;
11049 ;;; Intelli-mouse commmands
11050 ;;;
11051
11052 (defun gnus-wheel-summary-scroll (event)
11053   (interactive "e")
11054   (let ((amount (if (memq 'shift (event-modifiers event))
11055                     (car gnus-wheel-scroll-amount)
11056                   (cdr gnus-wheel-scroll-amount)))
11057         (direction (- (* (static-if (featurep 'xemacs)
11058                              (event-button event)
11059                            (cond ((eq 'mouse-4 (event-basic-type event))
11060                                   4)
11061                                  ((eq 'mouse-5 (event-basic-type event))
11062                                   5)))
11063                          2) 9))
11064         edge)
11065     (gnus-summary-scroll-up (* amount direction))
11066     (when (gnus-eval-in-buffer-window gnus-article-buffer
11067             (save-restriction
11068               (widen)
11069               (and (if (< 0 direction)
11070                        (gnus-article-next-page 0)
11071                      (gnus-article-prev-page 0)
11072                      (bobp))
11073                    (if (setq edge (get-text-property
11074                                    (point-min) 'gnus-wheel-edge))
11075                        (setq edge (* edge direction))
11076                      (setq edge -1))
11077                    (or (plusp edge)
11078                        (let ((buffer-read-only nil)
11079                              (inhibit-read-only t))
11080                          (put-text-property (point-min) (point-max)
11081                                             'gnus-wheel-edge direction)
11082                          nil))
11083                    (or (> edge gnus-wheel-edge-resistance)
11084                        (let ((buffer-read-only nil)
11085                              (inhibit-read-only t))
11086                          (put-text-property (point-min) (point-max)
11087                                             'gnus-wheel-edge
11088                                             (* (1+ edge) direction))
11089                          nil))
11090                    (eq last-command 'gnus-wheel-summary-scroll))))
11091       (gnus-summary-next-article nil nil (minusp direction)))))
11092
11093 (defun gnus-wheel-install ()
11094   "Enable mouse wheel support on summary window."
11095   (when gnus-use-wheel
11096     (let ((keys
11097            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11098       (dolist (key keys)
11099         (define-key gnus-summary-mode-map key
11100           'gnus-wheel-summary-scroll)))))
11101
11102 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11103
11104 ;;;
11105 ;;; Traditional PGP commmands
11106 ;;;
11107
11108 (defun gnus-summary-decrypt-article (&optional force)
11109   "Decrypt the current article in traditional PGP way.
11110 This will have permanent effect only in mail groups.
11111 If FORCE is non-nil, allow editing of articles even in read-only
11112 groups."
11113   (interactive "P")
11114   (gnus-summary-select-article t)
11115   (gnus-eval-in-buffer-window gnus-article-buffer
11116     (save-excursion
11117       (save-restriction
11118         (widen)
11119         (goto-char (point-min))
11120         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11121           (error "Not a traditional PGP message!"))
11122         (let ((armor-start (match-beginning 0)))
11123           (if (and (pgg-decrypt-region armor-start (point-max))
11124                    (or force (not (gnus-group-read-only-p))))
11125               (let ((inhibit-read-only t)
11126                     buffer-read-only)
11127                 (delete-region armor-start
11128                                (progn
11129                                  (re-search-forward "^-+END PGP" nil t)
11130                                  (beginning-of-line 2)
11131                                  (point)))
11132                 (insert-buffer-substring pgg-output-buffer))))))))
11133
11134 (defun gnus-summary-verify-article ()
11135   "Verify the current article in traditional PGP way."
11136   (interactive)
11137   (save-excursion
11138     (set-buffer gnus-original-article-buffer)
11139     (goto-char (point-min))
11140     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11141       (error "Not a traditional PGP message!"))
11142     (re-search-forward "^-+END PGP" nil t)
11143     (beginning-of-line 2)
11144     (call-interactively (function pgg-verify-region))))
11145
11146 ;;;
11147 ;;; Generic summary marking commands
11148 ;;;
11149
11150 (defvar gnus-summary-marking-alist
11151   '((read gnus-del-mark "d")
11152     (unread gnus-unread-mark "u")
11153     (ticked gnus-ticked-mark "!")
11154     (dormant gnus-dormant-mark "?")
11155     (expirable gnus-expirable-mark "e"))
11156   "An alist of names/marks/keystrokes.")
11157
11158 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11159 (defvar gnus-summary-mark-map)
11160
11161 (defun gnus-summary-make-all-marking-commands ()
11162   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11163   (dolist (elem gnus-summary-marking-alist)
11164     (apply 'gnus-summary-make-marking-command elem)))
11165
11166 (defun gnus-summary-make-marking-command (name mark keystroke)
11167   (let ((map (make-sparse-keymap)))
11168     (define-key gnus-summary-generic-mark-map keystroke map)
11169     (dolist (lway `((next "next" next nil "n")
11170                     (next-unread "next unread" next t "N")
11171                     (prev "previous" prev nil "p")
11172                     (prev-unread "previous unread" prev t "P")
11173                     (nomove "" nil nil ,keystroke)))
11174       (let ((func (gnus-summary-make-marking-command-1
11175                    mark (car lway) lway name)))
11176         (setq func (eval func))
11177         (define-key map (nth 4 lway) func)))))
11178
11179 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11180   `(defun ,(intern
11181             (format "gnus-summary-put-mark-as-%s%s"
11182                     name (if (eq way 'nomove)
11183                              ""
11184                            (concat "-" (symbol-name way)))))
11185      (n)
11186      ,(format
11187        "Mark the current article as %s%s.
11188 If N, the prefix, then repeat N times.
11189 If N is negative, move in reverse order.
11190 The difference between N and the actual number of articles marked is
11191 returned."
11192        name (car (cdr lway)))
11193      (interactive "p")
11194      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11195
11196 (defun gnus-summary-generic-mark (n mark move unread)
11197   "Mark N articles with MARK."
11198   (unless (eq major-mode 'gnus-summary-mode)
11199     (error "This command can only be used in the summary buffer"))
11200   (gnus-summary-show-thread)
11201   (let ((nummove
11202          (cond
11203           ((eq move 'next) 1)
11204           ((eq move 'prev) -1)
11205           (t 0))))
11206     (if (zerop nummove)
11207         (setq n 1)
11208       (when (< n 0)
11209         (setq n (abs n)
11210               nummove (* -1 nummove))))
11211     (while (and (> n 0)
11212                 (gnus-summary-mark-article nil mark)
11213                 (zerop (gnus-summary-next-subject nummove unread t)))
11214       (setq n (1- n)))
11215     (when (/= 0 n)
11216       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11217     (gnus-summary-recenter)
11218     (gnus-summary-position-point)
11219     (gnus-set-mode-line 'summary)
11220     n))
11221
11222 (defun gnus-summary-insert-articles (articles)
11223   (when (setq articles
11224               (gnus-sorted-difference articles
11225                                       (mapcar (lambda (h)
11226                                                 (mail-header-number h))
11227                                               gnus-newsgroup-headers)))
11228     (setq gnus-newsgroup-headers
11229           (merge 'list
11230                  gnus-newsgroup-headers
11231                  (gnus-fetch-headers articles)
11232                  'gnus-article-sort-by-number))
11233     ;; Suppress duplicates?
11234     (when gnus-suppress-duplicates
11235       (gnus-dup-suppress-articles))
11236
11237     ;; We might want to build some more threads first.
11238     (when (and gnus-fetch-old-headers
11239                (eq gnus-headers-retrieved-by 'nov))
11240       (if (eq gnus-fetch-old-headers 'invisible)
11241           (gnus-build-all-threads)
11242         (gnus-build-old-threads)))
11243     ;; Let the Gnus agent mark articles as read.
11244     (when gnus-agent
11245       (gnus-agent-get-undownloaded-list))
11246     ;; Remove list identifiers from subject
11247     (when gnus-list-identifiers
11248       (gnus-summary-remove-list-identifiers))
11249     ;; First and last article in this newsgroup.
11250     (when gnus-newsgroup-headers
11251       (setq gnus-newsgroup-begin
11252             (mail-header-number (car gnus-newsgroup-headers))
11253             gnus-newsgroup-end
11254             (mail-header-number
11255              (gnus-last-element gnus-newsgroup-headers))))
11256     (when gnus-use-scoring
11257       (gnus-possibly-score-headers))))
11258
11259 (defun gnus-summary-insert-old-articles (&optional all)
11260   "Insert all old articles in this group.
11261 If ALL is non-nil, already read articles become readable.
11262 If ALL is a number, fetch this number of articles."
11263   (interactive "P")
11264   (prog1
11265       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11266             older len)
11267         (setq older
11268               (gnus-sorted-difference
11269                (gnus-uncompress-range (list gnus-newsgroup-active))
11270                old))
11271         (setq len (length older))
11272         (cond
11273          ((null older) nil)
11274          ((numberp all)
11275           (if (< all len)
11276               (setq older (last older all))))
11277          (all nil)
11278          (t
11279           (if (and (numberp gnus-large-newsgroup)
11280                    (> len gnus-large-newsgroup))
11281               (let* ((cursor-in-echo-area nil)
11282                      (initial (gnus-parameter-large-newsgroup-initial 
11283                                gnus-newsgroup-name))
11284                      (input
11285                       (read-string
11286                        (format
11287                         "How many articles from %s (%s %d): "
11288                         (gnus-limit-string
11289                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11290                         (if initial "max" "default")
11291                         len)
11292                        (if initial
11293                            (cons (number-to-string initial)
11294                                  0)))))
11295                 (unless (string-match "^[ \t]*$" input)
11296                   (setq all (string-to-number input))
11297                   (if (< all len)
11298                       (setq older (last older all))))))))
11299         (if (not older)
11300             (message "No old news.")
11301           (gnus-summary-insert-articles older)
11302           (gnus-summary-limit (gnus-sorted-nunion old older))))
11303     (gnus-summary-position-point)))
11304
11305 (defun gnus-summary-insert-new-articles ()
11306   "Insert all new articles in this group."
11307   (interactive)
11308   (prog1
11309       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11310             (old-active gnus-newsgroup-active)
11311             (nnmail-fetched-sources (list t))
11312             i new)
11313         (setq gnus-newsgroup-active
11314               (gnus-activate-group gnus-newsgroup-name 'scan))
11315         (setq i (1+ (cdr old-active)))
11316         (while (<= i (cdr gnus-newsgroup-active))
11317           (push i new)
11318           (incf i))
11319         (if (not new)
11320             (message "No gnus is bad news.")
11321           (setq new (nreverse new))
11322           (gnus-summary-insert-articles new)
11323           (setq gnus-newsgroup-unreads
11324                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11325           (gnus-summary-limit (gnus-sorted-nunion old new))))
11326     (gnus-summary-position-point)))
11327
11328 (gnus-summary-make-all-marking-commands)
11329
11330 (gnus-ems-redefine)
11331
11332 (provide 'gnus-sum)
11333
11334 (run-hooks 'gnus-sum-load-hook)
11335
11336 ;;; gnus-sum.el ends here