Synch with Oort Gnus.
[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   '(((eq mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (eq mark gnus-dormant-mark)
871               (eq mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (eq mark gnus-dormant-mark)
875               (eq mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (eq mark gnus-dormant-mark)
878          (eq mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (eq mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (eq mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((eq mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (eq mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (eq mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((eq 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                           )
1999                         (lambda (a b)
2000                           (string< (symbol-name a)
2001                                    (symbol-name b)))))))
2002              ("Washing"
2003               ("Remove Blanks"
2004                ["Leading" gnus-article-strip-leading-blank-lines t]
2005                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2006                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2007                ["All of the above" gnus-article-strip-blank-lines t]
2008                ["All" gnus-article-strip-all-blank-lines t]
2009                ["Leading space" gnus-article-strip-leading-space t]
2010                ["Trailing space" gnus-article-strip-trailing-space t]
2011                ["Leading space in headers"
2012                 gnus-article-remove-leading-whitespace t])
2013               ["Overstrike" gnus-article-treat-overstrike t]
2014               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2015               ["Emphasis" gnus-article-emphasize t]
2016               ["Word wrap" gnus-article-fill-cited-article t]
2017               ["Fill long lines" gnus-article-fill-long-lines t]
2018               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2019               ["CR" gnus-article-remove-cr t]
2020               ["Rot 13" gnus-summary-caesar-message
2021                ,@(if (featurep 'xemacs) '(t)
2022                    '(:help "\"Caesar rotate\" article by 13"))]
2023               ["Unix pipe" gnus-summary-pipe-message t]
2024               ["Add buttons" gnus-article-add-buttons t]
2025               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2026               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2027               ["Toggle MIME" gnus-summary-toggle-mime t]
2028               ["Verbose header" gnus-summary-verbose-headers t]
2029               ["Toggle header" gnus-summary-toggle-header t]
2030               ["Unfold headers" gnus-article-treat-unfold-headers t]
2031               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2032               ["Html" gnus-article-wash-html t]
2033               ["URLs" gnus-article-unsplit-urls t]
2034               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2035               ["HZ" gnus-article-decode-HZ t]
2036               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2037               )
2038              ("Output"
2039               ["Save in default format" gnus-summary-save-article
2040                ,@(if (featurep 'xemacs) '(t)
2041                    '(:help "Save article using default method"))]
2042               ["Save in file" gnus-summary-save-article-file
2043                ,@(if (featurep 'xemacs) '(t)
2044                    '(:help "Save article in file"))]
2045               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2046               ["Save in MH folder" gnus-summary-save-article-folder t]
2047               ["Save in VM folder" gnus-summary-save-article-vm t]
2048               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2049               ["Save body in file" gnus-summary-save-article-body-file t]
2050               ["Pipe through a filter" gnus-summary-pipe-output t]
2051               ["Add to SOUP packet" gnus-soup-add-article t]
2052               ["Print with Muttprint" gnus-summary-muttprint t]
2053               ["Print" gnus-summary-print-article t])
2054              ("Backend"
2055               ["Respool article..." gnus-summary-respool-article t]
2056               ["Move article..." gnus-summary-move-article
2057                (gnus-check-backend-function
2058                 'request-move-article gnus-newsgroup-name)]
2059               ["Copy article..." gnus-summary-copy-article t]
2060               ["Crosspost article..." gnus-summary-crosspost-article
2061                (gnus-check-backend-function
2062                 'request-replace-article gnus-newsgroup-name)]
2063               ["Import file..." gnus-summary-import-article t]
2064               ["Create article..." gnus-summary-create-article t]
2065               ["Check if posted" gnus-summary-article-posted-p t]
2066               ["Edit article" gnus-summary-edit-article
2067                (not (gnus-group-read-only-p))]
2068               ["Delete article" gnus-summary-delete-article
2069                (gnus-check-backend-function
2070                 'request-expire-articles gnus-newsgroup-name)]
2071               ["Query respool" gnus-summary-respool-query t]
2072               ["Trace respool" gnus-summary-respool-trace t]
2073               ["Delete expirable articles" gnus-summary-expire-articles-now
2074                (gnus-check-backend-function
2075                 'request-expire-articles gnus-newsgroup-name)])
2076              ("Extract"
2077               ["Uudecode" gnus-uu-decode-uu
2078                ,@(if (featurep 'xemacs) '(t)
2079                    '(:help "Decode uuencoded article(s)"))]
2080               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2081               ["Unshar" gnus-uu-decode-unshar t]
2082               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2083               ["Save" gnus-uu-decode-save t]
2084               ["Binhex" gnus-uu-decode-binhex t]
2085               ["Postscript" gnus-uu-decode-postscript t])
2086              ("Cache"
2087               ["Enter article" gnus-cache-enter-article t]
2088               ["Remove article" gnus-cache-remove-article t])
2089              ["Translate" gnus-article-babel t]
2090              ["Select article buffer" gnus-summary-select-article-buffer t]
2091              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2092              ["Isearch article..." gnus-summary-isearch-article t]
2093              ["Beginning of the article" gnus-summary-beginning-of-article t]
2094              ["End of the article" gnus-summary-end-of-article t]
2095              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2096              ["Fetch referenced articles" gnus-summary-refer-references t]
2097              ["Fetch current thread" gnus-summary-refer-thread t]
2098              ["Fetch article with id..." gnus-summary-refer-article t]
2099              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2100              ["Redisplay" gnus-summary-show-article t]
2101              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2102       (easy-menu-define
2103        gnus-summary-article-menu gnus-summary-mode-map ""
2104        (cons "Article" innards))
2105
2106       (if (not (keymapp gnus-summary-article-menu))
2107           (easy-menu-define
2108            gnus-article-commands-menu gnus-article-mode-map ""
2109            (cons "Commands" innards))
2110         ;; in Emacs, don't share menu.
2111         (setq gnus-article-commands-menu
2112               (copy-keymap gnus-summary-article-menu))
2113         (define-key gnus-article-mode-map [menu-bar commands]
2114           (cons "Commands" gnus-article-commands-menu))))
2115
2116     (easy-menu-define
2117      gnus-summary-thread-menu gnus-summary-mode-map ""
2118      '("Threads"
2119        ["Toggle threading" gnus-summary-toggle-threads t]
2120        ["Hide threads" gnus-summary-hide-all-threads t]
2121        ["Show threads" gnus-summary-show-all-threads t]
2122        ["Hide thread" gnus-summary-hide-thread t]
2123        ["Show thread" gnus-summary-show-thread t]
2124        ["Go to next thread" gnus-summary-next-thread t]
2125        ["Go to previous thread" gnus-summary-prev-thread t]
2126        ["Go down thread" gnus-summary-down-thread t]
2127        ["Go up thread" gnus-summary-up-thread t]
2128        ["Top of thread" gnus-summary-top-thread t]
2129        ["Mark thread as read" gnus-summary-kill-thread t]
2130        ["Lower thread score" gnus-summary-lower-thread t]
2131        ["Raise thread score" gnus-summary-raise-thread t]
2132        ["Rethread current" gnus-summary-rethread-current t]))
2133
2134     (easy-menu-define
2135      gnus-summary-post-menu gnus-summary-mode-map ""
2136      `("Post"
2137        ["Send a message (mail or news)" gnus-summary-post-news
2138         ,@(if (featurep 'xemacs) '(t)
2139             '(:help "Post an article"))]
2140        ["Followup" gnus-summary-followup
2141         ,@(if (featurep 'xemacs) '(t)
2142             '(:help "Post followup to this article"))]
2143        ["Followup and yank" gnus-summary-followup-with-original
2144         ,@(if (featurep 'xemacs) '(t)
2145             '(:help "Post followup to this article, quoting its contents"))]
2146        ["Supersede article" gnus-summary-supersede-article t]
2147        ["Cancel article" gnus-summary-cancel-article
2148         ,@(if (featurep 'xemacs) '(t)
2149             '(:help "Cancel an article you posted"))]
2150        ["Reply" gnus-summary-reply t]
2151        ["Reply and yank" gnus-summary-reply-with-original t]
2152        ["Wide reply" gnus-summary-wide-reply t]
2153        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2154         ,@(if (featurep 'xemacs) '(t)
2155             '(:help "Mail a reply, quoting this article"))]
2156        ["Very wide reply" gnus-summary-very-wide-reply t]
2157        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2158         ,@(if (featurep 'xemacs) '(t)
2159             '(:help "Mail a very wide reply, quoting this article"))]
2160        ["Mail forward" gnus-summary-mail-forward t]
2161        ["Post forward" gnus-summary-post-forward t]
2162        ["Digest and mail" gnus-summary-digest-mail-forward t]
2163        ["Digest and post" gnus-summary-digest-post-forward t]
2164        ["Resend message" gnus-summary-resend-message t]
2165        ["Resend message edit" gnus-summary-resend-message-edit t]
2166        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2167        ["Send a mail" gnus-summary-mail-other-window t]
2168        ["Create a local message" gnus-summary-news-other-window t]
2169        ["Uuencode and post" gnus-uu-post-news
2170         ,@(if (featurep 'xemacs) '(t)
2171             '(:help "Post a uuencoded article"))]
2172        ["Followup via news" gnus-summary-followup-to-mail t]
2173        ["Followup via news and yank"
2174         gnus-summary-followup-to-mail-with-original t]
2175        ;;("Draft"
2176        ;;["Send" gnus-summary-send-draft t]
2177        ;;["Send bounced" gnus-resend-bounced-mail t])
2178        ))
2179
2180     (cond
2181      ((not (keymapp gnus-summary-post-menu))
2182       (setq gnus-article-post-menu gnus-summary-post-menu))
2183      ((not gnus-article-post-menu)
2184       ;; Don't share post menu.
2185       (setq gnus-article-post-menu
2186             (copy-keymap gnus-summary-post-menu))))
2187     (define-key gnus-article-mode-map [menu-bar post]
2188       (cons "Post" gnus-article-post-menu))
2189
2190     (easy-menu-define
2191      gnus-summary-misc-menu gnus-summary-mode-map ""
2192      `("Gnus"
2193        ("Mark Read"
2194         ["Mark as read" gnus-summary-mark-as-read-forward t]
2195         ["Mark same subject and select"
2196          gnus-summary-kill-same-subject-and-select t]
2197         ["Mark same subject" gnus-summary-kill-same-subject t]
2198         ["Catchup" gnus-summary-catchup
2199          ,@(if (featurep 'xemacs) '(t)
2200              '(:help "Mark unread articles in this group as read"))]
2201         ["Catchup all" gnus-summary-catchup-all t]
2202         ["Catchup to here" gnus-summary-catchup-to-here t]
2203         ["Catchup from here" gnus-summary-catchup-from-here t]
2204         ["Catchup region" gnus-summary-mark-region-as-read t]
2205         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2206        ("Mark Various"
2207         ["Tick" gnus-summary-tick-article-forward t]
2208         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2209         ["Remove marks" gnus-summary-clear-mark-forward t]
2210         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2211         ["Set bookmark" gnus-summary-set-bookmark t]
2212         ["Remove bookmark" gnus-summary-remove-bookmark t])
2213        ("Limit to"
2214         ["Marks..." gnus-summary-limit-to-marks t]
2215         ["Subject..." gnus-summary-limit-to-subject t]
2216         ["Author..." gnus-summary-limit-to-author t]
2217         ["Age..." gnus-summary-limit-to-age t]
2218         ["Extra..." gnus-summary-limit-to-extra t]
2219         ["Score" gnus-summary-limit-to-score t]
2220         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2221         ["Unread" gnus-summary-limit-to-unread t]
2222         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2223         ["Articles" gnus-summary-limit-to-articles t]
2224         ["Pop limit" gnus-summary-pop-limit t]
2225         ["Show dormant" gnus-summary-limit-include-dormant t]
2226         ["Hide childless dormant"
2227          gnus-summary-limit-exclude-childless-dormant t]
2228         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2229         ["Hide marked" gnus-summary-limit-exclude-marks t]
2230         ["Show expunged" gnus-summary-limit-include-expunged t])
2231        ("Process Mark"
2232         ["Set mark" gnus-summary-mark-as-processable t]
2233         ["Remove mark" gnus-summary-unmark-as-processable t]
2234         ["Remove all marks" gnus-summary-unmark-all-processable t]
2235         ["Mark above" gnus-uu-mark-over t]
2236         ["Mark series" gnus-uu-mark-series t]
2237         ["Mark region" gnus-uu-mark-region t]
2238         ["Unmark region" gnus-uu-unmark-region t]
2239         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2240         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2241         ["Mark all" gnus-uu-mark-all t]
2242         ["Mark buffer" gnus-uu-mark-buffer t]
2243         ["Mark sparse" gnus-uu-mark-sparse t]
2244         ["Mark thread" gnus-uu-mark-thread t]
2245         ["Unmark thread" gnus-uu-unmark-thread t]
2246         ("Process Mark Sets"
2247          ["Kill" gnus-summary-kill-process-mark t]
2248          ["Yank" gnus-summary-yank-process-mark
2249           gnus-newsgroup-process-stack]
2250          ["Save" gnus-summary-save-process-mark t]))
2251        ("Scroll article"
2252         ["Page forward" gnus-summary-next-page
2253          ,@(if (featurep 'xemacs) '(t)
2254              '(:help "Show next page of article"))]
2255         ["Page backward" gnus-summary-prev-page
2256          ,@(if (featurep 'xemacs) '(t)
2257              '(:help "Show previous page of article"))]
2258         ["Line forward" gnus-summary-scroll-up t])
2259        ("Move"
2260         ["Next unread article" gnus-summary-next-unread-article t]
2261         ["Previous unread article" gnus-summary-prev-unread-article t]
2262         ["Next article" gnus-summary-next-article t]
2263         ["Previous article" gnus-summary-prev-article t]
2264         ["Next unread subject" gnus-summary-next-unread-subject t]
2265         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2266         ["Next article same subject" gnus-summary-next-same-subject t]
2267         ["Previous article same subject" gnus-summary-prev-same-subject t]
2268         ["First unread article" gnus-summary-first-unread-article t]
2269         ["Best unread article" gnus-summary-best-unread-article t]
2270         ["Go to subject number..." gnus-summary-goto-subject t]
2271         ["Go to article number..." gnus-summary-goto-article t]
2272         ["Go to the last article" gnus-summary-goto-last-article t]
2273         ["Pop article off history" gnus-summary-pop-article t])
2274        ("Sort"
2275         ["Sort by number" gnus-summary-sort-by-number t]
2276         ["Sort by author" gnus-summary-sort-by-author t]
2277         ["Sort by subject" gnus-summary-sort-by-subject t]
2278         ["Sort by date" gnus-summary-sort-by-date t]
2279         ["Sort by score" gnus-summary-sort-by-score t]
2280         ["Sort by lines" gnus-summary-sort-by-lines t]
2281         ["Sort by characters" gnus-summary-sort-by-chars t]
2282         ["Original sort" gnus-summary-sort-by-original t])
2283        ("Help"
2284         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2285         ["Describe group" gnus-summary-describe-group t]
2286         ["Read manual" gnus-info-find-node t])
2287        ("Modes"
2288         ["Pick and read" gnus-pick-mode t]
2289         ["Binary" gnus-binary-mode t])
2290        ("Regeneration"
2291         ["Regenerate" gnus-summary-prepare t]
2292         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2293         ["Toggle threading" gnus-summary-toggle-threads t])
2294        ["See old articles" gnus-summary-insert-old-articles t]
2295        ["See new articles" gnus-summary-insert-new-articles t]
2296        ["Filter articles..." gnus-summary-execute-command t]
2297        ["Run command on subjects..." gnus-summary-universal-argument t]
2298        ["Search articles forward..." gnus-summary-search-article-forward t]
2299        ["Search articles backward..." gnus-summary-search-article-backward t]
2300        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2301        ["Expand window" gnus-summary-expand-window t]
2302        ["Expire expirable articles" gnus-summary-expire-articles
2303         (gnus-check-backend-function
2304          'request-expire-articles gnus-newsgroup-name)]
2305        ["Edit local kill file" gnus-summary-edit-local-kill t]
2306        ["Edit main kill file" gnus-summary-edit-global-kill t]
2307        ["Edit group parameters" gnus-summary-edit-parameters t]
2308        ["Customize group parameters" gnus-summary-customize-parameters t]
2309        ["Send a bug report" gnus-bug t]
2310        ("Exit"
2311         ["Catchup and exit" gnus-summary-catchup-and-exit
2312          ,@(if (featurep 'xemacs) '(t)
2313              '(:help "Mark unread articles in this group as read, then exit"))]
2314         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2315         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2316         ["Exit group" gnus-summary-exit
2317          ,@(if (featurep 'xemacs) '(t)
2318              '(:help "Exit current group, return to group selection mode"))]
2319         ["Exit group without updating" gnus-summary-exit-no-update t]
2320         ["Exit and goto next group" gnus-summary-next-group t]
2321         ["Exit and goto prev group" gnus-summary-prev-group t]
2322         ["Reselect group" gnus-summary-reselect-current-group t]
2323         ["Rescan group" gnus-summary-rescan-group t]
2324         ["Update dribble" gnus-summary-save-newsrc t])))
2325
2326     (gnus-run-hooks 'gnus-summary-menu-hook)))
2327
2328 (defvar gnus-summary-tool-bar-map nil)
2329
2330 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2331 (defun gnus-summary-make-tool-bar ()
2332   (if (and (fboundp 'tool-bar-add-item-from-menu)
2333            (default-value 'tool-bar-mode)
2334            (not gnus-summary-tool-bar-map))
2335       (setq gnus-summary-tool-bar-map
2336             (let ((tool-bar-map (make-sparse-keymap))
2337                   (load-path (mm-image-load-path)))
2338               (tool-bar-add-item-from-menu
2339                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2340               (tool-bar-add-item-from-menu
2341                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2342               (tool-bar-add-item-from-menu
2343                'gnus-summary-post-news "post" gnus-summary-mode-map)
2344               (tool-bar-add-item-from-menu
2345                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2346               (tool-bar-add-item-from-menu
2347                'gnus-summary-followup "followup" gnus-summary-mode-map)
2348               (tool-bar-add-item-from-menu
2349                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2350               (tool-bar-add-item-from-menu
2351                'gnus-summary-reply "reply" gnus-summary-mode-map)
2352               (tool-bar-add-item-from-menu
2353                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2354               (tool-bar-add-item-from-menu
2355                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2356               (tool-bar-add-item-from-menu
2357                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2358               (tool-bar-add-item-from-menu
2359                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2360               (tool-bar-add-item-from-menu
2361                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2362               (tool-bar-add-item-from-menu
2363                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2364               (tool-bar-add-item-from-menu
2365                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2366               (tool-bar-add-item-from-menu
2367                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2368               tool-bar-map)))
2369   (if gnus-summary-tool-bar-map
2370       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2371
2372 (defun gnus-score-set-default (var value)
2373   "A version of set that updates the GNU Emacs menu-bar."
2374   (set var value)
2375   ;; It is the message that forces the active status to be updated.
2376   (message ""))
2377
2378 (defun gnus-make-score-map (type)
2379   "Make a summary score map of type TYPE."
2380   (if t
2381       nil
2382     (let ((headers '(("author" "from" string)
2383                      ("subject" "subject" string)
2384                      ("article body" "body" string)
2385                      ("article head" "head" string)
2386                      ("xref" "xref" string)
2387                      ("extra header" "extra" string)
2388                      ("lines" "lines" number)
2389                      ("followups to author" "followup" string)))
2390           (types '((number ("less than" <)
2391                            ("greater than" >)
2392                            ("equal" =))
2393                    (string ("substring" s)
2394                            ("exact string" e)
2395                            ("fuzzy string" f)
2396                            ("regexp" r))))
2397           (perms '(("temporary" (current-time-string))
2398                    ("permanent" nil)
2399                    ("immediate" now)))
2400           header)
2401       (list
2402        (apply
2403         'nconc
2404         (list
2405          (if (eq type 'lower)
2406              "Lower score"
2407            "Increase score"))
2408         (let (outh)
2409           (while headers
2410             (setq header (car headers))
2411             (setq outh
2412                   (cons
2413                    (apply
2414                     'nconc
2415                     (list (car header))
2416                     (let ((ts (cdr (assoc (nth 2 header) types)))
2417                           outt)
2418                       (while ts
2419                         (setq outt
2420                               (cons
2421                                (apply
2422                                 'nconc
2423                                 (list (caar ts))
2424                                 (let ((ps perms)
2425                                       outp)
2426                                   (while ps
2427                                     (setq outp
2428                                           (cons
2429                                            (vector
2430                                             (caar ps)
2431                                             (list
2432                                              'gnus-summary-score-entry
2433                                              (nth 1 header)
2434                                              (if (or (string= (nth 1 header)
2435                                                               "head")
2436                                                      (string= (nth 1 header)
2437                                                               "body"))
2438                                                  ""
2439                                                (list 'gnus-summary-header
2440                                                      (nth 1 header)))
2441                                              (list 'quote (nth 1 (car ts)))
2442                                              (list 'gnus-score-delta-default
2443                                                    nil)
2444                                              (nth 1 (car ps))
2445                                              t)
2446                                             t)
2447                                            outp))
2448                                     (setq ps (cdr ps)))
2449                                   (list (nreverse outp))))
2450                                outt))
2451                         (setq ts (cdr ts)))
2452                       (list (nreverse outt))))
2453                    outh))
2454             (setq headers (cdr headers)))
2455           (list (nreverse outh))))))))
2456
2457 \f
2458
2459 (defun gnus-summary-mode (&optional group)
2460   "Major mode for reading articles.
2461
2462 All normal editing commands are switched off.
2463 \\<gnus-summary-mode-map>
2464 Each line in this buffer represents one article.  To read an
2465 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2466 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2467 respectively.
2468
2469 You can also post articles and send mail from this buffer.  To
2470 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2471 of an article, type `\\[gnus-summary-reply]'.
2472
2473 There are approx. one gazillion commands you can execute in this
2474 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2475
2476 The following commands are available:
2477
2478 \\{gnus-summary-mode-map}"
2479   (interactive)
2480   (kill-all-local-variables)
2481   (when (gnus-visual-p 'summary-menu 'menu)
2482     (gnus-summary-make-menu-bar)
2483     (gnus-summary-make-tool-bar))
2484   (gnus-summary-make-local-variables)
2485   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2486     (gnus-summary-make-local-variables))
2487   (gnus-make-thread-indent-array)
2488   (gnus-simplify-mode-line)
2489   (setq major-mode 'gnus-summary-mode)
2490   (setq mode-name "Summary")
2491   (make-local-variable 'minor-mode-alist)
2492   (use-local-map gnus-summary-mode-map)
2493   (buffer-disable-undo)
2494   (setq buffer-read-only t)             ;Disable modification
2495   (setq truncate-lines t)
2496   (setq selective-display t)
2497   (setq selective-display-ellipses t)   ;Display `...'
2498   (gnus-summary-set-display-table)
2499   (gnus-set-default-directory)
2500   (setq gnus-newsgroup-name group)
2501   (unless (gnus-news-group-p group)
2502     (setq gnus-newsgroup-incorporated
2503           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2504   (make-local-variable 'gnus-summary-line-format)
2505   (make-local-variable 'gnus-summary-line-format-spec)
2506   (make-local-variable 'gnus-summary-dummy-line-format)
2507   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2508   (make-local-variable 'gnus-summary-mark-positions)
2509   (make-local-hook 'pre-command-hook)
2510   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2511   (gnus-run-hooks 'gnus-summary-mode-hook)
2512   (turn-on-gnus-mailing-list-mode)
2513   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2514   (gnus-update-summary-mark-positions))
2515
2516 (defun gnus-summary-make-local-variables ()
2517   "Make all the local summary buffer variables."
2518   (let (global)
2519     (dolist (local gnus-summary-local-variables)
2520       (if (consp local)
2521           (progn
2522             (if (eq (cdr local) 'global)
2523                 ;; Copy the global value of the variable.
2524                 (setq global (symbol-value (car local)))
2525               ;; Use the value from the list.
2526               (setq global (eval (cdr local))))
2527             (set (make-local-variable (car local)) global))
2528         ;; Simple nil-valued local variable.
2529         (set (make-local-variable local) nil)))))
2530
2531 (defun gnus-summary-clear-local-variables ()
2532   (let ((locals gnus-summary-local-variables))
2533     (while locals
2534       (if (consp (car locals))
2535           (and (vectorp (caar locals))
2536                (set (caar locals) nil))
2537         (and (vectorp (car locals))
2538              (set (car locals) nil)))
2539       (setq locals (cdr locals)))))
2540
2541 ;; Summary data functions.
2542
2543 (defmacro gnus-data-number (data)
2544   `(car ,data))
2545
2546 (defmacro gnus-data-set-number (data number)
2547   `(setcar ,data ,number))
2548
2549 (defmacro gnus-data-mark (data)
2550   `(nth 1 ,data))
2551
2552 (defmacro gnus-data-set-mark (data mark)
2553   `(setcar (nthcdr 1 ,data) ,mark))
2554
2555 (defmacro gnus-data-pos (data)
2556   `(nth 2 ,data))
2557
2558 (defmacro gnus-data-set-pos (data pos)
2559   `(setcar (nthcdr 2 ,data) ,pos))
2560
2561 (defmacro gnus-data-header (data)
2562   `(nth 3 ,data))
2563
2564 (defmacro gnus-data-set-header (data header)
2565   `(setcar (nthcdr 3 ,data) ,header))
2566
2567 (defmacro gnus-data-level (data)
2568   `(nth 4 ,data))
2569
2570 (defmacro gnus-data-unread-p (data)
2571   `(= (nth 1 ,data) gnus-unread-mark))
2572
2573 (defmacro gnus-data-read-p (data)
2574   `(/= (nth 1 ,data) gnus-unread-mark))
2575
2576 (defmacro gnus-data-pseudo-p (data)
2577   `(consp (nth 3 ,data)))
2578
2579 (defmacro gnus-data-find (number)
2580   `(assq ,number gnus-newsgroup-data))
2581
2582 (defmacro gnus-data-find-list (number &optional data)
2583   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2584      (memq (assq ,number bdata)
2585            bdata)))
2586
2587 (defmacro gnus-data-make (number mark pos header level)
2588   `(list ,number ,mark ,pos ,header ,level))
2589
2590 (defun gnus-data-enter (after-article number mark pos header level offset)
2591   (let ((data (gnus-data-find-list after-article)))
2592     (unless data
2593       (error "No such article: %d" after-article))
2594     (setcdr data (cons (gnus-data-make number mark pos header level)
2595                        (cdr data)))
2596     (setq gnus-newsgroup-data-reverse nil)
2597     (gnus-data-update-list (cddr data) offset)))
2598
2599 (defun gnus-data-enter-list (after-article list &optional offset)
2600   (when list
2601     (let ((data (and after-article (gnus-data-find-list after-article)))
2602           (ilist list))
2603       (if (not (or data
2604                    after-article))
2605           (let ((odata gnus-newsgroup-data))
2606             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2607             (when offset
2608               (gnus-data-update-list odata offset)))
2609         ;; Find the last element in the list to be spliced into the main
2610         ;; list.
2611         (while (cdr list)
2612           (setq list (cdr list)))
2613         (if (not data)
2614             (progn
2615               (setcdr list gnus-newsgroup-data)
2616               (setq gnus-newsgroup-data ilist)
2617               (when offset
2618                 (gnus-data-update-list (cdr list) offset)))
2619           (setcdr list (cdr data))
2620           (setcdr data ilist)
2621           (when offset
2622             (gnus-data-update-list (cdr list) offset))))
2623       (setq gnus-newsgroup-data-reverse nil))))
2624
2625 (defun gnus-data-remove (article &optional offset)
2626   (let ((data gnus-newsgroup-data))
2627     (if (= (gnus-data-number (car data)) article)
2628         (progn
2629           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2630                 gnus-newsgroup-data-reverse nil)
2631           (when offset
2632             (gnus-data-update-list gnus-newsgroup-data offset)))
2633       (while (cdr data)
2634         (when (= (gnus-data-number (cadr data)) article)
2635           (setcdr data (cddr data))
2636           (when offset
2637             (gnus-data-update-list (cdr data) offset))
2638           (setq data nil
2639                 gnus-newsgroup-data-reverse nil))
2640         (setq data (cdr data))))))
2641
2642 (defmacro gnus-data-list (backward)
2643   `(if ,backward
2644        (or gnus-newsgroup-data-reverse
2645            (setq gnus-newsgroup-data-reverse
2646                  (reverse gnus-newsgroup-data)))
2647      gnus-newsgroup-data))
2648
2649 (defun gnus-data-update-list (data offset)
2650   "Add OFFSET to the POS of all data entries in DATA."
2651   (setq gnus-newsgroup-data-reverse nil)
2652   (while data
2653     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2654     (setq data (cdr data))))
2655
2656 (defun gnus-summary-article-pseudo-p (article)
2657   "Say whether this article is a pseudo article or not."
2658   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2659
2660 (defmacro gnus-summary-article-sparse-p (article)
2661   "Say whether this article is a sparse article or not."
2662   `(memq ,article gnus-newsgroup-sparse))
2663
2664 (defmacro gnus-summary-article-ancient-p (article)
2665   "Say whether this article is a sparse article or not."
2666   `(memq ,article gnus-newsgroup-ancient))
2667
2668 (defun gnus-article-parent-p (number)
2669   "Say whether this article is a parent or not."
2670   (let ((data (gnus-data-find-list number)))
2671     (and (cdr data)                     ; There has to be an article after...
2672          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2673             (gnus-data-level (nth 1 data))))))
2674
2675 (defun gnus-article-children (number)
2676   "Return a list of all children to NUMBER."
2677   (let* ((data (gnus-data-find-list number))
2678          (level (gnus-data-level (car data)))
2679          children)
2680     (setq data (cdr data))
2681     (while (and data
2682                 (= (gnus-data-level (car data)) (1+ level)))
2683       (push (gnus-data-number (car data)) children)
2684       (setq data (cdr data)))
2685     children))
2686
2687 (defmacro gnus-summary-skip-intangible ()
2688   "If the current article is intangible, then jump to a different article."
2689   '(let ((to (get-text-property (point) 'gnus-intangible)))
2690      (and to (gnus-summary-goto-subject to))))
2691
2692 (defmacro gnus-summary-article-intangible-p ()
2693   "Say whether this article is intangible or not."
2694   '(get-text-property (point) 'gnus-intangible))
2695
2696 (defun gnus-article-read-p (article)
2697   "Say whether ARTICLE is read or not."
2698   (not (or (memq article gnus-newsgroup-marked)
2699            (memq article gnus-newsgroup-unreads)
2700            (memq article gnus-newsgroup-unselected)
2701            (memq article gnus-newsgroup-dormant))))
2702
2703 ;; Some summary mode macros.
2704
2705 (defmacro gnus-summary-article-number ()
2706   "The article number of the article on the current line.
2707 If there isn's an article number here, then we return the current
2708 article number."
2709   '(progn
2710      (gnus-summary-skip-intangible)
2711      (or (get-text-property (point) 'gnus-number)
2712          (gnus-summary-last-subject))))
2713
2714 (defmacro gnus-summary-article-header (&optional number)
2715   "Return the header of article NUMBER."
2716   `(gnus-data-header (gnus-data-find
2717                       ,(or number '(gnus-summary-article-number)))))
2718
2719 (defmacro gnus-summary-thread-level (&optional number)
2720   "Return the level of thread that starts with article NUMBER."
2721   `(if (and (eq gnus-summary-make-false-root 'dummy)
2722             (get-text-property (point) 'gnus-intangible))
2723        0
2724      (gnus-data-level (gnus-data-find
2725                        ,(or number '(gnus-summary-article-number))))))
2726
2727 (defmacro gnus-summary-article-mark (&optional number)
2728   "Return the mark of article NUMBER."
2729   `(gnus-data-mark (gnus-data-find
2730                     ,(or number '(gnus-summary-article-number)))))
2731
2732 (defmacro gnus-summary-article-pos (&optional number)
2733   "Return the position of the line of article NUMBER."
2734   `(gnus-data-pos (gnus-data-find
2735                    ,(or number '(gnus-summary-article-number)))))
2736
2737 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2738 (defmacro gnus-summary-article-subject (&optional number)
2739   "Return current subject string or nil if nothing."
2740   `(let ((headers
2741           ,(if number
2742                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2743              '(gnus-data-header (assq (gnus-summary-article-number)
2744                                       gnus-newsgroup-data)))))
2745      (and headers
2746           (vectorp headers)
2747           (mail-header-subject headers))))
2748
2749 (defmacro gnus-summary-article-score (&optional number)
2750   "Return current article score."
2751   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2752                   gnus-newsgroup-scored))
2753        gnus-summary-default-score 0))
2754
2755 (defun gnus-summary-article-children (&optional number)
2756   "Return a list of article numbers that are children of article NUMBER."
2757   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2758          (level (gnus-data-level (car data)))
2759          l children)
2760     (while (and (setq data (cdr data))
2761                 (> (setq l (gnus-data-level (car data))) level))
2762       (and (= (1+ level) l)
2763            (push (gnus-data-number (car data))
2764                  children)))
2765     (nreverse children)))
2766
2767 (defun gnus-summary-article-parent (&optional number)
2768   "Return the article number of the parent of article NUMBER."
2769   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2770                                     (gnus-data-list t)))
2771          (level (gnus-data-level (car data))))
2772     (if (zerop level)
2773         ()                              ; This is a root.
2774       ;; We search until we find an article with a level less than
2775       ;; this one.  That function has to be the parent.
2776       (while (and (setq data (cdr data))
2777                   (not (< (gnus-data-level (car data)) level))))
2778       (and data (gnus-data-number (car data))))))
2779
2780 (defun gnus-unread-mark-p (mark)
2781   "Say whether MARK is the unread mark."
2782   (= mark gnus-unread-mark))
2783
2784 (defun gnus-read-mark-p (mark)
2785   "Say whether MARK is one of the marks that mark as read.
2786 This is all marks except unread, ticked, dormant, and expirable."
2787   (not (or (= mark gnus-unread-mark)
2788            (= mark gnus-ticked-mark)
2789            (= mark gnus-dormant-mark)
2790            (= mark gnus-expirable-mark))))
2791
2792 (defmacro gnus-article-mark (number)
2793   "Return the MARK of article NUMBER.
2794 This macro should only be used when computing the mark the \"first\"
2795 time; i.e., when generating the summary lines.  After that,
2796 `gnus-summary-article-mark' should be used to examine the
2797 marks of articles."
2798   `(cond
2799     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2800     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2801     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2802     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2803     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2804     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2805     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2806     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2807            gnus-ancient-mark))))
2808
2809 ;; Saving hidden threads.
2810
2811 (defmacro gnus-save-hidden-threads (&rest forms)
2812   "Save hidden threads, eval FORMS, and restore the hidden threads."
2813   (let ((config (make-symbol "config")))
2814     `(let ((,config (gnus-hidden-threads-configuration)))
2815        (unwind-protect
2816            (save-excursion
2817              ,@forms)
2818          (gnus-restore-hidden-threads-configuration ,config)))))
2819 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2820 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2821
2822 (defun gnus-data-compute-positions ()
2823   "Compute the positions of all articles."
2824   (setq gnus-newsgroup-data-reverse nil)
2825   (let ((data gnus-newsgroup-data))
2826     (save-excursion
2827       (gnus-save-hidden-threads
2828         (gnus-summary-show-all-threads)
2829         (goto-char (point-min))
2830         (while data
2831           (while (get-text-property (point) 'gnus-intangible)
2832             (forward-line 1))
2833           (gnus-data-set-pos (car data) (+ (point) 3))
2834           (setq data (cdr data))
2835           (forward-line 1))))))
2836
2837 (defun gnus-hidden-threads-configuration ()
2838   "Return the current hidden threads configuration."
2839   (save-excursion
2840     (let (config)
2841       (goto-char (point-min))
2842       (while (search-forward "\r" nil t)
2843         (push (1- (point)) config))
2844       config)))
2845
2846 (defun gnus-restore-hidden-threads-configuration (config)
2847   "Restore hidden threads configuration from CONFIG."
2848   (save-excursion
2849     (let (point buffer-read-only)
2850       (while (setq point (pop config))
2851         (when (and (< point (point-max))
2852                    (goto-char point)
2853                    (eq (char-after) ?\n))
2854           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2855
2856 ;; Various summary mode internalish functions.
2857
2858 (defun gnus-mouse-pick-article (e)
2859   (interactive "e")
2860   (mouse-set-point e)
2861   (gnus-summary-next-page nil t))
2862
2863 (defun gnus-summary-set-display-table ()
2864   "Change the display table.
2865 Odd characters have a tendency to mess
2866 up nicely formatted displays - we make all possible glyphs
2867 display only a single character."
2868
2869   ;; We start from the standard display table, if any.
2870   (let ((table (or (copy-sequence standard-display-table)
2871                    (make-display-table)))
2872         (i 32))
2873     ;; Nix out all the control chars...
2874     (while (>= (setq i (1- i)) 0)
2875       (aset table i [??]))
2876     ;; ... but not newline and cr, of course.  (cr is necessary for the
2877     ;; selective display).
2878     (aset table ?\n nil)
2879     (aset table ?\r nil)
2880     ;; We keep TAB as well.
2881     (aset table ?\t nil)
2882     ;; We nix out any glyphs over 126 that are not set already.
2883     (let ((i 256))
2884       (while (>= (setq i (1- i)) 127)
2885         ;; Only modify if the entry is nil.
2886         (unless (aref table i)
2887           (aset table i [??]))))
2888     (setq buffer-display-table table)))
2889
2890 (defun gnus-summary-set-article-display-arrow (pos)
2891   "Update the overlay arrow to point to line at position POS."
2892   (when (and gnus-summary-display-arrow
2893              (boundp 'overlay-arrow-position)
2894              (boundp 'overlay-arrow-string))
2895     (save-excursion
2896       (goto-char pos)
2897       (beginning-of-line)
2898       (unless overlay-arrow-position
2899         (setq overlay-arrow-position (make-marker)))
2900       (setq overlay-arrow-string "=>"
2901             overlay-arrow-position (set-marker overlay-arrow-position
2902                                                (point)
2903                                                (current-buffer))))))
2904
2905 (defun gnus-summary-buffer-name (group)
2906   "Return the summary buffer name of GROUP."
2907   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2908
2909 (defun gnus-summary-setup-buffer (group)
2910   "Initialize summary buffer."
2911   (let ((buffer (gnus-summary-buffer-name group))
2912         (dead-name (concat "*Dead Summary "
2913                            (gnus-group-decoded-name group) "*")))
2914     ;; If a dead summary buffer exists, we kill it.
2915     (when (gnus-buffer-live-p dead-name)
2916       (gnus-kill-buffer dead-name))
2917     (if (get-buffer buffer)
2918         (progn
2919           (set-buffer buffer)
2920           (setq gnus-summary-buffer (current-buffer))
2921           (not gnus-newsgroup-prepared))
2922       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2923       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2924       (gnus-summary-mode group)
2925       (when gnus-carpal
2926         (gnus-carpal-setup-buffer 'summary))
2927       (unless gnus-single-article-buffer
2928         (make-local-variable 'gnus-article-buffer)
2929         (make-local-variable 'gnus-article-current)
2930         (make-local-variable 'gnus-original-article-buffer))
2931       (setq gnus-newsgroup-name group)
2932       ;; Set any local variables in the group parameters.
2933       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2934       t)))
2935
2936 (defun gnus-set-global-variables ()
2937   "Set the global equivalents of the buffer-local variables.
2938 They are set to the latest values they had.  These reflect the summary
2939 buffer that was in action when the last article was fetched."
2940   (when (eq major-mode 'gnus-summary-mode)
2941     (setq gnus-summary-buffer (current-buffer))
2942     (let ((name gnus-newsgroup-name)
2943           (marked gnus-newsgroup-marked)
2944           (unread gnus-newsgroup-unreads)
2945           (headers gnus-current-headers)
2946           (data gnus-newsgroup-data)
2947           (summary gnus-summary-buffer)
2948           (article-buffer gnus-article-buffer)
2949           (original gnus-original-article-buffer)
2950           (gac gnus-article-current)
2951           (reffed gnus-reffed-article-number)
2952           (score-file gnus-current-score-file)
2953           (default-charset gnus-newsgroup-charset)
2954           vlist)
2955       (let ((locals gnus-newsgroup-variables))
2956         (while locals
2957           (if (consp (car locals))
2958               (push (eval (caar locals)) vlist)
2959             (push (eval (car locals)) vlist))
2960           (setq locals (cdr locals)))
2961         (setq vlist (nreverse vlist)))
2962       (save-excursion
2963         (set-buffer gnus-group-buffer)
2964         (setq gnus-newsgroup-name name
2965               gnus-newsgroup-marked marked
2966               gnus-newsgroup-unreads unread
2967               gnus-current-headers headers
2968               gnus-newsgroup-data data
2969               gnus-article-current gac
2970               gnus-summary-buffer summary
2971               gnus-article-buffer article-buffer
2972               gnus-original-article-buffer original
2973               gnus-reffed-article-number reffed
2974               gnus-current-score-file score-file
2975               gnus-newsgroup-charset default-charset)
2976         (let ((locals gnus-newsgroup-variables))
2977           (while locals
2978             (if (consp (car locals))
2979                 (set (caar locals) (pop vlist))
2980               (set (car locals) (pop vlist)))
2981             (setq locals (cdr locals))))
2982         ;; The article buffer also has local variables.
2983         (when (gnus-buffer-live-p gnus-article-buffer)
2984           (set-buffer gnus-article-buffer)
2985           (setq gnus-summary-buffer summary))))))
2986
2987 (defun gnus-summary-article-unread-p (article)
2988   "Say whether ARTICLE is unread or not."
2989   (memq article gnus-newsgroup-unreads))
2990
2991 (defun gnus-summary-first-article-p (&optional article)
2992   "Return whether ARTICLE is the first article in the buffer."
2993   (if (not (setq article (or article (gnus-summary-article-number))))
2994       nil
2995     (eq article (caar gnus-newsgroup-data))))
2996
2997 (defun gnus-summary-last-article-p (&optional article)
2998   "Return whether ARTICLE is the last article in the buffer."
2999   (if (not (setq article (or article (gnus-summary-article-number))))
3000       ;; All non-existent numbers are the last article.  :-)
3001       t
3002     (not (cdr (gnus-data-find-list article)))))
3003
3004 (defun gnus-make-thread-indent-array ()
3005   (let ((n 200))
3006     (unless (and gnus-thread-indent-array
3007                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3008       (setq gnus-thread-indent-array (make-vector 201 "")
3009             gnus-thread-indent-array-level gnus-thread-indent-level)
3010       (while (>= n 0)
3011         (aset gnus-thread-indent-array n
3012               (make-string (* n gnus-thread-indent-level) ? ))
3013         (setq n (1- n))))))
3014
3015 (defun gnus-update-summary-mark-positions ()
3016   "Compute where the summary marks are to go."
3017   (save-excursion
3018     (when (gnus-buffer-exists-p gnus-summary-buffer)
3019       (set-buffer gnus-summary-buffer))
3020     (let ((gnus-replied-mark 129)
3021           (gnus-score-below-mark 130)
3022           (gnus-score-over-mark 130)
3023           (gnus-download-mark 131)
3024           (spec gnus-summary-line-format-spec)
3025           gnus-visual pos)
3026       (save-excursion
3027         (gnus-set-work-buffer)
3028         (let ((gnus-summary-line-format-spec spec)
3029               (gnus-newsgroup-downloadable '((0 . t))))
3030           (gnus-summary-insert-line
3031            (make-full-mail-header 0 "" "nobody"
3032                                   "05 Apr 2001 23:33:09 +0400"
3033                                   "" "" 0 0 "" nil)
3034            0 nil 128 t nil "" nil 1)
3035           (goto-char (point-min))
3036           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3037                                              (- (point) 2)))))
3038           (goto-char (point-min))
3039           (push (cons 'replied (and (search-forward "\201" nil t)
3040                                     (- (point) 2)))
3041                 pos)
3042           (goto-char (point-min))
3043           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3044                 pos)
3045           (goto-char (point-min))
3046           (push (cons 'download
3047                       (and (search-forward "\203" nil t) (- (point) 2)))
3048                 pos)))
3049       (setq gnus-summary-mark-positions pos))))
3050
3051 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3052   "Insert a dummy root in the summary buffer."
3053   (beginning-of-line)
3054   (gnus-add-text-properties
3055    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3056    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3057
3058 (defun gnus-summary-extract-address-component (from)
3059   (or (car (funcall gnus-extract-address-components from))
3060       from))
3061
3062 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3063   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3064                                 default-mime-charset)))
3065     ;; Is it really necessary to do this next part for each summary line?
3066     ;; Luckily, doesn't seem to slow things down much.
3067     (or
3068      (and gnus-ignored-from-addresses
3069           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3070           (let ((extra-headers (mail-header-extra header))
3071                 to
3072                 newsgroups)
3073             (cond
3074              ((setq to (cdr (assq 'To extra-headers)))
3075               (concat "-> "
3076                       (inline
3077                         (gnus-summary-extract-address-component
3078                          (funcall gnus-decode-encoded-word-function to)))))
3079              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3080               (concat "=> " newsgroups)))))
3081      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3082
3083 (defun gnus-summary-insert-line (gnus-tmp-header
3084                                  gnus-tmp-level gnus-tmp-current
3085                                  gnus-tmp-unread gnus-tmp-replied
3086                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3087                                  &optional gnus-tmp-dummy gnus-tmp-score
3088                                  gnus-tmp-process)
3089   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3090          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3091          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3092          (gnus-tmp-score-char
3093           (if (or (null gnus-summary-default-score)
3094                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3095                       gnus-summary-zcore-fuzz))
3096               ?\ ;;;Whitespace
3097             (if (< gnus-tmp-score gnus-summary-default-score)
3098                 gnus-score-below-mark gnus-score-over-mark)))
3099          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3100          (gnus-tmp-replied
3101           (cond (gnus-tmp-process gnus-process-mark)
3102                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3103                  gnus-cached-mark)
3104                 (gnus-tmp-replied gnus-replied-mark)
3105                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3106                  gnus-forwarded-mark)
3107                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3108                  gnus-saved-mark)
3109                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3110                  gnus-recent-mark)
3111                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3112                  gnus-unseen-mark)
3113                 (t gnus-no-mark)))
3114          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3115          (gnus-tmp-name
3116           (cond
3117            ((string-match "<[^>]+> *$" gnus-tmp-from)
3118             (let ((beg (match-beginning 0)))
3119               (or (and (string-match "^\".+\"" gnus-tmp-from)
3120                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3121                   (substring gnus-tmp-from 0 beg))))
3122            ((string-match "(.+)" gnus-tmp-from)
3123             (substring gnus-tmp-from
3124                        (1+ (match-beginning 0)) (1- (match-end 0))))
3125            (t gnus-tmp-from)))
3126          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3127          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3128          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3129          (buffer-read-only nil))
3130     (when (string= gnus-tmp-name "")
3131       (setq gnus-tmp-name gnus-tmp-from))
3132     (unless (numberp gnus-tmp-lines)
3133       (setq gnus-tmp-lines -1))
3134     (if (= gnus-tmp-lines -1)
3135         (setq gnus-tmp-lines "?")
3136       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3137     (gnus-put-text-property-excluding-characters-with-faces
3138      (point)
3139      (progn (eval gnus-summary-line-format-spec) (point))
3140      'gnus-number gnus-tmp-number)
3141     (when (gnus-visual-p 'summary-highlight 'highlight)
3142       (forward-line -1)
3143       (gnus-run-hooks 'gnus-summary-update-hook)
3144       (forward-line 1))))
3145
3146 (defun gnus-summary-update-line (&optional dont-update)
3147   "Update summary line after change."
3148   (when (and gnus-summary-default-score
3149              (not gnus-summary-inhibit-highlight))
3150     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3151            (article (gnus-summary-article-number))
3152            (score (gnus-summary-article-score article)))
3153       (unless dont-update
3154         (if (and gnus-summary-mark-below
3155                  (< (gnus-summary-article-score)
3156                     gnus-summary-mark-below))
3157             ;; This article has a low score, so we mark it as read.
3158             (when (memq article gnus-newsgroup-unreads)
3159               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3160           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3161             ;; This article was previously marked as read on account
3162             ;; of a low score, but now it has risen, so we mark it as
3163             ;; unread.
3164             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3165         (gnus-summary-update-mark
3166          (if (or (null gnus-summary-default-score)
3167                  (<= (abs (- score gnus-summary-default-score))
3168                      gnus-summary-zcore-fuzz))
3169              ?\ ;;;Whitespace
3170            (if (< score gnus-summary-default-score)
3171                gnus-score-below-mark gnus-score-over-mark))
3172          'score))
3173       ;; Do visual highlighting.
3174       (when (gnus-visual-p 'summary-highlight 'highlight)
3175         (gnus-run-hooks 'gnus-summary-update-hook)))))
3176
3177 (defvar gnus-tmp-new-adopts nil)
3178
3179 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3180   "Return the number of articles in THREAD.
3181 This may be 0 in some cases -- if none of the articles in
3182 the thread are to be displayed."
3183   (let* ((number
3184           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3185           (cond
3186            ((not (listp thread))
3187             1)
3188            ((and (consp thread) (cdr thread))
3189             (apply
3190              '+ 1 (mapcar
3191                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3192            ((null thread)
3193             1)
3194            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3195             1)
3196            (t 0))))
3197     (when (and level (zerop level) gnus-tmp-new-adopts)
3198       (incf number
3199             (apply '+ (mapcar
3200                        'gnus-summary-number-of-articles-in-thread
3201                        gnus-tmp-new-adopts))))
3202     (if char
3203         (if (> number 1) gnus-not-empty-thread-mark
3204           gnus-empty-thread-mark)
3205       number)))
3206
3207 (defun gnus-summary-set-local-parameters (group)
3208   "Go through the local params of GROUP and set all variable specs in that list."
3209   (let ((params (gnus-group-find-parameter group))
3210         (vars '(quit-config))           ; Ignore quit-config.
3211         elem)
3212     (while params
3213       (setq elem (car params)
3214             params (cdr params))
3215       (and (consp elem)                 ; Has to be a cons.
3216            (consp (cdr elem))           ; The cdr has to be a list.
3217            (symbolp (car elem))         ; Has to be a symbol in there.
3218            (not (memq (car elem) vars))
3219            (ignore-errors               ; So we set it.
3220              (push (car elem) vars)
3221              (make-local-variable (car elem))
3222              (set (car elem) (eval (nth 1 elem))))))))
3223
3224 (defun gnus-summary-read-group (group &optional show-all no-article
3225                                       kill-buffer no-display backward
3226                                       select-articles)
3227   "Start reading news in newsgroup GROUP.
3228 If SHOW-ALL is non-nil, already read articles are also listed.
3229 If NO-ARTICLE is non-nil, no article is selected initially.
3230 If NO-DISPLAY, don't generate a summary buffer."
3231   (let (result)
3232     (while (and group
3233                 (null (setq result
3234                             (let ((gnus-auto-select-next nil))
3235                               (or (gnus-summary-read-group-1
3236                                    group show-all no-article
3237                                    kill-buffer no-display
3238                                    select-articles)
3239                                   (setq show-all nil
3240                                         select-articles nil)))))
3241                 (eq gnus-auto-select-next 'quietly))
3242       (set-buffer gnus-group-buffer)
3243       ;; The entry function called above goes to the next
3244       ;; group automatically, so we go two groups back
3245       ;; if we are searching for the previous group.
3246       (when backward
3247         (gnus-group-prev-unread-group 2))
3248       (if (not (equal group (gnus-group-group-name)))
3249           (setq group (gnus-group-group-name))
3250         (setq group nil)))
3251     result))
3252
3253 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3254   "Directly jump to the other GROUP from summary buffer.
3255 If SHOW-ALL is non-nil, already read articles are also listed."
3256   (interactive
3257    (if (eq gnus-summary-buffer (current-buffer))
3258        (list (completing-read
3259               "Group: " gnus-active-hashtb nil t
3260               (when (and gnus-newsgroup-name
3261                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3262                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3263               'gnus-group-history)
3264              current-prefix-arg)
3265      (error "%s must be invoked from a gnus summary buffer." this-command)))
3266   (unless (or (zerop (length group))
3267               (and gnus-newsgroup-name
3268                    (string-equal gnus-newsgroup-name group)))
3269     (gnus-summary-exit)
3270     (gnus-summary-read-group group show-all
3271                              gnus-dont-select-after-jump-to-other-group)))
3272
3273 (defun gnus-summary-read-group-1 (group show-all no-article
3274                                         kill-buffer no-display
3275                                         &optional select-articles)
3276   ;; Killed foreign groups can't be entered.
3277   ;;  (when (and (not (gnus-group-native-p group))
3278   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3279   ;;    (error "Dead non-native groups can't be entered"))
3280   (gnus-message 5 "Retrieving newsgroup: %s..."
3281                 (gnus-group-decoded-name group))
3282   (let* ((new-group (gnus-summary-setup-buffer group))
3283          (quit-config (gnus-group-quit-config group))
3284          (did-select (and new-group (gnus-select-newsgroup
3285                                      group show-all select-articles))))
3286     (cond
3287      ;; This summary buffer exists already, so we just select it.
3288      ((not new-group)
3289       (gnus-set-global-variables)
3290       (when kill-buffer
3291         (gnus-kill-or-deaden-summary kill-buffer))
3292       (gnus-configure-windows 'summary 'force)
3293       (gnus-set-mode-line 'summary)
3294       (gnus-summary-position-point)
3295       (message "")
3296       t)
3297      ;; We couldn't select this group.
3298      ((null did-select)
3299       (when (and (eq major-mode 'gnus-summary-mode)
3300                  (not (equal (current-buffer) kill-buffer)))
3301         (kill-buffer (current-buffer))
3302         (if (not quit-config)
3303             (progn
3304               ;; Update the info -- marks might need to be removed,
3305               ;; for instance.
3306               (gnus-summary-update-info)
3307               (set-buffer gnus-group-buffer)
3308               (gnus-group-jump-to-group group)
3309               (gnus-group-next-unread-group 1))
3310           (gnus-handle-ephemeral-exit quit-config)))
3311       (let ((grpinfo (gnus-get-info group)))
3312         (if (null (gnus-info-read grpinfo))
3313             (gnus-message 3 "Group %s contains no messages"
3314                           (gnus-group-decoded-name group))
3315           (gnus-message 3 "Can't select group")))
3316       nil)
3317      ;; The user did a `C-g' while prompting for number of articles,
3318      ;; so we exit this group.
3319      ((eq did-select 'quit)
3320       (and (eq major-mode 'gnus-summary-mode)
3321            (not (equal (current-buffer) kill-buffer))
3322            (kill-buffer (current-buffer)))
3323       (when kill-buffer
3324         (gnus-kill-or-deaden-summary kill-buffer))
3325       (if (not quit-config)
3326           (progn
3327             (set-buffer gnus-group-buffer)
3328             (gnus-group-jump-to-group group)
3329             (gnus-group-next-unread-group 1)
3330             (gnus-configure-windows 'group 'force))
3331         (gnus-handle-ephemeral-exit quit-config))
3332       ;; Finally signal the quit.
3333       (signal 'quit nil))
3334      ;; The group was successfully selected.
3335      (t
3336       (gnus-set-global-variables)
3337       ;; Save the active value in effect when the group was entered.
3338       (setq gnus-newsgroup-active
3339             (gnus-copy-sequence
3340              (gnus-active gnus-newsgroup-name)))
3341       ;; You can change the summary buffer in some way with this hook.
3342       (gnus-run-hooks 'gnus-select-group-hook)
3343       (gnus-update-format-specifications
3344        nil 'summary 'summary-mode 'summary-dummy)
3345       (gnus-update-summary-mark-positions)
3346       ;; Do score processing.
3347       (when gnus-use-scoring
3348         (gnus-possibly-score-headers))
3349       ;; Check whether to fill in the gaps in the threads.
3350       (when gnus-build-sparse-threads
3351         (gnus-build-sparse-threads))
3352       ;; Find the initial limit.
3353       (if gnus-show-threads
3354           (if show-all
3355               (let ((gnus-newsgroup-dormant nil))
3356                 (gnus-summary-initial-limit show-all))
3357             (gnus-summary-initial-limit show-all))
3358         ;; When untreaded, all articles are always shown.
3359         (setq gnus-newsgroup-limit
3360               (mapcar
3361                (lambda (header) (mail-header-number header))
3362                gnus-newsgroup-headers)))
3363       ;; Generate the summary buffer.
3364       (unless no-display
3365         (gnus-summary-prepare))
3366       (when gnus-use-trees
3367         (gnus-tree-open group)
3368         (setq gnus-summary-highlight-line-function
3369               'gnus-tree-highlight-article))
3370       ;; If the summary buffer is empty, but there are some low-scored
3371       ;; articles or some excluded dormants, we include these in the
3372       ;; buffer.
3373       (when (and (zerop (buffer-size))
3374                  (not no-display))
3375         (cond (gnus-newsgroup-dormant
3376                (gnus-summary-limit-include-dormant))
3377               ((and gnus-newsgroup-scored show-all)
3378                (gnus-summary-limit-include-expunged t))))
3379       ;; Function `gnus-apply-kill-file' must be called in this hook.
3380       (gnus-run-hooks 'gnus-apply-kill-hook)
3381       (if (and (zerop (buffer-size))
3382                (not no-display))
3383           (progn
3384             ;; This newsgroup is empty.
3385             (gnus-summary-catchup-and-exit nil t)
3386             (gnus-message 6 "No unread news")
3387             (when kill-buffer
3388               (gnus-kill-or-deaden-summary kill-buffer))
3389             ;; Return nil from this function.
3390             nil)
3391         ;; Hide conversation thread subtrees.  We cannot do this in
3392         ;; gnus-summary-prepare-hook since kill processing may not
3393         ;; work with hidden articles.
3394         (gnus-summary-maybe-hide-threads)
3395         (when kill-buffer
3396           (gnus-kill-or-deaden-summary kill-buffer))
3397         (gnus-summary-auto-select-subject)
3398         ;; Show first unread article if requested.
3399         (if (and (not no-article)
3400                  (not no-display)
3401                  gnus-newsgroup-unreads
3402                  gnus-auto-select-first)
3403             (progn
3404               (gnus-configure-windows 'summary)
3405               (let ((art (gnus-summary-article-number)))
3406                 (unless (or (memq art gnus-newsgroup-undownloaded)
3407                             (memq art gnus-newsgroup-downloadable))
3408                   (gnus-summary-goto-article art))))
3409           ;; Don't select any articles.
3410           (gnus-summary-position-point)
3411           (gnus-configure-windows 'summary 'force)
3412           (gnus-set-mode-line 'summary))
3413         (when (get-buffer-window gnus-group-buffer t)
3414           ;; Gotta use windows, because recenter does weird stuff if
3415           ;; the current buffer ain't the displayed window.
3416           (let ((owin (selected-window)))
3417             (select-window (get-buffer-window gnus-group-buffer t))
3418             (when (gnus-group-goto-group group)
3419               (recenter))
3420             (select-window owin)))
3421         ;; Mark this buffer as "prepared".
3422         (setq gnus-newsgroup-prepared t)
3423         (gnus-run-hooks 'gnus-summary-prepared-hook)
3424         t)))))
3425
3426 (defun gnus-summary-auto-select-subject ()
3427   "Select the subject line on initial group entry."
3428   (goto-char (point-min))
3429   (cond
3430    ((eq gnus-auto-select-subject 'best)
3431     (gnus-summary-best-unread-subject))
3432    ((eq gnus-auto-select-subject 'unread)
3433     (gnus-summary-first-unread-subject))
3434    ((eq gnus-auto-select-subject 'unseen)
3435     (gnus-summary-first-unseen-subject))
3436    ((eq gnus-auto-select-subject 'unseen-or-unread)
3437     (gnus-summary-first-unseen-or-unread-subject))
3438    ((eq gnus-auto-select-subject 'first)
3439     ;; Do nothing.
3440     )
3441    ((gnus-functionp gnus-auto-select-subject)
3442     (funcall gnus-auto-select-subject))))
3443
3444 (defun gnus-summary-prepare ()
3445   "Generate the summary buffer."
3446   (interactive)
3447   (let ((buffer-read-only nil))
3448     (erase-buffer)
3449     (setq gnus-newsgroup-data nil
3450           gnus-newsgroup-data-reverse nil)
3451     (gnus-run-hooks 'gnus-summary-generate-hook)
3452     ;; Generate the buffer, either with threads or without.
3453     (when gnus-newsgroup-headers
3454       (gnus-summary-prepare-threads
3455        (if gnus-show-threads
3456            (gnus-sort-gathered-threads
3457             (funcall gnus-summary-thread-gathering-function
3458                      (gnus-sort-threads
3459                       (gnus-cut-threads (gnus-make-threads)))))
3460          ;; Unthreaded display.
3461          (gnus-sort-articles gnus-newsgroup-headers))))
3462     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3463     ;; Call hooks for modifying summary buffer.
3464     (goto-char (point-min))
3465     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3466
3467 (defsubst gnus-general-simplify-subject (subject)
3468   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3469   (setq subject
3470         (cond
3471          ;; Truncate the subject.
3472          (gnus-simplify-subject-functions
3473           (gnus-map-function gnus-simplify-subject-functions subject))
3474          ((numberp gnus-summary-gather-subject-limit)
3475           (setq subject (gnus-simplify-subject-re subject))
3476           (if (> (length subject) gnus-summary-gather-subject-limit)
3477               (substring subject 0 gnus-summary-gather-subject-limit)
3478             subject))
3479          ;; Fuzzily simplify it.
3480          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3481           (gnus-simplify-subject-fuzzy subject))
3482          ;; Just remove the leading "Re:".
3483          (t
3484           (gnus-simplify-subject-re subject))))
3485
3486   (if (and gnus-summary-gather-exclude-subject
3487            (string-match gnus-summary-gather-exclude-subject subject))
3488       nil                               ; This article shouldn't be gathered
3489     subject))
3490
3491 (defun gnus-summary-simplify-subject-query ()
3492   "Query where the respool algorithm would put this article."
3493   (interactive)
3494   (gnus-summary-select-article)
3495   (message "%s"
3496            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3497
3498 (defun gnus-gather-threads-by-subject (threads)
3499   "Gather threads by looking at Subject headers."
3500   (if (not gnus-summary-make-false-root)
3501       threads
3502     (let ((hashtb (gnus-make-hashtable 1024))
3503           (prev threads)
3504           (result threads)
3505           subject hthread whole-subject)
3506       (while threads
3507         (setq subject (gnus-general-simplify-subject
3508                        (setq whole-subject (mail-header-subject
3509                                             (caar threads)))))
3510         (when subject
3511           (if (setq hthread (gnus-gethash subject hashtb))
3512               (progn
3513                 ;; We enter a dummy root into the thread, if we
3514                 ;; haven't done that already.
3515                 (unless (stringp (caar hthread))
3516                   (setcar hthread (list whole-subject (car hthread))))
3517                 ;; We add this new gathered thread to this gathered
3518                 ;; thread.
3519                 (setcdr (car hthread)
3520                         (nconc (cdar hthread) (list (car threads))))
3521                 ;; Remove it from the list of threads.
3522                 (setcdr prev (cdr threads))
3523                 (setq threads prev))
3524             ;; Enter this thread into the hash table.
3525             (gnus-sethash subject threads hashtb)))
3526         (setq prev threads)
3527         (setq threads (cdr threads)))
3528       result)))
3529
3530 (defun gnus-gather-threads-by-references (threads)
3531   "Gather threads by looking at References headers."
3532   (let ((idhashtb (gnus-make-hashtable 1024))
3533         (thhashtb (gnus-make-hashtable 1024))
3534         (prev threads)
3535         (result threads)
3536         ids references id gthread gid entered ref)
3537     (while threads
3538       (when (setq references (mail-header-references (caar threads)))
3539         (setq id (mail-header-id (caar threads))
3540               ids (inline (gnus-split-references references))
3541               entered nil)
3542         (while (setq ref (pop ids))
3543           (setq ids (delete ref ids))
3544           (if (not (setq gid (gnus-gethash ref idhashtb)))
3545               (progn
3546                 (gnus-sethash ref id idhashtb)
3547                 (gnus-sethash id threads thhashtb))
3548             (setq gthread (gnus-gethash gid thhashtb))
3549             (unless entered
3550               ;; We enter a dummy root into the thread, if we
3551               ;; haven't done that already.
3552               (unless (stringp (caar gthread))
3553                 (setcar gthread (list (mail-header-subject (caar gthread))
3554                                       (car gthread))))
3555               ;; We add this new gathered thread to this gathered
3556               ;; thread.
3557               (setcdr (car gthread)
3558                       (nconc (cdar gthread) (list (car threads)))))
3559             ;; Add it into the thread hash table.
3560             (gnus-sethash id gthread thhashtb)
3561             (setq entered t)
3562             ;; Remove it from the list of threads.
3563             (setcdr prev (cdr threads))
3564             (setq threads prev))))
3565       (setq prev threads)
3566       (setq threads (cdr threads)))
3567     result))
3568
3569 (defun gnus-sort-gathered-threads (threads)
3570   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3571   (let ((result threads))
3572     (while threads
3573       (when (stringp (caar threads))
3574         (setcdr (car threads)
3575                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3576       (setq threads (cdr threads)))
3577     result))
3578
3579 (defun gnus-thread-loop-p (root thread)
3580   "Say whether ROOT is in THREAD."
3581   (let ((stack (list thread))
3582         (infloop 0)
3583         th)
3584     (while (setq thread (pop stack))
3585       (setq th (cdr thread))
3586       (while (and th
3587                   (not (eq (caar th) root)))
3588         (pop th))
3589       (if th
3590           ;; We have found a loop.
3591           (let (ref-dep)
3592             (setcdr thread (delq (car th) (cdr thread)))
3593             (if (boundp (setq ref-dep (intern "none"
3594                                               gnus-newsgroup-dependencies)))
3595                 (setcdr (symbol-value ref-dep)
3596                         (nconc (cdr (symbol-value ref-dep))
3597                                (list (car th))))
3598               (set ref-dep (list nil (car th))))
3599             (setq infloop 1
3600                   stack nil))
3601         ;; Push all the subthreads onto the stack.
3602         (push (cdr thread) stack)))
3603     infloop))
3604
3605 (defun gnus-make-threads ()
3606   "Go through the dependency hashtb and find the roots.  Return all threads."
3607   (let (threads)
3608     (while (catch 'infloop
3609              (mapatoms
3610               (lambda (refs)
3611                 ;; Deal with self-referencing References loops.
3612                 (when (and (car (symbol-value refs))
3613                            (not (zerop
3614                                  (apply
3615                                   '+
3616                                   (mapcar
3617                                    (lambda (thread)
3618                                      (gnus-thread-loop-p
3619                                       (car (symbol-value refs)) thread))
3620                                    (cdr (symbol-value refs)))))))
3621                   (setq threads nil)
3622                   (throw 'infloop t))
3623                 (unless (car (symbol-value refs))
3624                   ;; These threads do not refer back to any other articles,
3625                   ;; so they're roots.
3626                   (setq threads (append (cdr (symbol-value refs)) threads))))
3627               gnus-newsgroup-dependencies)))
3628     threads))
3629
3630 ;; Build the thread tree.
3631 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3632   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3633
3634 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3635 if it was already present.
3636
3637 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3638 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3639 Message-IDs will be renamed to a unique Message-ID before being
3640 entered.
3641
3642 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3643   (let* ((id (mail-header-id header))
3644          (id-dep (and id (intern id dependencies)))
3645          ref ref-dep ref-header replaced)
3646     ;; Enter this `header' in the `dependencies' table.
3647     (cond
3648      ((not id-dep)
3649       (setq header nil))
3650      ;; The first two cases do the normal part: enter a new `header'
3651      ;; in the `dependencies' table.
3652      ((not (boundp id-dep))
3653       (set id-dep (list header)))
3654      ((null (car (symbol-value id-dep)))
3655       (setcar (symbol-value id-dep) header))
3656
3657      ;; From here the `header' was already present in the
3658      ;; `dependencies' table.
3659      (force-new
3660       ;; Overrides an existing entry;
3661       ;; just set the header part of the entry.
3662       (setcar (symbol-value id-dep) header)
3663       (setq replaced t))
3664
3665      ;; Renames the existing `header' to a unique Message-ID.
3666      ((not gnus-summary-ignore-duplicates)
3667       ;; An article with this Message-ID has already been seen.
3668       ;; We rename the Message-ID.
3669       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3670            (list header))
3671       (mail-header-set-id header id))
3672
3673      ;; The last case ignores an existing entry, except it adds any
3674      ;; additional Xrefs (in case the two articles came from different
3675      ;; servers.
3676      ;; Also sets `header' to `nil' meaning that the `dependencies'
3677      ;; table was *not* modified.
3678      (t
3679       (mail-header-set-xref
3680        (car (symbol-value id-dep))
3681        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3682                    "")
3683                (or (mail-header-xref header) "")))
3684       (setq header nil)))
3685
3686     (when (and header (not replaced))
3687       ;; First check that we are not creating a References loop.
3688       (setq ref (gnus-parent-id (mail-header-references header)))
3689       (while (and ref
3690                   (setq ref-dep (intern-soft ref dependencies))
3691                   (boundp ref-dep)
3692                   (setq ref-header (car (symbol-value ref-dep))))
3693         (if (string= id ref)
3694             ;; Yuk!  This is a reference loop.  Make the article be a
3695             ;; root article.
3696             (progn
3697               (mail-header-set-references (car (symbol-value id-dep)) "none")
3698               (setq ref nil))
3699           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3700       (setq ref (gnus-parent-id (mail-header-references header)))
3701       (setq ref-dep (intern (or ref "none") dependencies))
3702       (if (boundp ref-dep)
3703           (setcdr (symbol-value ref-dep)
3704                   (nconc (cdr (symbol-value ref-dep))
3705                          (list (symbol-value id-dep))))
3706         (set ref-dep (list nil (symbol-value id-dep)))))
3707     header))
3708
3709 (defun gnus-extract-message-id-from-in-reply-to (string)
3710   (if (string-match "<[^>]+>" string)
3711       (substring string (match-beginning 0) (match-end 0))
3712     nil))
3713
3714 (defun gnus-build-sparse-threads ()
3715   (let ((headers gnus-newsgroup-headers)
3716         (mail-parse-charset gnus-newsgroup-charset)
3717         (gnus-summary-ignore-duplicates t)
3718         header references generation relations
3719         subject child end new-child date)
3720     ;; First we create an alist of generations/relations, where
3721     ;; generations is how much we trust the relation, and the relation
3722     ;; is parent/child.
3723     (gnus-message 7 "Making sparse threads...")
3724     (save-excursion
3725       (nnheader-set-temp-buffer " *gnus sparse threads*")
3726       (while (setq header (pop headers))
3727         (when (and (setq references (mail-header-references header))
3728                    (not (string= references "")))
3729           (insert references)
3730           (setq child (mail-header-id header)
3731                 subject (mail-header-subject header)
3732                 date (mail-header-date header)
3733                 generation 0)
3734           (while (search-backward ">" nil t)
3735             (setq end (1+ (point)))
3736             (when (search-backward "<" nil t)
3737               (setq new-child (buffer-substring (point) end))
3738               (push (list (incf generation)
3739                           child (setq child new-child)
3740                           subject date)
3741                     relations)))
3742           (when child
3743             (push (list (1+ generation) child nil subject) relations))
3744           (erase-buffer)))
3745       (kill-buffer (current-buffer)))
3746     ;; Sort over trustworthiness.
3747     (mapcar
3748      (lambda (relation)
3749        (when (gnus-dependencies-add-header
3750               (make-full-mail-header-from-decoded-header
3751                gnus-reffed-article-number
3752                (nth 3 relation) "" (or (nth 4 relation) "")
3753                (nth 1 relation)
3754                (or (nth 2 relation) "") 0 0 "")
3755               gnus-newsgroup-dependencies nil)
3756          (push gnus-reffed-article-number gnus-newsgroup-limit)
3757          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3758          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3759                gnus-newsgroup-reads)
3760          (decf gnus-reffed-article-number)))
3761      (sort relations 'car-less-than-car))
3762     (gnus-message 7 "Making sparse threads...done")))
3763
3764 (defun gnus-build-old-threads ()
3765   ;; Look at all the articles that refer back to old articles, and
3766   ;; fetch the headers for the articles that aren't there.  This will
3767   ;; build complete threads - if the roots haven't been expired by the
3768   ;; server, that is.
3769   (let ((mail-parse-charset gnus-newsgroup-charset)
3770         id heads)
3771     (mapatoms
3772      (lambda (refs)
3773        (when (not (car (symbol-value refs)))
3774          (setq heads (cdr (symbol-value refs)))
3775          (while heads
3776            (if (memq (mail-header-number (caar heads))
3777                      gnus-newsgroup-dormant)
3778                (setq heads (cdr heads))
3779              (setq id (symbol-name refs))
3780              (while (and (setq id (gnus-build-get-header id))
3781                          (not (car (gnus-id-to-thread id)))))
3782              (setq heads nil)))))
3783      gnus-newsgroup-dependencies)))
3784
3785 ;; This function has to be called with point after the article number
3786 ;; on the beginning of the line.
3787 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3788   (let ((eol (gnus-point-at-eol))
3789         (buffer (current-buffer))
3790         header references in-reply-to)
3791
3792     ;; overview: [num subject from date id refs chars lines misc]
3793     (unwind-protect
3794         (progn
3795           (narrow-to-region (point) eol)
3796           (unless (eobp)
3797             (forward-char))
3798
3799           (setq header
3800                 (make-full-mail-header
3801                  number                         ; number
3802                  (nnheader-nov-field)           ; subject
3803                  (nnheader-nov-field)           ; from
3804                  (nnheader-nov-field)           ; date
3805                  (nnheader-nov-read-message-id) ; id
3806                  (nnheader-nov-field)           ; refs
3807                  (nnheader-nov-read-integer)    ; chars
3808                  (nnheader-nov-read-integer)    ; lines
3809                  (unless (eobp)
3810                    (if (looking-at "Xref: ")
3811                        (goto-char (match-end 0)))
3812                    (nnheader-nov-field))        ; Xref
3813                  (nnheader-nov-parse-extra))))  ; extra
3814
3815       (widen))
3816
3817     (when (and (string= references "")
3818                (setq in-reply-to (mail-header-extra header))
3819                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3820       (mail-header-set-references
3821        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3822
3823     (when gnus-alter-header-function
3824       (funcall gnus-alter-header-function header))
3825     (gnus-dependencies-add-header header dependencies force-new)))
3826
3827 (defun gnus-build-get-header (id)
3828   "Look through the buffer of NOV lines and find the header to ID.
3829 Enter this line into the dependencies hash table, and return
3830 the id of the parent article (if any)."
3831   (let ((deps gnus-newsgroup-dependencies)
3832         found header)
3833     (prog1
3834         (save-excursion
3835           (set-buffer nntp-server-buffer)
3836           (let ((case-fold-search nil))
3837             (goto-char (point-min))
3838             (while (and (not found)
3839                         (search-forward id nil t))
3840               (beginning-of-line)
3841               (setq found (looking-at
3842                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3843                                    (regexp-quote id))))
3844               (or found (beginning-of-line 2)))
3845             (when found
3846               (beginning-of-line)
3847               (and
3848                (setq header (gnus-nov-parse-line
3849                              (read (current-buffer)) deps))
3850                (gnus-parent-id (mail-header-references header))))))
3851       (when header
3852         (let ((number (mail-header-number header)))
3853           (push number gnus-newsgroup-limit)
3854           (push header gnus-newsgroup-headers)
3855           (if (memq number gnus-newsgroup-unselected)
3856               (progn
3857                 (setq gnus-newsgroup-unreads
3858                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3859                                                number))
3860                 (setq gnus-newsgroup-unselected
3861                       (delq number gnus-newsgroup-unselected)))
3862             (push number gnus-newsgroup-ancient)))))))
3863
3864 (defun gnus-build-all-threads ()
3865   "Read all the headers."
3866   (let ((gnus-summary-ignore-duplicates t)
3867         (mail-parse-charset gnus-newsgroup-charset)
3868         (dependencies gnus-newsgroup-dependencies)
3869         header article)
3870     (save-excursion
3871       (set-buffer nntp-server-buffer)
3872       (let ((case-fold-search nil))
3873         (goto-char (point-min))
3874         (while (not (eobp))
3875           (ignore-errors
3876             (setq article (read (current-buffer))
3877                   header (gnus-nov-parse-line article dependencies)))
3878           (when header
3879             (save-excursion
3880               (set-buffer gnus-summary-buffer)
3881               (push header gnus-newsgroup-headers)
3882               (if (memq (setq article (mail-header-number header))
3883                         gnus-newsgroup-unselected)
3884                   (progn
3885                     (setq gnus-newsgroup-unreads
3886                           (gnus-add-to-sorted-list
3887                            gnus-newsgroup-unreads article))
3888                     (setq gnus-newsgroup-unselected
3889                           (delq article gnus-newsgroup-unselected)))
3890                 (push article gnus-newsgroup-ancient)))
3891             (forward-line 1)))))))
3892
3893 (defun gnus-summary-update-article-line (article header)
3894   "Update the line for ARTICLE using HEADERS."
3895   (let* ((id (mail-header-id header))
3896          (thread (gnus-id-to-thread id)))
3897     (unless thread
3898       (error "Article in no thread"))
3899     ;; Update the thread.
3900     (setcar thread header)
3901     (gnus-summary-goto-subject article)
3902     (let* ((datal (gnus-data-find-list article))
3903            (data (car datal))
3904            (length (when (cdr datal)
3905                      (- (gnus-data-pos data)
3906                         (gnus-data-pos (cadr datal)))))
3907            (buffer-read-only nil)
3908            (level (gnus-summary-thread-level)))
3909       (gnus-delete-line)
3910       (gnus-summary-insert-line
3911        header level nil (gnus-article-mark article)
3912        (memq article gnus-newsgroup-replied)
3913        (memq article gnus-newsgroup-expirable)
3914        ;; Only insert the Subject string when it's different
3915        ;; from the previous Subject string.
3916        (if (and
3917             gnus-show-threads
3918             (gnus-subject-equal
3919              (condition-case ()
3920                  (mail-header-subject
3921                   (gnus-data-header
3922                    (cadr
3923                     (gnus-data-find-list
3924                      article
3925                      (gnus-data-list t)))))
3926                ;; Error on the side of excessive subjects.
3927                (error ""))
3928              (mail-header-subject header)))
3929            ""
3930          (mail-header-subject header))
3931        nil (cdr (assq article gnus-newsgroup-scored))
3932        (memq article gnus-newsgroup-processable))
3933       (when length
3934         (gnus-data-update-list
3935          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3936
3937 (defun gnus-summary-update-article (article &optional iheader)
3938   "Update ARTICLE in the summary buffer."
3939   (set-buffer gnus-summary-buffer)
3940   (let* ((header (gnus-summary-article-header article))
3941          (id (mail-header-id header))
3942          (data (gnus-data-find article))
3943          (thread (gnus-id-to-thread id))
3944          (references (mail-header-references header))
3945          (parent
3946           (gnus-id-to-thread
3947            (or (gnus-parent-id
3948                 (when (and references
3949                            (not (equal "" references)))
3950                   references))
3951                "none")))
3952          (buffer-read-only nil)
3953          (old (car thread)))
3954     (when thread
3955       (unless iheader
3956         (setcar thread nil)
3957         (when parent
3958           (delq thread parent)))
3959       (if (gnus-summary-insert-subject id header)
3960           ;; Set the (possibly) new article number in the data structure.
3961           (gnus-data-set-number data (gnus-id-to-article id))
3962         (setcar thread old)
3963         nil))))
3964
3965 (defun gnus-rebuild-thread (id &optional line)
3966   "Rebuild the thread containing ID.
3967 If LINE, insert the rebuilt thread starting on line LINE."
3968   (let ((buffer-read-only nil)
3969         old-pos current thread data)
3970     (if (not gnus-show-threads)
3971         (setq thread (list (car (gnus-id-to-thread id))))
3972       ;; Get the thread this article is part of.
3973       (setq thread (gnus-remove-thread id)))
3974     (setq old-pos (gnus-point-at-bol))
3975     (setq current (save-excursion
3976                     (and (re-search-backward "[\r\n]" nil t)
3977                          (gnus-summary-article-number))))
3978     ;; If this is a gathered thread, we have to go some re-gathering.
3979     (when (stringp (car thread))
3980       (let ((subject (car thread))
3981             roots thr)
3982         (setq thread (cdr thread))
3983         (while thread
3984           (unless (memq (setq thr (gnus-id-to-thread
3985                                    (gnus-root-id
3986                                     (mail-header-id (caar thread)))))
3987                         roots)
3988             (push thr roots))
3989           (setq thread (cdr thread)))
3990         ;; We now have all (unique) roots.
3991         (if (= (length roots) 1)
3992             ;; All the loose roots are now one solid root.
3993             (setq thread (car roots))
3994           (setq thread (cons subject (gnus-sort-threads roots))))))
3995     (let (threads)
3996       ;; We then insert this thread into the summary buffer.
3997       (when line
3998         (goto-char (point-min))
3999         (forward-line (1- line)))
4000       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4001         (if gnus-show-threads
4002             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4003           (gnus-summary-prepare-unthreaded thread))
4004         (setq data (nreverse gnus-newsgroup-data))
4005         (setq threads gnus-newsgroup-threads))
4006       ;; We splice the new data into the data structure.
4007       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4008       ;;!!! then we want to insert at the beginning of the buffer.
4009       ;;!!! That happens to be true with Gnus now, but that may
4010       ;;!!! change in the future.  Perhaps.
4011       (gnus-data-enter-list
4012        (if line nil current) data (- (point) old-pos))
4013       (setq gnus-newsgroup-threads
4014             (nconc threads gnus-newsgroup-threads))
4015       (gnus-data-compute-positions))))
4016
4017 (defun gnus-number-to-header (number)
4018   "Return the header for article NUMBER."
4019   (let ((headers gnus-newsgroup-headers))
4020     (while (and headers
4021                 (not (= number (mail-header-number (car headers)))))
4022       (pop headers))
4023     (when headers
4024       (car headers))))
4025
4026 (defun gnus-parent-headers (in-headers &optional generation)
4027   "Return the headers of the GENERATIONeth parent of HEADERS."
4028   (unless generation
4029     (setq generation 1))
4030   (let ((parent t)
4031         (headers in-headers)
4032         references)
4033     (while (and parent
4034                 (not (zerop generation))
4035                 (setq references (mail-header-references headers)))
4036       (setq headers (if (and references
4037                              (setq parent (gnus-parent-id references)))
4038                         (car (gnus-id-to-thread parent))
4039                       nil))
4040       (decf generation))
4041     (and (not (eq headers in-headers))
4042          headers)))
4043
4044 (defun gnus-id-to-thread (id)
4045   "Return the (sub-)thread where ID appears."
4046   (gnus-gethash id gnus-newsgroup-dependencies))
4047
4048 (defun gnus-id-to-article (id)
4049   "Return the article number of ID."
4050   (let ((thread (gnus-id-to-thread id)))
4051     (when (and thread
4052                (car thread))
4053       (mail-header-number (car thread)))))
4054
4055 (defun gnus-id-to-header (id)
4056   "Return the article headers of ID."
4057   (car (gnus-id-to-thread id)))
4058
4059 (defun gnus-article-displayed-root-p (article)
4060   "Say whether ARTICLE is a root(ish) article."
4061   (let ((level (gnus-summary-thread-level article))
4062         (refs (mail-header-references  (gnus-summary-article-header article)))
4063         particle)
4064     (cond
4065      ((null level) nil)
4066      ((zerop level) t)
4067      ((null refs) t)
4068      ((null (gnus-parent-id refs)) t)
4069      ((and (= 1 level)
4070            (null (setq particle (gnus-id-to-article
4071                                  (gnus-parent-id refs))))
4072            (null (gnus-summary-thread-level particle)))))))
4073
4074 (defun gnus-root-id (id)
4075   "Return the id of the root of the thread where ID appears."
4076   (let (last-id prev)
4077     (while (and id (setq prev (car (gnus-id-to-thread id))))
4078       (setq last-id id
4079             id (gnus-parent-id (mail-header-references prev))))
4080     last-id))
4081
4082 (defun gnus-articles-in-thread (thread)
4083   "Return the list of articles in THREAD."
4084   (cons (mail-header-number (car thread))
4085         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4086
4087 (defun gnus-remove-thread (id &optional dont-remove)
4088   "Remove the thread that has ID in it."
4089   (let (headers thread last-id)
4090     ;; First go up in this thread until we find the root.
4091     (setq last-id (gnus-root-id id)
4092           headers (message-flatten-list (gnus-id-to-thread last-id)))
4093     ;; We have now found the real root of this thread.  It might have
4094     ;; been gathered into some loose thread, so we have to search
4095     ;; through the threads to find the thread we wanted.
4096     (let ((threads gnus-newsgroup-threads)
4097           sub)
4098       (while threads
4099         (setq sub (car threads))
4100         (if (stringp (car sub))
4101             ;; This is a gathered thread, so we look at the roots
4102             ;; below it to find whether this article is in this
4103             ;; gathered root.
4104             (progn
4105               (setq sub (cdr sub))
4106               (while sub
4107                 (when (member (caar sub) headers)
4108                   (setq thread (car threads)
4109                         threads nil
4110                         sub nil))
4111                 (setq sub (cdr sub))))
4112           ;; It's an ordinary thread, so we check it.
4113           (when (eq (car sub) (car headers))
4114             (setq thread sub
4115                   threads nil)))
4116         (setq threads (cdr threads)))
4117       ;; If this article is in no thread, then it's a root.
4118       (if thread
4119           (unless dont-remove
4120             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4121         (setq thread (gnus-id-to-thread last-id)))
4122       (when thread
4123         (prog1
4124             thread                      ; We return this thread.
4125           (unless dont-remove
4126             (if (stringp (car thread))
4127                 (progn
4128                   ;; If we use dummy roots, then we have to remove the
4129                   ;; dummy root as well.
4130                   (when (eq gnus-summary-make-false-root 'dummy)
4131                     ;; We go to the dummy root by going to
4132                     ;; the first sub-"thread", and then one line up.
4133                     (gnus-summary-goto-article
4134                      (mail-header-number (caadr thread)))
4135                     (forward-line -1)
4136                     (gnus-delete-line)
4137                     (gnus-data-compute-positions))
4138                   (setq thread (cdr thread))
4139                   (while thread
4140                     (gnus-remove-thread-1 (car thread))
4141                     (setq thread (cdr thread))))
4142               (gnus-remove-thread-1 thread))))))))
4143
4144 (defun gnus-remove-thread-1 (thread)
4145   "Remove the thread THREAD recursively."
4146   (let ((number (mail-header-number (pop thread)))
4147         d)
4148     (setq thread (reverse thread))
4149     (while thread
4150       (gnus-remove-thread-1 (pop thread)))
4151     (when (setq d (gnus-data-find number))
4152       (goto-char (gnus-data-pos d))
4153       (gnus-summary-show-thread)
4154       (gnus-data-remove
4155        number
4156        (- (gnus-point-at-bol)
4157           (prog1
4158               (1+ (gnus-point-at-eol))
4159             (gnus-delete-line)))))))
4160
4161 (defun gnus-sort-threads-1 (threads func)
4162   (sort (mapcar (lambda (thread)
4163                   (cons (car thread)
4164                         (and (cdr thread)
4165                              (gnus-sort-threads-1 (cdr thread) func))))
4166                 threads) func))
4167
4168 (defun gnus-sort-threads (threads)
4169   "Sort THREADS."
4170   (if (not gnus-thread-sort-functions)
4171       threads
4172     (gnus-message 8 "Sorting threads...")
4173     (prog1
4174         (gnus-sort-threads-1
4175          threads
4176          (gnus-make-sort-function gnus-thread-sort-functions))
4177       (gnus-message 8 "Sorting threads...done"))))
4178
4179 (defun gnus-sort-articles (articles)
4180   "Sort ARTICLES."
4181   (when gnus-article-sort-functions
4182     (gnus-message 7 "Sorting articles...")
4183     (prog1
4184         (setq gnus-newsgroup-headers
4185               (sort articles (gnus-make-sort-function
4186                               gnus-article-sort-functions)))
4187       (gnus-message 7 "Sorting articles...done"))))
4188
4189 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4190 (defmacro gnus-thread-header (thread)
4191   "Return header of first article in THREAD.
4192 Note that THREAD must never, ever be anything else than a variable -
4193 using some other form will lead to serious barfage."
4194   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4195   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4196   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4197         (vector thread) 2))
4198
4199 (defsubst gnus-article-sort-by-number (h1 h2)
4200   "Sort articles by article number."
4201   (< (mail-header-number h1)
4202      (mail-header-number h2)))
4203
4204 (defun gnus-thread-sort-by-number (h1 h2)
4205   "Sort threads by root article number."
4206   (gnus-article-sort-by-number
4207    (gnus-thread-header h1) (gnus-thread-header h2)))
4208
4209 (defsubst gnus-article-sort-by-lines (h1 h2)
4210   "Sort articles by article Lines header."
4211   (< (mail-header-lines h1)
4212      (mail-header-lines h2)))
4213
4214 (defun gnus-thread-sort-by-lines (h1 h2)
4215   "Sort threads by root article Lines header."
4216   (gnus-article-sort-by-lines
4217    (gnus-thread-header h1) (gnus-thread-header h2)))
4218
4219 (defsubst gnus-article-sort-by-chars (h1 h2)
4220   "Sort articles by octet length."
4221   (< (mail-header-chars h1)
4222      (mail-header-chars h2)))
4223
4224 (defun gnus-thread-sort-by-chars (h1 h2)
4225   "Sort threads by root article octet length."
4226   (gnus-article-sort-by-chars
4227    (gnus-thread-header h1) (gnus-thread-header h2)))
4228
4229 (defsubst gnus-article-sort-by-author (h1 h2)
4230   "Sort articles by root author."
4231   (string-lessp
4232    (let ((addr (car (mime-entity-read-field h1 'From))))
4233      (or (std11-full-name-string addr)
4234          (std11-address-string addr)
4235          ""))
4236    (let ((addr (car (mime-entity-read-field h2 'From))))
4237      (or (std11-full-name-string addr)
4238          (std11-address-string addr)
4239          ""))
4240    ))
4241
4242 (defun gnus-thread-sort-by-author (h1 h2)
4243   "Sort threads by root author."
4244   (gnus-article-sort-by-author
4245    (gnus-thread-header h1)  (gnus-thread-header h2)))
4246
4247 (defsubst gnus-article-sort-by-subject (h1 h2)
4248   "Sort articles by root subject."
4249   (string-lessp
4250    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4251    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4252
4253 (defun gnus-thread-sort-by-subject (h1 h2)
4254   "Sort threads by root subject."
4255   (gnus-article-sort-by-subject
4256    (gnus-thread-header h1) (gnus-thread-header h2)))
4257
4258 (defsubst gnus-article-sort-by-date (h1 h2)
4259   "Sort articles by root article date."
4260   (time-less-p
4261    (gnus-date-get-time (mail-header-date h1))
4262    (gnus-date-get-time (mail-header-date h2))))
4263
4264 (defun gnus-thread-sort-by-date (h1 h2)
4265   "Sort threads by root article date."
4266   (gnus-article-sort-by-date
4267    (gnus-thread-header h1) (gnus-thread-header h2)))
4268
4269 (defsubst gnus-article-sort-by-score (h1 h2)
4270   "Sort articles by root article score.
4271 Unscored articles will be counted as having a score of zero."
4272   (> (or (cdr (assq (mail-header-number h1)
4273                     gnus-newsgroup-scored))
4274          gnus-summary-default-score 0)
4275      (or (cdr (assq (mail-header-number h2)
4276                     gnus-newsgroup-scored))
4277          gnus-summary-default-score 0)))
4278
4279 (defun gnus-thread-sort-by-score (h1 h2)
4280   "Sort threads by root article score."
4281   (gnus-article-sort-by-score
4282    (gnus-thread-header h1) (gnus-thread-header h2)))
4283
4284 (defun gnus-thread-sort-by-total-score (h1 h2)
4285   "Sort threads by the sum of all scores in the thread.
4286 Unscored articles will be counted as having a score of zero."
4287   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4288
4289 (defun gnus-thread-total-score (thread)
4290   ;; This function find the total score of THREAD.
4291   (cond
4292    ((null thread)
4293     0)
4294    ((consp thread)
4295     (if (stringp (car thread))
4296         (apply gnus-thread-score-function 0
4297                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4298       (gnus-thread-total-score-1 thread)))
4299    (t
4300     (gnus-thread-total-score-1 (list thread)))))
4301
4302 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4303   "Sort threads such that the thread with the most recently arrived article comes first."
4304   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4305
4306 (defun gnus-thread-highest-number (thread)
4307   "Return the highest article number in THREAD."
4308   (apply 'max (mapcar (lambda (header)
4309                         (mail-header-number header))
4310                       (message-flatten-list thread))))
4311
4312 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4313   "Sort threads such that the thread with the most recently dated article comes first."
4314   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4315
4316 (defun gnus-thread-latest-date (thread)
4317   "Return the highest article date in THREAD."
4318   (let ((previous-time 0))
4319     (apply 'max (mapcar
4320                  (lambda (header)
4321                    (setq previous-time
4322                          (time-to-seconds
4323                           (mail-header-parse-date
4324                            (condition-case ()
4325                                (mail-header-date header)
4326                              (error previous-time))))))
4327                  (sort
4328                   (message-flatten-list thread)
4329                   (lambda (h1 h2)
4330                     (< (mail-header-number h1)
4331                        (mail-header-number h2))))))))
4332
4333 (defun gnus-thread-total-score-1 (root)
4334   ;; This function find the total score of the thread below ROOT.
4335   (setq root (car root))
4336   (apply gnus-thread-score-function
4337          (or (append
4338               (mapcar 'gnus-thread-total-score
4339                       (cdr (gnus-id-to-thread (mail-header-id root))))
4340               (when (> (mail-header-number root) 0)
4341                 (list (or (cdr (assq (mail-header-number root)
4342                                      gnus-newsgroup-scored))
4343                           gnus-summary-default-score 0))))
4344              (list gnus-summary-default-score)
4345              '(0))))
4346
4347 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4348 (defvar gnus-tmp-prev-subject nil)
4349 (defvar gnus-tmp-false-parent nil)
4350 (defvar gnus-tmp-root-expunged nil)
4351 (defvar gnus-tmp-dummy-line nil)
4352
4353 (eval-when-compile (defvar gnus-tmp-header))
4354 (defun gnus-extra-header (type &optional header)
4355   "Return the extra header of TYPE."
4356   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4357       ""))
4358
4359 (defvar gnus-tmp-thread-tree-header-string "")
4360
4361 (defcustom gnus-sum-thread-tree-root "> "
4362   "With %B spec, used for the root of a thread.
4363 If nil, use subject instead."
4364   :type 'string
4365   :group 'gnus-thread)
4366 (defcustom gnus-sum-thread-tree-single-indent ""
4367   "With %B spec, used for a thread with just one message.
4368 If nil, use subject instead."
4369   :type 'string
4370   :group 'gnus-thread)
4371 (defcustom gnus-sum-thread-tree-vertical "| "
4372   "With %B spec, used for drawing a vertical line."
4373   :type 'string
4374   :group 'gnus-thread)
4375 (defcustom gnus-sum-thread-tree-indent "  "
4376   "With %B spec, used for indenting."
4377   :type 'string
4378   :group 'gnus-thread)
4379 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4380   "With %B spec, used for a leaf with brothers."
4381   :type 'string
4382   :group 'gnus-thread)
4383 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4384   "With %B spec, used for a leaf without brothers."
4385   :type 'string
4386   :group 'gnus-thread)
4387
4388 (defun gnus-summary-prepare-threads (threads)
4389   "Prepare summary buffer from THREADS and indentation LEVEL.
4390 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4391 or a straight list of headers."
4392   (gnus-message 7 "Generating summary...")
4393
4394   (setq gnus-newsgroup-threads threads)
4395   (beginning-of-line)
4396
4397   (let ((gnus-tmp-level 0)
4398         (default-score (or gnus-summary-default-score 0))
4399         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4400         thread number subject stack state gnus-tmp-gathered beg-match
4401         new-roots gnus-tmp-new-adopts thread-end
4402         gnus-tmp-header gnus-tmp-unread
4403         gnus-tmp-replied gnus-tmp-subject-or-nil
4404         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4405         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4406         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4407         tree-stack)
4408
4409     (setq gnus-tmp-prev-subject nil)
4410
4411     (if (vectorp (car threads))
4412         ;; If this is a straight (sic) list of headers, then a
4413         ;; threaded summary display isn't required, so we just create
4414         ;; an unthreaded one.
4415         (gnus-summary-prepare-unthreaded threads)
4416
4417       ;; Do the threaded display.
4418
4419       (while (or threads stack gnus-tmp-new-adopts new-roots)
4420
4421         (if (and (= gnus-tmp-level 0)
4422                  (or (not stack)
4423                      (= (caar stack) 0))
4424                  (not gnus-tmp-false-parent)
4425                  (or gnus-tmp-new-adopts new-roots))
4426             (if gnus-tmp-new-adopts
4427                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4428                       thread (list (car gnus-tmp-new-adopts))
4429                       gnus-tmp-header (caar thread)
4430                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4431               (when new-roots
4432                 (setq thread (list (car new-roots))
4433                       gnus-tmp-header (caar thread)
4434                       new-roots (cdr new-roots))))
4435
4436           (if threads
4437               ;; If there are some threads, we do them before the
4438               ;; threads on the stack.
4439               (setq thread threads
4440                     gnus-tmp-header (caar thread))
4441             ;; There were no current threads, so we pop something off
4442             ;; the stack.
4443             (setq state (car stack)
4444                   gnus-tmp-level (car state)
4445                   tree-stack (cadr state)
4446                   thread (caddr state)
4447                   stack (cdr stack)
4448                   gnus-tmp-header (caar thread))))
4449
4450         (setq gnus-tmp-false-parent nil)
4451         (setq gnus-tmp-root-expunged nil)
4452         (setq thread-end nil)
4453
4454         (if (stringp gnus-tmp-header)
4455             ;; The header is a dummy root.
4456             (cond
4457              ((eq gnus-summary-make-false-root 'adopt)
4458               ;; We let the first article adopt the rest.
4459               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4460                                                (cddar thread)))
4461               (setq gnus-tmp-gathered
4462                     (nconc (mapcar
4463                             (lambda (h) (mail-header-number (car h)))
4464                             (cddar thread))
4465                            gnus-tmp-gathered))
4466               (setq thread (cons (list (caar thread)
4467                                        (cadar thread))
4468                                  (cdr thread)))
4469               (setq gnus-tmp-level -1
4470                     gnus-tmp-false-parent t))
4471              ((eq gnus-summary-make-false-root 'empty)
4472               ;; We print adopted articles with empty subject fields.
4473               (setq gnus-tmp-gathered
4474                     (nconc (mapcar
4475                             (lambda (h) (mail-header-number (car h)))
4476                             (cddar thread))
4477                            gnus-tmp-gathered))
4478               (setq gnus-tmp-level -1))
4479              ((eq gnus-summary-make-false-root 'dummy)
4480               ;; We remember that we probably want to output a dummy
4481               ;; root.
4482               (setq gnus-tmp-dummy-line gnus-tmp-header)
4483               (setq gnus-tmp-prev-subject gnus-tmp-header))
4484              (t
4485               ;; We do not make a root for the gathered
4486               ;; sub-threads at all.
4487               (setq gnus-tmp-level -1)))
4488
4489           (setq number (mail-header-number gnus-tmp-header)
4490                 subject (mail-header-subject gnus-tmp-header))
4491
4492           (cond
4493            ;; If the thread has changed subject, we might want to make
4494            ;; this subthread into a root.
4495            ((and (null gnus-thread-ignore-subject)
4496                  (not (zerop gnus-tmp-level))
4497                  gnus-tmp-prev-subject
4498                  (not (inline
4499                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4500             (setq new-roots (nconc new-roots (list (car thread)))
4501                   thread-end t
4502                   gnus-tmp-header nil))
4503            ;; If the article lies outside the current limit,
4504            ;; then we do not display it.
4505            ((not (memq number gnus-newsgroup-limit))
4506             (setq gnus-tmp-gathered
4507                   (nconc (mapcar
4508                           (lambda (h) (mail-header-number (car h)))
4509                           (cdar thread))
4510                          gnus-tmp-gathered))
4511             (setq gnus-tmp-new-adopts (if (cdar thread)
4512                                           (append gnus-tmp-new-adopts
4513                                                   (cdar thread))
4514                                         gnus-tmp-new-adopts)
4515                   thread-end t
4516                   gnus-tmp-header nil)
4517             (when (zerop gnus-tmp-level)
4518               (setq gnus-tmp-root-expunged t)))
4519            ;; Perhaps this article is to be marked as read?
4520            ((and gnus-summary-mark-below
4521                  (< (or (cdr (assq number gnus-newsgroup-scored))
4522                         default-score)
4523                     gnus-summary-mark-below)
4524                  ;; Don't touch sparse articles.
4525                  (not (gnus-summary-article-sparse-p number))
4526                  (not (gnus-summary-article-ancient-p number)))
4527             (setq gnus-newsgroup-unreads
4528                   (delq number gnus-newsgroup-unreads))
4529             (if gnus-newsgroup-auto-expire
4530                 (setq gnus-newsgroup-expirable
4531                       (gnus-add-to-sorted-list
4532                        gnus-newsgroup-expirable number))
4533               (push (cons number gnus-low-score-mark)
4534                     gnus-newsgroup-reads))))
4535
4536           (when gnus-tmp-header
4537             ;; We may have an old dummy line to output before this
4538             ;; article.
4539             (when (and gnus-tmp-dummy-line
4540                        (gnus-subject-equal
4541                         gnus-tmp-dummy-line
4542                         (mail-header-subject gnus-tmp-header)))
4543               (gnus-summary-insert-dummy-line
4544                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4545               (setq gnus-tmp-dummy-line nil))
4546
4547             ;; Compute the mark.
4548             (setq gnus-tmp-unread (gnus-article-mark number))
4549
4550             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4551                                   gnus-tmp-header gnus-tmp-level)
4552                   gnus-newsgroup-data)
4553
4554             ;; Actually insert the line.
4555             (setq
4556              gnus-tmp-subject-or-nil
4557              (cond
4558               ((and gnus-thread-ignore-subject
4559                     gnus-tmp-prev-subject
4560                     (not (inline (gnus-subject-equal
4561                                   gnus-tmp-prev-subject subject))))
4562                subject)
4563               ((zerop gnus-tmp-level)
4564                (if (and (eq gnus-summary-make-false-root 'empty)
4565                         (memq number gnus-tmp-gathered)
4566                         gnus-tmp-prev-subject
4567                         (inline (gnus-subject-equal
4568                                  gnus-tmp-prev-subject subject)))
4569                    gnus-summary-same-subject
4570                  subject))
4571               (t gnus-summary-same-subject)))
4572             (if (and (eq gnus-summary-make-false-root 'adopt)
4573                      (= gnus-tmp-level 1)
4574                      (memq number gnus-tmp-gathered))
4575                 (setq gnus-tmp-opening-bracket ?\<
4576                       gnus-tmp-closing-bracket ?\>)
4577               (setq gnus-tmp-opening-bracket ?\[
4578                     gnus-tmp-closing-bracket ?\]))
4579             (setq
4580              gnus-tmp-indentation
4581              (aref gnus-thread-indent-array gnus-tmp-level)
4582              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4583              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4584                                 gnus-summary-default-score 0)
4585              gnus-tmp-score-char
4586              (if (or (null gnus-summary-default-score)
4587                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4588                          gnus-summary-zcore-fuzz))
4589                  ?\ ;;;Whitespace
4590                (if (< gnus-tmp-score gnus-summary-default-score)
4591                    gnus-score-below-mark gnus-score-over-mark))
4592              gnus-tmp-replied
4593              (cond ((memq number gnus-newsgroup-processable)
4594                     gnus-process-mark)
4595                    ((memq number gnus-newsgroup-cached)
4596                     gnus-cached-mark)
4597                    ((memq number gnus-newsgroup-replied)
4598                     gnus-replied-mark)
4599                    ((memq number gnus-newsgroup-forwarded)
4600                     gnus-forwarded-mark)
4601                    ((memq number gnus-newsgroup-saved)
4602                     gnus-saved-mark)
4603                    ((memq number gnus-newsgroup-recent)
4604                     gnus-recent-mark)
4605                    ((memq number gnus-newsgroup-unseen)
4606                     gnus-unseen-mark)
4607                    (t gnus-no-mark))
4608              gnus-tmp-from (mail-header-from gnus-tmp-header)
4609              gnus-tmp-name
4610              (cond
4611               ((string-match "<[^>]+> *$" gnus-tmp-from)
4612                (setq beg-match (match-beginning 0))
4613                (or (and (string-match "^\".+\"" gnus-tmp-from)
4614                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4615                    (substring gnus-tmp-from 0 beg-match)))
4616               ((string-match "(.+)" gnus-tmp-from)
4617                (substring gnus-tmp-from
4618                           (1+ (match-beginning 0)) (1- (match-end 0))))
4619               (t gnus-tmp-from))
4620              gnus-tmp-thread-tree-header-string
4621              (cond
4622               ((not gnus-show-threads) "")
4623               ((zerop gnus-tmp-level)
4624                (if (cdar thread)
4625                    (or gnus-sum-thread-tree-root subject)
4626                  (or gnus-sum-thread-tree-single-indent subject)))
4627               (t
4628                (concat (apply 'concat
4629                               (mapcar (lambda (item)
4630                                         (if (= item 1)
4631                                             gnus-sum-thread-tree-vertical
4632                                           gnus-sum-thread-tree-indent))
4633                                       (cdr (reverse tree-stack))))
4634                        (if (nth 1 thread)
4635                            gnus-sum-thread-tree-leaf-with-other
4636                          gnus-sum-thread-tree-single-leaf)))))
4637             (when (string= gnus-tmp-name "")
4638               (setq gnus-tmp-name gnus-tmp-from))
4639             (unless (numberp gnus-tmp-lines)
4640               (setq gnus-tmp-lines -1))
4641             (if (= gnus-tmp-lines -1)
4642                 (setq gnus-tmp-lines "?")
4643               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4644             (gnus-put-text-property
4645              (point)
4646              (progn (eval gnus-summary-line-format-spec) (point))
4647              'gnus-number number)
4648             (when gnus-visual-p
4649               (forward-line -1)
4650               (gnus-run-hooks 'gnus-summary-update-hook)
4651               (forward-line 1))
4652
4653             (setq gnus-tmp-prev-subject subject)))
4654
4655         (when (nth 1 thread)
4656           (push (list (max 0 gnus-tmp-level)
4657                       (copy-list tree-stack)
4658                       (nthcdr 1 thread))
4659                 stack))
4660         (push (if (nth 1 thread) 1 0) tree-stack)
4661         (incf gnus-tmp-level)
4662         (setq threads (if thread-end nil (cdar thread)))
4663         (unless threads
4664           (setq gnus-tmp-level 0)))))
4665   (gnus-message 7 "Generating summary...done"))
4666
4667 (defun gnus-summary-prepare-unthreaded (headers)
4668   "Generate an unthreaded summary buffer based on HEADERS."
4669   (let (header number mark)
4670
4671     (beginning-of-line)
4672
4673     (while headers
4674       ;; We may have to root out some bad articles...
4675       (when (memq (setq number (mail-header-number
4676                                 (setq header (pop headers))))
4677                   gnus-newsgroup-limit)
4678         ;; Mark article as read when it has a low score.
4679         (when (and gnus-summary-mark-below
4680                    (< (or (cdr (assq number gnus-newsgroup-scored))
4681                           gnus-summary-default-score 0)
4682                       gnus-summary-mark-below)
4683                    (not (gnus-summary-article-ancient-p number)))
4684           (setq gnus-newsgroup-unreads
4685                 (delq number gnus-newsgroup-unreads))
4686           (if gnus-newsgroup-auto-expire
4687               (push number gnus-newsgroup-expirable)
4688             (push (cons number gnus-low-score-mark)
4689                   gnus-newsgroup-reads)))
4690
4691         (setq mark (gnus-article-mark number))
4692         (push (gnus-data-make number mark (1+ (point)) header 0)
4693               gnus-newsgroup-data)
4694         (gnus-summary-insert-line
4695          header 0 number
4696          mark (memq number gnus-newsgroup-replied)
4697          (memq number gnus-newsgroup-expirable)
4698          (mail-header-subject header) nil
4699          (cdr (assq number gnus-newsgroup-scored))
4700          (memq number gnus-newsgroup-processable))))))
4701
4702 (defun gnus-summary-remove-list-identifiers ()
4703   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4704   (let ((regexp (if (consp gnus-list-identifiers)
4705                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4706                   gnus-list-identifiers))
4707         changed subject)
4708     (when regexp
4709       (dolist (header gnus-newsgroup-headers)
4710         (setq subject (mail-header-subject header)
4711               changed nil)
4712         (while (string-match
4713                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4714                 subject)
4715           (setq subject
4716                 (concat (substring subject 0 (match-beginning 2))
4717                         (substring subject (match-end 0)))
4718                 changed t))
4719         (when (and changed
4720                    (string-match
4721                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4722           (setq subject
4723                 (concat (substring subject 0 (match-beginning 1))
4724                         (substring subject (match-end 1)))))
4725         (when changed
4726           (mail-header-set-subject header subject))))))
4727
4728 (defun gnus-fetch-headers (articles)
4729   "Fetch headers of ARTICLES."
4730   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4731     (gnus-message 5 "Fetching headers for %s..." name)
4732     (prog1
4733         (if (eq 'nov
4734                 (setq gnus-headers-retrieved-by
4735                       (gnus-retrieve-headers
4736                        articles gnus-newsgroup-name
4737                        ;; We might want to fetch old headers, but
4738                        ;; not if there is only 1 article.
4739                        (and (or (and
4740                                  (not (eq gnus-fetch-old-headers 'some))
4741                                  (not (numberp gnus-fetch-old-headers)))
4742                                 (> (length articles) 1))
4743                             gnus-fetch-old-headers))))
4744             (gnus-get-newsgroup-headers-xover
4745              articles nil nil gnus-newsgroup-name t)
4746           (gnus-get-newsgroup-headers))
4747       (gnus-message 5 "Fetching headers for %s...done" name))))
4748
4749 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4750   "Select newsgroup GROUP.
4751 If READ-ALL is non-nil, all articles in the group are selected.
4752 If SELECT-ARTICLES, only select those articles from GROUP."
4753   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4754          ;;!!! Dirty hack; should be removed.
4755          (gnus-summary-ignore-duplicates
4756           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4757               t
4758             gnus-summary-ignore-duplicates))
4759          (info (nth 2 entry))
4760          articles fetched-articles cached)
4761
4762     (unless (gnus-check-server
4763              (set (make-local-variable 'gnus-current-select-method)
4764                   (gnus-find-method-for-group group)))
4765       (error "Couldn't open server"))
4766
4767     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4768         (gnus-activate-group group)     ; Or we can activate it...
4769         (progn                          ; Or we bug out.
4770           (when (equal major-mode 'gnus-summary-mode)
4771             (kill-buffer (current-buffer)))
4772           (error "Couldn't activate group %s: %s"
4773                  group (gnus-status-message group))))
4774
4775     (unless (gnus-request-group group t)
4776       (when (equal major-mode 'gnus-summary-mode)
4777         (kill-buffer (current-buffer)))
4778       (error "Couldn't request group %s: %s"
4779              group (gnus-status-message group)))
4780
4781     (setq gnus-newsgroup-name group
4782           gnus-newsgroup-unselected nil
4783           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4784
4785     (let ((display (gnus-group-find-parameter group 'display)))
4786       (setq gnus-newsgroup-display
4787             (cond
4788              ((not (zerop (or (car-safe read-all) 0)))
4789               ;; The user entered the group with C-u SPC/RET, let's show
4790               ;; all articles.
4791               'gnus-not-ignore)
4792              ((eq display 'all)
4793               'gnus-not-ignore)
4794              ((arrayp display)
4795               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4796              ((numberp display)
4797               ;; The following is probably the "correct" solution, but
4798               ;; it makes Gnus fetch all headers and then limit the
4799               ;; articles (which is slow), so instead we hack the
4800               ;; select-articles parameter instead. -- Simon Josefsson
4801               ;; <jas@kth.se>
4802               ;;
4803               ;; (gnus-byte-compile
4804               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4805               ;;                         display)))))
4806               (setq select-articles
4807                     (gnus-uncompress-range
4808                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4809                              (if (> tmp 0)
4810                                  tmp
4811                                1))
4812                            (cdr (gnus-active group)))))
4813               nil)
4814              (t
4815               nil))))
4816
4817     (gnus-summary-setup-default-charset)
4818
4819     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4820     (when (gnus-virtual-group-p group)
4821       (setq cached gnus-newsgroup-cached))
4822
4823     (setq gnus-newsgroup-unreads
4824           (gnus-sorted-ndifference
4825            (gnus-sorted-ndifference gnus-newsgroup-unreads
4826                                     gnus-newsgroup-marked)
4827            gnus-newsgroup-dormant))
4828
4829     (setq gnus-newsgroup-processable nil)
4830
4831     (gnus-update-read-articles group gnus-newsgroup-unreads)
4832
4833     ;; Adjust and set lists of article marks.
4834     (when info
4835       (gnus-adjust-marked-articles info))
4836
4837     (if (setq articles select-articles)
4838         (setq gnus-newsgroup-unselected
4839               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4840       (setq articles (gnus-articles-to-read group read-all)))
4841
4842     (cond
4843      ((null articles)
4844       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4845       'quit)
4846      ((eq articles 0) nil)
4847      (t
4848       ;; Init the dependencies hash table.
4849       (setq gnus-newsgroup-dependencies
4850             (gnus-make-hashtable (length articles)))
4851       (gnus-set-global-variables)
4852       ;; Retrieve the headers and read them in.
4853       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4854
4855       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4856       (when cached
4857         (setq gnus-newsgroup-cached cached))
4858
4859       ;; Suppress duplicates?
4860       (when gnus-suppress-duplicates
4861         (gnus-dup-suppress-articles))
4862
4863       ;; Set the initial limit.
4864       (setq gnus-newsgroup-limit (copy-sequence articles))
4865       ;; Remove canceled articles from the list of unread articles.
4866       (setq fetched-articles
4867             (mapcar (lambda (headers) (mail-header-number headers))
4868                     gnus-newsgroup-headers))
4869       (setq gnus-newsgroup-articles fetched-articles)
4870       (setq gnus-newsgroup-unreads
4871             (gnus-sorted-nintersection
4872              gnus-newsgroup-unreads fetched-articles))
4873       (gnus-compute-unseen-list)
4874
4875       ;; Removed marked articles that do not exist.
4876       (gnus-update-missing-marks
4877        (gnus-sorted-difference articles fetched-articles))
4878       ;; We might want to build some more threads first.
4879       (when (and gnus-fetch-old-headers
4880                  (eq gnus-headers-retrieved-by 'nov))
4881         (if (eq gnus-fetch-old-headers 'invisible)
4882             (gnus-build-all-threads)
4883           (gnus-build-old-threads)))
4884       ;; Let the Gnus agent mark articles as read.
4885       (when gnus-agent
4886         (gnus-agent-get-undownloaded-list))
4887       ;; Remove list identifiers from subject
4888       (when gnus-list-identifiers
4889         (gnus-summary-remove-list-identifiers))
4890       ;; Check whether auto-expire is to be done in this group.
4891       (setq gnus-newsgroup-auto-expire
4892             (gnus-group-auto-expirable-p group))
4893       ;; Set up the article buffer now, if necessary.
4894       (unless gnus-single-article-buffer
4895         (gnus-article-setup-buffer))
4896       ;; First and last article in this newsgroup.
4897       (when gnus-newsgroup-headers
4898         (setq gnus-newsgroup-begin
4899               (mail-header-number (car gnus-newsgroup-headers))
4900               gnus-newsgroup-end
4901               (mail-header-number
4902                (gnus-last-element gnus-newsgroup-headers))))
4903       ;; GROUP is successfully selected.
4904       (or gnus-newsgroup-headers t)))))
4905
4906 (defun gnus-compute-unseen-list ()
4907   ;; The `seen' marks are treated specially.
4908   (if (not gnus-newsgroup-seen)
4909       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4910     (setq gnus-newsgroup-unseen
4911           (gnus-inverse-list-range-intersection
4912            gnus-newsgroup-articles gnus-newsgroup-seen))))
4913
4914 (defun gnus-summary-display-make-predicate (display)
4915   (require 'gnus-agent)
4916   (when (= (length display) 1)
4917     (setq display (car display)))
4918   (unless gnus-summary-display-cache
4919     (dolist (elem (append '((unread . unread)
4920                             (read . read)
4921                             (unseen . unseen))
4922                           gnus-article-mark-lists))
4923       (push (cons (cdr elem)
4924                   (gnus-byte-compile
4925                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4926             gnus-summary-display-cache)))
4927   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4928         (gnus-category-predicate-cache gnus-summary-display-cache))
4929     (gnus-get-predicate display)))
4930
4931 ;; Uses the dynamically bound `number' variable.
4932 (defvar number)
4933 (defun gnus-article-marked-p (type &optional article)
4934   (let ((article (or article number)))
4935     (cond
4936      ((eq type 'tick)
4937       (memq article gnus-newsgroup-marked))
4938      ((eq type 'unsend)
4939       (memq article gnus-newsgroup-unsendable))
4940      ((eq type 'undownload)
4941       (memq article gnus-newsgroup-undownloaded))
4942      ((eq type 'download)
4943       (memq article gnus-newsgroup-downloadable))
4944      ((eq type 'unread)
4945       (memq article gnus-newsgroup-unreads))
4946      ((eq type 'read)
4947       (memq article gnus-newsgroup-reads))
4948      ((eq type 'dormant)
4949       (memq article gnus-newsgroup-dormant) )
4950      ((eq type 'expire)
4951       (memq article gnus-newsgroup-expirable))
4952      ((eq type 'reply)
4953       (memq article gnus-newsgroup-replied))
4954      ((eq type 'killed)
4955       (memq article gnus-newsgroup-killed))
4956      ((eq type 'bookmark)
4957       (assq article gnus-newsgroup-bookmarks))
4958      ((eq type 'score)
4959       (assq article gnus-newsgroup-scored))
4960      ((eq type 'save)
4961       (memq article gnus-newsgroup-saved))
4962      ((eq type 'cache)
4963       (memq article gnus-newsgroup-cached))
4964      ((eq type 'forward)
4965       (memq article gnus-newsgroup-forwarded))
4966      ((eq type 'seen)
4967       (not (memq article gnus-newsgroup-unseen)))
4968      ((eq type 'recent)
4969       (memq article gnus-newsgroup-recent))
4970      (t t))))
4971
4972 (defun gnus-articles-to-read (group &optional read-all)
4973   "Find out what articles the user wants to read."
4974   (let* ((articles
4975           ;; Select all articles if `read-all' is non-nil, or if there
4976           ;; are no unread articles.
4977           (if (or read-all
4978                   (and (zerop (length gnus-newsgroup-marked))
4979                        (zerop (length gnus-newsgroup-unreads)))
4980                   ;; Fetch all if the predicate is non-nil.
4981                   gnus-newsgroup-display)
4982               ;; We want to select the headers for all the articles in
4983               ;; the group, so we select either all the active
4984               ;; articles in the group, or (if that's nil), the
4985               ;; articles in the cache.
4986               (or
4987                (gnus-uncompress-range (gnus-active group))
4988                (gnus-cache-articles-in-group group))
4989             ;; Select only the "normal" subset of articles.
4990             (gnus-sorted-nunion
4991              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4992              gnus-newsgroup-unreads)))
4993          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4994          (scored (length scored-list))
4995          (number (length articles))
4996          (marked (+ (length gnus-newsgroup-marked)
4997                     (length gnus-newsgroup-dormant)))
4998          (select
4999           (cond
5000            ((numberp read-all)
5001             read-all)
5002            ((numberp gnus-newsgroup-display)
5003             gnus-newsgroup-display)
5004            (t
5005             (condition-case ()
5006                 (cond
5007                  ((and (or (<= scored marked) (= scored number))
5008                        (numberp gnus-large-newsgroup)
5009                        (> number gnus-large-newsgroup))
5010                   (let* ((cursor-in-echo-area nil)
5011                          (initial (gnus-parameter-large-newsgroup-initial
5012                                    gnus-newsgroup-name))
5013                          (input
5014                           (read-string
5015                            (format
5016                             "How many articles from %s (%s %d): "
5017                             (gnus-limit-string
5018                              (gnus-group-decoded-name gnus-newsgroup-name)
5019                              35)
5020                             (if initial "max" "default")
5021                             number)
5022                            (if initial
5023                                (cons (number-to-string initial)
5024                                      0)))))
5025                     (if (string-match "^[ \t]*$" input) number input)))
5026                  ((and (> scored marked) (< scored number)
5027                        (> (- scored number) 20))
5028                   (let ((input
5029                          (read-string
5030                           (format "%s %s (%d scored, %d total): "
5031                                   "How many articles from"
5032                                   (gnus-group-decoded-name group)
5033                                   scored number))))
5034                     (if (string-match "^[ \t]*$" input)
5035                         number input)))
5036                  (t number))
5037               (quit
5038                (message "Quit getting the articles to read")
5039                nil))))))
5040     (setq select (if (stringp select) (string-to-number select) select))
5041     (if (or (null select) (zerop select))
5042         select
5043       (if (and (not (zerop scored)) (<= (abs select) scored))
5044           (progn
5045             (setq articles (sort scored-list '<))
5046             (setq number (length articles)))
5047         (setq articles (copy-sequence articles)))
5048
5049       (when (< (abs select) number)
5050         (if (< select 0)
5051             ;; Select the N oldest articles.
5052             (setcdr (nthcdr (1- (abs select)) articles) nil)
5053           ;; Select the N most recent articles.
5054           (setq articles (nthcdr (- number select) articles))))
5055       (setq gnus-newsgroup-unselected
5056             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5057       (when gnus-alter-articles-to-read-function
5058         (setq gnus-newsgroup-unreads
5059               (sort
5060                (funcall gnus-alter-articles-to-read-function
5061                         gnus-newsgroup-name gnus-newsgroup-unreads)
5062                '<)))
5063       articles)))
5064
5065 (defun gnus-killed-articles (killed articles)
5066   (let (out)
5067     (while articles
5068       (when (inline (gnus-member-of-range (car articles) killed))
5069         (push (car articles) out))
5070       (setq articles (cdr articles)))
5071     out))
5072
5073 (defun gnus-uncompress-marks (marks)
5074   "Uncompress the mark ranges in MARKS."
5075   (let ((uncompressed '(score bookmark))
5076         out)
5077     (while marks
5078       (if (memq (caar marks) uncompressed)
5079           (push (car marks) out)
5080         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5081       (setq marks (cdr marks)))
5082     out))
5083
5084 (defun gnus-article-mark-to-type (mark)
5085   "Return the type of MARK."
5086   (or (cadr (assq mark gnus-article-special-mark-lists))
5087       'list))
5088
5089 (defun gnus-article-unpropagatable-p (mark)
5090   "Return whether MARK should be propagated to backend."
5091   (memq mark gnus-article-unpropagated-mark-lists))
5092
5093 (defun gnus-adjust-marked-articles (info)
5094   "Set all article lists and remove all marks that are no longer valid."
5095   (let* ((marked-lists (gnus-info-marks info))
5096          (active (gnus-active (gnus-info-group info)))
5097          (min (car active))
5098          (max (cdr active))
5099          (types gnus-article-mark-lists)
5100          marks var articles article mark mark-type)
5101
5102     (dolist (marks marked-lists)
5103       (setq mark (car marks)
5104             mark-type (gnus-article-mark-to-type mark)
5105             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5106
5107       ;; We set the variable according to the type of the marks list,
5108       ;; and then adjust the marks to a subset of the active articles.
5109       (cond
5110        ;; Adjust "simple" lists.
5111        ((eq mark-type 'list)
5112         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5113         (when (memq mark '(tick dormant expire reply save))
5114           (while articles
5115             (when (or (< (setq article (pop articles)) min) (> article max))
5116               (set var (delq article (symbol-value var)))))))
5117        ;; Adjust assocs.
5118        ((eq mark-type 'tuple)
5119         (set var (setq articles (cdr marks)))
5120         (when (not (listp (cdr (symbol-value var))))
5121           (set var (list (symbol-value var))))
5122         (when (not (listp (cdr articles)))
5123           (setq articles (list articles)))
5124         (while articles
5125           (when (or (not (consp (setq article (pop articles))))
5126                     (< (car article) min)
5127                     (> (car article) max))
5128             (set var (delq article (symbol-value var))))))
5129        ;; Adjust ranges (sloppily).
5130        ((eq mark-type 'range)
5131         (cond
5132          ((eq mark 'seen)
5133           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5134           ;; It should be (seen (NUM1 . NUM2)).
5135           (when (numberp (cddr marks))
5136             (setcdr marks (list (cdr marks))))
5137           (setq articles (cdr marks))
5138           (while (and articles
5139                       (or (and (consp (car articles))
5140                                (> min (cdar articles)))
5141                           (and (numberp (car articles))
5142                                (> min (car articles)))))
5143             (pop articles))
5144           (set var articles))))))))
5145
5146 (defun gnus-update-missing-marks (missing)
5147   "Go through the list of MISSING articles and remove them from the mark lists."
5148   (when missing
5149     (let (var m)
5150       ;; Go through all types.
5151       (dolist (elem gnus-article-mark-lists)
5152         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5153           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5154           (when (symbol-value var)
5155             ;; This list has articles.  So we delete all missing
5156             ;; articles from it.
5157             (setq m missing)
5158             (while m
5159               (set var (delq (pop m) (symbol-value var))))))))))
5160
5161 (defun gnus-update-marks ()
5162   "Enter the various lists of marked articles into the newsgroup info list."
5163   (let ((types gnus-article-mark-lists)
5164         (info (gnus-get-info gnus-newsgroup-name))
5165         type list newmarked symbol delta-marks)
5166     (when info
5167       ;; Add all marks lists to the list of marks lists.
5168       (while (setq type (pop types))
5169         (setq list (symbol-value
5170                     (setq symbol
5171                           (intern (format "gnus-newsgroup-%s" (car type))))))
5172
5173         (when list
5174           ;; Get rid of the entries of the articles that have the
5175           ;; default score.
5176           (when (and (eq (cdr type) 'score)
5177                      gnus-save-score
5178                      list)
5179             (let* ((arts list)
5180                    (prev (cons nil list))
5181                    (all prev))
5182               (while arts
5183                 (if (or (not (consp (car arts)))
5184                         (= (cdar arts) gnus-summary-default-score))
5185                     (setcdr prev (cdr arts))
5186                   (setq prev arts))
5187                 (setq arts (cdr arts)))
5188               (setq list (cdr all)))))
5189
5190         (when (eq (cdr type) 'seen)
5191           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5192
5193         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5194           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5195
5196         (when (and (gnus-check-backend-function
5197                     'request-set-mark gnus-newsgroup-name)
5198                    (not (gnus-article-unpropagatable-p (cdr type))))
5199           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5200                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5201                  (add (gnus-remove-from-range
5202                        (gnus-copy-sequence list) old)))
5203             (when add
5204               (push (list add 'add (list (cdr type))) delta-marks))
5205             (when del
5206               (push (list del 'del (list (cdr type))) delta-marks))))
5207
5208         (when list
5209           (push (cons (cdr type) list) newmarked)))
5210
5211       (when delta-marks
5212         (unless (gnus-check-group gnus-newsgroup-name)
5213           (error "Can't open server for %s" gnus-newsgroup-name))
5214         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5215
5216       ;; Enter these new marks into the info of the group.
5217       (if (nthcdr 3 info)
5218           (setcar (nthcdr 3 info) newmarked)
5219         ;; Add the marks lists to the end of the info.
5220         (when newmarked
5221           (setcdr (nthcdr 2 info) (list newmarked))))
5222
5223       ;; Cut off the end of the info if there's nothing else there.
5224       (let ((i 5))
5225         (while (and (> i 2)
5226                     (not (nth i info)))
5227           (when (nthcdr (decf i) info)
5228             (setcdr (nthcdr i info) nil)))))))
5229
5230 (defun gnus-set-mode-line (where)
5231   "Set the mode line of the article or summary buffers.
5232 If WHERE is `summary', the summary mode line format will be used."
5233   ;; Is this mode line one we keep updated?
5234   (when (and (memq where gnus-updated-mode-lines)
5235              (symbol-value
5236               (intern (format "gnus-%s-mode-line-format-spec" where))))
5237     (let (mode-string)
5238       (save-excursion
5239         ;; We evaluate this in the summary buffer since these
5240         ;; variables are buffer-local to that buffer.
5241         (set-buffer gnus-summary-buffer)
5242         ;; We bind all these variables that are used in the `eval' form
5243         ;; below.
5244         (let* ((mformat (symbol-value
5245                          (intern
5246                           (format "gnus-%s-mode-line-format-spec" where))))
5247                (gnus-tmp-group-name (gnus-group-decoded-name
5248                                      gnus-newsgroup-name))
5249                (gnus-tmp-article-number (or gnus-current-article 0))
5250                (gnus-tmp-unread gnus-newsgroup-unreads)
5251                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5252                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5253                (gnus-tmp-unread-and-unselected
5254                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5255                             (zerop gnus-tmp-unselected))
5256                        "")
5257                       ((zerop gnus-tmp-unselected)
5258                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5259                       (t (format "{%d(+%d) more}"
5260                                  gnus-tmp-unread-and-unticked
5261                                  gnus-tmp-unselected))))
5262                (gnus-tmp-subject
5263                 (if (and gnus-current-headers
5264                          (vectorp gnus-current-headers))
5265                     (gnus-mode-string-quote
5266                      (mail-header-subject gnus-current-headers))
5267                   ""))
5268                bufname-length max-len
5269                gnus-tmp-header);; passed as argument to any user-format-funcs
5270           (setq mode-string (eval mformat))
5271           (setq bufname-length (if (string-match "%b" mode-string)
5272                                    (- (length
5273                                        (buffer-name
5274                                         (if (eq where 'summary)
5275                                             nil
5276                                           (get-buffer gnus-article-buffer))))
5277                                       2)
5278                                  0))
5279           (setq max-len (max 4 (if gnus-mode-non-string-length
5280                                    (- (window-width)
5281                                       gnus-mode-non-string-length
5282                                       bufname-length)
5283                                  (length mode-string))))
5284           ;; We might have to chop a bit of the string off...
5285           (when (> (length mode-string) max-len)
5286             (setq mode-string
5287                   (concat (gnus-truncate-string mode-string (- max-len 3))
5288                           "...")))
5289           ;; Pad the mode string a bit.
5290           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5291       ;; Update the mode line.
5292       (setq mode-line-buffer-identification
5293             (gnus-mode-line-buffer-identification (list mode-string)))
5294       (set-buffer-modified-p t))))
5295
5296 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5297   "Go through the HEADERS list and add all Xrefs to a hash table.
5298 The resulting hash table is returned, or nil if no Xrefs were found."
5299   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5300          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5301          (xref-hashtb (gnus-make-hashtable))
5302          start group entry number xrefs header)
5303     (while headers
5304       (setq header (pop headers))
5305       (when (and (setq xrefs (mail-header-xref header))
5306                  (not (memq (setq number (mail-header-number header))
5307                             unreads)))
5308         (setq start 0)
5309         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5310           (setq start (match-end 0))
5311           (setq group (if prefix
5312                           (concat prefix (substring xrefs (match-beginning 1)
5313                                                     (match-end 1)))
5314                         (substring xrefs (match-beginning 1) (match-end 1))))
5315           (setq number
5316                 (string-to-int (substring xrefs (match-beginning 2)
5317                                           (match-end 2))))
5318           (if (setq entry (gnus-gethash group xref-hashtb))
5319               (setcdr entry (cons number (cdr entry)))
5320             (gnus-sethash group (cons number nil) xref-hashtb)))))
5321     (and start xref-hashtb)))
5322
5323 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5324   "Look through all the headers and mark the Xrefs as read."
5325   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5326         name entry info xref-hashtb idlist method nth4)
5327     (save-excursion
5328       (set-buffer gnus-group-buffer)
5329       (when (setq xref-hashtb
5330                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5331         (mapatoms
5332          (lambda (group)
5333            (unless (string= from-newsgroup (setq name (symbol-name group)))
5334              (setq idlist (symbol-value group))
5335              ;; Dead groups are not updated.
5336              (and (prog1
5337                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5338                             info (nth 2 entry))
5339                     (when (stringp (setq nth4 (gnus-info-method info)))
5340                       (setq nth4 (gnus-server-to-method nth4))))
5341                   ;; Only do the xrefs if the group has the same
5342                   ;; select method as the group we have just read.
5343                   (or (gnus-methods-equal-p
5344                        nth4 (gnus-find-method-for-group from-newsgroup))
5345                       virtual
5346                       (equal nth4 (setq method (gnus-find-method-for-group
5347                                                 from-newsgroup)))
5348                       (and (equal (car nth4) (car method))
5349                            (equal (nth 1 nth4) (nth 1 method))))
5350                   gnus-use-cross-reference
5351                   (or (not (eq gnus-use-cross-reference t))
5352                       virtual
5353                       ;; Only do cross-references on subscribed
5354                       ;; groups, if that is what is wanted.
5355                       (<= (gnus-info-level info) gnus-level-subscribed))
5356                   (gnus-group-make-articles-read name idlist))))
5357          xref-hashtb)))))
5358
5359 (defun gnus-compute-read-articles (group articles)
5360   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5361          (info (nth 2 entry))
5362          (active (gnus-active group))
5363          ninfo)
5364     (when entry
5365       ;; First peel off all invalid article numbers.
5366       (when active
5367         (let ((ids articles)
5368               id first)
5369           (while (setq id (pop ids))
5370             (when (and first (> id (cdr active)))
5371               ;; We'll end up in this situation in one particular
5372               ;; obscure situation.  If you re-scan a group and get
5373               ;; a new article that is cross-posted to a different
5374               ;; group that has not been re-scanned, you might get
5375               ;; crossposted article that has a higher number than
5376               ;; Gnus believes possible.  So we re-activate this
5377               ;; group as well.  This might mean doing the
5378               ;; crossposting thingy will *increase* the number
5379               ;; of articles in some groups.  Tsk, tsk.
5380               (setq active (or (gnus-activate-group group) active)))
5381             (when (or (> id (cdr active))
5382                       (< id (car active)))
5383               (setq articles (delq id articles))))))
5384       ;; If the read list is nil, we init it.
5385       (if (and active
5386                (null (gnus-info-read info))
5387                (> (car active) 1))
5388           (setq ninfo (cons 1 (1- (car active))))
5389         (setq ninfo (gnus-info-read info)))
5390       ;; Then we add the read articles to the range.
5391       (gnus-add-to-range
5392        ninfo (setq articles (sort articles '<))))))
5393
5394 (defun gnus-group-make-articles-read (group articles)
5395   "Update the info of GROUP to say that ARTICLES are read."
5396   (let* ((num 0)
5397          (entry (gnus-gethash group gnus-newsrc-hashtb))
5398          (info (nth 2 entry))
5399          (active (gnus-active group))
5400          range)
5401     (when entry
5402       (setq range (gnus-compute-read-articles group articles))
5403       (save-excursion
5404         (set-buffer gnus-group-buffer)
5405         (gnus-undo-register
5406           `(progn
5407              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5408              (gnus-info-set-read ',info ',(gnus-info-read info))
5409              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5410              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5411              (gnus-group-update-group ,group t))))
5412       ;; Add the read articles to the range.
5413       (gnus-info-set-read info range)
5414       (gnus-request-set-mark group (list (list range 'add '(read))))
5415       ;; Then we have to re-compute how many unread
5416       ;; articles there are in this group.
5417       (when active
5418         (cond
5419          ((not range)
5420           (setq num (- (1+ (cdr active)) (car active))))
5421          ((not (listp (cdr range)))
5422           (setq num (- (cdr active) (- (1+ (cdr range))
5423                                        (car range)))))
5424          (t
5425           (while range
5426             (if (numberp (car range))
5427                 (setq num (1+ num))
5428               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5429             (setq range (cdr range)))
5430           (setq num (- (cdr active) num))))
5431         ;; Update the number of unread articles.
5432         (setcar entry num)
5433         ;; Update the group buffer.
5434         (gnus-group-update-group group t)))))
5435
5436 (defvar gnus-newsgroup-none-id 0)
5437
5438 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5439   (let ((cur nntp-server-buffer)
5440         (dependencies
5441          (or dependencies
5442              (save-excursion (set-buffer gnus-summary-buffer)
5443                              gnus-newsgroup-dependencies)))
5444         headers id end ref
5445         (mail-parse-charset gnus-newsgroup-charset)
5446         (mail-parse-ignored-charsets
5447          (save-excursion (condition-case nil
5448                              (set-buffer gnus-summary-buffer)
5449                            (error))
5450                          gnus-newsgroup-ignored-charsets)))
5451     (save-excursion
5452       (set-buffer nntp-server-buffer)
5453       ;; Translate all TAB characters into SPACE characters.
5454       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5455       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5456       (gnus-run-hooks 'gnus-parse-headers-hook)
5457       (let ((case-fold-search t)
5458             in-reply-to header p lines chars ctype)
5459         (goto-char (point-min))
5460         ;; Search to the beginning of the next header.  Error messages
5461         ;; do not begin with 2 or 3.
5462         (while (re-search-forward "^[23][0-9]+ " nil t)
5463           (setq id nil
5464                 ref nil)
5465           ;; This implementation of this function, with nine
5466           ;; search-forwards instead of the one re-search-forward and
5467           ;; a case (which basically was the old function) is actually
5468           ;; about twice as fast, even though it looks messier.  You
5469           ;; can't have everything, I guess.  Speed and elegance
5470           ;; doesn't always go hand in hand.
5471           (setq
5472            header
5473            (make-full-mail-header
5474             ;; Number.
5475             (prog1
5476                 (read cur)
5477               (end-of-line)
5478               (setq p (point))
5479               (narrow-to-region (point)
5480                                 (or (and (search-forward "\n.\n" nil t)
5481                                          (- (point) 2))
5482                                     (point))))
5483             ;; Subject.
5484             (progn
5485               (goto-char p)
5486               (if (search-forward "\nsubject:" nil t)
5487                   (nnheader-header-value)
5488                 "(none)"))
5489             ;; From.
5490             (progn
5491               (goto-char p)
5492               (if (search-forward "\nfrom:" nil t)
5493                   (nnheader-header-value)
5494                 "(nobody)"))
5495             ;; Date.
5496             (progn
5497               (goto-char p)
5498               (if (search-forward "\ndate:" nil t)
5499                   (nnheader-header-value) ""))
5500             ;; Message-ID.
5501             (progn
5502               (goto-char p)
5503               (setq id (if (re-search-forward
5504                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5505                            ;; We do it this way to make sure the Message-ID
5506                            ;; is (somewhat) syntactically valid.
5507                            (buffer-substring (match-beginning 1)
5508                                              (match-end 1))
5509                          ;; If there was no message-id, we just fake one
5510                          ;; to make subsequent routines simpler.
5511                          (nnheader-generate-fake-message-id))))
5512             ;; References.
5513             (progn
5514               (goto-char p)
5515               (if (search-forward "\nreferences:" nil t)
5516                   (progn
5517                     (setq end (point))
5518                     (prog1
5519                         (nnheader-header-value)
5520                       (setq ref
5521                             (buffer-substring
5522                              (progn
5523                                ;; (end-of-line)
5524                                (search-backward ">" end t)
5525                                (1+ (point)))
5526                              (progn
5527                                (search-backward "<" end t)
5528                                (point))))))
5529                 ;; Get the references from the in-reply-to header if there
5530                 ;; were no references and the in-reply-to header looks
5531                 ;; promising.
5532                 (if (and (search-forward "\nin-reply-to:" nil t)
5533                          (setq in-reply-to (nnheader-header-value))
5534                          (string-match "<[^>]+>" in-reply-to))
5535                     (let (ref2)
5536                       (setq ref (substring in-reply-to (match-beginning 0)
5537                                            (match-end 0)))
5538                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5539                         (setq ref2 (substring in-reply-to (match-beginning 0)
5540                                               (match-end 0)))
5541                         (when (> (length ref2) (length ref))
5542                           (setq ref ref2)))
5543                       ref)
5544                   (setq ref nil))))
5545             ;; Chars.
5546             (progn
5547               (goto-char p)
5548               (if (search-forward "\nchars: " nil t)
5549                   (if (numberp (setq chars (ignore-errors (read cur))))
5550                       chars -1)
5551                 -1))
5552             ;; Lines.
5553             (progn
5554               (goto-char p)
5555               (if (search-forward "\nlines: " nil t)
5556                   (if (numberp (setq lines (ignore-errors (read cur))))
5557                       lines -1)
5558                 -1))
5559             ;; Xref.
5560             (progn
5561               (goto-char p)
5562               (and (search-forward "\nxref:" nil t)
5563                    (nnheader-header-value)))
5564             ;; Extra.
5565             (when gnus-extra-headers
5566               (let ((extra gnus-extra-headers)
5567                     out)
5568                 (while extra
5569                   (goto-char p)
5570                   (when (search-forward
5571                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5572                     (push (cons (car extra) (nnheader-header-value)) out))
5573                   (pop extra))
5574                 out))))
5575           (goto-char p)
5576           (if (and (search-forward "\ncontent-type: " nil t)
5577                    (setq ctype (nnheader-header-value)))
5578               (mime-entity-set-content-type-internal
5579                header (mime-parse-Content-Type ctype)))
5580           (when (equal id ref)
5581             (setq ref nil))
5582
5583           (when gnus-alter-header-function
5584             (funcall gnus-alter-header-function header)
5585             (setq id (mail-header-id header)
5586                   ref (gnus-parent-id (mail-header-references header))))
5587
5588           (when (setq header
5589                       (gnus-dependencies-add-header
5590                        header dependencies force-new))
5591             (push header headers))
5592           (goto-char (point-max))
5593           (widen))
5594         (nreverse headers)))))
5595
5596 ;; Goes through the xover lines and returns a list of vectors
5597 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5598                                                   force-new dependencies
5599                                                   group also-fetch-heads)
5600   "Parse the news overview data in the server buffer.
5601 Return a list of headers that match SEQUENCE (see
5602 `nntp-retrieve-headers')."
5603   ;; Get the Xref when the users reads the articles since most/some
5604   ;; NNTP servers do not include Xrefs when using XOVER.
5605   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5606   (let ((mail-parse-charset gnus-newsgroup-charset)
5607         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5608         (cur nntp-server-buffer)
5609         (dependencies (or dependencies gnus-newsgroup-dependencies))
5610         (allp (cond
5611                ((eq gnus-read-all-available-headers t)
5612                 t)
5613                ((stringp gnus-read-all-available-headers)
5614                 (string-match gnus-read-all-available-headers group))
5615                (t
5616                 nil)))
5617         number headers header)
5618     (save-excursion
5619       (set-buffer nntp-server-buffer)
5620       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5621       ;; Allow the user to mangle the headers before parsing them.
5622       (gnus-run-hooks 'gnus-parse-headers-hook)
5623       (goto-char (point-min))
5624       (gnus-parse-without-error
5625         (while (and (or sequence allp)
5626                     (not (eobp)))
5627           (setq number (read cur))
5628           (when (not allp)
5629             (while (and sequence
5630                         (< (car sequence) number))
5631               (setq sequence (cdr sequence))))
5632           (when (and (or allp
5633                          (and sequence
5634                               (eq number (car sequence))))
5635                      (progn
5636                        (setq sequence (cdr sequence))
5637                        (setq header (inline
5638                                       (gnus-nov-parse-line
5639                                        number dependencies force-new)))))
5640             (push header headers))
5641           (forward-line 1)))
5642       ;; A common bug in inn is that if you have posted an article and
5643       ;; then retrieves the active file, it will answer correctly --
5644       ;; the new article is included.  However, a NOV entry for the
5645       ;; article may not have been generated yet, so this may fail.
5646       ;; We work around this problem by retrieving the last few
5647       ;; headers using HEAD.
5648       (if (or (not also-fetch-heads)
5649               (not sequence))
5650           ;; We (probably) got all the headers.
5651           (nreverse headers)
5652         (let ((gnus-nov-is-evil t))
5653           (nconc
5654            (nreverse headers)
5655            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5656              (gnus-get-newsgroup-headers))))))))
5657
5658 (defun gnus-article-get-xrefs ()
5659   "Fill in the Xref value in `gnus-current-headers', if necessary.
5660 This is meant to be called in `gnus-article-internal-prepare-hook'."
5661   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5662                                  gnus-current-headers)))
5663     (or (not gnus-use-cross-reference)
5664         (not headers)
5665         (and (mail-header-xref headers)
5666              (not (string= (mail-header-xref headers) "")))
5667         (let ((case-fold-search t)
5668               xref)
5669           (save-restriction
5670             (nnheader-narrow-to-headers)
5671             (goto-char (point-min))
5672             (when (or (and (not (eobp))
5673                            (eq (downcase (char-after)) ?x)
5674                            (looking-at "Xref:"))
5675                       (search-forward "\nXref:" nil t))
5676               (goto-char (1+ (match-end 0)))
5677               (setq xref (buffer-substring (point)
5678                                            (progn (end-of-line) (point))))
5679               (mail-header-set-xref headers xref)))))))
5680
5681 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5682   "Find article ID and insert the summary line for that article.
5683 OLD-HEADER can either be a header or a line number to insert
5684 the subject line on."
5685   (let* ((line (and (numberp old-header) old-header))
5686          (old-header (and (vectorp old-header) old-header))
5687          (header (cond ((and old-header use-old-header)
5688                         old-header)
5689                        ((and (numberp id)
5690                              (gnus-number-to-header id))
5691                         (gnus-number-to-header id))
5692                        (t
5693                         (gnus-read-header id))))
5694          (number (and (numberp id) id))
5695          d)
5696     (when header
5697       ;; Rebuild the thread that this article is part of and go to the
5698       ;; article we have fetched.
5699       (when (and (not gnus-show-threads)
5700                  old-header)
5701         (when (and number
5702                    (setq d (gnus-data-find (mail-header-number old-header))))
5703           (goto-char (gnus-data-pos d))
5704           (gnus-data-remove
5705            number
5706            (- (gnus-point-at-bol)
5707               (prog1
5708                   (1+ (gnus-point-at-eol))
5709                 (gnus-delete-line))))))
5710       (when old-header
5711         (mail-header-set-number header (mail-header-number old-header)))
5712       (setq gnus-newsgroup-sparse
5713             (delq (setq number (mail-header-number header))
5714                   gnus-newsgroup-sparse))
5715       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5716       (push number gnus-newsgroup-limit)
5717       (gnus-rebuild-thread (mail-header-id header) line)
5718       (gnus-summary-goto-subject number nil t))
5719     (when (and (numberp number)
5720                (> number 0))
5721       ;; We have to update the boundaries even if we can't fetch the
5722       ;; article if ID is a number -- so that the next `P' or `N'
5723       ;; command will fetch the previous (or next) article even
5724       ;; if the one we tried to fetch this time has been canceled.
5725       (when (> number gnus-newsgroup-end)
5726         (setq gnus-newsgroup-end number))
5727       (when (< number gnus-newsgroup-begin)
5728         (setq gnus-newsgroup-begin number))
5729       (setq gnus-newsgroup-unselected
5730             (delq number gnus-newsgroup-unselected)))
5731     ;; Report back a success?
5732     (and header (mail-header-number header))))
5733
5734 ;;; Process/prefix in the summary buffer
5735
5736 (defun gnus-summary-work-articles (n)
5737   "Return a list of articles to be worked upon.
5738 The prefix argument, the list of process marked articles, and the
5739 current article will be taken into consideration."
5740   (save-excursion
5741     (set-buffer gnus-summary-buffer)
5742     (cond
5743      (n
5744       ;; A numerical prefix has been given.
5745       (setq n (prefix-numeric-value n))
5746       (let ((backward (< n 0))
5747             (n (abs (prefix-numeric-value n)))
5748             articles article)
5749         (save-excursion
5750           (while
5751               (and (> n 0)
5752                    (push (setq article (gnus-summary-article-number))
5753                          articles)
5754                    (if backward
5755                        (gnus-summary-find-prev nil article)
5756                      (gnus-summary-find-next nil article)))
5757             (decf n)))
5758         (nreverse articles)))
5759      ((and (gnus-region-active-p) (mark))
5760       (message "region active")
5761       ;; Work on the region between point and mark.
5762       (let ((max (max (point) (mark)))
5763             articles article)
5764         (save-excursion
5765           (goto-char (min (point) (mark)))
5766           (while
5767               (and
5768                (push (setq article (gnus-summary-article-number)) articles)
5769                (gnus-summary-find-next nil article)
5770                (< (point) max)))
5771           (nreverse articles))))
5772      (gnus-newsgroup-processable
5773       ;; There are process-marked articles present.
5774       ;; Save current state.
5775       (gnus-summary-save-process-mark)
5776       ;; Return the list.
5777       (reverse gnus-newsgroup-processable))
5778      (t
5779       ;; Just return the current article.
5780       (list (gnus-summary-article-number))))))
5781
5782 (defmacro gnus-summary-iterate (arg &rest forms)
5783   "Iterate over the process/prefixed articles and do FORMS.
5784 ARG is the interactive prefix given to the command.  FORMS will be
5785 executed with point over the summary line of the articles."
5786   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5787     `(let ((,articles (gnus-summary-work-articles ,arg)))
5788        (while ,articles
5789          (gnus-summary-goto-subject (car ,articles))
5790          ,@forms
5791          (pop ,articles)))))
5792
5793 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5794 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5795
5796 (defun gnus-summary-save-process-mark ()
5797   "Push the current set of process marked articles on the stack."
5798   (interactive)
5799   (push (copy-sequence gnus-newsgroup-processable)
5800         gnus-newsgroup-process-stack))
5801
5802 (defun gnus-summary-kill-process-mark ()
5803   "Push the current set of process marked articles on the stack and unmark."
5804   (interactive)
5805   (gnus-summary-save-process-mark)
5806   (gnus-summary-unmark-all-processable))
5807
5808 (defun gnus-summary-yank-process-mark ()
5809   "Pop the last process mark state off the stack and restore it."
5810   (interactive)
5811   (unless gnus-newsgroup-process-stack
5812     (error "Empty mark stack"))
5813   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5814
5815 (defun gnus-summary-process-mark-set (set)
5816   "Make SET into the current process marked articles."
5817   (gnus-summary-unmark-all-processable)
5818   (while set
5819     (gnus-summary-set-process-mark (pop set))))
5820
5821 ;;; Searching and stuff
5822
5823 (defun gnus-summary-search-group (&optional backward use-level)
5824   "Search for next unread newsgroup.
5825 If optional argument BACKWARD is non-nil, search backward instead."
5826   (save-excursion
5827     (set-buffer gnus-group-buffer)
5828     (when (gnus-group-search-forward
5829            backward nil (if use-level (gnus-group-group-level) nil))
5830       (gnus-group-group-name))))
5831
5832 (defun gnus-summary-best-group (&optional exclude-group)
5833   "Find the name of the best unread group.
5834 If EXCLUDE-GROUP, do not go to this group."
5835   (save-excursion
5836     (set-buffer gnus-group-buffer)
5837     (save-excursion
5838       (gnus-group-best-unread-group exclude-group))))
5839
5840 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5841   (if backward (gnus-summary-find-prev)
5842     (let* ((dummy (gnus-summary-article-intangible-p))
5843            (article (or article (gnus-summary-article-number)))
5844            (arts (gnus-data-find-list article))
5845            result)
5846       (when (and (not dummy)
5847                  (or (not gnus-summary-check-current)
5848                      (not unread)
5849                      (not (gnus-data-unread-p (car arts)))))
5850         (setq arts (cdr arts)))
5851       (when (setq result
5852                   (if unread
5853                       (progn
5854                         (while arts
5855                           (when (or (and undownloaded
5856                                          (eq gnus-undownloaded-mark
5857                                              (gnus-data-mark (car arts))))
5858                                     (gnus-data-unread-p (car arts)))
5859                             (setq result (car arts)
5860                                   arts nil))
5861                           (setq arts (cdr arts)))
5862                         result)
5863                     (car arts)))
5864         (goto-char (gnus-data-pos result))
5865         (gnus-data-number result)))))
5866
5867 (defun gnus-summary-find-prev (&optional unread article)
5868   (let* ((eobp (eobp))
5869          (article (or article (gnus-summary-article-number)))
5870          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5871          result)
5872     (when (and (not eobp)
5873                (or (not gnus-summary-check-current)
5874                    (not unread)
5875                    (not (gnus-data-unread-p (car arts)))))
5876       (setq arts (cdr arts)))
5877     (when (setq result
5878                 (if unread
5879                     (progn
5880                       (while arts
5881                         (when (gnus-data-unread-p (car arts))
5882                           (setq result (car arts)
5883                                 arts nil))
5884                         (setq arts (cdr arts)))
5885                       result)
5886                   (car arts)))
5887       (goto-char (gnus-data-pos result))
5888       (gnus-data-number result))))
5889
5890 (defun gnus-summary-find-subject (subject &optional unread backward article)
5891   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5892          (article (or article (gnus-summary-article-number)))
5893          (articles (gnus-data-list backward))
5894          (arts (gnus-data-find-list article articles))
5895          result)
5896     (when (or (not gnus-summary-check-current)
5897               (not unread)
5898               (not (gnus-data-unread-p (car arts))))
5899       (setq arts (cdr arts)))
5900     (while arts
5901       (and (or (not unread)
5902                (gnus-data-unread-p (car arts)))
5903            (vectorp (gnus-data-header (car arts)))
5904            (gnus-subject-equal
5905             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5906            (setq result (car arts)
5907                  arts nil))
5908       (setq arts (cdr arts)))
5909     (and result
5910          (goto-char (gnus-data-pos result))
5911          (gnus-data-number result))))
5912
5913 (defun gnus-summary-search-forward (&optional unread subject backward)
5914   "Search forward for an article.
5915 If UNREAD, look for unread articles.  If SUBJECT, look for
5916 articles with that subject.  If BACKWARD, search backward instead."
5917   (cond (subject (gnus-summary-find-subject subject unread backward))
5918         (backward (gnus-summary-find-prev unread))
5919         (t (gnus-summary-find-next unread))))
5920
5921 (defun gnus-recenter (&optional n)
5922   "Center point in window and redisplay frame.
5923 Also do horizontal recentering."
5924   (interactive "P")
5925   (when (and gnus-auto-center-summary
5926              (not (eq gnus-auto-center-summary 'vertical)))
5927     (gnus-horizontal-recenter))
5928   (recenter n))
5929
5930 (defun gnus-summary-recenter ()
5931   "Center point in the summary window.
5932 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5933 displayed, no centering will be performed."
5934   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5935   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5936   (interactive)
5937   (let* ((top (cond ((< (window-height) 4) 0)
5938                     ((< (window-height) 7) 1)
5939                     (t (if (numberp gnus-auto-center-summary)
5940                            gnus-auto-center-summary
5941                          2))))
5942          (height (1- (window-height)))
5943          (bottom (save-excursion (goto-char (point-max))
5944                                  (forward-line (- height))
5945                                  (point)))
5946          (window (get-buffer-window (current-buffer))))
5947     ;; The user has to want it.
5948     (when gnus-auto-center-summary
5949       (when (get-buffer-window gnus-article-buffer)
5950         ;; Only do recentering when the article buffer is displayed,
5951         ;; Set the window start to either `bottom', which is the biggest
5952         ;; possible valid number, or the second line from the top,
5953         ;; whichever is the least.
5954         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5955           (if (> bottom top-pos)
5956               ;; Keep the second line from the top visible
5957               (set-window-start window top-pos t)
5958             ;; Try to keep the bottom line visible; if it's partially
5959             ;; obscured, either scroll one more line to make it fully
5960             ;; visible, or revert to using TOP-POS.
5961             (save-excursion
5962               (goto-char (point-max))
5963               (forward-line -1)
5964               (let ((last-line-start (point)))
5965                 (goto-char bottom)
5966                 (set-window-start window (point) t)
5967                 (when (not (pos-visible-in-window-p last-line-start window))
5968                   (forward-line 1)
5969                   (set-window-start window (min (point) top-pos) t)))))))
5970       ;; Do horizontal recentering while we're at it.
5971       (when (and (get-buffer-window (current-buffer) t)
5972                  (not (eq gnus-auto-center-summary 'vertical)))
5973         (let ((selected (selected-window)))
5974           (select-window (get-buffer-window (current-buffer) t))
5975           (gnus-summary-position-point)
5976           (gnus-horizontal-recenter)
5977           (select-window selected))))))
5978
5979 (defun gnus-summary-jump-to-group (newsgroup)
5980   "Move point to NEWSGROUP in group mode buffer."
5981   ;; Keep update point of group mode buffer if visible.
5982   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5983       (save-window-excursion
5984         ;; Take care of tree window mode.
5985         (when (get-buffer-window gnus-group-buffer)
5986           (pop-to-buffer gnus-group-buffer))
5987         (gnus-group-jump-to-group newsgroup))
5988     (save-excursion
5989       ;; Take care of tree window mode.
5990       (if (get-buffer-window gnus-group-buffer)
5991           (pop-to-buffer gnus-group-buffer)
5992         (set-buffer gnus-group-buffer))
5993       (gnus-group-jump-to-group newsgroup))))
5994
5995 ;; This function returns a list of article numbers based on the
5996 ;; difference between the ranges of read articles in this group and
5997 ;; the range of active articles.
5998 (defun gnus-list-of-unread-articles (group)
5999   (let* ((read (gnus-info-read (gnus-get-info group)))
6000          (active (or (gnus-active group) (gnus-activate-group group)))
6001          (last (cdr active))
6002          first nlast unread)
6003     ;; If none are read, then all are unread.
6004     (if (not read)
6005         (setq first (car active))
6006       ;; If the range of read articles is a single range, then the
6007       ;; first unread article is the article after the last read
6008       ;; article.  Sounds logical, doesn't it?
6009       (if (and (not (listp (cdr read)))
6010                (or (< (car read) (car active))
6011                    (progn (setq read (list read))
6012                           nil)))
6013           (setq first (max (car active) (1+ (cdr read))))
6014         ;; `read' is a list of ranges.
6015         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6016                                   (caar read)))
6017                   1)
6018           (setq first (car active)))
6019         (while read
6020           (when first
6021             (while (< first nlast)
6022               (push first unread)
6023               (setq first (1+ first))))
6024           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6025           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6026           (setq read (cdr read)))))
6027     ;; And add the last unread articles.
6028     (while (<= first last)
6029       (push first unread)
6030       (setq first (1+ first)))
6031     ;; Return the list of unread articles.
6032     (delq 0 (nreverse unread))))
6033
6034 (defun gnus-list-of-read-articles (group)
6035   "Return a list of unread, unticked and non-dormant articles."
6036   (let* ((info (gnus-get-info group))
6037          (marked (gnus-info-marks info))
6038          (active (gnus-active group)))
6039     (and info active
6040          (gnus-list-range-difference
6041           (gnus-list-range-difference
6042            (gnus-sorted-complement
6043             (gnus-uncompress-range active)
6044             (gnus-list-of-unread-articles group))
6045            (cdr (assq 'dormant marked)))
6046           (cdr (assq 'tick marked))))))
6047
6048 ;; Various summary commands
6049
6050 (defun gnus-summary-select-article-buffer ()
6051   "Reconfigure windows to show article buffer."
6052   (interactive)
6053   (if (not (gnus-buffer-live-p gnus-article-buffer))
6054       (error "There is no article buffer for this summary buffer")
6055     (gnus-configure-windows 'article)
6056     (select-window (get-buffer-window gnus-article-buffer))))
6057
6058 (defun gnus-summary-universal-argument (arg)
6059   "Perform any operation on all articles that are process/prefixed."
6060   (interactive "P")
6061   (let ((articles (gnus-summary-work-articles arg))
6062         func article)
6063     (if (eq
6064          (setq
6065           func
6066           (key-binding
6067            (read-key-sequence
6068             (substitute-command-keys
6069              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6070          'undefined)
6071         (gnus-error 1 "Undefined key")
6072       (save-excursion
6073         (while articles
6074           (gnus-summary-goto-subject (setq article (pop articles)))
6075           (let (gnus-newsgroup-processable)
6076             (command-execute func))
6077           (gnus-summary-remove-process-mark article)))))
6078   (gnus-summary-position-point))
6079
6080 (defun gnus-summary-toggle-truncation (&optional arg)
6081   "Toggle truncation of summary lines.
6082 With arg, turn line truncation on iff arg is positive."
6083   (interactive "P")
6084   (setq truncate-lines
6085         (if (null arg) (not truncate-lines)
6086           (> (prefix-numeric-value arg) 0)))
6087   (redraw-display))
6088
6089 (defun gnus-summary-reselect-current-group (&optional all rescan)
6090   "Exit and then reselect the current newsgroup.
6091 The prefix argument ALL means to select all articles."
6092   (interactive "P")
6093   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6094     (error "Ephemeral groups can't be reselected"))
6095   (let ((current-subject (gnus-summary-article-number))
6096         (group gnus-newsgroup-name))
6097     (setq gnus-newsgroup-begin nil)
6098     (gnus-summary-exit)
6099     ;; We have to adjust the point of group mode buffer because
6100     ;; point was moved to the next unread newsgroup by exiting.
6101     (gnus-summary-jump-to-group group)
6102     (when rescan
6103       (save-excursion
6104         (save-window-excursion
6105           ;; Don't show group contents.
6106           (set-window-start (selected-window) (point-max))
6107           (gnus-group-get-new-news-this-group 1))))
6108     (gnus-group-read-group all t)
6109     (gnus-summary-goto-subject current-subject nil t)))
6110
6111 (defun gnus-summary-rescan-group (&optional all)
6112   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6113   (interactive "P")
6114   (gnus-summary-reselect-current-group all t))
6115
6116 (defun gnus-summary-update-info (&optional non-destructive)
6117   (save-excursion
6118     (let ((group gnus-newsgroup-name))
6119       (when group
6120         (when gnus-newsgroup-kill-headers
6121           (setq gnus-newsgroup-killed
6122                 (gnus-compress-sequence
6123                  (gnus-sorted-union
6124                   (gnus-list-range-intersection
6125                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6126                   gnus-newsgroup-unreads)
6127                  t)))
6128         (unless (listp (cdr gnus-newsgroup-killed))
6129           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6130         (let ((headers gnus-newsgroup-headers))
6131           ;; Set the new ranges of read articles.
6132           (save-excursion
6133             (set-buffer gnus-group-buffer)
6134             (gnus-undo-force-boundary))
6135           (gnus-update-read-articles
6136            group (gnus-sorted-union
6137                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6138           ;; Set the current article marks.
6139           (let ((gnus-newsgroup-scored
6140                  (if (and (not gnus-save-score)
6141                           (not non-destructive))
6142                      nil
6143                    gnus-newsgroup-scored)))
6144             (save-excursion
6145               (gnus-update-marks)))
6146           ;; Do the cross-ref thing.
6147           (when gnus-use-cross-reference
6148             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6149           ;; Do not switch windows but change the buffer to work.
6150           (set-buffer gnus-group-buffer)
6151           (unless (gnus-ephemeral-group-p group)
6152             (gnus-group-update-group group)))))))
6153
6154 (defun gnus-summary-save-newsrc (&optional force)
6155   "Save the current number of read/marked articles in the dribble buffer.
6156 The dribble buffer will then be saved.
6157 If FORCE (the prefix), also save the .newsrc file(s)."
6158   (interactive "P")
6159   (gnus-summary-update-info t)
6160   (if force
6161       (gnus-save-newsrc-file)
6162     (gnus-dribble-save)))
6163
6164 (defun gnus-summary-exit (&optional temporary)
6165   "Exit reading current newsgroup, and then return to group selection mode.
6166 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6167   (interactive)
6168   (gnus-set-global-variables)
6169   (gnus-kill-save-kill-buffer)
6170   (gnus-async-halt-prefetch)
6171   (let* ((group gnus-newsgroup-name)
6172          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6173          (mode major-mode)
6174          (group-point nil)
6175          (buf (current-buffer)))
6176     (unless quit-config
6177       ;; Do adaptive scoring, and possibly save score files.
6178       (when gnus-newsgroup-adaptive
6179         (gnus-score-adaptive))
6180       (when gnus-use-scoring
6181         (gnus-score-save)))
6182     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6183     ;; If we have several article buffers, we kill them at exit.
6184     (unless gnus-single-article-buffer
6185       (gnus-kill-buffer gnus-original-article-buffer)
6186       (setq gnus-article-current nil))
6187     (when gnus-use-cache
6188       (gnus-cache-possibly-remove-articles)
6189       (gnus-cache-save-buffers))
6190     (gnus-async-prefetch-remove-group group)
6191     (when gnus-suppress-duplicates
6192       (gnus-dup-enter-articles))
6193     (when gnus-use-trees
6194       (gnus-tree-close group))
6195     (when gnus-use-cache
6196       (gnus-cache-write-active))
6197     ;; Remove entries for this group.
6198     (nnmail-purge-split-history (gnus-group-real-name group))
6199     ;; Make all changes in this group permanent.
6200     (unless quit-config
6201       (gnus-run-hooks 'gnus-exit-group-hook)
6202       (gnus-summary-update-info))
6203     (gnus-close-group group)
6204     ;; Make sure where we were, and go to next newsgroup.
6205     (set-buffer gnus-group-buffer)
6206     (unless quit-config
6207       (gnus-group-jump-to-group group))
6208     (gnus-run-hooks 'gnus-summary-exit-hook)
6209     (unless (or quit-config
6210                 ;; If this group has disappeared from the summary
6211                 ;; buffer, don't skip forwards.
6212                 (not (string= group (gnus-group-group-name))))
6213       (gnus-group-next-unread-group 1))
6214     (setq group-point (point))
6215     (if temporary
6216         nil                             ;Nothing to do.
6217       ;; If we have several article buffers, we kill them at exit.
6218       (unless gnus-single-article-buffer
6219         (gnus-kill-buffer gnus-article-buffer)
6220         (gnus-kill-buffer gnus-original-article-buffer)
6221         (setq gnus-article-current nil))
6222       (set-buffer buf)
6223       (if (not gnus-kill-summary-on-exit)
6224           (progn
6225             (gnus-deaden-summary)
6226             (setq mode nil))
6227         ;; We set all buffer-local variables to nil.  It is unclear why
6228         ;; this is needed, but if we don't, buffer-local variables are
6229         ;; not garbage-collected, it seems.  This would the lead to en
6230         ;; ever-growing Emacs.
6231         (gnus-summary-clear-local-variables)
6232         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6233           (gnus-summary-clear-local-variables))
6234         (when (get-buffer gnus-article-buffer)
6235           (bury-buffer gnus-article-buffer))
6236         ;; We clear the global counterparts of the buffer-local
6237         ;; variables as well, just to be on the safe side.
6238         (set-buffer gnus-group-buffer)
6239         (gnus-summary-clear-local-variables)
6240         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6241           (gnus-summary-clear-local-variables)))
6242       (setq gnus-current-select-method gnus-select-method)
6243       (pop-to-buffer gnus-group-buffer)
6244       (if (not quit-config)
6245           (progn
6246             (goto-char group-point)
6247             (gnus-configure-windows 'group 'force)
6248             (unless (pos-visible-in-window-p)
6249               (forward-line (/ (static-if (featurep 'xemacs)
6250                                    (window-displayed-height)
6251                                  (1- (window-height)))
6252                                -2))
6253               (set-window-start (selected-window) (point))
6254               (goto-char group-point)))
6255         (gnus-handle-ephemeral-exit quit-config))
6256       ;; Return to group mode buffer.
6257       (when (eq mode 'gnus-summary-mode)
6258         (gnus-kill-buffer buf))
6259       ;; Clear the current group name.
6260       (unless quit-config
6261         (setq gnus-newsgroup-name nil)))))
6262
6263 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6264 (defun gnus-summary-exit-no-update (&optional no-questions)
6265   "Quit reading current newsgroup without updating read article info."
6266   (interactive)
6267   (let* ((group gnus-newsgroup-name)
6268          (quit-config (gnus-group-quit-config group)))
6269     (when (or no-questions
6270               gnus-expert-user
6271               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6272       (gnus-async-halt-prefetch)
6273       (mapcar 'funcall
6274               (delq 'gnus-summary-expire-articles
6275                     (copy-sequence gnus-summary-prepare-exit-hook)))
6276       ;; If we have several article buffers, we kill them at exit.
6277       (unless gnus-single-article-buffer
6278         (gnus-kill-buffer gnus-article-buffer)
6279         (gnus-kill-buffer gnus-original-article-buffer)
6280         (setq gnus-article-current nil))
6281       (if (not gnus-kill-summary-on-exit)
6282           (gnus-deaden-summary)
6283         (gnus-close-group group)
6284         (gnus-summary-clear-local-variables)
6285         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6286           (gnus-summary-clear-local-variables))
6287         (set-buffer gnus-group-buffer)
6288         (gnus-summary-clear-local-variables)
6289         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6290           (gnus-summary-clear-local-variables))
6291         (when (get-buffer gnus-summary-buffer)
6292           (kill-buffer gnus-summary-buffer)))
6293       (unless gnus-single-article-buffer
6294         (setq gnus-article-current nil))
6295       (when gnus-use-trees
6296         (gnus-tree-close group))
6297       (gnus-async-prefetch-remove-group group)
6298       (when (get-buffer gnus-article-buffer)
6299         (bury-buffer gnus-article-buffer))
6300       ;; Return to the group buffer.
6301       (gnus-configure-windows 'group 'force)
6302       ;; Clear the current group name.
6303       (setq gnus-newsgroup-name nil)
6304       (when (equal (gnus-group-group-name) group)
6305         (gnus-group-next-unread-group 1))
6306       (when quit-config
6307         (gnus-handle-ephemeral-exit quit-config)))))
6308
6309 (defun gnus-handle-ephemeral-exit (quit-config)
6310   "Handle movement when leaving an ephemeral group.
6311 The state which existed when entering the ephemeral is reset."
6312   (if (not (buffer-name (car quit-config)))
6313       (gnus-configure-windows 'group 'force)
6314     (set-buffer (car quit-config))
6315     (cond ((eq major-mode 'gnus-summary-mode)
6316            (gnus-set-global-variables))
6317           ((eq major-mode 'gnus-article-mode)
6318            (save-excursion
6319              ;; The `gnus-summary-buffer' variable may point
6320              ;; to the old summary buffer when using a single
6321              ;; article buffer.
6322              (unless (gnus-buffer-live-p gnus-summary-buffer)
6323                (set-buffer gnus-group-buffer))
6324              (set-buffer gnus-summary-buffer)
6325              (gnus-set-global-variables))))
6326     (if (or (eq (cdr quit-config) 'article)
6327             (eq (cdr quit-config) 'pick))
6328         (progn
6329           ;; The current article may be from the ephemeral group
6330           ;; thus it is best that we reload this article
6331           (gnus-summary-show-article)
6332           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6333               (gnus-configure-windows 'pick 'force)
6334             (gnus-configure-windows (cdr quit-config) 'force)))
6335       (gnus-configure-windows (cdr quit-config) 'force))
6336     (when (eq major-mode 'gnus-summary-mode)
6337       (gnus-summary-next-subject 1 nil t)
6338       (gnus-summary-recenter)
6339       (gnus-summary-position-point))))
6340
6341 (defun gnus-summary-preview-mime-message ()
6342   "MIME decode and play this message."
6343   (interactive)
6344   (let ((gnus-break-pages nil)
6345         (gnus-show-mime t))
6346     (gnus-summary-select-article gnus-show-all-headers t))
6347   (let ((w (get-buffer-window gnus-article-buffer)))
6348     (when w
6349       (select-window (get-buffer-window gnus-article-buffer)))))
6350
6351 ;;; Dead summaries.
6352
6353 (defvar gnus-dead-summary-mode-map nil)
6354
6355 (unless gnus-dead-summary-mode-map
6356   (setq gnus-dead-summary-mode-map (make-keymap))
6357   (suppress-keymap gnus-dead-summary-mode-map)
6358   (substitute-key-definition
6359    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6360   (dolist (key '("\C-d" "\r" "\177" [delete]))
6361     (define-key gnus-dead-summary-mode-map
6362       key 'gnus-summary-wake-up-the-dead))
6363   (dolist (key '("q" "Q"))
6364     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6365
6366 (defvar gnus-dead-summary-mode nil
6367   "Minor mode for Gnus summary buffers.")
6368
6369 (defun gnus-dead-summary-mode (&optional arg)
6370   "Minor mode for Gnus summary buffers."
6371   (interactive "P")
6372   (when (eq major-mode 'gnus-summary-mode)
6373     (make-local-variable 'gnus-dead-summary-mode)
6374     (setq gnus-dead-summary-mode
6375           (if (null arg) (not gnus-dead-summary-mode)
6376             (> (prefix-numeric-value arg) 0)))
6377     (when gnus-dead-summary-mode
6378       (gnus-add-minor-mode
6379        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6380
6381 (defun gnus-deaden-summary ()
6382   "Make the current summary buffer into a dead summary buffer."
6383   ;; Kill any previous dead summary buffer.
6384   (when (and gnus-dead-summary
6385              (buffer-name gnus-dead-summary))
6386     (save-excursion
6387       (set-buffer gnus-dead-summary)
6388       (when gnus-dead-summary-mode
6389         (kill-buffer (current-buffer)))))
6390   ;; Make this the current dead summary.
6391   (setq gnus-dead-summary (current-buffer))
6392   (gnus-dead-summary-mode 1)
6393   (let ((name (buffer-name)))
6394     (when (string-match "Summary" name)
6395       (rename-buffer
6396        (concat (substring name 0 (match-beginning 0)) "Dead "
6397                (substring name (match-beginning 0)))
6398        t)
6399       (bury-buffer))))
6400
6401 (defun gnus-kill-or-deaden-summary (buffer)
6402   "Kill or deaden the summary BUFFER."
6403   (save-excursion
6404     (when (and (buffer-name buffer)
6405                (not gnus-single-article-buffer))
6406       (save-excursion
6407         (set-buffer buffer)
6408         (gnus-kill-buffer gnus-article-buffer)
6409         (gnus-kill-buffer gnus-original-article-buffer)))
6410     (cond
6411      ;; Kill the buffer.
6412      (gnus-kill-summary-on-exit
6413       (when (and gnus-use-trees
6414                  (gnus-buffer-exists-p buffer))
6415         (save-excursion
6416           (set-buffer buffer)
6417           (gnus-tree-close gnus-newsgroup-name)))
6418       (gnus-kill-buffer buffer))
6419      ;; Deaden the buffer.
6420      ((gnus-buffer-exists-p buffer)
6421       (save-excursion
6422         (set-buffer buffer)
6423         (gnus-deaden-summary))))))
6424
6425 (defun gnus-summary-wake-up-the-dead (&rest args)
6426   "Wake up the dead summary buffer."
6427   (interactive)
6428   (gnus-dead-summary-mode -1)
6429   (let ((name (buffer-name)))
6430     (when (string-match "Dead " name)
6431       (rename-buffer
6432        (concat (substring name 0 (match-beginning 0))
6433                (substring name (match-end 0)))
6434        t)))
6435   (gnus-message 3 "This dead summary is now alive again"))
6436
6437 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6438 (defun gnus-summary-fetch-faq (&optional faq-dir)
6439   "Fetch the FAQ for the current group.
6440 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6441 in."
6442   (interactive
6443    (list
6444     (when current-prefix-arg
6445       (completing-read
6446        "Faq dir: " (and (listp gnus-group-faq-directory)
6447                         (mapcar (lambda (file) (list file))
6448                                 gnus-group-faq-directory))))))
6449   (let (gnus-faq-buffer)
6450     (when (setq gnus-faq-buffer
6451                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6452       (gnus-configure-windows 'summary-faq))))
6453
6454 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6455 (defun gnus-summary-describe-group (&optional force)
6456   "Describe the current newsgroup."
6457   (interactive "P")
6458   (gnus-group-describe-group force gnus-newsgroup-name))
6459
6460 (defun gnus-summary-describe-briefly ()
6461   "Describe summary mode commands briefly."
6462   (interactive)
6463   (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")))
6464
6465 ;; Walking around group mode buffer from summary mode.
6466
6467 (defun gnus-summary-next-group (&optional no-article target-group backward)
6468   "Exit current newsgroup and then select next unread newsgroup.
6469 If prefix argument NO-ARTICLE is non-nil, no article is selected
6470 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6471 previous group instead."
6472   (interactive "P")
6473   ;; Stop pre-fetching.
6474   (gnus-async-halt-prefetch)
6475   (let ((current-group gnus-newsgroup-name)
6476         (current-buffer (current-buffer))
6477         entered)
6478     ;; First we semi-exit this group to update Xrefs and all variables.
6479     ;; We can't do a real exit, because the window conf must remain
6480     ;; the same in case the user is prompted for info, and we don't
6481     ;; want the window conf to change before that...
6482     (gnus-summary-exit t)
6483     (while (not entered)
6484       ;; Then we find what group we are supposed to enter.
6485       (set-buffer gnus-group-buffer)
6486       (gnus-group-jump-to-group current-group)
6487       (setq target-group
6488             (or target-group
6489                 (if (eq gnus-keep-same-level 'best)
6490                     (gnus-summary-best-group gnus-newsgroup-name)
6491                   (gnus-summary-search-group backward gnus-keep-same-level))))
6492       (if (not target-group)
6493           ;; There are no further groups, so we return to the group
6494           ;; buffer.
6495           (progn
6496             (gnus-message 5 "Returning to the group buffer")
6497             (setq entered t)
6498             (when (gnus-buffer-live-p current-buffer)
6499               (set-buffer current-buffer)
6500               (gnus-summary-exit))
6501             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6502         ;; We try to enter the target group.
6503         (gnus-group-jump-to-group target-group)
6504         (let ((unreads (gnus-group-group-unread)))
6505           (if (and (or (eq t unreads)
6506                        (and unreads (not (zerop unreads))))
6507                    (gnus-summary-read-group
6508                     target-group nil no-article
6509                     (and (buffer-name current-buffer) current-buffer)
6510                     nil backward))
6511               (setq entered t)
6512             (setq current-group target-group
6513                   target-group nil)))))))
6514
6515 (defun gnus-summary-prev-group (&optional no-article)
6516   "Exit current newsgroup and then select previous unread newsgroup.
6517 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6518   (interactive "P")
6519   (gnus-summary-next-group no-article nil t))
6520
6521 ;; Walking around summary lines.
6522
6523 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6524   "Go to the first unread subject.
6525 If UNREAD is non-nil, go to the first unread article.
6526 Returns the article selected or nil if there are no unread articles."
6527   (interactive "P")
6528   (prog1
6529       (cond
6530        ;; Empty summary.
6531        ((null gnus-newsgroup-data)
6532         (gnus-message 3 "No articles in the group")
6533         nil)
6534        ;; Pick the first article.
6535        ((not unread)
6536         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6537         (gnus-data-number (car gnus-newsgroup-data)))
6538        ;; No unread articles.
6539        ((null gnus-newsgroup-unreads)
6540         (gnus-message 3 "No more unread articles")
6541         nil)
6542        ;; Find the first unread article.
6543        (t
6544         (let ((data gnus-newsgroup-data))
6545           (while (and data
6546                       (and (not (and undownloaded
6547                                      (eq gnus-undownloaded-mark
6548                                          (gnus-data-mark (car data)))))
6549                            (if unseen
6550                                (or (not (memq
6551                                          (gnus-data-number (car data))
6552                                          gnus-newsgroup-unseen))
6553                                    (not (gnus-data-unread-p (car data))))
6554                              (not (gnus-data-unread-p (car data))))))
6555             (setq data (cdr data)))
6556           (when data
6557             (goto-char (gnus-data-pos (car data)))
6558             (gnus-data-number (car data))))))
6559     (gnus-summary-position-point)))
6560
6561 (defun gnus-summary-next-subject (n &optional unread dont-display)
6562   "Go to next N'th summary line.
6563 If N is negative, go to the previous N'th subject line.
6564 If UNREAD is non-nil, only unread articles are selected.
6565 The difference between N and the actual number of steps taken is
6566 returned."
6567   (interactive "p")
6568   (let ((backward (< n 0))
6569         (n (abs n)))
6570     (while (and (> n 0)
6571                 (if backward
6572                     (gnus-summary-find-prev unread)
6573                   (gnus-summary-find-next unread)))
6574       (unless (zerop (setq n (1- n)))
6575         (gnus-summary-show-thread)))
6576     (when (/= 0 n)
6577       (gnus-message 7 "No more%s articles"
6578                     (if unread " unread" "")))
6579     (unless dont-display
6580       (gnus-summary-recenter)
6581       (gnus-summary-position-point))
6582     n))
6583
6584 (defun gnus-summary-next-unread-subject (n)
6585   "Go to next N'th unread summary line."
6586   (interactive "p")
6587   (gnus-summary-next-subject n t))
6588
6589 (defun gnus-summary-prev-subject (n &optional unread)
6590   "Go to previous N'th summary line.
6591 If optional argument UNREAD is non-nil, only unread article is selected."
6592   (interactive "p")
6593   (gnus-summary-next-subject (- n) unread))
6594
6595 (defun gnus-summary-prev-unread-subject (n)
6596   "Go to previous N'th unread summary line."
6597   (interactive "p")
6598   (gnus-summary-next-subject (- n) t))
6599
6600 (defun gnus-summary-goto-subject (article &optional force silent)
6601   "Go the subject line of ARTICLE.
6602 If FORCE, also allow jumping to articles not currently shown."
6603   (interactive "nArticle number: ")
6604   (unless (numberp article)
6605     (error "Article %s is not a number" article))
6606   (let ((b (point))
6607         (data (gnus-data-find article)))
6608     ;; We read in the article if we have to.
6609     (and (not data)
6610          force
6611          (gnus-summary-insert-subject
6612           article
6613           (if (or (numberp force) (vectorp force)) force)
6614           t)
6615          (setq data (gnus-data-find article)))
6616     (goto-char b)
6617     (if (not data)
6618         (progn
6619           (unless silent
6620             (gnus-message 3 "Can't find article %d" article))
6621           nil)
6622       (let ((pt (gnus-data-pos data)))
6623         (goto-char pt)
6624         (gnus-summary-set-article-display-arrow pt))
6625       (gnus-summary-position-point)
6626       article)))
6627
6628 ;; Walking around summary lines with displaying articles.
6629
6630 (defun gnus-summary-expand-window (&optional arg)
6631   "Make the summary buffer take up the entire Emacs frame.
6632 Given a prefix, will force an `article' buffer configuration."
6633   (interactive "P")
6634   (if arg
6635       (gnus-configure-windows 'article 'force)
6636     (gnus-configure-windows 'summary 'force)))
6637
6638 (defun gnus-summary-display-article (article &optional all-header)
6639   "Display ARTICLE in article buffer."
6640   (when (gnus-buffer-live-p gnus-article-buffer)
6641     (with-current-buffer gnus-article-buffer
6642       (set-buffer-multibyte t)))
6643   (gnus-set-global-variables)
6644   (when (gnus-buffer-live-p gnus-article-buffer)
6645     (with-current-buffer gnus-article-buffer
6646       (setq gnus-article-charset gnus-newsgroup-charset)
6647       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6648       (set-buffer-multibyte t)))
6649   (if (null article)
6650       nil
6651     (prog1
6652         (if gnus-summary-display-article-function
6653             (funcall gnus-summary-display-article-function article all-header)
6654           (gnus-article-prepare article all-header))
6655       (with-current-buffer gnus-article-buffer
6656         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6657              nil))
6658       (gnus-run-hooks 'gnus-select-article-hook)
6659       (when (and gnus-current-article
6660                  (not (zerop gnus-current-article)))
6661         (gnus-summary-goto-subject gnus-current-article))
6662       (gnus-summary-recenter)
6663       (when (and gnus-use-trees gnus-show-threads)
6664         (gnus-possibly-generate-tree article)
6665         (gnus-highlight-selected-tree article))
6666       ;; Successfully display article.
6667       (gnus-article-set-window-start
6668        (cdr (assq article gnus-newsgroup-bookmarks))))))
6669
6670 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6671   "Select the current article.
6672 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6673 non-nil, the article will be re-fetched even if it already present in
6674 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6675 be displayed."
6676   ;; Make sure we are in the summary buffer to work around bbdb bug.
6677   (unless (eq major-mode 'gnus-summary-mode)
6678     (set-buffer gnus-summary-buffer))
6679   (let ((article (or article (gnus-summary-article-number)))
6680         (all-headers (not (not all-headers))) ;Must be T or NIL.
6681         gnus-summary-display-article-function)
6682     (and (not pseudo)
6683          (gnus-summary-article-pseudo-p article)
6684          (error "This is a pseudo-article"))
6685     (save-excursion
6686       (set-buffer gnus-summary-buffer)
6687       (if (or (and gnus-single-article-buffer
6688                    (or (null gnus-current-article)
6689                        (null gnus-article-current)
6690                        (null (get-buffer gnus-article-buffer))
6691                        (not (eq article (cdr gnus-article-current)))
6692                        (not (equal (car gnus-article-current)
6693                                    gnus-newsgroup-name))))
6694               (and (not gnus-single-article-buffer)
6695                    (or (null gnus-current-article)
6696                        (not (eq gnus-current-article article))))
6697               force)
6698           ;; The requested article is different from the current article.
6699           (progn
6700             (gnus-summary-display-article article all-headers)
6701             (gnus-article-set-window-start
6702              (cdr (assq article gnus-newsgroup-bookmarks)))
6703             article)
6704         'old))))
6705
6706 (defun gnus-summary-force-verify-and-decrypt ()
6707   (interactive)
6708   (let ((mm-verify-option 'known)
6709         (mm-decrypt-option 'known))
6710     (gnus-summary-select-article nil 'force)))
6711
6712 (defun gnus-summary-set-current-mark (&optional current-mark)
6713   "Obsolete function."
6714   nil)
6715
6716 (defun gnus-summary-next-article (&optional unread subject backward push)
6717   "Select the next article.
6718 If UNREAD, only unread articles are selected.
6719 If SUBJECT, only articles with SUBJECT are selected.
6720 If BACKWARD, the previous article is selected instead of the next."
6721   (interactive "P")
6722   (cond
6723    ;; Is there such an article?
6724    ((and (gnus-summary-search-forward unread subject backward)
6725          (or (gnus-summary-display-article (gnus-summary-article-number))
6726              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6727     (gnus-summary-position-point))
6728    ;; If not, we try the first unread, if that is wanted.
6729    ((and subject
6730          gnus-auto-select-same
6731          (gnus-summary-first-unread-article))
6732     (gnus-summary-position-point)
6733     (gnus-message 6 "Wrapped"))
6734    ;; Try to get next/previous article not displayed in this group.
6735    ((and gnus-auto-extend-newsgroup
6736          (not unread) (not subject))
6737     (gnus-summary-goto-article
6738      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6739      nil (count-lines (point-min) (point))))
6740    ;; Go to next/previous group.
6741    (t
6742     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6743       (gnus-summary-jump-to-group gnus-newsgroup-name))
6744     (let ((cmd last-command-char)
6745           (point
6746            (save-excursion
6747              (set-buffer gnus-group-buffer)
6748              (point)))
6749           (group
6750            (if (eq gnus-keep-same-level 'best)
6751                (gnus-summary-best-group gnus-newsgroup-name)
6752              (gnus-summary-search-group backward gnus-keep-same-level))))
6753       ;; For some reason, the group window gets selected.  We change
6754       ;; it back.
6755       (select-window (get-buffer-window (current-buffer)))
6756       ;; Select next unread newsgroup automagically.
6757       (cond
6758        ((or (not gnus-auto-select-next)
6759             (not cmd))
6760         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6761        ((or (eq gnus-auto-select-next 'quietly)
6762             (and (eq gnus-auto-select-next 'slightly-quietly)
6763                  push)
6764             (and (eq gnus-auto-select-next 'almost-quietly)
6765                  (gnus-summary-last-article-p)))
6766         ;; Select quietly.
6767         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6768             (gnus-summary-exit)
6769           (gnus-message 7 "No more%s articles (%s)..."
6770                         (if unread " unread" "")
6771                         (if group (concat "selecting " group)
6772                           "exiting"))
6773           (gnus-summary-next-group nil group backward)))
6774        (t
6775         (when (gnus-key-press-event-p last-input-event)
6776           (gnus-summary-walk-group-buffer
6777            gnus-newsgroup-name cmd unread backward point))))))))
6778
6779 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6780   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6781                       (?\C-p (gnus-group-prev-unread-group 1))))
6782         (cursor-in-echo-area t)
6783         keve key group ended)
6784     (save-excursion
6785       (set-buffer gnus-group-buffer)
6786       (goto-char start)
6787       (setq group
6788             (if (eq gnus-keep-same-level 'best)
6789                 (gnus-summary-best-group gnus-newsgroup-name)
6790               (gnus-summary-search-group backward gnus-keep-same-level))))
6791     (while (not ended)
6792       (gnus-message
6793        5 "No more%s articles%s" (if unread " unread" "")
6794        (if (and group
6795                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6796            (format " (Type %s for %s [%s])"
6797                    (single-key-description cmd) group
6798                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6799          (format " (Type %s to exit %s)"
6800                  (single-key-description cmd)
6801                  gnus-newsgroup-name)))
6802       ;; Confirm auto selection.
6803       (setq key (car (setq keve (gnus-read-event-char))))
6804       (setq ended t)
6805       (cond
6806        ((assq key keystrokes)
6807         (let ((obuf (current-buffer)))
6808           (switch-to-buffer gnus-group-buffer)
6809           (when group
6810             (gnus-group-jump-to-group group))
6811           (eval (cadr (assq key keystrokes)))
6812           (setq group (gnus-group-group-name))
6813           (switch-to-buffer obuf))
6814         (setq ended nil))
6815        ((equal key cmd)
6816         (if (or (not group)
6817                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6818             (gnus-summary-exit)
6819           (gnus-summary-next-group nil group backward)))
6820        (t
6821         (push (cdr keve) unread-command-events))))))
6822
6823 (defun gnus-summary-next-unread-article ()
6824   "Select unread article after current one."
6825   (interactive)
6826   (gnus-summary-next-article
6827    (or (not (eq gnus-summary-goto-unread 'never))
6828        (gnus-summary-last-article-p (gnus-summary-article-number)))
6829    (and gnus-auto-select-same
6830         (gnus-summary-article-subject))))
6831
6832 (defun gnus-summary-prev-article (&optional unread subject)
6833   "Select the article after the current one.
6834 If UNREAD is non-nil, only unread articles are selected."
6835   (interactive "P")
6836   (gnus-summary-next-article unread subject t))
6837
6838 (defun gnus-summary-prev-unread-article ()
6839   "Select unread article before current one."
6840   (interactive)
6841   (gnus-summary-prev-article
6842    (or (not (eq gnus-summary-goto-unread 'never))
6843        (gnus-summary-first-article-p (gnus-summary-article-number)))
6844    (and gnus-auto-select-same
6845         (gnus-summary-article-subject))))
6846
6847 (defun gnus-summary-next-page (&optional lines circular)
6848   "Show next page of the selected article.
6849 If at the end of the current article, select the next article.
6850 LINES says how many lines should be scrolled up.
6851
6852 If CIRCULAR is non-nil, go to the start of the article instead of
6853 selecting the next article when reaching the end of the current
6854 article."
6855   (interactive "P")
6856   (setq gnus-summary-buffer (current-buffer))
6857   (gnus-set-global-variables)
6858   (let ((article (gnus-summary-article-number))
6859         (article-window (get-buffer-window gnus-article-buffer t))
6860         endp)
6861     ;; If the buffer is empty, we have no article.
6862     (unless article
6863       (error "No article to select"))
6864     (gnus-configure-windows 'article)
6865     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6866         (if (and (eq gnus-summary-goto-unread 'never)
6867                  (not (gnus-summary-last-article-p article)))
6868             (gnus-summary-next-article)
6869           (gnus-summary-next-unread-article))
6870       (if (or (null gnus-current-article)
6871               (null gnus-article-current)
6872               (/= article (cdr gnus-article-current))
6873               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6874           ;; Selected subject is different from current article's.
6875           (gnus-summary-display-article article)
6876         (when article-window
6877           (gnus-eval-in-buffer-window gnus-article-buffer
6878             (setq endp (gnus-article-next-page lines)))
6879           (when endp
6880             (cond (circular
6881                    (gnus-summary-beginning-of-article))
6882                   (lines
6883                    (gnus-message 3 "End of message"))
6884                   ((null lines)
6885                    (if (and (eq gnus-summary-goto-unread 'never)
6886                             (not (gnus-summary-last-article-p article)))
6887                        (gnus-summary-next-article)
6888                      (gnus-summary-next-unread-article))))))))
6889     (gnus-summary-recenter)
6890     (gnus-summary-position-point)))
6891
6892 (defun gnus-summary-prev-page (&optional lines move)
6893   "Show previous page of selected article.
6894 Argument LINES specifies lines to be scrolled down.
6895 If MOVE, move to the previous unread article if point is at
6896 the beginning of the buffer."
6897   (interactive "P")
6898   (let ((article (gnus-summary-article-number))
6899         (article-window (get-buffer-window gnus-article-buffer t))
6900         endp)
6901     (gnus-configure-windows 'article)
6902     (if (or (null gnus-current-article)
6903             (null gnus-article-current)
6904             (/= article (cdr gnus-article-current))
6905             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6906         ;; Selected subject is different from current article's.
6907         (gnus-summary-display-article article)
6908       (gnus-summary-recenter)
6909       (when article-window
6910         (gnus-eval-in-buffer-window gnus-article-buffer
6911           (setq endp (gnus-article-prev-page lines)))
6912         (when (and move endp)
6913           (cond (lines
6914                  (gnus-message 3 "Beginning of message"))
6915                 ((null lines)
6916                  (if (and (eq gnus-summary-goto-unread 'never)
6917                           (not (gnus-summary-first-article-p article)))
6918                      (gnus-summary-prev-article)
6919                    (gnus-summary-prev-unread-article))))))))
6920   (gnus-summary-position-point))
6921
6922 (defun gnus-summary-prev-page-or-article (&optional lines)
6923   "Show previous page of selected article.
6924 Argument LINES specifies lines to be scrolled down.
6925 If at the beginning of the article, go to the next article."
6926   (interactive "P")
6927   (gnus-summary-prev-page lines t))
6928
6929 (defun gnus-summary-scroll-up (lines)
6930   "Scroll up (or down) one line current article.
6931 Argument LINES specifies lines to be scrolled up (or down if negative)."
6932   (interactive "p")
6933   (gnus-configure-windows 'article)
6934   (gnus-summary-show-thread)
6935   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6936     (gnus-eval-in-buffer-window gnus-article-buffer
6937       (cond ((> lines 0)
6938              (when (gnus-article-next-page lines)
6939                (gnus-message 3 "End of message")))
6940             ((< lines 0)
6941              (gnus-article-prev-page (- lines))))))
6942   (gnus-summary-recenter)
6943   (gnus-summary-position-point))
6944
6945 (defun gnus-summary-scroll-down (lines)
6946   "Scroll down (or up) one line current article.
6947 Argument LINES specifies lines to be scrolled down (or up if negative)."
6948   (interactive "p")
6949   (gnus-summary-scroll-up (- lines)))
6950
6951 (defun gnus-summary-next-same-subject ()
6952   "Select next article which has the same subject as current one."
6953   (interactive)
6954   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6955
6956 (defun gnus-summary-prev-same-subject ()
6957   "Select previous article which has the same subject as current one."
6958   (interactive)
6959   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6960
6961 (defun gnus-summary-next-unread-same-subject ()
6962   "Select next unread article which has the same subject as current one."
6963   (interactive)
6964   (gnus-summary-next-article t (gnus-summary-article-subject)))
6965
6966 (defun gnus-summary-prev-unread-same-subject ()
6967   "Select previous unread article which has the same subject as current one."
6968   (interactive)
6969   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6970
6971 (defun gnus-summary-first-unread-article ()
6972   "Select the first unread article.
6973 Return nil if there are no unread articles."
6974   (interactive)
6975   (prog1
6976       (when (gnus-summary-first-subject t)
6977         (gnus-summary-show-thread)
6978         (gnus-summary-first-subject t)
6979         (gnus-summary-display-article (gnus-summary-article-number)))
6980     (gnus-summary-position-point)))
6981
6982 (defun gnus-summary-first-unread-subject ()
6983   "Place the point on the subject line of the first unread article.
6984 Return nil if there are no unread articles."
6985   (interactive)
6986   (prog1
6987       (when (gnus-summary-first-subject t)
6988         (gnus-summary-show-thread)
6989         (gnus-summary-first-subject t))
6990     (gnus-summary-position-point)))
6991
6992 (defun gnus-summary-first-unseen-subject ()
6993   "Place the point on the subject line of the first unseen article.
6994 Return nil if there are no unseen articles."
6995   (interactive)
6996   (prog1
6997       (when (gnus-summary-first-subject t t t)
6998         (gnus-summary-show-thread)
6999         (gnus-summary-first-subject t t t))
7000     (gnus-summary-position-point)))
7001
7002 (defun gnus-summary-first-unseen-or-unread-subject ()
7003   "Place the point on the subject line of the first unseen article.
7004 Return nil if there are no unseen articles."
7005   (interactive)
7006   (prog1
7007       (unless (when (gnus-summary-first-subject t t t)
7008                 (gnus-summary-show-thread)
7009                 (gnus-summary-first-subject t t t))
7010         (when (gnus-summary-first-subject t)
7011           (gnus-summary-show-thread)
7012           (gnus-summary-first-subject t)))
7013     (gnus-summary-position-point)))
7014
7015 (defun gnus-summary-first-article ()
7016   "Select the first article.
7017 Return nil if there are no articles."
7018   (interactive)
7019   (prog1
7020       (when (gnus-summary-first-subject)
7021         (gnus-summary-show-thread)
7022         (gnus-summary-first-subject)
7023         (gnus-summary-display-article (gnus-summary-article-number)))
7024     (gnus-summary-position-point)))
7025
7026 (defun gnus-summary-best-unread-article (&optional arg)
7027   "Select the unread article with the highest score.
7028 If given a prefix argument, select the next unread article that has a
7029 score higher than the default score."
7030   (interactive "P")
7031   (let ((article (if arg
7032                      (gnus-summary-better-unread-subject)
7033                    (gnus-summary-best-unread-subject))))
7034     (if article
7035         (gnus-summary-goto-article article)
7036       (error "No unread articles"))))
7037
7038 (defun gnus-summary-best-unread-subject ()
7039   "Select the unread subject with the highest score."
7040   (interactive)
7041   (let ((best -1000000)
7042         (data gnus-newsgroup-data)
7043         article score)
7044     (while data
7045       (and (gnus-data-unread-p (car data))
7046            (> (setq score
7047                     (gnus-summary-article-score (gnus-data-number (car data))))
7048               best)
7049            (setq best score
7050                  article (gnus-data-number (car data))))
7051       (setq data (cdr data)))
7052     (when article
7053       (gnus-summary-goto-subject article))
7054     (gnus-summary-position-point)
7055     article))
7056
7057 (defun gnus-summary-better-unread-subject ()
7058   "Select the first unread subject that has a score over the default score."
7059   (interactive)
7060   (let ((data gnus-newsgroup-data)
7061         article score)
7062     (while (and (setq article (gnus-data-number (car data)))
7063                 (or (gnus-data-read-p (car data))
7064                     (not (> (gnus-summary-article-score article)
7065                             gnus-summary-default-score))))
7066       (setq data (cdr data)))
7067     (when article
7068       (gnus-summary-goto-subject article))
7069     (gnus-summary-position-point)
7070     article))
7071
7072 (defun gnus-summary-last-subject ()
7073   "Go to the last displayed subject line in the group."
7074   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7075     (when article
7076       (gnus-summary-goto-subject article))))
7077
7078 (defun gnus-summary-goto-article (article &optional all-headers force)
7079   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7080 If ALL-HEADERS is non-nil, no header lines are hidden.
7081 If FORCE, go to the article even if it isn't displayed.  If FORCE
7082 is a number, it is the line the article is to be displayed on."
7083   (interactive
7084    (list
7085     (completing-read
7086      "Article number or Message-ID: "
7087      (mapcar (lambda (number) (list (int-to-string number)))
7088              gnus-newsgroup-limit))
7089     current-prefix-arg
7090     t))
7091   (prog1
7092       (if (and (stringp article)
7093                (string-match "@" article))
7094           (gnus-summary-refer-article article)
7095         (when (stringp article)
7096           (setq article (string-to-number article)))
7097         (if (gnus-summary-goto-subject article force)
7098             (gnus-summary-display-article article all-headers)
7099           (gnus-message 4 "Couldn't go to article %s" article) nil))
7100     (gnus-summary-position-point)))
7101
7102 (defun gnus-summary-goto-last-article ()
7103   "Go to the previously read article."
7104   (interactive)
7105   (prog1
7106       (when gnus-last-article
7107         (gnus-summary-goto-article gnus-last-article nil t))
7108     (gnus-summary-position-point)))
7109
7110 (defun gnus-summary-pop-article (number)
7111   "Pop one article off the history and go to the previous.
7112 NUMBER articles will be popped off."
7113   (interactive "p")
7114   (let (to)
7115     (setq gnus-newsgroup-history
7116           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7117     (if to
7118         (gnus-summary-goto-article (car to) nil t)
7119       (error "Article history empty")))
7120   (gnus-summary-position-point))
7121
7122 ;; Summary commands and functions for limiting the summary buffer.
7123
7124 (defun gnus-summary-limit-to-articles (n)
7125   "Limit the summary buffer to the next N articles.
7126 If not given a prefix, use the process marked articles instead."
7127   (interactive "P")
7128   (prog1
7129       (let ((articles (gnus-summary-work-articles n)))
7130         (setq gnus-newsgroup-processable nil)
7131         (gnus-summary-limit articles))
7132     (gnus-summary-position-point)))
7133
7134 (defun gnus-summary-pop-limit (&optional total)
7135   "Restore the previous limit.
7136 If given a prefix, remove all limits."
7137   (interactive "P")
7138   (when total
7139     (setq gnus-newsgroup-limits
7140           (list (mapcar (lambda (h) (mail-header-number h))
7141                         gnus-newsgroup-headers))))
7142   (unless gnus-newsgroup-limits
7143     (error "No limit to pop"))
7144   (prog1
7145       (gnus-summary-limit nil 'pop)
7146     (gnus-summary-position-point)))
7147
7148 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7149   "Limit the summary buffer to articles that have subjects that match a regexp.
7150 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7151   (interactive
7152    (list (read-string (if current-prefix-arg
7153                           "Exclude subject (regexp): "
7154                         "Limit to subject (regexp): "))
7155          nil current-prefix-arg))
7156   (unless header
7157     (setq header "subject"))
7158   (when (not (equal "" subject))
7159     (prog1
7160         (let ((articles (gnus-summary-find-matching
7161                          (or header "subject") subject 'all nil nil
7162                          not-matching)))
7163           (unless articles
7164             (error "Found no matches for \"%s\"" subject))
7165           (gnus-summary-limit articles))
7166       (gnus-summary-position-point))))
7167
7168 (defun gnus-summary-limit-to-author (from &optional not-matching)
7169   "Limit the summary buffer to articles that have authors that match a regexp.
7170 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7171   (interactive
7172    (list (read-string (if current-prefix-arg
7173                           "Exclude author (regexp): "
7174                         "Limit to author (regexp): "))
7175          current-prefix-arg))
7176   (gnus-summary-limit-to-subject from "from" not-matching))
7177
7178 (defun gnus-summary-limit-to-age (age &optional younger-p)
7179   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7180 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7181 articles that are younger than AGE days."
7182   (interactive
7183    (let ((younger current-prefix-arg)
7184          (days-got nil)
7185          days)
7186      (while (not days-got)
7187        (setq days (if younger
7188                       (read-string "Limit to articles within (in days): ")
7189                     (read-string "Limit to articles older than (in days): ")))
7190        (when (> (length days) 0)
7191          (setq days (read days)))
7192        (if (numberp days)
7193            (progn
7194              (setq days-got t)
7195              (if (< days 0)
7196                  (progn
7197                    (setq younger (not younger))
7198                    (setq days (* days -1)))))
7199          (message "Please enter a number.")
7200          (sleep-for 1)))
7201      (list days younger)))
7202   (prog1
7203       (let ((data gnus-newsgroup-data)
7204             (cutoff (days-to-time age))
7205             articles d date is-younger)
7206         (while (setq d (pop data))
7207           (when (and (vectorp (gnus-data-header d))
7208                      (setq date (mail-header-date (gnus-data-header d))))
7209             (setq is-younger (time-less-p
7210                               (time-since (condition-case ()
7211                                               (date-to-time date)
7212                                             (error '(0 0))))
7213                               cutoff))
7214             (when (if younger-p
7215                       is-younger
7216                     (not is-younger))
7217               (push (gnus-data-number d) articles))))
7218         (gnus-summary-limit (nreverse articles)))
7219     (gnus-summary-position-point)))
7220
7221 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7222   "Limit the summary buffer to articles that match an 'extra' header."
7223   (interactive
7224    (let ((header
7225           (intern
7226            (gnus-completing-read-with-default
7227             (symbol-name (car gnus-extra-headers))
7228             (if current-prefix-arg
7229                 "Exclude extra header:"
7230               "Limit extra header:")
7231             (mapcar (lambda (x)
7232                       (cons (symbol-name x) x))
7233                     gnus-extra-headers)
7234             nil
7235             t))))
7236      (list header
7237            (read-string (format "%s header %s (regexp): "
7238                                 (if current-prefix-arg "Exclude" "Limit to")
7239                                 header))
7240            current-prefix-arg)))
7241   (when (not (equal "" regexp))
7242     (prog1
7243         (let ((articles (gnus-summary-find-matching
7244                          (cons 'extra header) regexp 'all nil nil
7245                          not-matching)))
7246           (unless articles
7247             (error "Found no matches for \"%s\"" regexp))
7248           (gnus-summary-limit articles))
7249       (gnus-summary-position-point))))
7250
7251 (defun gnus-summary-limit-to-display-predicate ()
7252   "Limit the summary buffer to the predicated in the `display' group parameter."
7253   (interactive)
7254   (unless gnus-newsgroup-display
7255     (error "There is no `display' group parameter"))
7256   (let (articles)
7257     (dolist (number gnus-newsgroup-articles)
7258       (when (funcall gnus-newsgroup-display)
7259         (push number articles)))
7260     (gnus-summary-limit articles))
7261   (gnus-summary-position-point))
7262
7263 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7264 (make-obsolete
7265  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7266
7267 (defun gnus-summary-limit-to-unread (&optional all)
7268   "Limit the summary buffer to articles that are not marked as read.
7269 If ALL is non-nil, limit strictly to unread articles."
7270   (interactive "P")
7271   (if all
7272       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7273     (gnus-summary-limit-to-marks
7274      ;; Concat all the marks that say that an article is read and have
7275      ;; those removed.
7276      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7277            gnus-killed-mark gnus-kill-file-mark
7278            gnus-low-score-mark gnus-expirable-mark
7279            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7280            gnus-duplicate-mark gnus-souped-mark)
7281      'reverse)))
7282
7283 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7284 (make-obsolete 'gnus-summary-delete-marked-with
7285                'gnus-summary-limit-exlude-marks)
7286
7287 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7288   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7289 If REVERSE, limit the summary buffer to articles that are marked
7290 with MARKS.  MARKS can either be a string of marks or a list of marks.
7291 Returns how many articles were removed."
7292   (interactive "sMarks: ")
7293   (gnus-summary-limit-to-marks marks t))
7294
7295 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7296   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7297 If REVERSE (the prefix), limit the summary buffer to articles that are
7298 not marked with MARKS.  MARKS can either be a string of marks or a
7299 list of marks.
7300 Returns how many articles were removed."
7301   (interactive "sMarks: \nP")
7302   (prog1
7303       (let ((data gnus-newsgroup-data)
7304             (marks (if (listp marks) marks
7305                      (append marks nil))) ; Transform to list.
7306             articles)
7307         (while data
7308           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7309                   (memq (gnus-data-mark (car data)) marks))
7310             (push (gnus-data-number (car data)) articles))
7311           (setq data (cdr data)))
7312         (gnus-summary-limit articles))
7313     (gnus-summary-position-point)))
7314
7315 (defun gnus-summary-limit-to-score (score)
7316   "Limit to articles with score at or above SCORE."
7317   (interactive "NLimit to articles with score of at least: ")
7318   (let ((data gnus-newsgroup-data)
7319         articles)
7320     (while data
7321       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7322                 score)
7323         (push (gnus-data-number (car data)) articles))
7324       (setq data (cdr data)))
7325     (prog1
7326         (gnus-summary-limit articles)
7327       (gnus-summary-position-point))))
7328
7329 (defun gnus-summary-limit-include-thread (id)
7330   "Display all the hidden articles that is in the thread with ID in it.
7331 When called interactively, ID is the Message-ID of the current
7332 article."
7333   (interactive (list (mail-header-id (gnus-summary-article-header))))
7334   (let ((articles (gnus-articles-in-thread
7335                    (gnus-id-to-thread (gnus-root-id id)))))
7336     (prog1
7337         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7338       (gnus-summary-limit-include-matching-articles
7339        "subject"
7340        (regexp-quote (gnus-simplify-subject-re
7341                       (mail-header-subject (gnus-id-to-header id)))))
7342       (gnus-summary-position-point))))
7343
7344 (defun gnus-summary-limit-include-matching-articles (header regexp)
7345   "Display all the hidden articles that have HEADERs that match REGEXP."
7346   (interactive (list (read-string "Match on header: ")
7347                      (read-string "Regexp: ")))
7348   (let ((articles (gnus-find-matching-articles header regexp)))
7349     (prog1
7350         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7351       (gnus-summary-position-point))))
7352
7353 (defun gnus-summary-limit-include-dormant ()
7354   "Display all the hidden articles that are marked as dormant.
7355 Note that this command only works on a subset of the articles currently
7356 fetched for this group."
7357   (interactive)
7358   (unless gnus-newsgroup-dormant
7359     (error "There are no dormant articles in this group"))
7360   (prog1
7361       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7362     (gnus-summary-position-point)))
7363
7364 (defun gnus-summary-limit-exclude-dormant ()
7365   "Hide all dormant articles."
7366   (interactive)
7367   (prog1
7368       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7369     (gnus-summary-position-point)))
7370
7371 (defun gnus-summary-limit-exclude-childless-dormant ()
7372   "Hide all dormant articles that have no children."
7373   (interactive)
7374   (let ((data (gnus-data-list t))
7375         articles d children)
7376     ;; Find all articles that are either not dormant or have
7377     ;; children.
7378     (while (setq d (pop data))
7379       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7380                 (and (setq children
7381                            (gnus-article-children (gnus-data-number d)))
7382                      (let (found)
7383                        (while children
7384                          (when (memq (car children) articles)
7385                            (setq children nil
7386                                  found t))
7387                          (pop children))
7388                        found)))
7389         (push (gnus-data-number d) articles)))
7390     ;; Do the limiting.
7391     (prog1
7392         (gnus-summary-limit articles)
7393       (gnus-summary-position-point))))
7394
7395 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7396   "Mark all unread excluded articles as read.
7397 If ALL, mark even excluded ticked and dormants as read."
7398   (interactive "P")
7399   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7400   (let ((articles (gnus-sorted-ndifference
7401                    (sort
7402                     (mapcar (lambda (h) (mail-header-number h))
7403                             gnus-newsgroup-headers)
7404                     '<)
7405                    gnus-newsgroup-limit))
7406         article)
7407     (setq gnus-newsgroup-unreads
7408           (gnus-sorted-intersection gnus-newsgroup-unreads
7409                                     gnus-newsgroup-limit))
7410     (if all
7411         (setq gnus-newsgroup-dormant nil
7412               gnus-newsgroup-marked nil
7413               gnus-newsgroup-reads
7414               (nconc
7415                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7416                gnus-newsgroup-reads))
7417       (while (setq article (pop articles))
7418         (unless (or (memq article gnus-newsgroup-dormant)
7419                     (memq article gnus-newsgroup-marked))
7420           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7421
7422 (defun gnus-summary-limit (articles &optional pop)
7423   (if pop
7424       ;; We pop the previous limit off the stack and use that.
7425       (setq articles (car gnus-newsgroup-limits)
7426             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7427     ;; We use the new limit, so we push the old limit on the stack.
7428     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7429   ;; Set the limit.
7430   (setq gnus-newsgroup-limit articles)
7431   (let ((total (length gnus-newsgroup-data))
7432         (data (gnus-data-find-list (gnus-summary-article-number)))
7433         (gnus-summary-mark-below nil)   ; Inhibit this.
7434         found)
7435     ;; This will do all the work of generating the new summary buffer
7436     ;; according to the new limit.
7437     (gnus-summary-prepare)
7438     ;; Hide any threads, possibly.
7439     (gnus-summary-maybe-hide-threads)
7440     ;; Try to return to the article you were at, or one in the
7441     ;; neighborhood.
7442     (when data
7443       ;; We try to find some article after the current one.
7444       (while data
7445         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7446           (setq data nil
7447                 found t))
7448         (setq data (cdr data))))
7449     (unless found
7450       ;; If there is no data, that means that we were after the last
7451       ;; article.  The same goes when we can't find any articles
7452       ;; after the current one.
7453       (goto-char (point-max))
7454       (gnus-summary-find-prev))
7455     (gnus-set-mode-line 'summary)
7456     ;; We return how many articles were removed from the summary
7457     ;; buffer as a result of the new limit.
7458     (- total (length gnus-newsgroup-data))))
7459
7460 (defsubst gnus-invisible-cut-children (threads)
7461   (let ((num 0))
7462     (while threads
7463       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7464         (incf num))
7465       (pop threads))
7466     (< num 2)))
7467
7468 (defsubst gnus-cut-thread (thread)
7469   "Go forwards in the thread until we find an article that we want to display."
7470   (when (or (eq gnus-fetch-old-headers 'some)
7471             (eq gnus-fetch-old-headers 'invisible)
7472             (numberp gnus-fetch-old-headers)
7473             (eq gnus-build-sparse-threads 'some)
7474             (eq gnus-build-sparse-threads 'more))
7475     ;; Deal with old-fetched headers and sparse threads.
7476     (while (and
7477             thread
7478             (or
7479              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7480              (gnus-summary-article-ancient-p
7481               (mail-header-number (car thread))))
7482             (if (or (<= (length (cdr thread)) 1)
7483                     (eq gnus-fetch-old-headers 'invisible))
7484                 (setq gnus-newsgroup-limit
7485                       (delq (mail-header-number (car thread))
7486                             gnus-newsgroup-limit)
7487                       thread (cadr thread))
7488               (when (gnus-invisible-cut-children (cdr thread))
7489                 (let ((th (cdr thread)))
7490                   (while th
7491                     (if (memq (mail-header-number (caar th))
7492                               gnus-newsgroup-limit)
7493                         (setq thread (car th)
7494                               th nil)
7495                       (setq th (cdr th))))))))))
7496   thread)
7497
7498 (defun gnus-cut-threads (threads)
7499   "Cut off all uninteresting articles from the beginning of threads."
7500   (when (or (eq gnus-fetch-old-headers 'some)
7501             (eq gnus-fetch-old-headers 'invisible)
7502             (numberp gnus-fetch-old-headers)
7503             (eq gnus-build-sparse-threads 'some)
7504             (eq gnus-build-sparse-threads 'more))
7505     (let ((th threads))
7506       (while th
7507         (setcar th (gnus-cut-thread (car th)))
7508         (setq th (cdr th)))))
7509   ;; Remove nixed out threads.
7510   (delq nil threads))
7511
7512 (defun gnus-summary-initial-limit (&optional show-if-empty)
7513   "Figure out what the initial limit is supposed to be on group entry.
7514 This entails weeding out unwanted dormants, low-scored articles,
7515 fetch-old-headers verbiage, and so on."
7516   ;; Most groups have nothing to remove.
7517   (if (or gnus-inhibit-limiting
7518           (and (null gnus-newsgroup-dormant)
7519                (eq gnus-newsgroup-display 'gnus-not-ignore)
7520                (not (eq gnus-fetch-old-headers 'some))
7521                (not (numberp gnus-fetch-old-headers))
7522                (not (eq gnus-fetch-old-headers 'invisible))
7523                (null gnus-summary-expunge-below)
7524                (not (eq gnus-build-sparse-threads 'some))
7525                (not (eq gnus-build-sparse-threads 'more))
7526                (null gnus-thread-expunge-below)
7527                (not gnus-use-nocem)))
7528       ()                                ; Do nothing.
7529     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7530     (setq gnus-newsgroup-limit nil)
7531     (mapatoms
7532      (lambda (node)
7533        (unless (car (symbol-value node))
7534          ;; These threads have no parents -- they are roots.
7535          (let ((nodes (cdr (symbol-value node)))
7536                thread)
7537            (while nodes
7538              (if (and gnus-thread-expunge-below
7539                       (< (gnus-thread-total-score (car nodes))
7540                          gnus-thread-expunge-below))
7541                  (gnus-expunge-thread (pop nodes))
7542                (setq thread (pop nodes))
7543                (gnus-summary-limit-children thread))))))
7544      gnus-newsgroup-dependencies)
7545     ;; If this limitation resulted in an empty group, we might
7546     ;; pop the previous limit and use it instead.
7547     (when (and (not gnus-newsgroup-limit)
7548                show-if-empty)
7549       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7550     gnus-newsgroup-limit))
7551
7552 (defun gnus-summary-limit-children (thread)
7553   "Return 1 if this subthread is visible and 0 if it is not."
7554   ;; First we get the number of visible children to this thread.  This
7555   ;; is done by recursing down the thread using this function, so this
7556   ;; will really go down to a leaf article first, before slowly
7557   ;; working its way up towards the root.
7558   (when thread
7559     (let ((children
7560            (if (cdr thread)
7561                (apply '+ (mapcar 'gnus-summary-limit-children
7562                                  (cdr thread)))
7563              0))
7564           (number (mail-header-number (car thread)))
7565           score)
7566       (if (and
7567            (not (memq number gnus-newsgroup-marked))
7568            (or
7569             ;; If this article is dormant and has absolutely no visible
7570             ;; children, then this article isn't visible.
7571             (and (memq number gnus-newsgroup-dormant)
7572                  (zerop children))
7573             ;; If this is "fetch-old-headered" and there is no
7574             ;; visible children, then we don't want this article.
7575             (and (or (eq gnus-fetch-old-headers 'some)
7576                      (numberp gnus-fetch-old-headers))
7577                  (gnus-summary-article-ancient-p number)
7578                  (zerop children))
7579             ;; If this is "fetch-old-headered" and `invisible', then
7580             ;; we don't want this article.
7581             (and (eq gnus-fetch-old-headers 'invisible)
7582                  (gnus-summary-article-ancient-p number))
7583             ;; If this is a sparsely inserted article with no children,
7584             ;; we don't want it.
7585             (and (eq gnus-build-sparse-threads 'some)
7586                  (gnus-summary-article-sparse-p number)
7587                  (zerop children))
7588             ;; If we use expunging, and this article is really
7589             ;; low-scored, then we don't want this article.
7590             (when (and gnus-summary-expunge-below
7591                        (< (setq score
7592                                 (or (cdr (assq number gnus-newsgroup-scored))
7593                                     gnus-summary-default-score))
7594                           gnus-summary-expunge-below))
7595               ;; We increase the expunge-tally here, but that has
7596               ;; nothing to do with the limits, really.
7597               (incf gnus-newsgroup-expunged-tally)
7598               ;; We also mark as read here, if that's wanted.
7599               (when (and gnus-summary-mark-below
7600                          (< score gnus-summary-mark-below))
7601                 (setq gnus-newsgroup-unreads
7602                       (delq number gnus-newsgroup-unreads))
7603                 (if gnus-newsgroup-auto-expire
7604                     (push number gnus-newsgroup-expirable)
7605                   (push (cons number gnus-low-score-mark)
7606                         gnus-newsgroup-reads)))
7607               t)
7608             ;; Do the `display' group parameter.
7609             (and gnus-newsgroup-display
7610                  (not (funcall gnus-newsgroup-display)))
7611             ;; Check NoCeM things.
7612             (if (and gnus-use-nocem
7613                      (gnus-nocem-unwanted-article-p
7614                       (mail-header-id (car thread))))
7615                 (progn
7616                   (setq gnus-newsgroup-unreads
7617                         (delq number gnus-newsgroup-unreads))
7618                   t))))
7619           ;; Nope, invisible article.
7620           0
7621         ;; Ok, this article is to be visible, so we add it to the limit
7622         ;; and return 1.
7623         (push number gnus-newsgroup-limit)
7624         1))))
7625
7626 (defun gnus-expunge-thread (thread)
7627   "Mark all articles in THREAD as read."
7628   (let* ((number (mail-header-number (car thread))))
7629     (incf gnus-newsgroup-expunged-tally)
7630     ;; We also mark as read here, if that's wanted.
7631     (setq gnus-newsgroup-unreads
7632           (delq number gnus-newsgroup-unreads))
7633     (if gnus-newsgroup-auto-expire
7634         (push number gnus-newsgroup-expirable)
7635       (push (cons number gnus-low-score-mark)
7636             gnus-newsgroup-reads)))
7637   ;; Go recursively through all subthreads.
7638   (mapcar 'gnus-expunge-thread (cdr thread)))
7639
7640 ;; Summary article oriented commands
7641
7642 (defun gnus-summary-refer-parent-article (n)
7643   "Refer parent article N times.
7644 If N is negative, go to ancestor -N instead.
7645 The difference between N and the number of articles fetched is returned."
7646   (interactive "p")
7647   (let ((skip 1)
7648         error header ref)
7649     (when (not (natnump n))
7650       (setq skip (abs n)
7651             n 1))
7652     (while (and (> n 0)
7653                 (not error))
7654       (setq header (gnus-summary-article-header))
7655       (if (and (eq (mail-header-number header)
7656                    (cdr gnus-article-current))
7657                (equal gnus-newsgroup-name
7658                       (car gnus-article-current)))
7659           ;; If we try to find the parent of the currently
7660           ;; displayed article, then we take a look at the actual
7661           ;; References header, since this is slightly more
7662           ;; reliable than the References field we got from the
7663           ;; server.
7664           (save-excursion
7665             (set-buffer gnus-original-article-buffer)
7666             (nnheader-narrow-to-headers)
7667             (unless (setq ref (message-fetch-field "references"))
7668               (setq ref (message-fetch-field "in-reply-to")))
7669             (widen))
7670         (setq ref
7671               ;; It's not the current article, so we take a bet on
7672               ;; the value we got from the server.
7673               (mail-header-references header)))
7674       (if (and ref
7675                (not (equal ref "")))
7676           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7677             (gnus-message 1 "Couldn't find parent"))
7678         (gnus-message 1 "No references in article %d"
7679                       (gnus-summary-article-number))
7680         (setq error t))
7681       (decf n))
7682     (gnus-summary-position-point)
7683     n))
7684
7685 (defun gnus-summary-refer-references ()
7686   "Fetch all articles mentioned in the References header.
7687 Return the number of articles fetched."
7688   (interactive)
7689   (let ((ref (mail-header-references (gnus-summary-article-header)))
7690         (current (gnus-summary-article-number))
7691         (n 0))
7692     (if (or (not ref)
7693             (equal ref ""))
7694         (error "No References in the current article")
7695       ;; For each Message-ID in the References header...
7696       (while (string-match "<[^>]*>" ref)
7697         (incf n)
7698         ;; ... fetch that article.
7699         (gnus-summary-refer-article
7700          (prog1 (match-string 0 ref)
7701            (setq ref (substring ref (match-end 0))))))
7702       (gnus-summary-goto-subject current)
7703       (gnus-summary-position-point)
7704       n)))
7705
7706 (defun gnus-summary-refer-thread (&optional limit)
7707   "Fetch all articles in the current thread.
7708 If LIMIT (the numerical prefix), fetch that many old headers instead
7709 of what's specified by the `gnus-refer-thread-limit' variable."
7710   (interactive "P")
7711   (let ((id (mail-header-id (gnus-summary-article-header)))
7712         (limit (if limit (prefix-numeric-value limit)
7713                  gnus-refer-thread-limit)))
7714     ;; We want to fetch LIMIT *old* headers, but we also have to
7715     ;; re-fetch all the headers in the current buffer, because many of
7716     ;; them may be undisplayed.  So we adjust LIMIT.
7717     (when (numberp limit)
7718       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7719     (unless (eq gnus-fetch-old-headers 'invisible)
7720       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7721       ;; Retrieve the headers and read them in.
7722       (if (eq (gnus-retrieve-headers
7723                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7724               'nov)
7725           (gnus-build-all-threads)
7726         (error "Can't fetch thread from backends that don't support NOV"))
7727       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7728     (gnus-summary-limit-include-thread id)))
7729
7730 (defun gnus-summary-refer-article (message-id)
7731   "Fetch an article specified by MESSAGE-ID."
7732   (interactive "sMessage-ID: ")
7733   (when (and (stringp message-id)
7734              (not (zerop (length message-id))))
7735     ;; Construct the correct Message-ID if necessary.
7736     ;; Suggested by tale@pawl.rpi.edu.
7737     (unless (string-match "^<" message-id)
7738       (setq message-id (concat "<" message-id)))
7739     (unless (string-match ">$" message-id)
7740       (setq message-id (concat message-id ">")))
7741     (let* ((header (gnus-id-to-header message-id))
7742            (sparse (and header
7743                         (gnus-summary-article-sparse-p
7744                          (mail-header-number header))
7745                         (memq (mail-header-number header)
7746                               gnus-newsgroup-limit)))
7747            number)
7748       (cond
7749        ;; If the article is present in the buffer we just go to it.
7750        ((and header
7751              (or (not (gnus-summary-article-sparse-p
7752                        (mail-header-number header)))
7753                  sparse))
7754         (prog1
7755             (gnus-summary-goto-article
7756              (mail-header-number header) nil t)
7757           (when sparse
7758             (gnus-summary-update-article (mail-header-number header)))))
7759        (t
7760         ;; We fetch the article.
7761         (catch 'found
7762           (dolist (gnus-override-method (gnus-refer-article-methods))
7763             (gnus-check-server gnus-override-method)
7764             ;; Fetch the header, and display the article.
7765             (when (setq number (gnus-summary-insert-subject message-id))
7766               (gnus-summary-select-article nil nil nil number)
7767               (throw 'found t)))
7768           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7769
7770 (defun gnus-refer-article-methods ()
7771   "Return a list of referrable methods."
7772   (cond
7773    ;; No method, so we default to current and native.
7774    ((null gnus-refer-article-method)
7775     (list gnus-current-select-method gnus-select-method))
7776    ;; Current.
7777    ((eq 'current gnus-refer-article-method)
7778     (list gnus-current-select-method))
7779    ;; List of select methods.
7780    ((not (and (symbolp (car gnus-refer-article-method))
7781               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7782     (let (out)
7783       (dolist (method gnus-refer-article-method)
7784         (push (if (eq 'current method)
7785                   gnus-current-select-method
7786                 method)
7787               out))
7788       (nreverse out)))
7789    ;; One single select method.
7790    (t
7791     (list gnus-refer-article-method))))
7792
7793 (defun gnus-summary-edit-parameters ()
7794   "Edit the group parameters of the current group."
7795   (interactive)
7796   (gnus-group-edit-group gnus-newsgroup-name 'params))
7797
7798 (defun gnus-summary-customize-parameters ()
7799   "Customize the group parameters of the current group."
7800   (interactive)
7801   (gnus-group-customize gnus-newsgroup-name))
7802
7803 (defun gnus-summary-enter-digest-group (&optional force)
7804   "Enter an nndoc group based on the current article.
7805 If FORCE, force a digest interpretation.  If not, try
7806 to guess what the document format is."
7807   (interactive "P")
7808   (let ((conf gnus-current-window-configuration))
7809     (save-excursion
7810       (gnus-summary-select-article))
7811     (setq gnus-current-window-configuration conf)
7812     (let* ((name (format "%s-%d"
7813                          (gnus-group-prefixed-name
7814                           gnus-newsgroup-name (list 'nndoc ""))
7815                          (save-excursion
7816                            (set-buffer gnus-summary-buffer)
7817                            gnus-current-article)))
7818            (ogroup gnus-newsgroup-name)
7819            (params (append (gnus-info-params (gnus-get-info ogroup))
7820                            (list (cons 'to-group ogroup))
7821                            (list (cons 'save-article-group ogroup))))
7822            (case-fold-search t)
7823            (buf (current-buffer))
7824            dig to-address)
7825       (save-excursion
7826         (set-buffer gnus-original-article-buffer)
7827         ;; Have the digest group inherit the main mail address of
7828         ;; the parent article.
7829         (when (setq to-address (or (message-fetch-field "reply-to")
7830                                    (message-fetch-field "from")))
7831           (setq params (append
7832                         (list (cons 'to-address
7833                                     (funcall gnus-decode-encoded-word-function
7834                                              to-address))))))
7835         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7836         (insert-buffer-substring gnus-original-article-buffer)
7837         ;; Remove lines that may lead nndoc to misinterpret the
7838         ;; document type.
7839         (narrow-to-region
7840          (goto-char (point-min))
7841          (or (search-forward "\n\n" nil t) (point)))
7842         (goto-char (point-min))
7843         (delete-matching-lines "^Path:\\|^From ")
7844         (widen))
7845       (unwind-protect
7846           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7847                     (gnus-newsgroup-ephemeral-ignored-charsets
7848                      gnus-newsgroup-ignored-charsets))
7849                 (gnus-group-read-ephemeral-group
7850                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7851                               (nndoc-article-type
7852                                ,(if force 'mbox 'guess)))
7853                  t nil nil nil
7854                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7855                                                         "ADAPT")))))
7856               ;; Make all postings to this group go to the parent group.
7857               (nconc (gnus-info-params (gnus-get-info name))
7858                      params)
7859             ;; Couldn't select this doc group.
7860             (switch-to-buffer buf)
7861             (gnus-set-global-variables)
7862             (gnus-configure-windows 'summary)
7863             (gnus-message 3 "Article couldn't be entered?"))
7864         (kill-buffer dig)))))
7865
7866 (defun gnus-summary-read-document (n)
7867   "Open a new group based on the current article(s).
7868 This will allow you to read digests and other similar
7869 documents as newsgroups.
7870 Obeys the standard process/prefix convention."
7871   (interactive "P")
7872   (let* ((articles (gnus-summary-work-articles n))
7873          (ogroup gnus-newsgroup-name)
7874          (params (append (gnus-info-params (gnus-get-info ogroup))
7875                          (list (cons 'to-group ogroup))))
7876          article group egroup groups vgroup)
7877     (while (setq article (pop articles))
7878       (setq group (format "%s-%d" gnus-newsgroup-name article))
7879       (gnus-summary-remove-process-mark article)
7880       (when (gnus-summary-display-article article)
7881         (save-excursion
7882           (with-temp-buffer
7883             (insert-buffer-substring gnus-original-article-buffer)
7884             ;; Remove some headers that may lead nndoc to make
7885             ;; the wrong guess.
7886             (message-narrow-to-head)
7887             (goto-char (point-min))
7888             (delete-matching-lines "^\\(Path\\):\\|^From ")
7889             (widen)
7890             (if (setq egroup
7891                       (gnus-group-read-ephemeral-group
7892                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7893                                      (nndoc-article-type guess))
7894                        t nil t))
7895                 (progn
7896                   ;; Make all postings to this group go to the parent group.
7897                   (nconc (gnus-info-params (gnus-get-info egroup))
7898                          params)
7899                   (push egroup groups))
7900               ;; Couldn't select this doc group.
7901               (gnus-error 3 "Article couldn't be entered"))))))
7902     ;; Now we have selected all the documents.
7903     (cond
7904      ((not groups)
7905       (error "None of the articles could be interpreted as documents"))
7906      ((gnus-group-read-ephemeral-group
7907        (setq vgroup (format
7908                      "nnvirtual:%s-%s" gnus-newsgroup-name
7909                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7910        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7911        t
7912        (cons (current-buffer) 'summary)))
7913      (t
7914       (error "Couldn't select virtual nndoc group")))))
7915
7916 (defun gnus-summary-isearch-article (&optional regexp-p)
7917   "Do incremental search forward on the current article.
7918 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7919   (interactive "P")
7920   (let* ((gnus-inhibit-treatment t)
7921          (old (gnus-summary-select-article)))
7922     (gnus-configure-windows 'article)
7923     (gnus-eval-in-buffer-window gnus-article-buffer
7924       (save-restriction
7925         (widen)
7926         (when (eq 'old old)
7927           (gnus-article-show-all-headers))
7928         (goto-char (point-min))
7929         (isearch-forward regexp-p)))))
7930
7931 (defun gnus-summary-search-article-forward (regexp &optional backward)
7932   "Search for an article containing REGEXP forward.
7933 If BACKWARD, search backward instead."
7934   (interactive
7935    (list (read-string
7936           (format "Search article %s (regexp%s): "
7937                   (if current-prefix-arg "backward" "forward")
7938                   (if gnus-last-search-regexp
7939                       (concat ", default " gnus-last-search-regexp)
7940                     "")))
7941          current-prefix-arg))
7942   (if (string-equal regexp "")
7943       (setq regexp (or gnus-last-search-regexp ""))
7944     (setq gnus-last-search-regexp regexp)
7945     (setq gnus-article-before-search gnus-current-article))
7946   ;; Intentionally set gnus-last-article.
7947   (setq gnus-last-article gnus-article-before-search)
7948   (let ((gnus-last-article gnus-last-article))
7949     (if (gnus-summary-search-article regexp backward)
7950         (gnus-summary-show-thread)
7951       (error "Search failed: \"%s\"" regexp))))
7952
7953 (defun gnus-summary-search-article-backward (regexp)
7954   "Search for an article containing REGEXP backward."
7955   (interactive
7956    (list (read-string
7957           (format "Search article backward (regexp%s): "
7958                   (if gnus-last-search-regexp
7959                       (concat ", default " gnus-last-search-regexp)
7960                     "")))))
7961   (gnus-summary-search-article-forward regexp 'backward))
7962
7963 (eval-when-compile
7964   (defmacro gnus-summary-search-article-position-point (regexp backward)
7965     "Dehighlight the last matched text and goto the beginning position."
7966     (` (if (and gnus-summary-search-article-matched-data
7967                 (let ((text (caddr gnus-summary-search-article-matched-data))
7968                       (inhibit-read-only t)
7969                       buffer-read-only)
7970                   (delete-region
7971                    (goto-char (car gnus-summary-search-article-matched-data))
7972                    (cadr gnus-summary-search-article-matched-data))
7973                   (insert text)
7974                   (string-match (, regexp) text)))
7975            (if (, backward) (beginning-of-line) (end-of-line))
7976          (goto-char (if (, backward) (point-max) (point-min))))))
7977
7978   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7979     "Place point where X-Face image is displayed."
7980     (if (featurep 'xemacs)
7981         (` (let ((end (if (search-forward "\n\n" nil t)
7982                           (goto-char (1- (point)))
7983                         (point-min)))
7984                  extent)
7985              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7986              (unless (and (re-search-forward "^From:" end t)
7987                           (setq extent (extent-at (point)))
7988                           (extent-begin-glyph extent))
7989                (goto-char (, opoint)))))
7990       (` (let ((end (if (search-forward "\n\n" nil t)
7991                         (goto-char (1- (point)))
7992                       (point-min)))
7993                (start (or (search-backward "\n\n" nil t) (point-min))))
7994            (goto-char
7995             (or (text-property-any start end 'x-face-image t);; x-face-e21
7996                 (text-property-any start end 'x-face-mule-bitmap-image t)
7997                 (, opoint)))))))
7998
7999   (defmacro gnus-summary-search-article-highlight-matched-text
8000     (backward treated x-face)
8001     "Highlight matched text in the function `gnus-summary-search-article'."
8002     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8003              (end (set-marker (make-marker) (match-end 0)))
8004              (inhibit-read-only t)
8005              buffer-read-only)
8006          (unless treated
8007            (let ((,@
8008                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8009                     (mapcar
8010                      (lambda (item) (setq items (delq item items)))
8011                      '(gnus-treat-buttonize
8012                        gnus-treat-fill-article
8013                        gnus-treat-fill-long-lines
8014                        gnus-treat-emphasize
8015                        gnus-treat-highlight-headers
8016                        gnus-treat-highlight-citation
8017                        gnus-treat-highlight-signature
8018                        gnus-treat-overstrike
8019                        gnus-treat-display-xface
8020                        gnus-treat-buttonize-head
8021                        gnus-treat-decode-article-as-default-mime-charset))
8022                     (static-if (featurep 'xemacs)
8023                         items
8024                       (cons '(x-face-mule-delete-x-face-field
8025                               (quote never))
8026                             items))))
8027                  (gnus-treat-display-xface
8028                   (when (, x-face) gnus-treat-display-xface)))
8029              (gnus-article-prepare-mime-display)))
8030          (goto-char (if (, backward) start end))
8031          (when (, x-face)
8032            (gnus-summary-search-article-highlight-goto-x-face (point)))
8033          (setq gnus-summary-search-article-matched-data
8034                (list start end (buffer-substring start end)))
8035          (unless (eq start end);; matched text has been deleted. :-<
8036            (put-text-property start end 'face
8037                               (or (find-face 'isearch)
8038                                   'secondary-selection))))))
8039   )
8040
8041 (defun gnus-summary-search-article (regexp &optional backward)
8042   "Search for an article containing REGEXP.
8043 Optional argument BACKWARD means do search for backward.
8044 `gnus-select-article-hook' is not called during the search."
8045   ;; We have to require this here to make sure that the following
8046   ;; dynamic binding isn't shadowed by autoloading.
8047   (require 'gnus-async)
8048   (require 'gnus-art)
8049   (let ((gnus-select-article-hook nil)  ;Disable hook.
8050         (gnus-article-prepare-hook nil)
8051         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8052         (gnus-use-article-prefetch nil)
8053         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8054         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8055         (sum (current-buffer))
8056         (found nil)
8057         point treated)
8058     (gnus-save-hidden-threads
8059       (static-if (featurep 'xemacs)
8060           (let ((gnus-inhibit-treatment t))
8061             (setq treated (eq 'old (gnus-summary-select-article)))
8062             (when (and treated
8063                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8064                                  (window-live-p (get-buffer-window
8065                                                  gnus-article-buffer t)))))
8066               (gnus-summary-select-article nil t)
8067               (setq treated nil)))
8068         (let ((gnus-inhibit-treatment t)
8069               (x-face-mule-delete-x-face-field 'never))
8070           (setq treated (eq 'old (gnus-summary-select-article)))
8071           (when (and treated
8072                      (not
8073                       (and (gnus-buffer-live-p gnus-article-buffer)
8074                            (window-live-p (get-buffer-window
8075                                            gnus-article-buffer t))
8076                            (or (not (string-match "^\\^X-Face:" regexp))
8077                                (with-current-buffer gnus-article-buffer
8078                                  gnus-summary-search-article-matched-data)))))
8079             (gnus-summary-select-article nil t)
8080             (setq treated nil))))
8081       (set-buffer gnus-article-buffer)
8082       (widen)
8083       (if treated
8084           (progn
8085             (gnus-article-show-all-headers)
8086             (gnus-summary-search-article-position-point regexp backward))
8087         (goto-char (if backward (point-max) (point-min))))
8088       (while (not found)
8089         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8090         (if (if backward
8091                 (re-search-backward regexp nil t)
8092               (re-search-forward regexp nil t))
8093             ;; We found the regexp.
8094             (progn
8095               (gnus-summary-search-article-highlight-matched-text
8096                backward treated (string-match "^\\^X-Face:" regexp))
8097               (setq found 'found)
8098               (forward-line
8099                (/ (- 2 (window-height
8100                         (get-buffer-window gnus-article-buffer t)))
8101                   2))
8102               (set-window-start
8103                (get-buffer-window (current-buffer))
8104                (point))
8105               (set-buffer sum)
8106               (setq point (point)))
8107           ;; We didn't find it, so we go to the next article.
8108           (set-buffer sum)
8109           (setq found 'not)
8110           (while (eq found 'not)
8111             (if (not (if backward (gnus-summary-find-prev)
8112                        (gnus-summary-find-next)))
8113                 ;; No more articles.
8114                 (setq found t)
8115               ;; Select the next article and adjust point.
8116               (unless (gnus-summary-article-sparse-p
8117                        (gnus-summary-article-number))
8118                 (setq found nil)
8119                 (let ((gnus-inhibit-treatment t))
8120                   (gnus-summary-select-article))
8121                 (setq treated nil)
8122                 (set-buffer gnus-article-buffer)
8123                 (widen)
8124                 (goto-char (if backward (point-max) (point-min))))))))
8125       (gnus-message 7 ""))
8126     ;; Return whether we found the regexp.
8127     (when (eq found 'found)
8128       (goto-char point)
8129       (gnus-summary-show-thread)
8130       (gnus-summary-goto-subject gnus-current-article)
8131       (gnus-summary-position-point)
8132       t)))
8133
8134 (defun gnus-find-matching-articles (header regexp)
8135   "Return a list of all articles that match REGEXP on HEADER.
8136 This search includes all articles in the current group that Gnus has
8137 fetched headers for, whether they are displayed or not."
8138   (let ((articles nil)
8139         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8140         (case-fold-search t))
8141     (dolist (header gnus-newsgroup-headers)
8142       (when (string-match regexp (funcall func header))
8143         (push (mail-header-number header) articles)))
8144     (nreverse articles)))
8145
8146 (defun gnus-summary-find-matching (header regexp &optional backward unread
8147                                           not-case-fold not-matching)
8148   "Return a list of all articles that match REGEXP on HEADER.
8149 The search stars on the current article and goes forwards unless
8150 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8151 If UNREAD is non-nil, only unread articles will
8152 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8153 in the comparisons. If NOT-MATCHING, return a list of all articles that
8154 not match REGEXP on HEADER."
8155   (let ((case-fold-search (not not-case-fold))
8156         articles d func)
8157     (if (consp header)
8158         (if (eq (car header) 'extra)
8159             (setq func
8160                   `(lambda (h)
8161                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8162                          "")))
8163           (error "%s is an invalid header" header))
8164       (unless (fboundp (intern (concat "mail-header-" header)))
8165         (error "%s is not a valid header" header))
8166       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8167     (dolist (d (if (eq backward 'all)
8168                    gnus-newsgroup-data
8169                  (gnus-data-find-list
8170                   (gnus-summary-article-number)
8171                   (gnus-data-list backward))))
8172       (when (and (or (not unread)       ; We want all articles...
8173                      (gnus-data-unread-p d)) ; Or just unreads.
8174                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8175                  (if not-matching
8176                      (not (string-match
8177                            regexp
8178                            (funcall func (gnus-data-header d))))
8179                    (string-match regexp
8180                                  (funcall func (gnus-data-header d)))))
8181         (push (gnus-data-number d) articles))) ; Success!
8182     (nreverse articles)))
8183
8184 (defun gnus-summary-execute-command (header regexp command &optional backward)
8185   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8186 If HEADER is an empty string (or nil), the match is done on the entire
8187 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8188   (interactive
8189    (list (let ((completion-ignore-case t))
8190            (completing-read
8191             "Header name: "
8192             (mapcar (lambda (header) (list (format "%s" header)))
8193                     (append
8194                      '("Number" "Subject" "From" "Lines" "Date"
8195                        "Message-ID" "Xref" "References" "Body")
8196                      gnus-extra-headers))
8197             nil 'require-match))
8198          (read-string "Regexp: ")
8199          (read-key-sequence "Command: ")
8200          current-prefix-arg))
8201   (when (equal header "Body")
8202     (setq header ""))
8203   ;; Hidden thread subtrees must be searched as well.
8204   (gnus-summary-show-all-threads)
8205   ;; We don't want to change current point nor window configuration.
8206   (save-excursion
8207     (save-window-excursion
8208       (gnus-message 6 "Executing %s..." (key-description command))
8209       ;; We'd like to execute COMMAND interactively so as to give arguments.
8210       (gnus-execute header regexp
8211                     `(call-interactively ',(key-binding command))
8212                     backward)
8213       (gnus-message 6 "Executing %s...done" (key-description command)))))
8214
8215 (defun gnus-summary-beginning-of-article ()
8216   "Scroll the article back to the beginning."
8217   (interactive)
8218   (gnus-summary-select-article)
8219   (gnus-configure-windows 'article)
8220   (gnus-eval-in-buffer-window gnus-article-buffer
8221     (widen)
8222     (goto-char (point-min))
8223     (when gnus-page-broken
8224       (gnus-narrow-to-page))))
8225
8226 (defun gnus-summary-end-of-article ()
8227   "Scroll to the end of the article."
8228   (interactive)
8229   (gnus-summary-select-article)
8230   (gnus-configure-windows 'article)
8231   (gnus-eval-in-buffer-window gnus-article-buffer
8232     (widen)
8233     (goto-char (point-max))
8234     (recenter -3)
8235     (when gnus-page-broken
8236       (gnus-narrow-to-page))))
8237
8238 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8239   "Truncate to LEN and quote all \"(\"'s in STRING."
8240   (gnus-replace-in-string (if (and len (> (length string) len))
8241                               (substring string 0 len)
8242                             string)
8243                           "[()]" "\\\\\\&"))
8244
8245 (defun gnus-summary-print-article (&optional filename n)
8246   "Generate and print a PostScript image of the N next (mail) articles.
8247
8248 If N is negative, print the N previous articles.  If N is nil and articles
8249 have been marked with the process mark, print these instead.
8250
8251 If the optional first argument FILENAME is nil, send the image to the
8252 printer.  If FILENAME is a string, save the PostScript image in a file with
8253 that name.  If FILENAME is a number, prompt the user for the name of the file
8254 to save in."
8255   (interactive (list (ps-print-preprint current-prefix-arg)))
8256   (dolist (article (gnus-summary-work-articles n))
8257     (gnus-summary-select-article nil nil 'pseudo article)
8258     (gnus-eval-in-buffer-window gnus-article-buffer
8259       (gnus-print-buffer))
8260     (gnus-summary-remove-process-mark article))
8261   (ps-despool filename))
8262
8263 (defun gnus-print-buffer ()
8264   (let ((buffer (generate-new-buffer " *print*")))
8265     (unwind-protect
8266         (progn
8267           (copy-to-buffer buffer (point-min) (point-max))
8268           (set-buffer buffer)
8269           (gnus-article-delete-invisible-text)
8270           (gnus-remove-text-with-property 'gnus-decoration)
8271           (when (gnus-visual-p 'article-highlight 'highlight)
8272             ;; Copy-to-buffer doesn't copy overlay.  So redo
8273             ;; highlight.
8274             (let ((gnus-article-buffer buffer))
8275               (gnus-article-highlight-citation t)
8276               (gnus-article-highlight-signature)))
8277           (let ((ps-left-header
8278                  (list
8279                   (concat "("
8280                           (gnus-summary-print-truncate-and-quote
8281                            (mail-header-subject gnus-current-headers)
8282                            66) ")")
8283                   (concat "("
8284                           (gnus-summary-print-truncate-and-quote
8285                            (mail-header-from gnus-current-headers)
8286                            45) ")")))
8287                 (ps-right-header
8288                  (list
8289                   "/pagenumberstring load"
8290                   (concat "("
8291                           (mail-header-date gnus-current-headers) ")"))))
8292             (gnus-run-hooks 'gnus-ps-print-hook)
8293             (save-excursion
8294               (if window-system
8295                   (ps-spool-buffer-with-faces)
8296                 (ps-spool-buffer)))))
8297       (kill-buffer buffer))))
8298
8299 (defun gnus-summary-show-article (&optional arg)
8300   "Force redisplaying of the current article.
8301 If ARG (the prefix) is a number, show the article with the charset
8302 defined in `gnus-summary-show-article-charset-alist', or the charset
8303 input.
8304 If ARG (the prefix) is non-nil and not a number, show the raw article
8305 without any article massaging functions being run.  Normally, the key strokes
8306 are `C-u g'."
8307   (interactive "P")
8308   (cond
8309    ((numberp arg)
8310     (gnus-summary-show-article t)
8311     (let* ((gnus-newsgroup-charset
8312             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8313                 (mm-read-coding-system
8314                  "View as charset: " ;; actually it is coding system.
8315                  (save-excursion
8316                    (set-buffer gnus-article-buffer)
8317                    (mm-detect-coding-region (point) (point-max))))))
8318            (default-mime-charset gnus-newsgroup-charset)
8319            (gnus-newsgroup-ignored-charsets 'gnus-all))
8320       (gnus-summary-select-article nil 'force)
8321       (let ((deps gnus-newsgroup-dependencies)
8322             head header lines)
8323         (save-excursion
8324           (set-buffer gnus-original-article-buffer)
8325           (save-restriction
8326             (message-narrow-to-head)
8327             (setq head (buffer-string))
8328             (goto-char (point-min))
8329             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8330               (goto-char (point-max))
8331               (widen)
8332               (setq lines (1- (count-lines (point) (point-max))))))
8333           (with-temp-buffer
8334             (insert (format "211 %d Article retrieved.\n"
8335                             (cdr gnus-article-current)))
8336             (insert head)
8337             (if lines (insert (format "Lines: %d\n" lines)))
8338             (insert ".\n")
8339             (let ((nntp-server-buffer (current-buffer)))
8340               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8341         (gnus-data-set-header
8342          (gnus-data-find (cdr gnus-article-current))
8343          header)
8344         (gnus-summary-update-article-line
8345          (cdr gnus-article-current) header)
8346         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8347           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8348    ((not arg)
8349     ;; Select the article the normal way.
8350     (gnus-summary-select-article nil 'force))
8351    (t
8352     ;; We have to require this here to make sure that the following
8353     ;; dynamic binding isn't shadowed by autoloading.
8354     (require 'gnus-async)
8355     (require 'gnus-art)
8356     ;; Bind the article treatment functions to nil.
8357     (let ((gnus-have-all-headers t)
8358           gnus-article-prepare-hook
8359           gnus-article-decode-hook
8360           gnus-break-pages
8361           gnus-show-mime
8362           (gnus-inhibit-treatment t))
8363       (gnus-summary-select-article nil 'force))))
8364   (gnus-summary-goto-subject gnus-current-article)
8365   (gnus-summary-position-point))
8366
8367 (defun gnus-summary-show-raw-article ()
8368   "Show the raw article without any article massaging functions being run."
8369   (interactive)
8370   (gnus-summary-show-article t))
8371
8372 (defun gnus-summary-verbose-headers (&optional arg)
8373   "Toggle permanent full header display.
8374 If ARG is a positive number, turn header display on.
8375 If ARG is a negative number, turn header display off."
8376   (interactive "P")
8377   (setq gnus-show-all-headers
8378         (cond ((or (not (numberp arg))
8379                    (zerop arg))
8380                (not gnus-show-all-headers))
8381               ((natnump arg)
8382                t)))
8383   (gnus-summary-show-article))
8384
8385 (defun gnus-summary-toggle-header (&optional arg)
8386   "Show the headers if they are hidden, or hide them if they are shown.
8387 If ARG is a positive number, show the entire header.
8388 If ARG is a negative number, hide the unwanted header lines."
8389   (interactive "P")
8390   (save-excursion
8391     (set-buffer gnus-article-buffer)
8392     (save-restriction
8393       (let* ((buffer-read-only nil)
8394              (inhibit-point-motion-hooks t)
8395              hidden e)
8396         (save-restriction
8397           (article-narrow-to-head)
8398           (setq e (point-max)
8399                 hidden (if (numberp arg)
8400                            (>= arg 0)
8401                          (gnus-article-hidden-text-p 'headers))))
8402         (delete-region (point-min) e)
8403         (goto-char (point-min))
8404         (save-excursion
8405           (set-buffer gnus-original-article-buffer)
8406           (goto-char (point-min))
8407           (setq e (search-forward "\n\n" nil t)
8408                 e (if e (1- e) (point-max))))
8409         (insert-buffer-substring gnus-original-article-buffer 1 e)
8410         (save-restriction
8411           (narrow-to-region (point-min) (point))
8412           (article-decode-encoded-words)
8413           (if  hidden
8414               (let ((gnus-treat-hide-headers nil)
8415                     (gnus-treat-hide-boring-headers nil))
8416                 (gnus-delete-wash-type 'headers)
8417                 (gnus-treat-article 'head))
8418             (gnus-treat-article 'head)))
8419         (gnus-set-mode-line 'article)))))
8420
8421 (defun gnus-summary-show-all-headers ()
8422   "Make all header lines visible."
8423   (interactive)
8424   (gnus-summary-toggle-header 1))
8425
8426 (defun gnus-summary-toggle-mime (&optional arg)
8427   "Toggle MIME processing.
8428 If ARG is a positive number, turn MIME processing on."
8429   (interactive "P")
8430   (setq gnus-show-mime
8431         (if (null arg)
8432             (not gnus-show-mime)
8433           (> (prefix-numeric-value arg) 0)))
8434   (gnus-summary-select-article t 'force))
8435
8436 (defun gnus-summary-caesar-message (&optional arg)
8437   "Caesar rotate the current article by 13.
8438 The numerical prefix specifies how many places to rotate each letter
8439 forward."
8440   (interactive "P")
8441   (gnus-summary-select-article)
8442   (let ((mail-header-separator ""))
8443     (gnus-eval-in-buffer-window gnus-article-buffer
8444       (save-restriction
8445         (widen)
8446         (let ((start (window-start))
8447               buffer-read-only)
8448           (message-caesar-buffer-body arg)
8449           (set-window-start (get-buffer-window (current-buffer)) start))))))
8450
8451 (defun gnus-summary-stop-page-breaking ()
8452   "Stop page breaking in the current article."
8453   (interactive)
8454   (gnus-summary-select-article)
8455   (gnus-eval-in-buffer-window gnus-article-buffer
8456     (widen)
8457     (when (gnus-visual-p 'page-marker)
8458       (let ((buffer-read-only nil))
8459         (gnus-remove-text-with-property 'gnus-prev)
8460         (gnus-remove-text-with-property 'gnus-next))
8461       (setq gnus-page-broken nil))))
8462
8463 (defun gnus-summary-move-article (&optional n to-newsgroup
8464                                             select-method action)
8465   "Move the current article to a different newsgroup.
8466 If N is a positive number, move the N next articles.
8467 If N is a negative number, move the N previous articles.
8468 If N is nil and any articles have been marked with the process mark,
8469 move those articles instead.
8470 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8471 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8472 re-spool using this method.
8473
8474 For this function to work, both the current newsgroup and the
8475 newsgroup that you want to move to have to support the `request-move'
8476 and `request-accept' functions.
8477
8478 ACTION can be either `move' (the default), `crosspost' or `copy'."
8479   (interactive "P")
8480   (unless action
8481     (setq action 'move))
8482   ;; Check whether the source group supports the required functions.
8483   (cond ((and (eq action 'move)
8484               (not (gnus-check-backend-function
8485                     'request-move-article gnus-newsgroup-name)))
8486          (error "The current group does not support article moving"))
8487         ((and (eq action 'crosspost)
8488               (not (gnus-check-backend-function
8489                     'request-replace-article gnus-newsgroup-name)))
8490          (error "The current group does not support article editing")))
8491   (let ((articles (gnus-summary-work-articles n))
8492         (prefix (if (gnus-check-backend-function
8493                      'request-move-article gnus-newsgroup-name)
8494                     (gnus-group-real-prefix gnus-newsgroup-name)
8495                   ""))
8496         (names '((move "Move" "Moving")
8497                  (copy "Copy" "Copying")
8498                  (crosspost "Crosspost" "Crossposting")))
8499         (copy-buf (save-excursion
8500                     (nnheader-set-temp-buffer " *copy article*")))
8501         (default-marks gnus-article-mark-lists)
8502         (no-expire-marks (delete '(expirable . expire)
8503                                  (copy-sequence gnus-article-mark-lists)))
8504         art-group to-method new-xref article to-groups)
8505     (unless (assq action names)
8506       (error "Unknown action %s" action))
8507     ;; Read the newsgroup name.
8508     (when (and (not to-newsgroup)
8509                (not select-method))
8510       (if (and gnus-move-split-methods
8511                (not
8512                 (and (memq gnus-current-article articles)
8513                      (gnus-buffer-live-p gnus-original-article-buffer))))
8514           ;; When `gnus-move-split-methods' is non-nil, we have to
8515           ;; select an article to give `gnus-read-move-group-name' an
8516           ;; opportunity to suggest an appropriate default.  However,
8517           ;; we needn't render or mark the article.
8518           (let ((gnus-display-mime-function nil)
8519                 (gnus-article-prepare-hook nil)
8520                 (gnus-mark-article-hook nil))
8521             (gnus-summary-select-article nil nil nil (car articles))))
8522       (setq to-newsgroup
8523             (gnus-read-move-group-name
8524              (cadr (assq action names))
8525              (symbol-value (intern (format "gnus-current-%s-group" action)))
8526              articles prefix))
8527       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8528     (setq to-method (or select-method
8529                         (gnus-server-to-method
8530                          (gnus-group-method to-newsgroup))))
8531     ;; Check the method we are to move this article to...
8532     (unless (gnus-check-backend-function
8533              'request-accept-article (car to-method))
8534       (error "%s does not support article copying" (car to-method)))
8535     (unless (gnus-check-server to-method)
8536       (error "Can't open server %s" (car to-method)))
8537     (gnus-message 6 "%s to %s: %s..."
8538                   (caddr (assq action names))
8539                   (or (car select-method) to-newsgroup) articles)
8540     (while articles
8541       (setq article (pop articles))
8542       (setq
8543        art-group
8544        (cond
8545         ;; Move the article.
8546         ((eq action 'move)
8547          ;; Remove this article from future suppression.
8548          (gnus-dup-unsuppress-article article)
8549          (gnus-request-move-article
8550           article                       ; Article to move
8551           gnus-newsgroup-name           ; From newsgroup
8552           (nth 1 (gnus-find-method-for-group
8553                   gnus-newsgroup-name)) ; Server
8554           (list 'gnus-request-accept-article
8555                 to-newsgroup (list 'quote select-method)
8556                 (not articles) t)       ; Accept form
8557           (not articles)))              ; Only save nov last time
8558         ;; Copy the article.
8559         ((eq action 'copy)
8560          (save-excursion
8561            (set-buffer copy-buf)
8562            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8563              (gnus-request-accept-article
8564               to-newsgroup select-method (not articles) t))))
8565         ;; Crosspost the article.
8566         ((eq action 'crosspost)
8567          (let ((xref (message-tokenize-header
8568                       (mail-header-xref (gnus-summary-article-header article))
8569                       " ")))
8570            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8571                                   ":" (number-to-string article)))
8572            (unless xref
8573              (setq xref (list (system-name))))
8574            (setq new-xref
8575                  (concat
8576                   (mapconcat 'identity
8577                              (delete "Xref:" (delete new-xref xref))
8578                              " ")
8579                   " " new-xref))
8580            (save-excursion
8581              (set-buffer copy-buf)
8582              ;; First put the article in the destination group.
8583              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8584              (when (consp (setq art-group
8585                                 (gnus-request-accept-article
8586                                  to-newsgroup select-method (not articles))))
8587                (setq new-xref (concat new-xref " " (car art-group)
8588                                       ":"
8589                                       (number-to-string (cdr art-group))))
8590                ;; Now we have the new Xrefs header, so we insert
8591                ;; it and replace the new article.
8592                (nnheader-replace-header "Xref" new-xref)
8593                (gnus-request-replace-article
8594                 (cdr art-group) to-newsgroup (current-buffer))
8595                art-group))))))
8596       (cond
8597        ((not art-group)
8598         (gnus-message 1 "Couldn't %s article %s: %s"
8599                       (cadr (assq action names)) article
8600                       (nnheader-get-report (car to-method))))
8601        ((eq art-group 'junk)
8602         (when (eq action 'move)
8603           (gnus-summary-mark-article article gnus-canceled-mark)
8604           (gnus-message 4 "Deleted article %s" article)))
8605        (t
8606         (let* ((pto-group (gnus-group-prefixed-name
8607                            (car art-group) to-method))
8608                (entry
8609                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8610                (info (nth 2 entry))
8611                (to-group (gnus-info-group info))
8612                to-marks)
8613           ;; Update the group that has been moved to.
8614           (when (and info
8615                      (memq action '(move copy)))
8616             (unless (member to-group to-groups)
8617               (push to-group to-groups))
8618
8619             (unless (memq article gnus-newsgroup-unreads)
8620               (push 'read to-marks)
8621               (gnus-info-set-read
8622                info (gnus-add-to-range (gnus-info-read info)
8623                                        (list (cdr art-group)))))
8624
8625             ;; See whether the article is to be put in the cache.
8626             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8627                              default-marks
8628                            no-expire-marks))
8629                   (to-article (cdr art-group)))
8630
8631               ;; Enter the article into the cache in the new group,
8632               ;; if that is required.
8633               (when gnus-use-cache
8634                 (gnus-cache-possibly-enter-article
8635                  to-group to-article
8636                  (let ((header (copy-sequence
8637                                 (gnus-summary-article-header article))))
8638                    (mail-header-set-number header to-article)
8639                    header)
8640                  (memq article gnus-newsgroup-marked)
8641                  (memq article gnus-newsgroup-dormant)
8642                  (memq article gnus-newsgroup-unreads)))
8643
8644               (when gnus-preserve-marks
8645                 ;; Copy any marks over to the new group.
8646                 (when (and (equal to-group gnus-newsgroup-name)
8647                            (not (memq article gnus-newsgroup-unreads)))
8648                   ;; Mark this article as read in this group.
8649                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8650                   (setcdr (gnus-active to-group) to-article)
8651                   (setcdr gnus-newsgroup-active to-article))
8652
8653                 (while marks
8654                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8655                     (when (memq article (symbol-value
8656                                          (intern (format "gnus-newsgroup-%s"
8657                                                          (caar marks)))))
8658                       (push (cdar marks) to-marks)
8659                       ;; If the other group is the same as this group,
8660                       ;; then we have to add the mark to the list.
8661                       (when (equal to-group gnus-newsgroup-name)
8662                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8663                              (cons to-article
8664                                    (symbol-value
8665                                     (intern (format "gnus-newsgroup-%s"
8666                                                     (caar marks)))))))
8667                       ;; Copy the marks to other group.
8668                       (gnus-add-marked-articles
8669                        to-group (cdar marks) (list to-article) info)))
8670                   (setq marks (cdr marks)))
8671
8672                 (gnus-request-set-mark to-group (list (list (list to-article)
8673                                                             'add
8674                                                             to-marks))))
8675
8676               (gnus-dribble-enter
8677                (concat "(gnus-group-set-info '"
8678                        (gnus-prin1-to-string (gnus-get-info to-group))
8679                        ")"))))
8680
8681           ;; Update the Xref header in this article to point to
8682           ;; the new crossposted article we have just created.
8683           (when (eq action 'crosspost)
8684             (save-excursion
8685               (set-buffer copy-buf)
8686               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8687               (nnheader-replace-header "Xref" new-xref)
8688               (gnus-request-replace-article
8689                article gnus-newsgroup-name (current-buffer)))))
8690
8691         ;;;!!!Why is this necessary?
8692         (set-buffer gnus-summary-buffer)
8693
8694         (gnus-summary-goto-subject article)
8695         (when (eq action 'move)
8696           (gnus-summary-mark-article article gnus-canceled-mark))))
8697       (gnus-summary-remove-process-mark article))
8698     ;; Re-activate all groups that have been moved to.
8699     (save-excursion
8700       (set-buffer gnus-group-buffer)
8701       (let ((gnus-group-marked to-groups))
8702         (gnus-group-get-new-news-this-group nil t)))
8703
8704     (gnus-kill-buffer copy-buf)
8705     (gnus-summary-position-point)
8706     (gnus-set-mode-line 'summary)))
8707
8708 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8709   "Move the current article to a different newsgroup.
8710 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8711 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8712 re-spool using this method."
8713   (interactive "P")
8714   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8715
8716 (defun gnus-summary-crosspost-article (&optional n)
8717   "Crosspost the current article to some other group."
8718   (interactive "P")
8719   (gnus-summary-move-article n nil nil 'crosspost))
8720
8721 (defcustom gnus-summary-respool-default-method nil
8722   "Default method type for respooling an article.
8723 If nil, use to the current newsgroup method."
8724   :type 'symbol
8725   :group 'gnus-summary-mail)
8726
8727 (defun gnus-summary-respool-article (&optional n method)
8728   "Respool the current article.
8729 The article will be squeezed through the mail spooling process again,
8730 which means that it will be put in some mail newsgroup or other
8731 depending on `nnmail-split-methods'.
8732 If N is a positive number, respool the N next articles.
8733 If N is a negative number, respool the N previous articles.
8734 If N is nil and any articles have been marked with the process mark,
8735 respool those articles instead.
8736
8737 Respooling can be done both from mail groups and \"real\" newsgroups.
8738 In the former case, the articles in question will be moved from the
8739 current group into whatever groups they are destined to.  In the
8740 latter case, they will be copied into the relevant groups."
8741   (interactive
8742    (list current-prefix-arg
8743          (let* ((methods (gnus-methods-using 'respool))
8744                 (methname
8745                  (symbol-name (or gnus-summary-respool-default-method
8746                                   (car (gnus-find-method-for-group
8747                                         gnus-newsgroup-name)))))
8748                 (method
8749                  (gnus-completing-read-with-default
8750                   methname "What backend do you want to use when respooling?"
8751                   methods nil t nil 'gnus-mail-method-history))
8752                 ms)
8753            (cond
8754             ((zerop (length (setq ms (gnus-servers-using-backend
8755                                       (intern method)))))
8756              (list (intern method) ""))
8757             ((= 1 (length ms))
8758              (car ms))
8759             (t
8760              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8761                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8762                            ms-alist))))))))
8763   (unless method
8764     (error "No method given for respooling"))
8765   (if (assoc (symbol-name
8766               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8767              (gnus-methods-using 'respool))
8768       (gnus-summary-move-article n nil method)
8769     (gnus-summary-copy-article n nil method)))
8770
8771 (defun gnus-summary-import-article (file &optional edit)
8772   "Import an arbitrary file into a mail newsgroup."
8773   (interactive "fImport file: \nP")
8774   (let ((group gnus-newsgroup-name)
8775         (now (current-time))
8776         atts lines group-art)
8777     (unless (gnus-check-backend-function 'request-accept-article group)
8778       (error "%s does not support article importing" group))
8779     (or (file-readable-p file)
8780         (not (file-regular-p file))
8781         (error "Can't read %s" file))
8782     (save-excursion
8783       (set-buffer (gnus-get-buffer-create " *import file*"))
8784       (erase-buffer)
8785       (nnheader-insert-file-contents file)
8786       (goto-char (point-min))
8787       (if (nnheader-article-p)
8788           (save-restriction
8789             (goto-char (point-min))
8790             (search-forward "\n\n" nil t)
8791             (narrow-to-region (point-min) (1- (point)))
8792             (goto-char (point-min))
8793             (unless (re-search-forward "^date:" nil t)
8794               (goto-char (point-max))
8795               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8796         ;; This doesn't look like an article, so we fudge some headers.
8797         (setq atts (file-attributes file)
8798               lines (count-lines (point-min) (point-max)))
8799         (insert "From: " (read-string "From: ") "\n"
8800                 "Subject: " (read-string "Subject: ") "\n"
8801                 "Date: " (message-make-date (nth 5 atts)) "\n"
8802                 "Message-ID: " (message-make-message-id) "\n"
8803                 "Lines: " (int-to-string lines) "\n"
8804                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8805       (setq group-art (gnus-request-accept-article group nil t))
8806       (kill-buffer (current-buffer)))
8807     (setq gnus-newsgroup-active (gnus-activate-group group))
8808     (forward-line 1)
8809     (gnus-summary-goto-article (cdr group-art) nil t)
8810     (when edit
8811       (gnus-summary-edit-article))))
8812
8813 (defun gnus-summary-create-article ()
8814   "Create an article in a mail newsgroup."
8815   (interactive)
8816   (let ((group gnus-newsgroup-name)
8817         (now (current-time))
8818         group-art)
8819     (unless (gnus-check-backend-function 'request-accept-article group)
8820       (error "%s does not support article importing" group))
8821     (save-excursion
8822       (set-buffer (gnus-get-buffer-create " *import file*"))
8823       (erase-buffer)
8824       (goto-char (point-min))
8825       ;; This doesn't look like an article, so we fudge some headers.
8826       (insert "From: " (read-string "From: ") "\n"
8827               "Subject: " (read-string "Subject: ") "\n"
8828               "Date: " (message-make-date now) "\n"
8829               "Message-ID: " (message-make-message-id) "\n")
8830       (setq group-art (gnus-request-accept-article group nil t))
8831       (kill-buffer (current-buffer)))
8832     (setq gnus-newsgroup-active (gnus-activate-group group))
8833     (forward-line 1)
8834     (gnus-summary-goto-article (cdr group-art) nil t)
8835     (gnus-summary-edit-article)))
8836
8837 (defun gnus-summary-article-posted-p ()
8838   "Say whether the current (mail) article is available from news as well.
8839 This will be the case if the article has both been mailed and posted."
8840   (interactive)
8841   (let ((id (mail-header-references (gnus-summary-article-header)))
8842         (gnus-override-method (car (gnus-refer-article-methods))))
8843     (if (gnus-request-head id "")
8844         (gnus-message 2 "The current message was found on %s"
8845                       gnus-override-method)
8846       (gnus-message 2 "The current message couldn't be found on %s"
8847                     gnus-override-method)
8848       nil)))
8849
8850 (defun gnus-summary-expire-articles (&optional now)
8851   "Expire all articles that are marked as expirable in the current group."
8852   (interactive)
8853   (when (gnus-check-backend-function
8854          'request-expire-articles gnus-newsgroup-name)
8855     ;; This backend supports expiry.
8856     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8857            (expirable (if total
8858                           (progn
8859                             ;; We need to update the info for
8860                             ;; this group for `gnus-list-of-read-articles'
8861                             ;; to give us the right answer.
8862                             (gnus-run-hooks 'gnus-exit-group-hook)
8863                             (gnus-summary-update-info)
8864                             (gnus-list-of-read-articles gnus-newsgroup-name))
8865                         (setq gnus-newsgroup-expirable
8866                               (sort gnus-newsgroup-expirable '<))))
8867            (expiry-wait (if now 'immediate
8868                           (gnus-group-find-parameter
8869                            gnus-newsgroup-name 'expiry-wait)))
8870            (nnmail-expiry-target
8871             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8872                 nnmail-expiry-target))
8873            es)
8874       (when expirable
8875         ;; There are expirable articles in this group, so we run them
8876         ;; through the expiry process.
8877         (gnus-message 6 "Expiring articles...")
8878         (unless (gnus-check-group gnus-newsgroup-name)
8879           (error "Can't open server for %s" gnus-newsgroup-name))
8880         ;; The list of articles that weren't expired is returned.
8881         (save-excursion
8882           (if expiry-wait
8883               (let ((nnmail-expiry-wait-function nil)
8884                     (nnmail-expiry-wait expiry-wait))
8885                 (setq es (gnus-request-expire-articles
8886                           expirable gnus-newsgroup-name)))
8887             (setq es (gnus-request-expire-articles
8888                       expirable gnus-newsgroup-name)))
8889           (unless total
8890             (setq gnus-newsgroup-expirable es))
8891           ;; We go through the old list of expirable, and mark all
8892           ;; really expired articles as nonexistent.
8893           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8894             (let ((gnus-use-cache nil))
8895               (dolist (article expirable)
8896                 (when (and (not (memq article es))
8897                            (gnus-data-find article))
8898                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8899         (gnus-message 6 "Expiring articles...done")))))
8900
8901 (defun gnus-summary-expire-articles-now ()
8902   "Expunge all expirable articles in the current group.
8903 This means that *all* articles that are marked as expirable will be
8904 deleted forever, right now."
8905   (interactive)
8906   (or gnus-expert-user
8907       (gnus-yes-or-no-p
8908        "Are you really, really, really sure you want to delete all these messages? ")
8909       (error "Phew!"))
8910   (gnus-summary-expire-articles t))
8911
8912 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8913 (defun gnus-summary-delete-article (&optional n)
8914   "Delete the N next (mail) articles.
8915 This command actually deletes articles.  This is not a marking
8916 command.  The article will disappear forever from your life, never to
8917 return.
8918 If N is negative, delete backwards.
8919 If N is nil and articles have been marked with the process mark,
8920 delete these instead."
8921   (interactive "P")
8922   (unless (gnus-check-backend-function 'request-expire-articles
8923                                        gnus-newsgroup-name)
8924     (error "The current newsgroup does not support article deletion"))
8925   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8926     (error "Couldn't open server"))
8927   ;; Compute the list of articles to delete.
8928   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8929         not-deleted)
8930     (if (and gnus-novice-user
8931              (not (gnus-yes-or-no-p
8932                    (format "Do you really want to delete %s forever? "
8933                            (if (> (length articles) 1)
8934                                (format "these %s articles" (length articles))
8935                              "this article")))))
8936         ()
8937       ;; Delete the articles.
8938       (setq not-deleted (gnus-request-expire-articles
8939                          articles gnus-newsgroup-name 'force))
8940       (while articles
8941         (gnus-summary-remove-process-mark (car articles))
8942         ;; The backend might not have been able to delete the article
8943         ;; after all.
8944         (unless (memq (car articles) not-deleted)
8945           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8946         (setq articles (cdr articles)))
8947       (when not-deleted
8948         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8949     (gnus-summary-position-point)
8950     (gnus-set-mode-line 'summary)
8951     not-deleted))
8952
8953 (defun gnus-summary-edit-article (&optional force)
8954   "Edit the current article.
8955 This will have permanent effect only in mail groups.
8956 If FORCE is non-nil, allow editing of articles even in read-only
8957 groups."
8958   (interactive "P")
8959   (save-excursion
8960     (set-buffer gnus-summary-buffer)
8961     (let ((mail-parse-charset gnus-newsgroup-charset)
8962           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8963       (gnus-set-global-variables)
8964       (when (and (not force)
8965                  (gnus-group-read-only-p))
8966         (error "The current newsgroup does not support article editing"))
8967       (gnus-summary-show-article t)
8968       (gnus-article-edit-article
8969        'ignore
8970        `(lambda (no-highlight)
8971           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8972                 (message-options message-options)
8973                 (message-options-set-recipient)
8974                 (mail-parse-ignored-charsets
8975                  ',gnus-newsgroup-ignored-charsets))
8976             (gnus-summary-edit-article-done
8977              ,(or (mail-header-references gnus-current-headers) "")
8978              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8979
8980 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8981
8982 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8983                                                  no-highlight)
8984   "Make edits to the current article permanent."
8985   (interactive)
8986   (save-excursion
8987     ;; The buffer restriction contains the entire article if it exists.
8988     (when (article-goto-body)
8989       (let ((lines (count-lines (point) (point-max)))
8990             (length (- (point-max) (point)))
8991             (case-fold-search t)
8992             (body (copy-marker (point))))
8993         (goto-char (point-min))
8994         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8995           (delete-region (match-beginning 1) (match-end 1))
8996           (insert (number-to-string length)))
8997         (goto-char (point-min))
8998         (when (re-search-forward
8999                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9000           (delete-region (match-beginning 1) (match-end 1))
9001           (insert (number-to-string length)))
9002         (goto-char (point-min))
9003         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9004           (delete-region (match-beginning 1) (match-end 1))
9005           (insert (number-to-string lines))))))
9006   ;; Replace the article.
9007   (let ((buf (current-buffer)))
9008     (with-temp-buffer
9009       (insert-buffer-substring buf)
9010
9011       (if (and (not read-only)
9012                (not (gnus-request-replace-article
9013                      (cdr gnus-article-current) (car gnus-article-current)
9014                      (current-buffer) t)))
9015           (error "Couldn't replace article")
9016         ;; Update the summary buffer.
9017         (if (and references
9018                  (equal (message-tokenize-header references " ")
9019                         (message-tokenize-header
9020                          (or (message-fetch-field "references") "") " ")))
9021             ;; We only have to update this line.
9022             (save-excursion
9023               (save-restriction
9024                 (message-narrow-to-head)
9025                 (let ((head (buffer-string))
9026                       header)
9027                   (with-temp-buffer
9028                     (insert (format "211 %d Article retrieved.\n"
9029                                     (cdr gnus-article-current)))
9030                     (insert head)
9031                     (insert ".\n")
9032                     (let ((nntp-server-buffer (current-buffer)))
9033                       (setq header (car (gnus-get-newsgroup-headers
9034                                          nil t))))
9035                     (save-excursion
9036                       (set-buffer gnus-summary-buffer)
9037                       (gnus-data-set-header
9038                        (gnus-data-find (cdr gnus-article-current))
9039                        header)
9040                       (gnus-summary-update-article-line
9041                        (cdr gnus-article-current) header)
9042                       (if (gnus-summary-goto-subject
9043                            (cdr gnus-article-current) nil t)
9044                           (gnus-summary-update-secondary-mark
9045                            (cdr gnus-article-current))))))))
9046           ;; Update threads.
9047           (set-buffer (or buffer gnus-summary-buffer))
9048           (gnus-summary-update-article (cdr gnus-article-current))
9049           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9050               (gnus-summary-update-secondary-mark
9051                (cdr gnus-article-current))))
9052         ;; Prettify the article buffer again.
9053         (unless no-highlight
9054           (save-excursion
9055             (set-buffer gnus-article-buffer)
9056             ;;;!!! Fix this -- article should be rehighlighted.
9057             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9058             (set-buffer gnus-original-article-buffer)
9059             (gnus-request-article
9060              (cdr gnus-article-current)
9061              (car gnus-article-current) (current-buffer))))
9062         ;; Prettify the summary buffer line.
9063         (when (gnus-visual-p 'summary-highlight 'highlight)
9064           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9065
9066 (defun gnus-summary-edit-wash (key)
9067   "Perform editing command KEY in the article buffer."
9068   (interactive
9069    (list
9070     (progn
9071       (message "%s" (concat (this-command-keys) "- "))
9072       (read-char))))
9073   (message "")
9074   (gnus-summary-edit-article)
9075   (execute-kbd-macro (concat (this-command-keys) key))
9076   (gnus-article-edit-done))
9077
9078 ;;; Respooling
9079
9080 (defun gnus-summary-respool-query (&optional silent trace)
9081   "Query where the respool algorithm would put this article."
9082   (interactive)
9083   (let (gnus-mark-article-hook)
9084     (gnus-summary-select-article)
9085     (save-excursion
9086       (set-buffer gnus-original-article-buffer)
9087       (save-restriction
9088         (message-narrow-to-head)
9089         (let ((groups (nnmail-article-group 'identity trace)))
9090           (unless silent
9091             (if groups
9092                 (message "This message would go to %s"
9093                          (mapconcat 'car groups ", "))
9094               (message "This message would go to no groups"))
9095             groups))))))
9096
9097 (defun gnus-summary-respool-trace ()
9098   "Trace where the respool algorithm would put this article.
9099 Display a buffer showing all fancy splitting patterns which matched."
9100   (interactive)
9101   (gnus-summary-respool-query nil t))
9102
9103 ;; Summary marking commands.
9104
9105 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9106   "Mark articles which has the same subject as read, and then select the next.
9107 If UNMARK is positive, remove any kind of mark.
9108 If UNMARK is negative, tick articles."
9109   (interactive "P")
9110   (when unmark
9111     (setq unmark (prefix-numeric-value unmark)))
9112   (let ((count
9113          (gnus-summary-mark-same-subject
9114           (gnus-summary-article-subject) unmark)))
9115     ;; Select next unread article.  If auto-select-same mode, should
9116     ;; select the first unread article.
9117     (gnus-summary-next-article t (and gnus-auto-select-same
9118                                       (gnus-summary-article-subject)))
9119     (gnus-message 7 "%d article%s marked as %s"
9120                   count (if (= count 1) " is" "s are")
9121                   (if unmark "unread" "read"))))
9122
9123 (defun gnus-summary-kill-same-subject (&optional unmark)
9124   "Mark articles which has the same subject as read.
9125 If UNMARK is positive, remove any kind of mark.
9126 If UNMARK is negative, tick articles."
9127   (interactive "P")
9128   (when unmark
9129     (setq unmark (prefix-numeric-value unmark)))
9130   (let ((count
9131          (gnus-summary-mark-same-subject
9132           (gnus-summary-article-subject) unmark)))
9133     ;; If marked as read, go to next unread subject.
9134     (when (null unmark)
9135       ;; Go to next unread subject.
9136       (gnus-summary-next-subject 1 t))
9137     (gnus-message 7 "%d articles are marked as %s"
9138                   count (if unmark "unread" "read"))))
9139
9140 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9141   "Mark articles with same SUBJECT as read, and return marked number.
9142 If optional argument UNMARK is positive, remove any kinds of marks.
9143 If optional argument UNMARK is negative, mark articles as unread instead."
9144   (let ((count 1))
9145     (save-excursion
9146       (cond
9147        ((null unmark)                   ; Mark as read.
9148         (while (and
9149                 (progn
9150                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9151                   (gnus-summary-show-thread) t)
9152                 (gnus-summary-find-subject subject))
9153           (setq count (1+ count))))
9154        ((> unmark 0)                    ; Tick.
9155         (while (and
9156                 (progn
9157                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9158                   (gnus-summary-show-thread) t)
9159                 (gnus-summary-find-subject subject))
9160           (setq count (1+ count))))
9161        (t                               ; Mark as unread.
9162         (while (and
9163                 (progn
9164                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9165                   (gnus-summary-show-thread) t)
9166                 (gnus-summary-find-subject subject))
9167           (setq count (1+ count)))))
9168       (gnus-set-mode-line 'summary)
9169       ;; Return the number of marked articles.
9170       count)))
9171
9172 (defun gnus-summary-mark-as-processable (n &optional unmark)
9173   "Set the process mark on the next N articles.
9174 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9175 the process mark instead.  The difference between N and the actual
9176 number of articles marked is returned."
9177   (interactive "P")
9178   (if (and (null n) (gnus-region-active-p))
9179       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9180     (setq n (prefix-numeric-value n))
9181     (let ((backward (< n 0))
9182           (n (abs n)))
9183       (while (and
9184               (> n 0)
9185               (if unmark
9186                   (gnus-summary-remove-process-mark
9187                    (gnus-summary-article-number))
9188                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9189               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9190         (setq n (1- n)))
9191       (when (/= 0 n)
9192         (gnus-message 7 "No more articles"))
9193       (gnus-summary-recenter)
9194       (gnus-summary-position-point)
9195       n)))
9196
9197 (defun gnus-summary-unmark-as-processable (n)
9198   "Remove the process mark from the next N articles.
9199 If N is negative, unmark backward instead.  The difference between N and
9200 the actual number of articles unmarked is returned."
9201   (interactive "P")
9202   (gnus-summary-mark-as-processable n t))
9203
9204 (defun gnus-summary-unmark-all-processable ()
9205   "Remove the process mark from all articles."
9206   (interactive)
9207   (save-excursion
9208     (while gnus-newsgroup-processable
9209       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9210   (gnus-summary-position-point))
9211
9212 (defun gnus-summary-add-mark (article type)
9213   "Mark ARTICLE with a mark of TYPE."
9214   (let ((vtype (car (assq type gnus-article-mark-lists)))
9215         var)
9216     (if (not vtype)
9217         (error "No such mark type: %s" type)
9218       (setq var (intern (format "gnus-newsgroup-%s" type)))
9219       (set var (cons article (symbol-value var)))
9220       (if (memq type '(processable cached replied forwarded recent saved))
9221           (gnus-summary-update-secondary-mark article)
9222         ;;; !!! This is bogus.  We should find out what primary
9223         ;;; !!! mark we want to set.
9224         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9225
9226 (defun gnus-summary-mark-as-expirable (n)
9227   "Mark N articles forward as expirable.
9228 If N is negative, mark backward instead.  The difference between N and
9229 the actual number of articles marked is returned."
9230   (interactive "p")
9231   (gnus-summary-mark-forward n gnus-expirable-mark))
9232
9233 (defun gnus-summary-mark-article-as-replied (article)
9234   "Mark ARTICLE as replied to and update the summary line.
9235 ARTICLE can also be a list of articles."
9236   (interactive (list (gnus-summary-article-number)))
9237   (let ((articles (if (listp article) article (list article))))
9238     (dolist (article articles)
9239       (push article gnus-newsgroup-replied)
9240       (let ((buffer-read-only nil))
9241         (when (gnus-summary-goto-subject article nil t)
9242           (gnus-summary-update-secondary-mark article))))))
9243
9244 (defun gnus-summary-mark-article-as-forwarded (article)
9245   "Mark ARTICLE as forwarded and update the summary line.
9246 ARTICLE can also be a list of articles."
9247   (let ((articles (if (listp article) article (list article))))
9248     (dolist (article articles)
9249       (push article gnus-newsgroup-forwarded)
9250       (let ((buffer-read-only nil))
9251         (when (gnus-summary-goto-subject article nil t)
9252           (gnus-summary-update-secondary-mark article))))))
9253
9254 (defun gnus-summary-set-bookmark (article)
9255   "Set a bookmark in current article."
9256   (interactive (list (gnus-summary-article-number)))
9257   (when (or (not (get-buffer gnus-article-buffer))
9258             (not gnus-current-article)
9259             (not gnus-article-current)
9260             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9261     (error "No current article selected"))
9262   ;; Remove old bookmark, if one exists.
9263   (let ((old (assq article gnus-newsgroup-bookmarks)))
9264     (when old
9265       (setq gnus-newsgroup-bookmarks
9266             (delq old gnus-newsgroup-bookmarks))))
9267   ;; Set the new bookmark, which is on the form
9268   ;; (article-number . line-number-in-body).
9269   (push
9270    (cons article
9271          (save-excursion
9272            (set-buffer gnus-article-buffer)
9273            (count-lines
9274             (min (point)
9275                  (save-excursion
9276                    (goto-char (point-min))
9277                    (search-forward "\n\n" nil t)
9278                    (point)))
9279             (point))))
9280    gnus-newsgroup-bookmarks)
9281   (gnus-message 6 "A bookmark has been added to the current article."))
9282
9283 (defun gnus-summary-remove-bookmark (article)
9284   "Remove the bookmark from the current article."
9285   (interactive (list (gnus-summary-article-number)))
9286   ;; Remove old bookmark, if one exists.
9287   (let ((old (assq article gnus-newsgroup-bookmarks)))
9288     (if old
9289         (progn
9290           (setq gnus-newsgroup-bookmarks
9291                 (delq old gnus-newsgroup-bookmarks))
9292           (gnus-message 6 "Removed bookmark."))
9293       (gnus-message 6 "No bookmark in current article."))))
9294
9295 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9296 (defun gnus-summary-mark-as-dormant (n)
9297   "Mark N articles forward as dormant.
9298 If N is negative, mark backward instead.  The difference between N and
9299 the actual number of articles marked is returned."
9300   (interactive "p")
9301   (gnus-summary-mark-forward n gnus-dormant-mark))
9302
9303 (defun gnus-summary-set-process-mark (article)
9304   "Set the process mark on ARTICLE and update the summary line."
9305   (setq gnus-newsgroup-processable
9306         (cons article
9307               (delq article gnus-newsgroup-processable)))
9308   (when (gnus-summary-goto-subject article)
9309     (gnus-summary-show-thread)
9310     (gnus-summary-goto-subject article)
9311     (gnus-summary-update-secondary-mark article)))
9312
9313 (defun gnus-summary-remove-process-mark (article)
9314   "Remove the process mark from ARTICLE and update the summary line."
9315   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9316   (when (gnus-summary-goto-subject article)
9317     (gnus-summary-show-thread)
9318     (gnus-summary-goto-subject article)
9319     (gnus-summary-update-secondary-mark article)))
9320
9321 (defun gnus-summary-set-saved-mark (article)
9322   "Set the process mark on ARTICLE and update the summary line."
9323   (push article gnus-newsgroup-saved)
9324   (when (gnus-summary-goto-subject article)
9325     (gnus-summary-update-secondary-mark article)))
9326
9327 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9328   "Mark N articles as read forwards.
9329 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9330 The difference between N and the actual number of articles marked is
9331 returned.
9332 Iff NO-EXPIRE, auto-expiry will be inhibited."
9333   (interactive "p")
9334   (gnus-summary-show-thread)
9335   (let ((backward (< n 0))
9336         (gnus-summary-goto-unread
9337          (and gnus-summary-goto-unread
9338               (not (eq gnus-summary-goto-unread 'never))
9339               (not (memq mark (list gnus-unread-mark
9340                                     gnus-ticked-mark gnus-dormant-mark)))))
9341         (n (abs n))
9342         (mark (or mark gnus-del-mark)))
9343     (while (and (> n 0)
9344                 (gnus-summary-mark-article nil mark no-expire)
9345                 (zerop (gnus-summary-next-subject
9346                         (if backward -1 1)
9347                         (and gnus-summary-goto-unread
9348                              (not (eq gnus-summary-goto-unread 'never)))
9349                         t)))
9350       (setq n (1- n)))
9351     (when (/= 0 n)
9352       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9353     (gnus-summary-recenter)
9354     (gnus-summary-position-point)
9355     (gnus-set-mode-line 'summary)
9356     n))
9357
9358 (defun gnus-summary-mark-article-as-read (mark)
9359   "Mark the current article quickly as read with MARK."
9360   (let ((article (gnus-summary-article-number)))
9361     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9362     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9363     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9364     (push (cons article mark) gnus-newsgroup-reads)
9365     ;; Possibly remove from cache, if that is used.
9366     (when gnus-use-cache
9367       (gnus-cache-enter-remove-article article))
9368     ;; Allow the backend to change the mark.
9369     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9370     ;; Check for auto-expiry.
9371     (when (and gnus-newsgroup-auto-expire
9372                (memq mark gnus-auto-expirable-marks))
9373       (setq mark gnus-expirable-mark)
9374       ;; Let the backend know about the mark change.
9375       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9376       (push article gnus-newsgroup-expirable))
9377     ;; Set the mark in the buffer.
9378     (gnus-summary-update-mark mark 'unread)
9379     t))
9380
9381 (defun gnus-summary-mark-article-as-unread (mark)
9382   "Mark the current article quickly as unread with MARK."
9383   (let* ((article (gnus-summary-article-number))
9384          (old-mark (gnus-summary-article-mark article)))
9385     ;; Allow the backend to change the mark.
9386     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9387     (if (eq mark old-mark)
9388         t
9389       (if (<= article 0)
9390           (progn
9391             (gnus-error 1 "Can't mark negative article numbers")
9392             nil)
9393         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9394         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9395         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9396         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9397         (cond ((= mark gnus-ticked-mark)
9398                (setq gnus-newsgroup-marked
9399                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9400                                               article)))
9401               ((= mark gnus-dormant-mark)
9402                (setq gnus-newsgroup-dormant
9403                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9404                                               article)))
9405               (t
9406                (setq gnus-newsgroup-unreads
9407                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9408                                               article))))
9409         (gnus-pull article gnus-newsgroup-reads)
9410
9411         ;; See whether the article is to be put in the cache.
9412         (and gnus-use-cache
9413              (vectorp (gnus-summary-article-header article))
9414              (save-excursion
9415                (gnus-cache-possibly-enter-article
9416                 gnus-newsgroup-name article
9417                 (gnus-summary-article-header article)
9418                 (= mark gnus-ticked-mark)
9419                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9420
9421         ;; Fix the mark.
9422         (gnus-summary-update-mark mark 'unread)
9423         t))))
9424
9425 (defun gnus-summary-mark-article (&optional article mark no-expire)
9426   "Mark ARTICLE with MARK.  MARK can be any character.
9427 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9428 `??' (dormant) and `?E' (expirable).
9429 If MARK is nil, then the default character `?r' is used.
9430 If ARTICLE is nil, then the article on the current line will be
9431 marked.
9432 Iff NO-EXPIRE, auto-expiry will be inhibited."
9433   ;; The mark might be a string.
9434   (when (stringp mark)
9435     (setq mark (aref mark 0)))
9436   ;; If no mark is given, then we check auto-expiring.
9437   (when (null mark)
9438     (setq mark gnus-del-mark))
9439   (when (and (not no-expire)
9440              gnus-newsgroup-auto-expire
9441              (memq mark gnus-auto-expirable-marks))
9442     (setq mark gnus-expirable-mark))
9443   (let ((article (or article (gnus-summary-article-number)))
9444         (old-mark (gnus-summary-article-mark article)))
9445     ;; Allow the backend to change the mark.
9446     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9447     (if (eq mark old-mark)
9448         t
9449       (unless article
9450         (error "No article on current line"))
9451       (if (not (if (or (= mark gnus-unread-mark)
9452                        (= mark gnus-ticked-mark)
9453                        (= mark gnus-dormant-mark))
9454                    (gnus-mark-article-as-unread article mark)
9455                  (gnus-mark-article-as-read article mark)))
9456           t
9457         ;; See whether the article is to be put in the cache.
9458         (and gnus-use-cache
9459              (not (= mark gnus-canceled-mark))
9460              (vectorp (gnus-summary-article-header article))
9461              (save-excursion
9462                (gnus-cache-possibly-enter-article
9463                 gnus-newsgroup-name article
9464                 (gnus-summary-article-header article)
9465                 (= mark gnus-ticked-mark)
9466                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9467
9468         (when (gnus-summary-goto-subject article nil t)
9469           (let ((buffer-read-only nil))
9470             (gnus-summary-show-thread)
9471             ;; Fix the mark.
9472             (gnus-summary-update-mark mark 'unread)
9473             t))))))
9474
9475 (defun gnus-summary-update-secondary-mark (article)
9476   "Update the secondary (read, process, cache) mark."
9477   (gnus-summary-update-mark
9478    (cond ((memq article gnus-newsgroup-processable)
9479           gnus-process-mark)
9480          ((memq article gnus-newsgroup-cached)
9481           gnus-cached-mark)
9482          ((memq article gnus-newsgroup-replied)
9483           gnus-replied-mark)
9484          ((memq article gnus-newsgroup-forwarded)
9485           gnus-forwarded-mark)
9486          ((memq article gnus-newsgroup-saved)
9487           gnus-saved-mark)
9488          ((memq article gnus-newsgroup-recent)
9489           gnus-recent-mark)
9490          ((memq article gnus-newsgroup-unseen)
9491           gnus-unseen-mark)
9492          (t gnus-no-mark))
9493    'replied)
9494   (when (gnus-visual-p 'summary-highlight 'highlight)
9495     (gnus-run-hooks 'gnus-summary-update-hook))
9496   t)
9497
9498 (defun gnus-summary-update-mark (mark type)
9499   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9500         (buffer-read-only nil))
9501     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9502     (when forward
9503       (when (looking-at "\r")
9504         (incf forward))
9505       (when (<= (+ forward (point)) (point-max))
9506         ;; Go to the right position on the line.
9507         (goto-char (+ forward (point)))
9508         ;; Replace the old mark with the new mark.
9509         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9510         ;; Optionally update the marks by some user rule.
9511         (when (eq type 'unread)
9512           (gnus-data-set-mark
9513            (gnus-data-find (gnus-summary-article-number)) mark)
9514           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9515
9516 (defun gnus-mark-article-as-read (article &optional mark)
9517   "Enter ARTICLE in the pertinent lists and remove it from others."
9518   ;; Make the article expirable.
9519   (let ((mark (or mark gnus-del-mark)))
9520     (setq gnus-newsgroup-expirable
9521           (if (= mark gnus-expirable-mark)
9522               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9523             (delq article gnus-newsgroup-expirable)))
9524     ;; Remove from unread and marked lists.
9525     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9526     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9527     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9528     (push (cons article mark) gnus-newsgroup-reads)
9529     ;; Possibly remove from cache, if that is used.
9530     (when gnus-use-cache
9531       (gnus-cache-enter-remove-article article))
9532     t))
9533
9534 (defun gnus-mark-article-as-unread (article &optional mark)
9535   "Enter ARTICLE in the pertinent lists and remove it from others."
9536   (let ((mark (or mark gnus-ticked-mark)))
9537     (if (<= article 0)
9538         (progn
9539           (gnus-error 1 "Can't mark negative article numbers")
9540           nil)
9541       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9542             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9543             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9544             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9545
9546       ;; Unsuppress duplicates?
9547       (when gnus-suppress-duplicates
9548         (gnus-dup-unsuppress-article article))
9549
9550       (cond ((= mark gnus-ticked-mark)
9551              (setq gnus-newsgroup-marked
9552                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9553             ((= mark gnus-dormant-mark)
9554              (setq gnus-newsgroup-dormant
9555                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9556             (t
9557              (setq gnus-newsgroup-unreads
9558                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9559       (gnus-pull article gnus-newsgroup-reads)
9560       t)))
9561
9562 (defalias 'gnus-summary-mark-as-unread-forward
9563   'gnus-summary-tick-article-forward)
9564 (make-obsolete 'gnus-summary-mark-as-unread-forward
9565                'gnus-summary-tick-article-forward)
9566 (defun gnus-summary-tick-article-forward (n)
9567   "Tick N articles forwards.
9568 If N is negative, tick backwards instead.
9569 The difference between N and the number of articles ticked is returned."
9570   (interactive "p")
9571   (gnus-summary-mark-forward n gnus-ticked-mark))
9572
9573 (defalias 'gnus-summary-mark-as-unread-backward
9574   'gnus-summary-tick-article-backward)
9575 (make-obsolete 'gnus-summary-mark-as-unread-backward
9576                'gnus-summary-tick-article-backward)
9577 (defun gnus-summary-tick-article-backward (n)
9578   "Tick N articles backwards.
9579 The difference between N and the number of articles ticked is returned."
9580   (interactive "p")
9581   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9582
9583 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9584 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9585 (defun gnus-summary-tick-article (&optional article clear-mark)
9586   "Mark current article as unread.
9587 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9588 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9589   (interactive)
9590   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9591                                        gnus-ticked-mark)))
9592
9593 (defun gnus-summary-mark-as-read-forward (n)
9594   "Mark N articles as read forwards.
9595 If N is negative, mark backwards instead.
9596 The difference between N and the actual number of articles marked is
9597 returned."
9598   (interactive "p")
9599   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9600
9601 (defun gnus-summary-mark-as-read-backward (n)
9602   "Mark the N articles as read backwards.
9603 The difference between N and the actual number of articles marked is
9604 returned."
9605   (interactive "p")
9606   (gnus-summary-mark-forward
9607    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9608
9609 (defun gnus-summary-mark-as-read (&optional article mark)
9610   "Mark current article as read.
9611 ARTICLE specifies the article to be marked as read.
9612 MARK specifies a string to be inserted at the beginning of the line."
9613   (gnus-summary-mark-article article mark))
9614
9615 (defun gnus-summary-clear-mark-forward (n)
9616   "Clear marks from N articles forward.
9617 If N is negative, clear backward instead.
9618 The difference between N and the number of marks cleared is returned."
9619   (interactive "p")
9620   (gnus-summary-mark-forward n gnus-unread-mark))
9621
9622 (defun gnus-summary-clear-mark-backward (n)
9623   "Clear marks from N articles backward.
9624 The difference between N and the number of marks cleared is returned."
9625   (interactive "p")
9626   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9627
9628 (defun gnus-summary-mark-unread-as-read ()
9629   "Intended to be used by `gnus-summary-mark-article-hook'."
9630   (when (memq gnus-current-article gnus-newsgroup-unreads)
9631     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9632
9633 (defun gnus-summary-mark-read-and-unread-as-read ()
9634   "Intended to be used by `gnus-summary-mark-article-hook'."
9635   (let ((mark (gnus-summary-article-mark)))
9636     (when (or (gnus-unread-mark-p mark)
9637               (gnus-read-mark-p mark))
9638       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9639
9640 (defun gnus-summary-mark-unread-as-ticked ()
9641   "Intended to be used by `gnus-summary-mark-article-hook'."
9642   (when (memq gnus-current-article gnus-newsgroup-unreads)
9643     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9644
9645 (defun gnus-summary-mark-region-as-read (point mark all)
9646   "Mark all unread articles between point and mark as read.
9647 If given a prefix, mark all articles between point and mark as read,
9648 even ticked and dormant ones."
9649   (interactive "r\nP")
9650   (save-excursion
9651     (let (article)
9652       (goto-char point)
9653       (beginning-of-line)
9654       (while (and
9655               (< (point) mark)
9656               (progn
9657                 (when (or all
9658                           (memq (setq article (gnus-summary-article-number))
9659                                 gnus-newsgroup-unreads))
9660                   (gnus-summary-mark-article article gnus-del-mark))
9661                 t)
9662               (gnus-summary-find-next))))))
9663
9664 (defun gnus-summary-mark-below (score mark)
9665   "Mark articles with score less than SCORE with MARK."
9666   (interactive "P\ncMark: ")
9667   (setq score (if score
9668                   (prefix-numeric-value score)
9669                 (or gnus-summary-default-score 0)))
9670   (save-excursion
9671     (set-buffer gnus-summary-buffer)
9672     (goto-char (point-min))
9673     (while
9674         (progn
9675           (and (< (gnus-summary-article-score) score)
9676                (gnus-summary-mark-article nil mark))
9677           (gnus-summary-find-next)))))
9678
9679 (defun gnus-summary-kill-below (&optional score)
9680   "Mark articles with score below SCORE as read."
9681   (interactive "P")
9682   (gnus-summary-mark-below score gnus-killed-mark))
9683
9684 (defun gnus-summary-clear-above (&optional score)
9685   "Clear all marks from articles with score above SCORE."
9686   (interactive "P")
9687   (gnus-summary-mark-above score gnus-unread-mark))
9688
9689 (defun gnus-summary-tick-above (&optional score)
9690   "Tick all articles with score above SCORE."
9691   (interactive "P")
9692   (gnus-summary-mark-above score gnus-ticked-mark))
9693
9694 (defun gnus-summary-mark-above (score mark)
9695   "Mark articles with score over SCORE with MARK."
9696   (interactive "P\ncMark: ")
9697   (setq score (if score
9698                   (prefix-numeric-value score)
9699                 (or gnus-summary-default-score 0)))
9700   (save-excursion
9701     (set-buffer gnus-summary-buffer)
9702     (goto-char (point-min))
9703     (while (and (progn
9704                   (when (> (gnus-summary-article-score) score)
9705                     (gnus-summary-mark-article nil mark))
9706                   t)
9707                 (gnus-summary-find-next)))))
9708
9709 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9710 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9711 (defun gnus-summary-limit-include-expunged (&optional no-error)
9712   "Display all the hidden articles that were expunged for low scores."
9713   (interactive)
9714   (let ((buffer-read-only nil))
9715     (let ((scored gnus-newsgroup-scored)
9716           headers h)
9717       (while scored
9718         (unless (gnus-summary-article-header (caar scored))
9719           (and (setq h (gnus-number-to-header (caar scored)))
9720                (< (cdar scored) gnus-summary-expunge-below)
9721                (push h headers)))
9722         (setq scored (cdr scored)))
9723       (if (not headers)
9724           (when (not no-error)
9725             (error "No expunged articles hidden"))
9726         (goto-char (point-min))
9727         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9728         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9729         (mapcar (lambda (x) (push (mail-header-number x)
9730                                   gnus-newsgroup-limit))
9731                 headers)
9732         (gnus-summary-prepare-unthreaded (nreverse headers))
9733         (goto-char (point-min))
9734         (gnus-summary-position-point)
9735         t))))
9736
9737 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9738   "Mark all unread articles in this newsgroup as read.
9739 If prefix argument ALL is non-nil, ticked and dormant articles will
9740 also be marked as read.
9741 If QUIETLY is non-nil, no questions will be asked.
9742 If TO-HERE is non-nil, it should be a point in the buffer.  All
9743 articles before (after, if REVERSE is set) this point will be marked as read.
9744 Note that this function will only catch up the unread article
9745 in the current summary buffer limitation.
9746 The number of articles marked as read is returned."
9747   (interactive "P")
9748   (prog1
9749       (save-excursion
9750         (when (or quietly
9751                   (not gnus-interactive-catchup) ;Without confirmation?
9752                   gnus-expert-user
9753                   (gnus-y-or-n-p
9754                    (if all
9755                        "Mark absolutely all articles as read? "
9756                      "Mark all unread articles as read? ")))
9757           (if (and not-mark
9758                    (not gnus-newsgroup-adaptive)
9759                    (not gnus-newsgroup-auto-expire)
9760                    (not gnus-suppress-duplicates)
9761                    (or (not gnus-use-cache)
9762                        (eq gnus-use-cache 'passive)))
9763               (progn
9764                 (when all
9765                   (setq gnus-newsgroup-marked nil
9766                         gnus-newsgroup-dormant nil))
9767                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9768             ;; We actually mark all articles as canceled, which we
9769             ;; have to do when using auto-expiry or adaptive scoring.
9770             (gnus-summary-show-all-threads)
9771             (if (and to-here reverse)
9772                 (progn
9773                   (goto-char to-here)
9774                   (while (and
9775                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9776                           (gnus-summary-find-next (not all) nil nil t))))
9777               (when (gnus-summary-first-subject (not all) t)
9778                 (while (and
9779                         (if to-here (< (point) to-here) t)
9780                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9781                         (gnus-summary-find-next (not all) nil nil t)))))
9782             (gnus-set-mode-line 'summary))
9783           t))
9784     (gnus-summary-position-point)))
9785
9786 (defun gnus-summary-catchup-to-here (&optional all)
9787   "Mark all unticked articles before the current one as read.
9788 If ALL is non-nil, also mark ticked and dormant articles as read."
9789   (interactive "P")
9790   (save-excursion
9791     (gnus-save-hidden-threads
9792       (let ((beg (point)))
9793         ;; We check that there are unread articles.
9794         (when (or all (gnus-summary-find-prev))
9795           (gnus-summary-catchup all t beg)))))
9796   (gnus-summary-position-point))
9797
9798 (defun gnus-summary-catchup-from-here (&optional all)
9799   "Mark all unticked articles after the current one as read.
9800 If ALL is non-nil, also mark ticked and dormant articles as read."
9801   (interactive "P")
9802   (save-excursion
9803     (gnus-save-hidden-threads
9804       (let ((beg (point)))
9805         ;; We check that there are unread articles.
9806         (when (or all (gnus-summary-find-next))
9807           (gnus-summary-catchup all t beg nil t)))))
9808   (gnus-summary-position-point))
9809
9810 (defun gnus-summary-catchup-all (&optional quietly)
9811   "Mark all articles in this newsgroup as read."
9812   (interactive "P")
9813   (gnus-summary-catchup t quietly))
9814
9815 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9816   "Mark all unread articles in this group as read, then exit.
9817 If prefix argument ALL is non-nil, all articles are marked as read.
9818 If QUIETLY is non-nil, no questions will be asked."
9819   (interactive "P")
9820   (when (gnus-summary-catchup all quietly nil 'fast)
9821     ;; Select next newsgroup or exit.
9822     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9823              (eq gnus-auto-select-next 'quietly))
9824         (gnus-summary-next-group nil)
9825       (gnus-summary-exit))))
9826
9827 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9828   "Mark all articles in this newsgroup as read, and then exit."
9829   (interactive "P")
9830   (gnus-summary-catchup-and-exit t quietly))
9831
9832 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9833   "Mark all articles in this group as read and select the next group.
9834 If given a prefix, mark all articles, unread as well as ticked, as
9835 read."
9836   (interactive "P")
9837   (save-excursion
9838     (gnus-summary-catchup all))
9839   (gnus-summary-next-group))
9840
9841 ;;;
9842 ;;; with article
9843 ;;;
9844
9845 (defmacro gnus-with-article (article &rest forms)
9846   "Select ARTICLE and perform FORMS in the original article buffer.
9847 Then replace the article with the result."
9848   `(progn
9849      ;; We don't want the article to be marked as read.
9850      (let (gnus-mark-article-hook)
9851        (gnus-summary-select-article t t nil ,article))
9852      (set-buffer gnus-original-article-buffer)
9853      ,@forms
9854      (if (not (gnus-check-backend-function
9855                'request-replace-article (car gnus-article-current)))
9856          (gnus-message 5 "Read-only group; not replacing")
9857        (unless (gnus-request-replace-article
9858                 ,article (car gnus-article-current)
9859                 (current-buffer) t)
9860          (error "Couldn't replace article")))
9861      ;; The cache and backlog have to be flushed somewhat.
9862      (when gnus-keep-backlog
9863        (gnus-backlog-remove-article
9864         (car gnus-article-current) (cdr gnus-article-current)))
9865      (when gnus-use-cache
9866        (gnus-cache-update-article
9867         (car gnus-article-current) (cdr gnus-article-current)))))
9868
9869 (put 'gnus-with-article 'lisp-indent-function 1)
9870 (put 'gnus-with-article 'edebug-form-spec '(form body))
9871
9872 ;; Thread-based commands.
9873
9874 (defun gnus-summary-articles-in-thread (&optional article)
9875   "Return a list of all articles in the current thread.
9876 If ARTICLE is non-nil, return all articles in the thread that starts
9877 with that article."
9878   (let* ((article (or article (gnus-summary-article-number)))
9879          (data (gnus-data-find-list article))
9880          (top-level (gnus-data-level (car data)))
9881          (top-subject
9882           (cond ((null gnus-thread-operation-ignore-subject)
9883                  (gnus-simplify-subject-re
9884                   (mail-header-subject (gnus-data-header (car data)))))
9885                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9886                  (gnus-simplify-subject-fuzzy
9887                   (mail-header-subject (gnus-data-header (car data)))))
9888                 (t nil)))
9889          (end-point (save-excursion
9890                       (if (gnus-summary-go-to-next-thread)
9891                           (point) (point-max))))
9892          articles)
9893     (while (and data
9894                 (< (gnus-data-pos (car data)) end-point))
9895       (when (or (not top-subject)
9896                 (string= top-subject
9897                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9898                              (gnus-simplify-subject-fuzzy
9899                               (mail-header-subject
9900                                (gnus-data-header (car data))))
9901                            (gnus-simplify-subject-re
9902                             (mail-header-subject
9903                              (gnus-data-header (car data)))))))
9904         (push (gnus-data-number (car data)) articles))
9905       (unless (and (setq data (cdr data))
9906                    (> (gnus-data-level (car data)) top-level))
9907         (setq data nil)))
9908     ;; Return the list of articles.
9909     (nreverse articles)))
9910
9911 (defun gnus-summary-rethread-current ()
9912   "Rethread the thread the current article is part of."
9913   (interactive)
9914   (let* ((gnus-show-threads t)
9915          (article (gnus-summary-article-number))
9916          (id (mail-header-id (gnus-summary-article-header)))
9917          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9918     (unless id
9919       (error "No article on the current line"))
9920     (gnus-rebuild-thread id)
9921     (gnus-summary-goto-subject article)))
9922
9923 (defun gnus-summary-reparent-thread ()
9924   "Make the current article child of the marked (or previous) article.
9925
9926 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9927 is non-nil or the Subject: of both articles are the same."
9928   (interactive)
9929   (unless (not (gnus-group-read-only-p))
9930     (error "The current newsgroup does not support article editing"))
9931   (unless (<= (length gnus-newsgroup-processable) 1)
9932     (error "No more than one article may be marked"))
9933   (save-window-excursion
9934     (let ((gnus-article-buffer " *reparent*")
9935           (current-article (gnus-summary-article-number))
9936           ;; First grab the marked article, otherwise one line up.
9937           (parent-article (if (not (null gnus-newsgroup-processable))
9938                               (car gnus-newsgroup-processable)
9939                             (save-excursion
9940                               (if (eq (forward-line -1) 0)
9941                                   (gnus-summary-article-number)
9942                                 (error "Beginning of summary buffer"))))))
9943       (unless (not (eq current-article parent-article))
9944         (error "An article may not be self-referential"))
9945       (let ((message-id (mail-header-id
9946                          (gnus-summary-article-header parent-article))))
9947         (unless (and message-id (not (equal message-id "")))
9948           (error "No message-id in desired parent"))
9949         (gnus-with-article current-article
9950           (save-restriction
9951             (goto-char (point-min))
9952             (message-narrow-to-head)
9953             (if (re-search-forward "^References: " nil t)
9954                 (progn
9955                   (re-search-forward "^[^ \t]" nil t)
9956                   (forward-line -1)
9957                   (end-of-line)
9958                   (insert " " message-id))
9959               (insert "References: " message-id "\n"))))
9960         (set-buffer gnus-summary-buffer)
9961         (gnus-summary-unmark-all-processable)
9962         (gnus-summary-update-article current-article)
9963         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9964             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9965         (gnus-summary-rethread-current)
9966         (gnus-message 3 "Article %d is now the child of article %d"
9967                       current-article parent-article)))))
9968
9969 (defun gnus-summary-toggle-threads (&optional arg)
9970   "Toggle showing conversation threads.
9971 If ARG is positive number, turn showing conversation threads on."
9972   (interactive "P")
9973   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9974     (setq gnus-show-threads
9975           (if (null arg) (not gnus-show-threads)
9976             (> (prefix-numeric-value arg) 0)))
9977     (gnus-summary-prepare)
9978     (gnus-summary-goto-subject current)
9979     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9980     (gnus-summary-position-point)))
9981
9982 (defun gnus-summary-show-all-threads ()
9983   "Show all threads."
9984   (interactive)
9985   (save-excursion
9986     (let ((buffer-read-only nil))
9987       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9988   (gnus-summary-position-point))
9989
9990 (defun gnus-summary-show-thread ()
9991   "Show thread subtrees.
9992 Returns nil if no thread was there to be shown."
9993   (interactive)
9994   (let ((buffer-read-only nil)
9995         (orig (point))
9996         ;; first goto end then to beg, to have point at beg after let
9997         (end (progn (end-of-line) (point)))
9998         (beg (progn (beginning-of-line) (point))))
9999     (prog1
10000         ;; Any hidden lines here?
10001         (search-forward "\r" end t)
10002       (subst-char-in-region beg end ?\^M ?\n t)
10003       (goto-char orig)
10004       (gnus-summary-position-point))))
10005
10006 (defun gnus-summary-maybe-hide-threads ()
10007   "If requested, hide the threads that should be hidden."
10008   (when (and gnus-show-threads
10009              gnus-thread-hide-subtree)
10010     (gnus-summary-hide-all-threads
10011      (if (or (consp gnus-thread-hide-subtree)
10012              (gnus-functionp gnus-thread-hide-subtree))
10013          (gnus-make-predicate gnus-thread-hide-subtree)
10014        nil))))
10015
10016 ;;; Hiding predicates.
10017
10018 (defun gnus-article-unread-p (header)
10019   (memq (mail-header-number header) gnus-newsgroup-unreads))
10020
10021 (defun gnus-article-unseen-p (header)
10022   (memq (mail-header-number header) gnus-newsgroup-unseen))
10023
10024 (defun gnus-map-articles (predicate articles)
10025   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10026   (apply 'gnus-or (mapcar predicate
10027                           (mapcar 'gnus-summary-article-header articles))))
10028
10029 (defun gnus-summary-hide-all-threads (&optional predicate)
10030   "Hide all thread subtrees.
10031 If PREDICATE is supplied, threads that satisfy this predicate
10032 will not be hidden."
10033   (interactive)
10034   (save-excursion
10035     (goto-char (point-min))
10036     (let ((end nil))
10037       (while (not end)
10038         (when (or (not predicate)
10039                   (gnus-map-articles
10040                    predicate (gnus-summary-article-children)))
10041             (gnus-summary-hide-thread))
10042         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10043   (gnus-summary-position-point))
10044
10045 (defun gnus-summary-hide-thread ()
10046   "Hide thread subtrees.
10047 If PREDICATE is supplied, threads that satisfy this predicate
10048 will not be hidden.
10049 Returns nil if no threads were there to be hidden."
10050   (interactive)
10051   (let ((buffer-read-only nil)
10052         (start (point))
10053         (article (gnus-summary-article-number)))
10054     (goto-char start)
10055     ;; Go forward until either the buffer ends or the subthread
10056     ;; ends.
10057     (when (and (not (eobp))
10058                (or (zerop (gnus-summary-next-thread 1 t))
10059                    (goto-char (point-max))))
10060       (prog1
10061           (if (and (> (point) start)
10062                    (search-backward "\n" start t))
10063               (progn
10064                 (subst-char-in-region start (point) ?\n ?\^M)
10065                 (gnus-summary-goto-subject article))
10066             (goto-char start)
10067             nil)))))
10068
10069 (defun gnus-summary-go-to-next-thread (&optional previous)
10070   "Go to the same level (or less) next thread.
10071 If PREVIOUS is non-nil, go to previous thread instead.
10072 Return the article number moved to, or nil if moving was impossible."
10073   (let ((level (gnus-summary-thread-level))
10074         (way (if previous -1 1))
10075         (beg (point)))
10076     (forward-line way)
10077     (while (and (not (eobp))
10078                 (< level (gnus-summary-thread-level)))
10079       (forward-line way))
10080     (if (eobp)
10081         (progn
10082           (goto-char beg)
10083           nil)
10084       (setq beg (point))
10085       (prog1
10086           (gnus-summary-article-number)
10087         (goto-char beg)))))
10088
10089 (defun gnus-summary-next-thread (n &optional silent)
10090   "Go to the same level next N'th thread.
10091 If N is negative, search backward instead.
10092 Returns the difference between N and the number of skips actually
10093 done.
10094
10095 If SILENT, don't output messages."
10096   (interactive "p")
10097   (let ((backward (< n 0))
10098         (n (abs n)))
10099     (while (and (> n 0)
10100                 (gnus-summary-go-to-next-thread backward))
10101       (decf n))
10102     (unless silent
10103       (gnus-summary-position-point))
10104     (when (and (not silent) (/= 0 n))
10105       (gnus-message 7 "No more threads"))
10106     n))
10107
10108 (defun gnus-summary-prev-thread (n)
10109   "Go to the same level previous N'th thread.
10110 Returns the difference between N and the number of skips actually
10111 done."
10112   (interactive "p")
10113   (gnus-summary-next-thread (- n)))
10114
10115 (defun gnus-summary-go-down-thread ()
10116   "Go down one level in the current thread."
10117   (let ((children (gnus-summary-article-children)))
10118     (when children
10119       (gnus-summary-goto-subject (car children)))))
10120
10121 (defun gnus-summary-go-up-thread ()
10122   "Go up one level in the current thread."
10123   (let ((parent (gnus-summary-article-parent)))
10124     (when parent
10125       (gnus-summary-goto-subject parent))))
10126
10127 (defun gnus-summary-down-thread (n)
10128   "Go down thread N steps.
10129 If N is negative, go up instead.
10130 Returns the difference between N and how many steps down that were
10131 taken."
10132   (interactive "p")
10133   (let ((up (< n 0))
10134         (n (abs n)))
10135     (while (and (> n 0)
10136                 (if up (gnus-summary-go-up-thread)
10137                   (gnus-summary-go-down-thread)))
10138       (setq n (1- n)))
10139     (gnus-summary-position-point)
10140     (when (/= 0 n)
10141       (gnus-message 7 "Can't go further"))
10142     n))
10143
10144 (defun gnus-summary-up-thread (n)
10145   "Go up thread N steps.
10146 If N is negative, go down instead.
10147 Returns the difference between N and how many steps down that were
10148 taken."
10149   (interactive "p")
10150   (gnus-summary-down-thread (- n)))
10151
10152 (defun gnus-summary-top-thread ()
10153   "Go to the top of the thread."
10154   (interactive)
10155   (while (gnus-summary-go-up-thread))
10156   (gnus-summary-article-number))
10157
10158 (defun gnus-summary-kill-thread (&optional unmark)
10159   "Mark articles under current thread as read.
10160 If the prefix argument is positive, remove any kinds of marks.
10161 If the prefix argument is negative, tick articles instead."
10162   (interactive "P")
10163   (when unmark
10164     (setq unmark (prefix-numeric-value unmark)))
10165   (let ((articles (gnus-summary-articles-in-thread)))
10166     (save-excursion
10167       ;; Expand the thread.
10168       (gnus-summary-show-thread)
10169       ;; Mark all the articles.
10170       (while articles
10171         (gnus-summary-goto-subject (car articles))
10172         (cond ((null unmark)
10173                (gnus-summary-mark-article-as-read gnus-killed-mark))
10174               ((> unmark 0)
10175                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10176               (t
10177                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10178         (setq articles (cdr articles))))
10179     ;; Hide killed subtrees.
10180     (and (null unmark)
10181          gnus-thread-hide-killed
10182          (gnus-summary-hide-thread))
10183     ;; If marked as read, go to next unread subject.
10184     (when (null unmark)
10185       ;; Go to next unread subject.
10186       (gnus-summary-next-subject 1 t)))
10187   (gnus-set-mode-line 'summary))
10188
10189 ;; Summary sorting commands
10190
10191 (defun gnus-summary-sort-by-number (&optional reverse)
10192   "Sort the summary buffer by article number.
10193 Argument REVERSE means reverse order."
10194   (interactive "P")
10195   (gnus-summary-sort 'number reverse))
10196
10197 (defun gnus-summary-sort-by-author (&optional reverse)
10198   "Sort the summary buffer by author name alphabetically.
10199 If `case-fold-search' is non-nil, case of letters is ignored.
10200 Argument REVERSE means reverse order."
10201   (interactive "P")
10202   (gnus-summary-sort 'author reverse))
10203
10204 (defun gnus-summary-sort-by-subject (&optional reverse)
10205   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10206 If `case-fold-search' is non-nil, case of letters is ignored.
10207 Argument REVERSE means reverse order."
10208   (interactive "P")
10209   (gnus-summary-sort 'subject reverse))
10210
10211 (defun gnus-summary-sort-by-date (&optional reverse)
10212   "Sort the summary buffer by date.
10213 Argument REVERSE means reverse order."
10214   (interactive "P")
10215   (gnus-summary-sort 'date reverse))
10216
10217 (defun gnus-summary-sort-by-score (&optional reverse)
10218   "Sort the summary buffer by score.
10219 Argument REVERSE means reverse order."
10220   (interactive "P")
10221   (gnus-summary-sort 'score reverse))
10222
10223 (defun gnus-summary-sort-by-lines (&optional reverse)
10224   "Sort the summary buffer by the number of lines.
10225 Argument REVERSE means reverse order."
10226   (interactive "P")
10227   (gnus-summary-sort 'lines reverse))
10228
10229 (defun gnus-summary-sort-by-chars (&optional reverse)
10230   "Sort the summary buffer by article length.
10231 Argument REVERSE means reverse order."
10232   (interactive "P")
10233   (gnus-summary-sort 'chars reverse))
10234
10235 (defun gnus-summary-sort-by-original (&optional reverse)
10236   "Sort the summary buffer using the default sorting method.
10237 Argument REVERSE means reverse order."
10238   (interactive "P")
10239   (let* ((buffer-read-only)
10240          (gnus-summary-prepare-hook nil))
10241     ;; We do the sorting by regenerating the threads.
10242     (gnus-summary-prepare)
10243     ;; Hide subthreads if needed.
10244     (gnus-summary-maybe-hide-threads)))
10245
10246 (defun gnus-summary-sort (predicate reverse)
10247   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10248   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10249          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10250          (gnus-thread-sort-functions
10251           (if (not reverse)
10252               thread
10253             `(lambda (t1 t2)
10254                (,thread t2 t1))))
10255          (gnus-sort-gathered-threads-function
10256           gnus-thread-sort-functions)
10257          (gnus-article-sort-functions
10258           (if (not reverse)
10259               article
10260             `(lambda (t1 t2)
10261                (,article t2 t1))))
10262          (buffer-read-only)
10263          (gnus-summary-prepare-hook nil))
10264     ;; We do the sorting by regenerating the threads.
10265     (gnus-summary-prepare)
10266     ;; Hide subthreads if needed.
10267     (gnus-summary-maybe-hide-threads)))
10268
10269 ;; Summary saving commands.
10270
10271 (defun gnus-summary-save-article (&optional n not-saved)
10272   "Save the current article using the default saver function.
10273 If N is a positive number, save the N next articles.
10274 If N is a negative number, save the N previous articles.
10275 If N is nil and any articles have been marked with the process mark,
10276 save those articles instead.
10277 The variable `gnus-default-article-saver' specifies the saver function."
10278   (interactive "P")
10279   (let* ((articles (gnus-summary-work-articles n))
10280          (save-buffer (save-excursion
10281                         (nnheader-set-temp-buffer " *Gnus Save*")))
10282          (num (length articles))
10283          header file)
10284     (dolist (article articles)
10285       (setq header (gnus-summary-article-header article))
10286       (if (not (vectorp header))
10287           ;; This is a pseudo-article.
10288           (if (assq 'name header)
10289               (gnus-copy-file (cdr (assq 'name header)))
10290             (gnus-message 1 "Article %d is unsaveable" article))
10291         ;; This is a real article.
10292         (save-window-excursion
10293           (let ((gnus-display-mime-function nil)
10294                 (gnus-article-prepare-hook nil))
10295             (gnus-summary-select-article t nil nil article)))
10296         (save-excursion
10297           (set-buffer save-buffer)
10298           (erase-buffer)
10299           (insert-buffer-substring gnus-original-article-buffer))
10300         (setq file (gnus-article-save save-buffer file num))
10301         (gnus-summary-remove-process-mark article)
10302         (unless not-saved
10303           (gnus-summary-set-saved-mark article))))
10304     (gnus-kill-buffer save-buffer)
10305     (gnus-summary-position-point)
10306     (gnus-set-mode-line 'summary)
10307     n))
10308
10309 (defun gnus-summary-pipe-output (&optional arg)
10310   "Pipe the current article to a subprocess.
10311 If N is a positive number, pipe the N next articles.
10312 If N is a negative number, pipe the N previous articles.
10313 If N is nil and any articles have been marked with the process mark,
10314 pipe those articles instead."
10315   (interactive "P")
10316   (require 'gnus-art)
10317   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10318     (gnus-summary-save-article arg t))
10319   (let ((buffer (get-buffer "*Shell Command Output*")))
10320     (if (and buffer
10321              (with-current-buffer buffer (> (point-max) (point-min))))
10322         (gnus-configure-windows 'pipe))))
10323
10324 (defun gnus-summary-save-article-mail (&optional arg)
10325   "Append the current article to an mail file.
10326 If N is a positive number, save the N next articles.
10327 If N is a negative number, save the N previous articles.
10328 If N is nil and any articles have been marked with the process mark,
10329 save those articles instead."
10330   (interactive "P")
10331   (require 'gnus-art)
10332   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10333     (gnus-summary-save-article arg)))
10334
10335 (defun gnus-summary-save-article-rmail (&optional arg)
10336   "Append the current article to an rmail file.
10337 If N is a positive number, save the N next articles.
10338 If N is a negative number, save the N previous articles.
10339 If N is nil and any articles have been marked with the process mark,
10340 save those articles instead."
10341   (interactive "P")
10342   (require 'gnus-art)
10343   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10344     (gnus-summary-save-article arg)))
10345
10346 (defun gnus-summary-save-article-file (&optional arg)
10347   "Append the current article to a file.
10348 If N is a positive number, save the N next articles.
10349 If N is a negative number, save the N previous articles.
10350 If N is nil and any articles have been marked with the process mark,
10351 save those articles instead."
10352   (interactive "P")
10353   (require 'gnus-art)
10354   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10355     (gnus-summary-save-article arg)))
10356
10357 (defun gnus-summary-write-article-file (&optional arg)
10358   "Write the current article to a file, deleting the previous file.
10359 If N is a positive number, save the N next articles.
10360 If N is a negative number, save the N previous articles.
10361 If N is nil and any articles have been marked with the process mark,
10362 save those articles instead."
10363   (interactive "P")
10364   (require 'gnus-art)
10365   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10366     (gnus-summary-save-article arg)))
10367
10368 (defun gnus-summary-save-article-body-file (&optional arg)
10369   "Append the current article body to a file.
10370 If N is a positive number, save the N next articles.
10371 If N is a negative number, save the N previous articles.
10372 If N is nil and any articles have been marked with the process mark,
10373 save those articles instead."
10374   (interactive "P")
10375   (require 'gnus-art)
10376   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10377     (gnus-summary-save-article arg)))
10378
10379 (defun gnus-summary-muttprint (&optional arg)
10380   "Print the current article using Muttprint.
10381 If N is a positive number, save the N next articles.
10382 If N is a negative number, save the N previous articles.
10383 If N is nil and any articles have been marked with the process mark,
10384 save those articles instead."
10385   (interactive "P")
10386   (require 'gnus-art)
10387   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10388     (gnus-summary-save-article arg t)))
10389
10390 (defun gnus-summary-pipe-message (program)
10391   "Pipe the current article through PROGRAM."
10392   (interactive "sProgram: ")
10393   (gnus-summary-select-article)
10394   (let ((mail-header-separator ""))
10395     (gnus-eval-in-buffer-window gnus-article-buffer
10396       (save-restriction
10397         (widen)
10398         (let ((start (window-start))
10399               buffer-read-only)
10400           (message-pipe-buffer-body program)
10401           (set-window-start (get-buffer-window (current-buffer)) start))))))
10402
10403 (defun gnus-get-split-value (methods)
10404   "Return a value based on the split METHODS."
10405   (let (split-name method result match)
10406     (when methods
10407       (save-excursion
10408         (set-buffer gnus-original-article-buffer)
10409         (save-restriction
10410           (nnheader-narrow-to-headers)
10411           (while (and methods (not split-name))
10412             (goto-char (point-min))
10413             (setq method (pop methods))
10414             (setq match (car method))
10415             (when (cond
10416                    ((stringp match)
10417                     ;; Regular expression.
10418                     (ignore-errors
10419                       (re-search-forward match nil t)))
10420                    ((gnus-functionp match)
10421                     ;; Function.
10422                     (save-restriction
10423                       (widen)
10424                       (setq result (funcall match gnus-newsgroup-name))))
10425                    ((consp match)
10426                     ;; Form.
10427                     (save-restriction
10428                       (widen)
10429                       (setq result (eval match)))))
10430               (setq split-name (cdr method))
10431               (cond ((stringp result)
10432                      (push (expand-file-name
10433                             result gnus-article-save-directory)
10434                            split-name))
10435                     ((consp result)
10436                      (setq split-name (append result split-name)))))))))
10437     (nreverse split-name)))
10438
10439 (defun gnus-valid-move-group-p (group)
10440   (and (boundp group)
10441        (symbol-name group)
10442        (symbol-value group)
10443        (gnus-get-function (gnus-find-method-for-group
10444                            (symbol-name group)) 'request-accept-article t)))
10445
10446 (defun gnus-read-move-group-name (prompt default articles prefix)
10447   "Read a group name."
10448   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10449          (minibuffer-confirm-incomplete nil) ; XEmacs
10450          (prom
10451           (format "%s %s to:"
10452                   prompt
10453                   (if (> (length articles) 1)
10454                       (format "these %d articles" (length articles))
10455                     "this article")))
10456          (to-newsgroup
10457           (cond
10458            ((null split-name)
10459             (gnus-completing-read-with-default
10460              default prom
10461              gnus-active-hashtb
10462              'gnus-valid-move-group-p
10463              nil prefix
10464              'gnus-group-history))
10465            ((= 1 (length split-name))
10466             (gnus-completing-read-with-default
10467              (car split-name) prom
10468              gnus-active-hashtb
10469              'gnus-valid-move-group-p
10470              nil nil
10471              'gnus-group-history))
10472            (t
10473             (gnus-completing-read-with-default
10474              nil prom
10475              (mapcar (lambda (el) (list el))
10476                      (nreverse split-name))
10477              nil nil nil
10478              'gnus-group-history))))
10479          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10480     (when to-newsgroup
10481       (if (or (string= to-newsgroup "")
10482               (string= to-newsgroup prefix))
10483           (setq to-newsgroup default))
10484       (unless to-newsgroup
10485         (error "No group name entered"))
10486       (or (gnus-active to-newsgroup)
10487           (gnus-activate-group to-newsgroup nil nil to-method)
10488           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10489                                      to-newsgroup))
10490               (or (and (gnus-request-create-group to-newsgroup to-method)
10491                        (gnus-activate-group
10492                         to-newsgroup nil nil to-method)
10493                        (gnus-subscribe-group to-newsgroup))
10494                   (error "Couldn't create group %s" to-newsgroup)))
10495           (error "No such group: %s" to-newsgroup)))
10496     to-newsgroup))
10497
10498 (defun gnus-summary-save-parts (type dir n &optional reverse)
10499   "Save parts matching TYPE to DIR.
10500 If REVERSE, save parts that do not match TYPE."
10501   (interactive
10502    (list (read-string "Save parts of type: "
10503                       (or (car gnus-summary-save-parts-type-history)
10504                           gnus-summary-save-parts-default-mime)
10505                       'gnus-summary-save-parts-type-history)
10506          (setq gnus-summary-save-parts-last-directory
10507                (read-file-name "Save to directory: "
10508                                gnus-summary-save-parts-last-directory
10509                                nil t))
10510          current-prefix-arg))
10511   (gnus-summary-iterate n
10512     (let ((gnus-display-mime-function nil)
10513           (gnus-inhibit-treatment t))
10514       (gnus-summary-select-article))
10515     (save-excursion
10516       (set-buffer gnus-article-buffer)
10517       (let ((handles (or gnus-article-mime-handles
10518                          (mm-dissect-buffer nil gnus-article-loose-mime)
10519                          (mm-uu-dissect))))
10520         (when handles
10521           (gnus-summary-save-parts-1 type dir handles reverse)
10522           (unless gnus-article-mime-handles ;; Don't destroy this case.
10523             (mm-destroy-parts handles)))))))
10524
10525 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10526   (if (stringp (car handle))
10527       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10528               (cdr handle))
10529     (when (if reverse
10530               (not (string-match type (mm-handle-media-type handle)))
10531             (string-match type (mm-handle-media-type handle)))
10532       (let ((file (expand-file-name
10533                    (file-name-nondirectory
10534                     (or
10535                      (mail-content-type-get
10536                       (mm-handle-disposition handle) 'filename)
10537                      (concat gnus-newsgroup-name
10538                              "." (number-to-string
10539                                   (cdr gnus-article-current)))))
10540                    dir)))
10541         (unless (file-exists-p file)
10542           (mm-save-part-to-file handle file))))))
10543
10544 ;; Summary extract commands
10545
10546 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10547   (let ((buffer-read-only nil)
10548         (article (gnus-summary-article-number))
10549         after-article b e)
10550     (unless (gnus-summary-goto-subject article)
10551       (error "No such article: %d" article))
10552     (gnus-summary-position-point)
10553     ;; If all commands are to be bunched up on one line, we collect
10554     ;; them here.
10555     (unless gnus-view-pseudos-separately
10556       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10557             files action)
10558         (while ps
10559           (setq action (cdr (assq 'action (car ps))))
10560           (setq files (list (cdr (assq 'name (car ps)))))
10561           (while (and ps (cdr ps)
10562                       (string= (or action "1")
10563                                (or (cdr (assq 'action (cadr ps))) "2")))
10564             (push (cdr (assq 'name (cadr ps))) files)
10565             (setcdr ps (cddr ps)))
10566           (when files
10567             (when (not (string-match "%s" action))
10568               (push " " files))
10569             (push " " files)
10570             (when (assq 'execute (car ps))
10571               (setcdr (assq 'execute (car ps))
10572                       (funcall (if (string-match "%s" action)
10573                                    'format 'concat)
10574                                action
10575                                (mapconcat
10576                                 (lambda (f)
10577                                   (if (equal f " ")
10578                                       f
10579                                     (gnus-quote-arg-for-sh-or-csh f)))
10580                                 files " ")))))
10581           (setq ps (cdr ps)))))
10582     (if (and gnus-view-pseudos (not not-view))
10583         (while pslist
10584           (when (assq 'execute (car pslist))
10585             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10586                                   (eq gnus-view-pseudos 'not-confirm)))
10587           (setq pslist (cdr pslist)))
10588       (save-excursion
10589         (while pslist
10590           (setq after-article (or (cdr (assq 'article (car pslist)))
10591                                   (gnus-summary-article-number)))
10592           (gnus-summary-goto-subject after-article)
10593           (forward-line 1)
10594           (setq b (point))
10595           (insert "    " (file-name-nondirectory
10596                           (cdr (assq 'name (car pslist))))
10597                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10598           (setq e (point))
10599           (forward-line -1)             ; back to `b'
10600           (gnus-add-text-properties
10601            b (1- e) (list 'gnus-number gnus-reffed-article-number
10602                           gnus-mouse-face-prop gnus-mouse-face))
10603           (gnus-data-enter
10604            after-article gnus-reffed-article-number
10605            gnus-unread-mark b (car pslist) 0 (- e b))
10606           (setq gnus-newsgroup-unreads
10607                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10608                                          gnus-reffed-article-number))
10609           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10610           (setq pslist (cdr pslist)))))))
10611
10612 (defun gnus-pseudos< (p1 p2)
10613   (let ((c1 (cdr (assq 'action p1)))
10614         (c2 (cdr (assq 'action p2))))
10615     (and c1 c2 (string< c1 c2))))
10616
10617 (defun gnus-request-pseudo-article (props)
10618   (cond ((assq 'execute props)
10619          (gnus-execute-command (cdr (assq 'execute props)))))
10620   (let ((gnus-current-article (gnus-summary-article-number)))
10621     (gnus-run-hooks 'gnus-mark-article-hook)))
10622
10623 (defun gnus-execute-command (command &optional automatic)
10624   (save-excursion
10625     (gnus-article-setup-buffer)
10626     (set-buffer gnus-article-buffer)
10627     (setq buffer-read-only nil)
10628     (let ((command (if automatic command
10629                      (read-string "Command: " (cons command 0)))))
10630       (erase-buffer)
10631       (insert "$ " command "\n\n")
10632       (if gnus-view-pseudo-asynchronously
10633           (start-process "gnus-execute" (current-buffer) shell-file-name
10634                          shell-command-switch command)
10635         (call-process shell-file-name nil t nil
10636                       shell-command-switch command)))))
10637
10638 ;; Summary kill commands.
10639
10640 (defun gnus-summary-edit-global-kill (article)
10641   "Edit the \"global\" kill file."
10642   (interactive (list (gnus-summary-article-number)))
10643   (gnus-group-edit-global-kill article))
10644
10645 (defun gnus-summary-edit-local-kill ()
10646   "Edit a local kill file applied to the current newsgroup."
10647   (interactive)
10648   (setq gnus-current-headers (gnus-summary-article-header))
10649   (gnus-group-edit-local-kill
10650    (gnus-summary-article-number) gnus-newsgroup-name))
10651
10652 ;;; Header reading.
10653
10654 (defun gnus-read-header (id &optional header)
10655   "Read the headers of article ID and enter them into the Gnus system."
10656   (let ((group gnus-newsgroup-name)
10657         (gnus-override-method
10658          (or
10659           gnus-override-method
10660           (and (gnus-news-group-p gnus-newsgroup-name)
10661                (car (gnus-refer-article-methods)))))
10662         where)
10663     ;; First we check to see whether the header in question is already
10664     ;; fetched.
10665     (if (stringp id)
10666         ;; This is a Message-ID.
10667         (setq header (or header (gnus-id-to-header id)))
10668       ;; This is an article number.
10669       (setq header (or header (gnus-summary-article-header id))))
10670     (if (and header
10671              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10672         ;; We have found the header.
10673         header
10674       ;; If this is a sparse article, we have to nix out its
10675       ;; previous entry in the thread hashtb.
10676       (when (and header
10677                  (gnus-summary-article-sparse-p (mail-header-number header)))
10678         (let* ((parent (gnus-parent-id (mail-header-references header)))
10679                (thread (and parent (gnus-id-to-thread parent))))
10680           (when thread
10681             (delq (assq header thread) thread))))
10682       ;; We have to really fetch the header to this article.
10683       (save-excursion
10684         (set-buffer nntp-server-buffer)
10685         (when (setq where (gnus-request-head id group))
10686           (nnheader-fold-continuation-lines)
10687           (goto-char (point-max))
10688           (insert ".\n")
10689           (goto-char (point-min))
10690           (insert "211 ")
10691           (princ (cond
10692                   ((numberp id) id)
10693                   ((cdr where) (cdr where))
10694                   (header (mail-header-number header))
10695                   (t gnus-reffed-article-number))
10696                  (current-buffer))
10697           (insert " Article retrieved.\n"))
10698         (if (or (not where)
10699                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10700             ()                          ; Malformed head.
10701           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10702             (when (and (stringp id)
10703                        (not (string= (gnus-group-real-name group)
10704                                      (car where))))
10705               ;; If we fetched by Message-ID and the article came
10706               ;; from a different group, we fudge some bogus article
10707               ;; numbers for this article.
10708               (mail-header-set-number header gnus-reffed-article-number))
10709             (save-excursion
10710               (set-buffer gnus-summary-buffer)
10711               (decf gnus-reffed-article-number)
10712               (gnus-remove-header (mail-header-number header))
10713               (push header gnus-newsgroup-headers)
10714               (setq gnus-current-headers header)
10715               (push (mail-header-number header) gnus-newsgroup-limit)))
10716           header)))))
10717
10718 (defun gnus-remove-header (number)
10719   "Remove header NUMBER from `gnus-newsgroup-headers'."
10720   (if (and gnus-newsgroup-headers
10721            (= number (mail-header-number (car gnus-newsgroup-headers))))
10722       (pop gnus-newsgroup-headers)
10723     (let ((headers gnus-newsgroup-headers))
10724       (while (and (cdr headers)
10725                   (not (= number (mail-header-number (cadr headers)))))
10726         (pop headers))
10727       (when (cdr headers)
10728         (setcdr headers (cddr headers))))))
10729
10730 ;;;
10731 ;;; summary highlights
10732 ;;;
10733
10734 (defun gnus-highlight-selected-summary ()
10735   "Highlight selected article in summary buffer."
10736   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10737   (when gnus-summary-selected-face
10738     (save-excursion
10739       (let* ((beg (progn (beginning-of-line) (point)))
10740              (end (progn (end-of-line) (point)))
10741              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10742              (from (if (get-text-property beg gnus-mouse-face-prop)
10743                        beg
10744                      (or (next-single-property-change
10745                           beg gnus-mouse-face-prop nil end)
10746                          beg)))
10747              (to
10748               (if (= from end)
10749                   (- from 2)
10750                 (or (next-single-property-change
10751                      from gnus-mouse-face-prop nil end)
10752                     end))))
10753         ;; If no mouse-face prop on line we will have to = from = end,
10754         ;; so we highlight the entire line instead.
10755         (when (= (+ to 2) from)
10756           (setq from beg)
10757           (setq to end))
10758         (if gnus-newsgroup-selected-overlay
10759             ;; Move old overlay.
10760             (gnus-move-overlay
10761              gnus-newsgroup-selected-overlay from to (current-buffer))
10762           ;; Create new overlay.
10763           (gnus-overlay-put
10764            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10765            'face gnus-summary-selected-face))))))
10766
10767 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10768 (defun gnus-summary-highlight-line ()
10769   "Highlight current line according to `gnus-summary-highlight'."
10770   (let* ((list gnus-summary-highlight)
10771          (beg (gnus-point-at-bol))
10772          (article (gnus-summary-article-number))
10773          (score (or (cdr (assq (or article gnus-current-article)
10774                                gnus-newsgroup-scored))
10775                     gnus-summary-default-score 0))
10776          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10777          (inhibit-read-only t)
10778          (default gnus-summary-default-score)
10779          (default-high gnus-summary-default-high-score)
10780          (default-low gnus-summary-default-low-score))
10781     ;; Eval the cars of the lists until we find a match.
10782     (while (and list
10783                 (not (eval (caar list))))
10784       (setq list (cdr list)))
10785     (let ((face (cdar list)))
10786       (unless (eq face (get-text-property beg 'face))
10787         (gnus-put-text-property-excluding-characters-with-faces
10788          beg (gnus-point-at-eol) 'face
10789          (setq face (if (boundp face) (symbol-value face) face)))
10790         (when gnus-summary-highlight-line-function
10791           (funcall gnus-summary-highlight-line-function article face))))))
10792
10793 (defun gnus-update-read-articles (group unread &optional compute)
10794   "Update the list of read articles in GROUP.
10795 UNREAD is a sorted list."
10796   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10797          (entry (gnus-gethash group gnus-newsrc-hashtb))
10798          (info (nth 2 entry))
10799          (prev 1)
10800          read)
10801     (if (or (not info) (not active))
10802         ;; There is no info on this group if it was, in fact,
10803         ;; killed.  Gnus stores no information on killed groups, so
10804         ;; there's nothing to be done.
10805         ;; One could store the information somewhere temporarily,
10806         ;; perhaps...  Hmmm...
10807         ()
10808       ;; Remove any negative articles numbers.
10809       (while (and unread (< (car unread) 0))
10810         (setq unread (cdr unread)))
10811       ;; Remove any expired article numbers
10812       (while (and unread (< (car unread) (car active)))
10813         (setq unread (cdr unread)))
10814       ;; Compute the ranges of read articles by looking at the list of
10815       ;; unread articles.
10816       (while unread
10817         (when (/= (car unread) prev)
10818           (push (if (= prev (1- (car unread))) prev
10819                   (cons prev (1- (car unread))))
10820                 read))
10821         (setq prev (1+ (car unread)))
10822         (setq unread (cdr unread)))
10823       (when (<= prev (cdr active))
10824         (push (cons prev (cdr active)) read))
10825       (setq read (if (> (length read) 1) (nreverse read) read))
10826       (if compute
10827           read
10828         (save-excursion
10829           (let (setmarkundo)
10830             ;; Propagate the read marks to the backend.
10831             (when (gnus-check-backend-function 'request-set-mark group)
10832               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10833                     (add (gnus-remove-from-range read (gnus-info-read info))))
10834                 (when (or add del)
10835                   (unless (gnus-check-group group)
10836                     (error "Can't open server for %s" group))
10837                   (gnus-request-set-mark
10838                    group (delq nil (list (if add (list add 'add '(read)))
10839                                          (if del (list del 'del '(read))))))
10840                   (setq setmarkundo
10841                         `(gnus-request-set-mark
10842                           ,group
10843                           ',(delq nil (list
10844                                        (if del (list del 'add '(read)))
10845                                        (if add (list add 'del '(read))))))))))
10846             (set-buffer gnus-group-buffer)
10847             (gnus-undo-register
10848               `(progn
10849                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10850                  (gnus-info-set-read ',info ',(gnus-info-read info))
10851                  (gnus-get-unread-articles-in-group ',info
10852                                                     (gnus-active ,group))
10853                  (gnus-group-update-group ,group t)
10854                  ,setmarkundo))))
10855         ;; Enter this list into the group info.
10856         (gnus-info-set-read info read)
10857         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10858         (gnus-get-unread-articles-in-group info (gnus-active group))
10859         t))))
10860
10861 (defun gnus-offer-save-summaries ()
10862   "Offer to save all active summary buffers."
10863   (let (buffers)
10864     ;; Go through all buffers and find all summaries.
10865     (dolist (buffer (buffer-list))
10866       (when (and (setq buffer (buffer-name buffer))
10867                  (string-match "Summary" buffer)
10868                  (save-excursion
10869                    (set-buffer buffer)
10870                    ;; We check that this is, indeed, a summary buffer.
10871                    (and (eq major-mode 'gnus-summary-mode)
10872                         ;; Also make sure this isn't bogus.
10873                         gnus-newsgroup-prepared
10874                         ;; Also make sure that this isn't a
10875                         ;; dead summary buffer.
10876                         (not gnus-dead-summary-mode))))
10877         (push buffer buffers)))
10878     ;; Go through all these summary buffers and offer to save them.
10879     (when buffers
10880       (save-excursion
10881         (map-y-or-n-p
10882          "Update summary buffer %s? "
10883          (lambda (buf)
10884            (switch-to-buffer buf)
10885            (gnus-summary-exit))
10886          buffers)))))
10887
10888
10889 ;;; @ for mime-partial
10890 ;;;
10891
10892 (defun gnus-request-partial-message ()
10893   (save-excursion
10894     (let ((number (gnus-summary-article-number))
10895           (group gnus-newsgroup-name)
10896           (mother gnus-article-buffer))
10897       (set-buffer (get-buffer-create " *Partial Article*"))
10898       (erase-buffer)
10899       (setq mime-preview-buffer mother)
10900       (gnus-request-article-this-buffer number group)
10901       (mime-parse-buffer)
10902       )))
10903
10904 (autoload 'mime-combine-message/partial-pieces-automatically
10905   "mime-partial"
10906   "Internal method to combine message/partial messages automatically.")
10907
10908 (mime-add-condition
10909  'action '((type . message)(subtype . partial)
10910            (major-mode . gnus-original-article-mode)
10911            (method . mime-combine-message/partial-pieces-automatically)
10912            (summary-buffer-exp . gnus-summary-buffer)
10913            (request-partial-message-method . gnus-request-partial-message)
10914            ))
10915
10916
10917 ;;; @ for message/rfc822
10918 ;;;
10919
10920 (defun gnus-mime-extract-message/rfc822 (entity situation)
10921   "Burst a forwarded article."
10922   (save-excursion
10923     (set-buffer gnus-summary-buffer)
10924     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10925                                    gnus-newsgroup-name 'gnus-group-history))
10926            (gnus-group-marked (list group))
10927            article info)
10928       (with-temp-buffer
10929         (mime-insert-entity-content entity)
10930         (setq article (gnus-request-accept-article group)))
10931       (when (and (consp article)
10932                  (numberp (setq article (cdr article))))
10933         (setq info (gnus-get-info group))
10934         (gnus-info-set-read info
10935                             (gnus-remove-from-range (gnus-info-read info)
10936                                                     (list article)))
10937         (when (string-equal group gnus-newsgroup-name)
10938           (forward-line 1)
10939           (let (gnus-show-threads)
10940             (gnus-summary-goto-subject article t))
10941           (gnus-summary-clear-mark-forward 1))
10942         (set-buffer gnus-group-buffer)
10943         (gnus-group-get-new-news-this-group nil t)))))
10944
10945 (mime-add-condition
10946  'action '((type . message)(subtype . rfc822)
10947            (major-mode . gnus-original-article-mode)
10948            (method . gnus-mime-extract-message/rfc822)
10949            (mode . "extract")
10950            ))
10951
10952 (mime-add-condition
10953  'action '((type . message)(subtype . news)
10954            (major-mode . gnus-original-article-mode)
10955            (method . gnus-mime-extract-message/rfc822)
10956            (mode . "extract")
10957            ))
10958
10959 (defun gnus-mime-extract-multipart (entity situation)
10960   (let ((children (mime-entity-children entity))
10961         mime-acting-situation-to-override
10962         f)
10963     (while children
10964       (mime-play-entity (car children)
10965                         (cons (assq 'mode situation)
10966                               mime-acting-situation-to-override))
10967       (setq children (cdr children)))
10968     (if (setq f (cdr (assq 'after-method
10969                            mime-acting-situation-to-override)))
10970         (eval f)
10971       )))
10972
10973 (mime-add-condition
10974  'action '((type . multipart)
10975            (method . gnus-mime-extract-multipart)
10976            (mode . "extract")
10977            )
10978  'with-default)
10979
10980
10981 ;;; @ end
10982 ;;;
10983
10984 (defun gnus-summary-setup-default-charset ()
10985   "Setup newsgroup default charset."
10986   (if (equal gnus-newsgroup-name "nndraft:drafts")
10987       (setq gnus-newsgroup-charset nil)
10988     (let* ((ignored-charsets
10989             (or gnus-newsgroup-ephemeral-ignored-charsets
10990                 (append
10991                  (and gnus-newsgroup-name
10992                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10993                  gnus-newsgroup-ignored-charsets))))
10994       (setq gnus-newsgroup-charset
10995             (or gnus-newsgroup-ephemeral-charset
10996                 (and gnus-newsgroup-name
10997                      (gnus-parameter-charset gnus-newsgroup-name))
10998                 gnus-default-charset))
10999       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11000            ignored-charsets))))
11001
11002 ;;;
11003 ;;; Mime Commands
11004 ;;;
11005
11006 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11007   "Display the current article buffer fully MIME-buttonized.
11008 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11009 treated as multipart/mixed."
11010   (interactive "P")
11011   (require 'gnus-art)
11012   (let ((gnus-unbuttonized-mime-types nil)
11013         (gnus-mime-display-multipart-as-mixed show-all-parts))
11014     (gnus-summary-show-article)))
11015
11016 (defun gnus-summary-repair-multipart (article)
11017   "Add a Content-Type header to a multipart article without one."
11018   (interactive (list (gnus-summary-article-number)))
11019   (gnus-with-article article
11020     (message-narrow-to-head)
11021     (message-remove-header "Mime-Version")
11022     (goto-char (point-max))
11023     (insert "Mime-Version: 1.0\n")
11024     (widen)
11025     (when (search-forward "\n--" nil t)
11026       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11027         (message-narrow-to-head)
11028         (message-remove-header "Content-Type")
11029         (goto-char (point-max))
11030         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11031                         separator))
11032         (widen))))
11033   (let (gnus-mark-article-hook)
11034     (gnus-summary-select-article t t nil article)))
11035
11036 (defun gnus-summary-toggle-display-buttonized ()
11037   "Toggle the buttonizing of the article buffer."
11038   (interactive)
11039   (require 'gnus-art)
11040   (if (setq gnus-inhibit-mime-unbuttonizing
11041             (not gnus-inhibit-mime-unbuttonizing))
11042       (let ((gnus-unbuttonized-mime-types nil))
11043         (gnus-summary-show-article))
11044     (gnus-summary-show-article)))
11045
11046 ;;;
11047 ;;; Intelli-mouse commmands
11048 ;;;
11049
11050 (defun gnus-wheel-summary-scroll (event)
11051   (interactive "e")
11052   (let ((amount (if (memq 'shift (event-modifiers event))
11053                     (car gnus-wheel-scroll-amount)
11054                   (cdr gnus-wheel-scroll-amount)))
11055         (direction (- (* (static-if (featurep 'xemacs)
11056                              (event-button event)
11057                            (cond ((eq 'mouse-4 (event-basic-type event))
11058                                   4)
11059                                  ((eq 'mouse-5 (event-basic-type event))
11060                                   5)))
11061                          2) 9))
11062         edge)
11063     (gnus-summary-scroll-up (* amount direction))
11064     (when (gnus-eval-in-buffer-window gnus-article-buffer
11065             (save-restriction
11066               (widen)
11067               (and (if (< 0 direction)
11068                        (gnus-article-next-page 0)
11069                      (gnus-article-prev-page 0)
11070                      (bobp))
11071                    (if (setq edge (get-text-property
11072                                    (point-min) 'gnus-wheel-edge))
11073                        (setq edge (* edge direction))
11074                      (setq edge -1))
11075                    (or (plusp edge)
11076                        (let ((buffer-read-only nil)
11077                              (inhibit-read-only t))
11078                          (put-text-property (point-min) (point-max)
11079                                             'gnus-wheel-edge direction)
11080                          nil))
11081                    (or (> edge gnus-wheel-edge-resistance)
11082                        (let ((buffer-read-only nil)
11083                              (inhibit-read-only t))
11084                          (put-text-property (point-min) (point-max)
11085                                             'gnus-wheel-edge
11086                                             (* (1+ edge) direction))
11087                          nil))
11088                    (eq last-command 'gnus-wheel-summary-scroll))))
11089       (gnus-summary-next-article nil nil (minusp direction)))))
11090
11091 (defun gnus-wheel-install ()
11092   "Enable mouse wheel support on summary window."
11093   (when gnus-use-wheel
11094     (let ((keys
11095            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11096       (dolist (key keys)
11097         (define-key gnus-summary-mode-map key
11098           'gnus-wheel-summary-scroll)))))
11099
11100 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11101
11102 ;;;
11103 ;;; Traditional PGP commmands
11104 ;;;
11105
11106 (defun gnus-summary-decrypt-article (&optional force)
11107   "Decrypt the current article in traditional PGP way.
11108 This will have permanent effect only in mail groups.
11109 If FORCE is non-nil, allow editing of articles even in read-only
11110 groups."
11111   (interactive "P")
11112   (gnus-summary-select-article t)
11113   (gnus-eval-in-buffer-window gnus-article-buffer
11114     (save-excursion
11115       (save-restriction
11116         (widen)
11117         (goto-char (point-min))
11118         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11119           (error "Not a traditional PGP message!"))
11120         (let ((armor-start (match-beginning 0)))
11121           (if (and (pgg-decrypt-region armor-start (point-max))
11122                    (or force (not (gnus-group-read-only-p))))
11123               (let ((inhibit-read-only t)
11124                     buffer-read-only)
11125                 (delete-region armor-start
11126                                (progn
11127                                  (re-search-forward "^-+END PGP" nil t)
11128                                  (beginning-of-line 2)
11129                                  (point)))
11130                 (insert-buffer-substring pgg-output-buffer))))))))
11131
11132 (defun gnus-summary-verify-article ()
11133   "Verify the current article in traditional PGP way."
11134   (interactive)
11135   (save-excursion
11136     (set-buffer gnus-original-article-buffer)
11137     (goto-char (point-min))
11138     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11139       (error "Not a traditional PGP message!"))
11140     (re-search-forward "^-+END PGP" nil t)
11141     (beginning-of-line 2)
11142     (call-interactively (function pgg-verify-region))))
11143
11144 ;;;
11145 ;;; Generic summary marking commands
11146 ;;;
11147
11148 (defvar gnus-summary-marking-alist
11149   '((read gnus-del-mark "d")
11150     (unread gnus-unread-mark "u")
11151     (ticked gnus-ticked-mark "!")
11152     (dormant gnus-dormant-mark "?")
11153     (expirable gnus-expirable-mark "e"))
11154   "An alist of names/marks/keystrokes.")
11155
11156 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11157 (defvar gnus-summary-mark-map)
11158
11159 (defun gnus-summary-make-all-marking-commands ()
11160   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11161   (dolist (elem gnus-summary-marking-alist)
11162     (apply 'gnus-summary-make-marking-command elem)))
11163
11164 (defun gnus-summary-make-marking-command (name mark keystroke)
11165   (let ((map (make-sparse-keymap)))
11166     (define-key gnus-summary-generic-mark-map keystroke map)
11167     (dolist (lway `((next "next" next nil "n")
11168                     (next-unread "next unread" next t "N")
11169                     (prev "previous" prev nil "p")
11170                     (prev-unread "previous unread" prev t "P")
11171                     (nomove "" nil nil ,keystroke)))
11172       (let ((func (gnus-summary-make-marking-command-1
11173                    mark (car lway) lway name)))
11174         (setq func (eval func))
11175         (define-key map (nth 4 lway) func)))))
11176
11177 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11178   `(defun ,(intern
11179             (format "gnus-summary-put-mark-as-%s%s"
11180                     name (if (eq way 'nomove)
11181                              ""
11182                            (concat "-" (symbol-name way)))))
11183      (n)
11184      ,(format
11185        "Mark the current article as %s%s.
11186 If N, the prefix, then repeat N times.
11187 If N is negative, move in reverse order.
11188 The difference between N and the actual number of articles marked is
11189 returned."
11190        name (car (cdr lway)))
11191      (interactive "p")
11192      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11193
11194 (defun gnus-summary-generic-mark (n mark move unread)
11195   "Mark N articles with MARK."
11196   (unless (eq major-mode 'gnus-summary-mode)
11197     (error "This command can only be used in the summary buffer"))
11198   (gnus-summary-show-thread)
11199   (let ((nummove
11200          (cond
11201           ((eq move 'next) 1)
11202           ((eq move 'prev) -1)
11203           (t 0))))
11204     (if (zerop nummove)
11205         (setq n 1)
11206       (when (< n 0)
11207         (setq n (abs n)
11208               nummove (* -1 nummove))))
11209     (while (and (> n 0)
11210                 (gnus-summary-mark-article nil mark)
11211                 (zerop (gnus-summary-next-subject nummove unread t)))
11212       (setq n (1- n)))
11213     (when (/= 0 n)
11214       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11215     (gnus-summary-recenter)
11216     (gnus-summary-position-point)
11217     (gnus-set-mode-line 'summary)
11218     n))
11219
11220 (defun gnus-summary-insert-articles (articles)
11221   (when (setq articles
11222               (gnus-sorted-difference articles
11223                                       (mapcar (lambda (h)
11224                                                 (mail-header-number h))
11225                                               gnus-newsgroup-headers)))
11226     (setq gnus-newsgroup-headers
11227           (merge 'list
11228                  gnus-newsgroup-headers
11229                  (gnus-fetch-headers articles)
11230                  'gnus-article-sort-by-number))
11231     ;; Suppress duplicates?
11232     (when gnus-suppress-duplicates
11233       (gnus-dup-suppress-articles))
11234
11235     ;; We might want to build some more threads first.
11236     (when (and gnus-fetch-old-headers
11237                (eq gnus-headers-retrieved-by 'nov))
11238       (if (eq gnus-fetch-old-headers 'invisible)
11239           (gnus-build-all-threads)
11240         (gnus-build-old-threads)))
11241     ;; Let the Gnus agent mark articles as read.
11242     (when gnus-agent
11243       (gnus-agent-get-undownloaded-list))
11244     ;; Remove list identifiers from subject
11245     (when gnus-list-identifiers
11246       (gnus-summary-remove-list-identifiers))
11247     ;; First and last article in this newsgroup.
11248     (when gnus-newsgroup-headers
11249       (setq gnus-newsgroup-begin
11250             (mail-header-number (car gnus-newsgroup-headers))
11251             gnus-newsgroup-end
11252             (mail-header-number
11253              (gnus-last-element gnus-newsgroup-headers))))
11254     (when gnus-use-scoring
11255       (gnus-possibly-score-headers))))
11256
11257 (defun gnus-summary-insert-old-articles (&optional all)
11258   "Insert all old articles in this group.
11259 If ALL is non-nil, already read articles become readable.
11260 If ALL is a number, fetch this number of articles."
11261   (interactive "P")
11262   (prog1
11263       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11264             older len)
11265         (setq older
11266               (gnus-sorted-difference
11267                (gnus-uncompress-range (list gnus-newsgroup-active))
11268                old))
11269         (setq len (length older))
11270         (cond
11271          ((null older) nil)
11272          ((numberp all)
11273           (if (< all len)
11274               (setq older (last older all))))
11275          (all nil)
11276          (t
11277           (if (and (numberp gnus-large-newsgroup)
11278                    (> len gnus-large-newsgroup))
11279               (let* ((cursor-in-echo-area nil)
11280                      (initial (gnus-parameter-large-newsgroup-initial 
11281                                gnus-newsgroup-name))
11282                      (input
11283                       (read-string
11284                        (format
11285                         "How many articles from %s (%s %d): "
11286                         (gnus-limit-string
11287                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11288                         (if initial "max" "default")
11289                         len)
11290                        (if initial
11291                            (cons (number-to-string initial)
11292                                  0)))))
11293                 (unless (string-match "^[ \t]*$" input)
11294                   (setq all (string-to-number input))
11295                   (if (< all len)
11296                       (setq older (last older all))))))))
11297         (if (not older)
11298             (message "No old news.")
11299           (gnus-summary-insert-articles older)
11300           (gnus-summary-limit (gnus-sorted-nunion old older))))
11301     (gnus-summary-position-point)))
11302
11303 (defun gnus-summary-insert-new-articles ()
11304   "Insert all new articles in this group."
11305   (interactive)
11306   (prog1
11307       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11308             (old-active gnus-newsgroup-active)
11309             (nnmail-fetched-sources (list t))
11310             i new)
11311         (setq gnus-newsgroup-active
11312               (gnus-activate-group gnus-newsgroup-name 'scan))
11313         (setq i (1+ (cdr old-active)))
11314         (while (<= i (cdr gnus-newsgroup-active))
11315           (push i new)
11316           (incf i))
11317         (if (not new)
11318             (message "No gnus is bad news.")
11319           (setq new (nreverse new))
11320           (gnus-summary-insert-articles new)
11321           (setq gnus-newsgroup-unreads
11322                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11323           (gnus-summary-limit (gnus-sorted-nunion old new))))
11324     (gnus-summary-position-point)))
11325
11326 (gnus-summary-make-all-marking-commands)
11327
11328 (gnus-ems-redefine)
11329
11330 (provide 'gnus-sum)
11331
11332 (run-hooks 'gnus-sum-load-hook)
11333
11334 ;;; gnus-sum.el ends here