1;;; gnus-sum.el --- summary mode commands for Gnus
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING.  If not, write to the
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
25
26;;; Commentary:
27
28;;; Code:
29
30(eval-when-compile
31  (require 'cl)
32  (defvar tool-bar-mode))
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 'gmm-utils)
42(require 'mm-decode)
43(require 'nnoo)
44
45(autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46(autoload 'gnus-cache-write-active "gnus-cache")
47(autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48(autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49(autoload 'gnus-pick-line-number "gnus-salt" nil t)
50(autoload 'mm-uu-dissect "mm-uu")
51(autoload 'gnus-article-outlook-deuglify-article "deuglify"
52  "Deuglify broken Outlook (Express) articles and redisplay."
53  t)
54(autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55(autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56(autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58(defcustom gnus-kill-summary-on-exit t
59  "*If non-nil, kill the summary buffer when you exit from it.
60If nil, the summary will become a \"*Dead Summary*\" buffer, and
61it will be killed sometime later."
62  :group 'gnus-summary-exit
63  :type 'boolean)
64
65(defcustom gnus-fetch-old-headers nil
66  "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67If an unread article in the group refers to an older, already read (or
68just marked as read) article, the old article will not normally be
69displayed in the Summary buffer.  If this variable is t, Gnus
70will attempt to grab the headers to the old articles, and thereby
71build complete threads.  If it has the value `some', only enough
72headers to connect otherwise loose threads will be displayed.  This
73variable can also be a number.  In that case, no more than that number
74of old headers will be fetched.  If it has the value `invisible', all
75old headers will be fetched, but none will be displayed.
76
77The server has to support NOV for any of this to work."
78  :group 'gnus-thread
79  :type '(choice (const :tag "off" nil)
80		 (const :tag "on" t)
81		 (const some)
82		 (const invisible)
83		 number
84		 (sexp :menu-tag "other" t)))
85
86(defcustom gnus-refer-thread-limit 200
87  "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
88If t, fetch all the available old headers."
89  :group 'gnus-thread
90  :type '(choice number
91		 (sexp :menu-tag "other" t)))
92
93(defcustom gnus-summary-make-false-root 'adopt
94  "*nil means that Gnus won't gather loose threads.
95If the root of a thread has expired or been read in a previous
96session, the information necessary to build a complete thread has been
97lost.  Instead of having many small sub-threads from this original thread
98scattered all over the summary buffer, Gnus can gather them.
99
100If non-nil, Gnus will try to gather all loose sub-threads from an
101original thread into one large thread.
102
103If this variable is non-nil, it should be one of `none', `adopt',
104`dummy' or `empty'.
105
106If this variable is `none', Gnus will not make a false root, but just
107present the sub-threads after another.
108If this variable is `dummy', Gnus will create a dummy root that will
109have all the sub-threads as children.
110If this variable is `adopt', Gnus will make one of the \"children\"
111the parent and mark all the step-children as such.
112If this variable is `empty', the \"children\" are printed with empty
113subject fields.  (Or rather, they will be printed with a string
114given by the `gnus-summary-same-subject' variable.)"
115  :group 'gnus-thread
116  :type '(choice (const :tag "off" nil)
117		 (const none)
118		 (const dummy)
119		 (const adopt)
120		 (const empty)))
121
122(defcustom gnus-summary-make-false-root-always nil
123  "Always make a false dummy root."
124  :version "22.1"
125  :group 'gnus-thread
126  :type 'boolean)
127
128(defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
129  "*A regexp to match subjects to be excluded from loose thread gathering.
130As loose thread gathering is done on subjects only, that means that
131there can be many false gatherings performed.  By rooting out certain
132common subjects, gathering might become saner."
133  :group 'gnus-thread
134  :type 'regexp)
135
136(defcustom gnus-summary-gather-subject-limit nil
137  "*Maximum length of subject comparisons when gathering loose threads.
138Use nil to compare full subjects.  Setting this variable to a low
139number will help gather threads that have been corrupted by
140newsreaders chopping off subject lines, but it might also mean that
141unrelated articles that have subject that happen to begin with the
142same few characters will be incorrectly gathered.
143
144If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
145comparing subjects."
146  :group 'gnus-thread
147  :type '(choice (const :tag "off" nil)
148		 (const fuzzy)
149		 (sexp :menu-tag "on" t)))
150
151(defcustom gnus-simplify-subject-functions nil
152  "List of functions taking a string argument that simplify subjects.
153The functions are applied recursively.
154
155Useful functions to put in this list include:
156`gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
157`gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
158  :group 'gnus-thread
159  :type '(repeat function))
160
161(defcustom gnus-simplify-ignored-prefixes nil
162  "*Remove matches for this regexp from subject lines when simplifying fuzzily."
163  :group 'gnus-thread
164  :type '(choice (const :tag "off" nil)
165		 regexp))
166
167(defcustom gnus-build-sparse-threads nil
168  "*If non-nil, fill in the gaps in threads.
169If `some', only fill in the gaps that are needed to tie loose threads
170together.  If `more', fill in all leaf nodes that Gnus can find.  If
171non-nil and non-`some', fill in all gaps that Gnus manages to guess."
172  :group 'gnus-thread
173  :type '(choice (const :tag "off" nil)
174		 (const some)
175		 (const more)
176		 (sexp :menu-tag "all" t)))
177
178(defcustom gnus-summary-thread-gathering-function
179  'gnus-gather-threads-by-subject
180  "*Function used for gathering loose threads.
181There are two pre-defined functions: `gnus-gather-threads-by-subject',
182which only takes Subjects into consideration; and
183`gnus-gather-threads-by-references', which compared the References
184headers of the articles to find matches."
185  :group 'gnus-thread
186  :type '(radio (function-item gnus-gather-threads-by-subject)
187		(function-item gnus-gather-threads-by-references)
188		(function :tag "other")))
189
190(defcustom gnus-summary-same-subject ""
191  "*String indicating that the current article has the same subject as the previous.
192This variable will only be used if the value of
193`gnus-summary-make-false-root' is `empty'."
194  :group 'gnus-summary-format
195  :type 'string)
196
197(defcustom gnus-summary-goto-unread t
198  "*If t, many commands will go to the next unread article.
199This applies to marking commands as well as other commands that
200\"naturally\" select the next article, like, for instance, `SPC' at
201the end of an article.
202
203If nil, the marking commands do NOT go to the next unread article
204\(they go to the next article instead).  If `never', commands that
205usually go to the next unread article, will go to the next article,
206whether it is read or not."
207  :group 'gnus-summary-marks
208  :link '(custom-manual "(gnus)Setting Marks")
209  :type '(choice (const :tag "off" nil)
210		 (const never)
211		 (sexp :menu-tag "on" t)))
212
213(defcustom gnus-summary-default-score 0
214  "*Default article score level.
215All scores generated by the score files will be added to this score.
216If this variable is nil, scoring will be disabled."
217  :group 'gnus-score-default
218  :type '(choice (const :tag "disable")
219		 integer))
220
221(defcustom gnus-summary-default-high-score 0
222  "*Default threshold for a high scored article.
223An article will be highlighted as high scored if its score is greater
224than this score."
225  :version "22.1"
226  :group 'gnus-score-default
227  :type 'integer)
228
229(defcustom gnus-summary-default-low-score 0
230  "*Default threshold for a low scored article.
231An article will be highlighted as low scored if its score is smaller
232than this score."
233  :version "22.1"
234  :group 'gnus-score-default
235  :type 'integer)
236
237(defcustom gnus-summary-zcore-fuzz 0
238  "*Fuzziness factor for the zcore in the summary buffer.
239Articles with scores closer than this to `gnus-summary-default-score'
240will not be marked."
241  :group 'gnus-summary-format
242  :type 'integer)
243
244(defcustom gnus-simplify-subject-fuzzy-regexp nil
245  "*Strings to be removed when doing fuzzy matches.
246This can either be a regular expression or list of regular expressions
247that will be removed from subject strings if fuzzy subject
248simplification is selected."
249  :group 'gnus-thread
250  :type '(repeat regexp))
251
252(defcustom gnus-show-threads t
253  "*If non-nil, display threads in summary mode."
254  :group 'gnus-thread
255  :type 'boolean)
256
257(defcustom gnus-thread-hide-subtree nil
258  "*If non-nil, hide all threads initially.
259This can be a predicate specifier which says which threads to hide.
260If threads are hidden, you have to run the command
261`gnus-summary-show-thread' by hand or select an article."
262  :group 'gnus-thread
263  :type '(radio (sexp :format "Non-nil\n"
264		      :match (lambda (widget value)
265			       (not (or (consp value) (functionp value))))
266		      :value t)
267		(const nil)
268		(sexp :tag "Predicate specifier")))
269
270(defcustom gnus-thread-hide-killed t
271  "*If non-nil, hide killed threads automatically."
272  :group 'gnus-thread
273  :type 'boolean)
274
275(defcustom gnus-thread-ignore-subject t
276  "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
277If nil, articles that have different subjects from their parents will
278start separate threads."
279  :group 'gnus-thread
280  :type 'boolean)
281
282(defcustom gnus-thread-operation-ignore-subject t
283  "*If non-nil, subjects will be ignored when doing thread commands.
284This affects commands like `gnus-summary-kill-thread' and
285`gnus-summary-lower-thread'.
286
287If this variable is nil, articles in the same thread with different
288subjects will not be included in the operation in question.  If this
289variable is `fuzzy', only articles that have subjects that are fuzzily
290equal will be included."
291  :group 'gnus-thread
292  :type '(choice (const :tag "off" nil)
293		 (const fuzzy)
294		 (sexp :tag "on" t)))
295
296(defcustom gnus-thread-indent-level 4
297  "*Number that says how much each sub-thread should be indented."
298  :group 'gnus-thread
299  :type 'integer)
300
301(defcustom gnus-auto-extend-newsgroup t
302  "*If non-nil, extend newsgroup forward and backward when requested."
303  :group 'gnus-summary-choose
304  :type 'boolean)
305
306(defcustom gnus-auto-select-first t
307  "If non-nil, select an article on group entry.
308An article is selected automatically when entering a group
309e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
310`gnus-summary-catchup-and-goto-next-group'.
311
312Which article is selected is controlled by the variable
313`gnus-auto-select-subject'.
314
315If you want to prevent automatic selection of articles in some
316newsgroups, set the variable to nil in `gnus-select-group-hook'."
317  ;; Commands include...
318  ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
319  ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
320  ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
321  :group 'gnus-group-select
322  :type '(choice (const :tag "none" nil)
323		 (sexp :menu-tag "first" t)))
324
325(defcustom gnus-auto-select-subject 'unread
326  "*Says what subject to place under point when entering a group.
327
328This variable can either be the symbols `first' (place point on the
329first subject), `unread' (place point on the subject line of the first
330unread article), `best' (place point on the subject line of the
331higest-scored article), `unseen' (place point on the subject line of
332the first unseen article), `unseen-or-unread' (place point on the subject
333line of the first unseen article or, if all article have been seen, on the
334subject line of the first unread article), or a function to be called to
335place point on some subject line."
336  :version "22.1"
337  :group 'gnus-group-select
338  :type '(choice (const best)
339		 (const unread)
340		 (const first)
341		 (const unseen)
342	         (const unseen-or-unread)))
343
344(defcustom gnus-auto-select-next t
345  "*If non-nil, offer to go to the next group from the end of the previous.
346If the value is t and the next newsgroup is empty, Gnus will exit
347summary mode and go back to group mode.  If the value is neither nil
348nor t, Gnus will select the following unread newsgroup.  In
349particular, if the value is the symbol `quietly', the next unread
350newsgroup will be selected without any confirmation, and if it is
351`almost-quietly', the next group will be selected without any
352confirmation if you are located on the last article in the group.
353Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
354will go to the next group without confirmation."
355  :group 'gnus-summary-maneuvering
356  :type '(choice (const :tag "off" nil)
357		 (const quietly)
358		 (const almost-quietly)
359		 (const slightly-quietly)
360		 (sexp :menu-tag "on" t)))
361
362(defcustom gnus-auto-select-same nil
363  "*If non-nil, select the next article with the same subject.
364If there are no more articles with the same subject, go to
365the first unread article."
366  :group 'gnus-summary-maneuvering
367  :type 'boolean)
368
369(defcustom gnus-auto-goto-ignores 'unfetched
370  "*Says how to handle unfetched articles when maneuvering.
371
372This variable can either be the symbols nil (maneuver to any
373article), `undownloaded' (maneuvering while unplugged ignores articles
374that have not been fetched), `always-undownloaded' (maneuvering always
375ignores articles that have not been fetched), `unfetched' (maneuvering
376ignores articles whose headers have not been fetched).
377
378NOTE: The list of unfetched articles will always be nil when plugged
379and, when unplugged, a subset of the undownloaded article list."
380  :version "22.1"
381  :group 'gnus-summary-maneuvering
382  :type '(choice (const :tag "None" nil)
383                 (const :tag "Undownloaded when unplugged" undownloaded)
384                 (const :tag "Undownloaded" always-undownloaded)
385                 (const :tag "Unfetched" unfetched)))
386
387(defcustom gnus-summary-check-current nil
388  "*If non-nil, consider the current article when moving.
389The \"unread\" movement commands will stay on the same line if the
390current article is unread."
391  :group 'gnus-summary-maneuvering
392  :type 'boolean)
393
394(defcustom gnus-auto-center-summary t
395  "*If non-nil, always center the current summary buffer.
396In particular, if `vertical' do only vertical recentering.  If non-nil
397and non-`vertical', do both horizontal and vertical recentering."
398  :group 'gnus-summary-maneuvering
399  :type '(choice (const :tag "none" nil)
400		 (const vertical)
401		 (integer :tag "height")
402		 (sexp :menu-tag "both" t)))
403
404(defvar gnus-auto-center-group t
405  "*If non-nil, always center the group buffer.")
406
407(defcustom gnus-show-all-headers nil
408  "*If non-nil, don't hide any headers."
409  :group 'gnus-article-hiding
410  :group 'gnus-article-headers
411  :type 'boolean)
412
413(defcustom gnus-summary-ignore-duplicates nil
414  "*If non-nil, ignore articles with identical Message-ID headers."
415  :group 'gnus-summary
416  :type 'boolean)
417
418(defcustom gnus-single-article-buffer t
419  "*If non-nil, display all articles in the same buffer.
420If nil, each group will get its own article buffer."
421  :group 'gnus-article-various
422  :type 'boolean)
423
424(defcustom gnus-break-pages t
425  "*If non-nil, do page breaking on articles.
426The page delimiter is specified by the `gnus-page-delimiter'
427variable."
428  :group 'gnus-article-various
429  :type 'boolean)
430
431(defcustom gnus-move-split-methods nil
432  "*Variable used to suggest where articles are to be moved to.
433It uses the same syntax as the `gnus-split-methods' variable.
434However, whereas `gnus-split-methods' specifies file names as targets,
435this variable specifies group names."
436  :group 'gnus-summary-mail
437  :type '(repeat (choice (list :value (fun) function)
438			 (cons :value ("" "") regexp (repeat string))
439			 (sexp :value nil))))
440
441;; FIXME: Although the custom type is `character' for the following variables,
442;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
443
444(defcustom gnus-unread-mark ?           ;Whitespace
445  "*Mark used for unread articles."
446  :group 'gnus-summary-marks
447  :type 'character)
448
449(defcustom gnus-ticked-mark ?!
450  "*Mark used for ticked articles."
451  :group 'gnus-summary-marks
452  :type 'character)
453
454(defcustom gnus-dormant-mark ??
455  "*Mark used for dormant articles."
456  :group 'gnus-summary-marks
457  :type 'character)
458
459(defcustom gnus-del-mark ?r
460  "*Mark used for del'd articles."
461  :group 'gnus-summary-marks
462  :type 'character)
463
464(defcustom gnus-read-mark ?R
465  "*Mark used for read articles."
466  :group 'gnus-summary-marks
467  :type 'character)
468
469(defcustom gnus-expirable-mark ?E
470  "*Mark used for expirable articles."
471  :group 'gnus-summary-marks
472  :type 'character)
473
474(defcustom gnus-killed-mark ?K
475  "*Mark used for killed articles."
476  :group 'gnus-summary-marks
477  :type 'character)
478
479(defcustom gnus-spam-mark ?$
480  "*Mark used for spam articles."
481  :version "22.1"
482  :group 'gnus-summary-marks
483  :type 'character)
484
485(defcustom gnus-souped-mark ?F
486  "*Mark used for souped articles."
487  :group 'gnus-summary-marks
488  :type 'character)
489
490(defcustom gnus-kill-file-mark ?X
491  "*Mark used for articles killed by kill files."
492  :group 'gnus-summary-marks
493  :type 'character)
494
495(defcustom gnus-low-score-mark ?Y
496  "*Mark used for articles with a low score."
497  :group 'gnus-summary-marks
498  :type 'character)
499
500(defcustom gnus-catchup-mark ?C
501  "*Mark used for articles that are caught up."
502  :group 'gnus-summary-marks
503  :type 'character)
504
505(defcustom gnus-replied-mark ?A
506  "*Mark used for articles that have been replied to."
507  :group 'gnus-summary-marks
508  :type 'character)
509
510(defcustom gnus-forwarded-mark ?F
511  "*Mark used for articles that have been forwarded."
512  :version "22.1"
513  :group 'gnus-summary-marks
514  :type 'character)
515
516(defcustom gnus-recent-mark ?N
517  "*Mark used for articles that are recent."
518  :version "22.1"
519  :group 'gnus-summary-marks
520  :type 'character)
521
522(defcustom gnus-cached-mark ?*
523  "*Mark used for articles that are in the cache."
524  :group 'gnus-summary-marks
525  :type 'character)
526
527(defcustom gnus-saved-mark ?S
528  "*Mark used for articles that have been saved."
529  :group 'gnus-summary-marks
530  :type 'character)
531
532(defcustom gnus-unseen-mark ?.
533  "*Mark used for articles that haven't been seen."
534  :version "22.1"
535  :group 'gnus-summary-marks
536  :type 'character)
537
538(defcustom gnus-no-mark ?               ;Whitespace
539  "*Mark used for articles that have no other secondary mark."
540  :version "22.1"
541  :group 'gnus-summary-marks
542  :type 'character)
543
544(defcustom gnus-ancient-mark ?O
545  "*Mark used for ancient articles."
546  :group 'gnus-summary-marks
547  :type 'character)
548
549(defcustom gnus-sparse-mark ?Q
550  "*Mark used for sparsely reffed articles."
551  :group 'gnus-summary-marks
552  :type 'character)
553
554(defcustom gnus-canceled-mark ?G
555  "*Mark used for canceled articles."
556  :group 'gnus-summary-marks
557  :type 'character)
558
559(defcustom gnus-duplicate-mark ?M
560  "*Mark used for duplicate articles."
561  :group 'gnus-summary-marks
562  :type 'character)
563
564(defcustom gnus-undownloaded-mark ?-
565  "*Mark used for articles that weren't downloaded."
566  :version "22.1"
567  :group 'gnus-summary-marks
568  :type 'character)
569
570(defcustom gnus-downloaded-mark ?+
571  "*Mark used for articles that were downloaded."
572  :group 'gnus-summary-marks
573  :type 'character)
574
575(defcustom gnus-downloadable-mark ?%
576  "*Mark used for articles that are to be downloaded."
577  :group 'gnus-summary-marks
578  :type 'character)
579
580(defcustom gnus-unsendable-mark ?=
581  "*Mark used for articles that won't be sent."
582  :group 'gnus-summary-marks
583  :type 'character)
584
585(defcustom gnus-score-over-mark ?+
586  "*Score mark used for articles with high scores."
587  :group 'gnus-summary-marks
588  :type 'character)
589
590(defcustom gnus-score-below-mark ?-
591  "*Score mark used for articles with low scores."
592  :group 'gnus-summary-marks
593  :type 'character)
594
595(defcustom gnus-empty-thread-mark ?     ;Whitespace
596  "*There is no thread under the article."
597  :group 'gnus-summary-marks
598  :type 'character)
599
600(defcustom gnus-not-empty-thread-mark ?=
601  "*There is a thread under the article."
602  :group 'gnus-summary-marks
603  :type 'character)
604
605(defcustom gnus-view-pseudo-asynchronously nil
606  "*If non-nil, Gnus will view pseudo-articles asynchronously."
607  :group 'gnus-extract-view
608  :type 'boolean)
609
610(defcustom gnus-auto-expirable-marks
611  (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
612	gnus-low-score-mark gnus-ancient-mark gnus-read-mark
613	gnus-souped-mark gnus-duplicate-mark)
614  "*The list of marks converted into expiration if a group is auto-expirable."
615  :version "21.1"
616  :group 'gnus-summary
617  :type '(repeat character))
618
619(defcustom gnus-inhibit-user-auto-expire t
620  "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
621  :version "21.1"
622  :group 'gnus-summary
623  :type 'boolean)
624
625(defcustom gnus-view-pseudos nil
626  "*If `automatic', pseudo-articles will be viewed automatically.
627If `not-confirm', pseudos will be viewed automatically, and the user
628will not be asked to confirm the command."
629  :group 'gnus-extract-view
630  :type '(choice (const :tag "off" nil)
631		 (const automatic)
632		 (const not-confirm)))
633
634(defcustom gnus-view-pseudos-separately t
635  "*If non-nil, one pseudo-article will be created for each file to be viewed.
636If nil, all files that use the same viewing command will be given as a
637list of parameters to that command."
638  :group 'gnus-extract-view
639  :type 'boolean)
640
641(defcustom gnus-insert-pseudo-articles t
642  "*If non-nil, insert pseudo-articles when decoding articles."
643  :group 'gnus-extract-view
644  :type 'boolean)
645
646(defcustom gnus-summary-dummy-line-format
647  "   %(:                             :%) %S\n"
648  "*The format specification for the dummy roots in the summary buffer.
649It works along the same lines as a normal formatting string,
650with some simple extensions.
651
652%S  The subject
653
654General format specifiers can also be used.
655See `(gnus)Formatting Variables'."
656  :link '(custom-manual "(gnus)Formatting Variables")
657  :group 'gnus-threading
658  :type 'string)
659
660(defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
661  "*The format specification for the summary mode line.
662It works along the same lines as a normal formatting string,
663with some simple extensions:
664
665%G  Group name
666%p  Unprefixed group name
667%A  Current article number
668%z  Current article score
669%V  Gnus version
670%U  Number of unread articles in the group
671%e  Number of unselected articles in the group
672%Z  A string with unread/unselected article counts
673%g  Shortish group name
674%S  Subject of the current article
675%u  User-defined spec
676%s  Current score file name
677%d  Number of dormant articles
678%r  Number of articles that have been marked as read in this session
679%E  Number of articles expunged by the score files"
680  :group 'gnus-summary-format
681  :type 'string)
682
683(defcustom gnus-list-identifiers nil
684  "Regexp that matches list identifiers to be removed from subject.
685This can also be a list of regexps."
686  :version "21.1"
687  :group 'gnus-summary-format
688  :group 'gnus-article-hiding
689  :type '(choice (const :tag "none" nil)
690		 (regexp :value ".*")
691		 (repeat :value (".*") regexp)))
692
693(defcustom gnus-summary-mark-below 0
694  "*Mark all articles with a score below this variable as read.
695This variable is local to each summary buffer and usually set by the
696score file."
697  :group 'gnus-score-default
698  :type 'integer)
699
700(defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
701  "*List of functions used for sorting articles in the summary buffer.
702
703Each function takes two articles and returns non-nil if the first
704article should be sorted before the other.  If you use more than one
705function, the primary sort function should be the last.  You should
706probably always include `gnus-article-sort-by-number' in the list of
707sorting functions -- preferably first.  Also note that sorting by date
708is often much slower than sorting by number, and the sorting order is
709very similar.  (Sorting by date means sorting by the time the message
710was sent, sorting by number means sorting by arrival time.)
711
712Ready-made functions include `gnus-article-sort-by-number',
713`gnus-article-sort-by-author', `gnus-article-sort-by-subject',
714`gnus-article-sort-by-date', `gnus-article-sort-by-random'
715and `gnus-article-sort-by-score'.
716
717When threading is turned on, the variable `gnus-thread-sort-functions'
718controls how articles are sorted."
719  :group 'gnus-summary-sort
720  :type '(repeat (choice (function-item gnus-article-sort-by-number)
721			 (function-item gnus-article-sort-by-author)
722			 (function-item gnus-article-sort-by-subject)
723			 (function-item gnus-article-sort-by-date)
724			 (function-item gnus-article-sort-by-score)
725			 (function-item gnus-article-sort-by-random)
726			 (function :tag "other"))))
727
728(defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
729  "*List of functions used for sorting threads in the summary buffer.
730By default, threads are sorted by article number.
731
732Each function takes two threads and returns non-nil if the first
733thread should be sorted before the other.  If you use more than one
734function, the primary sort function should be the last.  You should
735probably always include `gnus-thread-sort-by-number' in the list of
736sorting functions -- preferably first.  Also note that sorting by date
737is often much slower than sorting by number, and the sorting order is
738very similar.  (Sorting by date means sorting by the time the message
739was sent, sorting by number means sorting by arrival time.)
740
741Ready-made functions include `gnus-thread-sort-by-number',
742`gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
743`gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
744`gnus-thread-sort-by-most-recent-number',
745`gnus-thread-sort-by-most-recent-date',
746`gnus-thread-sort-by-random', and
747`gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
748
749When threading is turned off, the variable
750`gnus-article-sort-functions' controls how articles are sorted."
751  :group 'gnus-summary-sort
752  :type '(repeat (choice (function-item gnus-thread-sort-by-number)
753			 (function-item gnus-thread-sort-by-author)
754			 (function-item gnus-thread-sort-by-subject)
755			 (function-item gnus-thread-sort-by-date)
756			 (function-item gnus-thread-sort-by-score)
757			 (function-item gnus-thread-sort-by-total-score)
758			 (function-item gnus-thread-sort-by-random)
759			 (function :tag "other"))))
760
761(defcustom gnus-thread-score-function '+
762  "*Function used for calculating the total score of a thread.
763
764The function is called with the scores of the article and each
765subthread and should then return the score of the thread.
766
767Some functions you can use are `+', `max', or `min'."
768  :group 'gnus-summary-sort
769  :type 'function)
770
771(defcustom gnus-summary-expunge-below nil
772  "All articles that have a score less than this variable will be expunged.
773This variable is local to the summary buffers."
774  :group 'gnus-score-default
775  :type '(choice (const :tag "off" nil)
776		 integer))
777
778(defcustom gnus-thread-expunge-below nil
779  "All threads that have a total score less than this variable will be expunged.
780See `gnus-thread-score-function' for en explanation of what a
781\"thread score\" is.
782
783This variable is local to the summary buffers."
784  :group 'gnus-threading
785  :group 'gnus-score-default
786  :type '(choice (const :tag "off" nil)
787		 integer))
788
789(defcustom gnus-summary-mode-hook nil
790  "*A hook for Gnus summary mode.
791This hook is run before any variables are set in the summary buffer."
792  :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
793  :group 'gnus-summary-various
794  :type 'hook)
795
796;; Extracted from gnus-xmas-redefine in order to preserve user settings
797(when (featurep 'xemacs)
798  (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
799  (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
800  (add-hook 'gnus-summary-mode-hook
801	    'gnus-xmas-switch-horizontal-scrollbar-off))
802
803(defcustom gnus-summary-menu-hook nil
804  "*Hook run after the creation of the summary mode menu."
805  :group 'gnus-summary-visual
806  :type 'hook)
807
808(defcustom gnus-summary-exit-hook nil
809  "*A hook called on exit from the summary buffer.
810It will be called with point in the group buffer."
811  :group 'gnus-summary-exit
812  :type 'hook)
813
814(defcustom gnus-summary-prepare-hook nil
815  "*A hook called after the summary buffer has been generated.
816If you want to modify the summary buffer, you can use this hook."
817  :group 'gnus-summary-various
818  :type 'hook)
819
820(defcustom gnus-summary-prepared-hook nil
821  "*A hook called as the last thing after the summary buffer has been generated."
822  :group 'gnus-summary-various
823  :type 'hook)
824
825(defcustom gnus-summary-generate-hook nil
826  "*A hook run just before generating the summary buffer.
827This hook is commonly used to customize threading variables and the
828like."
829  :group 'gnus-summary-various
830  :type 'hook)
831
832(defcustom gnus-select-group-hook nil
833  "*A hook called when a newsgroup is selected.
834
835If you'd like to simplify subjects like the
836`gnus-summary-next-same-subject' command does, you can use the
837following hook:
838
839 (add-hook gnus-select-group-hook
840	   (lambda ()
841	     (mapcar (lambda (header)
842		       (mail-header-set-subject
843			header
844			(gnus-simplify-subject
845			 (mail-header-subject header) 're-only)))
846		     gnus-newsgroup-headers)))"
847  :group 'gnus-group-select
848  :type 'hook)
849
850(defcustom gnus-select-article-hook nil
851  "*A hook called when an article is selected."
852  :group 'gnus-summary-choose
853  :options '(gnus-agent-fetch-selected-article)
854  :type 'hook)
855
856(defcustom gnus-visual-mark-article-hook
857  (list 'gnus-highlight-selected-summary)
858  "*Hook run after selecting an article in the summary buffer.
859It is meant to be used for highlighting the article in some way.  It
860is not run if `gnus-visual' is nil."
861  :group 'gnus-summary-visual
862  :type 'hook)
863
864(defcustom gnus-parse-headers-hook nil
865  "*A hook called before parsing the headers."
866  :group 'gnus-various
867  :type 'hook)
868
869(defcustom gnus-exit-group-hook nil
870  "*A hook called when exiting summary mode.
871This hook is not called from the non-updating exit commands like `Q'."
872  :group 'gnus-various
873  :type 'hook)
874
875(defcustom gnus-summary-update-hook
876  (list 'gnus-summary-highlight-line)
877  "*A hook called when a summary line is changed.
878The hook will not be called if `gnus-visual' is nil.
879
880The default function `gnus-summary-highlight-line' will
881highlight the line according to the `gnus-summary-highlight'
882variable."
883  :group 'gnus-summary-visual
884  :type 'hook)
885
886(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
887  "*A hook called when an article is selected for the first time.
888The hook is intended to mark an article as read (or unread)
889automatically when it is selected."
890  :group 'gnus-summary-choose
891  :type 'hook)
892
893(defcustom gnus-group-no-more-groups-hook nil
894  "*A hook run when returning to group mode having no more (unread) groups."
895  :group 'gnus-group-select
896  :type 'hook)
897
898(defcustom gnus-ps-print-hook nil
899  "*A hook run before ps-printing something from Gnus."
900  :group 'gnus-summary
901  :type 'hook)
902
903(defcustom gnus-summary-article-move-hook nil
904  "*A hook called after an article is moved, copied, respooled, or crossposted."
905  :version "22.1"
906  :group 'gnus-summary
907  :type 'hook)
908
909(defcustom gnus-summary-article-delete-hook nil
910  "*A hook called after an article is deleted."
911  :version "22.1"
912  :group 'gnus-summary
913  :type 'hook)
914
915(defcustom gnus-summary-article-expire-hook nil
916  "*A hook called after an article is expired."
917  :version "22.1"
918  :group 'gnus-summary
919  :type 'hook)
920
921(defcustom gnus-summary-display-arrow
922  (and (fboundp 'display-graphic-p)
923       (display-graphic-p))
924  "*If non-nil, display an arrow highlighting the current article."
925  :version "22.1"
926  :group 'gnus-summary
927  :type 'boolean)
928
929(defcustom gnus-summary-selected-face 'gnus-summary-selected
930  "Face used for highlighting the current article in the summary buffer."
931  :group 'gnus-summary-visual
932  :type 'face)
933
934(defvar gnus-tmp-downloaded nil)
935
936(defcustom gnus-summary-highlight
937  '(((eq mark gnus-canceled-mark)
938     . gnus-summary-cancelled)
939    ((and uncached (> score default-high))
940     . gnus-summary-high-undownloaded)
941    ((and uncached (< score default-low))
942     . gnus-summary-low-undownloaded)
943    (uncached
944     . gnus-summary-normal-undownloaded)
945    ((and (> score default-high)
946	  (or (eq mark gnus-dormant-mark)
947	      (eq mark gnus-ticked-mark)))
948     . gnus-summary-high-ticked)
949    ((and (< score default-low)
950	  (or (eq mark gnus-dormant-mark)
951	      (eq mark gnus-ticked-mark)))
952     . gnus-summary-low-ticked)
953    ((or (eq mark gnus-dormant-mark)
954	 (eq mark gnus-ticked-mark))
955     . gnus-summary-normal-ticked)
956    ((and (> score default-high) (eq mark gnus-ancient-mark))
957     . gnus-summary-high-ancient)
958    ((and (< score default-low) (eq mark gnus-ancient-mark))
959     . gnus-summary-low-ancient)
960    ((eq mark gnus-ancient-mark)
961     . gnus-summary-normal-ancient)
962    ((and (> score default-high) (eq mark gnus-unread-mark))
963     . gnus-summary-high-unread)
964    ((and (< score default-low) (eq mark gnus-unread-mark))
965     . gnus-summary-low-unread)
966    ((eq mark gnus-unread-mark)
967     . gnus-summary-normal-unread)
968    ((> score default-high)
969     . gnus-summary-high-read)
970    ((< score default-low)
971     . gnus-summary-low-read)
972    (t
973     . gnus-summary-normal-read))
974  "*Controls the highlighting of summary buffer lines.
975
976A list of (FORM . FACE) pairs.  When deciding how a a particular
977summary line should be displayed, each form is evaluated.  The content
978of the face field after the first true form is used.  You can change
979how those summary lines are displayed, by editing the face field.
980
981You can use the following variables in the FORM field.
982
983score:        The article's score
984default:      The default article score.
985default-high: The default score for high scored articles.
986default-low:  The default score for low scored articles.
987below:        The score below which articles are automatically marked as read.
988mark:         The article's mark.
989uncached:     Non-nil if the article is uncached."
990  :group 'gnus-summary-visual
991  :type '(repeat (cons (sexp :tag "Form" nil)
992		       face)))
993
994(defcustom gnus-alter-header-function nil
995  "Function called to allow alteration of article header structures.
996The function is called with one parameter, the article header vector,
997which it may alter in any way."
998  :type '(choice (const :tag "None" nil)
999		 function)
1000  :group 'gnus-summary)
1001
1002(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1003  "Function used to decode a string with encoded words.")
1004
1005(defvar gnus-decode-encoded-address-function
1006  'mail-decode-encoded-address-string
1007  "Function used to decode addresses with encoded words.")
1008
1009(defcustom gnus-extra-headers '(To Newsgroups)
1010  "*Extra headers to parse."
1011  :version "21.1"
1012  :group 'gnus-summary
1013  :type '(repeat symbol))
1014
1015(defcustom gnus-ignored-from-addresses
1016  (and user-mail-address
1017       (not (string= user-mail-address ""))
1018       (regexp-quote user-mail-address))
1019  "*Regexp of From headers that may be suppressed in favor of To headers."
1020  :version "21.1"
1021  :group 'gnus-summary
1022  :type 'regexp)
1023
1024(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1025  "List of charsets that should be ignored.
1026When these charsets are used in the \"charset\" parameter, the
1027default charset will be used instead."
1028  :version "21.1"
1029  :type '(repeat symbol)
1030  :group 'gnus-charset)
1031
1032(gnus-define-group-parameter
1033 ignored-charsets
1034 :type list
1035 :function-document
1036 "Return the ignored charsets of GROUP."
1037 :variable gnus-group-ignored-charsets-alist
1038 :variable-default
1039 '(("alt\\.chinese\\.text" iso-8859-1))
1040 :variable-document
1041 "Alist of regexps (to match group names) and charsets that should be ignored.
1042When these charsets are used in the \"charset\" parameter, the
1043default charset will be used instead."
1044 :variable-group gnus-charset
1045 :variable-type '(repeat (cons (regexp :tag "Group")
1046			       (repeat symbol)))
1047 :parameter-type '(choice :tag "Ignored charsets"
1048			  :value nil
1049			  (repeat (symbol)))
1050 :parameter-document       "\
1051List of charsets that should be ignored.
1052
1053When these charsets are used in the \"charset\" parameter, the
1054default charset will be used instead.")
1055
1056(defcustom gnus-group-highlight-words-alist nil
1057  "Alist of group regexps and highlight regexps.
1058This variable uses the same syntax as `gnus-emphasis-alist'."
1059  :version "21.1"
1060  :type '(repeat (cons (regexp :tag "Group")
1061		       (repeat (list (regexp :tag "Highlight regexp")
1062				     (number :tag "Group for entire word" 0)
1063				     (number :tag "Group for displayed part" 0)
1064				     (symbol :tag "Face"
1065					     gnus-emphasis-highlight-words)))))
1066  :group 'gnus-summary-visual)
1067
1068(defcustom gnus-summary-show-article-charset-alist
1069  nil
1070  "Alist of number and charset.
1071The article will be shown with the charset corresponding to the
1072numbered argument.
1073For example: ((1 . cn-gb-2312) (2 . big5))."
1074  :version "21.1"
1075  :type '(repeat (cons (number :tag "Argument" 1)
1076		       (symbol :tag "Charset")))
1077  :group 'gnus-charset)
1078
1079(defcustom gnus-preserve-marks t
1080  "Whether marks are preserved when moving, copying and respooling messages."
1081  :version "21.1"
1082  :type 'boolean
1083  :group 'gnus-summary-marks)
1084
1085(defcustom gnus-alter-articles-to-read-function nil
1086  "Function to be called to alter the list of articles to be selected."
1087  :type '(choice (const nil) function)
1088  :group 'gnus-summary)
1089
1090(defcustom gnus-orphan-score nil
1091  "*All orphans get this score added.  Set in the score file."
1092  :group 'gnus-score-default
1093  :type '(choice (const nil)
1094		 integer))
1095
1096(defcustom gnus-summary-save-parts-default-mime "image/.*"
1097  "*A regexp to match MIME parts when saving multiple parts of a
1098message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1099This regexp will be used by default when prompting the user for which
1100type of files to save."
1101  :group 'gnus-summary
1102  :type 'regexp)
1103
1104(defcustom gnus-read-all-available-headers nil
1105  "Whether Gnus should parse all headers made available to it.
1106This is mostly relevant for slow back ends where the user may
1107wish to widen the summary buffer to include all headers
1108that were fetched.  Say, for nnultimate groups."
1109  :version "22.1"
1110  :group 'gnus-summary
1111  :type '(choice boolean regexp))
1112
1113(defcustom gnus-summary-muttprint-program "muttprint"
1114  "Command (and optional arguments) used to run Muttprint."
1115  :version "22.1"
1116  :group 'gnus-summary
1117  :type 'string)
1118
1119(defcustom gnus-article-loose-mime nil
1120  "If non-nil, don't require MIME-Version header.
1121Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1122supply the MIME-Version header or deliberately strip it from the mail.
1123Set it to non-nil, Gnus will treat some articles as MIME even if
1124the MIME-Version header is missed."
1125  :version "22.1"
1126  :type 'boolean
1127  :group 'gnus-article-mime)
1128
1129(defcustom gnus-article-emulate-mime t
1130  "If non-nil, use MIME emulation for uuencode and the like.
1131This means that Gnus will search message bodies for text that look
1132like uuencoded bits, yEncoded bits, and so on, and present that using
1133the normal Gnus MIME machinery."
1134  :version "22.1"
1135  :type 'boolean
1136  :group 'gnus-article-mime)
1137
1138;;; Internal variables
1139
1140(defvar gnus-summary-display-cache nil)
1141(defvar gnus-article-mime-handles nil)
1142(defvar gnus-article-decoded-p nil)
1143(defvar gnus-article-charset nil)
1144(defvar gnus-article-ignored-charsets nil)
1145(defvar gnus-scores-exclude-files nil)
1146(defvar gnus-page-broken nil)
1147
1148(defvar gnus-original-article nil)
1149(defvar gnus-article-internal-prepare-hook nil)
1150(defvar gnus-newsgroup-process-stack nil)
1151
1152(defvar gnus-thread-indent-array nil)
1153(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1154(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1155  "Function called to sort the articles within a thread after it has been gathered together.")
1156
1157(defvar gnus-summary-save-parts-type-history nil)
1158(defvar gnus-summary-save-parts-last-directory mm-default-directory)
1159
1160;; Avoid highlighting in kill files.
1161(defvar gnus-summary-inhibit-highlight nil)
1162(defvar gnus-newsgroup-selected-overlay nil)
1163(defvar gnus-inhibit-limiting nil)
1164(defvar gnus-newsgroup-adaptive-score-file nil)
1165(defvar gnus-current-score-file nil)
1166(defvar gnus-current-move-group nil)
1167(defvar gnus-current-copy-group nil)
1168(defvar gnus-current-crosspost-group nil)
1169(defvar gnus-newsgroup-display nil)
1170
1171(defvar gnus-newsgroup-dependencies nil)
1172(defvar gnus-newsgroup-adaptive nil)
1173(defvar gnus-summary-display-article-function nil)
1174(defvar gnus-summary-highlight-line-function nil
1175  "Function called after highlighting a summary line.")
1176
1177(defvar gnus-summary-line-format-alist
1178  `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1179    (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1180    (?s gnus-tmp-subject-or-nil ?s)
1181    (?n gnus-tmp-name ?s)
1182    (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1183	?s)
1184    (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1185	    gnus-tmp-from) ?s)
1186    (?F gnus-tmp-from ?s)
1187    (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1188    (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1189    (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1190    (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1191    (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1192    (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1193    (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1194    (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1195    (?L gnus-tmp-lines ?s)
1196    (?O gnus-tmp-downloaded ?c)
1197    (?I gnus-tmp-indentation ?s)
1198    (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1199    (?R gnus-tmp-replied ?c)
1200    (?\[ gnus-tmp-opening-bracket ?c)
1201    (?\] gnus-tmp-closing-bracket ?c)
1202    (?\> (make-string gnus-tmp-level ? ) ?s)
1203    (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1204    (?i gnus-tmp-score ?d)
1205    (?z gnus-tmp-score-char ?c)
1206    (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1207    (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1208    (?U gnus-tmp-unread ?c)
1209    (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1210	?s)
1211    (?t (gnus-summary-number-of-articles-in-thread
1212	 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1213	?d)
1214    (?e (gnus-summary-number-of-articles-in-thread
1215	 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1216	?c)
1217    (?u gnus-tmp-user-defined ?s)
1218    (?P (gnus-pick-line-number) ?d)
1219    (?B gnus-tmp-thread-tree-header-string ?s)
1220    (user-date (gnus-user-date
1221		,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1222  "An alist of format specifications that can appear in summary lines.
1223These are paired with what variables they correspond with, along with
1224the type of the variable (string, integer, character, etc).")
1225
1226(defvar gnus-summary-dummy-line-format-alist
1227  `((?S gnus-tmp-subject ?s)
1228    (?N gnus-tmp-number ?d)
1229    (?u gnus-tmp-user-defined ?s)))
1230
1231(defvar gnus-summary-mode-line-format-alist
1232  `((?G gnus-tmp-group-name ?s)
1233    (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1234    (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1235    (?A gnus-tmp-article-number ?d)
1236    (?Z gnus-tmp-unread-and-unselected ?s)
1237    (?V gnus-version ?s)
1238    (?U gnus-tmp-unread-and-unticked ?d)
1239    (?S gnus-tmp-subject ?s)
1240    (?e gnus-tmp-unselected ?d)
1241    (?u gnus-tmp-user-defined ?s)
1242    (?d (length gnus-newsgroup-dormant) ?d)
1243    (?t (length gnus-newsgroup-marked) ?d)
1244    (?h (length gnus-newsgroup-spam-marked) ?d)
1245    (?r (length gnus-newsgroup-reads) ?d)
1246    (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1247    (?E gnus-newsgroup-expunged-tally ?d)
1248    (?s (gnus-current-score-file-nondirectory) ?s)))
1249
1250(defvar gnus-last-search-regexp nil
1251  "Default regexp for article search command.")
1252
1253(defvar gnus-last-shell-command nil
1254  "Default shell command on article.")
1255
1256(defvar gnus-newsgroup-agentized nil
1257  "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1258(defvar gnus-newsgroup-begin nil)
1259(defvar gnus-newsgroup-end nil)
1260(defvar gnus-newsgroup-last-rmail nil)
1261(defvar gnus-newsgroup-last-mail nil)
1262(defvar gnus-newsgroup-last-folder nil)
1263(defvar gnus-newsgroup-last-file nil)
1264(defvar gnus-newsgroup-last-directory nil)
1265(defvar gnus-newsgroup-auto-expire nil)
1266(defvar gnus-newsgroup-active nil)
1267
1268(defvar gnus-newsgroup-data nil)
1269(defvar gnus-newsgroup-data-reverse nil)
1270(defvar gnus-newsgroup-limit nil)
1271(defvar gnus-newsgroup-limits nil)
1272(defvar gnus-summary-use-undownloaded-faces nil)
1273
1274(defvar gnus-newsgroup-unreads nil
1275  "Sorted list of unread articles in the current newsgroup.")
1276
1277(defvar gnus-newsgroup-unselected nil
1278  "Sorted list of unselected unread articles in the current newsgroup.")
1279
1280(defvar gnus-newsgroup-reads nil
1281  "Alist of read articles and article marks in the current newsgroup.")
1282
1283(defvar gnus-newsgroup-expunged-tally nil)
1284
1285(defvar gnus-newsgroup-marked nil
1286  "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1287
1288(defvar gnus-newsgroup-spam-marked nil
1289  "List of ranges of articles that have been marked as spam.")
1290
1291(defvar gnus-newsgroup-killed nil
1292  "List of ranges of articles that have been through the scoring process.")
1293
1294(defvar gnus-newsgroup-cached nil
1295  "Sorted list of articles that come from the article cache.")
1296
1297(defvar gnus-newsgroup-saved nil
1298  "List of articles that have been saved.")
1299
1300(defvar gnus-newsgroup-kill-headers nil)
1301
1302(defvar gnus-newsgroup-replied nil
1303  "List of articles that have been replied to in the current newsgroup.")
1304
1305(defvar gnus-newsgroup-forwarded nil
1306  "List of articles that have been forwarded in the current newsgroup.")
1307
1308(defvar gnus-newsgroup-recent nil
1309  "List of articles that have are recent in the current newsgroup.")
1310
1311(defvar gnus-newsgroup-expirable nil
1312  "Sorted list of articles in the current newsgroup that can be expired.")
1313
1314(defvar gnus-newsgroup-processable nil
1315  "List of articles in the current newsgroup that can be processed.")
1316
1317(defvar gnus-newsgroup-downloadable nil
1318  "Sorted list of articles in the current newsgroup that can be processed.")
1319
1320(defvar gnus-newsgroup-unfetched nil
1321  "Sorted list of articles in the current newsgroup whose headers have
1322not been fetched into the agent.
1323
1324This list will always be a subset of gnus-newsgroup-undownloaded.")
1325
1326(defvar gnus-newsgroup-undownloaded nil
1327  "List of articles in the current newsgroup that haven't been downloaded.")
1328
1329(defvar gnus-newsgroup-unsendable nil
1330  "List of articles in the current newsgroup that won't be sent.")
1331
1332(defvar gnus-newsgroup-bookmarks nil
1333  "List of articles in the current newsgroup that have bookmarks.")
1334
1335(defvar gnus-newsgroup-dormant nil
1336  "Sorted list of dormant articles in the current newsgroup.")
1337
1338(defvar gnus-newsgroup-unseen nil
1339  "List of unseen articles in the current newsgroup.")
1340
1341(defvar gnus-newsgroup-seen nil
1342  "Range of seen articles in the current newsgroup.")
1343
1344(defvar gnus-newsgroup-articles nil
1345  "List of articles in the current newsgroup.")
1346
1347(defvar gnus-newsgroup-scored nil
1348  "List of scored articles in the current newsgroup.")
1349
1350(defvar gnus-newsgroup-headers nil
1351  "List of article headers in the current newsgroup.")
1352
1353(defvar gnus-newsgroup-threads nil)
1354
1355(defvar gnus-newsgroup-prepared nil
1356  "Whether the current group has been prepared properly.")
1357
1358(defvar gnus-newsgroup-ancient nil
1359  "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1360
1361(defvar gnus-newsgroup-sparse nil)
1362
1363(defvar gnus-current-article nil)
1364(defvar gnus-article-current nil)
1365(defvar gnus-current-headers nil)
1366(defvar gnus-have-all-headers nil)
1367(defvar gnus-last-article nil)
1368(defvar gnus-newsgroup-history nil)
1369(defvar gnus-newsgroup-charset nil)
1370(defvar gnus-newsgroup-ephemeral-charset nil)
1371(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1372
1373(defvar gnus-article-before-search nil)
1374
1375(defvar gnus-summary-local-variables
1376  '(gnus-newsgroup-name
1377    gnus-newsgroup-begin gnus-newsgroup-end
1378    gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1379    gnus-newsgroup-last-folder gnus-newsgroup-last-file
1380    gnus-newsgroup-last-directory
1381    gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1382    gnus-newsgroup-unselected gnus-newsgroup-marked
1383    gnus-newsgroup-spam-marked
1384    gnus-newsgroup-reads gnus-newsgroup-saved
1385    gnus-newsgroup-replied gnus-newsgroup-forwarded
1386    gnus-newsgroup-recent
1387    gnus-newsgroup-expirable
1388    gnus-newsgroup-processable gnus-newsgroup-killed
1389    gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1390    gnus-newsgroup-unfetched
1391    gnus-newsgroup-unsendable gnus-newsgroup-unseen
1392    gnus-newsgroup-seen gnus-newsgroup-articles
1393    gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1394    gnus-newsgroup-headers gnus-newsgroup-threads
1395    gnus-newsgroup-prepared gnus-summary-highlight-line-function
1396    gnus-current-article gnus-current-headers gnus-have-all-headers
1397    gnus-last-article gnus-article-internal-prepare-hook
1398    gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1399    gnus-newsgroup-scored gnus-newsgroup-kill-headers
1400    gnus-thread-expunge-below
1401    gnus-score-alist gnus-current-score-file
1402    (gnus-summary-expunge-below . global)
1403    (gnus-summary-mark-below . global)
1404    (gnus-orphan-score . global)
1405    gnus-newsgroup-active gnus-scores-exclude-files
1406    gnus-newsgroup-history gnus-newsgroup-ancient
1407    gnus-newsgroup-sparse gnus-newsgroup-process-stack
1408    (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1409    gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1410    (gnus-newsgroup-expunged-tally . 0)
1411    gnus-cache-removable-articles gnus-newsgroup-cached
1412    gnus-newsgroup-data gnus-newsgroup-data-reverse
1413    gnus-newsgroup-limit gnus-newsgroup-limits
1414    gnus-newsgroup-charset gnus-newsgroup-display
1415    gnus-summary-use-undownloaded-faces)
1416  "Variables that are buffer-local to the summary buffers.")
1417
1418(defvar gnus-newsgroup-variables nil
1419  "A list of variables that have separate values in different newsgroups.
1420A list of newsgroup (summary buffer) local variables, or cons of
1421variables and their default expressions to be evalled (when the default
1422values are not nil), that should be made global while the summary buffer
1423is active.
1424
1425Note: The default expressions will be evaluated (using function `eval')
1426before assignment to the local variable rather than just assigned to it.
1427If the default expression is the symbol `global', that symbol will not
1428be evaluated but the global value of the local variable will be used
1429instead.
1430
1431These variables can be used to set variables in the group parameters
1432while still allowing them to affect operations done in other buffers.
1433For example:
1434
1435\(setq gnus-newsgroup-variables
1436     '(message-use-followup-to
1437       (gnus-visible-headers .
1438	 \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1439")
1440
1441;; Byte-compiler warning.
1442(eval-when-compile
1443  ;; Bind features so that require will believe that gnus-sum has
1444  ;; already been loaded (avoids infinite recursion)
1445  (let ((features (cons 'gnus-sum features)))
1446    ;; Several of the declarations in gnus-sum are needed to load the
1447    ;; following files. Right now, these definitions have been
1448    ;; compiled but not defined (evaluated).  We could either do a
1449    ;; eval-and-compile about all of the declarations or evaluate the
1450    ;; source file.
1451    (if (boundp 'gnus-newsgroup-variables)
1452        nil
1453      (load "gnus-sum.el" t t t))
1454    (require 'gnus)
1455    (require 'gnus-agent)
1456    (require 'gnus-art)))
1457
1458;; MIME stuff.
1459
1460(defvar gnus-decode-encoded-word-methods
1461  '(mail-decode-encoded-word-string)
1462  "List of methods used to decode encoded words.
1463
1464This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1465is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1466\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1467whose names match REGEXP.
1468
1469For example:
1470\((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1471 mail-decode-encoded-word-string
1472 (\"chinese\" . rfc1843-decode-string))")
1473
1474(defvar gnus-decode-encoded-word-methods-cache nil)
1475
1476(defun gnus-multi-decode-encoded-word-string (string)
1477  "Apply the functions from `gnus-encoded-word-methods' that match."
1478  (unless (and gnus-decode-encoded-word-methods-cache
1479	       (eq gnus-newsgroup-name
1480		   (car gnus-decode-encoded-word-methods-cache)))
1481    (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1482    (mapcar (lambda (x)
1483	      (if (symbolp x)
1484		  (nconc gnus-decode-encoded-word-methods-cache (list x))
1485		(if (and gnus-newsgroup-name
1486			 (string-match (car x) gnus-newsgroup-name))
1487		    (nconc gnus-decode-encoded-word-methods-cache
1488			   (list (cdr x))))))
1489	    gnus-decode-encoded-word-methods))
1490  (let ((xlist gnus-decode-encoded-word-methods-cache))
1491    (pop xlist)
1492    (while xlist
1493      (setq string (funcall (pop xlist) string))))
1494  string)
1495
1496;; Subject simplification.
1497
1498(defun gnus-simplify-whitespace (str)
1499  "Remove excessive whitespace from STR."
1500  ;; Multiple spaces.
1501  (while (string-match "[ \t][ \t]+" str)
1502    (setq str (concat (substring str 0 (match-beginning 0))
1503			" "
1504			(substring str (match-end 0)))))
1505  ;; Leading spaces.
1506  (when (string-match "^[ \t]+" str)
1507    (setq str (substring str (match-end 0))))
1508  ;; Trailing spaces.
1509  (when (string-match "[ \t]+$" str)
1510    (setq str (substring str 0 (match-beginning 0))))
1511  str)
1512
1513(defun gnus-simplify-all-whitespace (str)
1514  "Remove all whitespace from STR."
1515  (while (string-match "[ \t\n]+" str)
1516    (setq str (replace-match "" nil nil str)))
1517  str)
1518
1519(defsubst gnus-simplify-subject-re (subject)
1520  "Remove \"Re:\" from subject lines."
1521  (if (string-match message-subject-re-regexp subject)
1522      (substring subject (match-end 0))
1523    subject))
1524
1525(defun gnus-simplify-subject (subject &optional re-only)
1526  "Remove `Re:' and words in parentheses.
1527If RE-ONLY is non-nil, strip leading `Re:'s only."
1528  (let ((case-fold-search t))		;Ignore case.
1529    ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1530    (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1531      (setq subject (substring subject (match-end 0))))
1532    ;; Remove uninteresting prefixes.
1533    (when (and (not re-only)
1534	       gnus-simplify-ignored-prefixes
1535	       (string-match gnus-simplify-ignored-prefixes subject))
1536      (setq subject (substring subject (match-end 0))))
1537    ;; Remove words in parentheses from end.
1538    (unless re-only
1539      (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1540	(setq subject (substring subject 0 (match-beginning 0)))))
1541    ;; Return subject string.
1542    subject))
1543
1544;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1545;; all whitespace.
1546(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1547  (goto-char (point-min))
1548  (while (re-search-forward regexp nil t)
1549    (replace-match (or newtext ""))))
1550
1551(defun gnus-simplify-buffer-fuzzy ()
1552  "Simplify string in the buffer fuzzily.
1553The string in the accessible portion of the current buffer is simplified.
1554It is assumed to be a single-line subject.
1555Whitespace is generally cleaned up, and miscellaneous leading/trailing
1556matter is removed.  Additional things can be deleted by setting
1557`gnus-simplify-subject-fuzzy-regexp'."
1558  (let ((case-fold-search t)
1559	(modified-tick))
1560    (gnus-simplify-buffer-fuzzy-step "\t" " ")
1561
1562    (while (not (eq modified-tick (buffer-modified-tick)))
1563      (setq modified-tick (buffer-modified-tick))
1564      (cond
1565       ((listp gnus-simplify-subject-fuzzy-regexp)
1566	(mapcar 'gnus-simplify-buffer-fuzzy-step
1567		gnus-simplify-subject-fuzzy-regexp))
1568       (gnus-simplify-subject-fuzzy-regexp
1569	(gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1570      (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1571      (gnus-simplify-buffer-fuzzy-step
1572       "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1573      (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1574
1575    (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1576    (gnus-simplify-buffer-fuzzy-step "  +" " ")
1577    (gnus-simplify-buffer-fuzzy-step " $")
1578    (gnus-simplify-buffer-fuzzy-step "^ +")))
1579
1580(defun gnus-simplify-subject-fuzzy (subject)
1581  "Simplify a subject string fuzzily.
1582See `gnus-simplify-buffer-fuzzy' for details."
1583  (save-excursion
1584    (gnus-set-work-buffer)
1585    (let ((case-fold-search t))
1586      ;; Remove uninteresting prefixes.
1587      (when (and gnus-simplify-ignored-prefixes
1588		 (string-match gnus-simplify-ignored-prefixes subject))
1589	(setq subject (substring subject (match-end 0))))
1590      (insert subject)
1591      (inline (gnus-simplify-buffer-fuzzy))
1592      (buffer-string))))
1593
1594(defsubst gnus-simplify-subject-fully (subject)
1595  "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1596  (cond
1597   (gnus-simplify-subject-functions
1598    (gnus-map-function gnus-simplify-subject-functions subject))
1599   ((null gnus-summary-gather-subject-limit)
1600    (gnus-simplify-subject-re subject))
1601   ((eq gnus-summary-gather-subject-limit 'fuzzy)
1602    (gnus-simplify-subject-fuzzy subject))
1603   ((numberp gnus-summary-gather-subject-limit)
1604    (gnus-limit-string (gnus-simplify-subject-re subject)
1605		       gnus-summary-gather-subject-limit))
1606   (t
1607    subject)))
1608
1609(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1610  "Check whether two subjects are equal.
1611If optional argument SIMPLE-FIRST is t, first argument is already
1612simplified."
1613  (cond
1614   ((null simple-first)
1615    (equal (gnus-simplify-subject-fully s1)
1616	   (gnus-simplify-subject-fully s2)))
1617   (t
1618    (equal s1
1619	   (gnus-simplify-subject-fully s2)))))
1620
1621(defun gnus-summary-bubble-group ()
1622  "Increase the score of the current group.
1623This is a handy function to add to `gnus-summary-exit-hook' to
1624increase the score of each group you read."
1625  (gnus-group-add-score gnus-newsgroup-name))
1626
1627
1628;;;
1629;;; Gnus summary mode
1630;;;
1631
1632(put 'gnus-summary-mode 'mode-class 'special)
1633
1634(defvar gnus-article-commands-menu)
1635
1636;; Non-orthogonal keys
1637
1638(gnus-define-keys gnus-summary-mode-map
1639  " " gnus-summary-next-page
1640  "\177" gnus-summary-prev-page
1641  [delete] gnus-summary-prev-page
1642  [backspace] gnus-summary-prev-page
1643  "\r" gnus-summary-scroll-up
1644  "\M-\r" gnus-summary-scroll-down
1645  "n" gnus-summary-next-unread-article
1646  "p" gnus-summary-prev-unread-article
1647  "N" gnus-summary-next-article
1648  "P" gnus-summary-prev-article
1649  "\M-\C-n" gnus-summary-next-same-subject
1650  "\M-\C-p" gnus-summary-prev-same-subject
1651  "\M-n" gnus-summary-next-unread-subject
1652  "\M-p" gnus-summary-prev-unread-subject
1653  "." gnus-summary-first-unread-article
1654  "," gnus-summary-best-unread-article
1655  "\M-s" gnus-summary-search-article-forward
1656  "\M-r" gnus-summary-search-article-backward
1657  "<" gnus-summary-beginning-of-article
1658  ">" gnus-summary-end-of-article
1659  "j" gnus-summary-goto-article
1660  "^" gnus-summary-refer-parent-article
1661  "\M-^" gnus-summary-refer-article
1662  "u" gnus-summary-tick-article-forward
1663  "!" gnus-summary-tick-article-forward
1664  "U" gnus-summary-tick-article-backward
1665  "d" gnus-summary-mark-as-read-forward
1666  "D" gnus-summary-mark-as-read-backward
1667  "E" gnus-summary-mark-as-expirable
1668  "\M-u" gnus-summary-clear-mark-forward
1669  "\M-U" gnus-summary-clear-mark-backward
1670  "k" gnus-summary-kill-same-subject-and-select
1671  "\C-k" gnus-summary-kill-same-subject
1672  "\M-\C-k" gnus-summary-kill-thread
1673  "\M-\C-l" gnus-summary-lower-thread
1674  "e" gnus-summary-edit-article
1675  "#" gnus-summary-mark-as-processable
1676  "\M-#" gnus-summary-unmark-as-processable
1677  "\M-\C-t" gnus-summary-toggle-threads
1678  "\M-\C-s" gnus-summary-show-thread
1679  "\M-\C-h" gnus-summary-hide-thread
1680  "\M-\C-f" gnus-summary-next-thread
1681  "\M-\C-b" gnus-summary-prev-thread
1682  [(meta down)] gnus-summary-next-thread
1683  [(meta up)] gnus-summary-prev-thread
1684  "\M-\C-u" gnus-summary-up-thread
1685  "\M-\C-d" gnus-summary-down-thread
1686  "&" gnus-summary-execute-command
1687  "c" gnus-summary-catchup-and-exit
1688  "\C-w" gnus-summary-mark-region-as-read
1689  "\C-t" gnus-summary-toggle-truncation
1690  "?" gnus-summary-mark-as-dormant
1691  "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1692  "\C-c\C-s\C-n" gnus-summary-sort-by-number
1693  "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1694  "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1695  "\C-c\C-s\C-a" gnus-summary-sort-by-author
1696  "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1697  "\C-c\C-s\C-d" gnus-summary-sort-by-date
1698  "\C-c\C-s\C-i" gnus-summary-sort-by-score
1699  "\C-c\C-s\C-o" gnus-summary-sort-by-original
1700  "\C-c\C-s\C-r" gnus-summary-sort-by-random
1701  "=" gnus-summary-expand-window
1702  "\C-x\C-s" gnus-summary-reselect-current-group
1703  "\M-g" gnus-summary-rescan-group
1704  "w" gnus-summary-stop-page-breaking
1705  "\C-c\C-r" gnus-summary-caesar-message
1706  "f" gnus-summary-followup
1707  "F" gnus-summary-followup-with-original
1708  "C" gnus-summary-cancel-article
1709  "r" gnus-summary-reply
1710  "R" gnus-summary-reply-with-original
1711  "\C-c\C-f" gnus-summary-mail-forward
1712  "o" gnus-summary-save-article
1713  "\C-o" gnus-summary-save-article-mail
1714  "|" gnus-summary-pipe-output
1715  "\M-k" gnus-summary-edit-local-kill
1716  "\M-K" gnus-summary-edit-global-kill
1717  ;; "V" gnus-version
1718  "\C-c\C-d" gnus-summary-describe-group
1719  "q" gnus-summary-exit
1720  "Q" gnus-summary-exit-no-update
1721  "\C-c\C-i" gnus-info-find-node
1722  gnus-mouse-2 gnus-mouse-pick-article
1723  [follow-link] mouse-face
1724  "m" gnus-summary-mail-other-window
1725  "a" gnus-summary-post-news
1726  "i" gnus-summary-news-other-window
1727  "x" gnus-summary-limit-to-unread
1728  "s" gnus-summary-isearch-article
1729  "t" gnus-summary-toggle-header
1730  "g" gnus-summary-show-article
1731  "l" gnus-summary-goto-last-article
1732  "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1733  "\C-d" gnus-summary-enter-digest-group
1734  "\M-\C-d" gnus-summary-read-document
1735  "\M-\C-e" gnus-summary-edit-parameters
1736  "\M-\C-a" gnus-summary-customize-parameters
1737  "\C-c\C-b" gnus-bug
1738  "*" gnus-cache-enter-article
1739  "\M-*" gnus-cache-remove-article
1740  "\M-&" gnus-summary-universal-argument
1741  "\C-l" gnus-recenter
1742  "I" gnus-summary-increase-score
1743  "L" gnus-summary-lower-score
1744  "\M-i" gnus-symbolic-argument
1745  "h" gnus-summary-select-article-buffer
1746
1747  "b" gnus-article-view-part
1748  "\M-t" gnus-summary-toggle-display-buttonized
1749
1750  "V" gnus-summary-score-map
1751  "X" gnus-uu-extract-map
1752  "S" gnus-summary-send-map)
1753
1754;; Sort of orthogonal keymap
1755(gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1756  "t" gnus-summary-tick-article-forward
1757  "!" gnus-summary-tick-article-forward
1758  "d" gnus-summary-mark-as-read-forward
1759  "r" gnus-summary-mark-as-read-forward
1760  "c" gnus-summary-clear-mark-forward
1761  " " gnus-summary-clear-mark-forward
1762  "e" gnus-summary-mark-as-expirable
1763  "x" gnus-summary-mark-as-expirable
1764  "?" gnus-summary-mark-as-dormant
1765  "b" gnus-summary-set-bookmark
1766  "B" gnus-summary-remove-bookmark
1767  "#" gnus-summary-mark-as-processable
1768  "\M-#" gnus-summary-unmark-as-processable
1769  "S" gnus-summary-limit-include-expunged
1770  "C" gnus-summary-catchup
1771  "H" gnus-summary-catchup-to-here
1772  "h" gnus-summary-catchup-from-here
1773  "\C-c" gnus-summary-catchup-all
1774  "k" gnus-summary-kill-same-subject-and-select
1775  "K" gnus-summary-kill-same-subject
1776  "P" gnus-uu-mark-map)
1777
1778(gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1779  "c" gnus-summary-clear-above
1780  "u" gnus-summary-tick-above
1781  "m" gnus-summary-mark-above
1782  "k" gnus-summary-kill-below)
1783
1784(gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1785  "/" gnus-summary-limit-to-subject
1786  "n" gnus-summary-limit-to-articles
1787  "w" gnus-summary-pop-limit
1788  "s" gnus-summary-limit-to-subject
1789  "a" gnus-summary-limit-to-author
1790  "u" gnus-summary-limit-to-unread
1791  "m" gnus-summary-limit-to-marks
1792  "M" gnus-summary-limit-exclude-marks
1793  "v" gnus-summary-limit-to-score
1794  "*" gnus-summary-limit-include-cached
1795  "D" gnus-summary-limit-include-dormant
1796  "T" gnus-summary-limit-include-thread
1797  "d" gnus-summary-limit-exclude-dormant
1798  "t" gnus-summary-limit-to-age
1799  "." gnus-summary-limit-to-unseen
1800  "x" gnus-summary-limit-to-extra
1801  "p" gnus-summary-limit-to-display-predicate
1802  "E" gnus-summary-limit-include-expunged
1803  "c" gnus-summary-limit-exclude-childless-dormant
1804  "C" gnus-summary-limit-mark-excluded-as-read
1805  "o" gnus-summary-insert-old-articles
1806  "N" gnus-summary-insert-new-articles)
1807
1808(gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1809  "n" gnus-summary-next-unread-article
1810  "p" gnus-summary-prev-unread-article
1811  "N" gnus-summary-next-article
1812  "P" gnus-summary-prev-article
1813  "\C-n" gnus-summary-next-same-subject
1814  "\C-p" gnus-summary-prev-same-subject
1815  "\M-n" gnus-summary-next-unread-subject
1816  "\M-p" gnus-summary-prev-unread-subject
1817  "f" gnus-summary-first-unread-article
1818  "b" gnus-summary-best-unread-article
1819  "j" gnus-summary-goto-article
1820  "g" gnus-summary-goto-subject
1821  "l" gnus-summary-goto-last-article
1822  "o" gnus-summary-pop-article)
1823
1824(gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1825  "k" gnus-summary-kill-thread
1826  "l" gnus-summary-lower-thread
1827  "i" gnus-summary-raise-thread
1828  "T" gnus-summary-toggle-threads
1829  "t" gnus-summary-rethread-current
1830  "^" gnus-summary-reparent-thread
1831  "s" gnus-summary-show-thread
1832  "S" gnus-summary-show-all-threads
1833  "h" gnus-summary-hide-thread
1834  "H" gnus-summary-hide-all-threads
1835  "n" gnus-summary-next-thread
1836  "p" gnus-summary-prev-thread
1837  "u" gnus-summary-up-thread
1838  "o" gnus-summary-top-thread
1839  "d" gnus-summary-down-thread
1840  "#" gnus-uu-mark-thread
1841  "\M-#" gnus-uu-unmark-thread)
1842
1843(gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1844  "g" gnus-summary-prepare
1845  "c" gnus-summary-insert-cached-articles
1846  "d" gnus-summary-insert-dormant-articles)
1847
1848(gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1849  "c" gnus-summary-catchup-and-exit
1850  "C" gnus-summary-catchup-all-and-exit
1851  "E" gnus-summary-exit-no-update
1852  "Q" gnus-summary-exit
1853  "Z" gnus-summary-exit
1854  "n" gnus-summary-catchup-and-goto-next-group
1855  "R" gnus-summary-reselect-current-group
1856  "G" gnus-summary-rescan-group
1857  "N" gnus-summary-next-group
1858  "s" gnus-summary-save-newsrc
1859  "P" gnus-summary-prev-group)
1860
1861(gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1862  " " gnus-summary-next-page
1863  "n" gnus-summary-next-page
1864  "\177" gnus-summary-prev-page
1865  [delete] gnus-summary-prev-page
1866  "p" gnus-summary-prev-page
1867  "\r" gnus-summary-scroll-up
1868  "\M-\r" gnus-summary-scroll-down
1869  "<" gnus-summary-beginning-of-article
1870  ">" gnus-summary-end-of-article
1871  "b" gnus-summary-beginning-of-article
1872  "e" gnus-summary-end-of-article
1873  "^" gnus-summary-refer-parent-article
1874  "r" gnus-summary-refer-parent-article
1875  "D" gnus-summary-enter-digest-group
1876  "R" gnus-summary-refer-references
1877  "T" gnus-summary-refer-thread
1878  "g" gnus-summary-show-article
1879  "s" gnus-summary-isearch-article
1880  "P" gnus-summary-print-article
1881  "M" gnus-mailing-list-insinuate
1882  "t" gnus-article-babel)
1883
1884(gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1885  "b" gnus-article-add-buttons
1886  "B" gnus-article-add-buttons-to-head
1887  "o" gnus-article-treat-overstrike
1888  "e" gnus-article-emphasize
1889  "w" gnus-article-fill-cited-article
1890  "Q" gnus-article-fill-long-lines
1891  "C" gnus-article-capitalize-sentences
1892  "c" gnus-article-remove-cr
1893  "q" gnus-article-de-quoted-unreadable
1894  "6" gnus-article-de-base64-unreadable
1895  "Z" gnus-article-decode-HZ
1896  "h" gnus-article-wash-html
1897  "u" gnus-article-unsplit-urls
1898  "s" gnus-summary-force-verify-and-decrypt
1899  "f" gnus-article-display-x-face
1900  "l" gnus-summary-stop-page-breaking
1901  "r" gnus-summary-caesar-message
1902  "m" gnus-summary-morse-message
1903  "t" gnus-summary-toggle-header
1904  "g" gnus-treat-smiley
1905  "v" gnus-summary-verbose-headers
1906  "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1907  "p" gnus-article-verify-x-pgp-sig
1908  "d" gnus-article-treat-dumbquotes)
1909
1910(gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1911  ;; mnemonic: deuglif*Y*
1912  "u" gnus-article-outlook-unwrap-lines
1913  "a" gnus-article-outlook-repair-attribution
1914  "c" gnus-article-outlook-rearrange-citation
1915  "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1916
1917(gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1918  "a" gnus-article-hide
1919  "h" gnus-article-hide-headers
1920  "b" gnus-article-hide-boring-headers
1921  "s" gnus-article-hide-signature
1922  "c" gnus-article-hide-citation
1923  "C" gnus-article-hide-citation-in-followups
1924  "l" gnus-article-hide-list-identifiers
1925  "B" gnus-article-strip-banner
1926  "P" gnus-article-hide-pem
1927  "\C-c" gnus-article-hide-citation-maybe)
1928
1929(gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1930  "a" gnus-article-highlight
1931  "h" gnus-article-highlight-headers
1932  "c" gnus-article-highlight-citation
1933  "s" gnus-article-highlight-signature)
1934
1935(gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1936  "f" gnus-article-treat-fold-headers
1937  "u" gnus-article-treat-unfold-headers
1938  "n" gnus-article-treat-fold-newsgroups)
1939
1940(gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1941  "x" gnus-article-display-x-face
1942  "d" gnus-article-display-face
1943  "s" gnus-treat-smiley
1944  "D" gnus-article-remove-images
1945  "f" gnus-treat-from-picon
1946  "m" gnus-treat-mail-picon
1947  "n" gnus-treat-newsgroups-picon)
1948
1949(gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1950  "w" gnus-article-decode-mime-words
1951  "c" gnus-article-decode-charset
1952  "v" gnus-mime-view-all-parts
1953  "b" gnus-article-view-part)
1954
1955(gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1956  "z" gnus-article-date-ut
1957  "u" gnus-article-date-ut
1958  "l" gnus-article-date-local
1959  "p" gnus-article-date-english
1960  "e" gnus-article-date-lapsed
1961  "o" gnus-article-date-original
1962  "i" gnus-article-date-iso8601
1963  "s" gnus-article-date-user)
1964
1965(gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1966  "t" gnus-article-remove-trailing-blank-lines
1967  "l" gnus-article-strip-leading-blank-lines
1968  "m" gnus-article-strip-multiple-blank-lines
1969  "a" gnus-article-strip-blank-lines
1970  "A" gnus-article-strip-all-blank-lines
1971  "s" gnus-article-strip-leading-space
1972  "e" gnus-article-strip-trailing-space
1973  "w" gnus-article-remove-leading-whitespace)
1974
1975(gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1976  "v" gnus-version
1977  "f" gnus-summary-fetch-faq
1978  "d" gnus-summary-describe-group
1979  "h" gnus-summary-describe-briefly
1980  "i" gnus-info-find-node
1981  "c" gnus-group-fetch-charter
1982  "C" gnus-group-fetch-control)
1983
1984(gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1985  "e" gnus-summary-expire-articles
1986  "\M-\C-e" gnus-summary-expire-articles-now
1987  "\177" gnus-summary-delete-article
1988  [delete] gnus-summary-delete-article
1989  [backspace] gnus-summary-delete-article
1990  "m" gnus-summary-move-article
1991  "r" gnus-summary-respool-article
1992  "w" gnus-summary-edit-article
1993  "c" gnus-summary-copy-article
1994  "B" gnus-summary-crosspost-article
1995  "q" gnus-summary-respool-query
1996  "t" gnus-summary-respool-trace
1997  "i" gnus-summary-import-article
1998  "I" gnus-summary-create-article
1999  "p" gnus-summary-article-posted-p)
2000
2001(gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2002  "o" gnus-summary-save-article
2003  "m" gnus-summary-save-article-mail
2004  "F" gnus-summary-write-article-file
2005  "r" gnus-summary-save-article-rmail
2006  "f" gnus-summary-save-article-file
2007  "b" gnus-summary-save-article-body-file
2008  "B" gnus-summary-write-article-body-file
2009  "h" gnus-summary-save-article-folder
2010  "v" gnus-summary-save-article-vm
2011  "p" gnus-summary-pipe-output
2012  "P" gnus-summary-muttprint
2013  "s" gnus-soup-add-article)
2014
2015(gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2016  "b" gnus-summary-display-buttonized
2017  "m" gnus-summary-repair-multipart
2018  "v" gnus-article-view-part
2019  "o" gnus-article-save-part
2020  "c" gnus-article-copy-part
2021  "C" gnus-article-view-part-as-charset
2022  "e" gnus-article-view-part-externally
2023  "E" gnus-article-encrypt-body
2024  "i" gnus-article-inline-part
2025  "|" gnus-article-pipe-part)
2026
2027(gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2028  "p" gnus-summary-mark-as-processable
2029  "u" gnus-summary-unmark-as-processable
2030  "U" gnus-summary-unmark-all-processable
2031  "v" gnus-uu-mark-over
2032  "s" gnus-uu-mark-series
2033  "r" gnus-uu-mark-region
2034  "g" gnus-uu-unmark-region
2035  "R" gnus-uu-mark-by-regexp
2036  "G" gnus-uu-unmark-by-regexp
2037  "t" gnus-uu-mark-thread
2038  "T" gnus-uu-unmark-thread
2039  "a" gnus-uu-mark-all
2040  "b" gnus-uu-mark-buffer
2041  "S" gnus-uu-mark-sparse
2042  "k" gnus-summary-kill-process-mark
2043  "y" gnus-summary-yank-process-mark
2044  "w" gnus-summary-save-process-mark
2045  "i" gnus-uu-invert-processable)
2046
2047(gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2048  ;;"x" gnus-uu-extract-any
2049  "m" gnus-summary-save-parts
2050  "u" gnus-uu-decode-uu
2051  "U" gnus-uu-decode-uu-and-save
2052  "s" gnus-uu-decode-unshar
2053  "S" gnus-uu-decode-unshar-and-save
2054  "o" gnus-uu-decode-save
2055  "O" gnus-uu-decode-save
2056  "b" gnus-uu-decode-binhex
2057  "B" gnus-uu-decode-binhex
2058  "p" gnus-uu-decode-postscript
2059  "P" gnus-uu-decode-postscript-and-save)
2060
2061(gnus-define-keys
2062    (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2063  "u" gnus-uu-decode-uu-view
2064  "U" gnus-uu-decode-uu-and-save-view
2065  "s" gnus-uu-decode-unshar-view
2066  "S" gnus-uu-decode-unshar-and-save-view
2067  "o" gnus-uu-decode-save-view
2068  "O" gnus-uu-decode-save-view
2069  "b" gnus-uu-decode-binhex-view
2070  "B" gnus-uu-decode-binhex-view
2071  "p" gnus-uu-decode-postscript-view
2072  "P" gnus-uu-decode-postscript-and-save-view)
2073
2074(defvar gnus-article-post-menu nil)
2075
2076(defconst gnus-summary-menu-maxlen 20)
2077
2078(defun gnus-summary-menu-split (menu)
2079  ;; If we have lots of elements, divide them into groups of 20
2080  ;; and make a pane (or submenu) for each one.
2081  (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2082      (let ((menu menu) sublists next
2083	    (i 1))
2084	(while menu
2085	  ;; Pull off the next gnus-summary-menu-maxlen elements
2086	  ;; and make them the next element of sublist.
2087	  (setq next (nthcdr gnus-summary-menu-maxlen menu))
2088	  (if next
2089	      (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2090		      nil))
2091	  (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2092					     (aref (car (last menu)) 0)) menu)
2093			       sublists))
2094	  (setq i (1+ i))
2095	  (setq menu next))
2096	(nreverse sublists))
2097    ;; Few elements--put them all in one pane.
2098    menu))
2099
2100(defun gnus-summary-make-menu-bar ()
2101  (gnus-turn-off-edit-menu 'summary)
2102
2103  (unless (boundp 'gnus-summary-misc-menu)
2104
2105    (easy-menu-define
2106      gnus-summary-kill-menu gnus-summary-mode-map ""
2107      (cons
2108       "Score"
2109       (nconc
2110	(list
2111	 ["Customize" gnus-score-customize t])
2112	(gnus-make-score-map 'increase)
2113	(gnus-make-score-map 'lower)
2114	'(("Mark"
2115	   ["Kill below" gnus-summary-kill-below t]
2116	   ["Mark above" gnus-summary-mark-above t]
2117	   ["Tick above" gnus-summary-tick-above t]
2118	   ["Clear above" gnus-summary-clear-above t])
2119	  ["Current score" gnus-summary-current-score t]
2120	  ["Set score" gnus-summary-set-score t]
2121	  ["Switch current score file..." gnus-score-change-score-file t]
2122	  ["Set mark below..." gnus-score-set-mark-below t]
2123	  ["Set expunge below..." gnus-score-set-expunge-below t]
2124	  ["Edit current score file" gnus-score-edit-current-scores t]
2125	  ["Edit score file" gnus-score-edit-file t]
2126	  ["Trace score" gnus-score-find-trace t]
2127	  ["Find words" gnus-score-find-favourite-words t]
2128	  ["Rescore buffer" gnus-summary-rescore t]
2129	  ["Increase score..." gnus-summary-increase-score t]
2130	  ["Lower score..." gnus-summary-lower-score t]))))
2131
2132    ;; Define both the Article menu in the summary buffer and the
2133    ;; equivalent Commands menu in the article buffer here for
2134    ;; consistency.
2135    (let ((innards
2136	   `(("Hide"
2137	      ["All" gnus-article-hide t]
2138	      ["Headers" gnus-article-hide-headers t]
2139	      ["Signature" gnus-article-hide-signature t]
2140	      ["Citation" gnus-article-hide-citation t]
2141	      ["List identifiers" gnus-article-hide-list-identifiers t]
2142	      ["Banner" gnus-article-strip-banner t]
2143	      ["Boring headers" gnus-article-hide-boring-headers t])
2144	     ("Highlight"
2145	      ["All" gnus-article-highlight t]
2146	      ["Headers" gnus-article-highlight-headers t]
2147	      ["Signature" gnus-article-highlight-signature t]
2148	      ["Citation" gnus-article-highlight-citation t])
2149	     ("MIME"
2150	      ["Words" gnus-article-decode-mime-words t]
2151	      ["Charset" gnus-article-decode-charset t]
2152	      ["QP" gnus-article-de-quoted-unreadable t]
2153	      ["Base64" gnus-article-de-base64-unreadable t]
2154	      ["View MIME buttons" gnus-summary-display-buttonized t]
2155	      ["View all" gnus-mime-view-all-parts t]
2156	      ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2157	      ["Encrypt body" gnus-article-encrypt-body
2158	       :active (not (gnus-group-read-only-p))
2159	       ,@(if (featurep 'xemacs) nil
2160		   '(:help "Encrypt the message body on disk"))]
2161	      ["Extract all parts..." gnus-summary-save-parts t]
2162	      ("Multipart"
2163	       ["Repair multipart" gnus-summary-repair-multipart t]
2164	       ["Pipe part..." gnus-article-pipe-part t]
2165	       ["Inline part" gnus-article-inline-part t]
2166	       ["Encrypt body" gnus-article-encrypt-body
2167		:active (not (gnus-group-read-only-p))
2168	       ,@(if (featurep 'xemacs) nil
2169		   '(:help "Encrypt the message body on disk"))]
2170	       ["View part externally" gnus-article-view-part-externally t]
2171	       ["View part with charset..." gnus-article-view-part-as-charset t]
2172	       ["Copy part" gnus-article-copy-part t]
2173	       ["Save part..." gnus-article-save-part t]
2174	       ["View part" gnus-article-view-part t]))
2175	     ("Date"
2176	      ["Local" gnus-article-date-local t]
2177	      ["ISO8601" gnus-article-date-iso8601 t]
2178	      ["UT" gnus-article-date-ut t]
2179	      ["Original" gnus-article-date-original t]
2180	      ["Lapsed" gnus-article-date-lapsed t]
2181	      ["User-defined" gnus-article-date-user t])
2182	     ("Display"
2183	      ["Remove images" gnus-article-remove-images t]
2184	      ["Toggle smiley" gnus-treat-smiley t]
2185	      ["Show X-Face" gnus-article-display-x-face t]
2186	      ["Show picons in From" gnus-treat-from-picon t]
2187	      ["Show picons in mail headers" gnus-treat-mail-picon t]
2188	      ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2189	      ("View as different encoding"
2190	       ,@(gnus-summary-menu-split
2191		  (mapcar
2192		   (lambda (cs)
2193		     ;; Since easymenu under Emacs doesn't allow
2194		     ;; lambda forms for menu commands, we should
2195		     ;; provide intern'ed function symbols.
2196		     (let ((command (intern (format "\
2197gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2198		       (fset command
2199			     `(lambda ()
2200				(interactive)
2201				(let ((gnus-summary-show-article-charset-alist
2202				       '((1 . ,cs))))
2203				  (gnus-summary-show-article 1))))
2204		       `[,(symbol-name cs) ,command t]))
2205		   (sort (if (fboundp 'coding-system-list)
2206			     (coding-system-list)
2207			   (mapcar 'car mm-mime-mule-charset-alist))
2208			 'string<)))))
2209	     ("Washing"
2210	      ("Remove Blanks"
2211	       ["Leading" gnus-article-strip-leading-blank-lines t]
2212	       ["Multiple" gnus-article-strip-multiple-blank-lines t]
2213	       ["Trailing" gnus-article-remove-trailing-blank-lines t]
2214	       ["All of the above" gnus-article-strip-blank-lines t]
2215	       ["All" gnus-article-strip-all-blank-lines t]
2216	       ["Leading space" gnus-article-strip-leading-space t]
2217	       ["Trailing space" gnus-article-strip-trailing-space t]
2218	       ["Leading space in headers"
2219		gnus-article-remove-leading-whitespace t])
2220	      ["Overstrike" gnus-article-treat-overstrike t]
2221	      ["Dumb quotes" gnus-article-treat-dumbquotes t]
2222	      ["Emphasis" gnus-article-emphasize t]
2223	      ["Word wrap" gnus-article-fill-cited-article t]
2224	      ["Fill long lines" gnus-article-fill-long-lines t]
2225	      ["Capitalize sentences" gnus-article-capitalize-sentences t]
2226	      ["Remove CR" gnus-article-remove-cr t]
2227	      ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2228	      ["Base64" gnus-article-de-base64-unreadable t]
2229	      ["Rot 13" gnus-summary-caesar-message
2230	       ,@(if (featurep 'xemacs) '(t)
2231		   '(:help "\"Caesar rotate\" article by 13"))]
2232	      ["Morse decode" gnus-summary-morse-message t]
2233	      ["Unix pipe..." gnus-summary-pipe-message t]
2234	      ["Add buttons" gnus-article-add-buttons t]
2235	      ["Add buttons to head" gnus-article-add-buttons-to-head t]
2236	      ["Stop page breaking" gnus-summary-stop-page-breaking t]
2237	      ["Verbose header" gnus-summary-verbose-headers t]
2238	      ["Toggle header" gnus-summary-toggle-header t]
2239	      ["Unfold headers" gnus-article-treat-unfold-headers t]
2240	      ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2241	      ["Html" gnus-article-wash-html t]
2242	      ["Unsplit URLs" gnus-article-unsplit-urls t]
2243	      ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2244	      ["Decode HZ" gnus-article-decode-HZ t]
2245	      ("(Outlook) Deuglify"
2246	       ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2247	       ["Repair attribution" gnus-article-outlook-repair-attribution t]
2248	       ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2249	       ["Full (Outlook) deuglify"
2250		gnus-article-outlook-deuglify-article t])
2251	      )
2252	     ("Output"
2253	      ["Save in default format..." gnus-summary-save-article
2254	       ,@(if (featurep 'xemacs) '(t)
2255		   '(:help "Save article using default method"))]
2256	      ["Save in file..." gnus-summary-save-article-file
2257	       ,@(if (featurep 'xemacs) '(t)
2258		   '(:help "Save article in file"))]
2259	      ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2260	      ["Save in MH folder..." gnus-summary-save-article-folder t]
2261	      ["Save in VM folder..." gnus-summary-save-article-vm t]
2262	      ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2263	      ["Save body in file..." gnus-summary-save-article-body-file t]
2264	      ["Pipe through a filter..." gnus-summary-pipe-output t]
2265	      ["Add to SOUP packet" gnus-soup-add-article t]
2266	      ["Print with Muttprint..." gnus-summary-muttprint t]
2267	      ["Print" gnus-summary-print-article
2268	       ,@(if (featurep 'xemacs) '(t)
2269		   '(:help "Generate and print a PostScript image"))])
2270	     ("Copy, move,... (Backend)"
2271	      ,@(if (featurep 'xemacs) nil
2272		  '(:help "Copying, moving, expiring articles..."))
2273	      ["Respool article..." gnus-summary-respool-article t]
2274	      ["Move article..." gnus-summary-move-article
2275	       (gnus-check-backend-function
2276		'request-move-article gnus-newsgroup-name)]
2277	      ["Copy article..." gnus-summary-copy-article t]
2278	      ["Crosspost article..." gnus-summary-crosspost-article
2279	       (gnus-check-backend-function
2280		'request-replace-article gnus-newsgroup-name)]
2281	      ["Import file..." gnus-summary-import-article
2282	       (gnus-check-backend-function
2283		'request-accept-article gnus-newsgroup-name)]
2284	      ["Create article..." gnus-summary-create-article
2285	       (gnus-check-backend-function
2286		'request-accept-article gnus-newsgroup-name)]
2287	      ["Check if posted" gnus-summary-article-posted-p t]
2288	      ["Edit article" gnus-summary-edit-article
2289	       (not (gnus-group-read-only-p))]
2290	      ["Delete article" gnus-summary-delete-article
2291	       (gnus-check-backend-function
2292		'request-expire-articles gnus-newsgroup-name)]
2293	      ["Query respool" gnus-summary-respool-query t]
2294	      ["Trace respool" gnus-summary-respool-trace t]
2295	      ["Delete expirable articles" gnus-summary-expire-articles-now
2296	       (gnus-check-backend-function
2297		'request-expire-articles gnus-newsgroup-name)])
2298	     ("Extract"
2299	      ["Uudecode" gnus-uu-decode-uu
2300	       ,@(if (featurep 'xemacs) '(t)
2301		   '(:help "Decode uuencoded article(s)"))]
2302	      ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2303	      ["Unshar" gnus-uu-decode-unshar t]
2304	      ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2305	      ["Save" gnus-uu-decode-save t]
2306	      ["Binhex" gnus-uu-decode-binhex t]
2307	      ["Postscript" gnus-uu-decode-postscript t]
2308	      ["All MIME parts" gnus-summary-save-parts t])
2309	     ("Cache"
2310	      ["Enter article" gnus-cache-enter-article t]
2311	      ["Remove article" gnus-cache-remove-article t])
2312	     ["Translate" gnus-article-babel t]
2313	     ["Select article buffer" gnus-summary-select-article-buffer t]
2314	     ["Enter digest buffer" gnus-summary-enter-digest-group t]
2315	     ["Isearch article..." gnus-summary-isearch-article t]
2316	     ["Beginning of the article" gnus-summary-beginning-of-article t]
2317	     ["End of the article" gnus-summary-end-of-article t]
2318	     ["Fetch parent of article" gnus-summary-refer-parent-article t]
2319	     ["Fetch referenced articles" gnus-summary-refer-references t]
2320	     ["Fetch current thread" gnus-summary-refer-thread t]
2321	     ["Fetch article with id..." gnus-summary-refer-article t]
2322	     ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2323	     ["Redisplay" gnus-summary-show-article t]
2324	     ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2325      (easy-menu-define
2326	gnus-summary-article-menu gnus-summary-mode-map ""
2327	(cons "Article" innards))
2328
2329      (if (not (keymapp gnus-summary-article-menu))
2330	  (easy-menu-define
2331	    gnus-article-commands-menu gnus-article-mode-map ""
2332	    (cons "Commands" innards))
2333	;; in Emacs, don't share menu.
2334	(setq gnus-article-commands-menu
2335	      (copy-keymap gnus-summary-article-menu))
2336	(define-key gnus-article-mode-map [menu-bar commands]
2337	  (cons "Commands" gnus-article-commands-menu))))
2338
2339    (easy-menu-define
2340      gnus-summary-thread-menu gnus-summary-mode-map ""
2341      '("Threads"
2342	["Find all messages in thread" gnus-summary-refer-thread t]
2343	["Toggle threading" gnus-summary-toggle-threads t]
2344	["Hide threads" gnus-summary-hide-all-threads t]
2345	["Show threads" gnus-summary-show-all-threads t]
2346	["Hide thread" gnus-summary-hide-thread t]
2347	["Show thread" gnus-summary-show-thread t]
2348	["Go to next thread" gnus-summary-next-thread t]
2349	["Go to previous thread" gnus-summary-prev-thread t]
2350	["Go down thread" gnus-summary-down-thread t]
2351	["Go up thread" gnus-summary-up-thread t]
2352	["Top of thread" gnus-summary-top-thread t]
2353	["Mark thread as read" gnus-summary-kill-thread t]
2354	["Lower thread score" gnus-summary-lower-thread t]
2355	["Raise thread score" gnus-summary-raise-thread t]
2356	["Rethread current" gnus-summary-rethread-current t]))
2357
2358    (easy-menu-define
2359      gnus-summary-post-menu gnus-summary-mode-map ""
2360      `("Post"
2361	["Send a message (mail or news)" gnus-summary-post-news
2362	 ,@(if (featurep 'xemacs) '(t)
2363	     '(:help "Compose a new message (mail or news)"))]
2364	["Followup" gnus-summary-followup
2365	 ,@(if (featurep 'xemacs) '(t)
2366	     '(:help "Post followup to this article"))]
2367	["Followup and yank" gnus-summary-followup-with-original
2368	 ,@(if (featurep 'xemacs) '(t)
2369	     '(:help "Post followup to this article, quoting its contents"))]
2370	["Supersede article" gnus-summary-supersede-article t]
2371	["Cancel article" gnus-summary-cancel-article
2372	 ,@(if (featurep 'xemacs) '(t)
2373	     '(:help "Cancel an article you posted"))]
2374	["Reply" gnus-summary-reply t]
2375	["Reply and yank" gnus-summary-reply-with-original t]
2376	["Wide reply" gnus-summary-wide-reply t]
2377	["Wide reply and yank" gnus-summary-wide-reply-with-original
2378	 ,@(if (featurep 'xemacs) '(t)
2379	     '(:help "Mail a reply, quoting this article"))]
2380	["Very wide reply" gnus-summary-very-wide-reply t]
2381	["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2382	 ,@(if (featurep 'xemacs) '(t)
2383	     '(:help "Mail a very wide reply, quoting this article"))]
2384	["Mail forward" gnus-summary-mail-forward t]
2385	["Post forward" gnus-summary-post-forward t]
2386	["Digest and mail" gnus-uu-digest-mail-forward t]
2387	["Digest and post" gnus-uu-digest-post-forward t]
2388	["Resend message" gnus-summary-resend-message t]
2389	["Resend message edit" gnus-summary-resend-message-edit t]
2390	["Send bounced mail" gnus-summary-resend-bounced-mail t]
2391	["Send a mail" gnus-summary-mail-other-window t]
2392	["Create a local message" gnus-summary-news-other-window t]
2393	["Uuencode and post" gnus-uu-post-news
2394	 ,@(if (featurep 'xemacs) '(t)
2395	     '(:help "Post a uuencoded article"))]
2396	["Followup via news" gnus-summary-followup-to-mail t]
2397	["Followup via news and yank"
2398	 gnus-summary-followup-to-mail-with-original t]
2399	;;("Draft"
2400	;;["Send" gnus-summary-send-draft t]
2401	;;["Send bounced" gnus-resend-bounced-mail t])
2402	))
2403
2404    (cond
2405     ((not (keymapp gnus-summary-post-menu))
2406      (setq gnus-article-post-menu gnus-summary-post-menu))
2407     ((not gnus-article-post-menu)
2408      ;; Don't share post menu.
2409      (setq gnus-article-post-menu
2410	    (copy-keymap gnus-summary-post-menu))))
2411    (define-key gnus-article-mode-map [menu-bar post]
2412      (cons "Post" gnus-article-post-menu))
2413
2414    (easy-menu-define
2415      gnus-summary-misc-menu gnus-summary-mode-map ""
2416      `("Gnus"
2417	("Mark Read"
2418	 ["Mark as read" gnus-summary-mark-as-read-forward t]
2419	 ["Mark same subject and select"
2420	  gnus-summary-kill-same-subject-and-select t]
2421	 ["Mark same subject" gnus-summary-kill-same-subject t]
2422	 ["Catchup" gnus-summary-catchup
2423	  ,@(if (featurep 'xemacs) '(t)
2424	      '(:help "Mark unread articles in this group as read"))]
2425	 ["Catchup all" gnus-summary-catchup-all t]
2426	 ["Catchup to here" gnus-summary-catchup-to-here t]
2427	 ["Catchup from here" gnus-summary-catchup-from-here t]
2428	 ["Catchup region" gnus-summary-mark-region-as-read
2429	  (gnus-mark-active-p)]
2430	 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2431	("Mark Various"
2432	 ["Tick" gnus-summary-tick-article-forward t]
2433	 ["Mark as dormant" gnus-summary-mark-as-dormant t]
2434	 ["Remove marks" gnus-summary-clear-mark-forward t]
2435	 ["Set expirable mark" gnus-summary-mark-as-expirable t]
2436	 ["Set bookmark" gnus-summary-set-bookmark t]
2437	 ["Remove bookmark" gnus-summary-remove-bookmark t])
2438	("Limit to"
2439	 ["Marks..." gnus-summary-limit-to-marks t]
2440	 ["Subject..." gnus-summary-limit-to-subject t]
2441	 ["Author..." gnus-summary-limit-to-author t]
2442	 ["Age..." gnus-summary-limit-to-age t]
2443	 ["Extra..." gnus-summary-limit-to-extra t]
2444	 ["Score..." gnus-summary-limit-to-score t]
2445	 ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2446	 ["Unread" gnus-summary-limit-to-unread t]
2447	 ["Unseen" gnus-summary-limit-to-unseen t]
2448	 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2449	 ["Next or process marked articles" gnus-summary-limit-to-articles t]
2450	 ["Pop limit" gnus-summary-pop-limit t]
2451	 ["Show dormant" gnus-summary-limit-include-dormant t]
2452	 ["Hide childless dormant"
2453	  gnus-summary-limit-exclude-childless-dormant t]
2454	 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2455	 ["Hide marked" gnus-summary-limit-exclude-marks t]
2456	 ["Show expunged" gnus-summary-limit-include-expunged t])
2457	("Process Mark"
2458	 ["Set mark" gnus-summary-mark-as-processable t]
2459	 ["Remove mark" gnus-summary-unmark-as-processable t]
2460	 ["Remove all marks" gnus-summary-unmark-all-processable t]
2461	 ["Mark above" gnus-uu-mark-over t]
2462	 ["Mark series" gnus-uu-mark-series t]
2463	 ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2464	 ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2465	 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2466	 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2467	 ["Mark all" gnus-uu-mark-all t]
2468	 ["Mark buffer" gnus-uu-mark-buffer t]
2469	 ["Mark sparse" gnus-uu-mark-sparse t]
2470	 ["Mark thread" gnus-uu-mark-thread t]
2471	 ["Unmark thread" gnus-uu-unmark-thread t]
2472	 ("Process Mark Sets"
2473	  ["Kill" gnus-summary-kill-process-mark t]
2474	  ["Yank" gnus-summary-yank-process-mark
2475	   gnus-newsgroup-process-stack]
2476	  ["Save" gnus-summary-save-process-mark t]
2477	  ["Run command on marked..." gnus-summary-universal-argument t]))
2478	("Scroll article"
2479	 ["Page forward" gnus-summary-next-page
2480	  ,@(if (featurep 'xemacs) '(t)
2481	      '(:help "Show next page of article"))]
2482	 ["Page backward" gnus-summary-prev-page
2483	  ,@(if (featurep 'xemacs) '(t)
2484	      '(:help "Show previous page of article"))]
2485	 ["Line forward" gnus-summary-scroll-up t])
2486	("Move"
2487	 ["Next unread article" gnus-summary-next-unread-article t]
2488	 ["Previous unread article" gnus-summary-prev-unread-article t]
2489	 ["Next article" gnus-summary-next-article t]
2490	 ["Previous article" gnus-summary-prev-article t]
2491	 ["Next unread subject" gnus-summary-next-unread-subject t]
2492	 ["Previous unread subject" gnus-summary-prev-unread-subject t]
2493	 ["Next article same subject" gnus-summary-next-same-subject t]
2494	 ["Previous article same subject" gnus-summary-prev-same-subject t]
2495	 ["First unread article" gnus-summary-first-unread-article t]
2496	 ["Best unread article" gnus-summary-best-unread-article t]
2497	 ["Go to subject number..." gnus-summary-goto-subject t]
2498	 ["Go to article number..." gnus-summary-goto-article t]
2499	 ["Go to the last article" gnus-summary-goto-last-article t]
2500	 ["Pop article off history" gnus-summary-pop-article t])
2501	("Sort"
2502	 ["Sort by number" gnus-summary-sort-by-number t]
2503	 ["Sort by author" gnus-summary-sort-by-author t]
2504	 ["Sort by subject" gnus-summary-sort-by-subject t]
2505	 ["Sort by date" gnus-summary-sort-by-date t]
2506	 ["Sort by score" gnus-summary-sort-by-score t]
2507	 ["Sort by lines" gnus-summary-sort-by-lines t]
2508	 ["Sort by characters" gnus-summary-sort-by-chars t]
2509	 ["Randomize" gnus-summary-sort-by-random t]
2510	 ["Original sort" gnus-summary-sort-by-original t])
2511	("Help"
2512	 ["Fetch group FAQ" gnus-summary-fetch-faq t]
2513	 ["Describe group" gnus-summary-describe-group t]
2514	 ["Fetch charter" gnus-group-fetch-charter
2515	  ,@(if (featurep 'xemacs) nil
2516	      '(:help "Display the charter of the current group"))]
2517	 ["Fetch control message" gnus-group-fetch-control
2518	  ,@(if (featurep 'xemacs) nil
2519	      '(:help "Display the archived control message for the current group"))]
2520	 ["Read manual" gnus-info-find-node t])
2521	("Modes"
2522	 ["Pick and read" gnus-pick-mode t]
2523	 ["Binary" gnus-binary-mode t])
2524	("Regeneration"
2525	 ["Regenerate" gnus-summary-prepare t]
2526	 ["Insert cached articles" gnus-summary-insert-cached-articles t]
2527	 ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2528	 ["Toggle threading" gnus-summary-toggle-threads t])
2529	["See old articles" gnus-summary-insert-old-articles t]
2530	["See new articles" gnus-summary-insert-new-articles t]
2531	["Filter articles..." gnus-summary-execute-command t]
2532	["Run command on articles..." gnus-summary-universal-argument t]
2533	["Search articles forward..." gnus-summary-search-article-forward t]
2534	["Search articles backward..." gnus-summary-search-article-backward t]
2535	["Toggle line truncation" gnus-summary-toggle-truncation t]
2536	["Expand window" gnus-summary-expand-window t]
2537	["Expire expirable articles" gnus-summary-expire-articles
2538	 (gnus-check-backend-function
2539	  'request-expire-articles gnus-newsgroup-name)]
2540	["Edit local kill file" gnus-summary-edit-local-kill t]
2541	["Edit main kill file" gnus-summary-edit-global-kill t]
2542	["Edit group parameters" gnus-summary-edit-parameters t]
2543	["Customize group parameters" gnus-summary-customize-parameters t]
2544	["Send a bug report" gnus-bug t]
2545	("Exit"
2546	 ["Catchup and exit" gnus-summary-catchup-and-exit
2547	  ,@(if (featurep 'xemacs) '(t)
2548	      '(:help "Mark unread articles in this group as read, then exit"))]
2549	 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2550	 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2551	 ["Exit group" gnus-summary-exit
2552	  ,@(if (featurep 'xemacs) '(t)
2553	      '(:help "Exit current group, return to group selection mode"))]
2554	 ["Exit group without updating" gnus-summary-exit-no-update t]
2555	 ["Exit and goto next group" gnus-summary-next-group t]
2556	 ["Exit and goto prev group" gnus-summary-prev-group t]
2557	 ["Reselect group" gnus-summary-reselect-current-group t]
2558	 ["Rescan group" gnus-summary-rescan-group t]
2559	 ["Update dribble" gnus-summary-save-newsrc t])))
2560
2561    (gnus-run-hooks 'gnus-summary-menu-hook)))
2562
2563(defvar gnus-summary-tool-bar-map nil)
2564
2565;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2566;; affect _new_ message buffers.  We might add a function that walks thru all
2567;; summary-mode buffers and force the update.
2568(defun gnus-summary-tool-bar-update (&optional symbol value)
2569  "Update summary mode toolbar.
2570Setter function for custom variables."
2571  (setq-default gnus-summary-tool-bar-map nil)
2572  (when symbol
2573    ;; When used as ":set" function:
2574    (set-default symbol value))
2575  (when (gnus-buffer-live-p gnus-summary-buffer)
2576    (with-current-buffer gnus-summary-buffer
2577      (gnus-summary-make-tool-bar))))
2578
2579(defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2580				     'gnus-summary-tool-bar-gnome
2581				   'gnus-summary-tool-bar-retro)
2582  "Specifies the Gnus summary tool bar.
2583
2584It can be either a list or a symbol refering to a list.  See
2585`gmm-tool-bar-from-list' for the format of the list.  The
2586default key map is `gnus-summary-mode-map'.
2587
2588Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2589`gnus-summary-tool-bar-retro'."
2590  :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2591		 (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2592		 (repeat :tag "User defined list" gmm-tool-bar-item)
2593		 (symbol))
2594  :version "22.1" ;; Gnus 5.10.9
2595  :initialize 'custom-initialize-default
2596  :set 'gnus-summary-tool-bar-update
2597  :group 'gnus-summary)
2598
2599(defcustom gnus-summary-tool-bar-gnome
2600  '((gnus-summary-post-news "mail/compose" nil)
2601    (gnus-summary-insert-new-articles "mail/inbox" nil
2602				      :visible (or (not gnus-agent)
2603						   gnus-plugged))
2604    (gnus-summary-reply-with-original "mail/reply")
2605    (gnus-summary-reply "mail/reply" nil :visible nil)
2606    (gnus-summary-followup-with-original "mail/reply-all")
2607    (gnus-summary-followup "mail/reply-all" nil :visible nil)
2608    (gnus-summary-mail-forward "mail/forward")
2609    (gnus-summary-save-article "mail/save")
2610    (gnus-summary-search-article-forward "search" nil :visible nil)
2611    (gnus-summary-print-article "print")
2612    (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2613    ;; Some new commands that may need more suitable icons:
2614    (gnus-summary-save-newsrc "save" nil :visible nil)
2615    ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2616    (gnus-summary-prev-article "left-arrow")
2617    (gnus-summary-next-article "right-arrow")
2618    (gnus-summary-next-page "next-page")
2619    ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2620    ;;
2621    ;; Maybe some sort-by-... could be added:
2622    ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2623    ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2624    (gnus-summary-mark-as-expirable
2625     "delete" nil
2626     :visible (gnus-check-backend-function 'request-expire-articles
2627					   gnus-newsgroup-name))
2628    (gnus-summary-mark-as-spam
2629     "mail/spam" t
2630     :visible (and (fboundp 'spam-group-ham-contents-p)
2631		   (spam-group-ham-contents-p gnus-newsgroup-name))
2632     :help "Mark as spam")
2633    (gnus-summary-mark-as-read-forward
2634     "mail/not-spam" nil
2635     :visible (and (fboundp 'spam-group-spam-contents-p)
2636		   (spam-group-spam-contents-p gnus-newsgroup-name)))
2637    ;;
2638    (gnus-summary-exit "exit")
2639    (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2640    (gnus-info-find-node "help"))
2641  "List of functions for the summary tool bar (GNOME style).
2642
2643See `gmm-tool-bar-from-list' for the format of the list."
2644  :type '(repeat gmm-tool-bar-item)
2645  :version "22.1" ;; Gnus 5.10.9
2646  :initialize 'custom-initialize-default
2647  :set 'gnus-summary-tool-bar-update
2648  :group 'gnus-summary)
2649
2650(defcustom gnus-summary-tool-bar-retro
2651  '((gnus-summary-prev-unread-article "gnus/prev-ur")
2652    (gnus-summary-next-unread-article "gnus/next-ur")
2653    (gnus-summary-post-news "gnus/post")
2654    (gnus-summary-followup-with-original "gnus/fuwo")
2655    (gnus-summary-followup "gnus/followup")
2656    (gnus-summary-reply-with-original "gnus/reply-wo")
2657    (gnus-summary-reply "gnus/reply")
2658    (gnus-summary-caesar-message "gnus/rot13")
2659    (gnus-uu-decode-uu "gnus/uu-decode")
2660    (gnus-summary-save-article-file "gnus/save-aif")
2661    (gnus-summary-save-article "gnus/save-art")
2662    (gnus-uu-post-news "gnus/uu-post")
2663    (gnus-summary-catchup "gnus/catchup")
2664    (gnus-summary-catchup-and-exit "gnus/cu-exit")
2665    (gnus-summary-exit "gnus/exit-summ")
2666    ;; Some new command that may need more suitable icons:
2667    (gnus-summary-print-article "gnus/print" nil :visible nil)
2668    (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2669    (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2670    ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2671    (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2672    ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2673    ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2674    ;;
2675    (gnus-info-find-node "gnus/help" nil :visible nil))
2676  "List of functions for the summary tool bar (retro look).
2677
2678See `gmm-tool-bar-from-list' for the format of the list."
2679  :type '(repeat gmm-tool-bar-item)
2680  :version "22.1" ;; Gnus 5.10.9
2681  :initialize 'custom-initialize-default
2682  :set 'gnus-summary-tool-bar-update
2683  :group 'gnus-summary)
2684
2685(defcustom gnus-summary-tool-bar-zap-list t
2686  "List of icon items from the global tool bar.
2687These items are not displayed in the Gnus summary mode tool bar.
2688
2689See `gmm-tool-bar-from-list' for the format of the list."
2690  :type 'gmm-tool-bar-zap-list
2691  :version "22.1" ;; Gnus 5.10.9
2692  :initialize 'custom-initialize-default
2693  :set 'gnus-summary-tool-bar-update
2694  :group 'gnus-summary)
2695
2696(defvar image-load-path)
2697
2698(defun gnus-summary-make-tool-bar (&optional force)
2699  "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2700When FORCE, rebuild the tool bar."
2701  (when (and (not (featurep 'xemacs))
2702	     (boundp 'tool-bar-mode)
2703	     tool-bar-mode
2704	     (or (not gnus-summary-tool-bar-map) force))
2705    (let* ((load-path
2706	    (gmm-image-load-path-for-library "gnus"
2707					     "mail/save.xpm"
2708					     nil t))
2709           (image-load-path (cons (car load-path)
2710                                  (when (boundp 'image-load-path)
2711                                    image-load-path)))
2712	   (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2713					gnus-summary-tool-bar-zap-list
2714					'gnus-summary-mode-map)))
2715      (when map
2716	;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2717	;; uses it's value.
2718	(setq gnus-summary-tool-bar-map map))))
2719  (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2720
2721(defun gnus-score-set-default (var value)
2722  "A version of set that updates the GNU Emacs menu-bar."
2723  (set var value)
2724  ;; It is the message that forces the active status to be updated.
2725  (message ""))
2726
2727(defun gnus-make-score-map (type)
2728  "Make a summary score map of type TYPE."
2729  (if t
2730      nil
2731    (let ((headers '(("author" "from" string)
2732		     ("subject" "subject" string)
2733		     ("article body" "body" string)
2734		     ("article head" "head" string)
2735		     ("xref" "xref" string)
2736		     ("extra header" "extra" string)
2737		     ("lines" "lines" number)
2738		     ("followups to author" "followup" string)))
2739	  (types '((number ("less than" <)
2740			   ("greater than" >)
2741			   ("equal" =))
2742		   (string ("substring" s)
2743			   ("exact string" e)
2744			   ("fuzzy string" f)
2745			   ("regexp" r))))
2746	  (perms '(("temporary" (current-time-string))
2747		   ("permanent" nil)
2748		   ("immediate" now)))
2749	  header)
2750      (list
2751       (apply
2752	'nconc
2753	(list
2754	 (if (eq type 'lower)
2755	     "Lower score"
2756	   "Increase score"))
2757	(let (outh)
2758	  (while headers
2759	    (setq header (car headers))
2760	    (setq outh
2761		  (cons
2762		   (apply
2763		    'nconc
2764		    (list (car header))
2765		    (let ((ts (cdr (assoc (nth 2 header) types)))
2766			  outt)
2767		      (while ts
2768			(setq outt
2769			      (cons
2770			       (apply
2771				'nconc
2772				(list (caar ts))
2773				(let ((ps perms)
2774				      outp)
2775				  (while ps
2776				    (setq outp
2777					  (cons
2778					   (vector
2779					    (caar ps)
2780					    (list
2781					     'gnus-summary-score-entry
2782					     (nth 1 header)
2783					     (if (or (string= (nth 1 header)
2784							      "head")
2785						     (string= (nth 1 header)
2786							      "body"))
2787						 ""
2788					       (list 'gnus-summary-header
2789						     (nth 1 header)))
2790					     (list 'quote (nth 1 (car ts)))
2791					     (list 'gnus-score-delta-default
2792						   nil)
2793					     (nth 1 (car ps))
2794					     t)
2795					    t)
2796					   outp))
2797				    (setq ps (cdr ps)))
2798				  (list (nreverse outp))))
2799			       outt))
2800			(setq ts (cdr ts)))
2801		      (list (nreverse outt))))
2802		   outh))
2803	    (setq headers (cdr headers)))
2804	  (list (nreverse outh))))))))
2805
2806
2807
2808(defun gnus-summary-mode (&optional group)
2809  "Major mode for reading articles.
2810
2811All normal editing commands are switched off.
2812\\<gnus-summary-mode-map>
2813Each line in this buffer represents one article.  To read an
2814article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2815and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2816respectively.
2817
2818You can also post articles and send mail from this buffer.  To
2819follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2820of an article, type `\\[gnus-summary-reply]'.
2821
2822There are approx. one gazillion commands you can execute in this
2823buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2824
2825The following commands are available:
2826
2827\\{gnus-summary-mode-map}"
2828  (interactive)
2829  (kill-all-local-variables)
2830  (when (gnus-visual-p 'summary-menu 'menu)
2831    (gnus-summary-make-menu-bar)
2832    (gnus-summary-make-tool-bar))
2833  (gnus-summary-make-local-variables)
2834  (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2835    (gnus-summary-make-local-variables))
2836  (gnus-make-thread-indent-array)
2837  (gnus-simplify-mode-line)
2838  (setq major-mode 'gnus-summary-mode)
2839  (setq mode-name "Summary")
2840  (make-local-variable 'minor-mode-alist)
2841  (use-local-map gnus-summary-mode-map)
2842  (buffer-disable-undo)
2843  (setq buffer-read-only t)		;Disable modification
2844  (setq truncate-lines t)
2845  (setq selective-display t)
2846  (setq selective-display-ellipses t)	;Display `...'
2847  (gnus-summary-set-display-table)
2848  (gnus-set-default-directory)
2849  (setq gnus-newsgroup-name group)
2850  (make-local-variable 'gnus-summary-line-format)
2851  (make-local-variable 'gnus-summary-line-format-spec)
2852  (make-local-variable 'gnus-summary-dummy-line-format)
2853  (make-local-variable 'gnus-summary-dummy-line-format-spec)
2854  (make-local-variable 'gnus-summary-mark-positions)
2855  (gnus-make-local-hook 'pre-command-hook)
2856  (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2857  (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2858  (turn-on-gnus-mailing-list-mode)
2859  (mm-enable-multibyte)
2860  (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2861  (gnus-update-summary-mark-positions))
2862
2863(defun gnus-summary-make-local-variables ()
2864  "Make all the local summary buffer variables."
2865  (let (global)
2866    (dolist (local gnus-summary-local-variables)
2867      (if (consp local)
2868	  (progn
2869	    (if (eq (cdr local) 'global)
2870		;; Copy the global value of the variable.
2871		(setq global (symbol-value (car local)))
2872	      ;; Use the value from the list.
2873	      (setq global (eval (cdr local))))
2874	    (set (make-local-variable (car local)) global))
2875	;; Simple nil-valued local variable.
2876	(set (make-local-variable local) nil)))))
2877
2878(defun gnus-summary-clear-local-variables ()
2879  (let ((locals gnus-summary-local-variables))
2880    (while locals
2881      (if (consp (car locals))
2882	  (and (vectorp (caar locals))
2883	       (set (caar locals) nil))
2884	(and (vectorp (car locals))
2885	     (set (car locals) nil)))
2886      (setq locals (cdr locals)))))
2887
2888;; Summary data functions.
2889
2890(defmacro gnus-data-number (data)
2891  `(car ,data))
2892
2893(defmacro gnus-data-set-number (data number)
2894  `(setcar ,data ,number))
2895
2896(defmacro gnus-data-mark (data)
2897  `(nth 1 ,data))
2898
2899(defmacro gnus-data-set-mark (data mark)
2900  `(setcar (nthcdr 1 ,data) ,mark))
2901
2902(defmacro gnus-data-pos (data)
2903  `(nth 2 ,data))
2904
2905(defmacro gnus-data-set-pos (data pos)
2906  `(setcar (nthcdr 2 ,data) ,pos))
2907
2908(defmacro gnus-data-header (data)
2909  `(nth 3 ,data))
2910
2911(defmacro gnus-data-set-header (data header)
2912  `(setf (nth 3 ,data) ,header))
2913
2914(defmacro gnus-data-level (data)
2915  `(nth 4 ,data))
2916
2917(defmacro gnus-data-unread-p (data)
2918  `(= (nth 1 ,data) gnus-unread-mark))
2919
2920(defmacro gnus-data-read-p (data)
2921  `(/= (nth 1 ,data) gnus-unread-mark))
2922
2923(defmacro gnus-data-pseudo-p (data)
2924  `(consp (nth 3 ,data)))
2925
2926(defmacro gnus-data-find (number)
2927  `(assq ,number gnus-newsgroup-data))
2928
2929(defmacro gnus-data-find-list (number &optional data)
2930  `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2931     (memq (assq ,number bdata)
2932	   bdata)))
2933
2934(defmacro gnus-data-make (number mark pos header level)
2935  `(list ,number ,mark ,pos ,header ,level))
2936
2937(defun gnus-data-enter (after-article number mark pos header level offset)
2938  (let ((data (gnus-data-find-list after-article)))
2939    (unless data
2940      (error "No such article: %d" after-article))
2941    (setcdr data (cons (gnus-data-make number mark pos header level)
2942		       (cdr data)))
2943    (setq gnus-newsgroup-data-reverse nil)
2944    (gnus-data-update-list (cddr data) offset)))
2945
2946(defun gnus-data-enter-list (after-article list &optional offset)
2947  (when list
2948    (let ((data (and after-article (gnus-data-find-list after-article)))
2949	  (ilist list))
2950      (if (not (or data
2951		   after-article))
2952	  (let ((odata gnus-newsgroup-data))
2953	    (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2954	    (when offset
2955	      (gnus-data-update-list odata offset)))
2956      ;; Find the last element in the list to be spliced into the main
2957	;; list.
2958	(while (cdr list)
2959	  (setq list (cdr list)))
2960	(if (not data)
2961	    (progn
2962	      (setcdr list gnus-newsgroup-data)
2963	      (setq gnus-newsgroup-data ilist)
2964	      (when offset
2965		(gnus-data-update-list (cdr list) offset)))
2966	  (setcdr list (cdr data))
2967	  (setcdr data ilist)
2968	  (when offset
2969	    (gnus-data-update-list (cdr list) offset))))
2970      (setq gnus-newsgroup-data-reverse nil))))
2971
2972(defun gnus-data-remove (article &optional offset)
2973  (let ((data gnus-newsgroup-data))
2974    (if (= (gnus-data-number (car data)) article)
2975	(progn
2976	  (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2977		gnus-newsgroup-data-reverse nil)
2978	  (when offset
2979	    (gnus-data-update-list gnus-newsgroup-data offset)))
2980      (while (cdr data)
2981	(when (= (gnus-data-number (cadr data)) article)
2982	  (setcdr data (cddr data))
2983	  (when offset
2984	    (gnus-data-update-list (cdr data) offset))
2985	  (setq data nil
2986		gnus-newsgroup-data-reverse nil))
2987	(setq data (cdr data))))))
2988
2989(defmacro gnus-data-list (backward)
2990  `(if ,backward
2991       (or gnus-newsgroup-data-reverse
2992	   (setq gnus-newsgroup-data-reverse
2993		 (reverse gnus-newsgroup-data)))
2994     gnus-newsgroup-data))
2995
2996(defun gnus-data-update-list (data offset)
2997  "Add OFFSET to the POS of all data entries in DATA."
2998  (setq gnus-newsgroup-data-reverse nil)
2999  (while data
3000    (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3001    (setq data (cdr data))))
3002
3003(defun gnus-summary-article-pseudo-p (article)
3004  "Say whether this article is a pseudo article or not."
3005  (not (vectorp (gnus-data-header (gnus-data-find article)))))
3006
3007(defmacro gnus-summary-article-sparse-p (article)
3008  "Say whether this article is a sparse article or not."
3009  `(memq ,article gnus-newsgroup-sparse))
3010
3011(defmacro gnus-summary-article-ancient-p (article)
3012  "Say whether this article is a sparse article or not."
3013  `(memq ,article gnus-newsgroup-ancient))
3014
3015(defun gnus-article-parent-p (number)
3016  "Say whether this article is a parent or not."
3017  (let ((data (gnus-data-find-list number)))
3018    (and (cdr data)              ; There has to be an article after...
3019	 (< (gnus-data-level (car data)) ; And it has to have a higher level.
3020	    (gnus-data-level (nth 1 data))))))
3021
3022(defun gnus-article-children (number)
3023  "Return a list of all children to NUMBER."
3024  (let* ((data (gnus-data-find-list number))
3025	 (level (gnus-data-level (car data)))
3026	 children)
3027    (setq data (cdr data))
3028    (while (and data
3029		(= (gnus-data-level (car data)) (1+ level)))
3030      (push (gnus-data-number (car data)) children)
3031      (setq data (cdr data)))
3032    children))
3033
3034(defmacro gnus-summary-skip-intangible ()
3035  "If the current article is intangible, then jump to a different article."
3036  '(let ((to (get-text-property (point) 'gnus-intangible)))
3037     (and to (gnus-summary-goto-subject to))))
3038
3039(defmacro gnus-summary-article-intangible-p ()
3040  "Say whether this article is intangible or not."
3041  '(get-text-property (point) 'gnus-intangible))
3042
3043(defun gnus-article-read-p (article)
3044  "Say whether ARTICLE is read or not."
3045  (not (or (memq article gnus-newsgroup-marked)
3046	   (memq article gnus-newsgroup-spam-marked)
3047	   (memq article gnus-newsgroup-unreads)
3048	   (memq article gnus-newsgroup-unselected)
3049	   (memq article gnus-newsgroup-dormant))))
3050
3051;; Some summary mode macros.
3052
3053(defmacro gnus-summary-article-number ()
3054  "The article number of the article on the current line.
3055If there isn't an article number here, then we return the current
3056article number."
3057  '(progn
3058     (gnus-summary-skip-intangible)
3059     (or (get-text-property (point) 'gnus-number)
3060	 (gnus-summary-last-subject))))
3061
3062(defmacro gnus-summary-article-header (&optional number)
3063  "Return the header of article NUMBER."
3064  `(gnus-data-header (gnus-data-find
3065		      ,(or number '(gnus-summary-article-number)))))
3066
3067(defmacro gnus-summary-thread-level (&optional number)
3068  "Return the level of thread that starts with article NUMBER."
3069  `(if (and (eq gnus-summary-make-false-root 'dummy)
3070	    (get-text-property (point) 'gnus-intangible))
3071       0
3072     (gnus-data-level (gnus-data-find
3073		       ,(or number '(gnus-summary-article-number))))))
3074
3075(defmacro gnus-summary-article-mark (&optional number)
3076  "Return the mark of article NUMBER."
3077  `(gnus-data-mark (gnus-data-find
3078		    ,(or number '(gnus-summary-article-number)))))
3079
3080(defmacro gnus-summary-article-pos (&optional number)
3081  "Return the position of the line of article NUMBER."
3082  `(gnus-data-pos (gnus-data-find
3083		   ,(or number '(gnus-summary-article-number)))))
3084
3085(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3086(defmacro gnus-summary-article-subject (&optional number)
3087  "Return current subject string or nil if nothing."
3088  `(let ((headers
3089	  ,(if number
3090	       `(gnus-data-header (assq ,number gnus-newsgroup-data))
3091	     '(gnus-data-header (assq (gnus-summary-article-number)
3092				      gnus-newsgroup-data)))))
3093     (and headers
3094	  (vectorp headers)
3095	  (mail-header-subject headers))))
3096
3097(defmacro gnus-summary-article-score (&optional number)
3098  "Return current article score."
3099  `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3100		  gnus-newsgroup-scored))
3101       gnus-summary-default-score 0))
3102
3103(defun gnus-summary-article-children (&optional number)
3104  "Return a list of article numbers that are children of article NUMBER."
3105  (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3106	 (level (gnus-data-level (car data)))
3107	 l children)
3108    (while (and (setq data (cdr data))
3109		(> (setq l (gnus-data-level (car data))) level))
3110      (and (= (1+ level) l)
3111	   (push (gnus-data-number (car data))
3112		 children)))
3113    (nreverse children)))
3114
3115(defun gnus-summary-article-parent (&optional number)
3116  "Return the article number of the parent of article NUMBER."
3117  (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3118				    (gnus-data-list t)))
3119	 (level (gnus-data-level (car data))))
3120    (if (zerop level)
3121	()				; This is a root.
3122      ;; We search until we find an article with a level less than
3123      ;; this one.  That function has to be the parent.
3124      (while (and (setq data (cdr data))
3125		  (not (< (gnus-data-level (car data)) level))))
3126      (and data (gnus-data-number (car data))))))
3127
3128(defun gnus-unread-mark-p (mark)
3129  "Say whether MARK is the unread mark."
3130  (= mark gnus-unread-mark))
3131
3132(defun gnus-read-mark-p (mark)
3133  "Say whether MARK is one of the marks that mark as read.
3134This is all marks except unread, ticked, dormant, and expirable."
3135  (not (or (= mark gnus-unread-mark)
3136	   (= mark gnus-ticked-mark)
3137	   (= mark gnus-spam-mark)
3138	   (= mark gnus-dormant-mark)
3139	   (= mark gnus-expirable-mark))))
3140
3141(defmacro gnus-article-mark (number)
3142  "Return the MARK of article NUMBER.
3143This macro should only be used when computing the mark the \"first\"
3144time; i.e., when generating the summary lines.  After that,
3145`gnus-summary-article-mark' should be used to examine the
3146marks of articles."
3147  `(cond
3148    ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3149    ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3150    ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3151    ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3152    ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3153    ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3154    ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3155    (t (or (cdr (assq ,number gnus-newsgroup-reads))
3156	   gnus-ancient-mark))))
3157
3158;; Saving hidden threads.
3159
3160(defmacro gnus-save-hidden-threads (&rest forms)
3161  "Save hidden threads, eval FORMS, and restore the hidden threads."
3162  (let ((config (make-symbol "config")))
3163    `(let ((,config (gnus-hidden-threads-configuration)))
3164       (unwind-protect
3165	   (save-excursion
3166	     ,@forms)
3167	 (gnus-restore-hidden-threads-configuration ,config)))))
3168(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3169(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3170
3171(defun gnus-data-compute-positions ()
3172  "Compute the positions of all articles."
3173  (setq gnus-newsgroup-data-reverse nil)
3174  (let ((data gnus-newsgroup-data))
3175    (save-excursion
3176      (gnus-save-hidden-threads
3177	(gnus-summary-show-all-threads)
3178	(goto-char (point-min))
3179	(while data
3180	  (while (get-text-property (point) 'gnus-intangible)
3181	    (forward-line 1))
3182	  (gnus-data-set-pos (car data) (+ (point) 3))
3183	  (setq data (cdr data))
3184	  (forward-line 1))))))
3185
3186(defun gnus-hidden-threads-configuration ()
3187  "Return the current hidden threads configuration."
3188  (save-excursion
3189    (let (config)
3190      (goto-char (point-min))
3191      (while (search-forward "\r" nil t)
3192	(push (1- (point)) config))
3193      config)))
3194
3195(defun gnus-restore-hidden-threads-configuration (config)
3196  "Restore hidden threads configuration from CONFIG."
3197  (save-excursion
3198    (let (point buffer-read-only)
3199      (while (setq point (pop config))
3200	(when (and (< point (point-max))
3201		   (goto-char point)
3202		   (eq (char-after) ?\n))
3203	  (subst-char-in-region point (1+ point) ?\n ?\r))))))
3204
3205;; Various summary mode internalish functions.
3206
3207(defun gnus-mouse-pick-article (e)
3208  (interactive "e")
3209  (mouse-set-point e)
3210  (gnus-summary-next-page nil t))
3211
3212(defun gnus-summary-set-display-table ()
3213  "Change the display table.
3214Odd characters have a tendency to mess
3215up nicely formatted displays - we make all possible glyphs
3216display only a single character."
3217
3218  ;; We start from the standard display table, if any.
3219  (let ((table (or (copy-sequence standard-display-table)
3220		   (make-display-table)))
3221	(i 32))
3222    ;; Nix out all the control chars...
3223    (while (>= (setq i (1- i)) 0)
3224      (aset table i [??]))
3225   ;; ... but not newline and cr, of course.  (cr is necessary for the
3226    ;; selective display).
3227    (aset table ?\n nil)
3228    (aset table ?\r nil)
3229    ;; We keep TAB as well.
3230    (aset table ?\t nil)
3231    ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3232    ;; Emacs 23 (unicode), that are not set already.
3233    (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3234		 160
3235	       256)))
3236      (while (>= (setq i (1- i)) 127)
3237	;; Only modify if the entry is nil.
3238	(unless (aref table i)
3239	  (aset table i [??]))))
3240    (setq buffer-display-table table)))
3241
3242(defun gnus-summary-set-article-display-arrow (pos)
3243  "Update the overlay arrow to point to line at position POS."
3244  (when (and gnus-summary-display-arrow
3245	     (boundp 'overlay-arrow-position)
3246	     (boundp 'overlay-arrow-string))
3247    (save-excursion
3248      (goto-char pos)
3249      (beginning-of-line)
3250      (unless overlay-arrow-position
3251	(setq overlay-arrow-position (make-marker)))
3252      (setq overlay-arrow-string "=>"
3253	    overlay-arrow-position (set-marker overlay-arrow-position
3254					       (point)
3255					       (current-buffer))))))
3256
3257(defun gnus-summary-setup-buffer (group)
3258  "Initialize summary buffer."
3259  (let ((buffer (gnus-summary-buffer-name group))
3260	(dead-name (concat "*Dead Summary "
3261			   (gnus-group-decoded-name group) "*")))
3262    ;; If a dead summary buffer exists, we kill it.
3263    (when (gnus-buffer-live-p dead-name)
3264      (gnus-kill-buffer dead-name))
3265    (if (get-buffer buffer)
3266	(progn
3267	  (set-buffer buffer)
3268	  (setq gnus-summary-buffer (current-buffer))
3269	  (not gnus-newsgroup-prepared))
3270      ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3271      (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3272      (gnus-summary-mode group)
3273      (when gnus-carpal
3274	(gnus-carpal-setup-buffer 'summary))
3275      (unless gnus-single-article-buffer
3276	(make-local-variable 'gnus-article-buffer)
3277	(make-local-variable 'gnus-article-current)
3278	(make-local-variable 'gnus-original-article-buffer))
3279      (setq gnus-newsgroup-name group)
3280      ;; Set any local variables in the group parameters.
3281      (gnus-summary-set-local-parameters gnus-newsgroup-name)
3282      t)))
3283
3284(defun gnus-set-global-variables ()
3285  "Set the global equivalents of the buffer-local variables.
3286They are set to the latest values they had.  These reflect the summary
3287buffer that was in action when the last article was fetched."
3288  (when (eq major-mode 'gnus-summary-mode)
3289    (setq gnus-summary-buffer (current-buffer))
3290    (let ((name gnus-newsgroup-name)
3291	  (marked gnus-newsgroup-marked)
3292	  (spam gnus-newsgroup-spam-marked)
3293	  (unread gnus-newsgroup-unreads)
3294	  (headers gnus-current-headers)
3295	  (data gnus-newsgroup-data)
3296	  (summary gnus-summary-buffer)
3297	  (article-buffer gnus-article-buffer)
3298	  (original gnus-original-article-buffer)
3299	  (gac gnus-article-current)
3300	  (reffed gnus-reffed-article-number)
3301	  (score-file gnus-current-score-file)
3302	  (default-charset gnus-newsgroup-charset)
3303	  vlist)
3304      (let ((locals gnus-newsgroup-variables))
3305	(while locals
3306	  (if (consp (car locals))
3307	      (push (eval (caar locals)) vlist)
3308	    (push (eval (car locals)) vlist))
3309	  (setq locals (cdr locals)))
3310	(setq vlist (nreverse vlist)))
3311      (save-excursion
3312	(set-buffer gnus-group-buffer)
3313	(setq gnus-newsgroup-name name
3314	      gnus-newsgroup-marked marked
3315	      gnus-newsgroup-spam-marked spam
3316	      gnus-newsgroup-unreads unread
3317	      gnus-current-headers headers
3318	      gnus-newsgroup-data data
3319	      gnus-article-current gac
3320	      gnus-summary-buffer summary
3321	      gnus-article-buffer article-buffer
3322	      gnus-original-article-buffer original
3323	      gnus-reffed-article-number reffed
3324	      gnus-current-score-file score-file
3325	      gnus-newsgroup-charset default-charset)
3326	(let ((locals gnus-newsgroup-variables))
3327	  (while locals
3328	    (if (consp (car locals))
3329		(set (caar locals) (pop vlist))
3330	      (set (car locals) (pop vlist)))
3331	    (setq locals (cdr locals))))
3332	;; The article buffer also has local variables.
3333	(when (gnus-buffer-live-p gnus-article-buffer)
3334	  (set-buffer gnus-article-buffer)
3335	  (setq gnus-summary-buffer summary))))))
3336
3337(defun gnus-summary-article-unread-p (article)
3338  "Say whether ARTICLE is unread or not."
3339  (memq article gnus-newsgroup-unreads))
3340
3341(defun gnus-summary-first-article-p (&optional article)
3342  "Return whether ARTICLE is the first article in the buffer."
3343  (if (not (setq article (or article (gnus-summary-article-number))))
3344      nil
3345    (eq article (caar gnus-newsgroup-data))))
3346
3347(defun gnus-summary-last-article-p (&optional article)
3348  "Return whether ARTICLE is the last article in the buffer."
3349  (if (not (setq article (or article (gnus-summary-article-number))))
3350      ;; All non-existent numbers are the last article.  :-)
3351      t
3352    (not (cdr (gnus-data-find-list article)))))
3353
3354(defun gnus-make-thread-indent-array (&optional n)
3355  (when (or n
3356	    (progn (setq n 200) nil)
3357	    (null gnus-thread-indent-array)
3358	    (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3359    (setq gnus-thread-indent-array (make-vector (1+ n) "")
3360	  gnus-thread-indent-array-level gnus-thread-indent-level)
3361    (while (>= n 0)
3362      (aset gnus-thread-indent-array n
3363	    (make-string (* n gnus-thread-indent-level) ? ))
3364      (setq n (1- n)))))
3365
3366(defun gnus-update-summary-mark-positions ()
3367  "Compute where the summary marks are to go."
3368  (save-excursion
3369    (when (gnus-buffer-exists-p gnus-summary-buffer)
3370      (set-buffer gnus-summary-buffer))
3371    (let ((spec gnus-summary-line-format-spec)
3372	  pos)
3373      (save-excursion
3374	(gnus-set-work-buffer)
3375	(let ((gnus-tmp-unread ?Z)
3376	      (gnus-replied-mark ?Z)
3377	      (gnus-score-below-mark ?Z)
3378	      (gnus-score-over-mark ?Z)
3379	      (gnus-undownloaded-mark ?Z)
3380	      (gnus-summary-line-format-spec spec)
3381	      (gnus-newsgroup-downloadable '(0))
3382	      (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3383	      case-fold-search ignores)
3384	  ;; Here, all marks are bound to Z.
3385	  (gnus-summary-insert-line header
3386				    0 nil t gnus-tmp-unread t nil "" nil 1)
3387	  (goto-char (point-min))
3388	  ;; Memorize the positions of the same characters as dummy marks.
3389	  (while (re-search-forward "[A-D]" nil t)
3390	    (push (point) ignores))
3391	  (erase-buffer)
3392	  ;; We use A-D as dummy marks in order to know column positions
3393	  ;; where marks should be inserted.
3394	  (setq gnus-tmp-unread ?A
3395		gnus-replied-mark ?B
3396		gnus-score-below-mark ?C
3397		gnus-score-over-mark ?C
3398		gnus-undownloaded-mark ?D)
3399	  (gnus-summary-insert-line header
3400				    0 nil t gnus-tmp-unread t nil "" nil 1)
3401	  ;; Ignore characters which aren't dummy marks.
3402	  (dolist (p ignores)
3403	    (delete-region (goto-char (1- p)) p)
3404	    (insert ?Z))
3405	  (goto-char (point-min))
3406	  (setq pos (list (cons 'unread
3407				(and (search-forward "A" nil t)
3408				     (- (point) (point-min) 1)))))
3409	  (goto-char (point-min))
3410	  (push (cons 'replied (and (search-forward "B" nil t)
3411				    (- (point) (point-min) 1)))
3412		pos)
3413	  (goto-char (point-min))
3414	  (push (cons 'score (and (search-forward "C" nil t)
3415				  (- (point) (point-min) 1)))
3416		pos)
3417	  (goto-char (point-min))
3418	  (push (cons 'download (and (search-forward "D" nil t)
3419				     (- (point) (point-min) 1)))
3420		pos)))
3421      (setq gnus-summary-mark-positions pos))))
3422
3423(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3424  "Insert a dummy root in the summary buffer."
3425  (beginning-of-line)
3426  (gnus-add-text-properties
3427   (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3428   (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3429
3430(defun gnus-summary-extract-address-component (from)
3431  (or (car (funcall gnus-extract-address-components from))
3432      from))
3433
3434(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3435  (let ((mail-parse-charset gnus-newsgroup-charset)
3436	; Is it really necessary to do this next part for each summary line?
3437	; Luckily, doesn't seem to slow things down much.
3438	(mail-parse-ignored-charsets
3439	 (save-excursion (set-buffer gnus-summary-buffer)
3440			 gnus-newsgroup-ignored-charsets)))
3441    (or
3442     (and gnus-ignored-from-addresses
3443	  (string-match gnus-ignored-from-addresses gnus-tmp-from)
3444	  (let ((extra-headers (mail-header-extra header))
3445		to
3446		newsgroups)
3447	    (cond
3448	     ((setq to (cdr (assq 'To extra-headers)))
3449	      (concat "-> "
3450		      (inline
3451			(gnus-summary-extract-address-component
3452			 (funcall gnus-decode-encoded-address-function to)))))
3453	     ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3454	      (concat "=> " newsgroups)))))
3455     (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3456
3457(defun gnus-summary-insert-line (gnus-tmp-header
3458				 gnus-tmp-level gnus-tmp-current
3459				 undownloaded gnus-tmp-unread gnus-tmp-replied
3460				 gnus-tmp-expirable gnus-tmp-subject-or-nil
3461				 &optional gnus-tmp-dummy gnus-tmp-score
3462				 gnus-tmp-process)
3463  (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3464      (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3465					  gnus-tmp-level)))
3466  (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3467	 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3468	 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3469	 (gnus-tmp-score-char
3470	  (if (or (null gnus-summary-default-score)
3471		  (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3472		      gnus-summary-zcore-fuzz))
3473	      ?                         ;Whitespace
3474	    (if (< gnus-tmp-score gnus-summary-default-score)
3475		gnus-score-below-mark gnus-score-over-mark)))
3476	 (gnus-tmp-number (mail-header-number gnus-tmp-header))
3477	 (gnus-tmp-replied
3478	  (cond (gnus-tmp-process gnus-process-mark)
3479		((memq gnus-tmp-current gnus-newsgroup-cached)
3480		 gnus-cached-mark)
3481		(gnus-tmp-replied gnus-replied-mark)
3482		((memq gnus-tmp-current gnus-newsgroup-forwarded)
3483		 gnus-forwarded-mark)
3484		((memq gnus-tmp-current gnus-newsgroup-saved)
3485		 gnus-saved-mark)
3486		((memq gnus-tmp-number gnus-newsgroup-recent)
3487		 gnus-recent-mark)
3488		((memq gnus-tmp-number gnus-newsgroup-unseen)
3489		 gnus-unseen-mark)
3490		(t gnus-no-mark)))
3491	 (gnus-tmp-downloaded
3492	  (cond (undownloaded
3493                 gnus-undownloaded-mark)
3494                (gnus-newsgroup-agentized
3495                 gnus-downloaded-mark)
3496                (t
3497                 gnus-no-mark)))
3498	 (gnus-tmp-from (mail-header-from gnus-tmp-header))
3499	 (gnus-tmp-name
3500	  (cond
3501	   ((string-match "<[^>]+> *$" gnus-tmp-from)
3502	    (let ((beg (match-beginning 0)))
3503	      (or (and (string-match "^\".+\"" gnus-tmp-from)
3504		       (substring gnus-tmp-from 1 (1- (match-end 0))))
3505		  (substring gnus-tmp-from 0 beg))))
3506	   ((string-match "(.+)" gnus-tmp-from)
3507	    (substring gnus-tmp-from
3508		       (1+ (match-beginning 0)) (1- (match-end 0))))
3509	   (t gnus-tmp-from)))
3510	 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3511	 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3512	 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3513	 (buffer-read-only nil))
3514    (when (string= gnus-tmp-name "")
3515      (setq gnus-tmp-name gnus-tmp-from))
3516    (unless (numberp gnus-tmp-lines)
3517      (setq gnus-tmp-lines -1))
3518    (if (= gnus-tmp-lines -1)
3519	(setq gnus-tmp-lines "?")
3520      (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3521      (gnus-put-text-property
3522     (point)
3523     (progn (eval gnus-summary-line-format-spec) (point))
3524       'gnus-number gnus-tmp-number)
3525    (when (gnus-visual-p 'summary-highlight 'highlight)
3526      (forward-line -1)
3527      (gnus-run-hooks 'gnus-summary-update-hook)
3528      (forward-line 1))))
3529
3530(defun gnus-summary-update-line (&optional dont-update)
3531  "Update summary line after change."
3532  (when (and gnus-summary-default-score
3533	     (not gnus-summary-inhibit-highlight))
3534    (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3535	   (article (gnus-summary-article-number))
3536	   (score (gnus-summary-article-score article)))
3537      (unless dont-update
3538	(if (and gnus-summary-mark-below
3539		 (< (gnus-summary-article-score)
3540		    gnus-summary-mark-below))
3541	    ;; This article has a low score, so we mark it as read.
3542	    (when (memq article gnus-newsgroup-unreads)
3543	      (gnus-summary-mark-article-as-read gnus-low-score-mark))
3544	  (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3545	    ;; This article was previously marked as read on account
3546	    ;; of a low score, but now it has risen, so we mark it as
3547	    ;; unread.
3548	    (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3549	(gnus-summary-update-mark
3550	 (if (or (null gnus-summary-default-score)
3551		 (<= (abs (- score gnus-summary-default-score))
3552		     gnus-summary-zcore-fuzz))
3553	     ?                          ;Whitespace
3554	   (if (< score gnus-summary-default-score)
3555	       gnus-score-below-mark gnus-score-over-mark))
3556	 'score))
3557      ;; Do visual highlighting.
3558      (when (gnus-visual-p 'summary-highlight 'highlight)
3559	(gnus-run-hooks 'gnus-summary-update-hook)))))
3560
3561(defvar gnus-tmp-new-adopts nil)
3562
3563(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3564  "Return the number of articles in THREAD.
3565This may be 0 in some cases -- if none of the articles in
3566the thread are to be displayed."
3567  (let* ((number
3568	 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3569	  (cond
3570	   ((not (listp thread))
3571	    1)
3572	   ((and (consp thread) (cdr thread))
3573	    (apply
3574	     '+ 1 (mapcar
3575		   'gnus-summary-number-of-articles-in-thread (cdr thread))))
3576	   ((null thread)
3577	    1)
3578	   ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3579	    1)
3580	   (t 0))))
3581    (when (and level (zerop level) gnus-tmp-new-adopts)
3582      (incf number
3583	    (apply '+ (mapcar
3584		       'gnus-summary-number-of-articles-in-thread
3585		       gnus-tmp-new-adopts))))
3586    (if char
3587	(if (> number 1) gnus-not-empty-thread-mark
3588	  gnus-empty-thread-mark)
3589      number)))
3590
3591(defsubst gnus-summary-line-message-size (head)
3592  "Return pretty-printed version of message size.
3593This function is intended to be used in
3594`gnus-summary-line-format-alist'."
3595  (let ((c (or (mail-header-chars head) -1)))
3596    (cond ((< c 0) "n/a")		; chars not available
3597	  ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3598	  ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3599	  ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3600	  (t (format "%dM" (/ c (* 1024.0 1024)))))))
3601
3602
3603(defun gnus-summary-set-local-parameters (group)
3604  "Go through the local params of GROUP and set all variable specs in that list."
3605  (let ((params (gnus-group-find-parameter group))
3606	(vars '(quit-config))           ; Ignore quit-config.
3607	elem)
3608    (while params
3609      (setq elem (car params)
3610	    params (cdr params))
3611      (and (consp elem)			; Has to be a cons.
3612	   (consp (cdr elem))		; The cdr has to be a list.
3613	   (symbolp (car elem))		; Has to be a symbol in there.
3614	   (not (memq (car elem) vars))
3615	   (ignore-errors		; So we set it.
3616	     (push (car elem) vars)
3617	     (make-local-variable (car elem))
3618	     (set (car elem) (eval (nth 1 elem))))))))
3619
3620(defun gnus-summary-read-group (group &optional show-all no-article
3621				      kill-buffer no-display backward
3622				      select-articles)
3623  "Start reading news in newsgroup GROUP.
3624If SHOW-ALL is non-nil, already read articles are also listed.
3625If NO-ARTICLE is non-nil, no article is selected initially.
3626If NO-DISPLAY, don't generate a summary buffer."
3627  (let (result)
3628    (while (and group
3629		(null (setq result
3630			    (let ((gnus-auto-select-next nil))
3631			      (or (gnus-summary-read-group-1
3632				   group show-all no-article
3633				   kill-buffer no-display
3634				   select-articles)
3635				  (setq show-all nil
3636					select-articles nil)))))
3637		(eq gnus-auto-select-next 'quietly))
3638      (set-buffer gnus-group-buffer)
3639      ;; The entry function called above goes to the next
3640      ;; group automatically, so we go two groups back
3641      ;; if we are searching for the previous group.
3642      (when backward
3643	(gnus-group-prev-unread-group 2))
3644      (if (not (equal group (gnus-group-group-name)))
3645	  (setq group (gnus-group-group-name))
3646	(setq group nil)))
3647    result))
3648
3649(defun gnus-summary-read-group-1 (group show-all no-article
3650					kill-buffer no-display
3651					&optional select-articles)
3652  ;; Killed foreign groups can't be entered.
3653  ;;  (when (and (not (gnus-group-native-p group))
3654  ;;	     (not (gnus-gethash group gnus-newsrc-hashtb)))
3655  ;;    (error "Dead non-native groups can't be entered"))
3656  (gnus-message 5 "Retrieving newsgroup: %s..."
3657		(gnus-group-decoded-name group))
3658  (let* ((new-group (gnus-summary-setup-buffer group))
3659	 (quit-config (gnus-group-quit-config group))
3660	 (did-select (and new-group (gnus-select-newsgroup
3661				     group show-all select-articles))))
3662    (cond
3663     ;; This summary buffer exists already, so we just select it.
3664     ((not new-group)
3665      (gnus-set-global-variables)
3666      (when kill-buffer
3667	(gnus-kill-or-deaden-summary kill-buffer))
3668      (gnus-configure-windows 'summary 'force)
3669      (gnus-set-mode-line 'summary)
3670      (gnus-summary-position-point)
3671      (message "")
3672      t)
3673     ;; We couldn't select this group.
3674     ((null did-select)
3675      (when (and (eq major-mode 'gnus-summary-mode)
3676		 (not (equal (current-buffer) kill-buffer)))
3677	(kill-buffer (current-buffer))
3678	(if (not quit-config)
3679	    (progn
3680	      ;; Update the info -- marks might need to be removed,
3681	      ;; for instance.
3682	      (gnus-summary-update-info)
3683	      (set-buffer gnus-group-buffer)
3684	      (gnus-group-jump-to-group group)
3685	      (gnus-group-next-unread-group 1))
3686	  (gnus-handle-ephemeral-exit quit-config)))
3687      (let ((grpinfo (gnus-get-info group)))
3688	(if (null (gnus-info-read grpinfo))
3689	    (gnus-message 3 "Group %s contains no messages"
3690			  (gnus-group-decoded-name group))
3691	  (gnus-message 3 "Can't select group")))
3692      nil)
3693     ;; The user did a `C-g' while prompting for number of articles,
3694     ;; so we exit this group.
3695     ((eq did-select 'quit)
3696      (and (eq major-mode 'gnus-summary-mode)
3697	   (not (equal (current-buffer) kill-buffer))
3698	   (kill-buffer (current-buffer)))
3699      (when kill-buffer
3700	(gnus-kill-or-deaden-summary kill-buffer))
3701      (if (not quit-config)
3702	  (progn
3703	    (set-buffer gnus-group-buffer)
3704	    (gnus-group-jump-to-group group)
3705	    (gnus-group-next-unread-group 1)
3706	    (gnus-configure-windows 'group 'force))
3707	(gnus-handle-ephemeral-exit quit-config))
3708      ;; Finally signal the quit.
3709      (signal 'quit nil))
3710     ;; The group was successfully selected.
3711     (t
3712      (gnus-set-global-variables)
3713      ;; Save the active value in effect when the group was entered.
3714      (setq gnus-newsgroup-active
3715	    (gnus-copy-sequence
3716	     (gnus-active gnus-newsgroup-name)))
3717      ;; You can change the summary buffer in some way with this hook.
3718      (gnus-run-hooks 'gnus-select-group-hook)
3719      (when (memq 'summary (gnus-update-format-specifications
3720			    nil 'summary 'summary-mode 'summary-dummy))
3721	;; The format specification for the summary line was updated,
3722	;; so we need to update the mark positions as well.
3723	(gnus-update-summary-mark-positions))
3724      ;; Do score processing.
3725      (when gnus-use-scoring
3726	(gnus-possibly-score-headers))
3727      ;; Check whether to fill in the gaps in the threads.
3728      (when gnus-build-sparse-threads
3729	(gnus-build-sparse-threads))
3730      ;; Find the initial limit.
3731      (if show-all
3732	  (let ((gnus-newsgroup-dormant nil))
3733	    (gnus-summary-initial-limit show-all))
3734	(gnus-summary-initial-limit show-all))
3735      ;; Generate the summary buffer.
3736      (unless no-display
3737	(gnus-summary-prepare))
3738      (when gnus-use-trees
3739	(gnus-tree-open group)
3740	(setq gnus-summary-highlight-line-function
3741	      'gnus-tree-highlight-article))
3742      ;; If the summary buffer is empty, but there are some low-scored
3743      ;; articles or some excluded dormants, we include these in the
3744      ;; buffer.
3745      (when (and (zerop (buffer-size))
3746		 (not no-display))
3747	(cond (gnus-newsgroup-dormant
3748	       (gnus-summary-limit-include-dormant))
3749	      ((and gnus-newsgroup-scored show-all)
3750	       (gnus-summary-limit-include-expunged t))))
3751      ;; Function `gnus-apply-kill-file' must be called in this hook.
3752      (gnus-run-hooks 'gnus-apply-kill-hook)
3753      (if (and (zerop (buffer-size))
3754	       (not no-display))
3755	  (progn
3756	    ;; This newsgroup is empty.
3757	    (gnus-summary-catchup-and-exit nil t)
3758	    (gnus-message 6 "No unread news")
3759	    (when kill-buffer
3760	      (gnus-kill-or-deaden-summary kill-buffer))
3761	    ;; Return nil from this function.
3762	    nil)
3763	;; Hide conversation thread subtrees.  We cannot do this in
3764	;; gnus-summary-prepare-hook since kill processing may not
3765	;; work with hidden articles.
3766	(gnus-summary-maybe-hide-threads)
3767	(when kill-buffer
3768	  (gnus-kill-or-deaden-summary kill-buffer))
3769	(gnus-summary-auto-select-subject)
3770	;; Show first unread article if requested.
3771	(if (and (not no-article)
3772		 (not no-display)
3773		 gnus-newsgroup-unreads
3774		 gnus-auto-select-first)
3775	    (progn
3776	      (gnus-configure-windows 'summary)
3777	      (let ((art (gnus-summary-article-number)))
3778		(unless (and (not gnus-plugged)
3779			     (or (memq art gnus-newsgroup-undownloaded)
3780				 (memq art gnus-newsgroup-downloadable)))
3781		  (gnus-summary-goto-article art))))
3782	  ;; Don't select any articles.
3783	  (gnus-summary-position-point)
3784	  (gnus-configure-windows 'summary 'force)
3785	  (gnus-set-mode-line 'summary))
3786	(when (and gnus-auto-center-group
3787		   (get-buffer-window gnus-group-buffer t))
3788	  ;; Gotta use windows, because recenter does weird stuff if
3789	  ;; the current buffer ain't the displayed window.
3790	  (let ((owin (selected-window)))
3791	    (select-window (get-buffer-window gnus-group-buffer t))
3792	    (when (gnus-group-goto-group group)
3793	      (recenter))
3794	    (select-window owin)))
3795	;; Mark this buffer as "prepared".
3796	(setq gnus-newsgroup-prepared t)
3797	(gnus-run-hooks 'gnus-summary-prepared-hook)
3798	(unless (gnus-ephemeral-group-p group)
3799	  (gnus-group-update-group group))
3800	t)))))
3801
3802(defun gnus-summary-auto-select-subject ()
3803  "Select the subject line on initial group entry."
3804  (goto-char (point-min))
3805  (cond
3806   ((eq gnus-auto-select-subject 'best)
3807    (gnus-summary-best-unread-subject))
3808   ((eq gnus-auto-select-subject 'unread)
3809    (gnus-summary-first-unread-subject))
3810   ((eq gnus-auto-select-subject 'unseen)
3811    (gnus-summary-first-unseen-subject))
3812   ((eq gnus-auto-select-subject 'unseen-or-unread)
3813    (gnus-summary-first-unseen-or-unread-subject))
3814   ((eq gnus-auto-select-subject 'first)
3815    ;; Do nothing.
3816    )
3817   ((functionp gnus-auto-select-subject)
3818    (funcall gnus-auto-select-subject))))
3819
3820(defun gnus-summary-prepare ()
3821  "Generate the summary buffer."
3822  (interactive)
3823  (let ((buffer-read-only nil))
3824    (erase-buffer)
3825    (setq gnus-newsgroup-data nil
3826	  gnus-newsgroup-data-reverse nil)
3827    (gnus-run-hooks 'gnus-summary-generate-hook)
3828    ;; Generate the buffer, either with threads or without.
3829    (when gnus-newsgroup-headers
3830      (gnus-summary-prepare-threads
3831       (if gnus-show-threads
3832	   (gnus-sort-gathered-threads
3833	    (funcall gnus-summary-thread-gathering-function
3834		     (gnus-sort-threads
3835		      (gnus-cut-threads (gnus-make-threads)))))
3836	 ;; Unthreaded display.
3837	 (gnus-sort-articles gnus-newsgroup-headers))))
3838    (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3839    ;; Call hooks for modifying summary buffer.
3840    (goto-char (point-min))
3841    (gnus-run-hooks 'gnus-summary-prepare-hook)))
3842
3843(defsubst gnus-general-simplify-subject (subject)
3844  "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3845  (setq subject
3846	(cond
3847	 ;; Truncate the subject.
3848	 (gnus-simplify-subject-functions
3849	  (gnus-map-function gnus-simplify-subject-functions subject))
3850	 ((numberp gnus-summary-gather-subject-limit)
3851	  (setq subject (gnus-simplify-subject-re subject))
3852	  (if (> (length subject) gnus-summary-gather-subject-limit)
3853	      (substring subject 0 gnus-summary-gather-subject-limit)
3854	    subject))
3855	 ;; Fuzzily simplify it.
3856	 ((eq 'fuzzy gnus-summary-gather-subject-limit)
3857	  (gnus-simplify-subject-fuzzy subject))
3858	 ;; Just remove the leading "Re:".
3859	 (t
3860	  (gnus-simplify-subject-re subject))))
3861
3862  (if (and gnus-summary-gather-exclude-subject
3863	   (string-match gnus-summary-gather-exclude-subject subject))
3864      nil                         ; This article shouldn't be gathered
3865    subject))
3866
3867(defun gnus-summary-simplify-subject-query ()
3868  "Query where the respool algorithm would put this article."
3869  (interactive)
3870  (gnus-summary-select-article)
3871  (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3872
3873(defun gnus-gather-threads-by-subject (threads)
3874  "Gather threads by looking at Subject headers."
3875  (if (not gnus-summary-make-false-root)
3876      threads
3877    (let ((hashtb (gnus-make-hashtable 1024))
3878	  (prev threads)
3879	  (result threads)
3880	  subject hthread whole-subject)
3881      (while threads
3882	(setq subject (gnus-general-simplify-subject
3883		       (setq whole-subject (mail-header-subject
3884					    (caar threads)))))
3885	(when subject
3886	  (if (setq hthread (gnus-gethash subject hashtb))
3887	      (progn
3888		;; We enter a dummy root into the thread, if we
3889		;; haven't done that already.
3890		(unless (stringp (caar hthread))
3891		  (setcar hthread (list whole-subject (car hthread))))
3892		;; We add this new gathered thread to this gathered
3893		;; thread.
3894		(setcdr (car hthread)
3895			(nconc (cdar hthread) (list (car threads))))
3896		;; Remove it from the list of threads.
3897		(setcdr prev (cdr threads))
3898		(setq threads prev))
3899	    ;; Enter this thread into the hash table.
3900	    (gnus-sethash subject
3901			  (if gnus-summary-make-false-root-always
3902			      (progn
3903				;; If you want a dummy root above all
3904				;; threads...
3905				(setcar threads (list whole-subject
3906						      (car threads)))
3907				threads)
3908			    threads)
3909			  hashtb)))
3910	(setq prev threads)
3911	(setq threads (cdr threads)))
3912      result)))
3913
3914(defun gnus-gather-threads-by-references (threads)
3915  "Gather threads by looking at References headers."
3916  (let ((idhashtb (gnus-make-hashtable 1024))
3917	(thhashtb (gnus-make-hashtable 1024))
3918	(prev threads)
3919	(result threads)
3920	ids references id gthread gid entered ref)
3921    (while threads
3922      (when (setq references (mail-header-references (caar threads)))
3923	(setq id (mail-header-id (caar threads))
3924	      ids (inline (gnus-split-references references))
3925	      entered nil)
3926	(while (setq ref (pop ids))
3927	  (setq ids (delete ref ids))
3928	  (if (not (setq gid (gnus-gethash ref idhashtb)))
3929	      (progn
3930		(gnus-sethash ref id idhashtb)
3931		(gnus-sethash id threads thhashtb))
3932	    (setq gthread (gnus-gethash gid thhashtb))
3933	    (unless entered
3934	      ;; We enter a dummy root into the thread, if we
3935	      ;; haven't done that already.
3936	      (unless (stringp (caar gthread))
3937		(setcar gthread (list (mail-header-subject (caar gthread))
3938				      (car gthread))))
3939	      ;; We add this new gathered thread to this gathered
3940	      ;; thread.
3941	      (setcdr (car gthread)
3942		      (nconc (cdar gthread) (list (car threads)))))
3943	    ;; Add it into the thread hash table.
3944	    (gnus-sethash id gthread thhashtb)
3945	    (setq entered t)
3946	    ;; Remove it from the list of threads.
3947	    (setcdr prev (cdr threads))
3948	    (setq threads prev))))
3949      (setq prev threads)
3950      (setq threads (cdr threads)))
3951    result))
3952
3953(defun gnus-sort-gathered-threads (threads)
3954  "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3955  (let ((result threads))
3956    (while threads
3957      (when (stringp (caar threads))
3958	(setcdr (car threads)
3959		(sort (cdar threads) gnus-sort-gathered-threads-function)))
3960      (setq threads (cdr threads)))
3961    result))
3962
3963(defun gnus-thread-loop-p (root thread)
3964  "Say whether ROOT is in THREAD."
3965  (let ((stack (list thread))
3966	(infloop 0)
3967	th)
3968    (while (setq thread (pop stack))
3969      (setq th (cdr thread))
3970      (while (and th
3971		  (not (eq (caar th) root)))
3972	(pop th))
3973      (if th
3974	  ;; We have found a loop.
3975	  (let (ref-dep)
3976	    (setcdr thread (delq (car th) (cdr thread)))
3977	    (if (boundp (setq ref-dep (intern "none"
3978					      gnus-newsgroup-dependencies)))
3979		(setcdr (symbol-value ref-dep)
3980			(nconc (cdr (symbol-value ref-dep))
3981			       (list (car th))))
3982	      (set ref-dep (list nil (car th))))
3983	    (setq infloop 1
3984		  stack nil))
3985	;; Push all the subthreads onto the stack.
3986	(push (cdr thread) stack)))
3987    infloop))
3988
3989(defun gnus-make-threads ()
3990  "Go through the dependency hashtb and find the roots.  Return all threads."
3991  (let (threads)
3992    (while (catch 'infloop
3993	     (mapatoms
3994	      (lambda (refs)
3995		;; Deal with self-referencing References loops.
3996		(when (and (car (symbol-value refs))
3997			   (not (zerop
3998				 (apply
3999				  '+
4000				  (mapcar
4001				   (lambda (thread)
4002				     (gnus-thread-loop-p
4003				      (car (symbol-value refs)) thread))
4004				   (cdr (symbol-value refs)))))))
4005		  (setq threads nil)
4006		  (throw 'infloop t))
4007		(unless (car (symbol-value refs))
4008		  ;; These threads do not refer back to any other
4009		  ;; articles, so they're roots.
4010		  (setq threads (append (cdr (symbol-value refs)) threads))))
4011	      gnus-newsgroup-dependencies)))
4012    threads))
4013
4014;; Build the thread tree.
4015(defsubst gnus-dependencies-add-header (header dependencies force-new)
4016  "Enter HEADER into the DEPENDENCIES table if it is not already there.
4017
4018If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4019if it was already present.
4020
4021If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4022will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4023Message-IDs will be renamed to a unique Message-ID before being
4024entered.
4025
4026Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4027  (let* ((id (mail-header-id header))
4028	 (id-dep (and id (intern id dependencies)))
4029	 parent-id ref ref-dep ref-header replaced)
4030    ;; Enter this `header' in the `dependencies' table.
4031    (cond
4032     ((not id-dep)
4033      (setq header nil))
4034     ;; The first two cases do the normal part: enter a new `header'
4035     ;; in the `dependencies' table.
4036     ((not (boundp id-dep))
4037      (set id-dep (list header)))
4038     ((null (car (symbol-value id-dep)))
4039      (setcar (symbol-value id-dep) header))
4040
4041     ;; From here the `header' was already present in the
4042     ;; `dependencies' table.
4043     (force-new
4044      ;; Overrides an existing entry;
4045      ;; just set the header part of the entry.
4046      (setcar (symbol-value id-dep) header)
4047      (setq replaced t))
4048
4049     ;; Renames the existing `header' to a unique Message-ID.
4050     ((not gnus-summary-ignore-duplicates)
4051      ;; An article with this Message-ID has already been seen.
4052      ;; We rename the Message-ID.
4053      (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4054	   (list header))
4055      (mail-header-set-id header id))
4056
4057     ;; The last case ignores an existing entry, except it adds any
4058     ;; additional Xrefs (in case the two articles came from different
4059     ;; servers.
4060     ;; Also sets `header' to `nil' meaning that the `dependencies'
4061     ;; table was *not* modified.
4062     (t
4063      (mail-header-set-xref
4064       (car (symbol-value id-dep))
4065       (concat (or (mail-header-xref (car (symbol-value id-dep)))
4066		   "")
4067	       (or (mail-header-xref header) "")))
4068      (setq header nil)))
4069
4070    (when (and header (not replaced))
4071      ;; First check that we are not creating a References loop.
4072      (setq parent-id (gnus-parent-id (mail-header-references header)))
4073      (setq ref parent-id)
4074      (while (and ref
4075		  (setq ref-dep (intern-soft ref dependencies))
4076		  (boundp ref-dep)
4077		  (setq ref-header (car (symbol-value ref-dep))))
4078	(if (string= id ref)
4079	    ;; Yuk!  This is a reference loop.  Make the article be a
4080	    ;; root article.
4081	    (progn
4082	      (mail-header-set-references (car (symbol-value id-dep)) "none")
4083	      (setq ref nil)
4084	      (setq parent-id nil))
4085	  (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4086      (setq ref-dep (intern (or parent-id "none") dependencies))
4087      (if (boundp ref-dep)
4088	  (setcdr (symbol-value ref-dep)
4089		  (nconc (cdr (symbol-value ref-dep))
4090			 (list (symbol-value id-dep))))
4091	(set ref-dep (list nil (symbol-value id-dep)))))
4092    header))
4093
4094(defun gnus-extract-message-id-from-in-reply-to (string)
4095  (if (string-match "<[^>]+>" string)
4096      (substring string (match-beginning 0) (match-end 0))
4097    nil))
4098
4099(defun gnus-build-sparse-threads ()
4100  (let ((headers gnus-newsgroup-headers)
4101	(mail-parse-charset gnus-newsgroup-charset)
4102	(gnus-summary-ignore-duplicates t)
4103	header references generation relations
4104	subject child end new-child date)
4105    ;; First we create an alist of generations/relations, where
4106    ;; generations is how much we trust the relation, and the relation
4107    ;; is parent/child.
4108    (gnus-message 7 "Making sparse threads...")
4109    (save-excursion
4110      (nnheader-set-temp-buffer " *gnus sparse threads*")
4111      (while (setq header (pop headers))
4112	(when (and (setq references (mail-header-references header))
4113		   (not (string= references "")))
4114	  (insert references)
4115	  (setq child (mail-header-id header)
4116		subject (mail-header-subject header)
4117		date (mail-header-date header)
4118		generation 0)
4119	  (while (search-backward ">" nil t)
4120	    (setq end (1+ (point)))
4121	    (when (search-backward "<" nil t)
4122	      (setq new-child (buffer-substring (point) end))
4123	      (push (list (incf generation)
4124			  child (setq child new-child)
4125			  subject date)
4126		    relations)))
4127	  (when child
4128	    (push (list (1+ generation) child nil subject) relations))
4129	  (erase-buffer)))
4130      (kill-buffer (current-buffer)))
4131    ;; Sort over trustworthiness.
4132    (mapcar
4133     (lambda (relation)
4134       (when (gnus-dependencies-add-header
4135	      (make-full-mail-header
4136	       gnus-reffed-article-number
4137	       (nth 3 relation) "" (or (nth 4 relation) "")
4138	       (nth 1 relation)
4139	       (or (nth 2 relation) "") 0 0 "")
4140	      gnus-newsgroup-dependencies nil)
4141	 (push gnus-reffed-article-number gnus-newsgroup-limit)
4142	 (push gnus-reffed-article-number gnus-newsgroup-sparse)
4143	 (push (cons gnus-reffed-article-number gnus-sparse-mark)
4144	       gnus-newsgroup-reads)
4145	 (decf gnus-reffed-article-number)))
4146     (sort relations 'car-less-than-car))
4147    (gnus-message 7 "Making sparse threads...done")))
4148
4149(defun gnus-build-old-threads ()
4150  ;; Look at all the articles that refer back to old articles, and
4151  ;; fetch the headers for the articles that aren't there.  This will
4152  ;; build complete threads - if the roots haven't been expired by the
4153  ;; server, that is.
4154  (let ((mail-parse-charset gnus-newsgroup-charset)
4155	id heads)
4156    (mapatoms
4157     (lambda (refs)
4158       (when (not (car (symbol-value refs)))
4159	 (setq heads (cdr (symbol-value refs)))
4160	 (while heads
4161	   (if (memq (mail-header-number (caar heads))
4162		     gnus-newsgroup-dormant)
4163	       (setq heads (cdr heads))
4164	     (setq id (symbol-name refs))
4165	     (while (and (setq id (gnus-build-get-header id))
4166			 (not (car (gnus-id-to-thread id)))))
4167	     (setq heads nil)))))
4168     gnus-newsgroup-dependencies)))
4169
4170(defsubst gnus-remove-odd-characters (string)
4171  "Translate STRING into something that doesn't contain weird characters."
4172  (mm-subst-char-in-string
4173   ?\r ?\-
4174   (mm-subst-char-in-string
4175    ?\n ?\- string)))
4176
4177;; This function has to be called with point after the article number
4178;; on the beginning of the line.
4179(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4180  (let ((eol (gnus-point-at-eol))
4181	(buffer (current-buffer))
4182	header references in-reply-to)
4183
4184    ;; overview: [num subject from date id refs chars lines misc]
4185    (unwind-protect
4186	(let (x)
4187	  (narrow-to-region (point) eol)
4188	  (unless (eobp)
4189	    (forward-char))
4190
4191	  (setq header
4192		(make-full-mail-header
4193		 number			; number
4194		 (condition-case ()	; subject
4195		     (gnus-remove-odd-characters
4196		      (funcall gnus-decode-encoded-word-function
4197			       (setq x (nnheader-nov-field))))
4198		   (error x))
4199		 (condition-case ()	; from
4200		     (gnus-remove-odd-characters
4201		      (funcall gnus-decode-encoded-address-function
4202			       (setq x (nnheader-nov-field))))
4203		   (error x))
4204		 (nnheader-nov-field)	; date
4205		 (nnheader-nov-read-message-id)	; id
4206		 (setq references (nnheader-nov-field))	; refs
4207		 (nnheader-nov-read-integer) ; chars
4208		 (nnheader-nov-read-integer) ; lines
4209		 (unless (eobp)
4210		   (if (looking-at "Xref: ")
4211		       (goto-char (match-end 0)))
4212		   (nnheader-nov-field)) ; Xref
4213		 (nnheader-nov-parse-extra)))) ; extra
4214
4215      (widen))
4216
4217    (when (and (string= references "")
4218	       (setq in-reply-to (mail-header-extra header))
4219	       (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4220      (mail-header-set-references
4221       header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4222
4223    (when gnus-alter-header-function
4224      (funcall gnus-alter-header-function header))
4225    (gnus-dependencies-add-header header dependencies force-new)))
4226
4227(defun gnus-build-get-header (id)
4228  "Look through the buffer of NOV lines and find the header to ID.
4229Enter this line into the dependencies hash table, and return
4230the id of the parent article (if any)."
4231  (let ((deps gnus-newsgroup-dependencies)
4232	found header)
4233    (prog1
4234	(save-excursion
4235	  (set-buffer nntp-server-buffer)
4236	  (let ((case-fold-search nil))
4237	    (goto-char (point-min))
4238	    (while (and (not found)
4239			(search-forward id nil t))
4240	      (beginning-of-line)
4241	      (setq found (looking-at
4242			   (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4243				   (regexp-quote id))))
4244	      (or found (beginning-of-line 2)))
4245	    (when found
4246	      (beginning-of-line)
4247	      (and
4248	       (setq header (gnus-nov-parse-line
4249			     (read (current-buffer)) deps))
4250	       (gnus-parent-id (mail-header-references header))))))
4251      (when header
4252	(let ((number (mail-header-number header)))
4253	  (push number gnus-newsgroup-limit)
4254	  (push header gnus-newsgroup-headers)
4255	  (if (memq number gnus-newsgroup-unselected)
4256	      (progn
4257		(setq gnus-newsgroup-unreads
4258		      (gnus-add-to-sorted-list gnus-newsgroup-unreads
4259					       number))
4260		(setq gnus-newsgroup-unselected
4261		      (delq number gnus-newsgroup-unselected)))
4262	    (push number gnus-newsgroup-ancient)))))))
4263
4264(defun gnus-build-all-threads ()
4265  "Read all the headers."
4266  (let ((gnus-summary-ignore-duplicates t)
4267	(mail-parse-charset gnus-newsgroup-charset)
4268	(dependencies gnus-newsgroup-dependencies)
4269	header article)
4270    (save-excursion
4271      (set-buffer nntp-server-buffer)
4272      (let ((case-fold-search nil))
4273	(goto-char (point-min))
4274	(while (not (eobp))
4275	  (ignore-errors
4276	    (setq article (read (current-buffer))
4277		  header (gnus-nov-parse-line article dependencies)))
4278	  (when header
4279	    (save-excursion
4280	      (set-buffer gnus-summary-buffer)
4281	      (push header gnus-newsgroup-headers)
4282	      (if (memq (setq article (mail-header-number header))
4283			gnus-newsgroup-unselected)
4284		  (progn
4285		    (setq gnus-newsgroup-unreads
4286			  (gnus-add-to-sorted-list
4287			   gnus-newsgroup-unreads article))
4288		    (setq gnus-newsgroup-unselected
4289			  (delq article gnus-newsgroup-unselected)))
4290		(push article gnus-newsgroup-ancient)))
4291	    (forward-line 1)))))))
4292
4293(defun gnus-summary-update-article-line (article header)
4294  "Update the line for ARTICLE using HEADER."
4295  (let* ((id (mail-header-id header))
4296	 (thread (gnus-id-to-thread id)))
4297    (unless thread
4298      (error "Article in no thread"))
4299    ;; Update the thread.
4300    (setcar thread header)
4301    (gnus-summary-goto-subject article)
4302    (let* ((datal (gnus-data-find-list article))
4303	   (data (car datal))
4304	   (buffer-read-only nil)
4305	   (level (gnus-summary-thread-level)))
4306      (gnus-delete-line)
4307      (let ((inserted (- (point)
4308                         (progn
4309                           (gnus-summary-insert-line
4310                            header level nil
4311                            (memq article gnus-newsgroup-undownloaded)
4312                            (gnus-article-mark article)
4313                            (memq article gnus-newsgroup-replied)
4314                            (memq article gnus-newsgroup-expirable)
4315                            ;; Only insert the Subject string when it's different
4316                            ;; from the previous Subject string.
4317                            (if (and
4318                                 gnus-show-threads
4319                                 (gnus-subject-equal
4320                                  (condition-case ()
4321                                      (mail-header-subject
4322                                       (gnus-data-header
4323                                        (cadr
4324                                         (gnus-data-find-list
4325                                          article
4326                                          (gnus-data-list t)))))
4327                                    ;; Error on the side of excessive subjects.
4328                                    (error ""))
4329                                  (mail-header-subject header)))
4330                                ""
4331                              (mail-header-subject header))
4332                            nil (cdr (assq article gnus-newsgroup-scored))
4333                            (memq article gnus-newsgroup-processable))
4334                           (point)))))
4335        (when (cdr datal)
4336          (gnus-data-update-list
4337           (cdr datal)
4338           (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4339
4340(defun gnus-summary-update-article (article &optional iheader)
4341  "Update ARTICLE in the summary buffer."
4342  (set-buffer gnus-summary-buffer)
4343  (let* ((header (gnus-summary-article-header article))
4344	 (id (mail-header-id header))
4345	 (data (gnus-data-find article))
4346	 (thread (gnus-id-to-thread id))
4347	 (references (mail-header-references header))
4348	 (parent
4349	  (gnus-id-to-thread
4350	   (or (gnus-parent-id
4351		(when (and references
4352			   (not (equal "" references)))
4353		  references))
4354	       "none")))
4355	 (buffer-read-only nil)
4356	 (old (car thread)))
4357    (when thread
4358      (unless iheader
4359	(setcar thread nil)
4360	(when parent
4361	  (delq thread parent)))
4362      (if (gnus-summary-insert-subject id header)
4363	  ;; Set the (possibly) new article number in the data structure.
4364	  (gnus-data-set-number data (gnus-id-to-article id))
4365	(setcar thread old)
4366	nil))))
4367
4368(defun gnus-rebuild-thread (id &optional line)
4369  "Rebuild the thread containing ID.
4370If LINE, insert the rebuilt thread starting on line LINE."
4371  (let ((buffer-read-only nil)
4372	old-pos current thread data)
4373    (if (not gnus-show-threads)
4374	(setq thread (list (car (gnus-id-to-thread id))))
4375      ;; Get the thread this article is part of.
4376      (setq thread (gnus-remove-thread id)))
4377    (setq old-pos (gnus-point-at-bol))
4378    (setq current (save-excursion
4379		    (and (re-search-backward "[\r\n]" nil t)
4380			 (gnus-summary-article-number))))
4381    ;; If this is a gathered thread, we have to go some re-gathering.
4382    (when (stringp (car thread))
4383      (let ((subject (car thread))
4384	    roots thr)
4385	(setq thread (cdr thread))
4386	(while thread
4387	  (unless (memq (setq thr (gnus-id-to-thread
4388				   (gnus-root-id
4389				    (mail-header-id (caar thread)))))
4390			roots)
4391	    (push thr roots))
4392	  (setq thread (cdr thread)))
4393	;; We now have all (unique) roots.
4394	(if (= (length roots) 1)
4395	    ;; All the loose roots are now one solid root.
4396	    (setq thread (car roots))
4397	  (setq thread (cons subject (gnus-sort-threads roots))))))
4398    (let (threads)
4399      ;; We then insert this thread into the summary buffer.
4400      (when line
4401	(goto-char (point-min))
4402	(forward-line (1- line)))
4403      (let (gnus-newsgroup-data gnus-newsgroup-threads)
4404	(if gnus-show-threads
4405	    (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4406	  (gnus-summary-prepare-unthreaded thread))
4407	(setq data (nreverse gnus-newsgroup-data))
4408	(setq threads gnus-newsgroup-threads))
4409      ;; We splice the new data into the data structure.
4410      ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4411      ;;!!! then we want to insert at the beginning of the buffer.
4412      ;;!!! That happens to be true with Gnus now, but that may
4413      ;;!!! change in the future.  Perhaps.
4414      (gnus-data-enter-list
4415       (if line nil current) data (- (point) old-pos))
4416      (setq gnus-newsgroup-threads
4417	    (nconc threads gnus-newsgroup-threads))
4418      (gnus-data-compute-positions))))
4419
4420(defun gnus-number-to-header (number)
4421  "Return the header for article NUMBER."
4422  (let ((headers gnus-newsgroup-headers))
4423    (while (and headers
4424		(not (= number (mail-header-number (car headers)))))
4425      (pop headers))
4426    (when headers
4427      (car headers))))
4428
4429(defun gnus-parent-headers (in-headers &optional generation)
4430  "Return the headers of the GENERATIONeth parent of HEADERS."
4431  (unless generation
4432    (setq generation 1))
4433  (let ((parent t)
4434	(headers in-headers)
4435	references)
4436    (while (and parent
4437		(not (zerop generation))
4438		(setq references (mail-header-references headers)))
4439      (setq headers (if (and references
4440			     (setq parent (gnus-parent-id references)))
4441			(car (gnus-id-to-thread parent))
4442		      nil))
4443      (decf generation))
4444    (and (not (eq headers in-headers))
4445	 headers)))
4446
4447(defun gnus-id-to-thread (id)
4448  "Return the (sub-)thread where ID appears."
4449  (gnus-gethash id gnus-newsgroup-dependencies))
4450
4451(defun gnus-id-to-article (id)
4452  "Return the article number of ID."
4453  (let ((thread (gnus-id-to-thread id)))
4454    (when (and thread
4455	       (car thread))
4456      (mail-header-number (car thread)))))
4457
4458(defun gnus-id-to-header (id)
4459  "Return the article headers of ID."
4460  (car (gnus-id-to-thread id)))
4461
4462(defun gnus-article-displayed-root-p (article)
4463  "Say whether ARTICLE is a root(ish) article."
4464  (let ((level (gnus-summary-thread-level article))
4465	(refs (mail-header-references  (gnus-summary-article-header article)))
4466	particle)
4467    (cond
4468     ((null level) nil)
4469     ((zerop level) t)
4470     ((null refs) t)
4471     ((null (gnus-parent-id refs)) t)
4472     ((and (= 1 level)
4473	   (null (setq particle (gnus-id-to-article
4474				 (gnus-parent-id refs))))
4475	   (null (gnus-summary-thread-level particle)))))))
4476
4477(defun gnus-root-id (id)
4478  "Return the id of the root of the thread where ID appears."
4479  (let (last-id prev)
4480    (while (and id (setq prev (car (gnus-id-to-thread id))))
4481      (setq last-id id
4482	    id (gnus-parent-id (mail-header-references prev))))
4483    last-id))
4484
4485(defun gnus-articles-in-thread (thread)
4486  "Return the list of articles in THREAD."
4487  (cons (mail-header-number (car thread))
4488	(apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4489
4490(defun gnus-remove-thread (id &optional dont-remove)
4491  "Remove the thread that has ID in it."
4492  (let (headers thread last-id)
4493    ;; First go up in this thread until we find the root.
4494    (setq last-id (gnus-root-id id)
4495	  headers (message-flatten-list (gnus-id-to-thread last-id)))
4496    ;; We have now found the real root of this thread.  It might have
4497    ;; been gathered into some loose thread, so we have to search
4498    ;; through the threads to find the thread we wanted.
4499    (let ((threads gnus-newsgroup-threads)
4500	  sub)
4501      (while threads
4502	(setq sub (car threads))
4503	(if (stringp (car sub))
4504	    ;; This is a gathered thread, so we look at the roots
4505	    ;; below it to find whether this article is in this
4506	    ;; gathered root.
4507	    (progn
4508	      (setq sub (cdr sub))
4509	      (while sub
4510		(when (member (caar sub) headers)
4511		  (setq thread (car threads)
4512			threads nil
4513			sub nil))
4514		(setq sub (cdr sub))))
4515	  ;; It's an ordinary thread, so we check it.
4516	  (when (eq (car sub) (car headers))
4517	    (setq thread sub
4518		  threads nil)))
4519	(setq threads (cdr threads)))
4520      ;; If this article is in no thread, then it's a root.
4521      (if thread
4522	  (unless dont-remove
4523	    (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4524	(setq thread (gnus-id-to-thread last-id)))
4525      (when thread
4526	(prog1
4527	    thread			; We return this thread.
4528	  (unless dont-remove
4529	    (if (stringp (car thread))
4530		(progn
4531		  ;; If we use dummy roots, then we have to remove the
4532		  ;; dummy root as well.
4533		  (when (eq gnus-summary-make-false-root 'dummy)
4534		    ;; We go to the dummy root by going to
4535		    ;; the first sub-"thread", and then one line up.
4536		    (gnus-summary-goto-article
4537		     (mail-header-number (caadr thread)))
4538		    (forward-line -1)
4539		    (gnus-delete-line)
4540		    (gnus-data-compute-positions))
4541		  (setq thread (cdr thread))
4542		  (while thread
4543		    (gnus-remove-thread-1 (car thread))
4544		    (setq thread (cdr thread))))
4545	      (gnus-remove-thread-1 thread))))))))
4546
4547(defun gnus-remove-thread-1 (thread)
4548  "Remove the thread THREAD recursively."
4549  (let ((number (mail-header-number (pop thread)))
4550	d)
4551    (setq thread (reverse thread))
4552    (while thread
4553      (gnus-remove-thread-1 (pop thread)))
4554    (when (setq d (gnus-data-find number))
4555      (goto-char (gnus-data-pos d))
4556      (gnus-summary-show-thread)
4557      (gnus-data-remove
4558       number
4559       (- (gnus-point-at-bol)
4560	  (prog1
4561	      (1+ (gnus-point-at-eol))
4562	    (gnus-delete-line)))))))
4563
4564(defun gnus-sort-threads-recursive (threads func)
4565  (sort (mapcar (lambda (thread)
4566		  (cons (car thread)
4567			(and (cdr thread)
4568			     (gnus-sort-threads-recursive (cdr thread) func))))
4569		threads) func))
4570
4571(defun gnus-sort-threads-loop (threads func)
4572  (let* ((superthread (cons nil threads))
4573  	 (stack (list (cons superthread threads)))
4574  	 remaining-threads thread)
4575    (while stack
4576      (setq remaining-threads (cdr (car stack)))
4577      (if remaining-threads
4578  	  (progn (setq thread (car remaining-threads))
4579  		 (setcdr (car stack) (cdr remaining-threads))
4580  		 (if (cdr thread)
4581  		     (push (cons thread (cdr thread)) stack)))
4582  	(setq thread (caar stack))
4583  	(setcdr thread (sort (cdr thread) func))
4584  	(pop stack)))
4585    (cdr superthread)))
4586
4587(defun gnus-sort-threads (threads)
4588  "Sort THREADS."
4589  (if (not gnus-thread-sort-functions)
4590      threads
4591    (gnus-message 8 "Sorting threads...")
4592    (prog1
4593	(condition-case nil
4594	    (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4595	      (gnus-sort-threads-recursive
4596	       threads (gnus-make-sort-function gnus-thread-sort-functions)))
4597	  ;; Even after binding max-lisp-eval-depth, the recursive
4598	  ;; sorter might fail for very long threads.  In that case,
4599	  ;; try using a (less well-tested) non-recursive sorter.
4600	  (error (gnus-sort-threads-loop
4601		  threads (gnus-make-sort-function
4602			   gnus-thread-sort-functions))))
4603      (gnus-message 8 "Sorting threads...done"))))
4604
4605(defun gnus-sort-articles (articles)
4606  "Sort ARTICLES."
4607  (when gnus-article-sort-functions
4608    (gnus-message 7 "Sorting articles...")
4609    (prog1
4610	(setq gnus-newsgroup-headers
4611	      (sort articles (gnus-make-sort-function
4612			      gnus-article-sort-functions)))
4613      (gnus-message 7 "Sorting articles...done"))))
4614
4615;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4616(defmacro gnus-thread-header (thread)
4617  "Return header of first article in THREAD.
4618Note that THREAD must never, ever be anything else than a variable -
4619using some other form will lead to serious barfage."
4620  (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4621  ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4622  (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4623	(vector thread) 2))
4624
4625(defsubst gnus-article-sort-by-number (h1 h2)
4626  "Sort articles by article number."
4627  (< (mail-header-number h1)
4628     (mail-header-number h2)))
4629
4630(defun gnus-thread-sort-by-number (h1 h2)
4631  "Sort threads by root article number."
4632  (gnus-article-sort-by-number
4633   (gnus-thread-header h1) (gnus-thread-header h2)))
4634
4635(defsubst gnus-article-sort-by-random (h1 h2)
4636  "Sort articles by article number."
4637  (zerop (random 2)))
4638
4639(defun gnus-thread-sort-by-random (h1 h2)
4640  "Sort threads by root article number."
4641  (gnus-article-sort-by-random
4642   (gnus-thread-header h1) (gnus-thread-header h2)))
4643
4644(defsubst gnus-article-sort-by-lines (h1 h2)
4645  "Sort articles by article Lines header."
4646  (< (mail-header-lines h1)
4647     (mail-header-lines h2)))
4648
4649(defun gnus-thread-sort-by-lines (h1 h2)
4650  "Sort threads by root article Lines header."
4651  (gnus-article-sort-by-lines
4652   (gnus-thread-header h1) (gnus-thread-header h2)))
4653
4654(defsubst gnus-article-sort-by-chars (h1 h2)
4655  "Sort articles by octet length."
4656  (< (mail-header-chars h1)
4657     (mail-header-chars h2)))
4658
4659(defun gnus-thread-sort-by-chars (h1 h2)
4660  "Sort threads by root article octet length."
4661  (gnus-article-sort-by-chars
4662   (gnus-thread-header h1) (gnus-thread-header h2)))
4663
4664(defsubst gnus-article-sort-by-author (h1 h2)
4665  "Sort articles by root author."
4666  (string-lessp
4667   (let ((extract (funcall
4668		   gnus-extract-address-components
4669		   (mail-header-from h1))))
4670     (or (car extract) (cadr extract) ""))
4671   (let ((extract (funcall
4672		   gnus-extract-address-components
4673		   (mail-header-from h2))))
4674     (or (car extract) (cadr extract) ""))))
4675
4676(defun gnus-thread-sort-by-author (h1 h2)
4677  "Sort threads by root author."
4678  (gnus-article-sort-by-author
4679   (gnus-thread-header h1)  (gnus-thread-header h2)))
4680
4681(defsubst gnus-article-sort-by-subject (h1 h2)
4682  "Sort articles by root subject."
4683  (string-lessp
4684   (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4685   (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4686
4687(defun gnus-thread-sort-by-subject (h1 h2)
4688  "Sort threads by root subject."
4689  (gnus-article-sort-by-subject
4690   (gnus-thread-header h1) (gnus-thread-header h2)))
4691
4692(defsubst gnus-article-sort-by-date (h1 h2)
4693  "Sort articles by root article date."
4694  (time-less-p
4695   (gnus-date-get-time (mail-header-date h1))
4696   (gnus-date-get-time (mail-header-date h2))))
4697
4698(defun gnus-thread-sort-by-date (h1 h2)
4699  "Sort threads by root article date."
4700  (gnus-article-sort-by-date
4701   (gnus-thread-header h1) (gnus-thread-header h2)))
4702
4703(defsubst gnus-article-sort-by-score (h1 h2)
4704  "Sort articles by root article score.
4705Unscored articles will be counted as having a score of zero."
4706  (> (or (cdr (assq (mail-header-number h1)
4707		    gnus-newsgroup-scored))
4708	 gnus-summary-default-score 0)
4709     (or (cdr (assq (mail-header-number h2)
4710		    gnus-newsgroup-scored))
4711	 gnus-summary-default-score 0)))
4712
4713(defun gnus-thread-sort-by-score (h1 h2)
4714  "Sort threads by root article score."
4715  (gnus-article-sort-by-score
4716   (gnus-thread-header h1) (gnus-thread-header h2)))
4717
4718(defun gnus-thread-sort-by-total-score (h1 h2)
4719  "Sort threads by the sum of all scores in the thread.
4720Unscored articles will be counted as having a score of zero."
4721  (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4722
4723(defun gnus-thread-total-score (thread)
4724  ;; This function find the total score of THREAD.
4725  (cond
4726   ((null thread)
4727    0)
4728   ((consp thread)
4729    (if (stringp (car thread))
4730	(apply gnus-thread-score-function 0
4731	       (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4732      (gnus-thread-total-score-1 thread)))
4733   (t
4734    (gnus-thread-total-score-1 (list thread)))))
4735
4736(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4737  "Sort threads such that the thread with the most recently arrived article comes first."
4738  (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4739
4740(defun gnus-thread-highest-number (thread)
4741  "Return the highest article number in THREAD."
4742  (apply 'max (mapcar (lambda (header)
4743			(mail-header-number header))
4744		      (message-flatten-list thread))))
4745
4746(defun gnus-thread-sort-by-most-recent-date (h1 h2)
4747  "Sort threads such that the thread with the most recently dated article comes first."
4748  (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4749
4750(defun gnus-thread-latest-date (thread)
4751  "Return the highest article date in THREAD."
4752  (let ((previous-time 0))
4753    (apply 'max
4754	   (mapcar
4755	    (lambda (header)
4756	      (setq previous-time
4757		    (condition-case ()
4758			(time-to-seconds (mail-header-parse-date
4759					  (mail-header-date header)))
4760		      (error previous-time))))
4761	    (sort
4762	     (message-flatten-list thread)
4763	     (lambda (h1 h2)
4764	       (< (mail-header-number h1)
4765		  (mail-header-number h2))))))))
4766
4767(defun gnus-thread-total-score-1 (root)
4768  ;; This function find the total score of the thread below ROOT.
4769  (setq root (car root))
4770  (apply gnus-thread-score-function
4771	 (or (append
4772	      (mapcar 'gnus-thread-total-score
4773		      (cdr (gnus-id-to-thread (mail-header-id root))))
4774	      (when (> (mail-header-number root) 0)
4775		(list (or (cdr (assq (mail-header-number root)
4776				     gnus-newsgroup-scored))
4777			  gnus-summary-default-score 0))))
4778	     (list gnus-summary-default-score)
4779	     '(0))))
4780
4781;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4782(defvar gnus-tmp-prev-subject nil)
4783(defvar gnus-tmp-false-parent nil)
4784(defvar gnus-tmp-root-expunged nil)
4785(defvar gnus-tmp-dummy-line nil)
4786
4787(eval-when-compile (defvar gnus-tmp-header))
4788(defun gnus-extra-header (type &optional header)
4789  "Return the extra header of TYPE."
4790  (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4791      ""))
4792
4793(defvar gnus-tmp-thread-tree-header-string "")
4794
4795(defcustom gnus-sum-thread-tree-root "> "
4796  "With %B spec, used for the root of a thread.
4797If nil, use subject instead."
4798  :version "22.1"
4799  :type '(radio (const :format "%v  " nil) string)
4800  :group 'gnus-thread)
4801(defcustom gnus-sum-thread-tree-false-root "> "
4802  "With %B spec, used for a false root of a thread.
4803If nil, use subject instead."
4804  :version "22.1"
4805  :type '(radio (const :format "%v  " nil) string)
4806  :group 'gnus-thread)
4807(defcustom gnus-sum-thread-tree-single-indent ""
4808  "With %B spec, used for a thread with just one message.
4809If nil, use subject instead."
4810  :version "22.1"
4811  :type '(radio (const :format "%v  " nil) string)
4812  :group 'gnus-thread)
4813(defcustom gnus-sum-thread-tree-vertical "| "
4814  "With %B spec, used for drawing a vertical line."
4815  :version "22.1"
4816  :type 'string
4817  :group 'gnus-thread)
4818(defcustom gnus-sum-thread-tree-indent "  "
4819  "With %B spec, used for indenting."
4820  :version "22.1"
4821  :type 'string
4822  :group 'gnus-thread)
4823(defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4824  "With %B spec, used for a leaf with brothers."
4825  :version "22.1"
4826  :type 'string
4827  :group 'gnus-thread)
4828(defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4829  "With %B spec, used for a leaf without brothers."
4830  :version "22.1"
4831  :type 'string
4832  :group 'gnus-thread)
4833
4834(defun gnus-summary-prepare-threads (threads)
4835  "Prepare summary buffer from THREADS and indentation LEVEL.
4836THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4837or a straight list of headers."
4838  (gnus-message 7 "Generating summary...")
4839
4840  (setq gnus-newsgroup-threads threads)
4841  (beginning-of-line)
4842
4843  (let ((gnus-tmp-level 0)
4844	(default-score (or gnus-summary-default-score 0))
4845	(gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4846	(building-line-count gnus-summary-display-while-building)
4847	(building-count (integerp gnus-summary-display-while-building))
4848	thread number subject stack state gnus-tmp-gathered beg-match
4849	new-roots gnus-tmp-new-adopts thread-end simp-subject
4850	gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4851	gnus-tmp-replied gnus-tmp-subject-or-nil
4852	gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4853	gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4854	gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4855	tree-stack)
4856
4857    (setq gnus-tmp-prev-subject nil
4858          gnus-tmp-thread-tree-header-string "")
4859
4860    (if (vectorp (car threads))
4861	;; If this is a straight (sic) list of headers, then a
4862	;; threaded summary display isn't required, so we just create
4863	;; an unthreaded one.
4864	(gnus-summary-prepare-unthreaded threads)
4865
4866      ;; Do the threaded display.
4867
4868      (if gnus-summary-display-while-building
4869	  (switch-to-buffer (buffer-name)))
4870      (while (or threads stack gnus-tmp-new-adopts new-roots)
4871
4872	(if (and (= gnus-tmp-level 0)
4873		 (or (not stack)
4874		     (= (caar stack) 0))
4875		 (not gnus-tmp-false-parent)
4876		 (or gnus-tmp-new-adopts new-roots))
4877	    (if gnus-tmp-new-adopts
4878		(setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4879		      thread (list (car gnus-tmp-new-adopts))
4880		      gnus-tmp-header (caar thread)
4881		      gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4882	      (when new-roots
4883		(setq thread (list (car new-roots))
4884		      gnus-tmp-header (caar thread)
4885		      new-roots (cdr new-roots))))
4886
4887	  (if threads
4888	      ;; If there are some threads, we do them before the
4889	      ;; threads on the stack.
4890	      (setq thread threads
4891		    gnus-tmp-header (caar thread))
4892	    ;; There were no current threads, so we pop something off
4893	    ;; the stack.
4894	    (setq state (car stack)
4895		  gnus-tmp-level (car state)
4896		  tree-stack (cadr state)
4897		  thread (caddr state)
4898		  stack (cdr stack)
4899		  gnus-tmp-header (caar thread))))
4900
4901	(setq gnus-tmp-false-parent nil)
4902	(setq gnus-tmp-root-expunged nil)
4903	(setq thread-end nil)
4904
4905	(if (stringp gnus-tmp-header)
4906	    ;; The header is a dummy root.
4907	    (cond
4908	     ((eq gnus-summary-make-false-root 'adopt)
4909	      ;; We let the first article adopt the rest.
4910	      (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4911					       (cddar thread)))
4912	      (setq gnus-tmp-gathered
4913		    (nconc (mapcar
4914			    (lambda (h) (mail-header-number (car h)))
4915			    (cddar thread))
4916			   gnus-tmp-gathered))
4917	      (setq thread (cons (list (caar thread)
4918				       (cadar thread))
4919				 (cdr thread)))
4920	      (setq gnus-tmp-level -1
4921		    gnus-tmp-false-parent t))
4922	     ((eq gnus-summary-make-false-root 'empty)
4923	      ;; We print adopted articles with empty subject fields.
4924	      (setq gnus-tmp-gathered
4925		    (nconc (mapcar
4926			    (lambda (h) (mail-header-number (car h)))
4927			    (cddar thread))
4928			   gnus-tmp-gathered))
4929	      (setq gnus-tmp-level -1))
4930	     ((eq gnus-summary-make-false-root 'dummy)
4931	      ;; We remember that we probably want to output a dummy
4932	      ;; root.
4933	      (setq gnus-tmp-dummy-line gnus-tmp-header)
4934	      (setq gnus-tmp-prev-subject gnus-tmp-header))
4935	     (t
4936	      ;; We do not make a root for the gathered
4937	      ;; sub-threads at all.
4938	      (setq gnus-tmp-level -1)))
4939
4940	  (setq number (mail-header-number gnus-tmp-header)
4941		subject (mail-header-subject gnus-tmp-header)
4942		simp-subject (gnus-simplify-subject-fully subject))
4943
4944	  (cond
4945	   ;; If the thread has changed subject, we might want to make
4946	   ;; this subthread into a root.
4947	   ((and (null gnus-thread-ignore-subject)
4948		 (not (zerop gnus-tmp-level))
4949		 gnus-tmp-prev-subject
4950		 (not (string= gnus-tmp-prev-subject simp-subject)))
4951	    (setq new-roots (nconc new-roots (list (car thread)))
4952		  thread-end t
4953		  gnus-tmp-header nil))
4954	   ;; If the article lies outside the current limit,
4955	   ;; then we do not display it.
4956	   ((not (memq number gnus-newsgroup-limit))
4957	    (setq gnus-tmp-gathered
4958		  (nconc (mapcar
4959			  (lambda (h) (mail-header-number (car h)))
4960			  (cdar thread))
4961			 gnus-tmp-gathered))
4962	    (setq gnus-tmp-new-adopts (if (cdar thread)
4963					  (append gnus-tmp-new-adopts
4964						  (cdar thread))
4965					gnus-tmp-new-adopts)
4966		  thread-end t
4967		  gnus-tmp-header nil)
4968	    (when (zerop gnus-tmp-level)
4969	      (setq gnus-tmp-root-expunged t)))
4970	   ;; Perhaps this article is to be marked as read?
4971	   ((and gnus-summary-mark-below
4972		 (< (or (cdr (assq number gnus-newsgroup-scored))
4973			default-score)
4974		    gnus-summary-mark-below)
4975		 ;; Don't touch sparse articles.
4976		 (not (gnus-summary-article-sparse-p number))
4977		 (not (gnus-summary-article-ancient-p number)))
4978	    (setq gnus-newsgroup-unreads
4979		  (delq number gnus-newsgroup-unreads))
4980	    (if gnus-newsgroup-auto-expire
4981		(setq gnus-newsgroup-expirable
4982		      (gnus-add-to-sorted-list
4983		       gnus-newsgroup-expirable number))
4984	      (push (cons number gnus-low-score-mark)
4985		    gnus-newsgroup-reads))))
4986
4987	  (when gnus-tmp-header
4988	    ;; We may have an old dummy line to output before this
4989	    ;; article.
4990	    (when (and gnus-tmp-dummy-line
4991		       (gnus-subject-equal
4992			gnus-tmp-dummy-line
4993			(mail-header-subject gnus-tmp-header)))
4994	      (gnus-summary-insert-dummy-line
4995	       gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4996	      (setq gnus-tmp-dummy-line nil))
4997
4998	    ;; Compute the mark.
4999	    (setq gnus-tmp-unread (gnus-article-mark number))
5000
5001	    (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5002				  gnus-tmp-header gnus-tmp-level)
5003		  gnus-newsgroup-data)
5004
5005	    ;; Actually insert the line.
5006	    (setq
5007	     gnus-tmp-subject-or-nil
5008	     (cond
5009	      ((and gnus-thread-ignore-subject
5010		    gnus-tmp-prev-subject
5011		    (not (string= gnus-tmp-prev-subject simp-subject)))
5012	       subject)
5013	      ((zerop gnus-tmp-level)
5014	       (if (and (eq gnus-summary-make-false-root 'empty)
5015			(memq number gnus-tmp-gathered)
5016			gnus-tmp-prev-subject
5017			(string= gnus-tmp-prev-subject simp-subject))
5018		   gnus-summary-same-subject
5019		 subject))
5020	      (t gnus-summary-same-subject)))
5021	    (if (and (eq gnus-summary-make-false-root 'adopt)
5022		     (= gnus-tmp-level 1)
5023		     (memq number gnus-tmp-gathered))
5024		(setq gnus-tmp-opening-bracket ?\<
5025		      gnus-tmp-closing-bracket ?\>)
5026	      (setq gnus-tmp-opening-bracket ?\[
5027		    gnus-tmp-closing-bracket ?\]))
5028	    (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5029		(gnus-make-thread-indent-array
5030		 (max (* 2 (length gnus-thread-indent-array))
5031		      gnus-tmp-level)))
5032	    (setq
5033	     gnus-tmp-indentation
5034	     (aref gnus-thread-indent-array gnus-tmp-level)
5035	     gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5036	     gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5037				gnus-summary-default-score 0)
5038	     gnus-tmp-score-char
5039	     (if (or (null gnus-summary-default-score)
5040		     (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5041			 gnus-summary-zcore-fuzz))
5042		 ?                      ;Whitespace
5043	       (if (< gnus-tmp-score gnus-summary-default-score)
5044		   gnus-score-below-mark gnus-score-over-mark))
5045	     gnus-tmp-replied
5046	     (cond ((memq number gnus-newsgroup-processable)
5047		    gnus-process-mark)
5048		   ((memq number gnus-newsgroup-cached)
5049		    gnus-cached-mark)
5050		   ((memq number gnus-newsgroup-replied)
5051		    gnus-replied-mark)
5052		   ((memq number gnus-newsgroup-forwarded)
5053		    gnus-forwarded-mark)
5054		   ((memq number gnus-newsgroup-saved)
5055		    gnus-saved-mark)
5056		   ((memq number gnus-newsgroup-recent)
5057		    gnus-recent-mark)
5058		   ((memq number gnus-newsgroup-unseen)
5059		    gnus-unseen-mark)
5060		   (t gnus-no-mark))
5061	     gnus-tmp-downloaded
5062             (cond ((memq number gnus-newsgroup-undownloaded)
5063                    gnus-undownloaded-mark)
5064                   (gnus-newsgroup-agentized
5065                    gnus-downloaded-mark)
5066                   (t
5067                    gnus-no-mark))
5068	     gnus-tmp-from (mail-header-from gnus-tmp-header)
5069	     gnus-tmp-name
5070	     (cond
5071	      ((string-match "<[^>]+> *$" gnus-tmp-from)
5072	       (setq beg-match (match-beginning 0))
5073	       (or (and (string-match "^\".+\"" gnus-tmp-from)
5074			(substring gnus-tmp-from 1 (1- (match-end 0))))
5075		   (substring gnus-tmp-from 0 beg-match)))
5076	      ((string-match "(.+)" gnus-tmp-from)
5077	       (substring gnus-tmp-from
5078			  (1+ (match-beginning 0)) (1- (match-end 0))))
5079	      (t gnus-tmp-from))
5080
5081	     ;; Do the %B string
5082	     gnus-tmp-thread-tree-header-string
5083	     (cond
5084	      ((not gnus-show-threads) "")
5085	      ((zerop gnus-tmp-level)
5086	       (cond ((cdar thread)
5087		      (or gnus-sum-thread-tree-root subject))
5088		     (gnus-tmp-new-adopts
5089		      (or gnus-sum-thread-tree-false-root subject))
5090		     (t
5091		      (or gnus-sum-thread-tree-single-indent subject))))
5092	      (t
5093	       (concat (apply 'concat
5094			      (mapcar (lambda (item)
5095					(if (= item 1)
5096					    gnus-sum-thread-tree-vertical
5097					  gnus-sum-thread-tree-indent))
5098				      (cdr (reverse tree-stack))))
5099		       (if (nth 1 thread)
5100			   gnus-sum-thread-tree-leaf-with-other
5101			 gnus-sum-thread-tree-single-leaf)))))
5102	    (when (string= gnus-tmp-name "")
5103	      (setq gnus-tmp-name gnus-tmp-from))
5104	    (unless (numberp gnus-tmp-lines)
5105	      (setq gnus-tmp-lines -1))
5106	    (if (= gnus-tmp-lines -1)
5107		(setq gnus-tmp-lines "?")
5108	      (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5109              (gnus-put-text-property
5110	     (point)
5111	     (progn (eval gnus-summary-line-format-spec) (point))
5112               'gnus-number number)
5113	    (when gnus-visual-p
5114	      (forward-line -1)
5115	      (gnus-run-hooks 'gnus-summary-update-hook)
5116	      (forward-line 1))
5117
5118	    (setq gnus-tmp-prev-subject simp-subject)))
5119
5120	(when (nth 1 thread)
5121	  (push (list (max 0 gnus-tmp-level)
5122		      (copy-sequence tree-stack)
5123		      (nthcdr 1 thread))
5124		stack))
5125	(push (if (nth 1 thread) 1 0) tree-stack)
5126	(incf gnus-tmp-level)
5127	(setq threads (if thread-end nil (cdar thread)))
5128	(if gnus-summary-display-while-building
5129	    (if building-count
5130		(progn
5131		  ;; use a set frequency
5132		  (setq building-line-count (1- building-line-count))
5133		  (when (= building-line-count 0)
5134		    (sit-for 0)
5135		    (setq building-line-count
5136			  gnus-summary-display-while-building)))
5137	      ;; always
5138	      (sit-for 0)))
5139	(unless threads
5140	  (setq gnus-tmp-level 0)))))
5141  (gnus-message 7 "Generating summary...done"))
5142
5143(defun gnus-summary-prepare-unthreaded (headers)
5144  "Generate an unthreaded summary buffer based on HEADERS."
5145  (let (header number mark)
5146
5147    (beginning-of-line)
5148
5149    (while headers
5150      ;; We may have to root out some bad articles...
5151      (when (memq (setq number (mail-header-number
5152				(setq header (pop headers))))
5153		  gnus-newsgroup-limit)
5154	;; Mark article as read when it has a low score.
5155	(when (and gnus-summary-mark-below
5156		   (< (or (cdr (assq number gnus-newsgroup-scored))
5157			  gnus-summary-default-score 0)
5158		      gnus-summary-mark-below)
5159		   (not (gnus-summary-article-ancient-p number)))
5160	  (setq gnus-newsgroup-unreads
5161		(delq number gnus-newsgroup-unreads))
5162	  (if gnus-newsgroup-auto-expire
5163	      (push number gnus-newsgroup-expirable)
5164	    (push (cons number gnus-low-score-mark)
5165		  gnus-newsgroup-reads)))
5166
5167	(setq mark (gnus-article-mark number))
5168	(push (gnus-data-make number mark (1+ (point)) header 0)
5169	      gnus-newsgroup-data)
5170	(gnus-summary-insert-line
5171	 header 0 number
5172	 (memq number gnus-newsgroup-undownloaded)
5173	 mark (memq number gnus-newsgroup-replied)
5174	 (memq number gnus-newsgroup-expirable)
5175	 (mail-header-subject header) nil
5176	 (cdr (assq number gnus-newsgroup-scored))
5177	 (memq number gnus-newsgroup-processable))))))
5178
5179(defun gnus-summary-remove-list-identifiers ()
5180  "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5181  (let ((regexp (if (consp gnus-list-identifiers)
5182		    (mapconcat 'identity gnus-list-identifiers " *\\|")
5183		  gnus-list-identifiers))
5184	changed subject)
5185    (when regexp
5186      (dolist (header gnus-newsgroup-headers)
5187	(setq subject (mail-header-subject header)
5188	      changed nil)
5189	(while (string-match
5190		(concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
5191		subject)
5192	  (setq subject
5193		(concat (substring subject 0 (match-beginning 2))
5194			(substring subject (match-end 0)))
5195		changed t))
5196	(when (and changed
5197		   (string-match
5198		    "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
5199	  (setq subject
5200		(concat (substring subject 0 (match-beginning 1))
5201			(substring subject (match-end 1)))))
5202	(when changed
5203	  (mail-header-set-subject header subject))))))
5204
5205(defun gnus-fetch-headers (articles)
5206  "Fetch headers of ARTICLES."
5207  (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5208    (gnus-message 5 "Fetching headers for %s..." name)
5209    (prog1
5210	(if (eq 'nov
5211		(setq gnus-headers-retrieved-by
5212		      (gnus-retrieve-headers
5213		       articles gnus-newsgroup-name
5214		       ;; We might want to fetch old headers, but
5215		       ;; not if there is only 1 article.
5216		       (and (or (and
5217				 (not (eq gnus-fetch-old-headers 'some))
5218				 (not (numberp gnus-fetch-old-headers)))
5219				(> (length articles) 1))
5220			    gnus-fetch-old-headers))))
5221	    (gnus-get-newsgroup-headers-xover
5222	     articles nil nil gnus-newsgroup-name t)
5223	  (gnus-get-newsgroup-headers))
5224      (gnus-message 5 "Fetching headers for %s...done" name))))
5225
5226(defun gnus-select-newsgroup (group &optional read-all select-articles)
5227  "Select newsgroup GROUP.
5228If READ-ALL is non-nil, all articles in the group are selected.
5229If SELECT-ARTICLES, only select those articles from GROUP."
5230  (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5231	 ;;!!! Dirty hack; should be removed.
5232	 (gnus-summary-ignore-duplicates
5233	  (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5234	      t
5235	    gnus-summary-ignore-duplicates))
5236	 (info (nth 2 entry))
5237	 articles fetched-articles cached)
5238
5239    (unless (gnus-check-server
5240	     (set (make-local-variable 'gnus-current-select-method)
5241		  (gnus-find-method-for-group group)))
5242      (error "Couldn't open server"))
5243
5244    (or (and entry (not (eq (car entry) t))) ; Either it's active...
5245	(gnus-activate-group group)	; Or we can activate it...
5246	(progn				; Or we bug out.
5247	  (when (equal major-mode 'gnus-summary-mode)
5248	    (gnus-kill-buffer (current-buffer)))
5249	  (error "Couldn't activate group %s: %s"
5250		 (gnus-group-decoded-name group) (gnus-status-message group))))
5251
5252    (unless (gnus-request-group group t)
5253      (when (equal major-mode 'gnus-summary-mode)
5254	(gnus-kill-buffer (current-buffer)))
5255      (error "Couldn't request group %s: %s"
5256	     (gnus-group-decoded-name group) (gnus-status-message group)))
5257
5258    (when gnus-agent
5259      (gnus-agent-possibly-alter-active group (gnus-active group) info)
5260
5261      (setq gnus-summary-use-undownloaded-faces
5262	    (gnus-agent-find-parameter
5263	     group
5264	     'agent-enable-undownloaded-faces)))
5265
5266    (setq gnus-newsgroup-name group
5267	  gnus-newsgroup-unselected nil
5268	  gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5269
5270    (let ((display (gnus-group-find-parameter group 'display)))
5271      (setq gnus-newsgroup-display
5272	    (cond
5273	     ((not (zerop (or (car-safe read-all) 0)))
5274	      ;; The user entered the group with C-u SPC/RET, let's show
5275	      ;; all articles.
5276	      'gnus-not-ignore)
5277	     ((eq display 'all)
5278	      'gnus-not-ignore)
5279	     ((arrayp display)
5280	      (gnus-summary-display-make-predicate (mapcar 'identity display)))
5281	     ((numberp display)
5282	      ;; The following is probably the "correct" solution, but
5283	      ;; it makes Gnus fetch all headers and then limit the
5284	      ;; articles (which is slow), so instead we hack the
5285	      ;; select-articles parameter instead. -- Simon Josefsson
5286	      ;; <jas@kth.se>
5287	      ;;
5288	      ;; (gnus-byte-compile
5289	      ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5290	      ;; 			 display)))))
5291	      (setq select-articles
5292		    (gnus-uncompress-range
5293		     (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5294			     (if (> tmp 0)
5295				 tmp
5296			       1))
5297			   (cdr (gnus-active group)))))
5298	      nil)
5299	     (t
5300	      nil))))
5301
5302    (gnus-summary-setup-default-charset)
5303
5304    ;; Kludge to avoid having cached articles nixed out in virtual groups.
5305    (when (gnus-virtual-group-p group)
5306      (setq cached gnus-newsgroup-cached))
5307
5308    (setq gnus-newsgroup-unreads
5309	  (gnus-sorted-ndifference
5310	   (gnus-sorted-ndifference gnus-newsgroup-unreads
5311				    gnus-newsgroup-marked)
5312	   gnus-newsgroup-dormant))
5313
5314    (setq gnus-newsgroup-processable nil)
5315
5316    (gnus-update-read-articles group gnus-newsgroup-unreads)
5317
5318    ;; Adjust and set lists of article marks.
5319    (when info
5320      (gnus-adjust-marked-articles info))
5321    (if (setq articles select-articles)
5322	(setq gnus-newsgroup-unselected
5323	      (gnus-sorted-difference gnus-newsgroup-unreads articles))
5324      (setq articles (gnus-articles-to-read group read-all)))
5325
5326    (cond
5327     ((null articles)
5328      ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5329      'quit)
5330     ((eq articles 0) nil)
5331     (t
5332      ;; Init the dependencies hash table.
5333      (setq gnus-newsgroup-dependencies
5334	    (gnus-make-hashtable (length articles)))
5335      (gnus-set-global-variables)
5336      ;; Retrieve the headers and read them in.
5337
5338      (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5339
5340      ;; Kludge to avoid having cached articles nixed out in virtual groups.
5341      (when cached
5342	(setq gnus-newsgroup-cached cached))
5343
5344      ;; Suppress duplicates?
5345      (when gnus-suppress-duplicates
5346	(gnus-dup-suppress-articles))
5347
5348      ;; Set the initial limit.
5349      (setq gnus-newsgroup-limit (copy-sequence articles))
5350      ;; Remove canceled articles from the list of unread articles.
5351      (setq fetched-articles
5352	    (mapcar (lambda (headers) (mail-header-number headers))
5353		    gnus-newsgroup-headers))
5354      (setq gnus-newsgroup-articles fetched-articles)
5355      (setq gnus-newsgroup-unreads
5356	    (gnus-sorted-nintersection
5357	     gnus-newsgroup-unreads fetched-articles))
5358      (gnus-compute-unseen-list)
5359
5360      ;; Removed marked articles that do not exist.
5361      (gnus-update-missing-marks
5362       (gnus-sorted-difference articles fetched-articles))
5363      ;; We might want to build some more threads first.
5364      (when (and gnus-fetch-old-headers
5365		 (eq gnus-headers-retrieved-by 'nov))
5366	(if (eq gnus-fetch-old-headers 'invisible)
5367	    (gnus-build-all-threads)
5368	  (gnus-build-old-threads)))
5369      ;; Let the Gnus agent mark articles as read.
5370      (when gnus-agent
5371	(gnus-agent-get-undownloaded-list))
5372      ;; Remove list identifiers from subject
5373      (when gnus-list-identifiers
5374	(gnus-summary-remove-list-identifiers))
5375      ;; Check whether auto-expire is to be done in this group.
5376      (setq gnus-newsgroup-auto-expire
5377	    (gnus-group-auto-expirable-p group))
5378      ;; Set up the article buffer now, if necessary.
5379      (unless gnus-single-article-buffer
5380	(gnus-article-setup-buffer))
5381      ;; First and last article in this newsgroup.
5382      (when gnus-newsgroup-headers
5383	(setq gnus-newsgroup-begin
5384	      (mail-header-number (car gnus-newsgroup-headers))
5385	      gnus-newsgroup-end
5386	      (mail-header-number
5387	       (gnus-last-element gnus-newsgroup-headers))))
5388      ;; GROUP is successfully selected.
5389      (or gnus-newsgroup-headers t)))))
5390
5391(defun gnus-compute-unseen-list ()
5392  ;; The `seen' marks are treated specially.
5393  (if (not gnus-newsgroup-seen)
5394      (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5395    (setq gnus-newsgroup-unseen
5396	  (gnus-inverse-list-range-intersection
5397	   gnus-newsgroup-articles gnus-newsgroup-seen))))
5398
5399(defun gnus-summary-display-make-predicate (display)
5400  (require 'gnus-agent)
5401  (when (= (length display) 1)
5402    (setq display (car display)))
5403  (unless gnus-summary-display-cache
5404    (dolist (elem (append '((unread . unread)
5405			    (read . read)
5406			    (unseen . unseen))
5407			  gnus-article-mark-lists))
5408      (push (cons (cdr elem)
5409		  (gnus-byte-compile
5410		   `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5411	    gnus-summary-display-cache)))
5412  (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5413	(gnus-category-predicate-cache gnus-summary-display-cache))
5414    (gnus-get-predicate display)))
5415
5416;; Uses the dynamically bound `number' variable.
5417(eval-when-compile
5418  (defvar number))
5419(defun gnus-article-marked-p (type &optional article)
5420  (let ((article (or article number)))
5421    (cond
5422     ((eq type 'tick)
5423      (memq article gnus-newsgroup-marked))
5424     ((eq type 'spam)
5425      (memq article gnus-newsgroup-spam-marked))
5426     ((eq type 'unsend)
5427      (memq article gnus-newsgroup-unsendable))
5428     ((eq type 'undownload)
5429      (memq article gnus-newsgroup-undownloaded))
5430     ((eq type 'download)
5431      (memq article gnus-newsgroup-downloadable))
5432     ((eq type 'unread)
5433      (memq article gnus-newsgroup-unreads))
5434     ((eq type 'read)
5435      (memq article gnus-newsgroup-reads))
5436     ((eq type 'dormant)
5437      (memq article gnus-newsgroup-dormant) )
5438     ((eq type 'expire)
5439      (memq article gnus-newsgroup-expirable))
5440     ((eq type 'reply)
5441      (memq article gnus-newsgroup-replied))
5442     ((eq type 'killed)
5443      (memq article gnus-newsgroup-killed))
5444     ((eq type 'bookmark)
5445      (assq article gnus-newsgroup-bookmarks))
5446     ((eq type 'score)
5447      (assq article gnus-newsgroup-scored))
5448     ((eq type 'save)
5449      (memq article gnus-newsgroup-saved))
5450     ((eq type 'cache)
5451      (memq article gnus-newsgroup-cached))
5452     ((eq type 'forward)
5453      (memq article gnus-newsgroup-forwarded))
5454     ((eq type 'seen)
5455      (not (memq article gnus-newsgroup-unseen)))
5456     ((eq type 'recent)
5457      (memq article gnus-newsgroup-recent))
5458     (t t))))
5459
5460(defun gnus-articles-to-read (group &optional read-all)
5461  "Find out what articles the user wants to read."
5462  (let* ((articles
5463	  ;; Select all articles if `read-all' is non-nil, or if there
5464	  ;; are no unread articles.
5465	  (if (or read-all
5466		  (and (zerop (length gnus-newsgroup-marked))
5467		       (zerop (length gnus-newsgroup-unreads)))
5468		  ;; Fetch all if the predicate is non-nil.
5469		  gnus-newsgroup-display)
5470	      ;; We want to select the headers for all the articles in
5471	      ;; the group, so we select either all the active
5472	      ;; articles in the group, or (if that's nil), the
5473	      ;; articles in the cache.
5474	      (or
5475	       (gnus-uncompress-range (gnus-active group))
5476	       (gnus-cache-articles-in-group group))
5477	    ;; Select only the "normal" subset of articles.
5478	    (gnus-sorted-nunion
5479	     (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5480	     gnus-newsgroup-unreads)))
5481	 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5482	 (scored (length scored-list))
5483	 (number (length articles))
5484	 (marked (+ (length gnus-newsgroup-marked)
5485		    (length gnus-newsgroup-dormant)))
5486	 (select
5487	  (cond
5488	   ((numberp read-all)
5489	    read-all)
5490	   ((numberp gnus-newsgroup-display)
5491	    gnus-newsgroup-display)
5492	   (t
5493	    (condition-case ()
5494		(cond
5495		 ((and (or (<= scored marked) (= scored number))
5496		       (numberp gnus-large-newsgroup)
5497		       (> number gnus-large-newsgroup))
5498		  (let* ((cursor-in-echo-area nil)
5499			 (initial (gnus-parameter-large-newsgroup-initial
5500				   gnus-newsgroup-name))
5501			 (input
5502			  (read-string
5503			   (format
5504			    "How many articles from %s (%s %d): "
5505			    (gnus-limit-string
5506			     (gnus-group-decoded-name gnus-newsgroup-name)
5507			     35)
5508			    (if initial "max" "default")
5509			    number)
5510			   (if initial
5511			       (cons (number-to-string initial)
5512				     0)))))
5513		    (if (string-match "^[ \t]*$" input) number input)))
5514		 ((and (> scored marked) (< scored number)
5515		       (> (- scored number) 20))
5516		  (let ((input
5517			 (read-string
5518			  (format "%s %s (%d scored, %d total): "
5519				  "How many articles from"
5520				  (gnus-group-decoded-name group)
5521				  scored number))))
5522		    (if (string-match "^[ \t]*$" input)
5523			number input)))
5524		 (t number))
5525	      (quit
5526	       (message "Quit getting the articles to read")
5527	       nil))))))
5528    (setq select (if (stringp select) (string-to-number select) select))
5529    (if (or (null select) (zerop select))
5530	select
5531      (if (and (not (zerop scored)) (<= (abs select) scored))
5532	  (progn
5533	    (setq articles (sort scored-list '<))
5534	    (setq number (length articles)))
5535	(setq articles (copy-sequence articles)))
5536
5537      (when (< (abs select) number)
5538	(if (< select 0)
5539	    ;; Select the N oldest articles.
5540	    (setcdr (nthcdr (1- (abs select)) articles) nil)
5541	  ;; Select the N most recent articles.
5542	  (setq articles (nthcdr (- number select) articles))))
5543      (setq gnus-newsgroup-unselected
5544	    (gnus-sorted-difference gnus-newsgroup-unreads articles))
5545      (when gnus-alter-articles-to-read-function
5546	(setq articles
5547	      (sort
5548	       (funcall gnus-alter-articles-to-read-function
5549			gnus-newsgroup-name articles)
5550	       '<)))
5551      articles)))
5552
5553(defun gnus-killed-articles (killed articles)
5554  (let (out)
5555    (while articles
5556      (when (inline (gnus-member-of-range (car articles) killed))
5557	(push (car articles) out))
5558      (setq articles (cdr articles)))
5559    out))
5560
5561(defun gnus-uncompress-marks (marks)
5562  "Uncompress the mark ranges in MARKS."
5563  (let ((uncompressed '(score bookmark))
5564	out)
5565    (while marks
5566      (if (memq (caar marks) uncompressed)
5567	  (push (car marks) out)
5568	(push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5569      (setq marks (cdr marks)))
5570    out))
5571
5572(defun gnus-article-mark-to-type (mark)
5573  "Return the type of MARK."
5574  (or (cadr (assq mark gnus-article-special-mark-lists))
5575      'list))
5576
5577(defun gnus-article-unpropagatable-p (mark)
5578  "Return whether MARK should be propagated to back end."
5579  (memq mark gnus-article-unpropagated-mark-lists))
5580
5581(defun gnus-adjust-marked-articles (info)
5582  "Set all article lists and remove all marks that are no longer valid."
5583  (let* ((marked-lists (gnus-info-marks info))
5584	 (active (gnus-active (gnus-info-group info)))
5585	 (min (car active))
5586	 (max (cdr active))
5587	 (types gnus-article-mark-lists)
5588	 marks var articles article mark mark-type
5589         bgn end)
5590
5591    (dolist (marks marked-lists)
5592      (setq mark (car marks)
5593	    mark-type (gnus-article-mark-to-type mark)
5594	    var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5595
5596      ;; We set the variable according to the type of the marks list,
5597      ;; and then adjust the marks to a subset of the active articles.
5598      (cond
5599       ;; Adjust "simple" lists - compressed yet unsorted
5600       ((eq mark-type 'list)
5601        ;; Simultaneously uncompress and clip to active range
5602        ;; See gnus-uncompress-range for a description of possible marks
5603        (let (l lh)
5604          (if (not (cadr marks))
5605              (set var nil)
5606            (setq articles (if (numberp (cddr marks))
5607                               (list (cdr marks))
5608                             (cdr marks))
5609                  lh (cons nil nil)
5610                  l lh)
5611
5612            (while (setq article (pop articles))
5613              (cond ((consp article)
5614                     (setq bgn (max (car article) min)
5615                           end (min (cdr article) max))
5616                     (while (<= bgn end)
5617                       (setq l (setcdr l (cons bgn nil))
5618                             bgn (1+ bgn))))
5619                    ((and (<= min article)
5620                          (>= max article))
5621                     (setq l (setcdr l (cons article nil))))))
5622            (set var (cdr lh)))))
5623       ;; Adjust assocs.
5624       ((eq mark-type 'tuple)
5625	(set var (setq articles (cdr marks)))
5626	(when (not (listp (cdr (symbol-value var))))
5627	  (set var (list (symbol-value var))))
5628	(when (not (listp (cdr articles)))
5629	  (setq articles (list articles)))
5630	(while articles
5631	  (when (or (not (consp (setq article (pop articles))))
5632		    (< (car article) min)
5633		    (> (car article) max))
5634	    (set var (delq article (symbol-value var))))))
5635       ;; Adjust ranges (sloppily).
5636       ((eq mark-type 'range)
5637	(cond
5638	 ((eq mark 'seen)
5639	  ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5640	  ;; It should be (seen (NUM1 . NUM2)).
5641	  (when (numberp (cddr marks))
5642	    (setcdr marks (list (cdr marks))))
5643	  (setq articles (cdr marks))
5644	  (while (and articles
5645		      (or (and (consp (car articles))
5646			       (> min (cdar articles)))
5647			  (and (numberp (car articles))
5648			       (> min (car articles)))))
5649	    (pop articles))
5650	  (set var articles))))))))
5651
5652(defun gnus-update-missing-marks (missing)
5653  "Go through the list of MISSING articles and remove them from the mark lists."
5654  (when missing
5655    (let (var m)
5656      ;; Go through all types.
5657      (dolist (elem gnus-article-mark-lists)
5658	(when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5659	  (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5660	  (when (symbol-value var)
5661	    ;; This list has articles.  So we delete all missing
5662	    ;; articles from it.
5663	    (setq m missing)
5664	    (while m
5665	      (set var (delq (pop m) (symbol-value var))))))))))
5666
5667(defun gnus-update-marks ()
5668  "Enter the various lists of marked articles into the newsgroup info list."
5669  (let ((types gnus-article-mark-lists)
5670	(info (gnus-get-info gnus-newsgroup-name))
5671	type list newmarked symbol delta-marks)
5672    (when info
5673      ;; Add all marks lists to the list of marks lists.
5674      (while (setq type (pop types))
5675	(setq list (symbol-value
5676		    (setq symbol
5677			  (intern (format "gnus-newsgroup-%s" (car type))))))
5678
5679	(when list
5680	  ;; Get rid of the entries of the articles that have the
5681	  ;; default score.
5682	  (when (and (eq (cdr type) 'score)
5683		     gnus-save-score
5684		     list)
5685	    (let* ((arts list)
5686		   (prev (cons nil list))
5687		   (all prev))
5688	      (while arts
5689		(if (or (not (consp (car arts)))
5690			(= (cdar arts) gnus-summary-default-score))
5691		    (setcdr prev (cdr arts))
5692		  (setq prev arts))
5693		(setq arts (cdr arts)))
5694	      (setq list (cdr all)))))
5695
5696	(when (eq (cdr type) 'seen)
5697	  (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5698
5699	(when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5700	  (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5701
5702	(when (and (gnus-check-backend-function
5703		    'request-set-mark gnus-newsgroup-name)
5704		   (not (gnus-article-unpropagatable-p (cdr type))))
5705	  (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5706		 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5707		 (add (gnus-remove-from-range
5708		       (gnus-copy-sequence list) old)))
5709	    (when add
5710	      (push (list add 'add (list (cdr type))) delta-marks))
5711	    (when del
5712	      (push (list del 'del (list (cdr type))) delta-marks))))
5713
5714	(when list
5715	  (push (cons (cdr type) list) newmarked)))
5716
5717      (when delta-marks
5718	(unless (gnus-check-group gnus-newsgroup-name)
5719	  (error "Can't open server for %s" gnus-newsgroup-name))
5720	(gnus-request-set-mark gnus-newsgroup-name delta-marks))
5721
5722      ;; Enter these new marks into the info of the group.
5723      (if (nthcdr 3 info)
5724	  (setcar (nthcdr 3 info) newmarked)
5725	;; Add the marks lists to the end of the info.
5726	(when newmarked
5727	  (setcdr (nthcdr 2 info) (list newmarked))))
5728
5729      ;; Cut off the end of the info if there's nothing else there.
5730      (let ((i 5))
5731	(while (and (> i 2)
5732		    (not (nth i info)))
5733	  (when (nthcdr (decf i) info)
5734	    (setcdr (nthcdr i info) nil)))))))
5735
5736(defun gnus-set-mode-line (where)
5737  "Set the mode line of the article or summary buffers.
5738If WHERE is `summary', the summary mode line format will be used."
5739  ;; Is this mode line one we keep updated?
5740  (when (and (memq where gnus-updated-mode-lines)
5741	     (symbol-value
5742	      (intern (format "gnus-%s-mode-line-format-spec" where))))
5743    (let (mode-string)
5744      (save-excursion
5745	;; We evaluate this in the summary buffer since these
5746	;; variables are buffer-local to that buffer.
5747	(set-buffer gnus-summary-buffer)
5748       ;; We bind all these variables that are used in the `eval' form
5749	;; below.
5750	(let* ((mformat (symbol-value
5751			 (intern
5752			  (format "gnus-%s-mode-line-format-spec" where))))
5753	       (gnus-tmp-group-name (gnus-mode-string-quote
5754				     (gnus-group-decoded-name
5755				      gnus-newsgroup-name)))
5756	       (gnus-tmp-article-number (or gnus-current-article 0))
5757	       (gnus-tmp-unread gnus-newsgroup-unreads)
5758	       (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5759	       (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5760	       (gnus-tmp-unread-and-unselected
5761		(cond ((and (zerop gnus-tmp-unread-and-unticked)
5762			    (zerop gnus-tmp-unselected))
5763		       "")
5764		      ((zerop gnus-tmp-unselected)
5765		       (format "{%d more}" gnus-tmp-unread-and-unticked))
5766		      (t (format "{%d(+%d) more}"
5767				 gnus-tmp-unread-and-unticked
5768				 gnus-tmp-unselected))))
5769	       (gnus-tmp-subject
5770		(if (and gnus-current-headers
5771			 (vectorp gnus-current-headers))
5772		    (gnus-mode-string-quote
5773		     (mail-header-subject gnus-current-headers))
5774		  ""))
5775	       bufname-length max-len
5776	       gnus-tmp-header)	;; passed as argument to any user-format-funcs
5777	  (setq mode-string (eval mformat))
5778	  (setq bufname-length (if (string-match "%b" mode-string)
5779				   (- (length
5780				       (buffer-name
5781					(if (eq where 'summary)
5782					    nil
5783					  (get-buffer gnus-article-buffer))))
5784				      2)
5785				 0))
5786	  (setq max-len (max 4 (if gnus-mode-non-string-length
5787				   (- (window-width)
5788				      gnus-mode-non-string-length
5789				      bufname-length)
5790				 (length mode-string))))
5791	  ;; We might have to chop a bit of the string off...
5792	  (when (> (length mode-string) max-len)
5793	    (setq mode-string
5794		  (concat (truncate-string-to-width mode-string (- max-len 3))
5795			  "...")))
5796	  ;; Pad the mode string a bit.
5797	  (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5798      ;; Update the mode line.
5799      (setq mode-line-buffer-identification
5800	    (gnus-mode-line-buffer-identification (list mode-string)))
5801      (set-buffer-modified-p t))))
5802
5803(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5804  "Go through the HEADERS list and add all Xrefs to a hash table.
5805The resulting hash table is returned, or nil if no Xrefs were found."
5806  (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5807	 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5808	 (xref-hashtb (gnus-make-hashtable))
5809	 start group entry number xrefs header)
5810    (while headers
5811      (setq header (pop headers))
5812      (when (and (setq xrefs (mail-header-xref header))
5813		 (not (memq (setq number (mail-header-number header))
5814			    unreads)))
5815	(setq start 0)
5816	(while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5817	  (setq start (match-end 0))
5818	  (setq group (if prefix
5819			  (concat prefix (substring xrefs (match-beginning 1)
5820						    (match-end 1)))
5821			(substring xrefs (match-beginning 1) (match-end 1))))
5822	  (setq number
5823		(string-to-number (substring xrefs (match-beginning 2)
5824					  (match-end 2))))
5825	  (if (setq entry (gnus-gethash group xref-hashtb))
5826	      (setcdr entry (cons number (cdr entry)))
5827	    (gnus-sethash group (cons number nil) xref-hashtb)))))
5828    (and start xref-hashtb)))
5829
5830(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5831  "Look through all the headers and mark the Xrefs as read."
5832  (let ((virtual (gnus-virtual-group-p from-newsgroup))
5833	name entry info xref-hashtb idlist method nth4)
5834    (save-excursion
5835      (set-buffer gnus-group-buffer)
5836      (when (setq xref-hashtb
5837		  (gnus-create-xref-hashtb from-newsgroup headers unreads))
5838	(mapatoms
5839	 (lambda (group)
5840	   (unless (string= from-newsgroup (setq name (symbol-name group)))
5841	     (setq idlist (symbol-value group))
5842	     ;; Dead groups are not updated.
5843	     (and (prog1
5844		      (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5845			    info (nth 2 entry))
5846		    (when (stringp (setq nth4 (gnus-info-method info)))
5847		      (setq nth4 (gnus-server-to-method nth4))))
5848		  ;; Only do the xrefs if the group has the same
5849		  ;; select method as the group we have just read.
5850		  (or (gnus-methods-equal-p
5851		       nth4 (gnus-find-method-for-group from-newsgroup))
5852		      virtual
5853		      (equal nth4 (setq method (gnus-find-method-for-group
5854						from-newsgroup)))
5855		      (and (equal (car nth4) (car method))
5856			   (equal (nth 1 nth4) (nth 1 method))))
5857		  gnus-use-cross-reference
5858		  (or (not (eq gnus-use-cross-reference t))
5859		      virtual
5860		      ;; Only do cross-references on subscribed
5861		      ;; groups, if that is what is wanted.
5862		      (<= (gnus-info-level info) gnus-level-subscribed))
5863		  (gnus-group-make-articles-read name idlist))))
5864	 xref-hashtb)))))
5865
5866(defun gnus-compute-read-articles (group articles)
5867  (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5868	 (info (nth 2 entry))
5869	 (active (gnus-active group))
5870	 ninfo)
5871    (when entry
5872      ;; First peel off all invalid article numbers.
5873      (when active
5874	(let ((ids articles)
5875	      id first)
5876	  (while (setq id (pop ids))
5877	    (when (and first (> id (cdr active)))
5878	      ;; We'll end up in this situation in one particular
5879	      ;; obscure situation.  If you re-scan a group and get
5880	      ;; a new article that is cross-posted to a different
5881	      ;; group that has not been re-scanned, you might get
5882	      ;; crossposted article that has a higher number than
5883	      ;; Gnus believes possible.  So we re-activate this
5884	      ;; group as well.  This might mean doing the
5885	      ;; crossposting thingy will *increase* the number
5886	      ;; of articles in some groups.  Tsk, tsk.
5887	      (setq active (or (gnus-activate-group group) active)))
5888	    (when (or (> id (cdr active))
5889		      (< id (car active)))
5890	      (setq articles (delq id articles))))))
5891      ;; If the read list is nil, we init it.
5892      (if (and active
5893	       (null (gnus-info-read info))
5894	       (> (car active) 1))
5895	  (setq ninfo (cons 1 (1- (car active))))
5896	(setq ninfo (gnus-info-read info)))
5897      ;; Then we add the read articles to the range.
5898      (gnus-add-to-range
5899       ninfo (setq articles (sort articles '<))))))
5900
5901(defun gnus-group-make-articles-read (group articles)
5902  "Update the info of GROUP to say that ARTICLES are read."
5903  (let* ((num 0)
5904	 (entry (gnus-gethash group gnus-newsrc-hashtb))
5905	 (info (nth 2 entry))
5906	 (active (gnus-active group))
5907	 range)
5908    (when entry
5909      (setq range (gnus-compute-read-articles group articles))
5910      (save-excursion
5911	(set-buffer gnus-group-buffer)
5912	(gnus-undo-register
5913	  `(progn
5914	     (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5915	     (gnus-info-set-read ',info ',(gnus-info-read info))
5916	     (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5917	     (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5918	     (gnus-group-update-group ,group t))))
5919      ;; Add the read articles to the range.
5920      (gnus-info-set-read info range)
5921      (gnus-request-set-mark group (list (list range 'add '(read))))
5922      ;; Then we have to re-compute how many unread
5923      ;; articles there are in this group.
5924      (when active
5925	(cond
5926	 ((not range)
5927	  (setq num (- (1+ (cdr active)) (car active))))
5928	 ((not (listp (cdr range)))
5929	  (setq num (- (cdr active) (- (1+ (cdr range))
5930				       (car range)))))
5931	 (t
5932	  (while range
5933	    (if (numberp (car range))
5934		(setq num (1+ num))
5935	      (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5936	    (setq range (cdr range)))
5937	  (setq num (- (cdr active) num))))
5938	;; Update the number of unread articles.
5939	(setcar entry num)
5940	;; Update the group buffer.
5941	(unless (gnus-ephemeral-group-p group)
5942	  (gnus-group-update-group group t))))))
5943
5944(defvar gnus-newsgroup-none-id 0)
5945
5946(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5947  (let ((cur nntp-server-buffer)
5948	(dependencies
5949	 (or dependencies
5950	     (save-excursion (set-buffer gnus-summary-buffer)
5951			     gnus-newsgroup-dependencies)))
5952	headers id end ref
5953	(mail-parse-charset gnus-newsgroup-charset)
5954	(mail-parse-ignored-charsets
5955	 (save-excursion (condition-case nil
5956			     (set-buffer gnus-summary-buffer)
5957			   (error))
5958			 gnus-newsgroup-ignored-charsets)))
5959    (save-excursion
5960      (set-buffer nntp-server-buffer)
5961      ;; Translate all TAB characters into SPACE characters.
5962      (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5963      (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5964      (ietf-drums-unfold-fws)
5965      (gnus-run-hooks 'gnus-parse-headers-hook)
5966      (let ((case-fold-search t)
5967	    in-reply-to header p lines chars)
5968	(goto-char (point-min))
5969	;; Search to the beginning of the next header.  Error messages
5970	;; do not begin with 2 or 3.
5971	(while (re-search-forward "^[23][0-9]+ " nil t)
5972	  (setq id nil
5973		ref nil)
5974	  ;; This implementation of this function, with nine
5975	  ;; search-forwards instead of the one re-search-forward and
5976	  ;; a case (which basically was the old function) is actually
5977	  ;; about twice as fast, even though it looks messier.  You
5978	  ;; can't have everything, I guess.  Speed and elegance
5979	  ;; doesn't always go hand in hand.
5980	  (setq
5981	   header
5982	   (vector
5983	    ;; Number.
5984	    (prog1
5985		(read cur)
5986	      (end-of-line)
5987	      (setq p (point))
5988	      (narrow-to-region (point)
5989				(or (and (search-forward "\n.\n" nil t)
5990					 (- (point) 2))
5991				    (point))))
5992	    ;; Subject.
5993	    (progn
5994	      (goto-char p)
5995	      (if (search-forward "\nsubject:" nil t)
5996		  (funcall gnus-decode-encoded-word-function
5997			   (nnheader-header-value))
5998		"(none)"))
5999	    ;; From.
6000	    (progn
6001	      (goto-char p)
6002	      (if (search-forward "\nfrom:" nil t)
6003		  (funcall gnus-decode-encoded-address-function
6004			   (nnheader-header-value))
6005		"(nobody)"))
6006	    ;; Date.
6007	    (progn
6008	      (goto-char p)
6009	      (if (search-forward "\ndate:" nil t)
6010		  (nnheader-header-value) ""))
6011	    ;; Message-ID.
6012	    (progn
6013	      (goto-char p)
6014	      (setq id (if (re-search-forward
6015			    "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6016			   ;; We do it this way to make sure the Message-ID
6017			   ;; is (somewhat) syntactically valid.
6018			   (buffer-substring (match-beginning 1)
6019					     (match-end 1))
6020			 ;; If there was no message-id, we just fake one
6021			 ;; to make subsequent routines simpler.
6022			 (nnheader-generate-fake-message-id))))
6023	    ;; References.
6024	    (progn
6025	      (goto-char p)
6026	      (if (search-forward "\nreferences:" nil t)
6027		  (progn
6028		    (setq end (point))
6029		    (prog1
6030			(nnheader-header-value)
6031		      (setq ref
6032			    (buffer-substring
6033			     (progn
6034			       (end-of-line)
6035			       (search-backward ">" end t)
6036			       (1+ (point)))
6037			     (progn
6038			       (search-backward "<" end t)
6039			       (point))))))
6040		;; Get the references from the in-reply-to header if there
6041		;; were no references and the in-reply-to header looks
6042		;; promising.
6043		(if (and (search-forward "\nin-reply-to:" nil t)
6044			 (setq in-reply-to (nnheader-header-value))
6045			 (string-match "<[^>]+>" in-reply-to))
6046		    (let (ref2)
6047		      (setq ref (substring in-reply-to (match-beginning 0)
6048					   (match-end 0)))
6049		      (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6050			(setq ref2 (substring in-reply-to (match-beginning 0)
6051					      (match-end 0)))
6052			(when (> (length ref2) (length ref))
6053			  (setq ref ref2)))
6054		      ref)
6055		  (setq ref nil))))
6056	    ;; Chars.
6057	    (progn
6058	      (goto-char p)
6059	      (if (search-forward "\nchars: " nil t)
6060		  (if (numberp (setq chars (ignore-errors (read cur))))
6061		      chars -1)
6062		-1))
6063	    ;; Lines.
6064	    (progn
6065	      (goto-char p)
6066	      (if (search-forward "\nlines: " nil t)
6067		  (if (numberp (setq lines (ignore-errors (read cur))))
6068		      lines -1)
6069		-1))
6070	    ;; Xref.
6071	    (progn
6072	      (goto-char p)
6073	      (and (search-forward "\nxref:" nil t)
6074		   (nnheader-header-value)))
6075	    ;; Extra.
6076	    (when gnus-extra-headers
6077	      (let ((extra gnus-extra-headers)
6078		    out)
6079		(while extra
6080		  (goto-char p)
6081		  (when (search-forward
6082			 (concat "\n" (symbol-name (car extra)) ":") nil t)
6083		    (push (cons (car extra) (nnheader-header-value))
6084			  out))
6085		  (pop extra))
6086		out))))
6087	  (when (equal id ref)
6088	    (setq ref nil))
6089
6090	  (when gnus-alter-header-function
6091	    (funcall gnus-alter-header-function header)
6092	    (setq id (mail-header-id header)
6093		  ref (gnus-parent-id (mail-header-references header))))
6094
6095	  (when (setq header
6096		      (gnus-dependencies-add-header
6097		       header dependencies force-new))
6098	    (push header headers))
6099	  (goto-char (point-max))
6100	  (widen))
6101	(nreverse headers)))))
6102
6103;; Goes through the xover lines and returns a list of vectors
6104(defun gnus-get-newsgroup-headers-xover (sequence &optional
6105						  force-new dependencies
6106						  group also-fetch-heads)
6107  "Parse the news overview data in the server buffer.
6108Return a list of headers that match SEQUENCE (see
6109`nntp-retrieve-headers')."
6110  ;; Get the Xref when the users reads the articles since most/some
6111  ;; NNTP servers do not include Xrefs when using XOVER.
6112  (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6113  (let ((mail-parse-charset gnus-newsgroup-charset)
6114	(mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6115	(cur nntp-server-buffer)
6116	(dependencies (or dependencies gnus-newsgroup-dependencies))
6117	(allp (cond
6118	       ((eq gnus-read-all-available-headers t)
6119		t)
6120	       ((and (stringp gnus-read-all-available-headers)
6121		     group)
6122		(string-match gnus-read-all-available-headers group))
6123	       (t
6124		nil)))
6125	number headers header)
6126    (save-excursion
6127      (set-buffer nntp-server-buffer)
6128      (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6129      ;; Allow the user to mangle the headers before parsing them.
6130      (gnus-run-hooks 'gnus-parse-headers-hook)
6131      (goto-char (point-min))
6132      (gnus-parse-without-error
6133	(while (and (or sequence allp)
6134		    (not (eobp)))
6135	  (setq number (read cur))
6136	  (when (not allp)
6137	    (while (and sequence
6138			(< (car sequence) number))
6139	      (setq sequence (cdr sequence))))
6140	  (when (and (or allp
6141			 (and sequence
6142			      (eq number (car sequence))))
6143		     (progn
6144		       (setq sequence (cdr sequence))
6145		       (setq header (inline
6146				      (gnus-nov-parse-line
6147				       number dependencies force-new)))))
6148	    (push header headers))
6149	  (forward-line 1)))
6150      ;; A common bug in inn is that if you have posted an article and
6151      ;; then retrieves the active file, it will answer correctly --
6152      ;; the new article is included.  However, a NOV entry for the
6153      ;; article may not have been generated yet, so this may fail.
6154      ;; We work around this problem by retrieving the last few
6155      ;; headers using HEAD.
6156      (if (or (not also-fetch-heads)
6157	      (not sequence))
6158	  ;; We (probably) got all the headers.
6159	  (nreverse headers)
6160	(let ((gnus-nov-is-evil t))
6161	  (nconc
6162	   (nreverse headers)
6163	   (when (eq (gnus-retrieve-headers sequence group) 'headers)
6164	     (gnus-get-newsgroup-headers))))))))
6165
6166(defun gnus-article-get-xrefs ()
6167  "Fill in the Xref value in `gnus-current-headers', if necessary.
6168This is meant to be called in `gnus-article-internal-prepare-hook'."
6169  (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
6170				 gnus-current-headers)))
6171    (or (not gnus-use-cross-reference)
6172	(not headers)
6173	(and (mail-header-xref headers)
6174	     (not (string= (mail-header-xref headers) "")))
6175	(let ((case-fold-search t)
6176	      xref)
6177	  (save-restriction
6178	    (nnheader-narrow-to-headers)
6179	    (goto-char (point-min))
6180	    (when (or (and (not (eobp))
6181			   (eq (downcase (char-after)) ?x)
6182			   (looking-at "Xref:"))
6183		      (search-forward "\nXref:" nil t))
6184	      (goto-char (1+ (match-end 0)))
6185	      (setq xref (buffer-substring (point) (gnus-point-at-eol)))
6186	      (mail-header-set-xref headers xref)))))))
6187
6188(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6189  "Find article ID and insert the summary line for that article.
6190OLD-HEADER can either be a header or a line number to insert
6191the subject line on."
6192  (let* ((line (and (numberp old-header) old-header))
6193	 (old-header (and (vectorp old-header) old-header))
6194	 (header (cond ((and old-header use-old-header)
6195			old-header)
6196		       ((and (numberp id)
6197			     (gnus-number-to-header id))
6198			(gnus-number-to-header id))
6199		       (t
6200			(gnus-read-header id))))
6201	 (number (and (numberp id) id))
6202	 d)
6203    (when header
6204      ;; Rebuild the thread that this article is part of and go to the
6205      ;; article we have fetched.
6206      (when (and (not gnus-show-threads)
6207		 old-header)
6208	(when (and number
6209		   (setq d (gnus-data-find (mail-header-number old-header))))
6210	  (goto-char (gnus-data-pos d))
6211	  (gnus-data-remove
6212	   number
6213	   (- (gnus-point-at-bol)
6214	      (prog1
6215		  (1+ (gnus-point-at-eol))
6216		(gnus-delete-line))))))
6217      ;; Remove list identifiers from subject.
6218      (when gnus-list-identifiers
6219	(let ((gnus-newsgroup-headers (list header)))
6220	  (gnus-summary-remove-list-identifiers)))
6221      (when old-header
6222	(mail-header-set-number header (mail-header-number old-header)))
6223      (setq gnus-newsgroup-sparse
6224	    (delq (setq number (mail-header-number header))
6225		  gnus-newsgroup-sparse))
6226      (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6227      (push number gnus-newsgroup-limit)
6228      (gnus-rebuild-thread (mail-header-id header) line)
6229      (gnus-summary-goto-subject number nil t))
6230    (when (and (numberp number)
6231	       (> number 0))
6232      ;; We have to update the boundaries even if we can't fetch the
6233      ;; article if ID is a number -- so that the next `P' or `N'
6234      ;; command will fetch the previous (or next) article even
6235      ;; if the one we tried to fetch this time has been canceled.
6236      (when (> number gnus-newsgroup-end)
6237	(setq gnus-newsgroup-end number))
6238      (when (< number gnus-newsgroup-begin)
6239	(setq gnus-newsgroup-begin number))
6240      (setq gnus-newsgroup-unselected
6241	    (delq number gnus-newsgroup-unselected)))
6242    ;; Report back a success?
6243    (and header (mail-header-number header))))
6244
6245;;; Process/prefix in the summary buffer
6246
6247(defun gnus-summary-work-articles (n)
6248  "Return a list of articles to be worked upon.
6249The prefix argument, the list of process marked articles, and the
6250current article will be taken into consideration."
6251  (save-excursion
6252    (set-buffer gnus-summary-buffer)
6253    (cond
6254     (n
6255      ;; A numerical prefix has been given.
6256      (setq n (prefix-numeric-value n))
6257      (let ((backward (< n 0))
6258	    (n (abs (prefix-numeric-value n)))
6259	    articles article)
6260	(save-excursion
6261	  (while
6262	      (and (> n 0)
6263		   (push (setq article (gnus-summary-article-number))
6264			 articles)
6265		   (if backward
6266		       (gnus-summary-find-prev nil article)
6267		     (gnus-summary-find-next nil article)))
6268	    (decf n)))
6269	(nreverse articles)))
6270     ((and (gnus-region-active-p) (mark))
6271      (message "region active")
6272      ;; Work on the region between point and mark.
6273      (let ((max (max (point) (mark)))
6274	    articles article)
6275	(save-excursion
6276	  (goto-char (min (point) (mark)))
6277	  (while
6278	      (and
6279	       (push (setq article (gnus-summary-article-number)) articles)
6280	       (gnus-summary-find-next nil article)
6281	       (< (point) max)))
6282	  (nreverse articles))))
6283     (gnus-newsgroup-processable
6284      ;; There are process-marked articles present.
6285      ;; Save current state.
6286      (gnus-summary-save-process-mark)
6287      ;; Return the list.
6288      (reverse gnus-newsgroup-processable))
6289     (t
6290      ;; Just return the current article.
6291      (list (gnus-summary-article-number))))))
6292
6293(defmacro gnus-summary-iterate (arg &rest forms)
6294  "Iterate over the process/prefixed articles and do FORMS.
6295ARG is the interactive prefix given to the command.  FORMS will be
6296executed with point over the summary line of the articles."
6297  (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6298    `(let ((,articles (gnus-summary-work-articles ,arg)))
6299       (while ,articles
6300	 (gnus-summary-goto-subject (car ,articles))
6301	 ,@forms
6302	 (pop ,articles)))))
6303
6304(put 'gnus-summary-iterate 'lisp-indent-function 1)
6305(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6306
6307(defun gnus-summary-save-process-mark ()
6308  "Push the current set of process marked articles on the stack."
6309  (interactive)
6310  (push (copy-sequence gnus-newsgroup-processable)
6311	gnus-newsgroup-process-stack))
6312
6313(defun gnus-summary-kill-process-mark ()
6314  "Push the current set of process marked articles on the stack and unmark."
6315  (interactive)
6316  (gnus-summary-save-process-mark)
6317  (gnus-summary-unmark-all-processable))
6318
6319(defun gnus-summary-yank-process-mark ()
6320  "Pop the last process mark state off the stack and restore it."
6321  (interactive)
6322  (unless gnus-newsgroup-process-stack
6323    (error "Empty mark stack"))
6324  (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6325
6326(defun gnus-summary-process-mark-set (set)
6327  "Make SET into the current process marked articles."
6328  (gnus-summary-unmark-all-processable)
6329  (while set
6330    (gnus-summary-set-process-mark (pop set))))
6331
6332;;; Searching and stuff
6333
6334(defun gnus-summary-search-group (&optional backward use-level)
6335  "Search for next unread newsgroup.
6336If optional argument BACKWARD is non-nil, search backward instead."
6337  (save-excursion
6338    (set-buffer gnus-group-buffer)
6339    (when (gnus-group-search-forward
6340	   backward nil (if use-level (gnus-group-group-level) nil))
6341      (gnus-group-group-name))))
6342
6343(defun gnus-summary-best-group (&optional exclude-group)
6344  "Find the name of the best unread group.
6345If EXCLUDE-GROUP, do not go to this group."
6346  (save-excursion
6347    (set-buffer gnus-group-buffer)
6348    (save-excursion
6349      (gnus-group-best-unread-group exclude-group))))
6350
6351(defun gnus-summary-find-next (&optional unread article backward)
6352  (if backward
6353      (gnus-summary-find-prev unread article)
6354    (let* ((dummy (gnus-summary-article-intangible-p))
6355	   (article (or article (gnus-summary-article-number)))
6356	   (data (gnus-data-find-list article))
6357	   result)
6358      (when (and (not dummy)
6359		 (or (not gnus-summary-check-current)
6360		     (not unread)
6361		     (not (gnus-data-unread-p (car data)))))
6362	(setq data (cdr data)))
6363      (when (setq result
6364		  (if unread
6365		      (progn
6366			(while data
6367                          (unless (memq (gnus-data-number (car data))
6368                                        (cond
6369					 ((eq gnus-auto-goto-ignores
6370					      'always-undownloaded)
6371					  gnus-newsgroup-undownloaded)
6372					 (gnus-plugged
6373					  nil)
6374					 ((eq gnus-auto-goto-ignores
6375					      'unfetched)
6376					  gnus-newsgroup-unfetched)
6377					 ((eq gnus-auto-goto-ignores
6378					      'undownloaded)
6379					  gnus-newsgroup-undownloaded)))
6380                            (when (gnus-data-unread-p (car data))
6381                              (setq result (car data)
6382                                    data nil)))
6383			  (setq data (cdr data)))
6384			result)
6385		    (car data)))
6386	(goto-char (gnus-data-pos result))
6387	(gnus-data-number result)))))
6388
6389(defun gnus-summary-find-prev (&optional unread article)
6390  (let* ((eobp (eobp))
6391	 (article (or article (gnus-summary-article-number)))
6392	 (data (gnus-data-find-list article (gnus-data-list 'rev)))
6393	 result)
6394    (when (and (not eobp)
6395	       (or (not gnus-summary-check-current)
6396		   (not unread)
6397		   (not (gnus-data-unread-p (car data)))))
6398      (setq data (cdr data)))
6399    (when (setq result
6400		(if unread
6401		    (progn
6402		      (while data
6403                        (unless (memq (gnus-data-number (car data))
6404                                      (cond
6405				       ((eq gnus-auto-goto-ignores
6406					    'always-undownloaded)
6407					gnus-newsgroup-undownloaded)
6408				       (gnus-plugged
6409					nil)
6410				       ((eq gnus-auto-goto-ignores
6411					    'unfetched)
6412					gnus-newsgroup-unfetched)
6413				       ((eq gnus-auto-goto-ignores
6414					    'undownloaded)
6415					gnus-newsgroup-undownloaded)))
6416                          (when (gnus-data-unread-p (car data))
6417                            (setq result (car data)
6418                                  data nil)))
6419			(setq data (cdr data)))
6420		      result)
6421		  (car data)))
6422      (goto-char (gnus-data-pos result))
6423      (gnus-data-number result))))
6424
6425(defun gnus-summary-find-subject (subject &optional unread backward article)
6426  (let* ((simp-subject (gnus-simplify-subject-fully subject))
6427	 (article (or article (gnus-summary-article-number)))
6428	 (articles (gnus-data-list backward))
6429	 (arts (gnus-data-find-list article articles))
6430	 result)
6431    (when (or (not gnus-summary-check-current)
6432	      (not unread)
6433	      (not (gnus-data-unread-p (car arts))))
6434      (setq arts (cdr arts)))
6435    (while arts
6436      (and (or (not unread)
6437	       (gnus-data-unread-p (car arts)))
6438	   (vectorp (gnus-data-header (car arts)))
6439	   (gnus-subject-equal
6440	    simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6441	   (setq result (car arts)
6442		 arts nil))
6443      (setq arts (cdr arts)))
6444    (and result
6445	 (goto-char (gnus-data-pos result))
6446	 (gnus-data-number result))))
6447
6448(defun gnus-summary-search-forward (&optional unread subject backward)
6449  "Search forward for an article.
6450If UNREAD, look for unread articles.  If SUBJECT, look for
6451articles with that subject.  If BACKWARD, search backward instead."
6452  (cond (subject (gnus-summary-find-subject subject unread backward))
6453	(backward (gnus-summary-find-prev unread))
6454	(t (gnus-summary-find-next unread))))
6455
6456(defun gnus-recenter (&optional n)
6457  "Center point in window and redisplay frame.
6458Also do horizontal recentering."
6459  (interactive "P")
6460  (when (and gnus-auto-center-summary
6461	     (not (eq gnus-auto-center-summary 'vertical)))
6462    (gnus-horizontal-recenter))
6463  (recenter n))
6464
6465(defun gnus-summary-recenter ()
6466  "Center point in the summary window.
6467If `gnus-auto-center-summary' is nil, or the article buffer isn't
6468displayed, no centering will be performed."
6469  ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6470  ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6471  (interactive)
6472  ;; The user has to want it.
6473  (when gnus-auto-center-summary
6474    (let* ((top (cond ((< (window-height) 4) 0)
6475		      ((< (window-height) 7) 1)
6476		      (t (if (numberp gnus-auto-center-summary)
6477			     gnus-auto-center-summary
6478			   2))))
6479	   (height (1- (window-height)))
6480	   (bottom (save-excursion (goto-char (point-max))
6481				   (forward-line (- height))
6482				   (point)))
6483	   (window (get-buffer-window (current-buffer))))
6484      (when (get-buffer-window gnus-article-buffer)
6485	;; Only do recentering when the article buffer is displayed,
6486	;; Set the window start to either `bottom', which is the biggest
6487	;; possible valid number, or the second line from the top,
6488	;; whichever is the least.
6489	(let ((top-pos (save-excursion (forward-line (- top)) (point))))
6490	  (if (> bottom top-pos)
6491	      ;; Keep the second line from the top visible
6492	      (set-window-start window top-pos t)
6493	    ;; Try to keep the bottom line visible; if it's partially
6494	    ;; obscured, either scroll one more line to make it fully
6495	    ;; visible, or revert to using TOP-POS.
6496	    (save-excursion
6497	      (goto-char (point-max))
6498	      (forward-line -1)
6499	      (let ((last-line-start (point)))
6500		(goto-char bottom)
6501		(set-window-start window (point) t)
6502		(when (not (pos-visible-in-window-p last-line-start window))
6503		  (forward-line 1)
6504		  (set-window-start window (min (point) top-pos) t)))))))
6505      ;; Do horizontal recentering while we're at it.
6506      (when (and (get-buffer-window (current-buffer) t)
6507		 (not (eq gnus-auto-center-summary 'vertical)))
6508	(let ((selected (selected-window)))
6509	  (select-window (get-buffer-window (current-buffer) t))
6510	  (gnus-summary-position-point)
6511	  (gnus-horizontal-recenter)
6512	  (select-window selected))))))
6513
6514(defun gnus-summary-jump-to-group (newsgroup)
6515  "Move point to NEWSGROUP in group mode buffer."
6516  ;; Keep update point of group mode buffer if visible.
6517  (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6518      (save-window-excursion
6519	;; Take care of tree window mode.
6520	(when (get-buffer-window gnus-group-buffer)
6521	  (pop-to-buffer gnus-group-buffer))
6522	(gnus-group-jump-to-group newsgroup))
6523    (save-excursion
6524      ;; Take care of tree window mode.
6525      (if (get-buffer-window gnus-group-buffer)
6526	  (pop-to-buffer gnus-group-buffer)
6527	(set-buffer gnus-group-buffer))
6528      (gnus-group-jump-to-group newsgroup))))
6529
6530;; This function returns a list of article numbers based on the
6531;; difference between the ranges of read articles in this group and
6532;; the range of active articles.
6533(defun gnus-list-of-unread-articles (group)
6534  (let* ((read (gnus-info-read (gnus-get-info group)))
6535	 (active (or (gnus-active group) (gnus-activate-group group)))
6536	 (last (cdr active))
6537	 first nlast unread)
6538    ;; If none are read, then all are unread.
6539    (if (not read)
6540	(setq first (car active))
6541      ;; If the range of read articles is a single range, then the
6542      ;; first unread article is the article after the last read
6543      ;; article.  Sounds logical, doesn't it?
6544      (if (and (not (listp (cdr read)))
6545	       (or (< (car read) (car active))
6546		   (progn (setq read (list read))
6547			  nil)))
6548	  (setq first (max (car active) (1+ (cdr read))))
6549	;; `read' is a list of ranges.
6550	(when (/= (setq nlast (or (and (numberp (car read)) (car read))
6551				  (caar read)))
6552		  1)
6553	  (setq first (car active)))
6554	(while read
6555	  (when first
6556	    (while (< first nlast)
6557	      (setq unread (cons first unread)
6558                    first (1+ first))))
6559	  (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6560	  (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6561	  (setq read (cdr read)))))
6562    ;; And add the last unread articles.
6563    (while (<= first last)
6564      (setq unread (cons first unread)
6565            first (1+ first)))
6566    ;; Return the list of unread articles.
6567    (delq 0 (nreverse unread))))
6568
6569(defun gnus-list-of-read-articles (group)
6570  "Return a list of unread, unticked and non-dormant articles."
6571  (let* ((info (gnus-get-info group))
6572	 (marked (gnus-info-marks info))
6573	 (active (gnus-active group)))
6574    (and info active
6575	 (gnus-list-range-difference
6576	  (gnus-list-range-difference
6577	   (gnus-sorted-complement
6578	    (gnus-uncompress-range active)
6579	    (gnus-list-of-unread-articles group))
6580	   (cdr (assq 'dormant marked)))
6581	  (cdr (assq 'tick marked))))))
6582
6583;; This function returns a sequence of article numbers based on the
6584;; difference between the ranges of read articles in this group and
6585;; the range of active articles.
6586(defun gnus-sequence-of-unread-articles (group)
6587  (let* ((read (gnus-info-read (gnus-get-info group)))
6588	 (active (or (gnus-active group) (gnus-activate-group group)))
6589	 (last (cdr active))
6590	 first nlast unread)
6591    ;; If none are read, then all are unread.
6592    (if (not read)
6593	(setq first (car active))
6594      ;; If the range of read articles is a single range, then the
6595      ;; first unread article is the article after the last read
6596      ;; article.  Sounds logical, doesn't it?
6597      (if (and (not (listp (cdr read)))
6598	       (or (< (car read) (car active))
6599		   (progn (setq read (list read))
6600			  nil)))
6601	  (setq first (max (car active) (1+ (cdr read))))
6602	;; `read' is a list of ranges.
6603	(when (/= (setq nlast (or (and (numberp (car read)) (car read))
6604				  (caar read)))
6605		  1)
6606	  (setq first (car active)))
6607	(while read
6608	  (when first
6609            (push (cons first nlast) unread))
6610	  (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6611	  (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6612	  (setq read (cdr read)))))
6613    ;; And add the last unread articles.
6614    (cond ((not (and first last))
6615	   nil)
6616	  ((< first last)
6617	   (push (cons first last) unread))
6618	  ((= first last)
6619	   (push first unread)))
6620    ;; Return the sequence of unread articles.
6621    (delq 0 (nreverse unread))))
6622
6623;; Various summary commands
6624
6625(defun gnus-summary-select-article-buffer ()
6626  "Reconfigure windows to show article buffer."
6627  (interactive)
6628  (if (not (gnus-buffer-live-p gnus-article-buffer))
6629      (error "There is no article buffer for this summary buffer")
6630    (gnus-configure-windows 'article)
6631    (select-window (get-buffer-window gnus-article-buffer))))
6632
6633(defun gnus-summary-universal-argument (arg)
6634  "Perform any operation on all articles that are process/prefixed."
6635  (interactive "P")
6636  (let ((articles (gnus-summary-work-articles arg))
6637	func article)
6638    (if (eq
6639	 (setq
6640	  func
6641	  (key-binding
6642	   (read-key-sequence
6643	    (substitute-command-keys
6644	     "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6645	 'undefined)
6646	(gnus-error 1 "Undefined key")
6647      (save-excursion
6648	(while articles
6649	  (gnus-summary-goto-subject (setq article (pop articles)))
6650	  (let (gnus-newsgroup-processable)
6651	    (command-execute func))
6652	  (gnus-summary-remove-process-mark article)))))
6653  (gnus-summary-position-point))
6654
6655(defun gnus-summary-toggle-truncation (&optional arg)
6656  "Toggle truncation of summary lines.
6657With ARG, turn line truncation on if ARG is positive."
6658  (interactive "P")
6659  (setq truncate-lines
6660	(if (null arg) (not truncate-lines)
6661	  (> (prefix-numeric-value arg) 0)))
6662  (redraw-display))
6663
6664(defun gnus-summary-find-for-reselect ()
6665  "Return the number of an article to stay on across a reselect.
6666The current article is considered, then following articles, then previous
6667articles.  An article is sought which is not cancelled and isn't a temporary
6668insertion from another group.  If there's no such then return a dummy 0."
6669  (let (found)
6670    (dolist (rev '(nil t))
6671      (unless found      ; don't demand the reverse list if we don't need it
6672        (let ((data (gnus-data-find-list
6673                     (gnus-summary-article-number) (gnus-data-list rev))))
6674          (while (and data (not found))
6675            (if (and (< 0 (gnus-data-number (car data)))
6676                     (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6677                (setq found (gnus-data-number (car data))))
6678            (setq data (cdr data))))))
6679    (or found 0)))
6680
6681(defun gnus-summary-reselect-current-group (&optional all rescan)
6682  "Exit and then reselect the current newsgroup.
6683The prefix argument ALL means to select all articles."
6684  (interactive "P")
6685  (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6686    (error "Ephemeral groups can't be reselected"))
6687  (let ((current-subject (gnus-summary-find-for-reselect))
6688	(group gnus-newsgroup-name))
6689    (setq gnus-newsgroup-begin nil)
6690    (gnus-summary-exit nil 'leave-hidden)
6691    ;; We have to adjust the point of group mode buffer because
6692    ;; point was moved to the next unread newsgroup by exiting.
6693    (gnus-summary-jump-to-group group)
6694    (when rescan
6695      (save-excursion
6696	(gnus-group-get-new-news-this-group 1)))
6697    (gnus-group-read-group all t)
6698    (gnus-summary-goto-subject current-subject nil t)))
6699
6700(defun gnus-summary-rescan-group (&optional all)
6701  "Exit the newsgroup, ask for new articles, and select the newsgroup."
6702  (interactive "P")
6703  (gnus-summary-reselect-current-group all t))
6704
6705(defun gnus-summary-update-info (&optional non-destructive)
6706  (save-excursion
6707    (let ((group gnus-newsgroup-name))
6708      (when group
6709	(when gnus-newsgroup-kill-headers
6710	  (setq gnus-newsgroup-killed
6711		(gnus-compress-sequence
6712		 (gnus-sorted-union
6713		  (gnus-list-range-intersection
6714		   gnus-newsgroup-unselected gnus-newsgroup-killed)
6715		  gnus-newsgroup-unreads)
6716		 t)))
6717	(unless (listp (cdr gnus-newsgroup-killed))
6718	  (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6719	(let ((headers gnus-newsgroup-headers))
6720	  ;; Set the new ranges of read articles.
6721	  (save-excursion
6722	    (set-buffer gnus-group-buffer)
6723	    (gnus-undo-force-boundary))
6724	  (gnus-update-read-articles
6725	   group (gnus-sorted-union
6726		  gnus-newsgroup-unreads gnus-newsgroup-unselected))
6727	  ;; Set the current article marks.
6728	  (let ((gnus-newsgroup-scored
6729		 (if (and (not gnus-save-score)
6730			  (not non-destructive))
6731		     nil
6732		   gnus-newsgroup-scored)))
6733	    (save-excursion
6734	      (gnus-update-marks)))
6735	  ;; Do the cross-ref thing.
6736	  (when gnus-use-cross-reference
6737	    (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6738	  ;; Do not switch windows but change the buffer to work.
6739	  (set-buffer gnus-group-buffer)
6740	  (unless (gnus-ephemeral-group-p group)
6741	    (gnus-group-update-group group)))))))
6742
6743(defun gnus-summary-save-newsrc (&optional force)
6744  "Save the current number of read/marked articles in the dribble buffer.
6745The dribble buffer will then be saved.
6746If FORCE (the prefix), also save the .newsrc file(s)."
6747  (interactive "P")
6748  (gnus-summary-update-info t)
6749  (if force
6750      (gnus-save-newsrc-file)
6751    (gnus-dribble-save)))
6752
6753(defun gnus-summary-exit (&optional temporary leave-hidden)
6754  "Exit reading current newsgroup, and then return to group selection mode.
6755`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6756  (interactive)
6757  (gnus-set-global-variables)
6758  (when (gnus-buffer-live-p gnus-article-buffer)
6759    (save-excursion
6760      (set-buffer gnus-article-buffer)
6761      (mm-destroy-parts gnus-article-mime-handles)
6762      ;; Set it to nil for safety reason.
6763      (setq gnus-article-mime-handle-alist nil)
6764      (setq gnus-article-mime-handles nil)))
6765  (gnus-kill-save-kill-buffer)
6766  (gnus-async-halt-prefetch)
6767  (let* ((group gnus-newsgroup-name)
6768	 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6769	 (gnus-group-is-exiting-p t)
6770	 (mode major-mode)
6771	 (group-point nil)
6772	 (buf (current-buffer)))
6773    (unless quit-config
6774      ;; Do adaptive scoring, and possibly save score files.
6775      (when gnus-newsgroup-adaptive
6776	(gnus-score-adaptive))
6777      (when gnus-use-scoring
6778	(gnus-score-save)))
6779    (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6780    ;; If we have several article buffers, we kill them at exit.
6781    (unless gnus-single-article-buffer
6782      (gnus-kill-buffer gnus-original-article-buffer)
6783      (setq gnus-article-current nil))
6784    (when gnus-use-cache
6785      (gnus-cache-possibly-remove-articles)
6786      (gnus-cache-save-buffers))
6787    (gnus-async-prefetch-remove-group group)
6788    (when gnus-suppress-duplicates
6789      (gnus-dup-enter-articles))
6790    (when gnus-use-trees
6791      (gnus-tree-close group))
6792    (when gnus-use-cache
6793      (gnus-cache-write-active))
6794    ;; Remove entries for this group.
6795    (nnmail-purge-split-history (gnus-group-real-name group))
6796    ;; Make all changes in this group permanent.
6797    (unless quit-config
6798      (gnus-run-hooks 'gnus-exit-group-hook)
6799      (gnus-summary-update-info))
6800    (gnus-close-group group)
6801    ;; Make sure where we were, and go to next newsgroup.
6802    (set-buffer gnus-group-buffer)
6803    (unless quit-config
6804      (gnus-group-jump-to-group group))
6805    (gnus-run-hooks 'gnus-summary-exit-hook)
6806    (unless (or quit-config
6807		;; If this group has disappeared from the summary
6808		;; buffer, don't skip forwards.
6809		(not (string= group (gnus-group-group-name))))
6810      (gnus-group-next-unread-group 1))
6811    (setq group-point (point))
6812    (if temporary
6813	nil				;Nothing to do.
6814      ;; If we have several article buffers, we kill them at exit.
6815      (unless gnus-single-article-buffer
6816	(gnus-kill-buffer gnus-article-buffer)
6817	(gnus-kill-buffer gnus-original-article-buffer)
6818	(setq gnus-article-current nil))
6819      (set-buffer buf)
6820      (if (not gnus-kill-summary-on-exit)
6821	  (progn
6822	    (gnus-deaden-summary)
6823	    (setq mode nil))
6824	;; We set all buffer-local variables to nil.  It is unclear why
6825	;; this is needed, but if we don't, buffer-local variables are
6826	;; not garbage-collected, it seems.  This would the lead to en
6827	;; ever-growing Emacs.
6828	(gnus-summary-clear-local-variables)
6829	(let ((gnus-summary-local-variables gnus-newsgroup-variables))
6830	  (gnus-summary-clear-local-variables))
6831	(when (get-buffer gnus-article-buffer)
6832	  (bury-buffer gnus-article-buffer))
6833	;; We clear the global counterparts of the buffer-local
6834	;; variables as well, just to be on the safe side.
6835	(set-buffer gnus-group-buffer)
6836	(gnus-summary-clear-local-variables)
6837	(let ((gnus-summary-local-variables gnus-newsgroup-variables))
6838	  (gnus-summary-clear-local-variables))
6839	;; Return to group mode buffer.
6840	(when (eq mode 'gnus-summary-mode)
6841	  (gnus-kill-buffer buf)))
6842      (setq gnus-current-select-method gnus-select-method)
6843      (set-buffer gnus-group-buffer)
6844      (if quit-config
6845	  (gnus-handle-ephemeral-exit quit-config)
6846	(goto-char group-point)
6847	;; If gnus-group-buffer is already displayed, make sure we also move
6848	;; the cursor in the window that displays it.
6849	(let ((win (get-buffer-window (current-buffer) 0)))
6850	  (if win (set-window-point win (point))))
6851	(unless leave-hidden
6852	  (gnus-configure-windows 'group 'force)))
6853      ;; Clear the current group name.
6854      (unless quit-config
6855	(setq gnus-newsgroup-name nil)))))
6856
6857(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6858(defun gnus-summary-exit-no-update (&optional no-questions)
6859  "Quit reading current newsgroup without updating read article info."
6860  (interactive)
6861  (let* ((group gnus-newsgroup-name)
6862	 (gnus-group-is-exiting-p t)
6863	 (gnus-group-is-exiting-without-update-p t)
6864	 (quit-config (gnus-group-quit-config group)))
6865    (when (or no-questions
6866	      gnus-expert-user
6867	      (gnus-y-or-n-p "Discard changes to this group and exit? "))
6868      (gnus-async-halt-prefetch)
6869      (run-hooks 'gnus-summary-prepare-exit-hook)
6870      (when (gnus-buffer-live-p gnus-article-buffer)
6871	(save-excursion
6872	  (set-buffer gnus-article-buffer)
6873	  (mm-destroy-parts gnus-article-mime-handles)
6874	  ;; Set it to nil for safety reason.
6875	  (setq gnus-article-mime-handle-alist nil)
6876	  (setq gnus-article-mime-handles nil)))
6877      ;; If we have several article buffers, we kill them at exit.
6878      (unless gnus-single-article-buffer
6879	(gnus-kill-buffer gnus-article-buffer)
6880	(gnus-kill-buffer gnus-original-article-buffer)
6881	(setq gnus-article-current nil))
6882      (if (not gnus-kill-summary-on-exit)
6883	  (gnus-deaden-summary)
6884	(gnus-close-group group)
6885	(gnus-summary-clear-local-variables)
6886	(let ((gnus-summary-local-variables gnus-newsgroup-variables))
6887	  (gnus-summary-clear-local-variables))
6888	(set-buffer gnus-group-buffer)
6889	(gnus-summary-clear-local-variables)
6890	(let ((gnus-summary-local-variables gnus-newsgroup-variables))
6891	  (gnus-summary-clear-local-variables))
6892	(gnus-kill-buffer gnus-summary-buffer))
6893      (unless gnus-single-article-buffer
6894	(setq gnus-article-current nil))
6895      (when gnus-use-trees
6896	(gnus-tree-close group))
6897      (gnus-async-prefetch-remove-group group)
6898      (when (get-buffer gnus-article-buffer)
6899	(bury-buffer gnus-article-buffer))
6900      ;; Return to the group buffer.
6901      (gnus-configure-windows 'group 'force)
6902      ;; Clear the current group name.
6903      (setq gnus-newsgroup-name nil)
6904      (unless (gnus-ephemeral-group-p group)
6905	(gnus-group-update-group group))
6906      (when (equal (gnus-group-group-name) group)
6907	(gnus-group-next-unread-group 1))
6908      (when quit-config
6909	(gnus-handle-ephemeral-exit quit-config)))))
6910
6911(defun gnus-handle-ephemeral-exit (quit-config)
6912  "Handle movement when leaving an ephemeral group.
6913The state which existed when entering the ephemeral is reset."
6914  (if (not (buffer-name (car quit-config)))
6915      (gnus-configure-windows 'group 'force)
6916    (set-buffer (car quit-config))
6917    (cond ((eq major-mode 'gnus-summary-mode)
6918	   (gnus-set-global-variables))
6919	  ((eq major-mode 'gnus-article-mode)
6920	   (save-excursion
6921	     ;; The `gnus-summary-buffer' variable may point
6922	     ;; to the old summary buffer when using a single
6923	     ;; article buffer.
6924	     (unless (gnus-buffer-live-p gnus-summary-buffer)
6925	       (set-buffer gnus-group-buffer))
6926	     (set-buffer gnus-summary-buffer)
6927	     (gnus-set-global-variables))))
6928    (if (or (eq (cdr quit-config) 'article)
6929	    (eq (cdr quit-config) 'pick))
6930	(progn
6931	  ;; The current article may be from the ephemeral group
6932	  ;; thus it is best that we reload this article
6933	  ;;
6934	  ;; If we're exiting from a large digest, this can be
6935	  ;; extremely slow.  So, it's better not to reload it. -- jh.
6936	  ;;(gnus-summary-show-article)
6937	  (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6938	      (gnus-configure-windows 'pick 'force)
6939	    (gnus-configure-windows (cdr quit-config) 'force)))
6940      (gnus-configure-windows (cdr quit-config) 'force))
6941    (when (eq major-mode 'gnus-summary-mode)
6942      (gnus-summary-next-subject 1 nil t)
6943      (gnus-summary-recenter)
6944      (gnus-summary-position-point))))
6945
6946;;; Dead summaries.
6947
6948(defvar gnus-dead-summary-mode-map nil)
6949
6950(unless gnus-dead-summary-mode-map
6951  (setq gnus-dead-summary-mode-map (make-keymap))
6952  (suppress-keymap gnus-dead-summary-mode-map)
6953  (substitute-key-definition
6954   'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6955  (dolist (key '("\C-d" "\r" "\177" [delete]))
6956    (define-key gnus-dead-summary-mode-map
6957      key 'gnus-summary-wake-up-the-dead))
6958  (dolist (key '("q" "Q"))
6959    (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6960
6961(defvar gnus-dead-summary-mode nil
6962  "Minor mode for Gnus summary buffers.")
6963
6964(defun gnus-dead-summary-mode (&optional arg)
6965  "Minor mode for Gnus summary buffers."
6966  (interactive "P")
6967  (when (eq major-mode 'gnus-summary-mode)
6968    (make-local-variable 'gnus-dead-summary-mode)
6969    (setq gnus-dead-summary-mode
6970	  (if (null arg) (not gnus-dead-summary-mode)
6971	    (> (prefix-numeric-value arg) 0)))
6972    (when gnus-dead-summary-mode
6973      (gnus-add-minor-mode
6974       'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6975
6976(defun gnus-deaden-summary ()
6977  "Make the current summary buffer into a dead summary buffer."
6978  ;; Kill any previous dead summary buffer.
6979  (when (and gnus-dead-summary
6980	     (buffer-name gnus-dead-summary))
6981    (save-excursion
6982      (set-buffer gnus-dead-summary)
6983      (when gnus-dead-summary-mode
6984	(kill-buffer (current-buffer)))))
6985  ;; Make this the current dead summary.
6986  (setq gnus-dead-summary (current-buffer))
6987  (gnus-dead-summary-mode 1)
6988  (let ((name (buffer-name)))
6989    (when (string-match "Summary" name)
6990      (rename-buffer
6991       (concat (substring name 0 (match-beginning 0)) "Dead "
6992	       (substring name (match-beginning 0)))
6993       t)
6994      (bury-buffer))))
6995
6996(defun gnus-kill-or-deaden-summary (buffer)
6997  "Kill or deaden the summary BUFFER."
6998  (save-excursion
6999    (when (and (buffer-name buffer)
7000	       (not gnus-single-article-buffer))
7001      (save-excursion
7002	(set-buffer buffer)
7003	(gnus-kill-buffer gnus-article-buffer)
7004	(gnus-kill-buffer gnus-original-article-buffer)))
7005    (cond
7006     ;; Kill the buffer.
7007     (gnus-kill-summary-on-exit
7008      (when (and gnus-use-trees
7009		 (gnus-buffer-exists-p buffer))
7010	(save-excursion
7011	  (set-buffer buffer)
7012	  (gnus-tree-close gnus-newsgroup-name)))
7013      (gnus-kill-buffer buffer))
7014     ;; Deaden the buffer.
7015     ((gnus-buffer-exists-p buffer)
7016      (save-excursion
7017	(set-buffer buffer)
7018	(gnus-deaden-summary))))))
7019
7020(defun gnus-summary-wake-up-the-dead (&rest args)
7021  "Wake up the dead summary buffer."
7022  (interactive)
7023  (gnus-dead-summary-mode -1)
7024  (let ((name (buffer-name)))
7025    (when (string-match "Dead " name)
7026      (rename-buffer
7027       (concat (substring name 0 (match-beginning 0))
7028	       (substring name (match-end 0)))
7029       t)))
7030  (gnus-message 3 "This dead summary is now alive again"))
7031
7032;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7033(defun gnus-summary-fetch-faq (&optional faq-dir)
7034  "Fetch the FAQ for the current group.
7035If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7036in."
7037  (interactive
7038   (list
7039    (when current-prefix-arg
7040      (completing-read
7041       "FAQ dir: " (and (listp gnus-group-faq-directory)
7042			(mapcar (lambda (file) (list file))
7043				gnus-group-faq-directory))))))
7044  (let (gnus-faq-buffer)
7045    (when (setq gnus-faq-buffer
7046		(gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7047      (gnus-configure-windows 'summary-faq))))
7048
7049;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7050(defun gnus-summary-describe-group (&optional force)
7051  "Describe the current newsgroup."
7052  (interactive "P")
7053  (gnus-group-describe-group force gnus-newsgroup-name))
7054
7055(defun gnus-summary-describe-briefly ()
7056  "Describe summary mode commands briefly."
7057  (interactive)
7058  (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")))
7059
7060;; Walking around group mode buffer from summary mode.
7061
7062(defun gnus-summary-next-group (&optional no-article target-group backward)
7063  "Exit current newsgroup and then select next unread newsgroup.
7064If prefix argument NO-ARTICLE is non-nil, no article is selected
7065initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7066previous group instead."
7067  (interactive "P")
7068  ;; Stop pre-fetching.
7069  (gnus-async-halt-prefetch)
7070  (let ((current-group gnus-newsgroup-name)
7071	(current-buffer (current-buffer))
7072	entered)
7073    ;; First we semi-exit this group to update Xrefs and all variables.
7074    ;; We can't do a real exit, because the window conf must remain
7075    ;; the same in case the user is prompted for info, and we don't
7076    ;; want the window conf to change before that...
7077    (gnus-summary-exit t)
7078    (while (not entered)
7079      ;; Then we find what group we are supposed to enter.
7080      (set-buffer gnus-group-buffer)
7081      (gnus-group-jump-to-group current-group)
7082      (setq target-group
7083	    (or target-group
7084		(if (eq gnus-keep-same-level 'best)
7085		    (gnus-summary-best-group gnus-newsgroup-name)
7086		  (gnus-summary-search-group backward gnus-keep-same-level))))
7087      (if (not target-group)
7088	  ;; There are no further groups, so we return to the group
7089	  ;; buffer.
7090	  (progn
7091	    (gnus-message 5 "Returning to the group buffer")
7092	    (setq entered t)
7093	    (when (gnus-buffer-live-p current-buffer)
7094	      (set-buffer current-buffer)
7095	      (gnus-summary-exit))
7096	    (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7097	;; We try to enter the target group.
7098	(gnus-group-jump-to-group target-group)
7099	(let ((unreads (gnus-group-group-unread)))
7100	  (if (and (or (eq t unreads)
7101		       (and unreads (not (zerop unreads))))
7102 		   (gnus-summary-read-group
7103 		    target-group nil no-article
7104 		    (and (buffer-name current-buffer) current-buffer)
7105 		    nil backward))
7106	      (setq entered t)
7107	    (setq current-group target-group
7108		  target-group nil)))))))
7109
7110(defun gnus-summary-prev-group (&optional no-article)
7111  "Exit current newsgroup and then select previous unread newsgroup.
7112If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7113  (interactive "P")
7114  (gnus-summary-next-group no-article nil t))
7115
7116;; Walking around summary lines.
7117
7118(defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7119  "Go to the first subject satisfying any non-nil constraint.
7120If UNREAD is non-nil, the article should be unread.
7121If UNDOWNLOADED is non-nil, the article should be undownloaded.
7122If UNSEEN is non-nil, the article should be unseen.
7123Returns the article selected or nil if there are no matching articles."
7124  (interactive "P")
7125  (cond
7126   ;; Empty summary.
7127   ((null gnus-newsgroup-data)
7128    (gnus-message 3 "No articles in the group")
7129    nil)
7130   ;; Pick the first article.
7131   ((not (or unread undownloaded unseen))
7132    (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7133    (gnus-data-number (car gnus-newsgroup-data)))
7134   ;; Find the first unread article.
7135   (t
7136    (let ((data gnus-newsgroup-data))
7137      (while (and data
7138                  (let ((num (gnus-data-number (car data))))
7139                    (or (memq num gnus-newsgroup-unfetched)
7140                        (not (or (and unread
7141                                      (memq num gnus-newsgroup-unreads))
7142                                 (and undownloaded
7143                                      (memq num gnus-newsgroup-undownloaded))
7144                                 (and unseen
7145                                      (memq num gnus-newsgroup-unseen)))))))
7146        (setq data (cdr data)))
7147      (prog1
7148          (if data
7149              (progn
7150                (goto-char (gnus-data-pos (car data)))
7151                (gnus-data-number (car data)))
7152            (gnus-message 3 "No more%s articles"
7153                          (let* ((r (when unread " unread"))
7154                                 (d (when undownloaded " undownloaded"))
7155                                 (s (when unseen " unseen"))
7156                                 (l (delq nil (list r d s))))
7157                            (cond ((= 3 (length l))
7158                                   (concat r "," d ", or" s))
7159                                  ((= 2 (length l))
7160                                   (concat (car l) ", or" (cadr l)))
7161                                  ((= 1 (length l))
7162                                   (car l))
7163                                  (t
7164                                   ""))))
7165            nil
7166            )
7167        (gnus-summary-position-point))))))
7168
7169(defun gnus-summary-next-subject (n &optional unread dont-display)
7170  "Go to next N'th summary line.
7171If N is negative, go to the previous N'th subject line.
7172If UNREAD is non-nil, only unread articles are selected.
7173The difference between N and the actual number of steps taken is
7174returned."
7175  (interactive "p")
7176  (let ((backward (< n 0))
7177	(n (abs n)))
7178    (while (and (> n 0)
7179		(if backward
7180		    (gnus-summary-find-prev unread)
7181		  (gnus-summary-find-next unread)))
7182      (unless (zerop (setq n (1- n)))
7183	(gnus-summary-show-thread)))
7184    (when (/= 0 n)
7185      (gnus-message 7 "No more%s articles"
7186		    (if unread " unread" "")))
7187    (unless dont-display
7188      (gnus-summary-recenter)
7189      (gnus-summary-position-point))
7190    n))
7191
7192(defun gnus-summary-next-unread-subject (n)
7193  "Go to next N'th unread summary line."
7194  (interactive "p")
7195  (gnus-summary-next-subject n t))
7196
7197(defun gnus-summary-prev-subject (n &optional unread)
7198  "Go to previous N'th summary line.
7199If optional argument UNREAD is non-nil, only unread article is selected."
7200  (interactive "p")
7201  (gnus-summary-next-subject (- n) unread))
7202
7203(defun gnus-summary-prev-unread-subject (n)
7204  "Go to previous N'th unread summary line."
7205  (interactive "p")
7206  (gnus-summary-next-subject (- n) t))
7207
7208(defun gnus-summary-goto-subjects (articles)
7209  "Insert the subject header for ARTICLES in the current buffer."
7210  (save-excursion
7211    (dolist (article articles)
7212      (gnus-summary-goto-subject article t)))
7213  (gnus-summary-limit (append articles gnus-newsgroup-limit))
7214  (gnus-summary-position-point))
7215
7216(defun gnus-summary-goto-subject (article &optional force silent)
7217  "Go the subject line of ARTICLE.
7218If FORCE, also allow jumping to articles not currently shown."
7219  (interactive "nArticle number: ")
7220  (unless (numberp article)
7221    (error "Article %s is not a number" article))
7222  (let ((b (point))
7223	(data (gnus-data-find article)))
7224    ;; We read in the article if we have to.
7225    (and (not data)
7226	 force
7227	 (gnus-summary-insert-subject
7228	  article
7229	  (if (or (numberp force) (vectorp force)) force)
7230	  t)
7231	 (setq data (gnus-data-find article)))
7232    (goto-char b)
7233    (if (not data)
7234	(progn
7235	  (unless silent
7236	    (gnus-message 3 "Can't find article %d" article))
7237	  nil)
7238      (let ((pt (gnus-data-pos data)))
7239	(goto-char pt)
7240	(gnus-summary-set-article-display-arrow pt))
7241      (gnus-summary-position-point)
7242      article)))
7243
7244;; Walking around summary lines with displaying articles.
7245
7246(defun gnus-summary-expand-window (&optional arg)
7247  "Make the summary buffer take up the entire Emacs frame.
7248Given a prefix, will force an `article' buffer configuration."
7249  (interactive "P")
7250  (if arg
7251      (gnus-configure-windows 'article 'force)
7252    (gnus-configure-windows 'summary 'force)))
7253
7254(defun gnus-summary-display-article (article &optional all-header)
7255  "Display ARTICLE in article buffer."
7256  (when (gnus-buffer-live-p gnus-article-buffer)
7257    (with-current-buffer gnus-article-buffer
7258      (mm-enable-multibyte)))
7259  (gnus-set-global-variables)
7260  (when (gnus-buffer-live-p gnus-article-buffer)
7261    (with-current-buffer gnus-article-buffer
7262      (setq gnus-article-charset gnus-newsgroup-charset)
7263      (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7264      (mm-enable-multibyte)))
7265  (if (null article)
7266      nil
7267    (prog1
7268	(if gnus-summary-display-article-function
7269	    (funcall gnus-summary-display-article-function article all-header)
7270	  (gnus-article-prepare article all-header))
7271      (gnus-run-hooks 'gnus-select-article-hook)
7272      (when (and gnus-current-article
7273		 (not (zerop gnus-current-article)))
7274	(gnus-summary-goto-subject gnus-current-article))
7275      (gnus-summary-recenter)
7276      (when (and gnus-use-trees gnus-show-threads)
7277	(gnus-possibly-generate-tree article)
7278	(gnus-highlight-selected-tree article))
7279      ;; Successfully display article.
7280      (gnus-article-set-window-start
7281       (cdr (assq article gnus-newsgroup-bookmarks))))))
7282
7283(defun gnus-summary-select-article (&optional all-headers force pseudo article)
7284  "Select the current article.
7285If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7286non-nil, the article will be re-fetched even if it already present in
7287the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7288be displayed."
7289  ;; Make sure we are in the summary buffer to work around bbdb bug.
7290  (unless (eq major-mode 'gnus-summary-mode)
7291    (set-buffer gnus-summary-buffer))
7292  (let ((article (or article (gnus-summary-article-number)))
7293	(all-headers (not (not all-headers))) ;Must be t or nil.
7294	gnus-summary-display-article-function)
7295    (and (not pseudo)
7296	 (gnus-summary-article-pseudo-p article)
7297	 (error "This is a pseudo-article"))
7298    (save-excursion
7299      (set-buffer gnus-summary-buffer)
7300      (if (or (and gnus-single-article-buffer
7301		   (or (null gnus-current-article)
7302		       (null gnus-article-current)
7303		       (null (get-buffer gnus-article-buffer))
7304		       (not (eq article (cdr gnus-article-current)))
7305		       (not (equal (car gnus-article-current)
7306				   gnus-newsgroup-name))))
7307	      (and (not gnus-single-article-buffer)
7308		   (or (null gnus-current-article)
7309		       (not (eq gnus-current-article article))))
7310	      force)
7311	  ;; The requested article is different from the current article.
7312	  (progn
7313	    (gnus-summary-display-article article all-headers)
7314	    (when (gnus-buffer-live-p gnus-article-buffer)
7315	      (with-current-buffer gnus-article-buffer
7316		(if (not gnus-article-decoded-p) ;; a local variable
7317		    (mm-disable-multibyte))))
7318	    (gnus-article-set-window-start
7319	     (cdr (assq article gnus-newsgroup-bookmarks)))
7320	    article)
7321	'old))))
7322
7323(defun gnus-summary-force-verify-and-decrypt ()
7324  "Display buttons for signed/encrypted parts and verify/decrypt them."
7325  (interactive)
7326  (let ((mm-verify-option 'known)
7327	(mm-decrypt-option 'known)
7328	(gnus-article-emulate-mime t)
7329	(gnus-buttonized-mime-types (append (list "multipart/signed"
7330						  "multipart/encrypted")
7331					    gnus-buttonized-mime-types)))
7332    (gnus-summary-select-article nil 'force)))
7333
7334(defun gnus-summary-set-current-mark (&optional current-mark)
7335  "Obsolete function."
7336  nil)
7337
7338(defun gnus-summary-next-article (&optional unread subject backward push)
7339  "Select the next article.
7340If UNREAD, only unread articles are selected.
7341If SUBJECT, only articles with SUBJECT are selected.
7342If BACKWARD, the previous article is selected instead of the next."
7343  (interactive "P")
7344  ;; Make sure we are in the summary buffer.
7345  (unless (eq major-mode 'gnus-summary-mode)
7346    (set-buffer gnus-summary-buffer))
7347  (cond
7348   ;; Is there such an article?
7349   ((and (gnus-summary-search-forward unread subject backward)
7350	 (or (gnus-summary-display-article (gnus-summary-article-number))
7351	     (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7352    (gnus-summary-position-point))
7353   ;; If not, we try the first unread, if that is wanted.
7354   ((and subject
7355	 gnus-auto-select-same
7356	 (gnus-summary-first-unread-article))
7357    (gnus-summary-position-point)
7358    (gnus-message 6 "Wrapped"))
7359   ;; Try to get next/previous article not displayed in this group.
7360   ((and gnus-auto-extend-newsgroup
7361	 (not unread) (not subject))
7362    (gnus-summary-goto-article
7363     (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7364     nil (count-lines (point-min) (point))))
7365   ;; Go to next/previous group.
7366   (t
7367    (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7368      (gnus-summary-jump-to-group gnus-newsgroup-name))
7369    (let ((cmd last-command-char)
7370	  (point
7371	   (save-excursion
7372	     (set-buffer gnus-group-buffer)
7373	     (point)))
7374	  (group
7375	   (if (eq gnus-keep-same-level 'best)
7376	       (gnus-summary-best-group gnus-newsgroup-name)
7377	     (gnus-summary-search-group backward gnus-keep-same-level))))
7378      ;; For some reason, the group window gets selected.  We change
7379      ;; it back.
7380      (select-window (get-buffer-window (current-buffer)))
7381      ;; Select next unread newsgroup automagically.
7382      (cond
7383       ((or (not gnus-auto-select-next)
7384	    (not cmd))
7385	(gnus-message 7 "No more%s articles" (if unread " unread" "")))
7386       ((or (eq gnus-auto-select-next 'quietly)
7387	    (and (eq gnus-auto-select-next 'slightly-quietly)
7388		 push)
7389	    (and (eq gnus-auto-select-next 'almost-quietly)
7390		 (gnus-summary-last-article-p)))
7391	;; Select quietly.
7392	(if (gnus-ephemeral-group-p gnus-newsgroup-name)
7393	    (gnus-summary-exit)
7394	  (gnus-message 7 "No more%s articles (%s)..."
7395			(if unread " unread" "")
7396			(if group (concat "selecting " group)
7397			  "exiting"))
7398	  (gnus-summary-next-group nil group backward)))
7399       (t
7400	(when (gnus-key-press-event-p last-input-event)
7401	  (gnus-summary-walk-group-buffer
7402	   gnus-newsgroup-name cmd unread backward point))))))))
7403
7404(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7405  (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7406		      (?\C-p (gnus-group-prev-unread-group 1))))
7407	(cursor-in-echo-area t)
7408	keve key group ended prompt)
7409    (save-excursion
7410      (set-buffer gnus-group-buffer)
7411      (goto-char start)
7412      (setq group
7413	    (if (eq gnus-keep-same-level 'best)
7414		(gnus-summary-best-group gnus-newsgroup-name)
7415	      (gnus-summary-search-group backward gnus-keep-same-level))))
7416    (while (not ended)
7417      (setq prompt
7418	    (format
7419	     "No more%s articles%s " (if unread " unread" "")
7420	     (if (and group
7421		      (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7422		 (format " (Type %s for %s [%s])"
7423			 (single-key-description cmd)
7424			 (gnus-group-decoded-name group)
7425			 (car (gnus-gethash group gnus-newsrc-hashtb)))
7426	       (format " (Type %s to exit %s)"
7427		       (single-key-description cmd)
7428		       (gnus-group-decoded-name gnus-newsgroup-name)))))
7429      ;; Confirm auto selection.
7430      (setq key (car (setq keve (gnus-read-event-char prompt)))
7431	    ended t)
7432      (cond
7433       ((assq key keystrokes)
7434	(let ((obuf (current-buffer)))
7435	  (switch-to-buffer gnus-group-buffer)
7436	  (when group
7437	    (gnus-group-jump-to-group group))
7438	  (eval (cadr (assq key keystrokes)))
7439	  (setq group (gnus-group-group-name))
7440	  (switch-to-buffer obuf))
7441	(setq ended nil))
7442       ((equal key cmd)
7443	(if (or (not group)
7444		(gnus-ephemeral-group-p gnus-newsgroup-name))
7445	    (gnus-summary-exit)
7446	  (gnus-summary-next-group nil group backward)))
7447       (t
7448	(push (cdr keve) unread-command-events))))))
7449
7450(defun gnus-summary-next-unread-article ()
7451  "Select unread article after current one."
7452  (interactive)
7453  (gnus-summary-next-article
7454   (or (not (eq gnus-summary-goto-unread 'never))
7455       (gnus-summary-last-article-p (gnus-summary-article-number)))
7456   (and gnus-auto-select-same
7457	(gnus-summary-article-subject))))
7458
7459(defun gnus-summary-prev-article (&optional unread subject)
7460  "Select the article after the current one.
7461If UNREAD is non-nil, only unread articles are selected."
7462  (interactive "P")
7463  (gnus-summary-next-article unread subject t))
7464
7465(defun gnus-summary-prev-unread-article ()
7466  "Select unread article before current one."
7467  (interactive)
7468  (gnus-summary-prev-article
7469   (or (not (eq gnus-summary-goto-unread 'never))
7470       (gnus-summary-first-article-p (gnus-summary-article-number)))
7471   (and gnus-auto-select-same
7472	(gnus-summary-article-subject))))
7473
7474(defun gnus-summary-next-page (&optional lines circular stop)
7475  "Show next page of the selected article.
7476If at the end of the current article, select the next article.
7477LINES says how many lines should be scrolled up.
7478
7479If CIRCULAR is non-nil, go to the start of the article instead of
7480selecting the next article when reaching the end of the current
7481article.
7482
7483If STOP is non-nil, just stop when reaching the end of the message.
7484
7485Also see the variable `gnus-article-skip-boring'."
7486  (interactive "P")
7487  (setq gnus-summary-buffer (current-buffer))
7488  (gnus-set-global-variables)
7489  (let ((article (gnus-summary-article-number))
7490	(article-window (get-buffer-window gnus-article-buffer t))
7491	endp)
7492    ;; If the buffer is empty, we have no article.
7493    (unless article
7494      (error "No article to select"))
7495    (gnus-configure-windows 'article)
7496    (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7497	(if (and (eq gnus-summary-goto-unread 'never)
7498		 (not (gnus-summary-last-article-p article)))
7499	    (gnus-summary-next-article)
7500	  (gnus-summary-next-unread-article))
7501      (if (or (null gnus-current-article)
7502	      (null gnus-article-current)
7503	      (/= article (cdr gnus-article-current))
7504	      (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7505	  ;; Selected subject is different from current article's.
7506	  (gnus-summary-display-article article)
7507	(when article-window
7508	  (gnus-eval-in-buffer-window gnus-article-buffer
7509	    (setq endp (or (gnus-article-next-page lines)
7510			   (gnus-article-only-boring-p))))
7511	  (when endp
7512	    (cond (stop
7513		   (gnus-message 3 "End of message"))
7514		  (circular
7515		   (gnus-summary-beginning-of-article))
7516		  (lines
7517		   (gnus-message 3 "End of message"))
7518		  ((null lines)
7519		   (if (and (eq gnus-summary-goto-unread 'never)
7520			    (not (gnus-summary-last-article-p article)))
7521		       (gnus-summary-next-article)
7522		     (gnus-summary-next-unread-article))))))))
7523    (gnus-summary-recenter)
7524    (gnus-summary-position-point)))
7525
7526(defun gnus-summary-prev-page (&optional lines move)
7527  "Show previous page of selected article.
7528Argument LINES specifies lines to be scrolled down.
7529If MOVE, move to the previous unread article if point is at
7530the beginning of the buffer."
7531  (interactive "P")
7532  (let ((article (gnus-summary-article-number))
7533	(article-window (get-buffer-window gnus-article-buffer t))
7534	endp)
7535    (gnus-configure-windows 'article)
7536    (if (or (null gnus-current-article)
7537	    (null gnus-article-current)
7538	    (/= article (cdr gnus-article-current))
7539	    (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7540	;; Selected subject is different from current article's.
7541	(gnus-summary-display-article article)
7542      (gnus-summary-recenter)
7543      (when article-window
7544	(gnus-eval-in-buffer-window gnus-article-buffer
7545	  (setq endp (gnus-article-prev-page lines)))
7546	(when (and move endp)
7547	  (cond (lines
7548		 (gnus-message 3 "Beginning of message"))
7549		((null lines)
7550		 (if (and (eq gnus-summary-goto-unread 'never)
7551			  (not (gnus-summary-first-article-p article)))
7552		     (gnus-summary-prev-article)
7553		   (gnus-summary-prev-unread-article))))))))
7554  (gnus-summary-position-point))
7555
7556(defun gnus-summary-prev-page-or-article (&optional lines)
7557  "Show previous page of selected article.
7558Argument LINES specifies lines to be scrolled down.
7559If at the beginning of the article, go to the next article."
7560  (interactive "P")
7561  (gnus-summary-prev-page lines t))
7562
7563(defun gnus-summary-scroll-up (lines)
7564  "Scroll up (or down) one line current article.
7565Argument LINES specifies lines to be scrolled up (or down if negative)."
7566  (interactive "p")
7567  (gnus-configure-windows 'article)
7568  (gnus-summary-show-thread)
7569  (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7570    (gnus-eval-in-buffer-window gnus-article-buffer
7571      (cond ((> lines 0)
7572	     (when (gnus-article-next-page lines)
7573	       (gnus-message 3 "End of message")))
7574	    ((< lines 0)
7575	     (gnus-article-prev-page (- lines))))))
7576  (gnus-summary-recenter)
7577  (gnus-summary-position-point))
7578
7579(defun gnus-summary-scroll-down (lines)
7580  "Scroll down (or up) one line current article.
7581Argument LINES specifies lines to be scrolled down (or up if negative)."
7582  (interactive "p")
7583  (gnus-summary-scroll-up (- lines)))
7584
7585(defun gnus-summary-next-same-subject ()
7586  "Select next article which has the same subject as current one."
7587  (interactive)
7588  (gnus-summary-next-article nil (gnus-summary-article-subject)))
7589
7590(defun gnus-summary-prev-same-subject ()
7591  "Select previous article which has the same subject as current one."
7592  (interactive)
7593  (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7594
7595(defun gnus-summary-next-unread-same-subject ()
7596  "Select next unread article which has the same subject as current one."
7597  (interactive)
7598  (gnus-summary-next-article t (gnus-summary-article-subject)))
7599
7600(defun gnus-summary-prev-unread-same-subject ()
7601  "Select previous unread article which has the same subject as current one."
7602  (interactive)
7603  (gnus-summary-prev-article t (gnus-summary-article-subject)))
7604
7605(defun gnus-summary-first-unread-article ()
7606  "Select the first unread article.
7607Return nil if there are no unread articles."
7608  (interactive)
7609  (prog1
7610      (when (gnus-summary-first-subject t)
7611	(gnus-summary-show-thread)
7612	(gnus-summary-first-subject t)
7613	(gnus-summary-display-article (gnus-summary-article-number)))
7614    (gnus-summary-position-point)))
7615
7616(defun gnus-summary-first-unread-subject ()
7617  "Place the point on the subject line of the first unread article.
7618Return nil if there are no unread articles."
7619  (interactive)
7620  (prog1
7621      (when (gnus-summary-first-subject t)
7622	(gnus-summary-show-thread)
7623	(gnus-summary-first-subject t))
7624    (gnus-summary-position-point)))
7625
7626(defun gnus-summary-first-unseen-subject ()
7627  "Place the point on the subject line of the first unseen article.
7628Return nil if there are no unseen articles."
7629  (interactive)
7630  (prog1
7631      (when (gnus-summary-first-subject nil nil t)
7632	(gnus-summary-show-thread)
7633	(gnus-summary-first-subject nil nil t))
7634    (gnus-summary-position-point)))
7635
7636(defun gnus-summary-first-unseen-or-unread-subject ()
7637  "Place the point on the subject line of the first unseen article or,
7638if all article have been seen, on the subject line of the first unread
7639article."
7640  (interactive)
7641  (prog1
7642      (unless (when (gnus-summary-first-subject nil nil t)
7643		(gnus-summary-show-thread)
7644		(gnus-summary-first-subject nil nil t))
7645	(when (gnus-summary-first-subject t)
7646	  (gnus-summary-show-thread)
7647	  (gnus-summary-first-subject t)))
7648    (gnus-summary-position-point)))
7649
7650(defun gnus-summary-first-article ()
7651  "Select the first article.
7652Return nil if there are no articles."
7653  (interactive)
7654  (prog1
7655      (when (gnus-summary-first-subject)
7656	(gnus-summary-show-thread)
7657	(gnus-summary-first-subject)
7658	(gnus-summary-display-article (gnus-summary-article-number)))
7659    (gnus-summary-position-point)))
7660
7661(defun gnus-summary-best-unread-article (&optional arg)
7662  "Select the unread article with the highest score.
7663If given a prefix argument, select the next unread article that has a
7664score higher than the default score."
7665  (interactive "P")
7666  (let ((article (if arg
7667		     (gnus-summary-better-unread-subject)
7668		   (gnus-summary-best-unread-subject))))
7669    (if article
7670	(gnus-summary-goto-article article)
7671      (error "No unread articles"))))
7672
7673(defun gnus-summary-best-unread-subject ()
7674  "Select the unread subject with the highest score."
7675  (interactive)
7676  (let ((best -1000000)
7677	(data gnus-newsgroup-data)
7678	article score)
7679    (while data
7680      (and (gnus-data-unread-p (car data))
7681	   (> (setq score
7682		    (gnus-summary-article-score (gnus-data-number (car data))))
7683	      best)
7684	   (setq best score
7685		 article (gnus-data-number (car data))))
7686      (setq data (cdr data)))
7687    (when article
7688      (gnus-summary-goto-subject article))
7689    (gnus-summary-position-point)
7690    article))
7691
7692(defun gnus-summary-better-unread-subject ()
7693  "Select the first unread subject that has a score over the default score."
7694  (interactive)
7695  (let ((data gnus-newsgroup-data)
7696	article score)
7697    (while (and (setq article (gnus-data-number (car data)))
7698		(or (gnus-data-read-p (car data))
7699		    (not (> (gnus-summary-article-score article)
7700			    gnus-summary-default-score))))
7701      (setq data (cdr data)))
7702    (when article
7703      (gnus-summary-goto-subject article))
7704    (gnus-summary-position-point)
7705    article))
7706
7707(defun gnus-summary-last-subject ()
7708  "Go to the last displayed subject line in the group."
7709  (let ((article (gnus-data-number (car (gnus-data-list t)))))
7710    (when article
7711      (gnus-summary-goto-subject article))))
7712
7713(defun gnus-summary-goto-article (article &optional all-headers force)
7714  "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7715If ALL-HEADERS is non-nil, no header lines are hidden.
7716If FORCE, go to the article even if it isn't displayed.  If FORCE
7717is a number, it is the line the article is to be displayed on."
7718  (interactive
7719   (list
7720    (completing-read
7721     "Article number or Message-ID: "
7722     (mapcar (lambda (number) (list (int-to-string number)))
7723	     gnus-newsgroup-limit))
7724    current-prefix-arg
7725    t))
7726  (prog1
7727      (if (and (stringp article)
7728	       (string-match "@\\|%40" article))
7729	  (gnus-summary-refer-article article)
7730	(when (stringp article)
7731	  (setq article (string-to-number article)))
7732	(if (gnus-summary-goto-subject article force)
7733	    (gnus-summary-display-article article all-headers)
7734	  (gnus-message 4 "Couldn't go to article %s" article) nil))
7735    (gnus-summary-position-point)))
7736
7737(defun gnus-summary-goto-last-article ()
7738  "Go to the previously read article."
7739  (interactive)
7740  (prog1
7741      (when gnus-last-article
7742	(gnus-summary-goto-article gnus-last-article nil t))
7743    (gnus-summary-position-point)))
7744
7745(defun gnus-summary-pop-article (number)
7746  "Pop one article off the history and go to the previous.
7747NUMBER articles will be popped off."
7748  (interactive "p")
7749  (let (to)
7750    (setq gnus-newsgroup-history
7751	  (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7752    (if to
7753	(gnus-summary-goto-article (car to) nil t)
7754      (error "Article history empty")))
7755  (gnus-summary-position-point))
7756
7757;; Summary commands and functions for limiting the summary buffer.
7758
7759(defun gnus-summary-limit-to-articles (n)
7760  "Limit the summary buffer to the next N articles.
7761If not given a prefix, use the process marked articles instead."
7762  (interactive "P")
7763  (prog1
7764      (let ((articles (gnus-summary-work-articles n)))
7765	(setq gnus-newsgroup-processable nil)
7766	(gnus-summary-limit articles))
7767    (gnus-summary-position-point)))
7768
7769(defun gnus-summary-pop-limit (&optional total)
7770  "Restore the previous limit.
7771If given a prefix, remove all limits."
7772  (interactive "P")
7773  (when total
7774    (setq gnus-newsgroup-limits
7775	  (list (mapcar (lambda (h) (mail-header-number h))
7776			gnus-newsgroup-headers))))
7777  (unless gnus-newsgroup-limits
7778    (error "No limit to pop"))
7779  (prog1
7780      (gnus-summary-limit nil 'pop)
7781    (gnus-summary-position-point)))
7782
7783(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7784  "Limit the summary buffer to articles that have subjects that match a regexp.
7785If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7786  (interactive
7787   (list (read-string (if current-prefix-arg
7788			  "Exclude subject (regexp): "
7789			"Limit to subject (regexp): "))
7790	 nil current-prefix-arg))
7791  (unless header
7792    (setq header "subject"))
7793  (when (not (equal "" subject))
7794    (prog1
7795	(let ((articles (gnus-summary-find-matching
7796			 (or header "subject") subject 'all nil nil
7797			 not-matching)))
7798	  (unless articles
7799	    (error "Found no matches for \"%s\"" subject))
7800	  (gnus-summary-limit articles))
7801      (gnus-summary-position-point))))
7802
7803(defun gnus-summary-limit-to-author (from &optional not-matching)
7804  "Limit the summary buffer to articles that have authors that match a regexp.
7805If NOT-MATCHING, excluding articles that have authors that match a regexp."
7806  (interactive
7807   (list (read-string (if current-prefix-arg
7808			  "Exclude author (regexp): "
7809			"Limit to author (regexp): "))
7810	 current-prefix-arg))
7811  (gnus-summary-limit-to-subject from "from" not-matching))
7812
7813(defun gnus-summary-limit-to-age (age &optional younger-p)
7814  "Limit the summary buffer to articles that are older than (or equal) AGE days.
7815If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7816articles that are younger than AGE days."
7817  (interactive
7818   (let ((younger current-prefix-arg)
7819	 (days-got nil)
7820	 days)
7821     (while (not days-got)
7822       (setq days (if younger
7823		      (read-string "Limit to articles younger than (in days, older when negative): ")
7824		    (read-string
7825		     "Limit to articles older than (in days, younger when negative): ")))
7826       (when (> (length days) 0)
7827	 (setq days (read days)))
7828       (if (numberp days)
7829	   (progn
7830	     (setq days-got t)
7831	     (if (< days 0)
7832		 (progn
7833		   (setq younger (not younger))
7834		   (setq days (* days -1)))))
7835	 (message "Please enter a number.")
7836	 (sleep-for 1)))
7837     (list days younger)))
7838  (prog1
7839      (let ((data gnus-newsgroup-data)
7840	    (cutoff (days-to-time age))
7841	    articles d date is-younger)
7842	(while (setq d (pop data))
7843	  (when (and (vectorp (gnus-data-header d))
7844		     (setq date (mail-header-date (gnus-data-header d))))
7845	    (setq is-younger (time-less-p
7846			      (time-since (condition-case ()
7847					      (date-to-time date)
7848					    (error '(0 0))))
7849			      cutoff))
7850	    (when (if younger-p
7851		      is-younger
7852		    (not is-younger))
7853	      (push (gnus-data-number d) articles))))
7854	(gnus-summary-limit (nreverse articles)))
7855    (gnus-summary-position-point)))
7856
7857(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7858  "Limit the summary buffer to articles that match an 'extra' header."
7859  (interactive
7860   (let ((header
7861	  (intern
7862	   (gnus-completing-read-with-default
7863	    (symbol-name (car gnus-extra-headers))
7864	    (if current-prefix-arg
7865		"Exclude extra header"
7866	      "Limit extra header")
7867	    (mapcar (lambda (x)
7868		      (cons (symbol-name x) x))
7869		    gnus-extra-headers)
7870	    nil
7871	    t))))
7872     (list header
7873	   (read-string (format "%s header %s (regexp): "
7874				(if current-prefix-arg "Exclude" "Limit to")
7875				header))
7876	   current-prefix-arg)))
7877  (when (not (equal "" regexp))
7878    (prog1
7879	(let ((articles (gnus-summary-find-matching
7880			 (cons 'extra header) regexp 'all nil nil
7881			 not-matching)))
7882	  (unless articles
7883	    (error "Found no matches for \"%s\"" regexp))
7884	  (gnus-summary-limit articles))
7885      (gnus-summary-position-point))))
7886
7887(defun gnus-summary-limit-to-display-predicate ()
7888  "Limit the summary buffer to the predicated in the `display' group parameter."
7889  (interactive)
7890  (unless gnus-newsgroup-display
7891    (error "There is no `display' group parameter"))
7892  (let (articles)
7893    (dolist (number gnus-newsgroup-articles)
7894      (when (funcall gnus-newsgroup-display)
7895	(push number articles)))
7896    (gnus-summary-limit articles))
7897  (gnus-summary-position-point))
7898
7899(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7900(make-obsolete
7901 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7902
7903(defun gnus-summary-limit-to-unread (&optional all)
7904  "Limit the summary buffer to articles that are not marked as read.
7905If ALL is non-nil, limit strictly to unread articles."
7906  (interactive "P")
7907  (if all
7908      (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7909    (gnus-summary-limit-to-marks
7910     ;; Concat all the marks that say that an article is read and have
7911     ;; those removed.
7912     (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7913	   gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7914	   gnus-low-score-mark gnus-expirable-mark
7915	   gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7916	   gnus-duplicate-mark gnus-souped-mark)
7917     'reverse)))
7918
7919(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7920(make-obsolete 'gnus-summary-delete-marked-with
7921	       'gnus-summary-limit-exclude-marks)
7922
7923(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7924  "Exclude articles that are marked with MARKS (e.g. \"DK\").
7925If REVERSE, limit the summary buffer to articles that are marked
7926with MARKS.  MARKS can either be a string of marks or a list of marks.
7927Returns how many articles were removed."
7928  (interactive "sMarks: ")
7929  (gnus-summary-limit-to-marks marks t))
7930
7931(defun gnus-summary-limit-to-marks (marks &optional reverse)
7932  "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7933If REVERSE (the prefix), limit the summary buffer to articles that are
7934not marked with MARKS.  MARKS can either be a string of marks or a
7935list of marks.
7936Returns how many articles were removed."
7937  (interactive "sMarks: \nP")
7938  (prog1
7939      (let ((data gnus-newsgroup-data)
7940	    (marks (if (listp marks) marks
7941		     (append marks nil))) ; Transform to list.
7942	    articles)
7943	(while data
7944	  (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7945		  (memq (gnus-data-mark (car data)) marks))
7946	    (push (gnus-data-number (car data)) articles))
7947	  (setq data (cdr data)))
7948	(gnus-summary-limit articles))
7949    (gnus-summary-position-point)))
7950
7951(defun gnus-summary-limit-to-score (score)
7952  "Limit to articles with score at or above SCORE."
7953  (interactive "NLimit to articles with score of at least: ")
7954  (let ((data gnus-newsgroup-data)
7955	articles)
7956    (while data
7957      (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7958		score)
7959	(push (gnus-data-number (car data)) articles))
7960      (setq data (cdr data)))
7961    (prog1
7962	(gnus-summary-limit articles)
7963      (gnus-summary-position-point))))
7964
7965(defun gnus-summary-limit-to-unseen ()
7966  "Limit to unseen articles."
7967  (interactive)
7968  (prog1
7969      (gnus-summary-limit gnus-newsgroup-unseen)
7970    (gnus-summary-position-point)))
7971
7972(defun gnus-summary-limit-include-thread (id)
7973  "Display all the hidden articles that is in the thread with ID in it.
7974When called interactively, ID is the Message-ID of the current
7975article."
7976  (interactive (list (mail-header-id (gnus-summary-article-header))))
7977  (let ((articles (gnus-articles-in-thread
7978		   (gnus-id-to-thread (gnus-root-id id)))))
7979    (prog1
7980	(gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7981      (gnus-summary-limit-include-matching-articles
7982       "subject"
7983       (regexp-quote (gnus-simplify-subject-re
7984		      (mail-header-subject (gnus-id-to-header id)))))
7985      (gnus-summary-position-point))))
7986
7987(defun gnus-summary-limit-include-matching-articles (header regexp)
7988  "Display all the hidden articles that have HEADERs that match REGEXP."
7989  (interactive (list (read-string "Match on header: ")
7990		     (read-string "Regexp: ")))
7991  (let ((articles (gnus-find-matching-articles header regexp)))
7992    (prog1
7993	(gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7994      (gnus-summary-position-point))))
7995
7996(defun gnus-summary-insert-dormant-articles ()
7997  "Insert all the dormant articles for this group into the current buffer."
7998  (interactive)
7999  (let ((gnus-verbose (max 6 gnus-verbose)))
8000    (if (not gnus-newsgroup-dormant)
8001	(gnus-message 3 "No dormant articles for this group")
8002      (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8003
8004(defun gnus-summary-limit-include-dormant ()
8005  "Display all the hidden articles that are marked as dormant.
8006Note that this command only works on a subset of the articles currently
8007fetched for this group."
8008  (interactive)
8009  (unless gnus-newsgroup-dormant
8010    (error "There are no dormant articles in this group"))
8011  (prog1
8012      (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8013    (gnus-summary-position-point)))
8014
8015(defun gnus-summary-limit-exclude-dormant ()
8016  "Hide all dormant articles."
8017  (interactive)
8018  (prog1
8019      (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8020    (gnus-summary-position-point)))
8021
8022(defun gnus-summary-limit-exclude-childless-dormant ()
8023  "Hide all dormant articles that have no children."
8024  (interactive)
8025  (let ((data (gnus-data-list t))
8026	articles d children)
8027    ;; Find all articles that are either not dormant or have
8028    ;; children.
8029    (while (setq d (pop data))
8030      (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8031		(and (setq children
8032			   (gnus-article-children (gnus-data-number d)))
8033		     (let (found)
8034		       (while children
8035			 (when (memq (car children) articles)
8036			   (setq children nil
8037				 found t))
8038			 (pop children))
8039		       found)))
8040	(push (gnus-data-number d) articles)))
8041    ;; Do the limiting.
8042    (prog1
8043	(gnus-summary-limit articles)
8044      (gnus-summary-position-point))))
8045
8046(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8047  "Mark all unread excluded articles as read.
8048If ALL, mark even excluded ticked and dormants as read."
8049  (interactive "P")
8050  (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8051  (let ((articles (gnus-sorted-ndifference
8052		   (sort
8053		    (mapcar (lambda (h) (mail-header-number h))
8054			    gnus-newsgroup-headers)
8055		    '<)
8056		   gnus-newsgroup-limit))
8057	article)
8058    (setq gnus-newsgroup-unreads
8059	  (gnus-sorted-intersection gnus-newsgroup-unreads
8060				    gnus-newsgroup-limit))
8061    (if all
8062	(setq gnus-newsgroup-dormant nil
8063	      gnus-newsgroup-marked nil
8064	      gnus-newsgroup-reads
8065	      (nconc
8066	       (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8067	       gnus-newsgroup-reads))
8068      (while (setq article (pop articles))
8069	(unless (or (memq article gnus-newsgroup-dormant)
8070		    (memq article gnus-newsgroup-marked))
8071	  (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8072
8073(defun gnus-summary-limit (articles &optional pop)
8074  (if pop
8075      ;; We pop the previous limit off the stack and use that.
8076      (setq articles (car gnus-newsgroup-limits)
8077	    gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8078    ;; We use the new limit, so we push the old limit on the stack.
8079    (push gnus-newsgroup-limit gnus-newsgroup-limits))
8080  ;; Set the limit.
8081  (setq gnus-newsgroup-limit articles)
8082  (let ((total (length gnus-newsgroup-data))
8083	(data (gnus-data-find-list (gnus-summary-article-number)))
8084	(gnus-summary-mark-below nil)	; Inhibit this.
8085	found)
8086    ;; This will do all the work of generating the new summary buffer
8087    ;; according to the new limit.
8088    (gnus-summary-prepare)
8089    ;; Hide any threads, possibly.
8090    (gnus-summary-maybe-hide-threads)
8091    ;; Try to return to the article you were at, or one in the
8092    ;; neighborhood.
8093    (when data
8094      ;; We try to find some article after the current one.
8095      (while data
8096	(when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8097	  (setq data nil
8098		found t))
8099	(setq data (cdr data))))
8100    (unless found
8101      ;; If there is no data, that means that we were after the last
8102      ;; article.  The same goes when we can't find any articles
8103      ;; after the current one.
8104      (goto-char (point-max))
8105      (gnus-summary-find-prev))
8106    (gnus-set-mode-line 'summary)
8107    ;; We return how many articles were removed from the summary
8108    ;; buffer as a result of the new limit.
8109    (- total (length gnus-newsgroup-data))))
8110
8111(defsubst gnus-invisible-cut-children (threads)
8112  (let ((num 0))
8113    (while threads
8114      (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8115	(incf num))
8116      (pop threads))
8117    (< num 2)))
8118
8119(defsubst gnus-cut-thread (thread)
8120  "Go forwards in the thread until we find an article that we want to display."
8121  (when (or (eq gnus-fetch-old-headers 'some)
8122	    (eq gnus-fetch-old-headers 'invisible)
8123	    (numberp gnus-fetch-old-headers)
8124	    (eq gnus-build-sparse-threads 'some)
8125	    (eq gnus-build-sparse-threads 'more))
8126    ;; Deal with old-fetched headers and sparse threads.
8127    (while (and
8128	    thread
8129	    (or
8130	     (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8131	     (gnus-summary-article-ancient-p
8132	      (mail-header-number (car thread))))
8133	    (if (or (<= (length (cdr thread)) 1)
8134		    (eq gnus-fetch-old-headers 'invisible))
8135		(setq gnus-newsgroup-limit
8136		      (delq (mail-header-number (car thread))
8137			    gnus-newsgroup-limit)
8138		      thread (cadr thread))
8139	      (when (gnus-invisible-cut-children (cdr thread))
8140		(let ((th (cdr thread)))
8141		  (while th
8142		    (if (memq (mail-header-number (caar th))
8143			      gnus-newsgroup-limit)
8144			(setq thread (car th)
8145			      th nil)
8146		      (setq th (cdr th))))))))))
8147  thread)
8148
8149(defun gnus-cut-threads (threads)
8150  "Cut off all uninteresting articles from the beginning of THREADS."
8151  (when (or (eq gnus-fetch-old-headers 'some)
8152	    (eq gnus-fetch-old-headers 'invisible)
8153	    (numberp gnus-fetch-old-headers)
8154	    (eq gnus-build-sparse-threads 'some)
8155	    (eq gnus-build-sparse-threads 'more))
8156    (let ((th threads))
8157      (while th
8158	(setcar th (gnus-cut-thread (car th)))
8159	(setq th (cdr th)))))
8160  ;; Remove nixed out threads.
8161  (delq nil threads))
8162
8163(defun gnus-summary-initial-limit (&optional show-if-empty)
8164  "Figure out what the initial limit is supposed to be on group entry.
8165This entails weeding out unwanted dormants, low-scored articles,
8166fetch-old-headers verbiage, and so on."
8167  ;; Most groups have nothing to remove.
8168  (if (or gnus-inhibit-limiting
8169	  (and (null gnus-newsgroup-dormant)
8170	       (eq gnus-newsgroup-display 'gnus-not-ignore)
8171	       (not (eq gnus-fetch-old-headers 'some))
8172	       (not (numberp gnus-fetch-old-headers))
8173	       (not (eq gnus-fetch-old-headers 'invisible))
8174	       (null gnus-summary-expunge-below)
8175	       (not (eq gnus-build-sparse-threads 'some))
8176	       (not (eq gnus-build-sparse-threads 'more))
8177	       (null gnus-thread-expunge-below)
8178	       (not gnus-use-nocem)))
8179      ()				; Do nothing.
8180    (push gnus-newsgroup-limit gnus-newsgroup-limits)
8181    (setq gnus-newsgroup-limit nil)
8182    (mapatoms
8183     (lambda (node)
8184       (unless (car (symbol-value node))
8185	 ;; These threads have no parents -- they are roots.
8186	 (let ((nodes (cdr (symbol-value node)))
8187	       thread)
8188	   (while nodes
8189	     (if (and gnus-thread-expunge-below
8190		      (< (gnus-thread-total-score (car nodes))
8191			 gnus-thread-expunge-below))
8192		 (gnus-expunge-thread (pop nodes))
8193	       (setq thread (pop nodes))
8194	       (gnus-summary-limit-children thread))))))
8195     gnus-newsgroup-dependencies)
8196    ;; If this limitation resulted in an empty group, we might
8197    ;; pop the previous limit and use it instead.
8198    (when (and (not gnus-newsgroup-limit)
8199	       show-if-empty)
8200      (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8201    gnus-newsgroup-limit))
8202
8203(defun gnus-summary-limit-children (thread)
8204  "Return 1 if this subthread is visible and 0 if it is not."
8205  ;; First we get the number of visible children to this thread.  This
8206  ;; is done by recursing down the thread using this function, so this
8207  ;; will really go down to a leaf article first, before slowly
8208  ;; working its way up towards the root.
8209  (when thread
8210    (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8211	   (children
8212	   (if (cdr thread)
8213	       (apply '+ (mapcar 'gnus-summary-limit-children
8214				 (cdr thread)))
8215	     0))
8216	  (number (mail-header-number (car thread)))
8217	  score)
8218      (if (and
8219	   (not (memq number gnus-newsgroup-marked))
8220	   (or
8221	    ;; If this article is dormant and has absolutely no visible
8222	    ;; children, then this article isn't visible.
8223	    (and (memq number gnus-newsgroup-dormant)
8224		 (zerop children))
8225	    ;; If this is "fetch-old-headered" and there is no
8226	    ;; visible children, then we don't want this article.
8227	    (and (or (eq gnus-fetch-old-headers 'some)
8228		     (numberp gnus-fetch-old-headers))
8229		 (gnus-summary-article-ancient-p number)
8230		 (zerop children))
8231	    ;; If this is "fetch-old-headered" and `invisible', then
8232	    ;; we don't want this article.
8233	    (and (eq gnus-fetch-old-headers 'invisible)
8234		 (gnus-summary-article-ancient-p number))
8235	    ;; If this is a sparsely inserted article with no children,
8236	    ;; we don't want it.
8237	    (and (eq gnus-build-sparse-threads 'some)
8238		 (gnus-summary-article-sparse-p number)
8239		 (zerop children))
8240	    ;; If we use expunging, and this article is really
8241	    ;; low-scored, then we don't want this article.
8242	    (when (and gnus-summary-expunge-below
8243		       (< (setq score
8244				(or (cdr (assq number gnus-newsgroup-scored))
8245				    gnus-summary-default-score))
8246			  gnus-summary-expunge-below))
8247	      ;; We increase the expunge-tally here, but that has
8248	      ;; nothing to do with the limits, really.
8249	      (incf gnus-newsgroup-expunged-tally)
8250	      ;; We also mark as read here, if that's wanted.
8251	      (when (and gnus-summary-mark-below
8252			 (< score gnus-summary-mark-below))
8253		(setq gnus-newsgroup-unreads
8254		      (delq number gnus-newsgroup-unreads))
8255		(if gnus-newsgroup-auto-expire
8256		    (push number gnus-newsgroup-expirable)
8257		  (push (cons number gnus-low-score-mark)
8258			gnus-newsgroup-reads)))
8259	      t)
8260	    ;; Do the `display' group parameter.
8261	    (and gnus-newsgroup-display
8262		 (not (funcall gnus-newsgroup-display)))
8263	    ;; Check NoCeM things.
8264	    (if (and gnus-use-nocem
8265		     (gnus-nocem-unwanted-article-p
8266		      (mail-header-id (car thread))))
8267		(progn
8268		  (setq gnus-newsgroup-unreads
8269			(delq number gnus-newsgroup-unreads))
8270		  t))))
8271	  ;; Nope, invisible article.
8272	  0
8273	;; Ok, this article is to be visible, so we add it to the limit
8274	;; and return 1.
8275	(push number gnus-newsgroup-limit)
8276	1))))
8277
8278(defun gnus-expunge-thread (thread)
8279  "Mark all articles in THREAD as read."
8280  (let* ((number (mail-header-number (car thread))))
8281    (incf gnus-newsgroup-expunged-tally)
8282    ;; We also mark as read here, if that's wanted.
8283    (setq gnus-newsgroup-unreads
8284	  (delq number gnus-newsgroup-unreads))
8285    (if gnus-newsgroup-auto-expire
8286	(push number gnus-newsgroup-expirable)
8287      (push (cons number gnus-low-score-mark)
8288	    gnus-newsgroup-reads)))
8289  ;; Go recursively through all subthreads.
8290  (mapcar 'gnus-expunge-thread (cdr thread)))
8291
8292;; Summary article oriented commands
8293
8294(defun gnus-summary-refer-parent-article (n)
8295  "Refer parent article N times.
8296If N is negative, go to ancestor -N instead.
8297The difference between N and the number of articles fetched is returned."
8298  (interactive "p")
8299  (let ((skip 1)
8300	error header ref)
8301    (when (not (natnump n))
8302      (setq skip (abs n)
8303	    n 1))
8304    (while (and (> n 0)
8305		(not error))
8306      (setq header (gnus-summary-article-header))
8307      (if (and (eq (mail-header-number header)
8308		   (cdr gnus-article-current))
8309	       (equal gnus-newsgroup-name
8310		      (car gnus-article-current)))
8311	  ;; If we try to find the parent of the currently
8312	  ;; displayed article, then we take a look at the actual
8313	  ;; References header, since this is slightly more
8314	  ;; reliable than the References field we got from the
8315	  ;; server.
8316	  (save-excursion
8317	    (set-buffer gnus-original-article-buffer)
8318	    (nnheader-narrow-to-headers)
8319	    (unless (setq ref (message-fetch-field "references"))
8320	      (when (setq ref (message-fetch-field "in-reply-to"))
8321		(setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8322	    (widen))
8323	(setq ref
8324	      ;; It's not the current article, so we take a bet on
8325	      ;; the value we got from the server.
8326	      (mail-header-references header)))
8327      (if (and ref
8328	       (not (equal ref "")))
8329	  (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8330	    (gnus-message 1 "Couldn't find parent"))
8331	(gnus-message 1 "No references in article %d"
8332		      (gnus-summary-article-number))
8333	(setq error t))
8334      (decf n))
8335    (gnus-summary-position-point)
8336    n))
8337
8338(defun gnus-summary-refer-references ()
8339  "Fetch all articles mentioned in the References header.
8340Return the number of articles fetched."
8341  (interactive)
8342  (let ((ref (mail-header-references (gnus-summary-article-header)))
8343	(current (gnus-summary-article-number))
8344	(n 0))
8345    (if (or (not ref)
8346	    (equal ref ""))
8347	(error "No References in the current article")
8348      ;; For each Message-ID in the References header...
8349      (while (string-match "<[^>]*>" ref)
8350	(incf n)
8351	;; ... fetch that article.
8352	(gnus-summary-refer-article
8353	 (prog1 (match-string 0 ref)
8354	   (setq ref (substring ref (match-end 0))))))
8355      (gnus-summary-goto-subject current)
8356      (gnus-summary-position-point)
8357      n)))
8358
8359(defun gnus-summary-refer-thread (&optional limit)
8360  "Fetch all articles in the current thread.
8361If LIMIT (the numerical prefix), fetch that many old headers instead
8362of what's specified by the `gnus-refer-thread-limit' variable."
8363  (interactive "P")
8364  (let ((id (mail-header-id (gnus-summary-article-header)))
8365	(limit (if limit (prefix-numeric-value limit)
8366		 gnus-refer-thread-limit)))
8367    (unless (eq gnus-fetch-old-headers 'invisible)
8368      (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8369      ;; Retrieve the headers and read them in.
8370      (if (eq (if (numberp limit)
8371		  (gnus-retrieve-headers
8372		   (list (min
8373			  (+ (mail-header-number
8374			      (gnus-summary-article-header))
8375			     limit)
8376			  gnus-newsgroup-end))
8377		   gnus-newsgroup-name (* limit 2))
8378		;; gnus-refer-thread-limit is t, i.e. fetch _all_
8379		;; headers.
8380		(gnus-retrieve-headers (list gnus-newsgroup-end)
8381				       gnus-newsgroup-name limit))
8382	      'nov)
8383	  (gnus-build-all-threads)
8384	(error "Can't fetch thread from back ends that don't support NOV"))
8385      (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8386    (gnus-summary-limit-include-thread id)))
8387
8388(defun gnus-summary-refer-article (message-id)
8389  "Fetch an article specified by MESSAGE-ID."
8390  (interactive "sMessage-ID: ")
8391  (when (and (stringp message-id)
8392	     (not (zerop (length message-id))))
8393    (setq message-id (gnus-replace-in-string message-id " " ""))
8394    ;; Construct the correct Message-ID if necessary.
8395    ;; Suggested by tale@pawl.rpi.edu.
8396    (unless (string-match "^<" message-id)
8397      (setq message-id (concat "<" message-id)))
8398    (unless (string-match ">$" message-id)
8399      (setq message-id (concat message-id ">")))
8400    ;; People often post MIDs from URLs, so unhex it:
8401    (unless (string-match "@" message-id)
8402      (setq message-id (gnus-url-unhex-string message-id)))
8403    (let* ((header (gnus-id-to-header message-id))
8404	   (sparse (and header
8405			(gnus-summary-article-sparse-p
8406			 (mail-header-number header))
8407			(memq (mail-header-number header)
8408			      gnus-newsgroup-limit)))
8409	   number)
8410      (cond
8411       ;; If the article is present in the buffer we just go to it.
8412       ((and header
8413	     (or (not (gnus-summary-article-sparse-p
8414		       (mail-header-number header)))
8415		 sparse))
8416	(prog1
8417	    (gnus-summary-goto-article
8418	     (mail-header-number header) nil t)
8419	  (when sparse
8420	    (gnus-summary-update-article (mail-header-number header)))))
8421       (t
8422	;; We fetch the article.
8423	(catch 'found
8424	  (dolist (gnus-override-method (gnus-refer-article-methods))
8425	    (when (and (gnus-check-server gnus-override-method)
8426		       ;; Fetch the header,
8427		       (setq number (gnus-summary-insert-subject message-id)))
8428	      ;; and display the article.
8429	      (gnus-summary-select-article nil nil nil number)
8430	      (throw 'found t)))
8431	  (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8432
8433(defun gnus-refer-article-methods ()
8434  "Return a list of referable methods."
8435  (cond
8436   ;; No method, so we default to current and native.
8437   ((null gnus-refer-article-method)
8438    (list gnus-current-select-method gnus-select-method))
8439   ;; Current.
8440   ((eq 'current gnus-refer-article-method)
8441    (list gnus-current-select-method))
8442   ;; List of select methods.
8443   ((not (and (symbolp (car gnus-refer-article-method))
8444	      (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8445    (let (out)
8446      (dolist (method gnus-refer-article-method)
8447	(push (if (eq 'current method)
8448		  gnus-current-select-method
8449		method)
8450	      out))
8451      (nreverse out)))
8452   ;; One single select method.
8453   (t
8454    (list gnus-refer-article-method))))
8455
8456(defun gnus-summary-edit-parameters ()
8457  "Edit the group parameters of the current group."
8458  (interactive)
8459  (gnus-group-edit-group gnus-newsgroup-name 'params))
8460
8461(defun gnus-summary-customize-parameters ()
8462  "Customize the group parameters of the current group."
8463  (interactive)
8464  (gnus-group-customize gnus-newsgroup-name))
8465
8466(defun gnus-summary-enter-digest-group (&optional force)
8467  "Enter an nndoc group based on the current article.
8468If FORCE, force a digest interpretation.  If not, try
8469to guess what the document format is."
8470  (interactive "P")
8471  (let ((conf gnus-current-window-configuration))
8472    (save-window-excursion
8473      (save-excursion
8474	(let (gnus-article-prepare-hook
8475	      gnus-display-mime-function
8476	      gnus-break-pages)
8477	  (gnus-summary-select-article))))
8478    (setq gnus-current-window-configuration conf)
8479    (let* ((name (format "%s-%d"
8480			 (gnus-group-prefixed-name
8481			  gnus-newsgroup-name (list 'nndoc ""))
8482			 (save-excursion
8483			   (set-buffer gnus-summary-buffer)
8484			   gnus-current-article)))
8485	   (ogroup gnus-newsgroup-name)
8486	   (params (append (gnus-info-params (gnus-get-info ogroup))
8487			   (list (cons 'to-group ogroup))
8488			   (list (cons 'parent-group ogroup))
8489			   (list (cons 'save-article-group ogroup))))
8490	   (case-fold-search t)
8491	   (buf (current-buffer))
8492	   dig to-address)
8493      (save-excursion
8494	(set-buffer gnus-original-article-buffer)
8495	;; Have the digest group inherit the main mail address of
8496	;; the parent article.
8497	(when (setq to-address (or (gnus-fetch-field "reply-to")
8498				   (gnus-fetch-field "from")))
8499	  (setq params
8500		(append
8501		 (list (cons 'to-address
8502			     (funcall gnus-decode-encoded-address-function
8503				      to-address))))))
8504	(setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8505	(insert-buffer-substring gnus-original-article-buffer)
8506	;; Remove lines that may lead nndoc to misinterpret the
8507	;; document type.
8508	(narrow-to-region
8509	 (goto-char (point-min))
8510	 (or (search-forward "\n\n" nil t) (point)))
8511	(goto-char (point-min))
8512	(delete-matching-lines "^Path:\\|^From ")
8513	(widen))
8514      (unwind-protect
8515	  (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8516		    (gnus-newsgroup-ephemeral-ignored-charsets
8517		     gnus-newsgroup-ignored-charsets))
8518		(gnus-group-read-ephemeral-group
8519		 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8520			      (nndoc-article-type
8521			       ,(if force 'mbox 'guess)))
8522		 t nil nil nil
8523		 `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8524							"ADAPT")))))
8525	      ;; Make all postings to this group go to the parent group.
8526	      (nconc (gnus-info-params (gnus-get-info name))
8527		     params)
8528	    ;; Couldn't select this doc group.
8529	    (switch-to-buffer buf)
8530	    (gnus-set-global-variables)
8531	    (gnus-configure-windows 'summary)
8532	    (gnus-message 3 "Article couldn't be entered?"))
8533	(kill-buffer dig)))))
8534
8535(defun gnus-summary-read-document (n)
8536  "Open a new group based on the current article(s).
8537This will allow you to read digests and other similar
8538documents as newsgroups.
8539Obeys the standard process/prefix convention."
8540  (interactive "P")
8541  (let* ((articles (gnus-summary-work-articles n))
8542	 (ogroup gnus-newsgroup-name)
8543	 (params (append (gnus-info-params (gnus-get-info ogroup))
8544			 (list (cons 'to-group ogroup))))
8545	 article group egroup groups vgroup)
8546    (while (setq article (pop articles))
8547      (setq group (format "%s-%d" gnus-newsgroup-name article))
8548      (gnus-summary-remove-process-mark article)
8549      (when (gnus-summary-display-article article)
8550	(save-excursion
8551	  (with-temp-buffer
8552	    (insert-buffer-substring gnus-original-article-buffer)
8553	    ;; Remove some headers that may lead nndoc to make
8554	    ;; the wrong guess.
8555	    (message-narrow-to-head)
8556	    (goto-char (point-min))
8557	    (delete-matching-lines "^\\(Path\\):\\|^From ")
8558	    (widen)
8559	    (if (setq egroup
8560		      (gnus-group-read-ephemeral-group
8561		       group `(nndoc ,group (nndoc-address ,(current-buffer))
8562				     (nndoc-article-type guess))
8563		       t nil t))
8564		(progn
8565	    ;; Make all postings to this group go to the parent group.
8566		  (nconc (gnus-info-params (gnus-get-info egroup))
8567			 params)
8568		  (push egroup groups))
8569	      ;; Couldn't select this doc group.
8570	      (gnus-error 3 "Article couldn't be entered"))))))
8571    ;; Now we have selected all the documents.
8572    (cond
8573     ((not groups)
8574      (error "None of the articles could be interpreted as documents"))
8575     ((gnus-group-read-ephemeral-group
8576       (setq vgroup (format
8577		     "nnvirtual:%s-%s" gnus-newsgroup-name
8578		     (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8579       `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8580       t
8581       (cons (current-buffer) 'summary)))
8582     (t
8583      (error "Couldn't select virtual nndoc group")))))
8584
8585(defun gnus-summary-isearch-article (&optional regexp-p)
8586  "Do incremental search forward on the current article.
8587If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8588  (interactive "P")
8589  (gnus-summary-select-article)
8590  (gnus-configure-windows 'article)
8591  (gnus-eval-in-buffer-window gnus-article-buffer
8592    (save-restriction
8593      (widen)
8594      (isearch-forward regexp-p))))
8595
8596(defun gnus-summary-search-article-forward (regexp &optional backward)
8597  "Search for an article containing REGEXP forward.
8598If BACKWARD, search backward instead."
8599  (interactive
8600   (list (read-string
8601	  (format "Search article %s (regexp%s): "
8602		  (if current-prefix-arg "backward" "forward")
8603		  (if gnus-last-search-regexp
8604		      (concat ", default " gnus-last-search-regexp)
8605		    "")))
8606	 current-prefix-arg))
8607  (if (string-equal regexp "")
8608      (setq regexp (or gnus-last-search-regexp ""))
8609    (setq gnus-last-search-regexp regexp)
8610    (setq gnus-article-before-search gnus-current-article))
8611  ;; Intentionally set gnus-last-article.
8612  (setq gnus-last-article gnus-article-before-search)
8613  (let ((gnus-last-article gnus-last-article))
8614    (if (gnus-summary-search-article regexp backward)
8615	(gnus-summary-show-thread)
8616      (signal 'search-failed (list regexp)))))
8617
8618(defun gnus-summary-search-article-backward (regexp)
8619  "Search for an article containing REGEXP backward."
8620  (interactive
8621   (list (read-string
8622	  (format "Search article backward (regexp%s): "
8623		  (if gnus-last-search-regexp
8624		      (concat ", default " gnus-last-search-regexp)
8625		    "")))))
8626  (gnus-summary-search-article-forward regexp 'backward))
8627
8628(defun gnus-summary-search-article (regexp &optional backward)
8629  "Search for an article containing REGEXP.
8630Optional argument BACKWARD means do search for backward.
8631`gnus-select-article-hook' is not called during the search."
8632  ;; We have to require this here to make sure that the following
8633  ;; dynamic binding isn't shadowed by autoloading.
8634  (require 'gnus-async)
8635  (require 'gnus-art)
8636  (let ((gnus-select-article-hook nil)	;Disable hook.
8637	(gnus-article-prepare-hook nil)
8638	(gnus-mark-article-hook nil)	;Inhibit marking as read.
8639	(gnus-use-article-prefetch nil)
8640	(gnus-xmas-force-redisplay nil)	;Inhibit XEmacs redisplay.
8641	(gnus-use-trees nil)		;Inhibit updating tree buffer.
8642	(gnus-visual nil)
8643	(gnus-keep-backlog nil)
8644	(gnus-break-pages nil)
8645	(gnus-summary-display-arrow nil)
8646	(gnus-updated-mode-lines nil)
8647	(gnus-auto-center-summary nil)
8648	(sum (current-buffer))
8649	(gnus-display-mime-function nil)
8650	(found nil)
8651	point)
8652    (gnus-save-hidden-threads
8653      (gnus-summary-select-article)
8654      (set-buffer gnus-article-buffer)
8655      (goto-char (window-point (get-buffer-window (current-buffer))))
8656      (when backward
8657	(forward-line -1))
8658      (while (not found)
8659	(gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8660	(if (if backward
8661		(re-search-backward regexp nil t)
8662	      (re-search-forward regexp nil t))
8663	    ;; We found the regexp.
8664	    (progn
8665	      (setq found 'found)
8666	      (beginning-of-line)
8667	      (set-window-start
8668	       (get-buffer-window (current-buffer))
8669	       (point))
8670	      (forward-line 1)
8671	      (set-window-point
8672	       (get-buffer-window (current-buffer))
8673	       (point))
8674	      (set-buffer sum)
8675	      (setq point (point)))
8676	  ;; We didn't find it, so we go to the next article.
8677	  (set-buffer sum)
8678	  (setq found 'not)
8679	  (while (eq found 'not)
8680	    (if (not (if backward (gnus-summary-find-prev)
8681		       (gnus-summary-find-next)))
8682		;; No more articles.
8683		(setq found t)
8684	      ;; Select the next article and adjust point.
8685	      (unless (gnus-summary-article-sparse-p
8686		       (gnus-summary-article-number))
8687		(setq found nil)
8688		(gnus-summary-select-article)
8689		(set-buffer gnus-article-buffer)
8690		(widen)
8691		(goto-char (if backward (point-max) (point-min))))))))
8692      (gnus-message 7 ""))
8693    ;; Return whether we found the regexp.
8694    (when (eq found 'found)
8695      (goto-char point)
8696      (gnus-summary-show-thread)
8697      (gnus-summary-goto-subject gnus-current-article)
8698      (gnus-summary-position-point)
8699      t)))
8700
8701(defun gnus-find-matching-articles (header regexp)
8702  "Return a list of all articles that match REGEXP on HEADER.
8703This search includes all articles in the current group that Gnus has
8704fetched headers for, whether they are displayed or not."
8705  (let ((articles nil)
8706	(func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8707	(case-fold-search t))
8708    (dolist (header gnus-newsgroup-headers)
8709      (when (string-match regexp (funcall func header))
8710	(push (mail-header-number header) articles)))
8711    (nreverse articles)))
8712
8713(defun gnus-summary-find-matching (header regexp &optional backward unread
8714					  not-case-fold not-matching)
8715  "Return a list of all articles that match REGEXP on HEADER.
8716The search stars on the current article and goes forwards unless
8717BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8718If UNREAD is non-nil, only unread articles will
8719be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8720in the comparisons. If NOT-MATCHING, return a list of all articles that
8721not match REGEXP on HEADER."
8722  (let ((case-fold-search (not not-case-fold))
8723	articles d func)
8724    (if (consp header)
8725	(if (eq (car header) 'extra)
8726	    (setq func
8727		  `(lambda (h)
8728		     (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8729			 "")))
8730	  (error "%s is an invalid header" header))
8731      (unless (fboundp (intern (concat "mail-header-" header)))
8732	(error "%s is not a valid header" header))
8733      (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8734    (dolist (d (if (eq backward 'all)
8735		   gnus-newsgroup-data
8736		 (gnus-data-find-list
8737		  (gnus-summary-article-number)
8738		  (gnus-data-list backward))))
8739      (when (and (or (not unread)	; We want all articles...
8740		     (gnus-data-unread-p d)) ; Or just unreads.
8741		 (vectorp (gnus-data-header d)) ; It's not a pseudo.
8742		 (if not-matching
8743		     (not (string-match
8744			   regexp
8745			   (funcall func (gnus-data-header d))))
8746		   (string-match regexp
8747				 (funcall func (gnus-data-header d)))))
8748	(push (gnus-data-number d) articles))) ; Success!
8749    (nreverse articles)))
8750
8751(defun gnus-summary-execute-command (header regexp command &optional backward)
8752  "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8753If HEADER is an empty string (or nil), the match is done on the entire
8754article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8755  (interactive
8756   (list (let ((completion-ignore-case t))
8757	   (completing-read
8758	    "Header name: "
8759	    (mapcar (lambda (header) (list (format "%s" header)))
8760		    (append
8761		     '("Number" "Subject" "From" "Lines" "Date"
8762		       "Message-ID" "Xref" "References" "Body")
8763		     gnus-extra-headers))
8764	    nil 'require-match))
8765	 (read-string "Regexp: ")
8766	 (read-key-sequence "Command: ")
8767	 current-prefix-arg))
8768  (when (equal header "Body")
8769    (setq header ""))
8770  ;; Hidden thread subtrees must be searched as well.
8771  (gnus-summary-show-all-threads)
8772  ;; We don't want to change current point nor window configuration.
8773  (save-excursion
8774    (save-window-excursion
8775      (let (gnus-visual
8776	    gnus-treat-strip-trailing-blank-lines
8777	    gnus-treat-strip-leading-blank-lines
8778	    gnus-treat-strip-multiple-blank-lines
8779	    gnus-treat-hide-boring-headers
8780	    gnus-treat-fold-newsgroups
8781	    gnus-article-prepare-hook)
8782	(gnus-message 6 "Executing %s..." (key-description command))
8783	;; We'd like to execute COMMAND interactively so as to give arguments.
8784	(gnus-execute header regexp
8785		      `(call-interactively ',(key-binding command))
8786		      backward)
8787	(gnus-message 6 "Executing %s...done" (key-description command))))))
8788
8789(defun gnus-summary-beginning-of-article ()
8790  "Scroll the article back to the beginning."
8791  (interactive)
8792  (gnus-summary-select-article)
8793  (gnus-configure-windows 'article)
8794  (gnus-eval-in-buffer-window gnus-article-buffer
8795    (widen)
8796    (goto-char (point-min))
8797    (when gnus-break-pages
8798      (gnus-narrow-to-page))))
8799
8800(defun gnus-summary-end-of-article ()
8801  "Scroll to the end of the article."
8802  (interactive)
8803  (gnus-summary-select-article)
8804  (gnus-configure-windows 'article)
8805  (gnus-eval-in-buffer-window gnus-article-buffer
8806    (widen)
8807    (goto-char (point-max))
8808    (recenter -3)
8809    (when gnus-break-pages
8810      (when (re-search-backward page-delimiter nil t)
8811	(narrow-to-region (match-end 0) (point-max)))
8812      (gnus-narrow-to-page))))
8813
8814(defun gnus-summary-print-truncate-and-quote (string &optional len)
8815  "Truncate to LEN and quote all \"(\"'s in STRING."
8816  (gnus-replace-in-string (if (and len (> (length string) len))
8817			      (substring string 0 len)
8818			    string)
8819			  "[()]" "\\\\\\&"))
8820
8821(defun gnus-summary-print-article (&optional filename n)
8822  "Generate and print a PostScript image of the process-marked (mail) articles.
8823
8824If used interactively, print the current article if none are
8825process-marked.  With prefix arg, prompt the user for the name of the
8826file to save in.
8827
8828When used from Lisp, accept two optional args FILENAME and N.  N means
8829to print the next N articles.  If N is negative, print the N previous
8830articles.  If N is nil and articles have been marked with the process
8831mark, print these instead.
8832
8833If the optional first argument FILENAME is nil, send the image to the
8834printer.  If FILENAME is a string, save the PostScript image in a file with
8835that name.  If FILENAME is a number, prompt the user for the name of the file
8836to save in."
8837  (interactive (list (ps-print-preprint current-prefix-arg)))
8838  (dolist (article (gnus-summary-work-articles n))
8839    (gnus-summary-select-article nil nil 'pseudo article)
8840    (gnus-eval-in-buffer-window gnus-article-buffer
8841      (gnus-print-buffer))
8842    (gnus-summary-remove-process-mark article))
8843  (ps-despool filename))
8844
8845(defun gnus-print-buffer ()
8846  (let ((buffer (generate-new-buffer " *print*")))
8847    (unwind-protect
8848	(progn
8849	  (copy-to-buffer buffer (point-min) (point-max))
8850	  (set-buffer buffer)
8851	  (gnus-remove-text-with-property 'gnus-decoration)
8852	  (when (gnus-visual-p 'article-highlight 'highlight)
8853	    ;; Copy-to-buffer doesn't copy overlay.  So redo
8854	    ;; highlight.
8855	    (let ((gnus-article-buffer buffer))
8856	      (gnus-article-highlight-citation t)
8857	      (gnus-article-highlight-signature)
8858	      (gnus-article-emphasize)
8859	      (gnus-article-delete-invisible-text)))
8860	  (let ((ps-left-header
8861		 (list
8862		  (concat "("
8863			  (gnus-summary-print-truncate-and-quote
8864			   (mail-header-subject gnus-current-headers)
8865			   66) ")")
8866		  (concat "("
8867			  (gnus-summary-print-truncate-and-quote
8868			   (mail-header-from gnus-current-headers)
8869			   45) ")")))
8870		(ps-right-header
8871		 (list
8872		  "/pagenumberstring load"
8873		  (concat "("
8874			  (mail-header-date gnus-current-headers) ")"))))
8875	    (gnus-run-hooks 'gnus-ps-print-hook)
8876	    (save-excursion
8877	      (if window-system
8878		  (ps-spool-buffer-with-faces)
8879		(ps-spool-buffer)))))
8880      (kill-buffer buffer))))
8881
8882(defun gnus-summary-show-article (&optional arg)
8883  "Force redisplaying of the current article.
8884If ARG (the prefix) is a number, show the article with the charset
8885defined in `gnus-summary-show-article-charset-alist', or the charset
8886input.
8887If ARG (the prefix) is non-nil and not a number, show the raw article
8888without any article massaging functions being run.  Normally, the key
8889strokes are `C-u g'."
8890  (interactive "P")
8891  (cond
8892   ((numberp arg)
8893    (gnus-summary-show-article t)
8894    (let ((gnus-newsgroup-charset
8895	   (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8896	       (mm-read-coding-system
8897		"View as charset: " ;; actually it is coding system.
8898		(save-excursion
8899		  (set-buffer gnus-article-buffer)
8900		  (mm-detect-coding-region (point) (point-max))))))
8901	  (gnus-newsgroup-ignored-charsets 'gnus-all))
8902      (gnus-summary-select-article nil 'force)
8903      (let ((deps gnus-newsgroup-dependencies)
8904	    head header lines)
8905	(save-excursion
8906	  (set-buffer gnus-original-article-buffer)
8907	  (save-restriction
8908	    (message-narrow-to-head)
8909	    (setq head (buffer-string))
8910	    (goto-char (point-min))
8911	    (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8912	      (goto-char (point-max))
8913	      (widen)
8914	      (setq lines (1- (count-lines (point) (point-max))))))
8915	  (with-temp-buffer
8916	    (insert (format "211 %d Article retrieved.\n"
8917			    (cdr gnus-article-current)))
8918	    (insert head)
8919	    (if lines (insert (format "Lines: %d\n" lines)))
8920	    (insert ".\n")
8921	    (let ((nntp-server-buffer (current-buffer)))
8922	      (setq header (car (gnus-get-newsgroup-headers deps t))))))
8923	(gnus-data-set-header
8924	 (gnus-data-find (cdr gnus-article-current))
8925	 header)
8926	(gnus-summary-update-article-line
8927	 (cdr gnus-article-current) header)
8928	(when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8929	  (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8930   ((not arg)
8931    ;; Select the article the normal way.
8932    (gnus-summary-select-article nil 'force))
8933   (t
8934    ;; We have to require this here to make sure that the following
8935    ;; dynamic binding isn't shadowed by autoloading.
8936    (require 'gnus-async)
8937    (require 'gnus-art)
8938    ;; Bind the article treatment functions to nil.
8939    (let ((gnus-have-all-headers t)
8940	  gnus-article-prepare-hook
8941	  gnus-article-decode-hook
8942	  gnus-display-mime-function
8943	  gnus-break-pages)
8944      ;; Destroy any MIME parts.
8945      (when (gnus-buffer-live-p gnus-article-buffer)
8946	(save-excursion
8947	  (set-buffer gnus-article-buffer)
8948	  (mm-destroy-parts gnus-article-mime-handles)
8949	  ;; Set it to nil for safety reason.
8950	  (setq gnus-article-mime-handle-alist nil)
8951	  (setq gnus-article-mime-handles nil)))
8952      (gnus-summary-select-article nil 'force))))
8953  (gnus-summary-goto-subject gnus-current-article)
8954  (gnus-summary-position-point))
8955
8956(defun gnus-summary-show-raw-article ()
8957  "Show the raw article without any article massaging functions being run."
8958  (interactive)
8959  (gnus-summary-show-article t))
8960
8961(defun gnus-summary-verbose-headers (&optional arg)
8962  "Toggle permanent full header display.
8963If ARG is a positive number, turn header display on.
8964If ARG is a negative number, turn header display off."
8965  (interactive "P")
8966  (setq gnus-show-all-headers
8967	(cond ((or (not (numberp arg))
8968		   (zerop arg))
8969	       (not gnus-show-all-headers))
8970	      ((natnump arg)
8971	       t)))
8972  (gnus-summary-show-article))
8973
8974(defun gnus-summary-toggle-header (&optional arg)
8975  "Show the headers if they are hidden, or hide them if they are shown.
8976If ARG is a positive number, show the entire header.
8977If ARG is a negative number, hide the unwanted header lines."
8978  (interactive "P")
8979  (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8980		     (get-buffer-window gnus-article-buffer t))))
8981    (with-current-buffer gnus-article-buffer
8982      (widen)
8983      (article-narrow-to-head)
8984      (let* ((buffer-read-only nil)
8985	     (inhibit-point-motion-hooks t)
8986	     (hidden (if (numberp arg)
8987			 (>= arg 0)
8988		       (or (not (looking-at "[^ \t\n]+:"))
8989			   (gnus-article-hidden-text-p 'headers))))
8990	     s e)
8991	(delete-region (point-min) (point-max))
8992	(with-current-buffer gnus-original-article-buffer
8993	  (goto-char (setq s (point-min)))
8994	  (setq e (if (search-forward "\n\n" nil t)
8995		      (1- (point))
8996		    (point-max))))
8997	(insert-buffer-substring gnus-original-article-buffer s e)
8998	(run-hooks 'gnus-article-decode-hook)
8999	(if hidden
9000	    (let ((gnus-treat-hide-headers nil)
9001		  (gnus-treat-hide-boring-headers nil))
9002	      (gnus-delete-wash-type 'headers)
9003	      (gnus-treat-article 'head))
9004	  (gnus-treat-article 'head))
9005	(widen)
9006	(if window
9007	    (set-window-start window (goto-char (point-min))))
9008	(if gnus-break-pages
9009	    (gnus-narrow-to-page)
9010	  (when (gnus-visual-p 'page-marker)
9011	    (let ((buffer-read-only nil))
9012	      (gnus-remove-text-with-property 'gnus-prev)
9013	      (gnus-remove-text-with-property 'gnus-next))))
9014	(gnus-set-mode-line 'article)))))
9015
9016(defun gnus-summary-show-all-headers ()
9017  "Make all header lines visible."
9018  (interactive)
9019  (gnus-summary-toggle-header 1))
9020
9021(defun gnus-summary-caesar-message (&optional arg)
9022  "Caesar rotate the current article by 13.
9023The numerical prefix specifies how many places to rotate each letter
9024forward."
9025  (interactive "P")
9026  (gnus-summary-select-article)
9027  (let ((mail-header-separator ""))
9028    (gnus-eval-in-buffer-window gnus-article-buffer
9029      (save-restriction
9030	(widen)
9031	(let ((start (window-start))
9032	      buffer-read-only)
9033	  (message-caesar-buffer-body arg)
9034	  (set-window-start (get-buffer-window (current-buffer)) start)))))
9035  ;; Create buttons and stuff...
9036  (gnus-treat-article nil))
9037
9038(autoload 'unmorse-region "morse"
9039  "Convert morse coded text in region to ordinary ASCII text."
9040  t)
9041
9042(defun gnus-summary-morse-message (&optional arg)
9043  "Morse decode the current article."
9044  (interactive "P")
9045  (gnus-summary-select-article)
9046  (let ((mail-header-separator ""))
9047    (gnus-eval-in-buffer-window gnus-article-buffer
9048      (save-excursion
9049	(save-restriction
9050	  (widen)
9051	  (let ((pos (window-start))
9052		buffer-read-only)
9053	    (goto-char (point-min))
9054	    (when (message-goto-body)
9055	      (gnus-narrow-to-body))
9056	    (goto-char (point-min))
9057	    (while (re-search-forward "�" (point-max) t)
9058	      (replace-match "."))
9059	    (unmorse-region (point-min) (point-max))
9060	    (widen)
9061	    (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9062
9063(defun gnus-summary-stop-page-breaking ()
9064  "Stop page breaking in the current article."
9065  (interactive)
9066  (gnus-summary-select-article)
9067  (gnus-eval-in-buffer-window gnus-article-buffer
9068    (widen)
9069    (when (gnus-visual-p 'page-marker)
9070      (let ((buffer-read-only nil))
9071	(gnus-remove-text-with-property 'gnus-prev)
9072	(gnus-remove-text-with-property 'gnus-next))
9073      (setq gnus-page-broken nil))))
9074
9075(defun gnus-summary-move-article (&optional n to-newsgroup
9076					    select-method action)
9077  "Move the current article to a different newsgroup.
9078If N is a positive number, move the N next articles.
9079If N is a negative number, move the N previous articles.
9080If N is nil and any articles have been marked with the process mark,
9081move those articles instead.
9082If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9083If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9084re-spool using this method.
9085
9086When called interactively with TO-NEWSGROUP being nil, the value of
9087the variable `gnus-move-split-methods' is used for finding a default
9088for the target newsgroup.
9089
9090For this function to work, both the current newsgroup and the
9091newsgroup that you want to move to have to support the `request-move'
9092and `request-accept' functions.
9093
9094ACTION can be either `move' (the default), `crosspost' or `copy'."
9095  (interactive "P")
9096  (unless action
9097    (setq action 'move))
9098  ;; Check whether the source group supports the required functions.
9099  (cond ((and (eq action 'move)
9100	      (not (gnus-check-backend-function
9101		    'request-move-article gnus-newsgroup-name)))
9102	 (error "The current group does not support article moving"))
9103	((and (eq action 'crosspost)
9104	      (not (gnus-check-backend-function
9105		    'request-replace-article gnus-newsgroup-name)))
9106	 (error "The current group does not support article editing")))
9107  (let ((articles (gnus-summary-work-articles n))
9108	(prefix (if (gnus-check-backend-function
9109		     'request-move-article gnus-newsgroup-name)
9110		    (gnus-group-real-prefix gnus-newsgroup-name)
9111		  ""))
9112	(names '((move "Move" "Moving")
9113		 (copy "Copy" "Copying")
9114		 (crosspost "Crosspost" "Crossposting")))
9115	(copy-buf (save-excursion
9116		    (nnheader-set-temp-buffer " *copy article*")))
9117	art-group to-method new-xref article to-groups)
9118    (unless (assq action names)
9119      (error "Unknown action %s" action))
9120    ;; Read the newsgroup name.
9121    (when (and (not to-newsgroup)
9122	       (not select-method))
9123      (if (and gnus-move-split-methods
9124	       (not
9125		(and (memq gnus-current-article articles)
9126		     (gnus-buffer-live-p gnus-original-article-buffer))))
9127	  ;; When `gnus-move-split-methods' is non-nil, we have to
9128	  ;; select an article to give `gnus-read-move-group-name' an
9129	  ;; opportunity to suggest an appropriate default.  However,
9130	  ;; we needn't render or mark the article.
9131	  (let ((gnus-display-mime-function nil)
9132		(gnus-article-prepare-hook nil)
9133		(gnus-mark-article-hook nil))
9134	    (gnus-summary-select-article nil nil nil (car articles))))
9135      (setq to-newsgroup
9136	    (gnus-read-move-group-name
9137	     (cadr (assq action names))
9138	     (symbol-value (intern (format "gnus-current-%s-group" action)))
9139	     articles prefix))
9140      (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9141    (setq to-method (or select-method
9142			(gnus-server-to-method
9143			 (gnus-group-method to-newsgroup))))
9144    ;; Check the method we are to move this article to...
9145    (unless (gnus-check-backend-function
9146	     'request-accept-article (car to-method))
9147      (error "%s does not support article copying" (car to-method)))
9148    (unless (gnus-check-server to-method)
9149      (error "Can't open server %s" (car to-method)))
9150    (gnus-message 6 "%s to %s: %s..."
9151		  (caddr (assq action names))
9152		  (or (car select-method) to-newsgroup) articles)
9153    (while articles
9154      (setq article (pop articles))
9155      (setq
9156       art-group
9157       (cond
9158	;; Move the article.
9159	((eq action 'move)
9160	 ;; Remove this article from future suppression.
9161	 (gnus-dup-unsuppress-article article)
9162	 (gnus-request-move-article
9163	  article			; Article to move
9164	  gnus-newsgroup-name		; From newsgroup
9165	  (nth 1 (gnus-find-method-for-group
9166		  gnus-newsgroup-name)) ; Server
9167	  (list 'gnus-request-accept-article
9168		to-newsgroup (list 'quote select-method)
9169		(not articles) t)	; Accept form
9170	  (not articles)))		; Only save nov last time
9171	;; Copy the article.
9172	((eq action 'copy)
9173	 (save-excursion
9174	   (set-buffer copy-buf)
9175	   (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9176	     (gnus-request-accept-article
9177	      to-newsgroup select-method (not articles) t))))
9178	;; Crosspost the article.
9179	((eq action 'crosspost)
9180	 (let ((xref (message-tokenize-header
9181		      (mail-header-xref (gnus-summary-article-header article))
9182		      " ")))
9183	   (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9184				  ":" (number-to-string article)))
9185	   (unless xref
9186	     (setq xref (list (system-name))))
9187	   (setq new-xref
9188		 (concat
9189		  (mapconcat 'identity
9190			     (delete "Xref:" (delete new-xref xref))
9191			     " ")
9192		  " " new-xref))
9193	   (save-excursion
9194	     (set-buffer copy-buf)
9195	     ;; First put the article in the destination group.
9196	     (gnus-request-article-this-buffer article gnus-newsgroup-name)
9197	     (when (consp (setq art-group
9198				(gnus-request-accept-article
9199				 to-newsgroup select-method (not articles) t)))
9200	       (setq new-xref (concat new-xref " " (car art-group)
9201				      ":"
9202				      (number-to-string (cdr art-group))))
9203	       ;; Now we have the new Xrefs header, so we insert
9204	       ;; it and replace the new article.
9205	       (nnheader-replace-header "Xref" new-xref)
9206	       (gnus-request-replace-article
9207		(cdr art-group) to-newsgroup (current-buffer) t)
9208	       art-group))))))
9209      (cond
9210       ((not art-group)
9211	(gnus-message 1 "Couldn't %s article %s: %s"
9212		      (cadr (assq action names)) article
9213		      (nnheader-get-report (car to-method))))
9214       ((eq art-group 'junk)
9215	(when (eq action 'move)
9216	  (gnus-summary-mark-article article gnus-canceled-mark)
9217	  (gnus-message 4 "Deleted article %s" article)
9218	  ;; run the delete hook
9219	  (run-hook-with-args 'gnus-summary-article-delete-hook
9220			      action
9221			      (gnus-data-header
9222			       (assoc article (gnus-data-list nil)))
9223			      gnus-newsgroup-name nil
9224			      select-method)))
9225       (t
9226	(let* ((pto-group (gnus-group-prefixed-name
9227			   (car art-group) to-method))
9228	       (entry
9229		(gnus-gethash pto-group gnus-newsrc-hashtb))
9230	       (info (nth 2 entry))
9231	       (to-group (gnus-info-group info))
9232	       to-marks)
9233	  ;; Update the group that has been moved to.
9234	  (when (and info
9235		     (memq action '(move copy)))
9236	    (unless (member to-group to-groups)
9237	      (push to-group to-groups))
9238
9239	    (unless (memq article gnus-newsgroup-unreads)
9240	      (push 'read to-marks)
9241	      (gnus-info-set-read
9242	       info (gnus-add-to-range (gnus-info-read info)
9243				       (list (cdr art-group)))))
9244
9245	    ;; See whether the article is to be put in the cache.
9246	    (let ((marks (if (gnus-group-auto-expirable-p to-group)
9247			     gnus-article-mark-lists
9248			   (delete '(expirable . expire)
9249				   (copy-sequence gnus-article-mark-lists))))
9250		  (to-article (cdr art-group)))
9251
9252	      ;; Enter the article into the cache in the new group,
9253	      ;; if that is required.
9254	      (when gnus-use-cache
9255		(gnus-cache-possibly-enter-article
9256		 to-group to-article
9257		 (memq article gnus-newsgroup-marked)
9258		 (memq article gnus-newsgroup-dormant)
9259		 (memq article gnus-newsgroup-unreads)))
9260
9261	      (when gnus-preserve-marks
9262		;; Copy any marks over to the new group.
9263		(when (and (equal to-group gnus-newsgroup-name)
9264			   (not (memq article gnus-newsgroup-unreads)))
9265		  ;; Mark this article as read in this group.
9266		  (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9267		  (setcdr (gnus-active to-group) to-article)
9268		  (setcdr gnus-newsgroup-active to-article))
9269
9270		(while marks
9271		  (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9272		    (when (memq article (symbol-value
9273					 (intern (format "gnus-newsgroup-%s"
9274							 (caar marks)))))
9275		      (push (cdar marks) to-marks)
9276		      ;; If the other group is the same as this group,
9277		      ;; then we have to add the mark to the list.
9278		      (when (equal to-group gnus-newsgroup-name)
9279			(set (intern (format "gnus-newsgroup-%s" (caar marks)))
9280			     (cons to-article
9281				   (symbol-value
9282				    (intern (format "gnus-newsgroup-%s"
9283						    (caar marks)))))))
9284		      ;; Copy the marks to other group.
9285		      (gnus-add-marked-articles
9286		       to-group (cdar marks) (list to-article) info)))
9287		  (setq marks (cdr marks)))
9288
9289		(gnus-request-set-mark
9290		 to-group (list (list (list to-article) 'add to-marks))))
9291
9292	      (gnus-dribble-enter
9293	       (concat "(gnus-group-set-info '"
9294		       (gnus-prin1-to-string (gnus-get-info to-group))
9295		       ")"))))
9296
9297	  ;; Update the Xref header in this article to point to
9298	  ;; the new crossposted article we have just created.
9299	  (when (eq action 'crosspost)
9300	    (save-excursion
9301	      (set-buffer copy-buf)
9302	      (gnus-request-article-this-buffer article gnus-newsgroup-name)
9303	      (nnheader-replace-header "Xref" new-xref)
9304	      (gnus-request-replace-article
9305	       article gnus-newsgroup-name (current-buffer) t)))
9306
9307	  ;; run the move/copy/crosspost/respool hook
9308	  (run-hook-with-args 'gnus-summary-article-move-hook
9309			      action
9310			      (gnus-data-header
9311			       (assoc article (gnus-data-list nil)))
9312			      gnus-newsgroup-name
9313			      to-newsgroup
9314			      select-method))
9315
9316	;;;!!!Why is this necessary?
9317	(set-buffer gnus-summary-buffer)
9318
9319	(gnus-summary-goto-subject article)
9320	(when (eq action 'move)
9321	  (gnus-summary-mark-article article gnus-canceled-mark))))
9322      (gnus-summary-remove-process-mark article))
9323    ;; Re-activate all groups that have been moved to.
9324    (save-excursion
9325      (set-buffer gnus-group-buffer)
9326      (let ((gnus-group-marked to-groups))
9327	(gnus-group-get-new-news-this-group nil t)))
9328
9329    (gnus-kill-buffer copy-buf)
9330    (gnus-summary-position-point)
9331    (gnus-set-mode-line 'summary)))
9332
9333(defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9334  "Copy the current article to some other group.
9335If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9336When called interactively, if TO-NEWSGROUP is nil, use the value of
9337the variable `gnus-move-split-methods' for finding a default target
9338newsgroup.
9339If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9340re-spool using this method."
9341  (interactive "P")
9342  (gnus-summary-move-article n to-newsgroup select-method 'copy))
9343
9344(defun gnus-summary-crosspost-article (&optional n)
9345  "Crosspost the current article to some other group."
9346  (interactive "P")
9347  (gnus-summary-move-article n nil nil 'crosspost))
9348
9349(defcustom gnus-summary-respool-default-method nil
9350  "Default method type for respooling an article.
9351If nil, use to the current newsgroup method."
9352  :type 'symbol
9353  :group 'gnus-summary-mail)
9354
9355(defcustom gnus-summary-display-while-building nil
9356  "If non-nil, show and update the summary buffer as it's being built.
9357If the value is t, update the buffer after every line is inserted.  If
9358the value is an integer (N), update the display every N lines."
9359  :version "22.1"
9360  :group 'gnus-thread
9361  :type '(choice (const :tag "off" nil)
9362		 number
9363		 (const :tag "frequently" t)))
9364
9365(defun gnus-summary-respool-article (&optional n method)
9366  "Respool the current article.
9367The article will be squeezed through the mail spooling process again,
9368which means that it will be put in some mail newsgroup or other
9369depending on `nnmail-split-methods'.
9370If N is a positive number, respool the N next articles.
9371If N is a negative number, respool the N previous articles.
9372If N is nil and any articles have been marked with the process mark,
9373respool those articles instead.
9374
9375Respooling can be done both from mail groups and \"real\" newsgroups.
9376In the former case, the articles in question will be moved from the
9377current group into whatever groups they are destined to.  In the
9378latter case, they will be copied into the relevant groups."
9379  (interactive
9380   (list current-prefix-arg
9381	 (let* ((methods (gnus-methods-using 'respool))
9382		(methname
9383		 (symbol-name (or gnus-summary-respool-default-method
9384				  (car (gnus-find-method-for-group
9385					gnus-newsgroup-name)))))
9386		(method
9387		 (gnus-completing-read-with-default
9388		  methname "Backend to use when respooling"
9389		  methods nil t nil 'gnus-mail-method-history))
9390		ms)
9391	   (cond
9392	    ((zerop (length (setq ms (gnus-servers-using-backend
9393				      (intern method)))))
9394	     (list (intern method) ""))
9395	    ((= 1 (length ms))
9396	     (car ms))
9397	    (t
9398	     (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9399	       (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9400			   ms-alist))))))))
9401  (unless method
9402    (error "No method given for respooling"))
9403  (if (assoc (symbol-name
9404	      (car (gnus-find-method-for-group gnus-newsgroup-name)))
9405	     (gnus-methods-using 'respool))
9406      (gnus-summary-move-article n nil method)
9407    (gnus-summary-copy-article n nil method)))
9408
9409(defun gnus-summary-import-article (file &optional edit)
9410  "Import an arbitrary file into a mail newsgroup."
9411  (interactive "fImport file: \nP")
9412  (let ((group gnus-newsgroup-name)
9413	(now (current-time))
9414	atts lines group-art)
9415    (unless (gnus-check-backend-function 'request-accept-article group)
9416      (error "%s does not support article importing" group))
9417    (or (file-readable-p file)
9418	(not (file-regular-p file))
9419	(error "Can't read %s" file))
9420    (save-excursion
9421      (set-buffer (gnus-get-buffer-create " *import file*"))
9422      (erase-buffer)
9423      (nnheader-insert-file-contents file)
9424      (goto-char (point-min))
9425      (if (nnheader-article-p)
9426	  (save-restriction
9427	    (goto-char (point-min))
9428	    (search-forward "\n\n" nil t)
9429	    (narrow-to-region (point-min) (1- (point)))
9430	    (goto-char (point-min))
9431	    (unless (re-search-forward "^date:" nil t)
9432	      (goto-char (point-max))
9433	      (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9434       ;; This doesn't look like an article, so we fudge some headers.
9435	(setq atts (file-attributes file)
9436	      lines (count-lines (point-min) (point-max)))
9437	(insert "From: " (read-string "From: ") "\n"
9438		"Subject: " (read-string "Subject: ") "\n"
9439		"Date: " (message-make-date (nth 5 atts)) "\n"
9440		"Message-ID: " (message-make-message-id) "\n"
9441		"Lines: " (int-to-string lines) "\n"
9442		"Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9443      (setq group-art (gnus-request-accept-article group nil t))
9444      (kill-buffer (current-buffer)))
9445    (setq gnus-newsgroup-active (gnus-activate-group group))
9446    (forward-line 1)
9447    (gnus-summary-goto-article (cdr group-art) nil t)
9448    (when edit
9449      (gnus-summary-edit-article))))
9450
9451(defun gnus-summary-create-article ()
9452  "Create an article in a mail newsgroup."
9453  (interactive)
9454  (let ((group gnus-newsgroup-name)
9455	(now (current-time))
9456	group-art)
9457    (unless (gnus-check-backend-function 'request-accept-article group)
9458      (error "%s does not support article importing" group))
9459    (save-excursion
9460      (set-buffer (gnus-get-buffer-create " *import file*"))
9461      (erase-buffer)
9462      (goto-char (point-min))
9463      ;; This doesn't look like an article, so we fudge some headers.
9464      (insert "From: " (read-string "From: ") "\n"
9465	      "Subject: " (read-string "Subject: ") "\n"
9466	      "Date: " (message-make-date now) "\n"
9467	      "Message-ID: " (message-make-message-id) "\n")
9468      (setq group-art (gnus-request-accept-article group nil t))
9469      (kill-buffer (current-buffer)))
9470    (setq gnus-newsgroup-active (gnus-activate-group group))
9471    (forward-line 1)
9472    (gnus-summary-goto-article (cdr group-art) nil t)
9473    (gnus-summary-edit-article)))
9474
9475(defun gnus-summary-article-posted-p ()
9476  "Say whether the current (mail) article is available from news as well.
9477This will be the case if the article has both been mailed and posted."
9478  (interactive)
9479  (let ((id (mail-header-references (gnus-summary-article-header)))
9480	(gnus-override-method (car (gnus-refer-article-methods))))
9481    (if (gnus-request-head id "")
9482	(gnus-message 2 "The current message was found on %s"
9483		      gnus-override-method)
9484      (gnus-message 2 "The current message couldn't be found on %s"
9485		    gnus-override-method)
9486      nil)))
9487
9488(defun gnus-summary-expire-articles (&optional now)
9489  "Expire all articles that are marked as expirable in the current group."
9490  (interactive)
9491  (when (and (not gnus-group-is-exiting-without-update-p)
9492	     (gnus-check-backend-function
9493	      'request-expire-articles gnus-newsgroup-name))
9494    ;; This backend supports expiry.
9495    (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9496	   (expirable (if total
9497			  (progn
9498			    ;; We need to update the info for
9499			    ;; this group for `gnus-list-of-read-articles'
9500			    ;; to give us the right answer.
9501			    (gnus-run-hooks 'gnus-exit-group-hook)
9502			    (gnus-summary-update-info)
9503			    (gnus-list-of-read-articles gnus-newsgroup-name))
9504			(setq gnus-newsgroup-expirable
9505			      (sort gnus-newsgroup-expirable '<))))
9506	   (expiry-wait (if now 'immediate
9507			  (gnus-group-find-parameter
9508			   gnus-newsgroup-name 'expiry-wait)))
9509	   (nnmail-expiry-target
9510	    (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9511		nnmail-expiry-target))
9512	   es)
9513      (when expirable
9514	;; There are expirable articles in this group, so we run them
9515	;; through the expiry process.
9516	(gnus-message 6 "Expiring articles...")
9517	(unless (gnus-check-group gnus-newsgroup-name)
9518	  (error "Can't open server for %s" gnus-newsgroup-name))
9519	;; The list of articles that weren't expired is returned.
9520	(save-excursion
9521	  (if expiry-wait
9522	      (let ((nnmail-expiry-wait-function nil)
9523		    (nnmail-expiry-wait expiry-wait))
9524		(setq es (gnus-request-expire-articles
9525			  expirable gnus-newsgroup-name)))
9526	    (setq es (gnus-request-expire-articles
9527		      expirable gnus-newsgroup-name)))
9528	  (unless total
9529	    (setq gnus-newsgroup-expirable es))
9530	  ;; We go through the old list of expirable, and mark all
9531	  ;; really expired articles as nonexistent.
9532	  (unless (eq es expirable) ;If nothing was expired, we don't mark.
9533	    (let ((gnus-use-cache nil))
9534	      (dolist (article expirable)
9535		(when (and (not (memq article es))
9536			   (gnus-data-find article))
9537		  (gnus-summary-mark-article article gnus-canceled-mark)
9538		  (run-hook-with-args 'gnus-summary-article-expire-hook
9539				      'delete
9540				      (gnus-data-header
9541				       (assoc article (gnus-data-list nil)))
9542				      gnus-newsgroup-name
9543				      nil
9544				      nil))))))
9545	(gnus-message 6 "Expiring articles...done")))))
9546
9547(defun gnus-summary-expire-articles-now ()
9548  "Expunge all expirable articles in the current group.
9549This means that *all* articles that are marked as expirable will be
9550deleted forever, right now."
9551  (interactive)
9552  (or gnus-expert-user
9553      (gnus-yes-or-no-p
9554       "Are you really, really sure you want to delete all expirable messages? ")
9555      (error "Phew!"))
9556  (gnus-summary-expire-articles t))
9557
9558;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9559(defun gnus-summary-delete-article (&optional n)
9560  "Delete the N next (mail) articles.
9561This command actually deletes articles.  This is not a marking
9562command.  The article will disappear forever from your life, never to
9563return.
9564
9565If N is negative, delete backwards.
9566If N is nil and articles have been marked with the process mark,
9567delete these instead.
9568
9569If `gnus-novice-user' is non-nil you will be asked for
9570confirmation before the articles are deleted."
9571  (interactive "P")
9572  (unless (gnus-check-backend-function 'request-expire-articles
9573				       gnus-newsgroup-name)
9574    (error "The current newsgroup does not support article deletion"))
9575  (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9576    (error "Couldn't open server"))
9577  ;; Compute the list of articles to delete.
9578  (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9579	(nnmail-expiry-target 'delete)
9580	not-deleted)
9581    (if (and gnus-novice-user
9582	     (not (gnus-yes-or-no-p
9583		   (format "Do you really want to delete %s forever? "
9584			   (if (> (length articles) 1)
9585			       (format "these %s articles" (length articles))
9586			     "this article")))))
9587	()
9588      ;; Delete the articles.
9589      (setq not-deleted (gnus-request-expire-articles
9590			 articles gnus-newsgroup-name 'force))
9591      (while articles
9592	(gnus-summary-remove-process-mark (car articles))
9593	;; The backend might not have been able to delete the article
9594	;; after all.
9595	(unless (memq (car articles) not-deleted)
9596	  (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9597	(let* ((article (car articles))
9598	       (id (mail-header-id (gnus-data-header
9599				    (assoc article (gnus-data-list nil))))))
9600	  (run-hook-with-args 'gnus-summary-article-delete-hook
9601			      'delete id gnus-newsgroup-name nil
9602			      nil))
9603	(setq articles (cdr articles)))
9604      (when not-deleted
9605	(gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9606    (gnus-summary-position-point)
9607    (gnus-set-mode-line 'summary)
9608    not-deleted))
9609
9610(defun gnus-summary-edit-article (&optional arg)
9611  "Edit the current article.
9612This will have permanent effect only in mail groups.
9613If ARG is nil, edit the decoded articles.
9614If ARG is 1, edit the raw articles.
9615If ARG is 2, edit the raw articles even in read-only groups.
9616If ARG is 3, edit the articles with the current handles.
9617Otherwise, allow editing of articles even in read-only
9618groups."
9619  (interactive "P")
9620  (let (force raw current-handles)
9621    (cond
9622     ((null arg))
9623     ((eq arg 1)
9624      (setq raw t))
9625     ((eq arg 2)
9626      (setq raw t
9627	    force t))
9628     ((eq arg 3)
9629      (setq current-handles
9630	    (and (gnus-buffer-live-p gnus-article-buffer)
9631		 (with-current-buffer gnus-article-buffer
9632		   (prog1
9633		       gnus-article-mime-handles
9634		     (setq gnus-article-mime-handles nil))))))
9635     (t
9636      (setq force t)))
9637    (when (and raw (not force)
9638	       (member gnus-newsgroup-name '("nndraft:delayed"
9639					     "nndraft:drafts"
9640					     "nndraft:queue")))
9641      (error "Can't edit the raw article in group %s"
9642	     gnus-newsgroup-name))
9643    (save-excursion
9644      (set-buffer gnus-summary-buffer)
9645      (let ((mail-parse-charset gnus-newsgroup-charset)
9646	    (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9647	(gnus-set-global-variables)
9648	(when (and (not force)
9649		   (gnus-group-read-only-p))
9650	  (error "The current newsgroup does not support article editing"))
9651	(gnus-summary-show-article t)
9652	(when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9653	  (with-current-buffer gnus-article-buffer
9654	    (mm-enable-multibyte)))
9655	(if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9656	    (setq raw t))
9657	(gnus-article-edit-article
9658	 (if raw 'ignore
9659	   `(lambda ()
9660	      (let ((mbl mml-buffer-list))
9661		(setq mml-buffer-list nil)
9662		(let ((rfc2047-quote-decoded-words-containing-tspecials t))
9663		  (mime-to-mml ,'current-handles))
9664		(let ((mbl1 mml-buffer-list))
9665		  (setq mml-buffer-list mbl)
9666		  (set (make-local-variable 'mml-buffer-list) mbl1))
9667		(gnus-make-local-hook 'kill-buffer-hook)
9668		(add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9669	 `(lambda (no-highlight)
9670	    (let ((mail-parse-charset ',gnus-newsgroup-charset)
9671		  (message-options message-options)
9672		  (message-options-set-recipient)
9673		  (mail-parse-ignored-charsets
9674		   ',gnus-newsgroup-ignored-charsets))
9675	      ,(if (not raw) '(progn
9676				(mml-to-mime)
9677				(mml-destroy-buffers)
9678				(remove-hook 'kill-buffer-hook
9679					     'mml-destroy-buffers t)
9680				(kill-local-variable 'mml-buffer-list)))
9681	      (gnus-summary-edit-article-done
9682	       ,(or (mail-header-references gnus-current-headers) "")
9683	       ,(gnus-group-read-only-p)
9684	       ,gnus-summary-buffer no-highlight))))))))
9685
9686(defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9687
9688(defun gnus-summary-edit-article-done (&optional references read-only buffer
9689						 no-highlight)
9690  "Make edits to the current article permanent."
9691  (interactive)
9692  (save-excursion
9693   ;; The buffer restriction contains the entire article if it exists.
9694    (when (article-goto-body)
9695      (let ((lines (count-lines (point) (point-max)))
9696	    (length (- (point-max) (point)))
9697	    (case-fold-search t)
9698	    (body (copy-marker (point))))
9699	(goto-char (point-min))
9700	(when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9701	  (delete-region (match-beginning 1) (match-end 1))
9702	  (insert (number-to-string length)))
9703	(goto-char (point-min))
9704	(when (re-search-forward
9705	       "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9706	  (delete-region (match-beginning 1) (match-end 1))
9707	  (insert (number-to-string length)))
9708	(goto-char (point-min))
9709	(when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9710	  (delete-region (match-beginning 1) (match-end 1))
9711	  (insert (number-to-string lines))))))
9712  ;; Replace the article.
9713  (let ((buf (current-buffer)))
9714    (with-temp-buffer
9715      (insert-buffer-substring buf)
9716
9717      (if (and (not read-only)
9718	       (not (gnus-request-replace-article
9719		     (cdr gnus-article-current) (car gnus-article-current)
9720		     (current-buffer) t)))
9721	  (error "Couldn't replace article")
9722	;; Update the summary buffer.
9723	(if (and references
9724		 (equal (message-tokenize-header references " ")
9725			(message-tokenize-header
9726			 (or (message-fetch-field "references") "") " ")))
9727	    ;; We only have to update this line.
9728	    (save-excursion
9729	      (save-restriction
9730		(message-narrow-to-head)
9731		(let ((head (buffer-substring-no-properties
9732			     (point-min) (point-max)))
9733		      header)
9734		  (with-temp-buffer
9735		    (insert (format "211 %d Article retrieved.\n"
9736				    (cdr gnus-article-current)))
9737		    (insert head)
9738		    (insert ".\n")
9739		    (let ((nntp-server-buffer (current-buffer)))
9740		      (setq header (car (gnus-get-newsgroup-headers
9741					 nil t))))
9742		    (save-excursion
9743		      (set-buffer gnus-summary-buffer)
9744		      (gnus-data-set-header
9745		       (gnus-data-find (cdr gnus-article-current))
9746		       header)
9747		      (gnus-summary-update-article-line
9748		       (cdr gnus-article-current) header)
9749		      (if (gnus-summary-goto-subject
9750			   (cdr gnus-article-current) nil t)
9751			  (gnus-summary-update-secondary-mark
9752			   (cdr gnus-article-current))))))))
9753	  ;; Update threads.
9754	  (set-buffer (or buffer gnus-summary-buffer))
9755	  (gnus-summary-update-article (cdr gnus-article-current))
9756	  (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9757	      (gnus-summary-update-secondary-mark
9758	       (cdr gnus-article-current))))
9759	;; Prettify the article buffer again.
9760	(unless no-highlight
9761	  (save-excursion
9762	    (set-buffer gnus-article-buffer)
9763	    ;;;!!! Fix this -- article should be rehighlighted.
9764	    ;;;(gnus-run-hooks 'gnus-article-display-hook)
9765	    (set-buffer gnus-original-article-buffer)
9766	    (gnus-request-article
9767	     (cdr gnus-article-current)
9768	     (car gnus-article-current) (current-buffer))))
9769	;; Prettify the summary buffer line.
9770	(when (gnus-visual-p 'summary-highlight 'highlight)
9771	  (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9772
9773(defun gnus-summary-edit-wash (key)
9774  "Perform editing command KEY in the article buffer."
9775  (interactive
9776   (list
9777    (progn
9778      (message "%s" (concat (this-command-keys) "- "))
9779      (read-char))))
9780  (message "")
9781  (gnus-summary-edit-article)
9782  (execute-kbd-macro (concat (this-command-keys) key))
9783  (gnus-article-edit-done))
9784
9785;;; Respooling
9786
9787(defun gnus-summary-respool-query (&optional silent trace)
9788  "Query where the respool algorithm would put this article."
9789  (interactive)
9790  (let (gnus-mark-article-hook)
9791    (gnus-summary-select-article)
9792    (save-excursion
9793      (set-buffer gnus-original-article-buffer)
9794      (let ((groups (nnmail-article-group 'identity trace)))
9795	(unless silent
9796	  (if groups
9797	      (message "This message would go to %s"
9798		       (mapconcat 'car groups ", "))
9799	    (message "This message would go to no groups"))
9800	  groups)))))
9801
9802(defun gnus-summary-respool-trace ()
9803  "Trace where the respool algorithm would put this article.
9804Display a buffer showing all fancy splitting patterns which matched."
9805  (interactive)
9806  (gnus-summary-respool-query nil t))
9807
9808;; Summary marking commands.
9809
9810(defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9811  "Mark articles which has the same subject as read, and then select the next.
9812If UNMARK is positive, remove any kind of mark.
9813If UNMARK is negative, tick articles."
9814  (interactive "P")
9815  (when unmark
9816    (setq unmark (prefix-numeric-value unmark)))
9817  (let ((count
9818	 (gnus-summary-mark-same-subject
9819	  (gnus-summary-article-subject) unmark)))
9820    ;; Select next unread article.  If auto-select-same mode, should
9821    ;; select the first unread article.
9822    (gnus-summary-next-article t (and gnus-auto-select-same
9823				      (gnus-summary-article-subject)))
9824    (gnus-message 7 "%d article%s marked as %s"
9825		  count (if (= count 1) " is" "s are")
9826		  (if unmark "unread" "read"))))
9827
9828(defun gnus-summary-kill-same-subject (&optional unmark)
9829  "Mark articles which has the same subject as read.
9830If UNMARK is positive, remove any kind of mark.
9831If UNMARK is negative, tick articles."
9832  (interactive "P")
9833  (when unmark
9834    (setq unmark (prefix-numeric-value unmark)))
9835  (let ((count
9836	 (gnus-summary-mark-same-subject
9837	  (gnus-summary-article-subject) unmark)))
9838    ;; If marked as read, go to next unread subject.
9839    (when (null unmark)
9840      ;; Go to next unread subject.
9841      (gnus-summary-next-subject 1 t))
9842    (gnus-message 7 "%d articles are marked as %s"
9843		  count (if unmark "unread" "read"))))
9844
9845(defun gnus-summary-mark-same-subject (subject &optional unmark)
9846  "Mark articles with same SUBJECT as read, and return marked number.
9847If optional argument UNMARK is positive, remove any kinds of marks.
9848If optional argument UNMARK is negative, mark articles as unread instead."
9849  (let ((count 1))
9850    (save-excursion
9851      (cond
9852       ((null unmark)			; Mark as read.
9853	(while (and
9854		(progn
9855		  (gnus-summary-mark-article-as-read gnus-killed-mark)
9856		  (gnus-summary-show-thread) t)
9857		(gnus-summary-find-subject subject))
9858	  (setq count (1+ count))))
9859       ((> unmark 0)			; Tick.
9860	(while (and
9861		(progn
9862		  (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9863		  (gnus-summary-show-thread) t)
9864		(gnus-summary-find-subject subject))
9865	  (setq count (1+ count))))
9866       (t				; Mark as unread.
9867	(while (and
9868		(progn
9869		  (gnus-summary-mark-article-as-unread gnus-unread-mark)
9870		  (gnus-summary-show-thread) t)
9871		(gnus-summary-find-subject subject))
9872	  (setq count (1+ count)))))
9873      (gnus-set-mode-line 'summary)
9874      ;; Return the number of marked articles.
9875      count)))
9876
9877(defun gnus-summary-mark-as-processable (n &optional unmark)
9878  "Set the process mark on the next N articles.
9879If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9880the process mark instead.  The difference between N and the actual
9881number of articles marked is returned."
9882  (interactive "P")
9883  (if (and (null n) (gnus-region-active-p))
9884      (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9885    (setq n (prefix-numeric-value n))
9886    (let ((backward (< n 0))
9887	  (n (abs n)))
9888      (while (and
9889	      (> n 0)
9890	      (if unmark
9891		  (gnus-summary-remove-process-mark
9892		   (gnus-summary-article-number))
9893		(gnus-summary-set-process-mark (gnus-summary-article-number)))
9894	      (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9895	(setq n (1- n)))
9896      (when (/= 0 n)
9897	(gnus-message 7 "No more articles"))
9898      (gnus-summary-recenter)
9899      (gnus-summary-position-point)
9900      n)))
9901
9902(defun gnus-summary-unmark-as-processable (n)
9903  "Remove the process mark from the next N articles.
9904If N is negative, unmark backward instead.  The difference between N and
9905the actual number of articles unmarked is returned."
9906  (interactive "P")
9907  (gnus-summary-mark-as-processable n t))
9908
9909(defun gnus-summary-unmark-all-processable ()
9910  "Remove the process mark from all articles."
9911  (interactive)
9912  (save-excursion
9913    (while gnus-newsgroup-processable
9914      (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9915  (gnus-summary-position-point))
9916
9917(defun gnus-summary-add-mark (article type)
9918  "Mark ARTICLE with a mark of TYPE."
9919  (let ((vtype (car (assq type gnus-article-mark-lists)))
9920	var)
9921    (if (not vtype)
9922	(error "No such mark type: %s" type)
9923      (setq var (intern (format "gnus-newsgroup-%s" type)))
9924      (set var (cons article (symbol-value var)))
9925      (if (memq type '(processable cached replied forwarded recent saved))
9926	  (gnus-summary-update-secondary-mark article)
9927	;;; !!! This is bogus.  We should find out what primary
9928	;;; !!! mark we want to set.
9929	(gnus-summary-update-mark gnus-del-mark 'unread)))))
9930
9931(defun gnus-summary-mark-as-expirable (n)
9932  "Mark N articles forward as expirable.
9933If N is negative, mark backward instead.  The difference between N and
9934the actual number of articles marked is returned."
9935  (interactive "p")
9936  (gnus-summary-mark-forward n gnus-expirable-mark))
9937
9938(defun gnus-summary-mark-as-spam (n)
9939  "Mark N articles forward as spam.
9940If N is negative, mark backward instead.  The difference between N and
9941the actual number of articles marked is returned."
9942  (interactive "p")
9943  (gnus-summary-mark-forward n gnus-spam-mark))
9944
9945(defun gnus-summary-mark-article-as-replied (article)
9946  "Mark ARTICLE as replied to and update the summary line.
9947ARTICLE can also be a list of articles."
9948  (interactive (list (gnus-summary-article-number)))
9949  (let ((articles (if (listp article) article (list article))))
9950    (dolist (article articles)
9951      (unless (numberp article)
9952	(error "%s is not a number" article))
9953      (push article gnus-newsgroup-replied)
9954      (let ((buffer-read-only nil))
9955	(when (gnus-summary-goto-subject article nil t)
9956	  (gnus-summary-update-secondary-mark article))))))
9957
9958(defun gnus-summary-mark-article-as-forwarded (article)
9959  "Mark ARTICLE as forwarded and update the summary line.
9960ARTICLE can also be a list of articles."
9961  (let ((articles (if (listp article) article (list article))))
9962    (dolist (article articles)
9963      (push article gnus-newsgroup-forwarded)
9964      (let ((buffer-read-only nil))
9965	(when (gnus-summary-goto-subject article nil t)
9966	  (gnus-summary-update-secondary-mark article))))))
9967
9968(defun gnus-summary-set-bookmark (article)
9969  "Set a bookmark in current article."
9970  (interactive (list (gnus-summary-article-number)))
9971  (when (or (not (get-buffer gnus-article-buffer))
9972	    (not gnus-current-article)
9973	    (not gnus-article-current)
9974	    (not (equal gnus-newsgroup-name (car gnus-article-current))))
9975    (error "No current article selected"))
9976  ;; Remove old bookmark, if one exists.
9977  (gnus-pull article gnus-newsgroup-bookmarks)
9978  ;; Set the new bookmark, which is on the form
9979  ;; (article-number . line-number-in-body).
9980  (push
9981   (cons article
9982	 (save-excursion
9983	   (set-buffer gnus-article-buffer)
9984	   (count-lines
9985	    (min (point)
9986		 (save-excursion
9987		   (article-goto-body)
9988		   (point)))
9989	    (point))))
9990   gnus-newsgroup-bookmarks)
9991  (gnus-message 6 "A bookmark has been added to the current article."))
9992
9993(defun gnus-summary-remove-bookmark (article)
9994  "Remove the bookmark from the current article."
9995  (interactive (list (gnus-summary-article-number)))
9996  ;; Remove old bookmark, if one exists.
9997  (if (not (assq article gnus-newsgroup-bookmarks))
9998      (gnus-message 6 "No bookmark in current article.")
9999    (gnus-pull article gnus-newsgroup-bookmarks)
10000    (gnus-message 6 "Removed bookmark.")))
10001
10002;; Suggested by Daniel Quinlan <quinlan@best.com>.
10003(defun gnus-summary-mark-as-dormant (n)
10004  "Mark N articles forward as dormant.
10005If N is negative, mark backward instead.  The difference between N and
10006the actual number of articles marked is returned."
10007  (interactive "p")
10008  (gnus-summary-mark-forward n gnus-dormant-mark))
10009
10010(defun gnus-summary-set-process-mark (article)
10011  "Set the process mark on ARTICLE and update the summary line."
10012  (setq gnus-newsgroup-processable
10013	(cons article
10014	      (delq article gnus-newsgroup-processable)))
10015  (when (gnus-summary-goto-subject article)
10016    (gnus-summary-show-thread)
10017    (gnus-summary-goto-subject article)
10018    (gnus-summary-update-secondary-mark article)))
10019
10020(defun gnus-summary-remove-process-mark (article)
10021  "Remove the process mark from ARTICLE and update the summary line."
10022  (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10023  (when (gnus-summary-goto-subject article)
10024    (gnus-summary-show-thread)
10025    (gnus-summary-goto-subject article)
10026    (gnus-summary-update-secondary-mark article)))
10027
10028(defun gnus-summary-set-saved-mark (article)
10029  "Set the process mark on ARTICLE and update the summary line."
10030  (push article gnus-newsgroup-saved)
10031  (when (gnus-summary-goto-subject article)
10032    (gnus-summary-update-secondary-mark article)))
10033
10034(defun gnus-summary-mark-forward (n &optional mark no-expire)
10035  "Mark N articles as read forwards.
10036If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10037The difference between N and the actual number of articles marked is
10038returned.
10039If NO-EXPIRE, auto-expiry will be inhibited."
10040  (interactive "p")
10041  (gnus-summary-show-thread)
10042  (let ((backward (< n 0))
10043	(gnus-summary-goto-unread
10044	 (and gnus-summary-goto-unread
10045	      (not (eq gnus-summary-goto-unread 'never))
10046	      (not (memq mark (list gnus-unread-mark gnus-spam-mark
10047				    gnus-ticked-mark gnus-dormant-mark)))))
10048	(n (abs n))
10049	(mark (or mark gnus-del-mark)))
10050    (while (and (> n 0)
10051		(gnus-summary-mark-article nil mark no-expire)
10052		(zerop (gnus-summary-next-subject
10053			(if backward -1 1)
10054			(and gnus-summary-goto-unread
10055			     (not (eq gnus-summary-goto-unread 'never)))
10056			t)))
10057      (setq n (1- n)))
10058    (when (/= 0 n)
10059      (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10060    (gnus-summary-recenter)
10061    (gnus-summary-position-point)
10062    (gnus-set-mode-line 'summary)
10063    n))
10064
10065(defun gnus-summary-mark-article-as-read (mark)
10066  "Mark the current article quickly as read with MARK."
10067  (let ((article (gnus-summary-article-number)))
10068    (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10069    (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10070    (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10071    (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10072    (push (cons article mark) gnus-newsgroup-reads)
10073    ;; Possibly remove from cache, if that is used.
10074    (when gnus-use-cache
10075      (gnus-cache-enter-remove-article article))
10076    ;; Allow the backend to change the mark.
10077    (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10078    ;; Check for auto-expiry.
10079    (when (and gnus-newsgroup-auto-expire
10080	       (memq mark gnus-auto-expirable-marks))
10081      (setq mark gnus-expirable-mark)
10082      ;; Let the backend know about the mark change.
10083      (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10084      (push article gnus-newsgroup-expirable))
10085    ;; Set the mark in the buffer.
10086    (gnus-summary-update-mark mark 'unread)
10087    t))
10088
10089(defun gnus-summary-mark-article-as-unread (mark)
10090  "Mark the current article quickly as unread with MARK."
10091  (let* ((article (gnus-summary-article-number))
10092	 (old-mark (gnus-summary-article-mark article)))
10093    ;; Allow the backend to change the mark.
10094    (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10095    (if (eq mark old-mark)
10096	t
10097      (if (<= article 0)
10098	  (progn
10099	    (gnus-error 1 "Can't mark negative article numbers")
10100	    nil)
10101	(setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10102	(setq gnus-newsgroup-spam-marked
10103	      (delq article gnus-newsgroup-spam-marked))
10104	(setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10105	(setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10106	(setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10107	(cond ((= mark gnus-ticked-mark)
10108	       (setq gnus-newsgroup-marked
10109		     (gnus-add-to-sorted-list gnus-newsgroup-marked
10110					      article)))
10111	      ((= mark gnus-spam-mark)
10112	       (setq gnus-newsgroup-spam-marked
10113		     (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10114					      article)))
10115	      ((= mark gnus-dormant-mark)
10116	       (setq gnus-newsgroup-dormant
10117		     (gnus-add-to-sorted-list gnus-newsgroup-dormant
10118					      article)))
10119	      (t
10120	       (setq gnus-newsgroup-unreads
10121		     (gnus-add-to-sorted-list gnus-newsgroup-unreads
10122					      article))))
10123	(gnus-pull article gnus-newsgroup-reads)
10124
10125	;; See whether the article is to be put in the cache.
10126	(and gnus-use-cache
10127	     (vectorp (gnus-summary-article-header article))
10128	     (save-excursion
10129	       (gnus-cache-possibly-enter-article
10130		gnus-newsgroup-name article
10131		(= mark gnus-ticked-mark)
10132		(= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10133
10134	;; Fix the mark.
10135	(gnus-summary-update-mark mark 'unread)
10136	t))))
10137
10138(defun gnus-summary-mark-article (&optional article mark no-expire)
10139  "Mark ARTICLE with MARK.  MARK can be any character.
10140Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10141`??' (dormant) and `?E' (expirable).
10142If MARK is nil, then the default character `?r' is used.
10143If ARTICLE is nil, then the article on the current line will be
10144marked.
10145If NO-EXPIRE, auto-expiry will be inhibited."
10146  ;; The mark might be a string.
10147  (when (stringp mark)
10148    (setq mark (aref mark 0)))
10149  ;; If no mark is given, then we check auto-expiring.
10150  (when (null mark)
10151    (setq mark gnus-del-mark))
10152  (when (and (not no-expire)
10153	     gnus-newsgroup-auto-expire
10154	     (memq mark gnus-auto-expirable-marks))
10155    (setq mark gnus-expirable-mark))
10156  (let ((article (or article (gnus-summary-article-number)))
10157	(old-mark (gnus-summary-article-mark article)))
10158    ;; Allow the backend to change the mark.
10159    (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10160    (if (eq mark old-mark)
10161	t
10162      (unless article
10163	(error "No article on current line"))
10164      (if (not (if (or (= mark gnus-unread-mark)
10165		       (= mark gnus-ticked-mark)
10166		       (= mark gnus-spam-mark)
10167		       (= mark gnus-dormant-mark))
10168		   (gnus-mark-article-as-unread article mark)
10169		 (gnus-mark-article-as-read article mark)))
10170	  t
10171	;; See whether the article is to be put in the cache.
10172	(and gnus-use-cache
10173	     (not (= mark gnus-canceled-mark))
10174	     (vectorp (gnus-summary-article-header article))
10175	     (save-excursion
10176	       (gnus-cache-possibly-enter-article
10177		gnus-newsgroup-name article
10178		(= mark gnus-ticked-mark)
10179		(= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10180
10181	(when (gnus-summary-goto-subject article nil t)
10182	  (let ((buffer-read-only nil))
10183	    (gnus-summary-show-thread)
10184	    ;; Fix the mark.
10185	    (gnus-summary-update-mark mark 'unread)
10186	    t))))))
10187
10188(defun gnus-summary-update-secondary-mark (article)
10189  "Update the secondary (read, process, cache) mark."
10190  (gnus-summary-update-mark
10191   (cond ((memq article gnus-newsgroup-processable)
10192	  gnus-process-mark)
10193	 ((memq article gnus-newsgroup-cached)
10194	  gnus-cached-mark)
10195	 ((memq article gnus-newsgroup-replied)
10196	  gnus-replied-mark)
10197	 ((memq article gnus-newsgroup-forwarded)
10198	  gnus-forwarded-mark)
10199	 ((memq article gnus-newsgroup-saved)
10200	  gnus-saved-mark)
10201	 ((memq article gnus-newsgroup-recent)
10202	  gnus-recent-mark)
10203	 ((memq article gnus-newsgroup-unseen)
10204	  gnus-unseen-mark)
10205	 (t gnus-no-mark))
10206   'replied)
10207  (when (gnus-visual-p 'summary-highlight 'highlight)
10208    (gnus-run-hooks 'gnus-summary-update-hook))
10209  t)
10210
10211(defun gnus-summary-update-download-mark (article)
10212  "Update the download mark."
10213  (gnus-summary-update-mark
10214   (cond ((memq article gnus-newsgroup-undownloaded)
10215          gnus-undownloaded-mark)
10216         (gnus-newsgroup-agentized
10217          gnus-downloaded-mark)
10218         (t
10219          gnus-no-mark))
10220   'download)
10221  (gnus-summary-update-line t)
10222  t)
10223
10224(defun gnus-summary-update-mark (mark type)
10225  (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10226	(buffer-read-only nil))
10227    (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
10228    (when forward
10229      (when (looking-at "\r")
10230	(incf forward))
10231      (when (<= (+ forward (point)) (point-max))
10232	;; Go to the right position on the line.
10233	(goto-char (+ forward (point)))
10234	;; Replace the old mark with the new mark.
10235	(subst-char-in-region (point) (1+ (point)) (char-after) mark)
10236	;; Optionally update the marks by some user rule.
10237	(when (eq type 'unread)
10238	  (gnus-data-set-mark
10239	   (gnus-data-find (gnus-summary-article-number)) mark)
10240	  (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10241
10242(defun gnus-mark-article-as-read (article &optional mark)
10243  "Enter ARTICLE in the pertinent lists and remove it from others."
10244  ;; Make the article expirable.
10245  (let ((mark (or mark gnus-del-mark)))
10246    (setq gnus-newsgroup-expirable
10247	  (if (= mark gnus-expirable-mark)
10248	      (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10249	    (delq article gnus-newsgroup-expirable)))
10250    ;; Remove from unread and marked lists.
10251    (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10252    (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10253    (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10254    (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10255    (push (cons article mark) gnus-newsgroup-reads)
10256    ;; Possibly remove from cache, if that is used.
10257    (when gnus-use-cache
10258      (gnus-cache-enter-remove-article article))
10259    t))
10260
10261(defun gnus-mark-article-as-unread (article &optional mark)
10262  "Enter ARTICLE in the pertinent lists and remove it from others."
10263  (let ((mark (or mark gnus-ticked-mark)))
10264    (if (<= article 0)
10265	(progn
10266	  (gnus-error 1 "Can't mark negative article numbers")
10267	  nil)
10268      (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10269	    gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10270	    gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10271	    gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10272	    gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10273
10274      ;; Unsuppress duplicates?
10275      (when gnus-suppress-duplicates
10276	(gnus-dup-unsuppress-article article))
10277
10278      (cond ((= mark gnus-ticked-mark)
10279	     (setq gnus-newsgroup-marked
10280		   (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10281	    ((= mark gnus-spam-mark)
10282	     (setq gnus-newsgroup-spam-marked
10283		   (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10284					    article)))
10285	    ((= mark gnus-dormant-mark)
10286	     (setq gnus-newsgroup-dormant
10287		   (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10288	    (t
10289	     (setq gnus-newsgroup-unreads
10290		   (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10291      (gnus-pull article gnus-newsgroup-reads)
10292      t)))
10293
10294(defalias 'gnus-summary-mark-as-unread-forward
10295  'gnus-summary-tick-article-forward)
10296(make-obsolete 'gnus-summary-mark-as-unread-forward
10297	       'gnus-summary-tick-article-forward)
10298(defun gnus-summary-tick-article-forward (n)
10299  "Tick N articles forwards.
10300If N is negative, tick backwards instead.
10301The difference between N and the number of articles ticked is returned."
10302  (interactive "p")
10303  (gnus-summary-mark-forward n gnus-ticked-mark))
10304
10305(defalias 'gnus-summary-mark-as-unread-backward
10306  'gnus-summary-tick-article-backward)
10307(make-obsolete 'gnus-summary-mark-as-unread-backward
10308	       'gnus-summary-tick-article-backward)
10309(defun gnus-summary-tick-article-backward (n)
10310  "Tick N articles backwards.
10311The difference between N and the number of articles ticked is returned."
10312  (interactive "p")
10313  (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10314
10315(defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10316(make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10317(defun gnus-summary-tick-article (&optional article clear-mark)
10318  "Mark current article as unread.
10319Optional 1st argument ARTICLE specifies article number to be marked as unread.
10320Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10321  (interactive)
10322  (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10323				       gnus-ticked-mark)))
10324
10325(defun gnus-summary-mark-as-read-forward (n)
10326  "Mark N articles as read forwards.
10327If N is negative, mark backwards instead.
10328The difference between N and the actual number of articles marked is
10329returned."
10330  (interactive "p")
10331  (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10332
10333(defun gnus-summary-mark-as-read-backward (n)
10334  "Mark the N articles as read backwards.
10335The difference between N and the actual number of articles marked is
10336returned."
10337  (interactive "p")
10338  (gnus-summary-mark-forward
10339   (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10340
10341(defun gnus-summary-mark-as-read (&optional article mark)
10342  "Mark current article as read.
10343ARTICLE specifies the article to be marked as read.
10344MARK specifies a string to be inserted at the beginning of the line."
10345  (gnus-summary-mark-article article mark))
10346
10347(defun gnus-summary-clear-mark-forward (n)
10348  "Clear marks from N articles forward.
10349If N is negative, clear backward instead.
10350The difference between N and the number of marks cleared is returned."
10351  (interactive "p")
10352  (gnus-summary-mark-forward n gnus-unread-mark))
10353
10354(defun gnus-summary-clear-mark-backward (n)
10355  "Clear marks from N articles backward.
10356The difference between N and the number of marks cleared is returned."
10357  (interactive "p")
10358  (gnus-summary-mark-forward (- n) gnus-unread-mark))
10359
10360(defun gnus-summary-mark-unread-as-read ()
10361  "Intended to be used by `gnus-summary-mark-article-hook'."
10362  (when (memq gnus-current-article gnus-newsgroup-unreads)
10363    (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10364
10365(defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10366  "Intended to be used by `gnus-summary-mark-article-hook'."
10367  (let ((mark (gnus-summary-article-mark)))
10368    (when (or (gnus-unread-mark-p mark)
10369	      (gnus-read-mark-p mark))
10370      (gnus-summary-mark-article gnus-current-article
10371				 (or new-mark gnus-read-mark)))))
10372
10373(defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10374  "Intended to be used by `gnus-summary-mark-article-hook'."
10375  (let ((mark (gnus-summary-article-mark)))
10376    (when (or (gnus-unread-mark-p mark)
10377	      (gnus-read-mark-p mark))
10378      (gnus-summary-mark-article (gnus-summary-article-number)
10379				 (or new-mark gnus-read-mark)))))
10380
10381(defun gnus-summary-mark-unread-as-ticked ()
10382  "Intended to be used by `gnus-summary-mark-article-hook'."
10383  (when (memq gnus-current-article gnus-newsgroup-unreads)
10384    (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10385
10386(defun gnus-summary-mark-region-as-read (point mark all)
10387  "Mark all unread articles between point and mark as read.
10388If given a prefix, mark all articles between point and mark as read,
10389even ticked and dormant ones."
10390  (interactive "r\nP")
10391  (save-excursion
10392    (let (article)
10393      (goto-char point)
10394      (beginning-of-line)
10395      (while (and
10396	      (< (point) mark)
10397	      (progn
10398		(when (or all
10399			  (memq (setq article (gnus-summary-article-number))
10400				gnus-newsgroup-unreads))
10401		  (gnus-summary-mark-article article gnus-del-mark))
10402		t)
10403	      (gnus-summary-find-next))))))
10404
10405(defun gnus-summary-mark-below (score mark)
10406  "Mark articles with score less than SCORE with MARK."
10407  (interactive "P\ncMark: ")
10408  (setq score (if score
10409		  (prefix-numeric-value score)
10410		(or gnus-summary-default-score 0)))
10411  (save-excursion
10412    (set-buffer gnus-summary-buffer)
10413    (goto-char (point-min))
10414    (while
10415	(progn
10416	  (and (< (gnus-summary-article-score) score)
10417	       (gnus-summary-mark-article nil mark))
10418	  (gnus-summary-find-next)))))
10419
10420(defun gnus-summary-kill-below (&optional score)
10421  "Mark articles with score below SCORE as read."
10422  (interactive "P")
10423  (gnus-summary-mark-below score gnus-killed-mark))
10424
10425(defun gnus-summary-clear-above (&optional score)
10426  "Clear all marks from articles with score above SCORE."
10427  (interactive "P")
10428  (gnus-summary-mark-above score gnus-unread-mark))
10429
10430(defun gnus-summary-tick-above (&optional score)
10431  "Tick all articles with score above SCORE."
10432  (interactive "P")
10433  (gnus-summary-mark-above score gnus-ticked-mark))
10434
10435(defun gnus-summary-mark-above (score mark)
10436  "Mark articles with score over SCORE with MARK."
10437  (interactive "P\ncMark: ")
10438  (setq score (if score
10439		  (prefix-numeric-value score)
10440		(or gnus-summary-default-score 0)))
10441  (save-excursion
10442    (set-buffer gnus-summary-buffer)
10443    (goto-char (point-min))
10444    (while (and (progn
10445		  (when (> (gnus-summary-article-score) score)
10446		    (gnus-summary-mark-article nil mark))
10447		  t)
10448		(gnus-summary-find-next)))))
10449
10450;; Suggested by Daniel Quinlan <quinlan@best.com>.
10451(defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10452(defun gnus-summary-limit-include-expunged (&optional no-error)
10453  "Display all the hidden articles that were expunged for low scores."
10454  (interactive)
10455  (let ((buffer-read-only nil))
10456    (let ((scored gnus-newsgroup-scored)
10457	  headers h)
10458      (while scored
10459	(unless (gnus-summary-article-header (caar scored))
10460	  (and (setq h (gnus-number-to-header (caar scored)))
10461	       (< (cdar scored) gnus-summary-expunge-below)
10462	       (push h headers)))
10463	(setq scored (cdr scored)))
10464      (if (not headers)
10465	  (when (not no-error)
10466	    (error "No expunged articles hidden"))
10467	(goto-char (point-min))
10468	(push gnus-newsgroup-limit gnus-newsgroup-limits)
10469	(setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10470	(mapcar (lambda (x) (push (mail-header-number x)
10471				  gnus-newsgroup-limit))
10472		headers)
10473	(gnus-summary-prepare-unthreaded (nreverse headers))
10474	(goto-char (point-min))
10475	(gnus-summary-position-point)
10476	t))))
10477
10478(defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10479  "Mark all unread articles in this newsgroup as read.
10480If prefix argument ALL is non-nil, ticked and dormant articles will
10481also be marked as read.
10482If QUIETLY is non-nil, no questions will be asked.
10483
10484If TO-HERE is non-nil, it should be a point in the buffer.  All
10485articles before (after, if REVERSE is set) this point will be marked
10486as read.
10487
10488Note that this function will only catch up the unread article
10489in the current summary buffer limitation.
10490
10491The number of articles marked as read is returned."
10492  (interactive "P")
10493  (prog1
10494      (save-excursion
10495	(when (or quietly
10496		  (not gnus-interactive-catchup) ;Without confirmation?
10497		  gnus-expert-user
10498		  (gnus-y-or-n-p
10499		   (if all
10500		       "Mark absolutely all articles as read? "
10501		     "Mark all unread articles as read? ")))
10502	  (if (and not-mark
10503		   (not gnus-newsgroup-adaptive)
10504		   (not gnus-newsgroup-auto-expire)
10505		   (not gnus-suppress-duplicates)
10506		   (or (not gnus-use-cache)
10507		       (eq gnus-use-cache 'passive)))
10508	      (progn
10509		(when all
10510		  (setq gnus-newsgroup-marked nil
10511			gnus-newsgroup-spam-marked nil
10512			gnus-newsgroup-dormant nil))
10513		(setq gnus-newsgroup-unreads
10514		      (gnus-sorted-nunion
10515                       (gnus-sorted-intersection gnus-newsgroup-unreads
10516						 gnus-newsgroup-downloadable)
10517                       gnus-newsgroup-unfetched)))
10518	    ;; We actually mark all articles as canceled, which we
10519	    ;; have to do when using auto-expiry or adaptive scoring.
10520	    (gnus-summary-show-all-threads)
10521	    (if (and to-here reverse)
10522		(progn
10523		  (goto-char to-here)
10524		  (gnus-summary-mark-current-read-and-unread-as-read
10525		   gnus-catchup-mark)
10526		  (while (gnus-summary-find-next (not all))
10527		    (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10528	      (when (gnus-summary-first-subject (not all))
10529		(while (and
10530			(if to-here (< (point) to-here) t)
10531			(gnus-summary-mark-article-as-read gnus-catchup-mark)
10532			(gnus-summary-find-next (not all))))))
10533	    (gnus-set-mode-line 'summary))
10534	  t))
10535    (gnus-summary-position-point)))
10536
10537(defun gnus-summary-catchup-to-here (&optional all)
10538  "Mark all unticked articles before the current one as read.
10539If ALL is non-nil, also mark ticked and dormant articles as read."
10540  (interactive "P")
10541  (save-excursion
10542    (gnus-save-hidden-threads
10543      (let ((beg (point)))
10544	;; We check that there are unread articles.
10545	(when (or all (gnus-summary-find-prev))
10546	  (gnus-summary-catchup all t beg)))))
10547  (gnus-summary-position-point))
10548
10549(defun gnus-summary-catchup-from-here (&optional all)
10550  "Mark all unticked articles after (and including) the current one as read.
10551If ALL is non-nil, also mark ticked and dormant articles as read."
10552  (interactive "P")
10553  (save-excursion
10554    (gnus-save-hidden-threads
10555      (let ((beg (point)))
10556	;; We check that there are unread articles.
10557	(when (or all (gnus-summary-find-next))
10558	  (gnus-summary-catchup all t beg nil t)))))
10559  (gnus-summary-position-point))
10560
10561(defun gnus-summary-catchup-all (&optional quietly)
10562  "Mark all articles in this newsgroup as read.
10563This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10564instead, which marks only unread articles as read."
10565  (interactive "P")
10566  (gnus-summary-catchup t quietly))
10567
10568(defun gnus-summary-catchup-and-exit (&optional all quietly)
10569  "Mark all unread articles in this group as read, then exit.
10570If prefix argument ALL is non-nil, all articles are marked as read.
10571If QUIETLY is non-nil, no questions will be asked."
10572  (interactive "P")
10573  (when (gnus-summary-catchup all quietly nil 'fast)
10574    ;; Select next newsgroup or exit.
10575    (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10576	     (eq gnus-auto-select-next 'quietly))
10577	(gnus-summary-next-group nil)
10578      (gnus-summary-exit))))
10579
10580(defun gnus-summary-catchup-all-and-exit (&optional quietly)
10581  "Mark all articles in this newsgroup as read, and then exit.
10582This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10583instead, which marks only unread articles as read."
10584  (interactive "P")
10585  (gnus-summary-catchup-and-exit t quietly))
10586
10587(defun gnus-summary-catchup-and-goto-next-group (&optional all)
10588  "Mark all articles in this group as read and select the next group.
10589If given a prefix, mark all articles, unread as well as ticked, as
10590read."
10591  (interactive "P")
10592  (save-excursion
10593    (gnus-summary-catchup all))
10594  (gnus-summary-next-group))
10595
10596;;;
10597;;; with article
10598;;;
10599
10600(defmacro gnus-with-article (article &rest forms)
10601  "Select ARTICLE and perform FORMS in the original article buffer.
10602Then replace the article with the result."
10603  `(progn
10604     ;; We don't want the article to be marked as read.
10605     (let (gnus-mark-article-hook)
10606       (gnus-summary-select-article t t nil ,article))
10607     (set-buffer gnus-original-article-buffer)
10608     ,@forms
10609     (if (not (gnus-check-backend-function
10610	       'request-replace-article (car gnus-article-current)))
10611	 (gnus-message 5 "Read-only group; not replacing")
10612       (unless (gnus-request-replace-article
10613		,article (car gnus-article-current)
10614		(current-buffer) t)
10615	 (error "Couldn't replace article")))
10616     ;; The cache and backlog have to be flushed somewhat.
10617     (when gnus-keep-backlog
10618       (gnus-backlog-remove-article
10619	(car gnus-article-current) (cdr gnus-article-current)))
10620     (when gnus-use-cache
10621       (gnus-cache-update-article
10622	(car gnus-article-current) (cdr gnus-article-current)))))
10623
10624(put 'gnus-with-article 'lisp-indent-function 1)
10625(put 'gnus-with-article 'edebug-form-spec '(form body))
10626
10627;; Thread-based commands.
10628
10629(defun gnus-summary-articles-in-thread (&optional article)
10630  "Return a list of all articles in the current thread.
10631If ARTICLE is non-nil, return all articles in the thread that starts
10632with that article."
10633  (let* ((article (or article (gnus-summary-article-number)))
10634	 (data (gnus-data-find-list article))
10635	 (top-level (gnus-data-level (car data)))
10636	 (top-subject
10637	  (cond ((null gnus-thread-operation-ignore-subject)
10638		 (gnus-simplify-subject-re
10639		  (mail-header-subject (gnus-data-header (car data)))))
10640		((eq gnus-thread-operation-ignore-subject 'fuzzy)
10641		 (gnus-simplify-subject-fuzzy
10642		  (mail-header-subject (gnus-data-header (car data)))))
10643		(t nil)))
10644	 (end-point (save-excursion
10645		      (if (gnus-summary-go-to-next-thread)
10646			  (point) (point-max))))
10647	 articles)
10648    (while (and data
10649		(< (gnus-data-pos (car data)) end-point))
10650      (when (or (not top-subject)
10651		(string= top-subject
10652			 (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10653			     (gnus-simplify-subject-fuzzy
10654			      (mail-header-subject
10655			       (gnus-data-header (car data))))
10656			   (gnus-simplify-subject-re
10657			    (mail-header-subject
10658			     (gnus-data-header (car data)))))))
10659	(push (gnus-data-number (car data)) articles))
10660      (unless (and (setq data (cdr data))
10661		   (> (gnus-data-level (car data)) top-level))
10662	(setq data nil)))
10663    ;; Return the list of articles.
10664    (nreverse articles)))
10665
10666(defun gnus-summary-rethread-current ()
10667  "Rethread the thread the current article is part of."
10668  (interactive)
10669  (let* ((gnus-show-threads t)
10670	 (article (gnus-summary-article-number))
10671	 (id (mail-header-id (gnus-summary-article-header)))
10672	 (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10673    (unless id
10674      (error "No article on the current line"))
10675    (gnus-rebuild-thread id)
10676    (gnus-summary-goto-subject article)))
10677
10678(defun gnus-summary-reparent-thread ()
10679  "Make the current article child of the marked (or previous) article.
10680
10681Note that the re-threading will only work if `gnus-thread-ignore-subject'
10682is non-nil or the Subject: of both articles are the same."
10683  (interactive)
10684  (unless (not (gnus-group-read-only-p))
10685    (error "The current newsgroup does not support article editing"))
10686  (unless (<= (length gnus-newsgroup-processable) 1)
10687    (error "No more than one article may be marked"))
10688  (save-window-excursion
10689    (let ((gnus-article-buffer " *reparent*")
10690	  (current-article (gnus-summary-article-number))
10691	  ;; First grab the marked article, otherwise one line up.
10692	  (parent-article (if (not (null gnus-newsgroup-processable))
10693			      (car gnus-newsgroup-processable)
10694			    (save-excursion
10695			      (if (eq (forward-line -1) 0)
10696				  (gnus-summary-article-number)
10697				(error "Beginning of summary buffer"))))))
10698      (unless (not (eq current-article parent-article))
10699	(error "An article may not be self-referential"))
10700      (let ((message-id (mail-header-id
10701			 (gnus-summary-article-header parent-article))))
10702	(unless (and message-id (not (equal message-id "")))
10703	  (error "No message-id in desired parent"))
10704	(gnus-with-article current-article
10705	  (save-restriction
10706	    (goto-char (point-min))
10707	    (message-narrow-to-head)
10708	    (if (re-search-forward "^References: " nil t)
10709		(progn
10710		  (re-search-forward "^[^ \t]" nil t)
10711		  (forward-line -1)
10712		  (end-of-line)
10713		  (insert " " message-id))
10714	      (insert "References: " message-id "\n"))))
10715	(set-buffer gnus-summary-buffer)
10716	(gnus-summary-unmark-all-processable)
10717	(gnus-summary-update-article current-article)
10718	(if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10719	    (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10720	(gnus-summary-rethread-current)
10721	(gnus-message 3 "Article %d is now the child of article %d"
10722		      current-article parent-article)))))
10723
10724(defun gnus-summary-toggle-threads (&optional arg)
10725  "Toggle showing conversation threads.
10726If ARG is positive number, turn showing conversation threads on."
10727  (interactive "P")
10728  (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10729    (setq gnus-show-threads
10730	  (if (null arg) (not gnus-show-threads)
10731	    (> (prefix-numeric-value arg) 0)))
10732    (gnus-summary-prepare)
10733    (gnus-summary-goto-subject current)
10734    (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10735    (gnus-summary-position-point)))
10736
10737(defun gnus-summary-show-all-threads ()
10738  "Show all threads."
10739  (interactive)
10740  (save-excursion
10741    (let ((buffer-read-only nil))
10742      (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10743  (gnus-summary-position-point))
10744
10745(defun gnus-summary-show-thread ()
10746  "Show thread subtrees.
10747Returns nil if no thread was there to be shown."
10748  (interactive)
10749  (let ((buffer-read-only nil)
10750	(orig (point))
10751	(end (gnus-point-at-eol))
10752	;; Leave point at bol
10753	(beg (progn (beginning-of-line) (point))))
10754    (prog1
10755	;; Any hidden lines here?
10756	(search-forward "\r" end t)
10757      (subst-char-in-region beg end ?\^M ?\n t)
10758      (goto-char orig)
10759      (gnus-summary-position-point))))
10760
10761(defun gnus-summary-maybe-hide-threads ()
10762  "If requested, hide the threads that should be hidden."
10763  (when (and gnus-show-threads
10764	     gnus-thread-hide-subtree)
10765    (gnus-summary-hide-all-threads
10766     (if (or (consp gnus-thread-hide-subtree)
10767	     (functionp gnus-thread-hide-subtree))
10768	 (gnus-make-predicate gnus-thread-hide-subtree)
10769       nil))))
10770
10771;;; Hiding predicates.
10772
10773(defun gnus-article-unread-p (header)
10774  (memq (mail-header-number header) gnus-newsgroup-unreads))
10775
10776(defun gnus-article-unseen-p (header)
10777  (memq (mail-header-number header) gnus-newsgroup-unseen))
10778
10779(defun gnus-map-articles (predicate articles)
10780  "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10781  (apply 'gnus-or (mapcar predicate
10782			  (mapcar (lambda (number)
10783				    (gnus-summary-article-header number))
10784				  articles))))
10785
10786(defun gnus-summary-hide-all-threads (&optional predicate)
10787  "Hide all thread subtrees.
10788If PREDICATE is supplied, threads that satisfy this predicate
10789will not be hidden."
10790  (interactive)
10791  (save-excursion
10792    (goto-char (point-min))
10793    (let ((end nil))
10794      (while (not end)
10795	(when (or (not predicate)
10796		  (gnus-map-articles
10797		   predicate (gnus-summary-article-children)))
10798	    (gnus-summary-hide-thread))
10799	(setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10800  (gnus-summary-position-point))
10801
10802(defun gnus-summary-hide-thread ()
10803  "Hide thread subtrees.
10804If PREDICATE is supplied, threads that satisfy this predicate
10805will not be hidden.
10806Returns nil if no threads were there to be hidden."
10807  (interactive)
10808  (let ((buffer-read-only nil)
10809	(start (point))
10810	(article (gnus-summary-article-number)))
10811    (goto-char start)
10812    ;; Go forward until either the buffer ends or the subthread
10813    ;; ends.
10814    (when (and (not (eobp))
10815	       (or (zerop (gnus-summary-next-thread 1 t))
10816		   (goto-char (point-max))))
10817      (prog1
10818	  (if (and (> (point) start)
10819		   (search-backward "\n" start t))
10820	      (progn
10821		(subst-char-in-region start (point) ?\n ?\^M)
10822		(gnus-summary-goto-subject article))
10823	    (goto-char start)
10824	    nil)))))
10825
10826(defun gnus-summary-go-to-next-thread (&optional previous)
10827  "Go to the same level (or less) next thread.
10828If PREVIOUS is non-nil, go to previous thread instead.
10829Return the article number moved to, or nil if moving was impossible."
10830  (let ((level (gnus-summary-thread-level))
10831	(way (if previous -1 1))
10832	(beg (point)))
10833    (forward-line way)
10834    (while (and (not (eobp))
10835		(< level (gnus-summary-thread-level)))
10836      (forward-line way))
10837    (if (eobp)
10838	(progn
10839	  (goto-char beg)
10840	  nil)
10841      (setq beg (point))
10842      (prog1
10843	  (gnus-summary-article-number)
10844	(goto-char beg)))))
10845
10846(defun gnus-summary-next-thread (n &optional silent)
10847  "Go to the same level next N'th thread.
10848If N is negative, search backward instead.
10849Returns the difference between N and the number of skips actually
10850done.
10851
10852If SILENT, don't output messages."
10853  (interactive "p")
10854  (let ((backward (< n 0))
10855	(n (abs n)))
10856    (while (and (> n 0)
10857		(gnus-summary-go-to-next-thread backward))
10858      (decf n))
10859    (unless silent
10860      (gnus-summary-position-point))
10861    (when (and (not silent) (/= 0 n))
10862      (gnus-message 7 "No more threads"))
10863    n))
10864
10865(defun gnus-summary-prev-thread (n)
10866  "Go to the same level previous N'th thread.
10867Returns the difference between N and the number of skips actually
10868done."
10869  (interactive "p")
10870  (gnus-summary-next-thread (- n)))
10871
10872(defun gnus-summary-go-down-thread ()
10873  "Go down one level in the current thread."
10874  (let ((children (gnus-summary-article-children)))
10875    (when children
10876      (gnus-summary-goto-subject (car children)))))
10877
10878(defun gnus-summary-go-up-thread ()
10879  "Go up one level in the current thread."
10880  (let ((parent (gnus-summary-article-parent)))
10881    (when parent
10882      (gnus-summary-goto-subject parent))))
10883
10884(defun gnus-summary-down-thread (n)
10885  "Go down thread N steps.
10886If N is negative, go up instead.
10887Returns the difference between N and how many steps down that were
10888taken."
10889  (interactive "p")
10890  (let ((up (< n 0))
10891	(n (abs n)))
10892    (while (and (> n 0)
10893		(if up (gnus-summary-go-up-thread)
10894		  (gnus-summary-go-down-thread)))
10895      (setq n (1- n)))
10896    (gnus-summary-position-point)
10897    (when (/= 0 n)
10898      (gnus-message 7 "Can't go further"))
10899    n))
10900
10901(defun gnus-summary-up-thread (n)
10902  "Go up thread N steps.
10903If N is negative, go down instead.
10904Returns the difference between N and how many steps down that were
10905taken."
10906  (interactive "p")
10907  (gnus-summary-down-thread (- n)))
10908
10909(defun gnus-summary-top-thread ()
10910  "Go to the top of the thread."
10911  (interactive)
10912  (while (gnus-summary-go-up-thread))
10913  (gnus-summary-article-number))
10914
10915(defun gnus-summary-kill-thread (&optional unmark)
10916  "Mark articles under current thread as read.
10917If the prefix argument is positive, remove any kinds of marks.
10918If the prefix argument is negative, tick articles instead."
10919  (interactive "P")
10920  (when unmark
10921    (setq unmark (prefix-numeric-value unmark)))
10922  (let ((articles (gnus-summary-articles-in-thread)))
10923    (save-excursion
10924      ;; Expand the thread.
10925      (gnus-summary-show-thread)
10926      ;; Mark all the articles.
10927      (while articles
10928	(gnus-summary-goto-subject (car articles))
10929	(cond ((null unmark)
10930	       (gnus-summary-mark-article-as-read gnus-killed-mark))
10931	      ((> unmark 0)
10932	       (gnus-summary-mark-article-as-unread gnus-unread-mark))
10933	      (t
10934	       (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10935	(setq articles (cdr articles))))
10936    ;; Hide killed subtrees.
10937    (and (null unmark)
10938	 gnus-thread-hide-killed
10939	 (gnus-summary-hide-thread))
10940    ;; If marked as read, go to next unread subject.
10941    (when (null unmark)
10942      ;; Go to next unread subject.
10943      (gnus-summary-next-subject 1 t)))
10944  (gnus-set-mode-line 'summary))
10945
10946;; Summary sorting commands
10947
10948(defun gnus-summary-sort-by-number (&optional reverse)
10949  "Sort the summary buffer by article number.
10950Argument REVERSE means reverse order."
10951  (interactive "P")
10952  (gnus-summary-sort 'number reverse))
10953
10954(defun gnus-summary-sort-by-random (&optional reverse)
10955  "Randomize the order in the summary buffer.
10956Argument REVERSE means to randomize in reverse order."
10957  (interactive "P")
10958  (gnus-summary-sort 'random reverse))
10959
10960(defun gnus-summary-sort-by-author (&optional reverse)
10961  "Sort the summary buffer by author name alphabetically.
10962If `case-fold-search' is non-nil, case of letters is ignored.
10963Argument REVERSE means reverse order."
10964  (interactive "P")
10965  (gnus-summary-sort 'author reverse))
10966
10967(defun gnus-summary-sort-by-subject (&optional reverse)
10968  "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10969If `case-fold-search' is non-nil, case of letters is ignored.
10970Argument REVERSE means reverse order."
10971  (interactive "P")
10972  (gnus-summary-sort 'subject reverse))
10973
10974(defun gnus-summary-sort-by-date (&optional reverse)
10975  "Sort the summary buffer by date.
10976Argument REVERSE means reverse order."
10977  (interactive "P")
10978  (gnus-summary-sort 'date reverse))
10979
10980(defun gnus-summary-sort-by-score (&optional reverse)
10981  "Sort the summary buffer by score.
10982Argument REVERSE means reverse order."
10983  (interactive "P")
10984  (gnus-summary-sort 'score reverse))
10985
10986(defun gnus-summary-sort-by-lines (&optional reverse)
10987  "Sort the summary buffer by the number of lines.
10988Argument REVERSE means reverse order."
10989  (interactive "P")
10990  (gnus-summary-sort 'lines reverse))
10991
10992(defun gnus-summary-sort-by-chars (&optional reverse)
10993  "Sort the summary buffer by article length.
10994Argument REVERSE means reverse order."
10995  (interactive "P")
10996  (gnus-summary-sort 'chars reverse))
10997
10998(defun gnus-summary-sort-by-original (&optional reverse)
10999  "Sort the summary buffer using the default sorting method.
11000Argument REVERSE means reverse order."
11001  (interactive "P")
11002  (let* ((buffer-read-only)
11003	 (gnus-summary-prepare-hook nil))
11004    ;; We do the sorting by regenerating the threads.
11005    (gnus-summary-prepare)
11006    ;; Hide subthreads if needed.
11007    (gnus-summary-maybe-hide-threads)))
11008
11009(defun gnus-summary-sort (predicate reverse)
11010  "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11011  (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11012	 (article (intern (format "gnus-article-sort-by-%s" predicate)))
11013	 (gnus-thread-sort-functions
11014	  (if (not reverse)
11015	      thread
11016	    `(lambda (t1 t2)
11017	       (,thread t2 t1))))
11018	 (gnus-sort-gathered-threads-function
11019	  gnus-thread-sort-functions)
11020	 (gnus-article-sort-functions
11021	  (if (not reverse)
11022	      article
11023	    `(lambda (t1 t2)
11024	       (,article t2 t1))))
11025	 (buffer-read-only)
11026	 (gnus-summary-prepare-hook nil))
11027    ;; We do the sorting by regenerating the threads.
11028    (gnus-summary-prepare)
11029    ;; Hide subthreads if needed.
11030    (gnus-summary-maybe-hide-threads)))
11031
11032;; Summary saving commands.
11033
11034(defun gnus-summary-save-article (&optional n not-saved)
11035  "Save the current article using the default saver function.
11036If N is a positive number, save the N next articles.
11037If N is a negative number, save the N previous articles.
11038If N is nil and any articles have been marked with the process mark,
11039save those articles instead.
11040The variable `gnus-default-article-saver' specifies the saver function.
11041
11042If the optional second argument NOT-SAVED is non-nil, articles saved
11043will not be marked as saved."
11044  (interactive "P")
11045  (require 'gnus-art)
11046  (let* ((articles (gnus-summary-work-articles n))
11047	 (save-buffer (save-excursion
11048			(nnheader-set-temp-buffer " *Gnus Save*")))
11049	 (num (length articles))
11050	 ;; Whether to save decoded articles or raw articles.
11051	 (decode (when gnus-article-save-coding-system
11052		   (get gnus-default-article-saver :decode)))
11053	 ;; When saving many articles in a single file, use the other
11054	 ;; function to save articles other than the first one.
11055	 (saver2 (get gnus-default-article-saver :function))
11056	 (gnus-prompt-before-saving (if saver2
11057					t
11058				      gnus-prompt-before-saving))
11059	 (gnus-default-article-saver gnus-default-article-saver)
11060	 header file)
11061    (dolist (article articles)
11062      (setq header (gnus-summary-article-header article))
11063      (if (not (vectorp header))
11064	  ;; This is a pseudo-article.
11065	  (if (assq 'name header)
11066	      (gnus-copy-file (cdr (assq 'name header)))
11067	    (gnus-message 1 "Article %d is unsaveable" article))
11068	;; This is a real article.
11069	(save-window-excursion
11070	  (let ((gnus-display-mime-function (when decode
11071					      gnus-display-mime-function))
11072		(gnus-article-prepare-hook (when decode
11073					     gnus-article-prepare-hook)))
11074	    (gnus-summary-select-article t nil nil article)
11075	    (gnus-summary-goto-subject article)))
11076	(save-excursion
11077	  (set-buffer save-buffer)
11078	  (erase-buffer)
11079	  (insert-buffer-substring (if decode
11080				       gnus-article-buffer
11081				     gnus-original-article-buffer)))
11082	(setq file (gnus-article-save save-buffer file num))
11083	(gnus-summary-remove-process-mark article)
11084	(unless not-saved
11085	  (gnus-summary-set-saved-mark article)))
11086      (when saver2
11087	(setq gnus-default-article-saver saver2
11088	      saver2 nil)))
11089    (gnus-kill-buffer save-buffer)
11090    (gnus-summary-position-point)
11091    (gnus-set-mode-line 'summary)
11092    n))
11093
11094(defun gnus-summary-pipe-output (&optional arg headers)
11095  "Pipe the current article to a subprocess.
11096If N is a positive number, pipe the N next articles.
11097If N is a negative number, pipe the N previous articles.
11098If N is nil and any articles have been marked with the process mark,
11099pipe those articles instead.
11100If HEADERS (the symbolic prefix), include the headers, too."
11101  (interactive (gnus-interactive "P\ny"))
11102  (require 'gnus-art)
11103  (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11104	(gnus-save-all-headers (or headers gnus-save-all-headers)))
11105    (gnus-summary-save-article arg t))
11106  (let ((buffer (get-buffer "*Shell Command Output*")))
11107    (when (and buffer
11108	       (not (zerop (buffer-size buffer))))
11109      (gnus-configure-windows 'pipe))))
11110
11111(defun gnus-summary-save-article-mail (&optional arg)
11112  "Append the current article to a Unix mail box file.
11113If N is a positive number, save the N next articles.
11114If N is a negative number, save the N previous articles.
11115If N is nil and any articles have been marked with the process mark,
11116save those articles instead."
11117  (interactive "P")
11118  (require 'gnus-art)
11119  (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11120    (gnus-summary-save-article arg)))
11121
11122(defun gnus-summary-save-article-rmail (&optional arg)
11123  "Append the current article to an rmail file.
11124If N is a positive number, save the N next articles.
11125If N is a negative number, save the N previous articles.
11126If N is nil and any articles have been marked with the process mark,
11127save those articles instead."
11128  (interactive "P")
11129  (require 'gnus-art)
11130  (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11131    (gnus-summary-save-article arg)))
11132
11133(defun gnus-summary-save-article-file (&optional arg)
11134  "Append the current article to a file.
11135If N is a positive number, save the N next articles.
11136If N is a negative number, save the N previous articles.
11137If N is nil and any articles have been marked with the process mark,
11138save those articles instead."
11139  (interactive "P")
11140  (require 'gnus-art)
11141  (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11142    (gnus-summary-save-article arg)))
11143
11144(defun gnus-summary-write-article-file (&optional arg)
11145  "Write the current article to a file, deleting the previous file.
11146If N is a positive number, save the N next articles.
11147If N is a negative number, save the N previous articles.
11148If N is nil and any articles have been marked with the process mark,
11149save those articles instead."
11150  (interactive "P")
11151  (require 'gnus-art)
11152  (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11153    (gnus-summary-save-article arg)))
11154
11155(defun gnus-summary-save-article-body-file (&optional arg)
11156  "Append the current article body to a file.
11157If N is a positive number, save the N next articles.
11158If N is a negative number, save the N previous articles.
11159If N is nil and any articles have been marked with the process mark,
11160save those articles instead."
11161  (interactive "P")
11162  (require 'gnus-art)
11163  (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11164    (gnus-summary-save-article arg)))
11165
11166(defun gnus-summary-write-article-body-file (&optional arg)
11167  "Write the current article body to a file, deleting the previous file.
11168If N is a positive number, save the N next articles.
11169If N is a negative number, save the N previous articles.
11170If N is nil and any articles have been marked with the process mark,
11171save those articles instead."
11172  (interactive "P")
11173  (require 'gnus-art)
11174  (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11175    (gnus-summary-save-article arg)))
11176
11177(defun gnus-summary-muttprint (&optional arg)
11178  "Print the current article using Muttprint.
11179If N is a positive number, save the N next articles.
11180If N is a negative number, save the N previous articles.
11181If N is nil and any articles have been marked with the process mark,
11182save those articles instead."
11183  (interactive "P")
11184  (require 'gnus-art)
11185  (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11186    (gnus-summary-save-article arg t)))
11187
11188(defun gnus-summary-pipe-message (program)
11189  "Pipe the current article through PROGRAM."
11190  (interactive "sProgram: ")
11191  (gnus-summary-select-article)
11192  (let ((mail-header-separator ""))
11193    (gnus-eval-in-buffer-window gnus-article-buffer
11194      (save-restriction
11195	(widen)
11196	(let ((start (window-start))
11197	      buffer-read-only)
11198	  (message-pipe-buffer-body program)
11199	  (set-window-start (get-buffer-window (current-buffer)) start))))))
11200
11201(defun gnus-get-split-value (methods)
11202  "Return a value based on the split METHODS."
11203  (let (split-name method result match)
11204    (when methods
11205      (save-excursion
11206	(set-buffer gnus-original-article-buffer)
11207	(save-restriction
11208	  (nnheader-narrow-to-headers)
11209	  (while (and methods (not split-name))
11210	    (goto-char (point-min))
11211	    (setq method (pop methods))
11212	    (setq match (car method))
11213	    (when (cond
11214		   ((stringp match)
11215		    ;; Regular expression.
11216		    (ignore-errors
11217		      (re-search-forward match nil t)))
11218		   ((functionp match)
11219		    ;; Function.
11220		    (save-restriction
11221		      (widen)
11222		      (setq result (funcall match gnus-newsgroup-name))))
11223		   ((consp match)
11224		    ;; Form.
11225		    (save-restriction
11226		      (widen)
11227		      (setq result (eval match)))))
11228	      (setq split-name (cdr method))
11229	      (cond ((stringp result)
11230		     (push (expand-file-name
11231			    result gnus-article-save-directory)
11232			   split-name))
11233		    ((consp result)
11234		     (setq split-name (append result split-name)))))))))
11235    (nreverse split-name)))
11236
11237(defun gnus-valid-move-group-p (group)
11238  (and (boundp group)
11239       (symbol-name group)
11240       (symbol-value group)
11241       (gnus-get-function (gnus-find-method-for-group
11242			   (symbol-name group)) 'request-accept-article t)))
11243
11244(defun gnus-read-move-group-name (prompt default articles prefix)
11245  "Read a group name."
11246  (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11247	 (minibuffer-confirm-incomplete nil) ; XEmacs
11248	 (prom
11249	  (format "%s %s to"
11250		  prompt
11251		  (if (> (length articles) 1)
11252		      (format "these %d articles" (length articles))
11253		    "this article")))
11254	 (to-newsgroup
11255	  (cond
11256	   ((null split-name)
11257	    (gnus-completing-read-with-default
11258	     default prom
11259	     gnus-active-hashtb
11260	     'gnus-valid-move-group-p
11261	     nil prefix
11262	     'gnus-group-history))
11263	   ((= 1 (length split-name))
11264	    (gnus-completing-read-with-default
11265	     (car split-name) prom
11266	     gnus-active-hashtb
11267	     'gnus-valid-move-group-p
11268	     nil nil
11269	     'gnus-group-history))
11270	   (t
11271	    (gnus-completing-read-with-default
11272	     nil prom
11273	     (mapcar (lambda (el) (list el))
11274		     (nreverse split-name))
11275	     nil nil nil
11276	     'gnus-group-history))))
11277	 (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11278    (when to-newsgroup
11279      (if (or (string= to-newsgroup "")
11280	      (string= to-newsgroup prefix))
11281	  (setq to-newsgroup default))
11282      (unless to-newsgroup
11283	(error "No group name entered"))
11284      (or (gnus-active to-newsgroup)
11285	  (gnus-activate-group to-newsgroup nil nil to-method)
11286	  (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11287				     to-newsgroup))
11288	      (or (and (gnus-request-create-group to-newsgroup to-method)
11289		       (gnus-activate-group
11290			to-newsgroup nil nil to-method)
11291		       (gnus-subscribe-group to-newsgroup))
11292		  (error "Couldn't create group %s" to-newsgroup)))
11293	  (error "No such group: %s" to-newsgroup)))
11294    to-newsgroup))
11295
11296(defun gnus-summary-save-parts (type dir n &optional reverse)
11297  "Save parts matching TYPE to DIR.
11298If REVERSE, save parts that do not match TYPE."
11299  (interactive
11300   (list (read-string "Save parts of type: "
11301		      (or (car gnus-summary-save-parts-type-history)
11302			  gnus-summary-save-parts-default-mime)
11303		      'gnus-summary-save-parts-type-history)
11304	 (setq gnus-summary-save-parts-last-directory
11305	       (read-file-name "Save to directory: "
11306			       gnus-summary-save-parts-last-directory
11307			       nil t))
11308	 current-prefix-arg))
11309  (gnus-summary-iterate n
11310    (let ((gnus-display-mime-function nil)
11311	  (gnus-inhibit-treatment t))
11312      (gnus-summary-select-article))
11313    (save-excursion
11314      (set-buffer gnus-article-buffer)
11315      (let ((handles (or gnus-article-mime-handles
11316			 (mm-dissect-buffer nil gnus-article-loose-mime)
11317			 (and gnus-article-emulate-mime
11318			      (mm-uu-dissect)))))
11319	(when handles
11320	  (gnus-summary-save-parts-1 type dir handles reverse)
11321	  (unless gnus-article-mime-handles ;; Don't destroy this case.
11322	    (mm-destroy-parts handles)))))))
11323
11324(defun gnus-summary-save-parts-1 (type dir handle reverse)
11325  (if (stringp (car handle))
11326      (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11327	      (cdr handle))
11328    (when (if reverse
11329	      (not (string-match type (mm-handle-media-type handle)))
11330	    (string-match type (mm-handle-media-type handle)))
11331      (let ((file (expand-file-name
11332		   (gnus-map-function
11333		    mm-file-name-rewrite-functions
11334		    (file-name-nondirectory
11335		     (or
11336		      (mail-content-type-get
11337		       (mm-handle-disposition handle) 'filename)
11338		      (mail-content-type-get
11339		       (mm-handle-type handle) 'name)
11340		      (concat gnus-newsgroup-name
11341			      "." (number-to-string
11342				   (cdr gnus-article-current))))))
11343		   dir)))
11344	(unless (file-exists-p file)
11345	  (mm-save-part-to-file handle file))))))
11346
11347;; Summary extract commands
11348
11349(defun gnus-summary-insert-pseudos (pslist &optional not-view)
11350  (let ((buffer-read-only nil)
11351	(article (gnus-summary-article-number))
11352	after-article b e)
11353    (unless (gnus-summary-goto-subject article)
11354      (error "No such article: %d" article))
11355    (gnus-summary-position-point)
11356    ;; If all commands are to be bunched up on one line, we collect
11357    ;; them here.
11358    (unless gnus-view-pseudos-separately
11359      (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11360	    files action)
11361	(while ps
11362	  (setq action (cdr (assq 'action (car ps))))
11363	  (setq files (list (cdr (assq 'name (car ps)))))
11364	  (while (and ps (cdr ps)
11365		      (string= (or action "1")
11366			       (or (cdr (assq 'action (cadr ps))) "2")))
11367	    (push (cdr (assq 'name (cadr ps))) files)
11368	    (setcdr ps (cddr ps)))
11369	  (when files
11370	    (when (not (string-match "%s" action))
11371	      (push " " files))
11372	    (push " " files)
11373	    (when (assq 'execute (car ps))
11374	      (setcdr (assq 'execute (car ps))
11375		      (funcall (if (string-match "%s" action)
11376				   'format 'concat)
11377			       action
11378			       (mapconcat
11379				(lambda (f)
11380				  (if (equal f " ")
11381				      f
11382				    (mm-quote-arg f)))
11383				files " ")))))
11384	  (setq ps (cdr ps)))))
11385    (if (and gnus-view-pseudos (not not-view))
11386	(while pslist
11387	  (when (assq 'execute (car pslist))
11388	    (gnus-execute-command (cdr (assq 'execute (car pslist)))
11389				  (eq gnus-view-pseudos 'not-confirm)))
11390	  (setq pslist (cdr pslist)))
11391      (save-excursion
11392	(while pslist
11393	  (setq after-article (or (cdr (assq 'article (car pslist)))
11394				  (gnus-summary-article-number)))
11395	  (gnus-summary-goto-subject after-article)
11396	  (forward-line 1)
11397	  (setq b (point))
11398	  (insert "    " (file-name-nondirectory
11399			  (cdr (assq 'name (car pslist))))
11400		  ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11401	  (setq e (point))
11402	  (forward-line -1)		; back to `b'
11403	  (gnus-add-text-properties
11404	   b (1- e) (list 'gnus-number gnus-reffed-article-number
11405			  gnus-mouse-face-prop gnus-mouse-face))
11406	  (gnus-data-enter
11407	   after-article gnus-reffed-article-number
11408	   gnus-unread-mark b (car pslist) 0 (- e b))
11409	  (setq gnus-newsgroup-unreads
11410		(gnus-add-to-sorted-list gnus-newsgroup-unreads
11411					 gnus-reffed-article-number))
11412	  (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11413	  (setq pslist (cdr pslist)))))))
11414
11415(defun gnus-pseudos< (p1 p2)
11416  (let ((c1 (cdr (assq 'action p1)))
11417	(c2 (cdr (assq 'action p2))))
11418    (and c1 c2 (string< c1 c2))))
11419
11420(defun gnus-request-pseudo-article (props)
11421  (cond ((assq 'execute props)
11422	 (gnus-execute-command (cdr (assq 'execute props)))))
11423  (let ((gnus-current-article (gnus-summary-article-number)))
11424    (gnus-run-hooks 'gnus-mark-article-hook)))
11425
11426(defun gnus-execute-command (command &optional automatic)
11427  (save-excursion
11428    (gnus-article-setup-buffer)
11429    (set-buffer gnus-article-buffer)
11430    (setq buffer-read-only nil)
11431    (let ((command (if automatic command
11432		     (read-string "Command: " (cons command 0)))))
11433      (erase-buffer)
11434      (insert "$ " command "\n\n")
11435      (if gnus-view-pseudo-asynchronously
11436	  (start-process "gnus-execute" (current-buffer) shell-file-name
11437			 shell-command-switch command)
11438	(call-process shell-file-name nil t nil
11439		      shell-command-switch command)))))
11440
11441;; Summary kill commands.
11442
11443(defun gnus-summary-edit-global-kill (article)
11444  "Edit the \"global\" kill file."
11445  (interactive (list (gnus-summary-article-number)))
11446  (gnus-group-edit-global-kill article))
11447
11448(defun gnus-summary-edit-local-kill ()
11449  "Edit a local kill file applied to the current newsgroup."
11450  (interactive)
11451  (setq gnus-current-headers (gnus-summary-article-header))
11452  (gnus-group-edit-local-kill
11453   (gnus-summary-article-number) gnus-newsgroup-name))
11454
11455;;; Header reading.
11456
11457(defun gnus-read-header (id &optional header)
11458  "Read the headers of article ID and enter them into the Gnus system."
11459  (let ((group gnus-newsgroup-name)
11460	(gnus-override-method
11461	 (or
11462	  gnus-override-method
11463	  (and (gnus-news-group-p gnus-newsgroup-name)
11464	       (car (gnus-refer-article-methods)))))
11465	where)
11466    ;; First we check to see whether the header in question is already
11467    ;; fetched.
11468    (if (stringp id)
11469	;; This is a Message-ID.
11470	(setq header (or header (gnus-id-to-header id)))
11471      ;; This is an article number.
11472      (setq header (or header (gnus-summary-article-header id))))
11473    (if (and header
11474	     (not (gnus-summary-article-sparse-p (mail-header-number header))))
11475	;; We have found the header.
11476	header
11477      ;; We have to really fetch the header to this article.
11478      (save-excursion
11479	(set-buffer nntp-server-buffer)
11480	(when (setq where (gnus-request-head id group))
11481	  (nnheader-fold-continuation-lines)
11482	  (goto-char (point-max))
11483	  (insert ".\n")
11484	  (goto-char (point-min))
11485	  (insert "211 ")
11486	  (princ (cond
11487		  ((numberp id) id)
11488		  ((cdr where) (cdr where))
11489		  (header (mail-header-number header))
11490		  (t gnus-reffed-article-number))
11491		 (current-buffer))
11492	  (insert " Article retrieved.\n"))
11493	(if (or (not where)
11494		(not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11495	    ()				; Malformed head.
11496	  (unless (gnus-summary-article-sparse-p (mail-header-number header))
11497	    (when (and (stringp id)
11498		       (not (string= (gnus-group-real-name group)
11499				     (car where))))
11500	      ;; If we fetched by Message-ID and the article came
11501	      ;; from a different group, we fudge some bogus article
11502	      ;; numbers for this article.
11503	      (mail-header-set-number header gnus-reffed-article-number))
11504	    (save-excursion
11505	      (set-buffer gnus-summary-buffer)
11506	      (decf gnus-reffed-article-number)
11507	      (gnus-remove-header (mail-header-number header))
11508	      (push header gnus-newsgroup-headers)
11509	      (setq gnus-current-headers header)
11510	      (push (mail-header-number header) gnus-newsgroup-limit)))
11511	  header)))))
11512
11513(defun gnus-remove-header (number)
11514  "Remove header NUMBER from `gnus-newsgroup-headers'."
11515  (if (and gnus-newsgroup-headers
11516	   (= number (mail-header-number (car gnus-newsgroup-headers))))
11517      (pop gnus-newsgroup-headers)
11518    (let ((headers gnus-newsgroup-headers))
11519      (while (and (cdr headers)
11520		  (not (= number (mail-header-number (cadr headers)))))
11521	(pop headers))
11522      (when (cdr headers)
11523	(setcdr headers (cddr headers))))))
11524
11525;;;
11526;;; summary highlights
11527;;;
11528
11529(defun gnus-highlight-selected-summary ()
11530  "Highlight selected article in summary buffer."
11531  ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11532  (when gnus-summary-selected-face
11533    (save-excursion
11534      (let* ((beg (gnus-point-at-bol))
11535	     (end (gnus-point-at-eol))
11536	     ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11537	     (from (if (get-text-property beg gnus-mouse-face-prop)
11538		       beg
11539		     (or (next-single-property-change
11540			  beg gnus-mouse-face-prop nil end)
11541			 beg)))
11542	     (to
11543	      (if (= from end)
11544		  (- from 2)
11545		(or (next-single-property-change
11546		     from gnus-mouse-face-prop nil end)
11547		    end))))
11548	;; If no mouse-face prop on line we will have to = from = end,
11549	;; so we highlight the entire line instead.
11550	(when (= (+ to 2) from)
11551	  (setq from beg)
11552	  (setq to end))
11553	(if gnus-newsgroup-selected-overlay
11554	    ;; Move old overlay.
11555	    (gnus-move-overlay
11556	     gnus-newsgroup-selected-overlay from to (current-buffer))
11557	  ;; Create new overlay.
11558	  (gnus-overlay-put
11559	   (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11560	   'face gnus-summary-selected-face))))))
11561
11562(defvar gnus-summary-highlight-line-cached nil)
11563(defvar gnus-summary-highlight-line-trigger nil)
11564
11565(defun gnus-summary-highlight-line-0 ()
11566  (if (and (eq gnus-summary-highlight-line-trigger
11567               gnus-summary-highlight)
11568           gnus-summary-highlight-line-cached)
11569      gnus-summary-highlight-line-cached
11570    (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11571          gnus-summary-highlight-line-cached
11572          (let* ((cond (list 'cond))
11573                 (c cond)
11574                 (list gnus-summary-highlight))
11575            (while list
11576              (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11577			      nil))
11578              (setq c (cdr c)
11579                    list (cdr list)))
11580            (gnus-byte-compile (list 'lambda nil cond))))))
11581
11582(defun gnus-summary-highlight-line ()
11583  "Highlight current line according to `gnus-summary-highlight'."
11584  (let* ((beg (gnus-point-at-bol))
11585	 (article (or (gnus-summary-article-number) gnus-current-article))
11586	 (score (or (cdr (assq article
11587			       gnus-newsgroup-scored))
11588		    gnus-summary-default-score 0))
11589	 (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11590	 (inhibit-read-only t)
11591	 (default gnus-summary-default-score)
11592	 (default-high gnus-summary-default-high-score)
11593	 (default-low gnus-summary-default-low-score)
11594	 (uncached (and gnus-summary-use-undownloaded-faces
11595                        (memq article gnus-newsgroup-undownloaded)
11596                        (not (memq article gnus-newsgroup-cached)))))
11597    (let ((face (funcall (gnus-summary-highlight-line-0))))
11598      (unless (eq face (get-text-property beg 'face))
11599	(gnus-put-text-property-excluding-characters-with-faces
11600	 beg (gnus-point-at-eol) 'face
11601	 (setq face (if (boundp face) (symbol-value face) face)))
11602	(when gnus-summary-highlight-line-function
11603	  (funcall gnus-summary-highlight-line-function article face))))))
11604
11605(defun gnus-update-read-articles (group unread &optional compute)
11606  "Update the list of read articles in GROUP.
11607UNREAD is a sorted list."
11608  (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11609	 (entry (gnus-gethash group gnus-newsrc-hashtb))
11610	 (info (nth 2 entry))
11611	 (prev 1)
11612	 read)
11613    (if (or (not info) (not active))
11614	;; There is no info on this group if it was, in fact,
11615	;; killed.  Gnus stores no information on killed groups, so
11616	;; there's nothing to be done.
11617	;; One could store the information somewhere temporarily,
11618	;; perhaps...  Hmmm...
11619	()
11620      ;; Remove any negative articles numbers.
11621      (while (and unread (< (car unread) 0))
11622	(setq unread (cdr unread)))
11623      ;; Remove any expired article numbers
11624      (while (and unread (< (car unread) (car active)))
11625	(setq unread (cdr unread)))
11626      ;; Compute the ranges of read articles by looking at the list of
11627      ;; unread articles.
11628      (while unread
11629	(when (/= (car unread) prev)
11630	  (push (if (= prev (1- (car unread))) prev
11631		  (cons prev (1- (car unread))))
11632		read))
11633	(setq prev (1+ (car unread)))
11634	(setq unread (cdr unread)))
11635      (when (<= prev (cdr active))
11636	(push (cons prev (cdr active)) read))
11637      (setq read (if (> (length read) 1) (nreverse read) read))
11638      (if compute
11639	  read
11640	(save-excursion
11641	  (let (setmarkundo)
11642	    ;; Propagate the read marks to the backend.
11643	    (when (gnus-check-backend-function 'request-set-mark group)
11644	      (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11645		    (add (gnus-remove-from-range read (gnus-info-read info))))
11646		(when (or add del)
11647		  (unless (gnus-check-group group)
11648		    (error "Can't open server for %s" group))
11649		  (gnus-request-set-mark
11650		   group (delq nil (list (if add (list add 'add '(read)))
11651					 (if del (list del 'del '(read))))))
11652		  (setq setmarkundo
11653			`(gnus-request-set-mark
11654			  ,group
11655			  ',(delq nil (list
11656				       (if del (list del 'add '(read)))
11657				       (if add (list add 'del '(read))))))))))
11658	    (set-buffer gnus-group-buffer)
11659	    (gnus-undo-register
11660	      `(progn
11661		 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11662		 (gnus-info-set-read ',info ',(gnus-info-read info))
11663		 (gnus-get-unread-articles-in-group ',info
11664						    (gnus-active ,group))
11665		 (gnus-group-update-group ,group t)
11666		 ,setmarkundo))))
11667	;; Enter this list into the group info.
11668	(gnus-info-set-read info read)
11669	;; Set the number of unread articles in gnus-newsrc-hashtb.
11670	(gnus-get-unread-articles-in-group info (gnus-active group))
11671	t))))
11672
11673(defun gnus-offer-save-summaries ()
11674  "Offer to save all active summary buffers."
11675  (let (buffers)
11676    ;; Go through all buffers and find all summaries.
11677    (dolist (buffer (buffer-list))
11678      (when (and (setq buffer (buffer-name buffer))
11679		 (string-match "Summary" buffer)
11680		 (save-excursion
11681		   (set-buffer buffer)
11682		   ;; We check that this is, indeed, a summary buffer.
11683		   (and (eq major-mode 'gnus-summary-mode)
11684			;; Also make sure this isn't bogus.
11685			gnus-newsgroup-prepared
11686			;; Also make sure that this isn't a
11687			;; dead summary buffer.
11688			(not gnus-dead-summary-mode))))
11689	(push buffer buffers)))
11690    ;; Go through all these summary buffers and offer to save them.
11691    (when buffers
11692      (save-excursion
11693	(map-y-or-n-p
11694	 "Update summary buffer %s? "
11695	 (lambda (buf)
11696	   (switch-to-buffer buf)
11697	   (gnus-summary-exit))
11698	 buffers)))))
11699
11700(defun gnus-summary-setup-default-charset ()
11701  "Setup newsgroup default charset."
11702  (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11703      (setq gnus-newsgroup-charset nil)
11704    (let* ((ignored-charsets
11705	    (or gnus-newsgroup-ephemeral-ignored-charsets
11706		(append
11707		 (and gnus-newsgroup-name
11708		      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11709		 gnus-newsgroup-ignored-charsets))))
11710      (setq gnus-newsgroup-charset
11711	    (or gnus-newsgroup-ephemeral-charset
11712		(and gnus-newsgroup-name
11713		     (gnus-parameter-charset gnus-newsgroup-name))
11714		gnus-default-charset))
11715      (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11716	   ignored-charsets))))
11717
11718;;;
11719;;; Mime Commands
11720;;;
11721
11722(defun gnus-summary-display-buttonized (&optional show-all-parts)
11723  "Display the current article buffer fully MIME-buttonized.
11724If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11725treated as multipart/mixed."
11726  (interactive "P")
11727  (require 'gnus-art)
11728  (let ((gnus-unbuttonized-mime-types nil)
11729	(gnus-mime-display-multipart-as-mixed show-all-parts))
11730    (gnus-summary-show-article)))
11731
11732(defun gnus-summary-repair-multipart (article)
11733  "Add a Content-Type header to a multipart article without one."
11734  (interactive (list (gnus-summary-article-number)))
11735  (gnus-with-article article
11736    (message-narrow-to-head)
11737    (message-remove-header "Mime-Version")
11738    (goto-char (point-max))
11739    (insert "Mime-Version: 1.0\n")
11740    (widen)
11741    (when (search-forward "\n--" nil t)
11742      (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11743	(message-narrow-to-head)
11744	(message-remove-header "Content-Type")
11745	(goto-char (point-max))
11746	(insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11747			separator))
11748	(widen))))
11749  (let (gnus-mark-article-hook)
11750    (gnus-summary-select-article t t nil article)))
11751
11752(defun gnus-summary-toggle-display-buttonized ()
11753  "Toggle the buttonizing of the article buffer."
11754  (interactive)
11755  (require 'gnus-art)
11756  (if (setq gnus-inhibit-mime-unbuttonizing
11757	    (not gnus-inhibit-mime-unbuttonizing))
11758      (let ((gnus-unbuttonized-mime-types nil))
11759	(gnus-summary-show-article))
11760    (gnus-summary-show-article)))
11761
11762;;;
11763;;; Generic summary marking commands
11764;;;
11765
11766(defvar gnus-summary-marking-alist
11767  '((read gnus-del-mark "d")
11768    (unread gnus-unread-mark "u")
11769    (ticked gnus-ticked-mark "!")
11770    (dormant gnus-dormant-mark "?")
11771    (expirable gnus-expirable-mark "e"))
11772  "An alist of names/marks/keystrokes.")
11773
11774(defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11775(defvar gnus-summary-mark-map)
11776
11777(defun gnus-summary-make-all-marking-commands ()
11778  (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11779  (dolist (elem gnus-summary-marking-alist)
11780    (apply 'gnus-summary-make-marking-command elem)))
11781
11782(defun gnus-summary-make-marking-command (name mark keystroke)
11783  (let ((map (make-sparse-keymap)))
11784    (define-key gnus-summary-generic-mark-map keystroke map)
11785    (dolist (lway `((next "next" next nil "n")
11786		    (next-unread "next unread" next t "N")
11787		    (prev "previous" prev nil "p")
11788		    (prev-unread "previous unread" prev t "P")
11789		    (nomove "" nil nil ,keystroke)))
11790      (let ((func (gnus-summary-make-marking-command-1
11791		   mark (car lway) lway name)))
11792	(setq func (eval func))
11793	(define-key map (nth 4 lway) func)))))
11794
11795(defun gnus-summary-make-marking-command-1 (mark way lway name)
11796  `(defun ,(intern
11797	    (format "gnus-summary-put-mark-as-%s%s"
11798		    name (if (eq way 'nomove)
11799			     ""
11800			   (concat "-" (symbol-name way)))))
11801     (n)
11802     ,(format
11803       "Mark the current article as %s%s.
11804If N, the prefix, then repeat N times.
11805If N is negative, move in reverse order.
11806The difference between N and the actual number of articles marked is
11807returned."
11808       name (cadr lway))
11809     (interactive "p")
11810     (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11811
11812(defun gnus-summary-generic-mark (n mark move unread)
11813  "Mark N articles with MARK."
11814  (unless (eq major-mode 'gnus-summary-mode)
11815    (error "This command can only be used in the summary buffer"))
11816  (gnus-summary-show-thread)
11817  (let ((nummove
11818	 (cond
11819	  ((eq move 'next) 1)
11820	  ((eq move 'prev) -1)
11821	  (t 0))))
11822    (if (zerop nummove)
11823	(setq n 1)
11824      (when (< n 0)
11825	(setq n (abs n)
11826	      nummove (* -1 nummove))))
11827    (while (and (> n 0)
11828		(gnus-summary-mark-article nil mark)
11829		(zerop (gnus-summary-next-subject nummove unread t)))
11830      (setq n (1- n)))
11831    (when (/= 0 n)
11832      (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11833    (gnus-summary-recenter)
11834    (gnus-summary-position-point)
11835    (gnus-set-mode-line 'summary)
11836    n))
11837
11838(defun gnus-summary-insert-articles (articles)
11839  (when (setq articles
11840	      (gnus-sorted-difference articles
11841				      (mapcar (lambda (h)
11842						(mail-header-number h))
11843					      gnus-newsgroup-headers)))
11844    (setq gnus-newsgroup-headers
11845	  (gnus-merge 'list
11846		      gnus-newsgroup-headers
11847		      (gnus-fetch-headers articles)
11848		      'gnus-article-sort-by-number))
11849    ;; Suppress duplicates?
11850    (when gnus-suppress-duplicates
11851      (gnus-dup-suppress-articles))
11852
11853    ;; We might want to build some more threads first.
11854    (when (and gnus-fetch-old-headers
11855	       (eq gnus-headers-retrieved-by 'nov))
11856      (if (eq gnus-fetch-old-headers 'invisible)
11857	  (gnus-build-all-threads)
11858	(gnus-build-old-threads)))
11859    ;; Let the Gnus agent mark articles as read.
11860    (when gnus-agent
11861      (gnus-agent-get-undownloaded-list))
11862    ;; Remove list identifiers from subject
11863    (when gnus-list-identifiers
11864      (gnus-summary-remove-list-identifiers))
11865    ;; First and last article in this newsgroup.
11866    (when gnus-newsgroup-headers
11867      (setq gnus-newsgroup-begin
11868	    (mail-header-number (car gnus-newsgroup-headers))
11869	    gnus-newsgroup-end
11870	    (mail-header-number
11871	     (gnus-last-element gnus-newsgroup-headers))))
11872    (when gnus-use-scoring
11873      (gnus-possibly-score-headers))))
11874
11875(defun gnus-summary-insert-old-articles (&optional all)
11876  "Insert all old articles in this group.
11877If ALL is non-nil, already read articles become readable.
11878If ALL is a number, fetch this number of articles."
11879  (interactive "P")
11880  (prog1
11881      (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11882	    older len)
11883	(setq older
11884	      ;; Some nntp servers lie about their active range.  When
11885	      ;; this happens, the active range can be in the millions.
11886	      ;; Use a compressed range to avoid creating a huge list.
11887	      (gnus-range-difference (list gnus-newsgroup-active) old))
11888	(setq len (gnus-range-length older))
11889	(cond
11890	 ((null older) nil)
11891	 ((numberp all)
11892	  (if (< all len)
11893	      (let ((older-range (nreverse older)))
11894		(setq older nil)
11895
11896		(while (> all 0)
11897		  (let* ((r (pop older-range))
11898			 (min (if (numberp r) r (car r)))
11899			 (max (if (numberp r) r (cdr r))))
11900		    (while (and (<= min max)
11901				(> all 0))
11902		      (push max older)
11903		      (setq all (1- all)
11904			    max (1- max))))))
11905	    (setq older (gnus-uncompress-range older))))
11906	 (all
11907	  (setq older (gnus-uncompress-range older)))
11908	 (t
11909	  (when (and (numberp gnus-large-newsgroup)
11910		   (> len gnus-large-newsgroup))
11911	      (let* ((cursor-in-echo-area nil)
11912		     (initial (gnus-parameter-large-newsgroup-initial
11913			       gnus-newsgroup-name))
11914		     (input
11915		      (read-string
11916		       (format
11917			"How many articles from %s (%s %d): "
11918			(gnus-limit-string
11919			 (gnus-group-decoded-name gnus-newsgroup-name) 35)
11920			(if initial "max" "default")
11921			len)
11922		       (if initial
11923			   (cons (number-to-string initial)
11924				 0)))))
11925		(unless (string-match "^[ \t]*$" input)
11926		  (setq all (string-to-number input))
11927		  (if (< all len)
11928		      (let ((older-range (nreverse older)))
11929			(setq older nil)
11930
11931			(while (> all 0)
11932			  (let* ((r (pop older-range))
11933				 (min (if (numberp r) r (car r)))
11934				 (max (if (numberp r) r (cdr r))))
11935			    (while (and (<= min max)
11936					(> all 0))
11937			      (push max older)
11938			      (setq all (1- all)
11939				    max (1- max))))))))))
11940	  (setq older (gnus-uncompress-range older))))
11941	(if (not older)
11942	    (message "No old news.")
11943	  (gnus-summary-insert-articles older)
11944	  (gnus-summary-limit (gnus-sorted-nunion old older))))
11945    (gnus-summary-position-point)))
11946
11947(defun gnus-summary-insert-new-articles ()
11948  "Insert all new articles in this group."
11949  (interactive)
11950  (prog1
11951      (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11952	    (old-active gnus-newsgroup-active)
11953	    (nnmail-fetched-sources (list t))
11954	    i new)
11955	(setq gnus-newsgroup-active
11956	      (gnus-activate-group gnus-newsgroup-name 'scan))
11957	(setq i (cdr gnus-newsgroup-active))
11958	(while (> i (cdr old-active))
11959	  (push i new)
11960	  (decf i))
11961	(if (not new)
11962	    (message "No gnus is bad news.")
11963	  (gnus-summary-insert-articles new)
11964	  (setq gnus-newsgroup-unreads
11965		(gnus-sorted-nunion gnus-newsgroup-unreads new))
11966	  (gnus-summary-limit (gnus-sorted-nunion old new))))
11967    (gnus-summary-position-point)))
11968
11969(gnus-summary-make-all-marking-commands)
11970
11971(gnus-ems-redefine)
11972
11973(provide 'gnus-sum)
11974
11975(run-hooks 'gnus-sum-load-hook)
11976
11977;; Local Variables:
11978;; coding: iso-8859-1
11979;; End:
11980
11981;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11982;;; gnus-sum.el ends here
11983