Synch to Oort Gnus 200304040415.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (require 'gnus-clfns)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44 (require 'mime-view)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
57 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is non-nil, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const some)
89                  number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-refer-thread-limit 200
93   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
94 If t, fetch all the available old headers."
95   :group 'gnus-thread
96   :type '(choice number
97                  (sexp :menu-tag "other" t)))
98
99 (defcustom gnus-summary-make-false-root 'adopt
100   "*nil means that Gnus won't gather loose threads.
101 If the root of a thread has expired or been read in a previous
102 session, the information necessary to build a complete thread has been
103 lost.  Instead of having many small sub-threads from this original thread
104 scattered all over the summary buffer, Gnus can gather them.
105
106 If non-nil, Gnus will try to gather all loose sub-threads from an
107 original thread into one large thread.
108
109 If this variable is non-nil, it should be one of `none', `adopt',
110 `dummy' or `empty'.
111
112 If this variable is `none', Gnus will not make a false root, but just
113 present the sub-threads after another.
114 If this variable is `dummy', Gnus will create a dummy root that will
115 have all the sub-threads as children.
116 If this variable is `adopt', Gnus will make one of the \"children\"
117 the parent and mark all the step-children as such.
118 If this variable is `empty', the \"children\" are printed with empty
119 subject fields.  (Or rather, they will be printed with a string
120 given by the `gnus-summary-same-subject' variable.)"
121   :group 'gnus-thread
122   :type '(choice (const :tag "off" nil)
123                  (const none)
124                  (const dummy)
125                  (const adopt)
126                  (const empty)))
127
128 (defcustom gnus-summary-make-false-root-always nil
129   "Always make a false dummy root."
130   :group 'gnus-thread
131   :type 'boolean)
132
133 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
134   "*A regexp to match subjects to be excluded from loose thread gathering.
135 As loose thread gathering is done on subjects only, that means that
136 there can be many false gatherings performed.  By rooting out certain
137 common subjects, gathering might become saner."
138   :group 'gnus-thread
139   :type 'regexp)
140
141 (defcustom gnus-summary-gather-subject-limit nil
142   "*Maximum length of subject comparisons when gathering loose threads.
143 Use nil to compare full subjects.  Setting this variable to a low
144 number will help gather threads that have been corrupted by
145 newsreaders chopping off subject lines, but it might also mean that
146 unrelated articles that have subject that happen to begin with the
147 same few characters will be incorrectly gathered.
148
149 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
150 comparing subjects."
151   :group 'gnus-thread
152   :type '(choice (const :tag "off" nil)
153                  (const fuzzy)
154                  (sexp :menu-tag "on" t)))
155
156 (defcustom gnus-simplify-subject-functions nil
157   "List of functions taking a string argument that simplify subjects.
158 The functions are applied recursively.
159
160 Useful functions to put in this list include:
161 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
162 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
163   :group 'gnus-thread
164   :type '(repeat function))
165
166 (defcustom gnus-simplify-ignored-prefixes nil
167   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
168   :group 'gnus-thread
169   :type '(choice (const :tag "off" nil)
170                  regexp))
171
172 (defcustom gnus-build-sparse-threads nil
173   "*If non-nil, fill in the gaps in threads.
174 If `some', only fill in the gaps that are needed to tie loose threads
175 together.  If `more', fill in all leaf nodes that Gnus can find.  If
176 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
177   :group 'gnus-thread
178   :type '(choice (const :tag "off" nil)
179                  (const some)
180                  (const more)
181                  (sexp :menu-tag "all" t)))
182
183 (defcustom gnus-summary-thread-gathering-function
184   'gnus-gather-threads-by-subject
185   "*Function used for gathering loose threads.
186 There are two pre-defined functions: `gnus-gather-threads-by-subject',
187 which only takes Subjects into consideration; and
188 `gnus-gather-threads-by-references', which compared the References
189 headers of the articles to find matches."
190   :group 'gnus-thread
191   :type '(radio (function-item gnus-gather-threads-by-subject)
192                 (function-item gnus-gather-threads-by-references)
193                 (function :tag "other")))
194
195 (defcustom gnus-summary-same-subject ""
196   "*String indicating that the current article has the same subject as the previous.
197 This variable will only be used if the value of
198 `gnus-summary-make-false-root' is `empty'."
199   :group 'gnus-summary-format
200   :type 'string)
201
202 (defcustom gnus-summary-goto-unread t
203   "*If t, many commands will go to the next unread article.
204 This applies to marking commands as well as other commands that
205 \"naturally\" select the next article, like, for instance, `SPC' at
206 the end of an article.
207
208 If nil, the marking commands do NOT go to the next unread article
209 \(they go to the next article instead).  If `never', commands that
210 usually go to the next unread article, will go to the next article,
211 whether it is read or not."
212   :group 'gnus-summary-marks
213   :link '(custom-manual "(gnus)Setting Marks")
214   :type '(choice (const :tag "off" nil)
215                  (const never)
216                  (sexp :menu-tag "on" t)))
217
218 (defcustom gnus-summary-default-score 0
219   "*Default article score level.
220 All scores generated by the score files will be added to this score.
221 If this variable is nil, scoring will be disabled."
222   :group 'gnus-score-default
223   :type '(choice (const :tag "disable")
224                  integer))
225
226 (defcustom gnus-summary-default-high-score 0
227   "*Default threshold for a high scored article.
228 An article will be highlighted as high scored if its score is greater
229 than this score."
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :group 'gnus-score-default
238   :type 'integer)
239
240 (defcustom gnus-summary-zcore-fuzz 0
241   "*Fuzziness factor for the zcore in the summary buffer.
242 Articles with scores closer than this to `gnus-summary-default-score'
243 will not be marked."
244   :group 'gnus-summary-format
245   :type 'integer)
246
247 (defcustom gnus-simplify-subject-fuzzy-regexp nil
248   "*Strings to be removed when doing fuzzy matches.
249 This can either be a regular expression or list of regular expressions
250 that will be removed from subject strings if fuzzy subject
251 simplification is selected."
252   :group 'gnus-thread
253   :type '(repeat regexp))
254
255 (defcustom gnus-show-threads t
256   "*If non-nil, display threads in summary mode."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-hide-subtree nil
261   "*If non-nil, hide all threads initially.
262 This can be a predicate specifier which says which threads to hide.
263 If threads are hidden, you have to run the command
264 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
265 to expose hidden threads."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :group 'gnus-group-select
328   :type '(choice (const best)
329                  (const unread)
330                  (const first)
331                  (const unseen)
332                  (const unseen-or-unread)))
333
334 (defcustom gnus-dont-select-after-jump-to-other-group nil
335   "If non-nil, don't select the first unread article after entering the
336 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
337 it is depend on the value of `gnus-auto-select-first' whether to select
338 or not."
339   :group 'gnus-group-select
340   :type 'boolean)
341
342 (defcustom gnus-auto-select-next t
343   "*If non-nil, offer to go to the next group from the end of the previous.
344 If the value is t and the next newsgroup is empty, Gnus will exit
345 summary mode and go back to group mode.  If the value is neither nil
346 nor t, Gnus will select the following unread newsgroup.  In
347 particular, if the value is the symbol `quietly', the next unread
348 newsgroup will be selected without any confirmation, and if it is
349 `almost-quietly', the next group will be selected without any
350 confirmation if you are located on the last article in the group.
351 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
352 will go to the next group without confirmation."
353   :group 'gnus-summary-maneuvering
354   :type '(choice (const :tag "off" nil)
355                  (const quietly)
356                  (const almost-quietly)
357                  (const slightly-quietly)
358                  (sexp :menu-tag "on" t)))
359
360 (defcustom gnus-auto-select-same nil
361   "*If non-nil, select the next article with the same subject.
362 If there are no more articles with the same subject, go to
363 the first unread article."
364   :group 'gnus-summary-maneuvering
365   :type 'boolean)
366
367 (defcustom gnus-auto-goto-ignores 'unfetched
368   "*Says how to handle unfetched articles when maneuvering.
369
370 This variable can either be the symbols `nil' (maneuver to any
371 article), `undownloaded' (maneuvering while unplugged ignores articles
372 that have not been fetched), `always-undownloaded' (maneuvering always
373 ignores articles that have not been fetched), `unfetched' (maneuvering
374 ignores articles whose headers have not been fetched).
375
376 NOTE: The list of unfetched articles will always be nil when plugged
377 and, when unplugged, a subset of the undownloaded article list."
378   :group 'gnus-summary-maneuvering
379   :type '(choice (const :tag "None" nil)
380                  (const :tag "Undownloaded when unplugged" undownloaded)
381                  (const :tag "Undownloaded" always-undownloaded)
382                  (const :tag "Unfetched" unfetched)))
383
384 (defcustom gnus-summary-check-current nil
385   "*If non-nil, consider the current article when moving.
386 The \"unread\" movement commands will stay on the same line if the
387 current article is unread."
388   :group 'gnus-summary-maneuvering
389   :type 'boolean)
390
391 (defcustom gnus-auto-center-summary t
392   "*If non-nil, always center the current summary buffer.
393 In particular, if `vertical' do only vertical recentering.  If non-nil
394 and non-`vertical', do both horizontal and vertical recentering."
395   :group 'gnus-summary-maneuvering
396   :type '(choice (const :tag "none" nil)
397                  (const vertical)
398                  (integer :tag "height")
399                  (sexp :menu-tag "both" t)))
400
401 (defvar gnus-auto-center-group t
402   "*If non-nil, always center the group buffer.")
403
404 (defcustom gnus-show-all-headers nil
405   "*If non-nil, don't hide any headers."
406   :group 'gnus-article-hiding
407   :group 'gnus-article-headers
408   :type 'boolean)
409
410 (defcustom gnus-summary-ignore-duplicates nil
411   "*If non-nil, ignore articles with identical Message-ID headers."
412   :group 'gnus-summary
413   :type 'boolean)
414
415 (defcustom gnus-single-article-buffer t
416   "*If non-nil, display all articles in the same buffer.
417 If nil, each group will get its own article buffer."
418   :group 'gnus-article-various
419   :type 'boolean)
420
421 (defcustom gnus-break-pages t
422   "*If non-nil, do page breaking on articles.
423 The page delimiter is specified by the `gnus-page-delimiter'
424 variable."
425   :group 'gnus-article-various
426   :type 'boolean)
427
428 (defcustom gnus-show-mime t
429   "*If non-nil, do mime processing of articles.
430 The articles will simply be fed to the function given by
431 `gnus-article-display-method-for-mime'."
432   :group 'gnus-article-mime
433   :type 'boolean)
434
435 (defcustom gnus-move-split-methods nil
436   "*Variable used to suggest where articles are to be moved to.
437 It uses the same syntax as the `gnus-split-methods' variable.
438 However, whereas `gnus-split-methods' specifies file names as targets,
439 this variable specifies group names."
440   :group 'gnus-summary-mail
441   :type '(repeat (choice (list :value (fun) function)
442                          (cons :value ("" "") regexp (repeat string))
443                          (sexp :value nil))))
444
445 (defcustom gnus-unread-mark ?\ ;;;Whitespace
446   "*Mark used for unread articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-ticked-mark ?!
451   "*Mark used for ticked articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-dormant-mark ??
456   "*Mark used for dormant articles."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-del-mark ?r
461   "*Mark used for del'd articles."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-read-mark ?R
466   "*Mark used for read articles."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-expirable-mark ?E
471   "*Mark used for expirable articles."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-killed-mark ?K
476   "*Mark used for killed articles."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-spam-mark ?$
481   "*Mark used for spam articles."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-souped-mark ?F
486   "*Mark used for souped articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-kill-file-mark ?X
491   "*Mark used for articles killed by kill files."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-low-score-mark ?Y
496   "*Mark used for articles with a low score."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-catchup-mark ?C
501   "*Mark used for articles that are caught up."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-replied-mark ?A
506   "*Mark used for articles that have been replied to."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-forwarded-mark ?F
511   "*Mark used for articles that have been forwarded."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-recent-mark ?N
516   "*Mark used for articles that are recent."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-no-mark ?\ ;;;Whitespace
536   "*Mark used for articles that have no other secondary mark."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-ancient-mark ?O
541   "*Mark used for ancient articles."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-sparse-mark ?Q
546   "*Mark used for sparsely reffed articles."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-canceled-mark ?G
551   "*Mark used for canceled articles."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-duplicate-mark ?M
556   "*Mark used for duplicate articles."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-undownloaded-mark ?-
561   "*Mark used for articles that weren't downloaded."
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-downloaded-mark ?+
566   "*Mark used for articles that were downloaded."
567   :group 'gnus-summary-marks
568   :type 'character)
569
570 (defcustom gnus-downloadable-mark ?%
571   "*Mark used for articles that are to be downloaded."
572   :group 'gnus-summary-marks
573   :type 'character)
574
575 (defcustom gnus-unsendable-mark ?=
576   "*Mark used for articles that won't be sent."
577   :group 'gnus-summary-marks
578   :type 'character)
579
580 (defcustom gnus-score-over-mark ?+
581   "*Score mark used for articles with high scores."
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-score-below-mark ?-
586   "*Score mark used for articles with low scores."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
591   "*There is no thread under the article."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-not-empty-thread-mark ?=
596   "*There is a thread under the article."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-view-pseudo-asynchronously nil
601   "*If non-nil, Gnus will view pseudo-articles asynchronously."
602   :group 'gnus-extract-view
603   :type 'boolean)
604
605 (defcustom gnus-auto-expirable-marks
606   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
607         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
608         gnus-souped-mark gnus-duplicate-mark)
609   "*The list of marks converted into expiration if a group is auto-expirable."
610   :version "21.1"
611   :group 'gnus-summary
612   :type '(repeat character))
613
614 (defcustom gnus-inhibit-user-auto-expire t
615   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
616   :version "21.1"
617   :group 'gnus-summary
618   :type 'boolean)
619
620 (defcustom gnus-view-pseudos nil
621   "*If `automatic', pseudo-articles will be viewed automatically.
622 If `not-confirm', pseudos will be viewed automatically, and the user
623 will not be asked to confirm the command."
624   :group 'gnus-extract-view
625   :type '(choice (const :tag "off" nil)
626                  (const automatic)
627                  (const not-confirm)))
628
629 (defcustom gnus-view-pseudos-separately t
630   "*If non-nil, one pseudo-article will be created for each file to be viewed.
631 If nil, all files that use the same viewing command will be given as a
632 list of parameters to that command."
633   :group 'gnus-extract-view
634   :type 'boolean)
635
636 (defcustom gnus-insert-pseudo-articles t
637   "*If non-nil, insert pseudo-articles when decoding articles."
638   :group 'gnus-extract-view
639   :type 'boolean)
640
641 (defcustom gnus-summary-dummy-line-format
642   "   %(:                             :%) %S\n"
643   "*The format specification for the dummy roots in the summary buffer.
644 It works along the same lines as a normal formatting string,
645 with some simple extensions.
646
647 %S  The subject
648
649 General format specifiers can also be used.
650 See `(gnus)Formatting Variables'."
651   :link '(custom-manual "(gnus)Formatting Variables")
652   :group 'gnus-threading
653   :type 'string)
654
655 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
656   "*The format specification for the summary mode line.
657 It works along the same lines as a normal formatting string,
658 with some simple extensions:
659
660 %G  Group name
661 %p  Unprefixed group name
662 %A  Current article number
663 %z  Current article score
664 %V  Gnus version
665 %U  Number of unread articles in the group
666 %e  Number of unselected articles in the group
667 %Z  A string with unread/unselected article counts
668 %g  Shortish group name
669 %S  Subject of the current article
670 %u  User-defined spec
671 %s  Current score file name
672 %d  Number of dormant articles
673 %r  Number of articles that have been marked as read in this session
674 %E  Number of articles expunged by the score files"
675   :group 'gnus-summary-format
676   :type 'string)
677
678 (defcustom gnus-list-identifiers nil
679   "Regexp that matches list identifiers to be removed from subject.
680 This can also be a list of regexps."
681   :version "21.1"
682   :group 'gnus-summary-format
683   :group 'gnus-article-hiding
684   :type '(choice (const :tag "none" nil)
685                  (regexp :value ".*")
686                  (repeat :value (".*") regexp)))
687
688 (defcustom gnus-summary-mark-below 0
689   "*Mark all articles with a score below this variable as read.
690 This variable is local to each summary buffer and usually set by the
691 score file."
692   :group 'gnus-score-default
693   :type 'integer)
694
695 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
696   "*List of functions used for sorting articles in the summary buffer.
697
698 Each function takes two articles and returns non-nil if the first
699 article should be sorted before the other.  If you use more than one
700 function, the primary sort function should be the last.  You should
701 probably always include `gnus-article-sort-by-number' in the list of
702 sorting functions -- preferably first.  Also note that sorting by date
703 is often much slower than sorting by number, and the sorting order is
704 very similar.  (Sorting by date means sorting by the time the message
705 was sent, sorting by number means sorting by arrival time.)
706
707 Ready-made functions include `gnus-article-sort-by-number',
708 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
709 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
710 and `gnus-article-sort-by-score'.
711
712 When threading is turned on, the variable `gnus-thread-sort-functions'
713 controls how articles are sorted."
714   :group 'gnus-summary-sort
715   :type '(repeat (choice (function-item gnus-article-sort-by-number)
716                          (function-item gnus-article-sort-by-author)
717                          (function-item gnus-article-sort-by-subject)
718                          (function-item gnus-article-sort-by-date)
719                          (function-item gnus-article-sort-by-score)
720                          (function-item gnus-article-sort-by-random)
721                          (function :tag "other"))))
722
723 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
724   "*List of functions used for sorting threads in the summary buffer.
725 By default, threads are sorted by article number.
726
727 Each function takes two threads and returns non-nil if the first
728 thread should be sorted before the other.  If you use more than one
729 function, the primary sort function should be the last.  You should
730 probably always include `gnus-thread-sort-by-number' in the list of
731 sorting functions -- preferably first.  Also note that sorting by date
732 is often much slower than sorting by number, and the sorting order is
733 very similar.  (Sorting by date means sorting by the time the message
734 was sent, sorting by number means sorting by arrival time.)
735
736 Ready-made functions include `gnus-thread-sort-by-number',
737 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
738 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
739 `gnus-thread-sort-by-most-recent-number',
740 `gnus-thread-sort-by-most-recent-date',
741 `gnus-thread-sort-by-random', and
742 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
743
744 When threading is turned off, the variable
745 `gnus-article-sort-functions' controls how articles are sorted."
746   :group 'gnus-summary-sort
747   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
748                          (function-item gnus-thread-sort-by-author)
749                          (function-item gnus-thread-sort-by-subject)
750                          (function-item gnus-thread-sort-by-date)
751                          (function-item gnus-thread-sort-by-score)
752                          (function-item gnus-thread-sort-by-total-score)
753                          (function-item gnus-thread-sort-by-random)
754                          (function :tag "other"))))
755
756 (defcustom gnus-thread-score-function '+
757   "*Function used for calculating the total score of a thread.
758
759 The function is called with the scores of the article and each
760 subthread and should then return the score of the thread.
761
762 Some functions you can use are `+', `max', or `min'."
763   :group 'gnus-summary-sort
764   :type 'function)
765
766 (defcustom gnus-summary-expunge-below nil
767   "All articles that have a score less than this variable will be expunged.
768 This variable is local to the summary buffers."
769   :group 'gnus-score-default
770   :type '(choice (const :tag "off" nil)
771                  integer))
772
773 (defcustom gnus-thread-expunge-below nil
774   "All threads that have a total score less than this variable will be expunged.
775 See `gnus-thread-score-function' for en explanation of what a
776 \"thread score\" is.
777
778 This variable is local to the summary buffers."
779   :group 'gnus-threading
780   :group 'gnus-score-default
781   :type '(choice (const :tag "off" nil)
782                  integer))
783
784 (defcustom gnus-summary-mode-hook nil
785   "*A hook for Gnus summary mode.
786 This hook is run before any variables are set in the summary buffer."
787   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
788   :group 'gnus-summary-various
789   :type 'hook)
790
791 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
792 (when (featurep 'xemacs)
793   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
794   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
795   (add-hook 'gnus-summary-mode-hook
796             'gnus-xmas-switch-horizontal-scrollbar-off))
797
798 (defcustom gnus-summary-menu-hook nil
799   "*Hook run after the creation of the summary mode menu."
800   :group 'gnus-summary-visual
801   :type 'hook)
802
803 (defcustom gnus-summary-exit-hook nil
804   "*A hook called on exit from the summary buffer.
805 It will be called with point in the group buffer."
806   :group 'gnus-summary-exit
807   :type 'hook)
808
809 (defcustom gnus-summary-prepare-hook nil
810   "*A hook called after the summary buffer has been generated.
811 If you want to modify the summary buffer, you can use this hook."
812   :group 'gnus-summary-various
813   :type 'hook)
814
815 (defcustom gnus-summary-prepared-hook nil
816   "*A hook called as the last thing after the summary buffer has been generated."
817   :group 'gnus-summary-various
818   :type 'hook)
819
820 (defcustom gnus-summary-generate-hook nil
821   "*A hook run just before generating the summary buffer.
822 This hook is commonly used to customize threading variables and the
823 like."
824   :group 'gnus-summary-various
825   :type 'hook)
826
827 (defcustom gnus-select-group-hook nil
828   "*A hook called when a newsgroup is selected.
829
830 If you'd like to simplify subjects like the
831 `gnus-summary-next-same-subject' command does, you can use the
832 following hook:
833
834  (add-hook gnus-select-group-hook
835            (lambda ()
836              (mapcar (lambda (header)
837                        (mail-header-set-subject
838                         header
839                         (gnus-simplify-subject
840                          (mail-header-subject header) 're-only)))
841                      gnus-newsgroup-headers)))"
842   :group 'gnus-group-select
843   :type 'hook)
844
845 (defcustom gnus-select-article-hook nil
846   "*A hook called when an article is selected."
847   :group 'gnus-summary-choose
848   :options '(gnus-agent-fetch-selected-article)
849   :type 'hook)
850
851 (defcustom gnus-visual-mark-article-hook
852   (list 'gnus-highlight-selected-summary)
853   "*Hook run after selecting an article in the summary buffer.
854 It is meant to be used for highlighting the article in some way.  It
855 is not run if `gnus-visual' is nil."
856   :group 'gnus-summary-visual
857   :type 'hook)
858
859 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
860   "*A hook called before parsing the headers."
861   :group 'gnus-various
862   :type 'hook)
863
864 (defcustom gnus-exit-group-hook nil
865   "*A hook called when exiting summary mode.
866 This hook is not called from the non-updating exit commands like `Q'."
867   :group 'gnus-various
868   :type 'hook)
869
870 (defcustom gnus-summary-update-hook
871   (list 'gnus-summary-highlight-line)
872   "*A hook called when a summary line is changed.
873 The hook will not be called if `gnus-visual' is nil.
874
875 The default function `gnus-summary-highlight-line' will
876 highlight the line according to the `gnus-summary-highlight'
877 variable."
878   :group 'gnus-summary-visual
879   :type 'hook)
880
881 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
882   "*A hook called when an article is selected for the first time.
883 The hook is intended to mark an article as read (or unread)
884 automatically when it is selected."
885   :group 'gnus-summary-choose
886   :type 'hook)
887
888 (defcustom gnus-group-no-more-groups-hook nil
889   "*A hook run when returning to group mode having no more (unread) groups."
890   :group 'gnus-group-select
891   :type 'hook)
892
893 (defcustom gnus-ps-print-hook nil
894   "*A hook run before ps-printing something from Gnus."
895   :group 'gnus-summary
896   :type 'hook)
897
898 (defcustom gnus-summary-article-move-hook nil
899   "*A hook called after an article is moved, copied, respooled, or crossposted."
900   :group 'gnus-summary
901   :type 'hook)
902
903 (defcustom gnus-summary-article-delete-hook nil
904   "*A hook called after an article is deleted."
905   :group 'gnus-summary
906   :type 'hook)
907
908 (defcustom gnus-summary-article-expire-hook nil
909   "*A hook called after an article is expired."
910   :group 'gnus-summary
911   :type 'hook)
912
913 (defcustom gnus-summary-display-arrow
914   (and (fboundp 'display-graphic-p)
915        (display-graphic-p))
916   "*If non-nil, display an arrow highlighting the current article."
917   :version "21.1"
918   :group 'gnus-summary
919   :type 'boolean)
920
921 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
922   "Face used for highlighting the current article in the summary buffer."
923   :group 'gnus-summary-visual
924   :type 'face)
925
926 (defvar gnus-tmp-downloaded nil)
927
928 (defcustom gnus-summary-highlight
929   '(((eq mark gnus-canceled-mark)
930      . gnus-summary-cancelled-face)
931     ((and uncached (> score default-high))
932      . gnus-summary-high-undownloaded-face)
933     ((and uncached (< score default-low))
934      . gnus-summary-low-undownloaded-face)
935     (uncached
936      . gnus-summary-normal-undownloaded-face)
937     ((and (> score default-high)
938           (or (eq mark gnus-dormant-mark)
939               (eq mark gnus-ticked-mark)))
940      . gnus-summary-high-ticked-face)
941     ((and (< score default-low)
942           (or (eq mark gnus-dormant-mark)
943               (eq mark gnus-ticked-mark)))
944      . gnus-summary-low-ticked-face)
945     ((or (eq mark gnus-dormant-mark)
946          (eq mark gnus-ticked-mark))
947      . gnus-summary-normal-ticked-face)
948     ((and (> score default-high) (eq mark gnus-ancient-mark))
949      . gnus-summary-high-ancient-face)
950     ((and (< score default-low) (eq mark gnus-ancient-mark))
951      . gnus-summary-low-ancient-face)
952     ((eq mark gnus-ancient-mark)
953      . gnus-summary-normal-ancient-face)
954     ((and (> score default-high) (eq mark gnus-unread-mark))
955      . gnus-summary-high-unread-face)
956     ((and (< score default-low) (eq mark gnus-unread-mark))
957      . gnus-summary-low-unread-face)
958     ((eq mark gnus-unread-mark)
959      . gnus-summary-normal-unread-face)
960     ((> score default-high)
961      . gnus-summary-high-read-face)
962     ((< score default-low)
963      . gnus-summary-low-read-face)
964     (t
965      . gnus-summary-normal-read-face))
966   "*Controls the highlighting of summary buffer lines.
967
968 A list of (FORM . FACE) pairs.  When deciding how a a particular
969 summary line should be displayed, each form is evaluated.  The content
970 of the face field after the first true form is used.  You can change
971 how those summary lines are displayed, by editing the face field.
972
973 You can use the following variables in the FORM field.
974
975 score:        The article's score
976 default:      The default article score.
977 default-high: The default score for high scored articles.
978 default-low:  The default score for low scored articles.
979 below:        The score below which articles are automatically marked as read.
980 mark:         The articles mark."
981   :group 'gnus-summary-visual
982   :type '(repeat (cons (sexp :tag "Form" nil)
983                        face)))
984
985 (defcustom gnus-alter-header-function nil
986   "Function called to allow alteration of article header structures.
987 The function is called with one parameter, the article header vector,
988 which it may alter in any way."
989   :type '(choice (const :tag "None" nil)
990                  function)
991   :group 'gnus-summary)
992
993 (defvar gnus-decode-encoded-word-function
994   (mime-find-field-decoder 'From 'nov)
995   "Variable that says which function should be used to decode a string with encoded words.")
996
997 (defcustom gnus-extra-headers '(To Newsgroups)
998   "*Extra headers to parse."
999   :version "21.1"
1000   :group 'gnus-summary
1001   :type '(repeat symbol))
1002
1003 (defcustom gnus-ignored-from-addresses
1004   (and user-mail-address (regexp-quote user-mail-address))
1005   "*Regexp of From headers that may be suppressed in favor of To headers."
1006   :version "21.1"
1007   :group 'gnus-summary
1008   :type 'regexp)
1009
1010 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1011   "List of charsets that should be ignored.
1012 When these charsets are used in the \"charset\" parameter, the
1013 default charset will be used instead."
1014   :version "21.1"
1015   :type '(repeat symbol)
1016   :group 'gnus-charset)
1017
1018 (gnus-define-group-parameter
1019  ignored-charsets
1020  :type list
1021  :function-document
1022  "Return the ignored charsets of GROUP."
1023  :variable gnus-group-ignored-charsets-alist
1024  :variable-default
1025  '(("alt\\.chinese\\.text" iso-8859-1))
1026  :variable-document
1027  "Alist of regexps (to match group names) and charsets that should be ignored.
1028 When these charsets are used in the \"charset\" parameter, the
1029 default charset will be used instead."
1030  :variable-group gnus-charset
1031  :variable-type '(repeat (cons (regexp :tag "Group")
1032                                (repeat symbol)))
1033  :parameter-type '(choice :tag "Ignored charsets"
1034                           :value nil
1035                           (repeat (symbol)))
1036  :parameter-document       "\
1037 List of charsets that should be ignored.
1038
1039 When these charsets are used in the \"charset\" parameter, the
1040 default charset will be used instead.")
1041
1042 (defcustom gnus-group-highlight-words-alist nil
1043   "Alist of group regexps and highlight regexps.
1044 This variable uses the same syntax as `gnus-emphasis-alist'."
1045   :version "21.1"
1046   :type '(repeat (cons (regexp :tag "Group")
1047                        (repeat (list (regexp :tag "Highlight regexp")
1048                                      (number :tag "Group for entire word" 0)
1049                                      (number :tag "Group for displayed part" 0)
1050                                      (symbol :tag "Face"
1051                                              gnus-emphasis-highlight-words)))))
1052   :group 'gnus-summary-visual)
1053
1054 (defcustom gnus-use-wheel nil
1055   "Use Intelli-mouse on summary movement"
1056   :type 'boolean
1057   :group 'gnus-summary-maneuvering)
1058
1059 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1060   "Amount to scroll messages by spinning the mouse wheel.
1061 This is actually a cons cell, where the first item is the amount to scroll
1062 on a normal wheel event, and the second is the amount to scroll when the
1063 wheel is moved with the shift key depressed."
1064   :type '(cons (integer :tag "Shift") integer)
1065   :group 'gnus-summary-maneuvering)
1066
1067 (defcustom gnus-wheel-edge-resistance 2
1068   "How hard it should be to change the current article
1069 by moving the mouse over the edge of the article window."
1070   :type 'integer
1071   :group 'gnus-summary-maneuvering)
1072
1073 (defcustom gnus-summary-show-article-charset-alist
1074   nil
1075   "Alist of number and charset.
1076 The article will be shown with the charset corresponding to the
1077 numbered argument.
1078 For example: ((1 . cn-gb-2312) (2 . big5))."
1079   :version "21.1"
1080   :type '(repeat (cons (number :tag "Argument" 1)
1081                        (symbol :tag "Charset")))
1082   :group 'gnus-charset)
1083
1084 (defcustom gnus-preserve-marks t
1085   "Whether marks are preserved when moving, copying and respooling messages."
1086   :version "21.1"
1087   :type 'boolean
1088   :group 'gnus-summary-marks)
1089
1090 (defcustom gnus-alter-articles-to-read-function nil
1091   "Function to be called to alter the list of articles to be selected."
1092   :type '(choice (const nil) function)
1093   :group 'gnus-summary)
1094
1095 (defcustom gnus-orphan-score nil
1096   "*All orphans get this score added.  Set in the score file."
1097   :group 'gnus-score-default
1098   :type '(choice (const nil)
1099                  integer))
1100
1101 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1102   "*A regexp to match MIME parts when saving multiple parts of a
1103 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1104 This regexp will be used by default when prompting the user for which
1105 type of files to save."
1106   :group 'gnus-summary
1107   :type 'regexp)
1108
1109 (defcustom gnus-read-all-available-headers nil
1110   "Whether Gnus should parse all headers made available to it.
1111 This is mostly relevant for slow backends where the user may
1112 wish to widen the summary buffer to include all headers
1113 that were fetched.  Say, for nnultimate groups."
1114   :group 'gnus-summary
1115   :type '(choice boolean regexp))
1116
1117 (defcustom gnus-summary-muttprint-program "muttprint"
1118   "Command (and optional arguments) used to run Muttprint."
1119   :version "21.3"
1120   :group 'gnus-summary
1121   :type 'string)
1122
1123 (defcustom gnus-article-loose-mime nil
1124   "If non-nil, don't require MIME-Version header.
1125 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1126 supply the MIME-Version header or deliberately strip it From the mail.
1127 Set it to non-nil, Gnus will treat some articles as MIME even if
1128 the MIME-Version header is missed."
1129   :version "21.3"
1130   :type 'boolean
1131   :group 'gnus-article-mime)
1132
1133 (defcustom gnus-article-emulate-mime t
1134   "If non-nil, use MIME emulation for uuencode and the like.
1135 This means that Gnus will search message bodies for text that look
1136 like uuencoded bits, yEncoded bits, and so on, and present that using
1137 the normal Gnus MIME machinery."
1138   :type 'boolean
1139   :group 'gnus-article-mime)
1140
1141 ;;; Internal variables
1142
1143 (defvar gnus-summary-display-cache nil)
1144 (defvar gnus-article-mime-handles nil)
1145 (defvar gnus-article-decoded-p nil)
1146 (defvar gnus-article-charset nil)
1147 (defvar gnus-article-ignored-charsets nil)
1148 (defvar gnus-scores-exclude-files nil)
1149 (defvar gnus-page-broken nil)
1150
1151 (defvar gnus-original-article nil)
1152 (defvar gnus-article-internal-prepare-hook nil)
1153 (defvar gnus-newsgroup-process-stack nil)
1154
1155 (defvar gnus-thread-indent-array nil)
1156 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1157 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1158   "Function called to sort the articles within a thread after it has been gathered together.")
1159
1160 (defvar gnus-summary-save-parts-type-history nil)
1161 (defvar gnus-summary-save-parts-last-directory nil)
1162
1163 ;; Avoid highlighting in kill files.
1164 (defvar gnus-summary-inhibit-highlight nil)
1165 (defvar gnus-newsgroup-selected-overlay nil)
1166 (defvar gnus-inhibit-limiting nil)
1167 (defvar gnus-newsgroup-adaptive-score-file nil)
1168 (defvar gnus-current-score-file nil)
1169 (defvar gnus-current-move-group nil)
1170 (defvar gnus-current-copy-group nil)
1171 (defvar gnus-current-crosspost-group nil)
1172 (defvar gnus-newsgroup-display nil)
1173
1174 (defvar gnus-newsgroup-dependencies nil)
1175 (defvar gnus-newsgroup-adaptive nil)
1176 (defvar gnus-summary-display-article-function nil)
1177 (defvar gnus-summary-highlight-line-function nil
1178   "Function called after highlighting a summary line.")
1179
1180 (defvar gnus-summary-line-format-alist
1181   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1182     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1183     (?s gnus-tmp-subject-or-nil ?s)
1184     (?n gnus-tmp-name ?s)
1185     (?A (std11-address-string
1186          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1187     (?a (or (std11-full-name-string
1188              (car (mime-entity-read-field gnus-tmp-header 'From)))
1189             gnus-tmp-from) ?s)
1190     (?F gnus-tmp-from ?s)
1191     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1192     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1193     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1194     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1195     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1196     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1197     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1198     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1199     (?L gnus-tmp-lines ?s)
1200     (?O gnus-tmp-downloaded ?c)
1201     (?I gnus-tmp-indentation ?s)
1202     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1203     (?R gnus-tmp-replied ?c)
1204     (?\[ gnus-tmp-opening-bracket ?c)
1205     (?\] gnus-tmp-closing-bracket ?c)
1206     (?\> (make-string gnus-tmp-level ? ) ?s)
1207     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1208     (?i gnus-tmp-score ?d)
1209     (?z gnus-tmp-score-char ?c)
1210     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1211     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1212     (?U gnus-tmp-unread ?c)
1213     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1214         ?s)
1215     (?t (gnus-summary-number-of-articles-in-thread
1216          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1217         ?d)
1218     (?e (gnus-summary-number-of-articles-in-thread
1219          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1220         ?c)
1221     (?u gnus-tmp-user-defined ?s)
1222     (?P (gnus-pick-line-number) ?d)
1223     (?B gnus-tmp-thread-tree-header-string ?s)
1224     (user-date (gnus-user-date
1225                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1226   "An alist of format specifications that can appear in summary lines.
1227 These are paired with what variables they correspond with, along with
1228 the type of the variable (string, integer, character, etc).")
1229
1230 (defvar gnus-summary-dummy-line-format-alist
1231   `((?S gnus-tmp-subject ?s)
1232     (?N gnus-tmp-number ?d)
1233     (?u gnus-tmp-user-defined ?s)))
1234
1235 (defvar gnus-summary-mode-line-format-alist
1236   `((?G gnus-tmp-group-name ?s)
1237     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1238     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1239     (?A gnus-tmp-article-number ?d)
1240     (?Z gnus-tmp-unread-and-unselected ?s)
1241     (?V gnus-version ?s)
1242     (?U gnus-tmp-unread-and-unticked ?d)
1243     (?S gnus-tmp-subject ?s)
1244     (?e gnus-tmp-unselected ?d)
1245     (?u gnus-tmp-user-defined ?s)
1246     (?d (length gnus-newsgroup-dormant) ?d)
1247     (?t (length gnus-newsgroup-marked) ?d)
1248     (?h (length gnus-newsgroup-spam-marked) ?d)
1249     (?r (length gnus-newsgroup-reads) ?d)
1250     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1251     (?E gnus-newsgroup-expunged-tally ?d)
1252     (?s (gnus-current-score-file-nondirectory) ?s)))
1253
1254 (defvar gnus-last-search-regexp nil
1255   "Default regexp for article search command.")
1256
1257 (defvar gnus-summary-search-article-matched-data nil
1258   "Last matched data of article search command.  It is the local variable
1259 in `gnus-article-buffer' which consists of the list of start position,
1260 end position and text.")
1261
1262 (defvar gnus-last-shell-command nil
1263   "Default shell command on article.")
1264
1265 (defvar gnus-newsgroup-agentized nil
1266   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1267 (defvar gnus-newsgroup-begin nil)
1268 (defvar gnus-newsgroup-end nil)
1269 (defvar gnus-newsgroup-last-rmail nil)
1270 (defvar gnus-newsgroup-last-mail nil)
1271 (defvar gnus-newsgroup-last-folder nil)
1272 (defvar gnus-newsgroup-last-file nil)
1273 (defvar gnus-newsgroup-auto-expire nil)
1274 (defvar gnus-newsgroup-active nil)
1275
1276 (defvar gnus-newsgroup-data nil)
1277 (defvar gnus-newsgroup-data-reverse nil)
1278 (defvar gnus-newsgroup-limit nil)
1279 (defvar gnus-newsgroup-limits nil)
1280
1281 (defvar gnus-newsgroup-unreads nil
1282   "Sorted list of unread articles in the current newsgroup.")
1283
1284 (defvar gnus-newsgroup-unselected nil
1285   "Sorted list of unselected unread articles in the current newsgroup.")
1286
1287 (defvar gnus-newsgroup-reads nil
1288   "Alist of read articles and article marks in the current newsgroup.")
1289
1290 (defvar gnus-newsgroup-expunged-tally nil)
1291
1292 (defvar gnus-newsgroup-marked nil
1293   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1294
1295 (defvar gnus-newsgroup-spam-marked nil
1296   "List of ranges of articles that have been marked as spam.")
1297
1298 (defvar gnus-newsgroup-killed nil
1299   "List of ranges of articles that have been through the scoring process.")
1300
1301 (defvar gnus-newsgroup-cached nil
1302   "Sorted list of articles that come from the article cache.")
1303
1304 (defvar gnus-newsgroup-saved nil
1305   "List of articles that have been saved.")
1306
1307 (defvar gnus-newsgroup-kill-headers nil)
1308
1309 (defvar gnus-newsgroup-replied nil
1310   "List of articles that have been replied to in the current newsgroup.")
1311
1312 (defvar gnus-newsgroup-forwarded nil
1313   "List of articles that have been forwarded in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-recent nil
1316   "List of articles that have are recent in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-expirable nil
1319   "Sorted list of articles in the current newsgroup that can be expired.")
1320
1321 (defvar gnus-newsgroup-processable nil
1322   "List of articles in the current newsgroup that can be processed.")
1323
1324 (defvar gnus-newsgroup-downloadable nil
1325   "Sorted list of articles in the current newsgroup that can be processed.")
1326
1327 (defvar gnus-newsgroup-unfetched nil
1328   "Sorted list of articles in the current newsgroup whose headers have
1329 not been fetched into the agent.
1330
1331 This list will always be a subset of gnus-newsgroup-undownloaded.")
1332
1333 (defvar gnus-newsgroup-undownloaded nil
1334   "List of articles in the current newsgroup that haven't been downloaded.")
1335
1336 (defvar gnus-newsgroup-unsendable nil
1337   "List of articles in the current newsgroup that won't be sent.")
1338
1339 (defvar gnus-newsgroup-bookmarks nil
1340   "List of articles in the current newsgroup that have bookmarks.")
1341
1342 (defvar gnus-newsgroup-dormant nil
1343   "Sorted list of dormant articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-unseen nil
1346   "List of unseen articles in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-seen nil
1349   "Range of seen articles in the current newsgroup.")
1350
1351 (defvar gnus-newsgroup-articles nil
1352   "List of articles in the current newsgroup.")
1353
1354 (defvar gnus-newsgroup-scored nil
1355   "List of scored articles in the current newsgroup.")
1356
1357 (defvar gnus-newsgroup-incorporated nil
1358   "List of incorporated articles in the current newsgroup.")
1359
1360 (defvar gnus-newsgroup-headers nil
1361   "List of article headers in the current newsgroup.")
1362
1363 (defvar gnus-newsgroup-threads nil)
1364
1365 (defvar gnus-newsgroup-prepared nil
1366   "Whether the current group has been prepared properly.")
1367
1368 (defvar gnus-newsgroup-ancient nil
1369   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-sparse nil)
1372
1373 (defvar gnus-current-article nil)
1374 (defvar gnus-article-current nil)
1375 (defvar gnus-current-headers nil)
1376 (defvar gnus-have-all-headers nil)
1377 (defvar gnus-last-article nil)
1378 (defvar gnus-newsgroup-history nil)
1379 (defvar gnus-newsgroup-charset nil)
1380 (defvar gnus-newsgroup-ephemeral-charset nil)
1381 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1382
1383 (defvar gnus-article-before-search nil)
1384
1385 (defconst gnus-summary-local-variables
1386   '(gnus-newsgroup-name
1387     gnus-newsgroup-begin gnus-newsgroup-end
1388     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1389     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1390     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1391     gnus-newsgroup-unselected gnus-newsgroup-marked
1392     gnus-newsgroup-spam-marked
1393     gnus-newsgroup-reads gnus-newsgroup-saved
1394     gnus-newsgroup-replied gnus-newsgroup-forwarded
1395     gnus-newsgroup-recent
1396     gnus-newsgroup-expirable
1397     gnus-newsgroup-processable gnus-newsgroup-killed
1398     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1399     gnus-newsgroup-unfetched
1400     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1401     gnus-newsgroup-seen gnus-newsgroup-articles
1402     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1403     gnus-newsgroup-headers gnus-newsgroup-threads
1404     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1405     gnus-current-article gnus-current-headers gnus-have-all-headers
1406     gnus-last-article gnus-article-internal-prepare-hook
1407     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1408     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1409     gnus-thread-expunge-below
1410     gnus-score-alist gnus-current-score-file
1411     (gnus-summary-expunge-below . global)
1412     (gnus-summary-mark-below . global)
1413     (gnus-orphan-score . global)
1414     gnus-newsgroup-active gnus-scores-exclude-files
1415     gnus-newsgroup-history gnus-newsgroup-ancient
1416     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1417     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1418     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1419     (gnus-newsgroup-expunged-tally . 0)
1420     gnus-cache-removable-articles gnus-newsgroup-cached
1421     gnus-newsgroup-data gnus-newsgroup-data-reverse
1422     gnus-newsgroup-limit gnus-newsgroup-limits
1423     gnus-newsgroup-charset gnus-newsgroup-display
1424     gnus-newsgroup-incorporated)
1425   "Variables that are buffer-local to the summary buffers.")
1426
1427 (defvar gnus-newsgroup-variables nil
1428   "A list of variables that have separate values in different newsgroups.
1429 A list of newsgroup (summary buffer) local variables, or cons of
1430 variables and their default values (when the default values are not
1431 nil), that should be made global while the summary buffer is active.
1432 These variables can be used to set variables in the group parameters
1433 while still allowing them to affect operations done in other
1434 buffers. For example:
1435
1436 \(setq gnus-newsgroup-variables
1437      '(message-use-followup-to
1438        (gnus-visible-headers .
1439          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1440 ")
1441
1442 ;; Byte-compiler warning.
1443 (eval-when-compile
1444   ;; Bind features so that require will believe that gnus-sum has
1445   ;; already been loaded (avoids infinite recursion)
1446   (let ((features (cons 'gnus-sum features)))
1447     ;; Several of the declarations in gnus-sum are needed to load the
1448     ;; following files. Right now, these definitions have been
1449     ;; compiled but not defined (evaluated).  We could either do a
1450     ;; eval-and-compile about all of the declarations or evaluate the
1451     ;; source file.
1452     (if (boundp 'gnus-newsgroup-variables)
1453         nil
1454       (load "gnus-sum.el" t t t t))
1455     (require 'gnus)
1456     (require 'gnus-agent)
1457     (require 'gnus-art)))
1458
1459 ;; Subject simplification.
1460
1461 (defun gnus-simplify-whitespace (str)
1462   "Remove excessive whitespace from STR."
1463   ;; Multiple spaces.
1464   (while (string-match "[ \t][ \t]+" str)
1465     (setq str (concat (substring str 0 (match-beginning 0))
1466                         " "
1467                         (substring str (match-end 0)))))
1468   ;; Leading spaces.
1469   (when (string-match "^[ \t]+" str)
1470     (setq str (substring str (match-end 0))))
1471   ;; Trailing spaces.
1472   (when (string-match "[ \t]+$" str)
1473     (setq str (substring str 0 (match-beginning 0))))
1474   str)
1475
1476 (defun gnus-simplify-all-whitespace (str)
1477   "Remove all whitespace from STR."
1478   (while (string-match "[ \t\n]+" str)
1479     (setq str (replace-match "" nil nil str)))
1480   str)
1481
1482 (defsubst gnus-simplify-subject-re (subject)
1483   "Remove \"Re:\" from subject lines."
1484   (if (string-match message-subject-re-regexp subject)
1485       (substring subject (match-end 0))
1486     subject))
1487
1488 (defun gnus-simplify-subject (subject &optional re-only)
1489   "Remove `Re:' and words in parentheses.
1490 If RE-ONLY is non-nil, strip leading `Re:'s only."
1491   (let ((case-fold-search t))           ;Ignore case.
1492     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1493     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1494       (setq subject (substring subject (match-end 0))))
1495     ;; Remove uninteresting prefixes.
1496     (when (and (not re-only)
1497                gnus-simplify-ignored-prefixes
1498                (string-match gnus-simplify-ignored-prefixes subject))
1499       (setq subject (substring subject (match-end 0))))
1500     ;; Remove words in parentheses from end.
1501     (unless re-only
1502       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1503         (setq subject (substring subject 0 (match-beginning 0)))))
1504     ;; Return subject string.
1505     subject))
1506
1507 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1508 ;; all whitespace.
1509 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1510   (goto-char (point-min))
1511   (while (re-search-forward regexp nil t)
1512     (replace-match (or newtext ""))))
1513
1514 (defun gnus-simplify-buffer-fuzzy ()
1515   "Simplify string in the buffer fuzzily.
1516 The string in the accessible portion of the current buffer is simplified.
1517 It is assumed to be a single-line subject.
1518 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1519 matter is removed.  Additional things can be deleted by setting
1520 `gnus-simplify-subject-fuzzy-regexp'."
1521   (let ((case-fold-search t)
1522         (modified-tick))
1523     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1524
1525     (while (not (eq modified-tick (buffer-modified-tick)))
1526       (setq modified-tick (buffer-modified-tick))
1527       (cond
1528        ((listp gnus-simplify-subject-fuzzy-regexp)
1529         (mapcar 'gnus-simplify-buffer-fuzzy-step
1530                 gnus-simplify-subject-fuzzy-regexp))
1531        (gnus-simplify-subject-fuzzy-regexp
1532         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1533       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1534       (gnus-simplify-buffer-fuzzy-step
1535        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1536       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1537
1538     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1539     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1540     (gnus-simplify-buffer-fuzzy-step " $")
1541     (gnus-simplify-buffer-fuzzy-step "^ +")))
1542
1543 (defun gnus-simplify-subject-fuzzy (subject)
1544   "Simplify a subject string fuzzily.
1545 See `gnus-simplify-buffer-fuzzy' for details."
1546   (save-excursion
1547     (gnus-set-work-buffer)
1548     (let ((case-fold-search t))
1549       ;; Remove uninteresting prefixes.
1550       (when (and gnus-simplify-ignored-prefixes
1551                  (string-match gnus-simplify-ignored-prefixes subject))
1552         (setq subject (substring subject (match-end 0))))
1553       (insert subject)
1554       (inline (gnus-simplify-buffer-fuzzy))
1555       (buffer-string))))
1556
1557 (defsubst gnus-simplify-subject-fully (subject)
1558   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1559   (cond
1560    (gnus-simplify-subject-functions
1561     (gnus-map-function gnus-simplify-subject-functions subject))
1562    ((null gnus-summary-gather-subject-limit)
1563     (gnus-simplify-subject-re subject))
1564    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1565     (gnus-simplify-subject-fuzzy subject))
1566    ((numberp gnus-summary-gather-subject-limit)
1567     (gnus-limit-string (gnus-simplify-subject-re subject)
1568                        gnus-summary-gather-subject-limit))
1569    (t
1570     subject)))
1571
1572 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1573   "Check whether two subjects are equal.
1574 If optional argument SIMPLE-FIRST is t, first argument is already
1575 simplified."
1576   (cond
1577    ((null simple-first)
1578     (equal (gnus-simplify-subject-fully s1)
1579            (gnus-simplify-subject-fully s2)))
1580    (t
1581     (equal s1
1582            (gnus-simplify-subject-fully s2)))))
1583
1584 (defun gnus-summary-bubble-group ()
1585   "Increase the score of the current group.
1586 This is a handy function to add to `gnus-summary-exit-hook' to
1587 increase the score of each group you read."
1588   (gnus-group-add-score gnus-newsgroup-name))
1589
1590 \f
1591 ;;;
1592 ;;; Gnus summary mode
1593 ;;;
1594
1595 (put 'gnus-summary-mode 'mode-class 'special)
1596
1597 (defvar gnus-article-commands-menu)
1598
1599 ;; Non-orthogonal keys
1600
1601 (gnus-define-keys gnus-summary-mode-map
1602   " " gnus-summary-next-page
1603   "\177" gnus-summary-prev-page
1604   [delete] gnus-summary-prev-page
1605   [backspace] gnus-summary-prev-page
1606   "\r" gnus-summary-scroll-up
1607   "\M-\r" gnus-summary-scroll-down
1608   "n" gnus-summary-next-unread-article
1609   "p" gnus-summary-prev-unread-article
1610   "N" gnus-summary-next-article
1611   "P" gnus-summary-prev-article
1612   "\M-\C-n" gnus-summary-next-same-subject
1613   "\M-\C-p" gnus-summary-prev-same-subject
1614   "\M-n" gnus-summary-next-unread-subject
1615   "\M-p" gnus-summary-prev-unread-subject
1616   "." gnus-summary-first-unread-article
1617   "," gnus-summary-best-unread-article
1618   "\M-s" gnus-summary-search-article-forward
1619   "\M-r" gnus-summary-search-article-backward
1620   "<" gnus-summary-beginning-of-article
1621   ">" gnus-summary-end-of-article
1622   "j" gnus-summary-goto-article
1623   "^" gnus-summary-refer-parent-article
1624   "\M-^" gnus-summary-refer-article
1625   "u" gnus-summary-tick-article-forward
1626   "!" gnus-summary-tick-article-forward
1627   "U" gnus-summary-tick-article-backward
1628   "d" gnus-summary-mark-as-read-forward
1629   "D" gnus-summary-mark-as-read-backward
1630   "E" gnus-summary-mark-as-expirable
1631   "\M-u" gnus-summary-clear-mark-forward
1632   "\M-U" gnus-summary-clear-mark-backward
1633   "k" gnus-summary-kill-same-subject-and-select
1634   "\C-k" gnus-summary-kill-same-subject
1635   "\M-\C-k" gnus-summary-kill-thread
1636   "\M-\C-l" gnus-summary-lower-thread
1637   "e" gnus-summary-edit-article
1638   "#" gnus-summary-mark-as-processable
1639   "\M-#" gnus-summary-unmark-as-processable
1640   "\M-\C-t" gnus-summary-toggle-threads
1641   "\M-\C-s" gnus-summary-show-thread
1642   "\M-\C-h" gnus-summary-hide-thread
1643   "\M-\C-f" gnus-summary-next-thread
1644   "\M-\C-b" gnus-summary-prev-thread
1645   [(meta down)] gnus-summary-next-thread
1646   [(meta up)] gnus-summary-prev-thread
1647   "\M-\C-u" gnus-summary-up-thread
1648   "\M-\C-d" gnus-summary-down-thread
1649   "&" gnus-summary-execute-command
1650   "c" gnus-summary-catchup-and-exit
1651   "\C-w" gnus-summary-mark-region-as-read
1652   "\C-t" gnus-summary-toggle-truncation
1653   "?" gnus-summary-mark-as-dormant
1654   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1655   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1656   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1657   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1658   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1659   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1660   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1661   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1662   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1663   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1664   "=" gnus-summary-expand-window
1665   "\C-x\C-s" gnus-summary-reselect-current-group
1666   "\M-g" gnus-summary-rescan-group
1667   "w" gnus-summary-stop-page-breaking
1668   "\C-c\C-r" gnus-summary-caesar-message
1669   "\M-t" gnus-summary-toggle-mime
1670   "f" gnus-summary-followup
1671   "F" gnus-summary-followup-with-original
1672   "C" gnus-summary-cancel-article
1673   "r" gnus-summary-reply
1674   "R" gnus-summary-reply-with-original
1675   "\C-c\C-f" gnus-summary-mail-forward
1676   "o" gnus-summary-save-article
1677   "\C-o" gnus-summary-save-article-mail
1678   "|" gnus-summary-pipe-output
1679   "\M-k" gnus-summary-edit-local-kill
1680   "\M-K" gnus-summary-edit-global-kill
1681   ;; "V" gnus-version
1682   "\C-c\C-d" gnus-summary-describe-group
1683   "q" gnus-summary-exit
1684   "Q" gnus-summary-exit-no-update
1685   "\C-c\C-i" gnus-info-find-node
1686   gnus-mouse-2 gnus-mouse-pick-article
1687   "m" gnus-summary-mail-other-window
1688   "a" gnus-summary-post-news
1689   "i" gnus-summary-news-other-window
1690   "x" gnus-summary-limit-to-unread
1691   "s" gnus-summary-isearch-article
1692   "t" gnus-summary-toggle-header
1693   "g" gnus-summary-show-article
1694   "l" gnus-summary-goto-last-article
1695   "v" gnus-summary-preview-mime-message
1696   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1697   "\C-d" gnus-summary-enter-digest-group
1698   "\M-\C-d" gnus-summary-read-document
1699   "\M-\C-e" gnus-summary-edit-parameters
1700   "\M-\C-a" gnus-summary-customize-parameters
1701   "\C-c\C-b" gnus-bug
1702   "\C-c\C-n" gnus-namazu-search
1703   "*" gnus-cache-enter-article
1704   "\M-*" gnus-cache-remove-article
1705   "\M-&" gnus-summary-universal-argument
1706   "\C-l" gnus-recenter
1707   "I" gnus-summary-increase-score
1708   "L" gnus-summary-lower-score
1709   "\M-i" gnus-symbolic-argument
1710   "h" gnus-summary-select-article-buffer
1711
1712   "V" gnus-summary-score-map
1713   "X" gnus-uu-extract-map
1714   "S" gnus-summary-send-map)
1715
1716   ;; Sort of orthogonal keymap
1717 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1718   "t" gnus-summary-tick-article-forward
1719   "!" gnus-summary-tick-article-forward
1720   "d" gnus-summary-mark-as-read-forward
1721   "r" gnus-summary-mark-as-read-forward
1722   "c" gnus-summary-clear-mark-forward
1723   " " gnus-summary-clear-mark-forward
1724   "e" gnus-summary-mark-as-expirable
1725   "x" gnus-summary-mark-as-expirable
1726   "?" gnus-summary-mark-as-dormant
1727   "b" gnus-summary-set-bookmark
1728   "B" gnus-summary-remove-bookmark
1729   "#" gnus-summary-mark-as-processable
1730   "\M-#" gnus-summary-unmark-as-processable
1731   "S" gnus-summary-limit-include-expunged
1732   "C" gnus-summary-catchup
1733   "H" gnus-summary-catchup-to-here
1734   "h" gnus-summary-catchup-from-here
1735   "\C-c" gnus-summary-catchup-all
1736   "k" gnus-summary-kill-same-subject-and-select
1737   "K" gnus-summary-kill-same-subject
1738   "P" gnus-uu-mark-map)
1739
1740 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1741   "c" gnus-summary-clear-above
1742   "u" gnus-summary-tick-above
1743   "m" gnus-summary-mark-above
1744   "k" gnus-summary-kill-below)
1745
1746 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1747   "/" gnus-summary-limit-to-subject
1748   "n" gnus-summary-limit-to-articles
1749   "w" gnus-summary-pop-limit
1750   "s" gnus-summary-limit-to-subject
1751   "a" gnus-summary-limit-to-author
1752   "u" gnus-summary-limit-to-unread
1753   "m" gnus-summary-limit-to-marks
1754   "M" gnus-summary-limit-exclude-marks
1755   "v" gnus-summary-limit-to-score
1756   "*" gnus-summary-limit-include-cached
1757   "D" gnus-summary-limit-include-dormant
1758   "T" gnus-summary-limit-include-thread
1759   "d" gnus-summary-limit-exclude-dormant
1760   "t" gnus-summary-limit-to-age
1761   "." gnus-summary-limit-to-unseen
1762   "x" gnus-summary-limit-to-extra
1763   "p" gnus-summary-limit-to-display-predicate
1764   "E" gnus-summary-limit-include-expunged
1765   "c" gnus-summary-limit-exclude-childless-dormant
1766   "C" gnus-summary-limit-mark-excluded-as-read
1767   "o" gnus-summary-insert-old-articles
1768   "N" gnus-summary-insert-new-articles)
1769
1770 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1771   "n" gnus-summary-next-unread-article
1772   "p" gnus-summary-prev-unread-article
1773   "N" gnus-summary-next-article
1774   "P" gnus-summary-prev-article
1775   "\C-n" gnus-summary-next-same-subject
1776   "\C-p" gnus-summary-prev-same-subject
1777   "\M-n" gnus-summary-next-unread-subject
1778   "\M-p" gnus-summary-prev-unread-subject
1779   "f" gnus-summary-first-unread-article
1780   "b" gnus-summary-best-unread-article
1781   "j" gnus-summary-goto-article
1782   "g" gnus-summary-goto-subject
1783   "l" gnus-summary-goto-last-article
1784   "o" gnus-summary-pop-article)
1785
1786 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1787   "k" gnus-summary-kill-thread
1788   "l" gnus-summary-lower-thread
1789   "i" gnus-summary-raise-thread
1790   "T" gnus-summary-toggle-threads
1791   "t" gnus-summary-rethread-current
1792   "^" gnus-summary-reparent-thread
1793   "s" gnus-summary-show-thread
1794   "S" gnus-summary-show-all-threads
1795   "h" gnus-summary-hide-thread
1796   "H" gnus-summary-hide-all-threads
1797   "n" gnus-summary-next-thread
1798   "p" gnus-summary-prev-thread
1799   "u" gnus-summary-up-thread
1800   "o" gnus-summary-top-thread
1801   "d" gnus-summary-down-thread
1802   "#" gnus-uu-mark-thread
1803   "\M-#" gnus-uu-unmark-thread)
1804
1805 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1806   "g" gnus-summary-prepare
1807   "c" gnus-summary-insert-cached-articles
1808   "d" gnus-summary-insert-dormant-articles)
1809
1810 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1811   "c" gnus-summary-catchup-and-exit
1812   "C" gnus-summary-catchup-all-and-exit
1813   "E" gnus-summary-exit-no-update
1814   "J" gnus-summary-jump-to-other-group
1815   "Q" gnus-summary-exit
1816   "Z" gnus-summary-exit
1817   "n" gnus-summary-catchup-and-goto-next-group
1818   "R" gnus-summary-reselect-current-group
1819   "G" gnus-summary-rescan-group
1820   "N" gnus-summary-next-group
1821   "s" gnus-summary-save-newsrc
1822   "P" gnus-summary-prev-group)
1823
1824 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1825   " " gnus-summary-next-page
1826   "n" gnus-summary-next-page
1827   "\177" gnus-summary-prev-page
1828   [delete] gnus-summary-prev-page
1829   "p" gnus-summary-prev-page
1830   "\r" gnus-summary-scroll-up
1831   "\M-\r" gnus-summary-scroll-down
1832   "<" gnus-summary-beginning-of-article
1833   ">" gnus-summary-end-of-article
1834   "b" gnus-summary-beginning-of-article
1835   "e" gnus-summary-end-of-article
1836   "^" gnus-summary-refer-parent-article
1837   "r" gnus-summary-refer-parent-article
1838   "D" gnus-summary-enter-digest-group
1839   "R" gnus-summary-refer-references
1840   "T" gnus-summary-refer-thread
1841   "g" gnus-summary-show-article
1842   "s" gnus-summary-isearch-article
1843   "P" gnus-summary-print-article
1844   "M" gnus-mailing-list-insinuate
1845   "t" gnus-article-babel)
1846
1847 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1848   "b" gnus-article-add-buttons
1849   "B" gnus-article-add-buttons-to-head
1850   "o" gnus-article-treat-overstrike
1851   "e" gnus-article-emphasize
1852   "w" gnus-article-fill-cited-article
1853   "Q" gnus-article-fill-long-lines
1854   "C" gnus-article-capitalize-sentences
1855   "c" gnus-article-remove-cr
1856   "Z" gnus-article-decode-HZ
1857   "h" gnus-article-wash-html
1858   "u" gnus-article-unsplit-urls
1859   "f" gnus-article-display-x-face
1860   "l" gnus-summary-stop-page-breaking
1861   "r" gnus-summary-caesar-message
1862   "m" gnus-summary-morse-message
1863   "t" gnus-summary-toggle-header
1864   "g" gnus-treat-smiley
1865   "v" gnus-summary-verbose-headers
1866   "m" gnus-summary-toggle-mime
1867   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1868   "p" gnus-article-verify-x-pgp-sig
1869   "d" gnus-article-treat-dumbquotes)
1870
1871 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1872   ;; mnemonic: deuglif*Y*
1873   "u" gnus-article-outlook-unwrap-lines
1874   "a" gnus-article-outlook-repair-attribution
1875   "c" gnus-article-outlook-rearrange-citation
1876   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1877
1878 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1879   "a" gnus-article-hide
1880   "h" gnus-article-hide-headers
1881   "b" gnus-article-hide-boring-headers
1882   "s" gnus-article-hide-signature
1883   "c" gnus-article-hide-citation
1884   "C" gnus-article-hide-citation-in-followups
1885   "l" gnus-article-hide-list-identifiers
1886   "B" gnus-article-strip-banner
1887   "P" gnus-article-hide-pem
1888   "\C-c" gnus-article-hide-citation-maybe)
1889
1890 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1891   "a" gnus-article-highlight
1892   "h" gnus-article-highlight-headers
1893   "c" gnus-article-highlight-citation
1894   "s" gnus-article-highlight-signature)
1895
1896 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1897   "f" gnus-article-treat-fold-headers
1898   "u" gnus-article-treat-unfold-headers
1899   "n" gnus-article-treat-fold-newsgroups)
1900
1901 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1902   "x" gnus-article-display-x-face
1903   "d" gnus-article-display-face
1904   "s" gnus-treat-smiley
1905   "D" gnus-article-remove-images
1906   "f" gnus-treat-from-picon
1907   "m" gnus-treat-mail-picon
1908   "n" gnus-treat-newsgroups-picon)
1909
1910 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1911   "z" gnus-article-date-ut
1912   "u" gnus-article-date-ut
1913   "l" gnus-article-date-local
1914   "p" gnus-article-date-english
1915   "e" gnus-article-date-lapsed
1916   "o" gnus-article-date-original
1917   "i" gnus-article-date-iso8601
1918   "s" gnus-article-date-user)
1919
1920 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1921   "t" gnus-article-remove-trailing-blank-lines
1922   "l" gnus-article-strip-leading-blank-lines
1923   "m" gnus-article-strip-multiple-blank-lines
1924   "a" gnus-article-strip-blank-lines
1925   "A" gnus-article-strip-all-blank-lines
1926   "s" gnus-article-strip-leading-space
1927   "e" gnus-article-strip-trailing-space
1928   "w" gnus-article-remove-leading-whitespace)
1929
1930 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1931   "v" gnus-version
1932   "f" gnus-summary-fetch-faq
1933   "d" gnus-summary-describe-group
1934   "h" gnus-summary-describe-briefly
1935   "i" gnus-info-find-node
1936   "c" gnus-group-fetch-charter
1937   "C" gnus-group-fetch-control)
1938
1939 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1940   "e" gnus-summary-expire-articles
1941   "\M-\C-e" gnus-summary-expire-articles-now
1942   "\177" gnus-summary-delete-article
1943   [delete] gnus-summary-delete-article
1944   [backspace] gnus-summary-delete-article
1945   "m" gnus-summary-move-article
1946   "r" gnus-summary-respool-article
1947   "w" gnus-summary-edit-article
1948   "c" gnus-summary-copy-article
1949   "B" gnus-summary-crosspost-article
1950   "q" gnus-summary-respool-query
1951   "t" gnus-summary-respool-trace
1952   "i" gnus-summary-import-article
1953   "I" gnus-summary-create-article
1954   "p" gnus-summary-article-posted-p)
1955
1956 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1957   "o" gnus-summary-save-article
1958   "m" gnus-summary-save-article-mail
1959   "F" gnus-summary-write-article-file
1960   "r" gnus-summary-save-article-rmail
1961   "f" gnus-summary-save-article-file
1962   "b" gnus-summary-save-article-body-file
1963   "h" gnus-summary-save-article-folder
1964   "v" gnus-summary-save-article-vm
1965   "p" gnus-summary-pipe-output
1966   "P" gnus-summary-muttprint
1967   "s" gnus-soup-add-article)
1968
1969 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1970   "b" gnus-summary-display-buttonized
1971   "m" gnus-summary-repair-multipart
1972   "v" gnus-article-view-part
1973   "o" gnus-article-save-part
1974   "c" gnus-article-copy-part
1975   "C" gnus-article-view-part-as-charset
1976   "e" gnus-article-view-part-externally
1977   "E" gnus-article-encrypt-body
1978   "i" gnus-article-inline-part
1979   "|" gnus-article-pipe-part)
1980
1981 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1982   "p" gnus-summary-mark-as-processable
1983   "u" gnus-summary-unmark-as-processable
1984   "U" gnus-summary-unmark-all-processable
1985   "v" gnus-uu-mark-over
1986   "s" gnus-uu-mark-series
1987   "r" gnus-uu-mark-region
1988   "g" gnus-uu-unmark-region
1989   "R" gnus-uu-mark-by-regexp
1990   "G" gnus-uu-unmark-by-regexp
1991   "t" gnus-uu-mark-thread
1992   "T" gnus-uu-unmark-thread
1993   "a" gnus-uu-mark-all
1994   "b" gnus-uu-mark-buffer
1995   "S" gnus-uu-mark-sparse
1996   "k" gnus-summary-kill-process-mark
1997   "y" gnus-summary-yank-process-mark
1998   "w" gnus-summary-save-process-mark
1999   "i" gnus-uu-invert-processable)
2000
2001 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2002   ;;"x" gnus-uu-extract-any
2003   "m" gnus-summary-save-parts
2004   "u" gnus-uu-decode-uu
2005   "U" gnus-uu-decode-uu-and-save
2006   "s" gnus-uu-decode-unshar
2007   "S" gnus-uu-decode-unshar-and-save
2008   "o" gnus-uu-decode-save
2009   "O" gnus-uu-decode-save
2010   "b" gnus-uu-decode-binhex
2011   "B" gnus-uu-decode-binhex
2012   "p" gnus-uu-decode-postscript
2013   "P" gnus-uu-decode-postscript-and-save)
2014
2015 (gnus-define-keys
2016     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2017   "u" gnus-uu-decode-uu-view
2018   "U" gnus-uu-decode-uu-and-save-view
2019   "s" gnus-uu-decode-unshar-view
2020   "S" gnus-uu-decode-unshar-and-save-view
2021   "o" gnus-uu-decode-save-view
2022   "O" gnus-uu-decode-save-view
2023   "b" gnus-uu-decode-binhex-view
2024   "B" gnus-uu-decode-binhex-view
2025   "p" gnus-uu-decode-postscript-view
2026   "P" gnus-uu-decode-postscript-and-save-view)
2027
2028 (defvar gnus-article-post-menu nil)
2029
2030 (defconst gnus-summary-menu-maxlen 20)
2031
2032 (defun gnus-summary-menu-split (menu)
2033   ;; If we have lots of elements, divide them into groups of 20
2034   ;; and make a pane (or submenu) for each one.
2035   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2036       (let ((menu menu) sublists next
2037             (i 1))
2038         (while menu
2039           ;; Pull off the next gnus-summary-menu-maxlen elements
2040           ;; and make them the next element of sublist.
2041           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2042           (if next
2043               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2044                       nil))
2045           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2046                                              (aref (car (last menu)) 0)) menu)
2047                                sublists))
2048           (setq i (1+ i))
2049           (setq menu next))
2050         (nreverse sublists))
2051     ;; Few elements--put them all in one pane.
2052     menu))
2053
2054 (defun gnus-summary-make-menu-bar ()
2055   (gnus-turn-off-edit-menu 'summary)
2056
2057   (unless (boundp 'gnus-summary-misc-menu)
2058
2059     (easy-menu-define
2060      gnus-summary-kill-menu gnus-summary-mode-map ""
2061      (cons
2062       "Score"
2063       (nconc
2064        (list
2065         ["Customize" gnus-score-customize t])
2066        (gnus-make-score-map 'increase)
2067        (gnus-make-score-map 'lower)
2068        '(("Mark"
2069           ["Kill below" gnus-summary-kill-below t]
2070           ["Mark above" gnus-summary-mark-above t]
2071           ["Tick above" gnus-summary-tick-above t]
2072           ["Clear above" gnus-summary-clear-above t])
2073          ["Current score" gnus-summary-current-score t]
2074          ["Set score" gnus-summary-set-score t]
2075          ["Switch current score file..." gnus-score-change-score-file t]
2076          ["Set mark below..." gnus-score-set-mark-below t]
2077          ["Set expunge below..." gnus-score-set-expunge-below t]
2078          ["Edit current score file" gnus-score-edit-current-scores t]
2079          ["Edit score file" gnus-score-edit-file t]
2080          ["Trace score" gnus-score-find-trace t]
2081          ["Find words" gnus-score-find-favourite-words t]
2082          ["Rescore buffer" gnus-summary-rescore t]
2083          ["Increase score..." gnus-summary-increase-score t]
2084          ["Lower score..." gnus-summary-lower-score t]))))
2085
2086     ;; Define both the Article menu in the summary buffer and the
2087     ;; equivalent Commands menu in the article buffer here for
2088     ;; consistency.
2089     (let ((innards
2090            `(("Hide"
2091               ["All" gnus-article-hide t]
2092               ["Headers" gnus-article-hide-headers t]
2093               ["Signature" gnus-article-hide-signature t]
2094               ["Citation" gnus-article-hide-citation t]
2095               ["List identifiers" gnus-article-hide-list-identifiers t]
2096               ["Banner" gnus-article-strip-banner t]
2097               ["Boring headers" gnus-article-hide-boring-headers t])
2098              ("Highlight"
2099               ["All" gnus-article-highlight t]
2100               ["Headers" gnus-article-highlight-headers t]
2101               ["Signature" gnus-article-highlight-signature t]
2102               ["Citation" gnus-article-highlight-citation t])
2103              ("Date"
2104               ["Local" gnus-article-date-local t]
2105               ["ISO8601" gnus-article-date-iso8601 t]
2106               ["UT" gnus-article-date-ut t]
2107               ["Original" gnus-article-date-original t]
2108               ["Lapsed" gnus-article-date-lapsed t]
2109               ["User-defined" gnus-article-date-user t])
2110              ("Display"
2111               ["Remove images" gnus-article-remove-images t]
2112               ["Toggle smiley" gnus-treat-smiley t]
2113               ["Show X-Face" gnus-article-display-x-face t]
2114               ["Show picons in From" gnus-treat-from-picon t]
2115               ["Show picons in mail headers" gnus-treat-mail-picon t]
2116               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2117               ("View as different encoding"
2118                ,@(gnus-summary-menu-split
2119                   (mapcar
2120                    (lambda (cs)
2121                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2122                      ;; forms for menu commands, we should provide intern'ed
2123                      ;; function symbols.
2124                      (let ((command (intern (format "\
2125 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2126                        (fset command
2127                              `(lambda ()
2128                                 (interactive)
2129                                 (let ((gnus-summary-show-article-charset-alist
2130                                        '((1 . ,cs))))
2131                                   (gnus-summary-show-article 1))))
2132                        `[,(symbol-name cs) ,command t]))
2133                    (sort (if (fboundp 'coding-system-list)
2134                              (coding-system-list)
2135                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2136                            )
2137                          'string<)))))
2138              ("Washing"
2139               ("Remove Blanks"
2140                ["Leading" gnus-article-strip-leading-blank-lines t]
2141                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2142                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2143                ["All of the above" gnus-article-strip-blank-lines t]
2144                ["All" gnus-article-strip-all-blank-lines t]
2145                ["Leading space" gnus-article-strip-leading-space t]
2146                ["Trailing space" gnus-article-strip-trailing-space t]
2147                ["Leading space in headers"
2148                 gnus-article-remove-leading-whitespace t])
2149               ["Overstrike" gnus-article-treat-overstrike t]
2150               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2151               ["Emphasis" gnus-article-emphasize t]
2152               ["Word wrap" gnus-article-fill-cited-article t]
2153               ["Fill long lines" gnus-article-fill-long-lines t]
2154               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2155               ["CR" gnus-article-remove-cr t]
2156               ["Rot 13" gnus-summary-caesar-message
2157                ,@(if (featurep 'xemacs) '(t)
2158                    '(:help "\"Caesar rotate\" article by 13"))]
2159               ["Morse decode" gnus-summary-morse-message t]
2160               ["Unix pipe..." gnus-summary-pipe-message t]
2161               ["Add buttons" gnus-article-add-buttons t]
2162               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2163               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2164               ["Toggle MIME" gnus-summary-toggle-mime t]
2165               ["Verbose header" gnus-summary-verbose-headers t]
2166               ["Toggle header" gnus-summary-toggle-header t]
2167               ["Unfold headers" gnus-article-treat-unfold-headers t]
2168               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2169               ["Html" gnus-article-wash-html t]
2170               ["URLs" gnus-article-unsplit-urls t]
2171               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2172               ["HZ" gnus-article-decode-HZ t]
2173               ("(Outlook) Deuglify"
2174                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2175                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2176                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2177                ["Full (Outlook) deuglify"
2178                 gnus-article-outlook-deuglify-article t])
2179               )
2180              ("Output"
2181               ["Save in default format" gnus-summary-save-article
2182                ,@(if (featurep 'xemacs) '(t)
2183                    '(:help "Save article using default method"))]
2184               ["Save in file" gnus-summary-save-article-file
2185                ,@(if (featurep 'xemacs) '(t)
2186                    '(:help "Save article in file"))]
2187               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2188               ["Save in MH folder" gnus-summary-save-article-folder t]
2189               ["Save in VM folder" gnus-summary-save-article-vm t]
2190               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2191               ["Save body in file" gnus-summary-save-article-body-file t]
2192               ["Pipe through a filter" gnus-summary-pipe-output t]
2193               ["Add to SOUP packet" gnus-soup-add-article t]
2194               ["Print with Muttprint" gnus-summary-muttprint t]
2195               ["Print" gnus-summary-print-article t])
2196              ("Backend"
2197               ["Respool article..." gnus-summary-respool-article t]
2198               ["Move article..." gnus-summary-move-article
2199                (gnus-check-backend-function
2200                 'request-move-article gnus-newsgroup-name)]
2201               ["Copy article..." gnus-summary-copy-article t]
2202               ["Crosspost article..." gnus-summary-crosspost-article
2203                (gnus-check-backend-function
2204                 'request-replace-article gnus-newsgroup-name)]
2205               ["Import file..." gnus-summary-import-article t]
2206               ["Create article..." gnus-summary-create-article t]
2207               ["Check if posted" gnus-summary-article-posted-p t]
2208               ["Edit article" gnus-summary-edit-article
2209                (not (gnus-group-read-only-p))]
2210               ["Delete article" gnus-summary-delete-article
2211                (gnus-check-backend-function
2212                 'request-expire-articles gnus-newsgroup-name)]
2213               ["Query respool" gnus-summary-respool-query t]
2214               ["Trace respool" gnus-summary-respool-trace t]
2215               ["Delete expirable articles" gnus-summary-expire-articles-now
2216                (gnus-check-backend-function
2217                 'request-expire-articles gnus-newsgroup-name)])
2218              ("Extract"
2219               ["Uudecode" gnus-uu-decode-uu
2220                ,@(if (featurep 'xemacs) '(t)
2221                    '(:help "Decode uuencoded article(s)"))]
2222               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2223               ["Unshar" gnus-uu-decode-unshar t]
2224               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2225               ["Save" gnus-uu-decode-save t]
2226               ["Binhex" gnus-uu-decode-binhex t]
2227               ["Postscript" gnus-uu-decode-postscript t])
2228              ("Cache"
2229               ["Enter article" gnus-cache-enter-article t]
2230               ["Remove article" gnus-cache-remove-article t])
2231              ["Translate" gnus-article-babel t]
2232              ["Select article buffer" gnus-summary-select-article-buffer t]
2233              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2234              ["Isearch article..." gnus-summary-isearch-article t]
2235              ["Beginning of the article" gnus-summary-beginning-of-article t]
2236              ["End of the article" gnus-summary-end-of-article t]
2237              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2238              ["Fetch referenced articles" gnus-summary-refer-references t]
2239              ["Fetch current thread" gnus-summary-refer-thread t]
2240              ["Fetch article with id..." gnus-summary-refer-article t]
2241              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2242              ["Redisplay" gnus-summary-show-article t]
2243              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2244       (easy-menu-define
2245        gnus-summary-article-menu gnus-summary-mode-map ""
2246        (cons "Article" innards))
2247
2248       (if (not (keymapp gnus-summary-article-menu))
2249           (easy-menu-define
2250            gnus-article-commands-menu gnus-article-mode-map ""
2251            (cons "Commands" innards))
2252         ;; in Emacs, don't share menu.
2253         (setq gnus-article-commands-menu
2254               (copy-keymap gnus-summary-article-menu))
2255         (define-key gnus-article-mode-map [menu-bar commands]
2256           (cons "Commands" gnus-article-commands-menu))))
2257
2258     (easy-menu-define
2259      gnus-summary-thread-menu gnus-summary-mode-map ""
2260      '("Threads"
2261        ["Find all messages in thread" gnus-summary-refer-thread t]
2262        ["Toggle threading" gnus-summary-toggle-threads t]
2263        ["Hide threads" gnus-summary-hide-all-threads t]
2264        ["Show threads" gnus-summary-show-all-threads t]
2265        ["Hide thread" gnus-summary-hide-thread t]
2266        ["Show thread" gnus-summary-show-thread t]
2267        ["Go to next thread" gnus-summary-next-thread t]
2268        ["Go to previous thread" gnus-summary-prev-thread t]
2269        ["Go down thread" gnus-summary-down-thread t]
2270        ["Go up thread" gnus-summary-up-thread t]
2271        ["Top of thread" gnus-summary-top-thread t]
2272        ["Mark thread as read" gnus-summary-kill-thread t]
2273        ["Lower thread score" gnus-summary-lower-thread t]
2274        ["Raise thread score" gnus-summary-raise-thread t]
2275        ["Rethread current" gnus-summary-rethread-current t]))
2276
2277     (easy-menu-define
2278      gnus-summary-post-menu gnus-summary-mode-map ""
2279      `("Post"
2280        ["Send a message (mail or news)" gnus-summary-post-news
2281         ,@(if (featurep 'xemacs) '(t)
2282             '(:help "Post an article"))]
2283        ["Followup" gnus-summary-followup
2284         ,@(if (featurep 'xemacs) '(t)
2285             '(:help "Post followup to this article"))]
2286        ["Followup and yank" gnus-summary-followup-with-original
2287         ,@(if (featurep 'xemacs) '(t)
2288             '(:help "Post followup to this article, quoting its contents"))]
2289        ["Supersede article" gnus-summary-supersede-article t]
2290        ["Cancel article" gnus-summary-cancel-article
2291         ,@(if (featurep 'xemacs) '(t)
2292             '(:help "Cancel an article you posted"))]
2293        ["Reply" gnus-summary-reply t]
2294        ["Reply and yank" gnus-summary-reply-with-original t]
2295        ["Wide reply" gnus-summary-wide-reply t]
2296        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2297         ,@(if (featurep 'xemacs) '(t)
2298             '(:help "Mail a reply, quoting this article"))]
2299        ["Very wide reply" gnus-summary-very-wide-reply t]
2300        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2301         ,@(if (featurep 'xemacs) '(t)
2302             '(:help "Mail a very wide reply, quoting this article"))]
2303        ["Mail forward" gnus-summary-mail-forward t]
2304        ["Post forward" gnus-summary-post-forward t]
2305        ["Digest and mail" gnus-summary-digest-mail-forward t]
2306        ["Digest and post" gnus-summary-digest-post-forward t]
2307        ["Resend message" gnus-summary-resend-message t]
2308        ["Resend message edit" gnus-summary-resend-message-edit t]
2309        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2310        ["Send a mail" gnus-summary-mail-other-window t]
2311        ["Create a local message" gnus-summary-news-other-window t]
2312        ["Uuencode and post" gnus-uu-post-news
2313         ,@(if (featurep 'xemacs) '(t)
2314             '(:help "Post a uuencoded article"))]
2315        ["Followup via news" gnus-summary-followup-to-mail t]
2316        ["Followup via news and yank"
2317         gnus-summary-followup-to-mail-with-original t]
2318        ;;("Draft"
2319        ;;["Send" gnus-summary-send-draft t]
2320        ;;["Send bounced" gnus-resend-bounced-mail t])
2321        ))
2322
2323     (cond
2324      ((not (keymapp gnus-summary-post-menu))
2325       (setq gnus-article-post-menu gnus-summary-post-menu))
2326      ((not gnus-article-post-menu)
2327       ;; Don't share post menu.
2328       (setq gnus-article-post-menu
2329             (copy-keymap gnus-summary-post-menu))))
2330     (define-key gnus-article-mode-map [menu-bar post]
2331       (cons "Post" gnus-article-post-menu))
2332
2333     (easy-menu-define
2334      gnus-summary-misc-menu gnus-summary-mode-map ""
2335      `("Gnus"
2336        ("Mark Read"
2337         ["Mark as read" gnus-summary-mark-as-read-forward t]
2338         ["Mark same subject and select"
2339          gnus-summary-kill-same-subject-and-select t]
2340         ["Mark same subject" gnus-summary-kill-same-subject t]
2341         ["Catchup" gnus-summary-catchup
2342          ,@(if (featurep 'xemacs) '(t)
2343              '(:help "Mark unread articles in this group as read"))]
2344         ["Catchup all" gnus-summary-catchup-all t]
2345         ["Catchup to here" gnus-summary-catchup-to-here t]
2346         ["Catchup from here" gnus-summary-catchup-from-here t]
2347         ["Catchup region" gnus-summary-mark-region-as-read
2348          (gnus-mark-active-p)]
2349         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2350        ("Mark Various"
2351         ["Tick" gnus-summary-tick-article-forward t]
2352         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2353         ["Remove marks" gnus-summary-clear-mark-forward t]
2354         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2355         ["Set bookmark" gnus-summary-set-bookmark t]
2356         ["Remove bookmark" gnus-summary-remove-bookmark t])
2357        ("Limit to"
2358         ["Marks..." gnus-summary-limit-to-marks t]
2359         ["Subject..." gnus-summary-limit-to-subject t]
2360         ["Author..." gnus-summary-limit-to-author t]
2361         ["Age..." gnus-summary-limit-to-age t]
2362         ["Extra..." gnus-summary-limit-to-extra t]
2363         ["Score..." gnus-summary-limit-to-score t]
2364         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2365         ["Unread" gnus-summary-limit-to-unread t]
2366         ["Unseen" gnus-summary-limit-to-unseen t]
2367         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2368         ["Next articles" gnus-summary-limit-to-articles t]
2369         ["Pop limit" gnus-summary-pop-limit t]
2370         ["Show dormant" gnus-summary-limit-include-dormant t]
2371         ["Hide childless dormant"
2372          gnus-summary-limit-exclude-childless-dormant t]
2373         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2374         ["Hide marked" gnus-summary-limit-exclude-marks t]
2375         ["Show expunged" gnus-summary-limit-include-expunged t])
2376        ("Process Mark"
2377         ["Set mark" gnus-summary-mark-as-processable t]
2378         ["Remove mark" gnus-summary-unmark-as-processable t]
2379         ["Remove all marks" gnus-summary-unmark-all-processable t]
2380         ["Mark above" gnus-uu-mark-over t]
2381         ["Mark series" gnus-uu-mark-series t]
2382         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2383         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2384         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2385         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2386         ["Mark all" gnus-uu-mark-all t]
2387         ["Mark buffer" gnus-uu-mark-buffer t]
2388         ["Mark sparse" gnus-uu-mark-sparse t]
2389         ["Mark thread" gnus-uu-mark-thread t]
2390         ["Unmark thread" gnus-uu-unmark-thread t]
2391         ("Process Mark Sets"
2392          ["Kill" gnus-summary-kill-process-mark t]
2393          ["Yank" gnus-summary-yank-process-mark
2394           gnus-newsgroup-process-stack]
2395          ["Save" gnus-summary-save-process-mark t]
2396          ["Run command on marked..." gnus-summary-universal-argument t]))
2397        ("Scroll article"
2398         ["Page forward" gnus-summary-next-page
2399          ,@(if (featurep 'xemacs) '(t)
2400              '(:help "Show next page of article"))]
2401         ["Page backward" gnus-summary-prev-page
2402          ,@(if (featurep 'xemacs) '(t)
2403              '(:help "Show previous page of article"))]
2404         ["Line forward" gnus-summary-scroll-up t])
2405        ("Move"
2406         ["Next unread article" gnus-summary-next-unread-article t]
2407         ["Previous unread article" gnus-summary-prev-unread-article t]
2408         ["Next article" gnus-summary-next-article t]
2409         ["Previous article" gnus-summary-prev-article t]
2410         ["Next unread subject" gnus-summary-next-unread-subject t]
2411         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2412         ["Next article same subject" gnus-summary-next-same-subject t]
2413         ["Previous article same subject" gnus-summary-prev-same-subject t]
2414         ["First unread article" gnus-summary-first-unread-article t]
2415         ["Best unread article" gnus-summary-best-unread-article t]
2416         ["Go to subject number..." gnus-summary-goto-subject t]
2417         ["Go to article number..." gnus-summary-goto-article t]
2418         ["Go to the last article" gnus-summary-goto-last-article t]
2419         ["Pop article off history" gnus-summary-pop-article t])
2420        ("Sort"
2421         ["Sort by number" gnus-summary-sort-by-number t]
2422         ["Sort by author" gnus-summary-sort-by-author t]
2423         ["Sort by subject" gnus-summary-sort-by-subject t]
2424         ["Sort by date" gnus-summary-sort-by-date t]
2425         ["Sort by score" gnus-summary-sort-by-score t]
2426         ["Sort by lines" gnus-summary-sort-by-lines t]
2427         ["Sort by characters" gnus-summary-sort-by-chars t]
2428         ["Randomize" gnus-summary-sort-by-random t]
2429         ["Original sort" gnus-summary-sort-by-original t])
2430        ("Help"
2431         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2432         ["Describe group" gnus-summary-describe-group t]
2433         ["Fetch charter" gnus-group-fetch-charter
2434          ,@(if (featurep 'xemacs) nil
2435              '(:help "Display the charter of the current group"))]
2436         ["Fetch control message" gnus-group-fetch-control
2437          ,@(if (featurep 'xemacs) nil
2438              '(:help "Display the archived control message for the current group"))]
2439         ["Read manual" gnus-info-find-node t])
2440        ("Modes"
2441         ["Pick and read" gnus-pick-mode t]
2442         ["Binary" gnus-binary-mode t])
2443        ("Regeneration"
2444         ["Regenerate" gnus-summary-prepare t]
2445         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2446         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2447         ["Toggle threading" gnus-summary-toggle-threads t])
2448        ["See old articles" gnus-summary-insert-old-articles t]
2449        ["See new articles" gnus-summary-insert-new-articles t]
2450        ["Filter articles..." gnus-summary-execute-command t]
2451        ["Run command on articles..." gnus-summary-universal-argument t]
2452        ["Search articles forward..." gnus-summary-search-article-forward t]
2453        ["Search articles backward..." gnus-summary-search-article-backward t]
2454        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2455        ["Expand window" gnus-summary-expand-window t]
2456        ["Expire expirable articles" gnus-summary-expire-articles
2457         (gnus-check-backend-function
2458          'request-expire-articles gnus-newsgroup-name)]
2459        ["Edit local kill file" gnus-summary-edit-local-kill t]
2460        ["Edit main kill file" gnus-summary-edit-global-kill t]
2461        ["Edit group parameters" gnus-summary-edit-parameters t]
2462        ["Customize group parameters" gnus-summary-customize-parameters t]
2463        ["Send a bug report" gnus-bug t]
2464        ("Exit"
2465         ["Catchup and exit" gnus-summary-catchup-and-exit
2466          ,@(if (featurep 'xemacs) '(t)
2467              '(:help "Mark unread articles in this group as read, then exit"))]
2468         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2469         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2470         ["Exit group" gnus-summary-exit
2471          ,@(if (featurep 'xemacs) '(t)
2472              '(:help "Exit current group, return to group selection mode"))]
2473         ["Exit group without updating" gnus-summary-exit-no-update t]
2474         ["Exit and goto next group" gnus-summary-next-group t]
2475         ["Exit and goto prev group" gnus-summary-prev-group t]
2476         ["Reselect group" gnus-summary-reselect-current-group t]
2477         ["Rescan group" gnus-summary-rescan-group t]
2478         ["Update dribble" gnus-summary-save-newsrc t])))
2479
2480     (gnus-run-hooks 'gnus-summary-menu-hook)))
2481
2482 (defvar gnus-summary-tool-bar-map nil)
2483
2484 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2485 (defun gnus-summary-make-tool-bar ()
2486   (if (and (fboundp 'tool-bar-add-item-from-menu)
2487            (default-value 'tool-bar-mode)
2488            (not gnus-summary-tool-bar-map))
2489       (setq gnus-summary-tool-bar-map
2490             (let ((tool-bar-map (make-sparse-keymap))
2491                   (load-path (mm-image-load-path)))
2492               (tool-bar-add-item-from-menu
2493                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2494               (tool-bar-add-item-from-menu
2495                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2496               (tool-bar-add-item-from-menu
2497                'gnus-summary-post-news "post" gnus-summary-mode-map)
2498               (tool-bar-add-item-from-menu
2499                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2500               (tool-bar-add-item-from-menu
2501                'gnus-summary-followup "followup" gnus-summary-mode-map)
2502               (tool-bar-add-item-from-menu
2503                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2504               (tool-bar-add-item-from-menu
2505                'gnus-summary-reply "reply" gnus-summary-mode-map)
2506               (tool-bar-add-item-from-menu
2507                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2520               (tool-bar-add-item-from-menu
2521                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2522               tool-bar-map)))
2523   (if gnus-summary-tool-bar-map
2524       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2525
2526 (defun gnus-score-set-default (var value)
2527   "A version of set that updates the GNU Emacs menu-bar."
2528   (set var value)
2529   ;; It is the message that forces the active status to be updated.
2530   (message ""))
2531
2532 (defun gnus-make-score-map (type)
2533   "Make a summary score map of type TYPE."
2534   (if t
2535       nil
2536     (let ((headers '(("author" "from" string)
2537                      ("subject" "subject" string)
2538                      ("article body" "body" string)
2539                      ("article head" "head" string)
2540                      ("xref" "xref" string)
2541                      ("extra header" "extra" string)
2542                      ("lines" "lines" number)
2543                      ("followups to author" "followup" string)))
2544           (types '((number ("less than" <)
2545                            ("greater than" >)
2546                            ("equal" =))
2547                    (string ("substring" s)
2548                            ("exact string" e)
2549                            ("fuzzy string" f)
2550                            ("regexp" r))))
2551           (perms '(("temporary" (current-time-string))
2552                    ("permanent" nil)
2553                    ("immediate" now)))
2554           header)
2555       (list
2556        (apply
2557         'nconc
2558         (list
2559          (if (eq type 'lower)
2560              "Lower score"
2561            "Increase score"))
2562         (let (outh)
2563           (while headers
2564             (setq header (car headers))
2565             (setq outh
2566                   (cons
2567                    (apply
2568                     'nconc
2569                     (list (car header))
2570                     (let ((ts (cdr (assoc (nth 2 header) types)))
2571                           outt)
2572                       (while ts
2573                         (setq outt
2574                               (cons
2575                                (apply
2576                                 'nconc
2577                                 (list (caar ts))
2578                                 (let ((ps perms)
2579                                       outp)
2580                                   (while ps
2581                                     (setq outp
2582                                           (cons
2583                                            (vector
2584                                             (caar ps)
2585                                             (list
2586                                              'gnus-summary-score-entry
2587                                              (nth 1 header)
2588                                              (if (or (string= (nth 1 header)
2589                                                               "head")
2590                                                      (string= (nth 1 header)
2591                                                               "body"))
2592                                                  ""
2593                                                (list 'gnus-summary-header
2594                                                      (nth 1 header)))
2595                                              (list 'quote (nth 1 (car ts)))
2596                                              (list 'gnus-score-delta-default
2597                                                    nil)
2598                                              (nth 1 (car ps))
2599                                              t)
2600                                             t)
2601                                            outp))
2602                                     (setq ps (cdr ps)))
2603                                   (list (nreverse outp))))
2604                                outt))
2605                         (setq ts (cdr ts)))
2606                       (list (nreverse outt))))
2607                    outh))
2608             (setq headers (cdr headers)))
2609           (list (nreverse outh))))))))
2610
2611 \f
2612
2613 (defun gnus-summary-mode (&optional group)
2614   "Major mode for reading articles.
2615
2616 All normal editing commands are switched off.
2617 \\<gnus-summary-mode-map>
2618 Each line in this buffer represents one article.  To read an
2619 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2620 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2621 respectively.
2622
2623 You can also post articles and send mail from this buffer.  To
2624 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2625 of an article, type `\\[gnus-summary-reply]'.
2626
2627 There are approx. one gazillion commands you can execute in this
2628 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2629
2630 The following commands are available:
2631
2632 \\{gnus-summary-mode-map}"
2633   (interactive)
2634   (kill-all-local-variables)
2635   (when (gnus-visual-p 'summary-menu 'menu)
2636     (gnus-summary-make-menu-bar)
2637     (gnus-summary-make-tool-bar))
2638   (gnus-summary-make-local-variables)
2639   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2640     (gnus-summary-make-local-variables))
2641   (gnus-make-thread-indent-array)
2642   (gnus-simplify-mode-line)
2643   (setq major-mode 'gnus-summary-mode)
2644   (setq mode-name "Summary")
2645   (make-local-variable 'minor-mode-alist)
2646   (use-local-map gnus-summary-mode-map)
2647   (buffer-disable-undo)
2648   (setq buffer-read-only t)             ;Disable modification
2649   (setq truncate-lines t)
2650   (setq selective-display t)
2651   (setq selective-display-ellipses t)   ;Display `...'
2652   (gnus-summary-set-display-table)
2653   (gnus-set-default-directory)
2654   (setq gnus-newsgroup-name group)
2655   (unless (gnus-news-group-p group)
2656     (setq gnus-newsgroup-incorporated
2657           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2658   (make-local-variable 'gnus-summary-line-format)
2659   (make-local-variable 'gnus-summary-line-format-spec)
2660   (make-local-variable 'gnus-summary-dummy-line-format)
2661   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2662   (make-local-variable 'gnus-summary-mark-positions)
2663   (make-local-hook 'pre-command-hook)
2664   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2665   (gnus-run-hooks 'gnus-summary-mode-hook)
2666   (turn-on-gnus-mailing-list-mode)
2667   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2668   (gnus-update-summary-mark-positions))
2669
2670 (defun gnus-summary-make-local-variables ()
2671   "Make all the local summary buffer variables."
2672   (let (global)
2673     (dolist (local gnus-summary-local-variables)
2674       (if (consp local)
2675           (progn
2676             (if (eq (cdr local) 'global)
2677                 ;; Copy the global value of the variable.
2678                 (setq global (symbol-value (car local)))
2679               ;; Use the value from the list.
2680               (setq global (eval (cdr local))))
2681             (set (make-local-variable (car local)) global))
2682         ;; Simple nil-valued local variable.
2683         (set (make-local-variable local) nil)))))
2684
2685 (defun gnus-summary-clear-local-variables ()
2686   (let ((locals gnus-summary-local-variables))
2687     (while locals
2688       (if (consp (car locals))
2689           (and (vectorp (caar locals))
2690                (set (caar locals) nil))
2691         (and (vectorp (car locals))
2692              (set (car locals) nil)))
2693       (setq locals (cdr locals)))))
2694
2695 ;; Summary data functions.
2696
2697 (defmacro gnus-data-number (data)
2698   `(car ,data))
2699
2700 (defmacro gnus-data-set-number (data number)
2701   `(setcar ,data ,number))
2702
2703 (defmacro gnus-data-mark (data)
2704   `(nth 1 ,data))
2705
2706 (defmacro gnus-data-set-mark (data mark)
2707   `(setcar (nthcdr 1 ,data) ,mark))
2708
2709 (defmacro gnus-data-pos (data)
2710   `(nth 2 ,data))
2711
2712 (defmacro gnus-data-set-pos (data pos)
2713   `(setcar (nthcdr 2 ,data) ,pos))
2714
2715 (defmacro gnus-data-header (data)
2716   `(nth 3 ,data))
2717
2718 (defmacro gnus-data-set-header (data header)
2719   `(setcar (nthcdr 3 ,data) ,header))
2720
2721 (defmacro gnus-data-level (data)
2722   `(nth 4 ,data))
2723
2724 (defmacro gnus-data-unread-p (data)
2725   `(= (nth 1 ,data) gnus-unread-mark))
2726
2727 (defmacro gnus-data-read-p (data)
2728   `(/= (nth 1 ,data) gnus-unread-mark))
2729
2730 (defmacro gnus-data-pseudo-p (data)
2731   `(consp (nth 3 ,data)))
2732
2733 (defmacro gnus-data-find (number)
2734   `(assq ,number gnus-newsgroup-data))
2735
2736 (defmacro gnus-data-find-list (number &optional data)
2737   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2738      (memq (assq ,number bdata)
2739            bdata)))
2740
2741 (defmacro gnus-data-make (number mark pos header level)
2742   `(list ,number ,mark ,pos ,header ,level))
2743
2744 (defun gnus-data-enter (after-article number mark pos header level offset)
2745   (let ((data (gnus-data-find-list after-article)))
2746     (unless data
2747       (error "No such article: %d" after-article))
2748     (setcdr data (cons (gnus-data-make number mark pos header level)
2749                        (cdr data)))
2750     (setq gnus-newsgroup-data-reverse nil)
2751     (gnus-data-update-list (cddr data) offset)))
2752
2753 (defun gnus-data-enter-list (after-article list &optional offset)
2754   (when list
2755     (let ((data (and after-article (gnus-data-find-list after-article)))
2756           (ilist list))
2757       (if (not (or data
2758                    after-article))
2759           (let ((odata gnus-newsgroup-data))
2760             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2761             (when offset
2762               (gnus-data-update-list odata offset)))
2763         ;; Find the last element in the list to be spliced into the main
2764         ;; list.
2765         (while (cdr list)
2766           (setq list (cdr list)))
2767         (if (not data)
2768             (progn
2769               (setcdr list gnus-newsgroup-data)
2770               (setq gnus-newsgroup-data ilist)
2771               (when offset
2772                 (gnus-data-update-list (cdr list) offset)))
2773           (setcdr list (cdr data))
2774           (setcdr data ilist)
2775           (when offset
2776             (gnus-data-update-list (cdr list) offset))))
2777       (setq gnus-newsgroup-data-reverse nil))))
2778
2779 (defun gnus-data-remove (article &optional offset)
2780   (let ((data gnus-newsgroup-data))
2781     (if (= (gnus-data-number (car data)) article)
2782         (progn
2783           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2784                 gnus-newsgroup-data-reverse nil)
2785           (when offset
2786             (gnus-data-update-list gnus-newsgroup-data offset)))
2787       (while (cdr data)
2788         (when (= (gnus-data-number (cadr data)) article)
2789           (setcdr data (cddr data))
2790           (when offset
2791             (gnus-data-update-list (cdr data) offset))
2792           (setq data nil
2793                 gnus-newsgroup-data-reverse nil))
2794         (setq data (cdr data))))))
2795
2796 (defmacro gnus-data-list (backward)
2797   `(if ,backward
2798        (or gnus-newsgroup-data-reverse
2799            (setq gnus-newsgroup-data-reverse
2800                  (reverse gnus-newsgroup-data)))
2801      gnus-newsgroup-data))
2802
2803 (defun gnus-data-update-list (data offset)
2804   "Add OFFSET to the POS of all data entries in DATA."
2805   (setq gnus-newsgroup-data-reverse nil)
2806   (while data
2807     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2808     (setq data (cdr data))))
2809
2810 (defun gnus-summary-article-pseudo-p (article)
2811   "Say whether this article is a pseudo article or not."
2812   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2813
2814 (defmacro gnus-summary-article-sparse-p (article)
2815   "Say whether this article is a sparse article or not."
2816   `(memq ,article gnus-newsgroup-sparse))
2817
2818 (defmacro gnus-summary-article-ancient-p (article)
2819   "Say whether this article is a sparse article or not."
2820   `(memq ,article gnus-newsgroup-ancient))
2821
2822 (defun gnus-article-parent-p (number)
2823   "Say whether this article is a parent or not."
2824   (let ((data (gnus-data-find-list number)))
2825     (and (cdr data)                     ; There has to be an article after...
2826          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2827             (gnus-data-level (nth 1 data))))))
2828
2829 (defun gnus-article-children (number)
2830   "Return a list of all children to NUMBER."
2831   (let* ((data (gnus-data-find-list number))
2832          (level (gnus-data-level (car data)))
2833          children)
2834     (setq data (cdr data))
2835     (while (and data
2836                 (= (gnus-data-level (car data)) (1+ level)))
2837       (push (gnus-data-number (car data)) children)
2838       (setq data (cdr data)))
2839     children))
2840
2841 (defmacro gnus-summary-skip-intangible ()
2842   "If the current article is intangible, then jump to a different article."
2843   '(let ((to (get-text-property (point) 'gnus-intangible)))
2844      (and to (gnus-summary-goto-subject to))))
2845
2846 (defmacro gnus-summary-article-intangible-p ()
2847   "Say whether this article is intangible or not."
2848   '(get-text-property (point) 'gnus-intangible))
2849
2850 (defun gnus-article-read-p (article)
2851   "Say whether ARTICLE is read or not."
2852   (not (or (memq article gnus-newsgroup-marked)
2853            (memq article gnus-newsgroup-spam-marked)
2854            (memq article gnus-newsgroup-unreads)
2855            (memq article gnus-newsgroup-unselected)
2856            (memq article gnus-newsgroup-dormant))))
2857
2858 ;; Some summary mode macros.
2859
2860 (defmacro gnus-summary-article-number ()
2861   "The article number of the article on the current line.
2862 If there isn't an article number here, then we return the current
2863 article number."
2864   '(progn
2865      (gnus-summary-skip-intangible)
2866      (or (get-text-property (point) 'gnus-number)
2867          (gnus-summary-last-subject))))
2868
2869 (defmacro gnus-summary-article-header (&optional number)
2870   "Return the header of article NUMBER."
2871   `(gnus-data-header (gnus-data-find
2872                       ,(or number '(gnus-summary-article-number)))))
2873
2874 (defmacro gnus-summary-thread-level (&optional number)
2875   "Return the level of thread that starts with article NUMBER."
2876   `(if (and (eq gnus-summary-make-false-root 'dummy)
2877             (get-text-property (point) 'gnus-intangible))
2878        0
2879      (gnus-data-level (gnus-data-find
2880                        ,(or number '(gnus-summary-article-number))))))
2881
2882 (defmacro gnus-summary-article-mark (&optional number)
2883   "Return the mark of article NUMBER."
2884   `(gnus-data-mark (gnus-data-find
2885                     ,(or number '(gnus-summary-article-number)))))
2886
2887 (defmacro gnus-summary-article-pos (&optional number)
2888   "Return the position of the line of article NUMBER."
2889   `(gnus-data-pos (gnus-data-find
2890                    ,(or number '(gnus-summary-article-number)))))
2891
2892 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2893 (defmacro gnus-summary-article-subject (&optional number)
2894   "Return current subject string or nil if nothing."
2895   `(let ((headers
2896           ,(if number
2897                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2898              '(gnus-data-header (assq (gnus-summary-article-number)
2899                                       gnus-newsgroup-data)))))
2900      (and headers
2901           (vectorp headers)
2902           (mail-header-subject headers))))
2903
2904 (defmacro gnus-summary-article-score (&optional number)
2905   "Return current article score."
2906   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2907                   gnus-newsgroup-scored))
2908        gnus-summary-default-score 0))
2909
2910 (defun gnus-summary-article-children (&optional number)
2911   "Return a list of article numbers that are children of article NUMBER."
2912   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2913          (level (gnus-data-level (car data)))
2914          l children)
2915     (while (and (setq data (cdr data))
2916                 (> (setq l (gnus-data-level (car data))) level))
2917       (and (= (1+ level) l)
2918            (push (gnus-data-number (car data))
2919                  children)))
2920     (nreverse children)))
2921
2922 (defun gnus-summary-article-parent (&optional number)
2923   "Return the article number of the parent of article NUMBER."
2924   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2925                                     (gnus-data-list t)))
2926          (level (gnus-data-level (car data))))
2927     (if (zerop level)
2928         ()                              ; This is a root.
2929       ;; We search until we find an article with a level less than
2930       ;; this one.  That function has to be the parent.
2931       (while (and (setq data (cdr data))
2932                   (not (< (gnus-data-level (car data)) level))))
2933       (and data (gnus-data-number (car data))))))
2934
2935 (defun gnus-unread-mark-p (mark)
2936   "Say whether MARK is the unread mark."
2937   (= mark gnus-unread-mark))
2938
2939 (defun gnus-read-mark-p (mark)
2940   "Say whether MARK is one of the marks that mark as read.
2941 This is all marks except unread, ticked, dormant, and expirable."
2942   (not (or (= mark gnus-unread-mark)
2943            (= mark gnus-ticked-mark)
2944            (= mark gnus-spam-mark)
2945            (= mark gnus-dormant-mark)
2946            (= mark gnus-expirable-mark))))
2947
2948 (defmacro gnus-article-mark (number)
2949   "Return the MARK of article NUMBER.
2950 This macro should only be used when computing the mark the \"first\"
2951 time; i.e., when generating the summary lines.  After that,
2952 `gnus-summary-article-mark' should be used to examine the
2953 marks of articles."
2954   `(cond
2955     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2956     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2957     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2958     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2959     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2960     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2961     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2962     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2963            gnus-ancient-mark))))
2964
2965 ;; Saving hidden threads.
2966
2967 (defmacro gnus-save-hidden-threads (&rest forms)
2968   "Save hidden threads, eval FORMS, and restore the hidden threads."
2969   (let ((config (make-symbol "config")))
2970     `(let ((,config (gnus-hidden-threads-configuration)))
2971        (unwind-protect
2972            (save-excursion
2973              ,@forms)
2974          (gnus-restore-hidden-threads-configuration ,config)))))
2975 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2976 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2977
2978 (defun gnus-data-compute-positions ()
2979   "Compute the positions of all articles."
2980   (setq gnus-newsgroup-data-reverse nil)
2981   (let ((data gnus-newsgroup-data))
2982     (save-excursion
2983       (gnus-save-hidden-threads
2984         (gnus-summary-show-all-threads)
2985         (goto-char (point-min))
2986         (while data
2987           (while (get-text-property (point) 'gnus-intangible)
2988             (forward-line 1))
2989           (gnus-data-set-pos (car data) (+ (point) 3))
2990           (setq data (cdr data))
2991           (forward-line 1))))))
2992
2993 (defun gnus-hidden-threads-configuration ()
2994   "Return the current hidden threads configuration."
2995   (save-excursion
2996     (let (config)
2997       (goto-char (point-min))
2998       (while (search-forward "\r" nil t)
2999         (push (1- (point)) config))
3000       config)))
3001
3002 (defun gnus-restore-hidden-threads-configuration (config)
3003   "Restore hidden threads configuration from CONFIG."
3004   (save-excursion
3005     (let (point buffer-read-only)
3006       (while (setq point (pop config))
3007         (when (and (< point (point-max))
3008                    (goto-char point)
3009                    (eq (char-after) ?\n))
3010           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3011
3012 ;; Various summary mode internalish functions.
3013
3014 (defun gnus-mouse-pick-article (e)
3015   (interactive "e")
3016   (mouse-set-point e)
3017   (gnus-summary-next-page nil t))
3018
3019 (defun gnus-summary-set-display-table ()
3020   "Change the display table.
3021 Odd characters have a tendency to mess
3022 up nicely formatted displays - we make all possible glyphs
3023 display only a single character."
3024
3025   ;; We start from the standard display table, if any.
3026   (let ((table (or (copy-sequence standard-display-table)
3027                    (make-display-table)))
3028         (i 32))
3029     ;; Nix out all the control chars...
3030     (while (>= (setq i (1- i)) 0)
3031       (aset table i [??]))
3032     ;; ... but not newline and cr, of course.  (cr is necessary for the
3033     ;; selective display).
3034     (aset table ?\n nil)
3035     (aset table ?\r nil)
3036     ;; We keep TAB as well.
3037     (aset table ?\t nil)
3038     ;; We nix out any glyphs over 126 that are not set already.
3039     (let ((i 256))
3040       (while (>= (setq i (1- i)) 127)
3041         ;; Only modify if the entry is nil.
3042         (unless (aref table i)
3043           (aset table i [??]))))
3044     (setq buffer-display-table table)))
3045
3046 (defun gnus-summary-set-article-display-arrow (pos)
3047   "Update the overlay arrow to point to line at position POS."
3048   (when (and gnus-summary-display-arrow
3049              (boundp 'overlay-arrow-position)
3050              (boundp 'overlay-arrow-string))
3051     (save-excursion
3052       (goto-char pos)
3053       (beginning-of-line)
3054       (unless overlay-arrow-position
3055         (setq overlay-arrow-position (make-marker)))
3056       (setq overlay-arrow-string "=>"
3057             overlay-arrow-position (set-marker overlay-arrow-position
3058                                                (point)
3059                                                (current-buffer))))))
3060
3061 (defun gnus-summary-setup-buffer (group)
3062   "Initialize summary buffer."
3063   (let ((buffer (gnus-summary-buffer-name group))
3064         (dead-name (concat "*Dead Summary "
3065                            (gnus-group-decoded-name group) "*")))
3066     ;; If a dead summary buffer exists, we kill it.
3067     (when (gnus-buffer-live-p dead-name)
3068       (gnus-kill-buffer dead-name))
3069     (if (get-buffer buffer)
3070         (progn
3071           (set-buffer buffer)
3072           (setq gnus-summary-buffer (current-buffer))
3073           (not gnus-newsgroup-prepared))
3074       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3075       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3076       (gnus-summary-mode group)
3077       (when gnus-carpal
3078         (gnus-carpal-setup-buffer 'summary))
3079       (unless gnus-single-article-buffer
3080         (make-local-variable 'gnus-article-buffer)
3081         (make-local-variable 'gnus-article-current)
3082         (make-local-variable 'gnus-original-article-buffer))
3083       (setq gnus-newsgroup-name group)
3084       ;; Set any local variables in the group parameters.
3085       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3086       t)))
3087
3088 (defun gnus-set-global-variables ()
3089   "Set the global equivalents of the buffer-local variables.
3090 They are set to the latest values they had.  These reflect the summary
3091 buffer that was in action when the last article was fetched."
3092   (when (eq major-mode 'gnus-summary-mode)
3093     (setq gnus-summary-buffer (current-buffer))
3094     (let ((name gnus-newsgroup-name)
3095           (marked gnus-newsgroup-marked)
3096           (spam gnus-newsgroup-spam-marked)
3097           (unread gnus-newsgroup-unreads)
3098           (headers gnus-current-headers)
3099           (data gnus-newsgroup-data)
3100           (summary gnus-summary-buffer)
3101           (article-buffer gnus-article-buffer)
3102           (original gnus-original-article-buffer)
3103           (gac gnus-article-current)
3104           (reffed gnus-reffed-article-number)
3105           (score-file gnus-current-score-file)
3106           (default-charset gnus-newsgroup-charset)
3107           vlist)
3108       (let ((locals gnus-newsgroup-variables))
3109         (while locals
3110           (if (consp (car locals))
3111               (push (eval (caar locals)) vlist)
3112             (push (eval (car locals)) vlist))
3113           (setq locals (cdr locals)))
3114         (setq vlist (nreverse vlist)))
3115       (save-excursion
3116         (set-buffer gnus-group-buffer)
3117         (setq gnus-newsgroup-name name
3118               gnus-newsgroup-marked marked
3119               gnus-newsgroup-spam-marked spam
3120               gnus-newsgroup-unreads unread
3121               gnus-current-headers headers
3122               gnus-newsgroup-data data
3123               gnus-article-current gac
3124               gnus-summary-buffer summary
3125               gnus-article-buffer article-buffer
3126               gnus-original-article-buffer original
3127               gnus-reffed-article-number reffed
3128               gnus-current-score-file score-file
3129               gnus-newsgroup-charset default-charset)
3130         (let ((locals gnus-newsgroup-variables))
3131           (while locals
3132             (if (consp (car locals))
3133                 (set (caar locals) (pop vlist))
3134               (set (car locals) (pop vlist)))
3135             (setq locals (cdr locals))))
3136         ;; The article buffer also has local variables.
3137         (when (gnus-buffer-live-p gnus-article-buffer)
3138           (set-buffer gnus-article-buffer)
3139           (setq gnus-summary-buffer summary))))))
3140
3141 (defun gnus-summary-article-unread-p (article)
3142   "Say whether ARTICLE is unread or not."
3143   (memq article gnus-newsgroup-unreads))
3144
3145 (defun gnus-summary-first-article-p (&optional article)
3146   "Return whether ARTICLE is the first article in the buffer."
3147   (if (not (setq article (or article (gnus-summary-article-number))))
3148       nil
3149     (eq article (caar gnus-newsgroup-data))))
3150
3151 (defun gnus-summary-last-article-p (&optional article)
3152   "Return whether ARTICLE is the last article in the buffer."
3153   (if (not (setq article (or article (gnus-summary-article-number))))
3154       ;; All non-existent numbers are the last article.  :-)
3155       t
3156     (not (cdr (gnus-data-find-list article)))))
3157
3158 (defun gnus-make-thread-indent-array ()
3159   (let ((n 200))
3160     (unless (and gnus-thread-indent-array
3161                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3162       (setq gnus-thread-indent-array (make-vector 201 "")
3163             gnus-thread-indent-array-level gnus-thread-indent-level)
3164       (while (>= n 0)
3165         (aset gnus-thread-indent-array n
3166               (make-string (* n gnus-thread-indent-level) ? ))
3167         (setq n (1- n))))))
3168
3169 (defun gnus-update-summary-mark-positions ()
3170   "Compute where the summary marks are to go."
3171   (save-excursion
3172     (when (gnus-buffer-exists-p gnus-summary-buffer)
3173       (set-buffer gnus-summary-buffer))
3174     (let ((gnus-replied-mark 129)
3175           (gnus-score-below-mark 130)
3176           (gnus-score-over-mark 130)
3177           (gnus-undownloaded-mark 131)
3178           (spec gnus-summary-line-format-spec)
3179           gnus-visual pos)
3180       (save-excursion
3181         (gnus-set-work-buffer)
3182         (let ((gnus-summary-line-format-spec spec)
3183               (gnus-newsgroup-downloadable '(0)))
3184           (gnus-summary-insert-line
3185            (make-full-mail-header 0 "" "nobody"
3186                                   "05 Apr 2001 23:33:09 +0400"
3187                                   "" "" 0 0 "" nil)
3188            0 nil t 128 t nil "" nil 1)
3189           (goto-char (point-min))
3190           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3191                                              (- (point) (point-min) 1)))))
3192           (goto-char (point-min))
3193           (push (cons 'replied (and (search-forward "\201" nil t)
3194                                     (- (point) (point-min) 1)))
3195                 pos)
3196           (goto-char (point-min))
3197           (push (cons 'score (and (search-forward "\202" nil t)
3198                                   (- (point) (point-min) 1)))
3199                 pos)
3200           (goto-char (point-min))
3201           (push (cons 'download
3202                       (and (search-forward "\203" nil t)
3203                            (- (point) (point-min) 1)))
3204                 pos)))
3205       (setq gnus-summary-mark-positions pos))))
3206
3207 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3208   "Insert a dummy root in the summary buffer."
3209   (beginning-of-line)
3210   (gnus-add-text-properties
3211    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3212    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3213
3214 (defun gnus-summary-extract-address-component (from)
3215   (or (car (funcall gnus-extract-address-components from))
3216       from))
3217
3218 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3219   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3220                                 default-mime-charset)))
3221     ;; Is it really necessary to do this next part for each summary line?
3222     ;; Luckily, doesn't seem to slow things down much.
3223     (or
3224      (and gnus-ignored-from-addresses
3225           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3226           (let ((extra-headers (mail-header-extra header))
3227                 to
3228                 newsgroups)
3229             (cond
3230              ((setq to (cdr (assq 'To extra-headers)))
3231               (concat "-> "
3232                       (inline
3233                         (gnus-summary-extract-address-component
3234                          (funcall gnus-decode-encoded-word-function to)))))
3235              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3236               (concat "=> " newsgroups)))))
3237      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3238
3239 (defun gnus-summary-insert-line (gnus-tmp-header
3240                                  gnus-tmp-level gnus-tmp-current
3241                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3242                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3243                                  &optional gnus-tmp-dummy gnus-tmp-score
3244                                  gnus-tmp-process)
3245   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3246          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3247          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3248          (gnus-tmp-score-char
3249           (if (or (null gnus-summary-default-score)
3250                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3251                       gnus-summary-zcore-fuzz))
3252               ?\ ;;;Whitespace
3253             (if (< gnus-tmp-score gnus-summary-default-score)
3254                 gnus-score-below-mark gnus-score-over-mark)))
3255          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3256          (gnus-tmp-replied
3257           (cond (gnus-tmp-process gnus-process-mark)
3258                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3259                  gnus-cached-mark)
3260                 (gnus-tmp-replied gnus-replied-mark)
3261                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3262                  gnus-forwarded-mark)
3263                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3264                  gnus-saved-mark)
3265                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3266                  gnus-recent-mark)
3267                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3268                  gnus-unseen-mark)
3269                 (t gnus-no-mark)))
3270          (gnus-tmp-downloaded
3271           (cond (undownloaded 
3272                  gnus-undownloaded-mark)
3273                 (gnus-newsgroup-agentized
3274                  gnus-downloaded-mark)
3275                 (t
3276                  gnus-no-mark)))
3277          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3278          (gnus-tmp-name
3279           (cond
3280            ((string-match "<[^>]+> *$" gnus-tmp-from)
3281             (let ((beg (match-beginning 0)))
3282               (or (and (string-match "^\".+\"" gnus-tmp-from)
3283                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3284                   (substring gnus-tmp-from 0 beg))))
3285            ((string-match "(.+)" gnus-tmp-from)
3286             (substring gnus-tmp-from
3287                        (1+ (match-beginning 0)) (1- (match-end 0))))
3288            (t gnus-tmp-from)))
3289          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3290          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3291          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3292          (buffer-read-only nil))
3293     (when (string= gnus-tmp-name "")
3294       (setq gnus-tmp-name gnus-tmp-from))
3295     (unless (numberp gnus-tmp-lines)
3296       (setq gnus-tmp-lines -1))
3297     (if (= gnus-tmp-lines -1)
3298         (setq gnus-tmp-lines "?")
3299       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3300     (gnus-put-text-property-excluding-characters-with-faces
3301      (point)
3302      (progn (eval gnus-summary-line-format-spec) (point))
3303      'gnus-number gnus-tmp-number)
3304     (when (gnus-visual-p 'summary-highlight 'highlight)
3305       (forward-line -1)
3306       (gnus-run-hooks 'gnus-summary-update-hook)
3307       (forward-line 1))))
3308
3309 (defun gnus-summary-update-line (&optional dont-update)
3310   "Update summary line after change."
3311   (when (and gnus-summary-default-score
3312              (not gnus-summary-inhibit-highlight))
3313     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3314            (article (gnus-summary-article-number))
3315            (score (gnus-summary-article-score article)))
3316       (unless dont-update
3317         (if (and gnus-summary-mark-below
3318                  (< (gnus-summary-article-score)
3319                     gnus-summary-mark-below))
3320             ;; This article has a low score, so we mark it as read.
3321             (when (memq article gnus-newsgroup-unreads)
3322               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3323           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3324             ;; This article was previously marked as read on account
3325             ;; of a low score, but now it has risen, so we mark it as
3326             ;; unread.
3327             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3328         (gnus-summary-update-mark
3329          (if (or (null gnus-summary-default-score)
3330                  (<= (abs (- score gnus-summary-default-score))
3331                      gnus-summary-zcore-fuzz))
3332              ?\ ;;;Whitespace
3333            (if (< score gnus-summary-default-score)
3334                gnus-score-below-mark gnus-score-over-mark))
3335          'score))
3336       ;; Do visual highlighting.
3337       (when (gnus-visual-p 'summary-highlight 'highlight)
3338         (gnus-run-hooks 'gnus-summary-update-hook)))))
3339
3340 (defvar gnus-tmp-new-adopts nil)
3341
3342 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3343   "Return the number of articles in THREAD.
3344 This may be 0 in some cases -- if none of the articles in
3345 the thread are to be displayed."
3346   (let* ((number
3347           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3348           (cond
3349            ((not (listp thread))
3350             1)
3351            ((and (consp thread) (cdr thread))
3352             (apply
3353              '+ 1 (mapcar
3354                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3355            ((null thread)
3356             1)
3357            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3358             1)
3359            (t 0))))
3360     (when (and level (zerop level) gnus-tmp-new-adopts)
3361       (incf number
3362             (apply '+ (mapcar
3363                        'gnus-summary-number-of-articles-in-thread
3364                        gnus-tmp-new-adopts))))
3365     (if char
3366         (if (> number 1) gnus-not-empty-thread-mark
3367           gnus-empty-thread-mark)
3368       number)))
3369
3370 (defsubst gnus-summary-line-message-size (head)
3371   "Return pretty-printed version of message size.
3372 This function is intended to be used in
3373 `gnus-summary-line-format-alist', which see."
3374   (let ((c (or (mail-header-chars head) -1)))
3375     (cond ((< c 0) "n/a")               ; chars not available
3376           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3377           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3378           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3379           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3380
3381
3382 (defun gnus-summary-set-local-parameters (group)
3383   "Go through the local params of GROUP and set all variable specs in that list."
3384   (let ((params (gnus-group-find-parameter group))
3385         (vars '(quit-config))           ; Ignore quit-config.
3386         elem)
3387     (while params
3388       (setq elem (car params)
3389             params (cdr params))
3390       (and (consp elem)                 ; Has to be a cons.
3391            (consp (cdr elem))           ; The cdr has to be a list.
3392            (symbolp (car elem))         ; Has to be a symbol in there.
3393            (not (memq (car elem) vars))
3394            (ignore-errors               ; So we set it.
3395              (push (car elem) vars)
3396              (make-local-variable (car elem))
3397              (set (car elem) (eval (nth 1 elem))))))))
3398
3399 (defun gnus-summary-read-group (group &optional show-all no-article
3400                                       kill-buffer no-display backward
3401                                       select-articles)
3402   "Start reading news in newsgroup GROUP.
3403 If SHOW-ALL is non-nil, already read articles are also listed.
3404 If NO-ARTICLE is non-nil, no article is selected initially.
3405 If NO-DISPLAY, don't generate a summary buffer."
3406   (let (result)
3407     (while (and group
3408                 (null (setq result
3409                             (let ((gnus-auto-select-next nil))
3410                               (or (gnus-summary-read-group-1
3411                                    group show-all no-article
3412                                    kill-buffer no-display
3413                                    select-articles)
3414                                   (setq show-all nil
3415                                         select-articles nil)))))
3416                 (eq gnus-auto-select-next 'quietly))
3417       (set-buffer gnus-group-buffer)
3418       ;; The entry function called above goes to the next
3419       ;; group automatically, so we go two groups back
3420       ;; if we are searching for the previous group.
3421       (when backward
3422         (gnus-group-prev-unread-group 2))
3423       (if (not (equal group (gnus-group-group-name)))
3424           (setq group (gnus-group-group-name))
3425         (setq group nil)))
3426     result))
3427
3428 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3429   "Directly jump to the other GROUP from summary buffer.
3430 If SHOW-ALL is non-nil, already read articles are also listed."
3431   (interactive
3432    (if (eq gnus-summary-buffer (current-buffer))
3433        (list (completing-read
3434               "Group: " gnus-active-hashtb nil t
3435               (when (and gnus-newsgroup-name
3436                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3437                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3438               'gnus-group-history)
3439              current-prefix-arg)
3440      (error "%s must be invoked from a gnus summary buffer." this-command)))
3441   (unless (or (zerop (length group))
3442               (and gnus-newsgroup-name
3443                    (string-equal gnus-newsgroup-name group)))
3444     (gnus-summary-exit)
3445     (gnus-summary-read-group group show-all
3446                              gnus-dont-select-after-jump-to-other-group)))
3447
3448 (defun gnus-summary-read-group-1 (group show-all no-article
3449                                         kill-buffer no-display
3450                                         &optional select-articles)
3451   ;; Killed foreign groups can't be entered.
3452   ;;  (when (and (not (gnus-group-native-p group))
3453   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3454   ;;    (error "Dead non-native groups can't be entered"))
3455   (gnus-message 5 "Retrieving newsgroup: %s..."
3456                 (gnus-group-decoded-name group))
3457   (let* ((new-group (gnus-summary-setup-buffer group))
3458          (quit-config (gnus-group-quit-config group))
3459          (did-select (and new-group (gnus-select-newsgroup
3460                                      group show-all select-articles))))
3461     (cond
3462      ;; This summary buffer exists already, so we just select it.
3463      ((not new-group)
3464       (gnus-set-global-variables)
3465       (when kill-buffer
3466         (gnus-kill-or-deaden-summary kill-buffer))
3467       (gnus-configure-windows 'summary 'force)
3468       (gnus-set-mode-line 'summary)
3469       (gnus-summary-position-point)
3470       (message "")
3471       t)
3472      ;; We couldn't select this group.
3473      ((null did-select)
3474       (when (and (eq major-mode 'gnus-summary-mode)
3475                  (not (equal (current-buffer) kill-buffer)))
3476         (kill-buffer (current-buffer))
3477         (if (not quit-config)
3478             (progn
3479               ;; Update the info -- marks might need to be removed,
3480               ;; for instance.
3481               (gnus-summary-update-info)
3482               (set-buffer gnus-group-buffer)
3483               (gnus-group-jump-to-group group)
3484               (gnus-group-next-unread-group 1))
3485           (gnus-handle-ephemeral-exit quit-config)))
3486       (let ((grpinfo (gnus-get-info group)))
3487         (if (null (gnus-info-read grpinfo))
3488             (gnus-message 3 "Group %s contains no messages"
3489                           (gnus-group-decoded-name group))
3490           (gnus-message 3 "Can't select group")))
3491       nil)
3492      ;; The user did a `C-g' while prompting for number of articles,
3493      ;; so we exit this group.
3494      ((eq did-select 'quit)
3495       (and (eq major-mode 'gnus-summary-mode)
3496            (not (equal (current-buffer) kill-buffer))
3497            (kill-buffer (current-buffer)))
3498       (when kill-buffer
3499         (gnus-kill-or-deaden-summary kill-buffer))
3500       (if (not quit-config)
3501           (progn
3502             (set-buffer gnus-group-buffer)
3503             (gnus-group-jump-to-group group)
3504             (gnus-group-next-unread-group 1)
3505             (gnus-configure-windows 'group 'force))
3506         (gnus-handle-ephemeral-exit quit-config))
3507       ;; Finally signal the quit.
3508       (signal 'quit nil))
3509      ;; The group was successfully selected.
3510      (t
3511       (gnus-set-global-variables)
3512       ;; Save the active value in effect when the group was entered.
3513       (setq gnus-newsgroup-active
3514             (gnus-copy-sequence
3515              (gnus-active gnus-newsgroup-name)))
3516       ;; You can change the summary buffer in some way with this hook.
3517       (gnus-run-hooks 'gnus-select-group-hook)
3518       (gnus-update-format-specifications
3519        nil 'summary 'summary-mode 'summary-dummy)
3520       (gnus-update-summary-mark-positions)
3521       ;; Do score processing.
3522       (when gnus-use-scoring
3523         (gnus-possibly-score-headers))
3524       ;; Check whether to fill in the gaps in the threads.
3525       (when gnus-build-sparse-threads
3526         (gnus-build-sparse-threads))
3527       ;; Find the initial limit.
3528       (if gnus-show-threads
3529           (if show-all
3530               (let ((gnus-newsgroup-dormant nil))
3531                 (gnus-summary-initial-limit show-all))
3532             (gnus-summary-initial-limit show-all))
3533         ;; When unthreaded, all articles are always shown.
3534         (setq gnus-newsgroup-limit
3535               (mapcar
3536                (lambda (header) (mail-header-number header))
3537                gnus-newsgroup-headers)))
3538       ;; Generate the summary buffer.
3539       (unless no-display
3540         (gnus-summary-prepare))
3541       (when gnus-use-trees
3542         (gnus-tree-open group)
3543         (setq gnus-summary-highlight-line-function
3544               'gnus-tree-highlight-article))
3545       ;; If the summary buffer is empty, but there are some low-scored
3546       ;; articles or some excluded dormants, we include these in the
3547       ;; buffer.
3548       (when (and (zerop (buffer-size))
3549                  (not no-display))
3550         (cond (gnus-newsgroup-dormant
3551                (gnus-summary-limit-include-dormant))
3552               ((and gnus-newsgroup-scored show-all)
3553                (gnus-summary-limit-include-expunged t))))
3554       ;; Function `gnus-apply-kill-file' must be called in this hook.
3555       (gnus-run-hooks 'gnus-apply-kill-hook)
3556       (if (and (zerop (buffer-size))
3557                (not no-display))
3558           (progn
3559             ;; This newsgroup is empty.
3560             (gnus-summary-catchup-and-exit nil t)
3561             (gnus-message 6 "No unread news")
3562             (when kill-buffer
3563               (gnus-kill-or-deaden-summary kill-buffer))
3564             ;; Return nil from this function.
3565             nil)
3566         ;; Hide conversation thread subtrees.  We cannot do this in
3567         ;; gnus-summary-prepare-hook since kill processing may not
3568         ;; work with hidden articles.
3569         (gnus-summary-maybe-hide-threads)
3570         (when kill-buffer
3571           (gnus-kill-or-deaden-summary kill-buffer))
3572         (gnus-summary-auto-select-subject)
3573         ;; Show first unread article if requested.
3574         (if (and (not no-article)
3575                  (not no-display)
3576                  gnus-newsgroup-unreads
3577                  gnus-auto-select-first)
3578             (progn
3579               (gnus-configure-windows 'summary)
3580               (let ((art (gnus-summary-article-number)))
3581                 (unless (and (not gnus-plugged)
3582                              (or (memq art gnus-newsgroup-undownloaded)
3583                                  (memq art gnus-newsgroup-downloadable)))
3584                   (gnus-summary-goto-article art))))
3585           ;; Don't select any articles.
3586           (gnus-summary-position-point)
3587           (gnus-configure-windows 'summary 'force)
3588           (gnus-set-mode-line 'summary))
3589         (when (and gnus-auto-center-group
3590                    (get-buffer-window gnus-group-buffer t))
3591           ;; Gotta use windows, because recenter does weird stuff if
3592           ;; the current buffer ain't the displayed window.
3593           (let ((owin (selected-window)))
3594             (select-window (get-buffer-window gnus-group-buffer t))
3595             (when (gnus-group-goto-group group)
3596               (recenter))
3597             (select-window owin)))
3598         ;; Mark this buffer as "prepared".
3599         (setq gnus-newsgroup-prepared t)
3600         (gnus-run-hooks 'gnus-summary-prepared-hook)
3601         (unless (gnus-ephemeral-group-p group)
3602           (gnus-group-update-group group))
3603         t)))))
3604
3605 (defun gnus-summary-auto-select-subject ()
3606   "Select the subject line on initial group entry."
3607   (goto-char (point-min))
3608   (cond
3609    ((eq gnus-auto-select-subject 'best)
3610     (gnus-summary-best-unread-subject))
3611    ((eq gnus-auto-select-subject 'unread)
3612     (gnus-summary-first-unread-subject))
3613    ((eq gnus-auto-select-subject 'unseen)
3614     (gnus-summary-first-unseen-subject))
3615    ((eq gnus-auto-select-subject 'unseen-or-unread)
3616     (gnus-summary-first-unseen-or-unread-subject))
3617    ((eq gnus-auto-select-subject 'first)
3618     ;; Do nothing.
3619     )
3620    ((gnus-functionp gnus-auto-select-subject)
3621     (funcall gnus-auto-select-subject))))
3622
3623 (defun gnus-summary-prepare ()
3624   "Generate the summary buffer."
3625   (interactive)
3626   (let ((buffer-read-only nil))
3627     (erase-buffer)
3628     (setq gnus-newsgroup-data nil
3629           gnus-newsgroup-data-reverse nil)
3630     (gnus-run-hooks 'gnus-summary-generate-hook)
3631     ;; Generate the buffer, either with threads or without.
3632     (when gnus-newsgroup-headers
3633       (gnus-summary-prepare-threads
3634        (if gnus-show-threads
3635            (gnus-sort-gathered-threads
3636             (funcall gnus-summary-thread-gathering-function
3637                      (gnus-sort-threads
3638                       (gnus-cut-threads (gnus-make-threads)))))
3639          ;; Unthreaded display.
3640          (gnus-sort-articles gnus-newsgroup-headers))))
3641     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3642     ;; Call hooks for modifying summary buffer.
3643     (goto-char (point-min))
3644     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3645
3646 (defsubst gnus-general-simplify-subject (subject)
3647   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3648   (setq subject
3649         (cond
3650          ;; Truncate the subject.
3651          (gnus-simplify-subject-functions
3652           (gnus-map-function gnus-simplify-subject-functions subject))
3653          ((numberp gnus-summary-gather-subject-limit)
3654           (setq subject (gnus-simplify-subject-re subject))
3655           (if (> (length subject) gnus-summary-gather-subject-limit)
3656               (substring subject 0 gnus-summary-gather-subject-limit)
3657             subject))
3658          ;; Fuzzily simplify it.
3659          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3660           (gnus-simplify-subject-fuzzy subject))
3661          ;; Just remove the leading "Re:".
3662          (t
3663           (gnus-simplify-subject-re subject))))
3664
3665   (if (and gnus-summary-gather-exclude-subject
3666            (string-match gnus-summary-gather-exclude-subject subject))
3667       nil                               ; This article shouldn't be gathered
3668     subject))
3669
3670 (defun gnus-summary-simplify-subject-query ()
3671   "Query where the respool algorithm would put this article."
3672   (interactive)
3673   (gnus-summary-select-article)
3674   (message "%s"
3675            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3676
3677 (defun gnus-gather-threads-by-subject (threads)
3678   "Gather threads by looking at Subject headers."
3679   (if (not gnus-summary-make-false-root)
3680       threads
3681     (let ((hashtb (gnus-make-hashtable 1024))
3682           (prev threads)
3683           (result threads)
3684           subject hthread whole-subject)
3685       (while threads
3686         (setq subject (gnus-general-simplify-subject
3687                        (setq whole-subject (mail-header-subject
3688                                             (caar threads)))))
3689         (when subject
3690           (if (setq hthread (gnus-gethash subject hashtb))
3691               (progn
3692                 ;; We enter a dummy root into the thread, if we
3693                 ;; haven't done that already.
3694                 (unless (stringp (caar hthread))
3695                   (setcar hthread (list whole-subject (car hthread))))
3696                 ;; We add this new gathered thread to this gathered
3697                 ;; thread.
3698                 (setcdr (car hthread)
3699                         (nconc (cdar hthread) (list (car threads))))
3700                 ;; Remove it from the list of threads.
3701                 (setcdr prev (cdr threads))
3702                 (setq threads prev))
3703             ;; Enter this thread into the hash table.
3704             (gnus-sethash subject
3705                           (if gnus-summary-make-false-root-always
3706                               (progn
3707                                 ;; If you want a dummy root above all
3708                                 ;; threads...
3709                                 (setcar threads (list whole-subject
3710                                                       (car threads)))
3711                                 threads)
3712                             threads)
3713                           hashtb)))
3714         (setq prev threads)
3715         (setq threads (cdr threads)))
3716       result)))
3717
3718 (defun gnus-gather-threads-by-references (threads)
3719   "Gather threads by looking at References headers."
3720   (let ((idhashtb (gnus-make-hashtable 1024))
3721         (thhashtb (gnus-make-hashtable 1024))
3722         (prev threads)
3723         (result threads)
3724         ids references id gthread gid entered ref)
3725     (while threads
3726       (when (setq references (mail-header-references (caar threads)))
3727         (setq id (mail-header-id (caar threads))
3728               ids (inline (gnus-split-references references))
3729               entered nil)
3730         (while (setq ref (pop ids))
3731           (setq ids (delete ref ids))
3732           (if (not (setq gid (gnus-gethash ref idhashtb)))
3733               (progn
3734                 (gnus-sethash ref id idhashtb)
3735                 (gnus-sethash id threads thhashtb))
3736             (setq gthread (gnus-gethash gid thhashtb))
3737             (unless entered
3738               ;; We enter a dummy root into the thread, if we
3739               ;; haven't done that already.
3740               (unless (stringp (caar gthread))
3741                 (setcar gthread (list (mail-header-subject (caar gthread))
3742                                       (car gthread))))
3743               ;; We add this new gathered thread to this gathered
3744               ;; thread.
3745               (setcdr (car gthread)
3746                       (nconc (cdar gthread) (list (car threads)))))
3747             ;; Add it into the thread hash table.
3748             (gnus-sethash id gthread thhashtb)
3749             (setq entered t)
3750             ;; Remove it from the list of threads.
3751             (setcdr prev (cdr threads))
3752             (setq threads prev))))
3753       (setq prev threads)
3754       (setq threads (cdr threads)))
3755     result))
3756
3757 (defun gnus-sort-gathered-threads (threads)
3758   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3759   (let ((result threads))
3760     (while threads
3761       (when (stringp (caar threads))
3762         (setcdr (car threads)
3763                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3764       (setq threads (cdr threads)))
3765     result))
3766
3767 (defun gnus-thread-loop-p (root thread)
3768   "Say whether ROOT is in THREAD."
3769   (let ((stack (list thread))
3770         (infloop 0)
3771         th)
3772     (while (setq thread (pop stack))
3773       (setq th (cdr thread))
3774       (while (and th
3775                   (not (eq (caar th) root)))
3776         (pop th))
3777       (if th
3778           ;; We have found a loop.
3779           (let (ref-dep)
3780             (setcdr thread (delq (car th) (cdr thread)))
3781             (if (boundp (setq ref-dep (intern "none"
3782                                               gnus-newsgroup-dependencies)))
3783                 (setcdr (symbol-value ref-dep)
3784                         (nconc (cdr (symbol-value ref-dep))
3785                                (list (car th))))
3786               (set ref-dep (list nil (car th))))
3787             (setq infloop 1
3788                   stack nil))
3789         ;; Push all the subthreads onto the stack.
3790         (push (cdr thread) stack)))
3791     infloop))
3792
3793 (defun gnus-make-threads ()
3794   "Go through the dependency hashtb and find the roots.  Return all threads."
3795   (let (threads)
3796     (while (catch 'infloop
3797              (mapatoms
3798               (lambda (refs)
3799                 ;; Deal with self-referencing References loops.
3800                 (when (and (car (symbol-value refs))
3801                            (not (zerop
3802                                  (apply
3803                                   '+
3804                                   (mapcar
3805                                    (lambda (thread)
3806                                      (gnus-thread-loop-p
3807                                       (car (symbol-value refs)) thread))
3808                                    (cdr (symbol-value refs)))))))
3809                   (setq threads nil)
3810                   (throw 'infloop t))
3811                 (unless (car (symbol-value refs))
3812                   ;; These threads do not refer back to any other articles,
3813                   ;; so they're roots.
3814                   (setq threads (append (cdr (symbol-value refs)) threads))))
3815               gnus-newsgroup-dependencies)))
3816     threads))
3817
3818 ;; Build the thread tree.
3819 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3820   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3821
3822 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3823 if it was already present.
3824
3825 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3826 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3827 Message-IDs will be renamed to a unique Message-ID before being
3828 entered.
3829
3830 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3831   (let* ((id (mail-header-id header))
3832          (id-dep (and id (intern id dependencies)))
3833          parent-id ref ref-dep ref-header replaced)
3834     ;; Enter this `header' in the `dependencies' table.
3835     (cond
3836      ((not id-dep)
3837       (setq header nil))
3838      ;; The first two cases do the normal part: enter a new `header'
3839      ;; in the `dependencies' table.
3840      ((not (boundp id-dep))
3841       (set id-dep (list header)))
3842      ((null (car (symbol-value id-dep)))
3843       (setcar (symbol-value id-dep) header))
3844
3845      ;; From here the `header' was already present in the
3846      ;; `dependencies' table.
3847      (force-new
3848       ;; Overrides an existing entry;
3849       ;; just set the header part of the entry.
3850       (setcar (symbol-value id-dep) header)
3851       (setq replaced t))
3852
3853      ;; Renames the existing `header' to a unique Message-ID.
3854      ((not gnus-summary-ignore-duplicates)
3855       ;; An article with this Message-ID has already been seen.
3856       ;; We rename the Message-ID.
3857       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3858            (list header))
3859       (mail-header-set-id header id))
3860
3861      ;; The last case ignores an existing entry, except it adds any
3862      ;; additional Xrefs (in case the two articles came from different
3863      ;; servers.
3864      ;; Also sets `header' to `nil' meaning that the `dependencies'
3865      ;; table was *not* modified.
3866      (t
3867       (mail-header-set-xref
3868        (car (symbol-value id-dep))
3869        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3870                    "")
3871                (or (mail-header-xref header) "")))
3872       (setq header nil)))
3873
3874     (when (and header (not replaced))
3875       ;; First check that we are not creating a References loop.
3876       (setq parent-id (gnus-parent-id (mail-header-references header)))
3877       (setq ref parent-id)
3878       (while (and ref
3879                   (setq ref-dep (intern-soft ref dependencies))
3880                   (boundp ref-dep)
3881                   (setq ref-header (car (symbol-value ref-dep))))
3882         (if (string= id ref)
3883             ;; Yuk!  This is a reference loop.  Make the article be a
3884             ;; root article.
3885             (progn
3886               (mail-header-set-references (car (symbol-value id-dep)) "none")
3887               (setq ref nil)
3888               (setq parent-id nil))
3889           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3890       (setq ref-dep (intern (or parent-id "none") dependencies))
3891       (if (boundp ref-dep)
3892           (setcdr (symbol-value ref-dep)
3893                   (nconc (cdr (symbol-value ref-dep))
3894                          (list (symbol-value id-dep))))
3895         (set ref-dep (list nil (symbol-value id-dep)))))
3896     header))
3897
3898 (defun gnus-extract-message-id-from-in-reply-to (string)
3899   (if (string-match "<[^>]+>" string)
3900       (substring string (match-beginning 0) (match-end 0))
3901     nil))
3902
3903 (defun gnus-build-sparse-threads ()
3904   (let ((headers gnus-newsgroup-headers)
3905         (mail-parse-charset gnus-newsgroup-charset)
3906         (gnus-summary-ignore-duplicates t)
3907         header references generation relations
3908         subject child end new-child date)
3909     ;; First we create an alist of generations/relations, where
3910     ;; generations is how much we trust the relation, and the relation
3911     ;; is parent/child.
3912     (gnus-message 7 "Making sparse threads...")
3913     (save-excursion
3914       (nnheader-set-temp-buffer " *gnus sparse threads*")
3915       (while (setq header (pop headers))
3916         (when (and (setq references (mail-header-references header))
3917                    (not (string= references "")))
3918           (insert references)
3919           (setq child (mail-header-id header)
3920                 subject (mail-header-subject header)
3921                 date (mail-header-date header)
3922                 generation 0)
3923           (while (search-backward ">" nil t)
3924             (setq end (1+ (point)))
3925             (when (search-backward "<" nil t)
3926               (setq new-child (buffer-substring (point) end))
3927               (push (list (incf generation)
3928                           child (setq child new-child)
3929                           subject date)
3930                     relations)))
3931           (when child
3932             (push (list (1+ generation) child nil subject) relations))
3933           (erase-buffer)))
3934       (kill-buffer (current-buffer)))
3935     ;; Sort over trustworthiness.
3936     (mapcar
3937      (lambda (relation)
3938        (when (gnus-dependencies-add-header
3939               (make-full-mail-header-from-decoded-header
3940                gnus-reffed-article-number
3941                (nth 3 relation) "" (or (nth 4 relation) "")
3942                (nth 1 relation)
3943                (or (nth 2 relation) "") 0 0 "")
3944               gnus-newsgroup-dependencies nil)
3945          (push gnus-reffed-article-number gnus-newsgroup-limit)
3946          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3947          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3948                gnus-newsgroup-reads)
3949          (decf gnus-reffed-article-number)))
3950      (sort relations 'car-less-than-car))
3951     (gnus-message 7 "Making sparse threads...done")))
3952
3953 (defun gnus-build-old-threads ()
3954   ;; Look at all the articles that refer back to old articles, and
3955   ;; fetch the headers for the articles that aren't there.  This will
3956   ;; build complete threads - if the roots haven't been expired by the
3957   ;; server, that is.
3958   (let ((mail-parse-charset gnus-newsgroup-charset)
3959         id heads)
3960     (mapatoms
3961      (lambda (refs)
3962        (when (not (car (symbol-value refs)))
3963          (setq heads (cdr (symbol-value refs)))
3964          (while heads
3965            (if (memq (mail-header-number (caar heads))
3966                      gnus-newsgroup-dormant)
3967                (setq heads (cdr heads))
3968              (setq id (symbol-name refs))
3969              (while (and (setq id (gnus-build-get-header id))
3970                          (not (car (gnus-id-to-thread id)))))
3971              (setq heads nil)))))
3972      gnus-newsgroup-dependencies)))
3973
3974 ;; This function has to be called with point after the article number
3975 ;; on the beginning of the line.
3976 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3977   (let ((eol (gnus-point-at-eol))
3978         (buffer (current-buffer))
3979         header references in-reply-to)
3980
3981     ;; overview: [num subject from date id refs chars lines misc]
3982     (unwind-protect
3983         (progn
3984           (narrow-to-region (point) eol)
3985           (unless (eobp)
3986             (forward-char))
3987
3988           (setq header
3989                 (make-full-mail-header
3990                  number                         ; number
3991                  (nnheader-nov-field)           ; subject
3992                  (nnheader-nov-field)           ; from
3993                  (nnheader-nov-field)           ; date
3994                  (nnheader-nov-read-message-id) ; id
3995                  (nnheader-nov-field)           ; refs
3996                  (nnheader-nov-read-integer)    ; chars
3997                  (nnheader-nov-read-integer)    ; lines
3998                  (unless (eobp)
3999                    (if (looking-at "Xref: ")
4000                        (goto-char (match-end 0)))
4001                    (nnheader-nov-field))        ; Xref
4002                  (nnheader-nov-parse-extra))))  ; extra
4003
4004       (widen))
4005
4006     (when (and (string= references "")
4007                (setq in-reply-to (mail-header-extra header))
4008                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4009       (mail-header-set-references
4010        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4011
4012     (when gnus-alter-header-function
4013       (funcall gnus-alter-header-function header))
4014     (gnus-dependencies-add-header header dependencies force-new)))
4015
4016 (defun gnus-build-get-header (id)
4017   "Look through the buffer of NOV lines and find the header to ID.
4018 Enter this line into the dependencies hash table, and return
4019 the id of the parent article (if any)."
4020   (let ((deps gnus-newsgroup-dependencies)
4021         found header)
4022     (prog1
4023         (save-excursion
4024           (set-buffer nntp-server-buffer)
4025           (let ((case-fold-search nil))
4026             (goto-char (point-min))
4027             (while (and (not found)
4028                         (search-forward id nil t))
4029               (beginning-of-line)
4030               (setq found (looking-at
4031                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4032                                    (regexp-quote id))))
4033               (or found (beginning-of-line 2)))
4034             (when found
4035               (beginning-of-line)
4036               (and
4037                (setq header (gnus-nov-parse-line
4038                              (read (current-buffer)) deps))
4039                (gnus-parent-id (mail-header-references header))))))
4040       (when header
4041         (let ((number (mail-header-number header)))
4042           (push number gnus-newsgroup-limit)
4043           (push header gnus-newsgroup-headers)
4044           (if (memq number gnus-newsgroup-unselected)
4045               (progn
4046                 (setq gnus-newsgroup-unreads
4047                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4048                                                number))
4049                 (setq gnus-newsgroup-unselected
4050                       (delq number gnus-newsgroup-unselected)))
4051             (push number gnus-newsgroup-ancient)))))))
4052
4053 (defun gnus-build-all-threads ()
4054   "Read all the headers."
4055   (let ((gnus-summary-ignore-duplicates t)
4056         (mail-parse-charset gnus-newsgroup-charset)
4057         (dependencies gnus-newsgroup-dependencies)
4058         header article)
4059     (save-excursion
4060       (set-buffer nntp-server-buffer)
4061       (let ((case-fold-search nil))
4062         (goto-char (point-min))
4063         (while (not (eobp))
4064           (ignore-errors
4065             (setq article (read (current-buffer))
4066                   header (gnus-nov-parse-line article dependencies)))
4067           (when header
4068             (save-excursion
4069               (set-buffer gnus-summary-buffer)
4070               (push header gnus-newsgroup-headers)
4071               (if (memq (setq article (mail-header-number header))
4072                         gnus-newsgroup-unselected)
4073                   (progn
4074                     (setq gnus-newsgroup-unreads
4075                           (gnus-add-to-sorted-list
4076                            gnus-newsgroup-unreads article))
4077                     (setq gnus-newsgroup-unselected
4078                           (delq article gnus-newsgroup-unselected)))
4079                 (push article gnus-newsgroup-ancient)))
4080             (forward-line 1)))))))
4081
4082 (defun gnus-summary-update-article-line (article header)
4083   "Update the line for ARTICLE using HEADERS."
4084   (let* ((id (mail-header-id header))
4085          (thread (gnus-id-to-thread id)))
4086     (unless thread
4087       (error "Article in no thread"))
4088     ;; Update the thread.
4089     (setcar thread header)
4090     (gnus-summary-goto-subject article)
4091     (let* ((datal (gnus-data-find-list article))
4092            (data (car datal))
4093            (buffer-read-only nil)
4094            (level (gnus-summary-thread-level)))
4095       (gnus-delete-line)
4096       (let ((inserted (- (point)
4097                          (progn
4098                            (gnus-summary-insert-line
4099                             header level nil 
4100                             (memq article gnus-newsgroup-undownloaded)
4101                             (gnus-article-mark article)
4102                             (memq article gnus-newsgroup-replied)
4103                             (memq article gnus-newsgroup-expirable)
4104                             ;; Only insert the Subject string when it's different
4105                             ;; from the previous Subject string.
4106                             (if (and
4107                                  gnus-show-threads
4108                                  (gnus-subject-equal
4109                                   (condition-case ()
4110                                       (mail-header-subject
4111                                        (gnus-data-header
4112                                         (cadr
4113                                          (gnus-data-find-list
4114                                           article
4115                                           (gnus-data-list t)))))
4116                                     ;; Error on the side of excessive subjects.
4117                                     (error ""))
4118                                   (mail-header-subject header)))
4119                                 ""
4120                               (mail-header-subject header))
4121                             nil (cdr (assq article gnus-newsgroup-scored))
4122                             (memq article gnus-newsgroup-processable))
4123                            (point)))))
4124         (when (cdr datal)
4125           (gnus-data-update-list
4126            (cdr datal) 
4127            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4128
4129 (defun gnus-summary-update-article (article &optional iheader)
4130   "Update ARTICLE in the summary buffer."
4131   (set-buffer gnus-summary-buffer)
4132   (let* ((header (gnus-summary-article-header article))
4133          (id (mail-header-id header))
4134          (data (gnus-data-find article))
4135          (thread (gnus-id-to-thread id))
4136          (references (mail-header-references header))
4137          (parent
4138           (gnus-id-to-thread
4139            (or (gnus-parent-id
4140                 (when (and references
4141                            (not (equal "" references)))
4142                   references))
4143                "none")))
4144          (buffer-read-only nil)
4145          (old (car thread)))
4146     (when thread
4147       (unless iheader
4148         (setcar thread nil)
4149         (when parent
4150           (delq thread parent)))
4151       (if (gnus-summary-insert-subject id header)
4152           ;; Set the (possibly) new article number in the data structure.
4153           (gnus-data-set-number data (gnus-id-to-article id))
4154         (setcar thread old)
4155         nil))))
4156
4157 (defun gnus-rebuild-thread (id &optional line)
4158   "Rebuild the thread containing ID.
4159 If LINE, insert the rebuilt thread starting on line LINE."
4160   (let ((buffer-read-only nil)
4161         old-pos current thread data)
4162     (if (not gnus-show-threads)
4163         (setq thread (list (car (gnus-id-to-thread id))))
4164       ;; Get the thread this article is part of.
4165       (setq thread (gnus-remove-thread id)))
4166     (setq old-pos (gnus-point-at-bol))
4167     (setq current (save-excursion
4168                     (and (re-search-backward "[\r\n]" nil t)
4169                          (gnus-summary-article-number))))
4170     ;; If this is a gathered thread, we have to go some re-gathering.
4171     (when (stringp (car thread))
4172       (let ((subject (car thread))
4173             roots thr)
4174         (setq thread (cdr thread))
4175         (while thread
4176           (unless (memq (setq thr (gnus-id-to-thread
4177                                    (gnus-root-id
4178                                     (mail-header-id (caar thread)))))
4179                         roots)
4180             (push thr roots))
4181           (setq thread (cdr thread)))
4182         ;; We now have all (unique) roots.
4183         (if (= (length roots) 1)
4184             ;; All the loose roots are now one solid root.
4185             (setq thread (car roots))
4186           (setq thread (cons subject (gnus-sort-threads roots))))))
4187     (let (threads)
4188       ;; We then insert this thread into the summary buffer.
4189       (when line
4190         (goto-char (point-min))
4191         (forward-line (1- line)))
4192       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4193         (if gnus-show-threads
4194             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4195           (gnus-summary-prepare-unthreaded thread))
4196         (setq data (nreverse gnus-newsgroup-data))
4197         (setq threads gnus-newsgroup-threads))
4198       ;; We splice the new data into the data structure.
4199       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4200       ;;!!! then we want to insert at the beginning of the buffer.
4201       ;;!!! That happens to be true with Gnus now, but that may
4202       ;;!!! change in the future.  Perhaps.
4203       (gnus-data-enter-list
4204        (if line nil current) data (- (point) old-pos))
4205       (setq gnus-newsgroup-threads
4206             (nconc threads gnus-newsgroup-threads))
4207       (gnus-data-compute-positions))))
4208
4209 (defun gnus-number-to-header (number)
4210   "Return the header for article NUMBER."
4211   (let ((headers gnus-newsgroup-headers))
4212     (while (and headers
4213                 (not (= number (mail-header-number (car headers)))))
4214       (pop headers))
4215     (when headers
4216       (car headers))))
4217
4218 (defun gnus-parent-headers (in-headers &optional generation)
4219   "Return the headers of the GENERATIONeth parent of HEADERS."
4220   (unless generation
4221     (setq generation 1))
4222   (let ((parent t)
4223         (headers in-headers)
4224         references)
4225     (while (and parent
4226                 (not (zerop generation))
4227                 (setq references (mail-header-references headers)))
4228       (setq headers (if (and references
4229                              (setq parent (gnus-parent-id references)))
4230                         (car (gnus-id-to-thread parent))
4231                       nil))
4232       (decf generation))
4233     (and (not (eq headers in-headers))
4234          headers)))
4235
4236 (defun gnus-id-to-thread (id)
4237   "Return the (sub-)thread where ID appears."
4238   (gnus-gethash id gnus-newsgroup-dependencies))
4239
4240 (defun gnus-id-to-article (id)
4241   "Return the article number of ID."
4242   (let ((thread (gnus-id-to-thread id)))
4243     (when (and thread
4244                (car thread))
4245       (mail-header-number (car thread)))))
4246
4247 (defun gnus-id-to-header (id)
4248   "Return the article headers of ID."
4249   (car (gnus-id-to-thread id)))
4250
4251 (defun gnus-article-displayed-root-p (article)
4252   "Say whether ARTICLE is a root(ish) article."
4253   (let ((level (gnus-summary-thread-level article))
4254         (refs (mail-header-references  (gnus-summary-article-header article)))
4255         particle)
4256     (cond
4257      ((null level) nil)
4258      ((zerop level) t)
4259      ((null refs) t)
4260      ((null (gnus-parent-id refs)) t)
4261      ((and (= 1 level)
4262            (null (setq particle (gnus-id-to-article
4263                                  (gnus-parent-id refs))))
4264            (null (gnus-summary-thread-level particle)))))))
4265
4266 (defun gnus-root-id (id)
4267   "Return the id of the root of the thread where ID appears."
4268   (let (last-id prev)
4269     (while (and id (setq prev (car (gnus-id-to-thread id))))
4270       (setq last-id id
4271             id (gnus-parent-id (mail-header-references prev))))
4272     last-id))
4273
4274 (defun gnus-articles-in-thread (thread)
4275   "Return the list of articles in THREAD."
4276   (cons (mail-header-number (car thread))
4277         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4278
4279 (defun gnus-remove-thread (id &optional dont-remove)
4280   "Remove the thread that has ID in it."
4281   (let (headers thread last-id)
4282     ;; First go up in this thread until we find the root.
4283     (setq last-id (gnus-root-id id)
4284           headers (message-flatten-list (gnus-id-to-thread last-id)))
4285     ;; We have now found the real root of this thread.  It might have
4286     ;; been gathered into some loose thread, so we have to search
4287     ;; through the threads to find the thread we wanted.
4288     (let ((threads gnus-newsgroup-threads)
4289           sub)
4290       (while threads
4291         (setq sub (car threads))
4292         (if (stringp (car sub))
4293             ;; This is a gathered thread, so we look at the roots
4294             ;; below it to find whether this article is in this
4295             ;; gathered root.
4296             (progn
4297               (setq sub (cdr sub))
4298               (while sub
4299                 (when (member (caar sub) headers)
4300                   (setq thread (car threads)
4301                         threads nil
4302                         sub nil))
4303                 (setq sub (cdr sub))))
4304           ;; It's an ordinary thread, so we check it.
4305           (when (eq (car sub) (car headers))
4306             (setq thread sub
4307                   threads nil)))
4308         (setq threads (cdr threads)))
4309       ;; If this article is in no thread, then it's a root.
4310       (if thread
4311           (unless dont-remove
4312             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4313         (setq thread (gnus-id-to-thread last-id)))
4314       (when thread
4315         (prog1
4316             thread                      ; We return this thread.
4317           (unless dont-remove
4318             (if (stringp (car thread))
4319                 (progn
4320                   ;; If we use dummy roots, then we have to remove the
4321                   ;; dummy root as well.
4322                   (when (eq gnus-summary-make-false-root 'dummy)
4323                     ;; We go to the dummy root by going to
4324                     ;; the first sub-"thread", and then one line up.
4325                     (gnus-summary-goto-article
4326                      (mail-header-number (caadr thread)))
4327                     (forward-line -1)
4328                     (gnus-delete-line)
4329                     (gnus-data-compute-positions))
4330                   (setq thread (cdr thread))
4331                   (while thread
4332                     (gnus-remove-thread-1 (car thread))
4333                     (setq thread (cdr thread))))
4334               (gnus-remove-thread-1 thread))))))))
4335
4336 (defun gnus-remove-thread-1 (thread)
4337   "Remove the thread THREAD recursively."
4338   (let ((number (mail-header-number (pop thread)))
4339         d)
4340     (setq thread (reverse thread))
4341     (while thread
4342       (gnus-remove-thread-1 (pop thread)))
4343     (when (setq d (gnus-data-find number))
4344       (goto-char (gnus-data-pos d))
4345       (gnus-summary-show-thread)
4346       (gnus-data-remove
4347        number
4348        (- (gnus-point-at-bol)
4349           (prog1
4350               (1+ (gnus-point-at-eol))
4351             (gnus-delete-line)))))))
4352
4353 (defun gnus-sort-threads-1 (threads func)
4354   (sort (mapcar (lambda (thread)
4355                   (cons (car thread)
4356                         (and (cdr thread)
4357                              (gnus-sort-threads-1 (cdr thread) func))))
4358                 threads) func))
4359
4360 (defun gnus-sort-threads (threads)
4361   "Sort THREADS."
4362   (if (not gnus-thread-sort-functions)
4363       threads
4364     (gnus-message 8 "Sorting threads...")
4365     (let ((max-lisp-eval-depth 5000))
4366       (prog1 (gnus-sort-threads-1
4367          threads
4368          (gnus-make-sort-function gnus-thread-sort-functions))
4369         (gnus-message 8 "Sorting threads...done")))))
4370
4371 (defun gnus-sort-articles (articles)
4372   "Sort ARTICLES."
4373   (when gnus-article-sort-functions
4374     (gnus-message 7 "Sorting articles...")
4375     (prog1
4376         (setq gnus-newsgroup-headers
4377               (sort articles (gnus-make-sort-function
4378                               gnus-article-sort-functions)))
4379       (gnus-message 7 "Sorting articles...done"))))
4380
4381 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4382 (defmacro gnus-thread-header (thread)
4383   "Return header of first article in THREAD.
4384 Note that THREAD must never, ever be anything else than a variable -
4385 using some other form will lead to serious barfage."
4386   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4387   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4388   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4389         (vector thread) 2))
4390
4391 (defsubst gnus-article-sort-by-number (h1 h2)
4392   "Sort articles by article number."
4393   (< (mail-header-number h1)
4394      (mail-header-number h2)))
4395
4396 (defun gnus-thread-sort-by-number (h1 h2)
4397   "Sort threads by root article number."
4398   (gnus-article-sort-by-number
4399    (gnus-thread-header h1) (gnus-thread-header h2)))
4400
4401 (defsubst gnus-article-sort-by-random (h1 h2)
4402   "Sort articles by article number."
4403   (zerop (random 2)))
4404
4405 (defun gnus-thread-sort-by-random (h1 h2)
4406   "Sort threads by root article number."
4407   (gnus-article-sort-by-random
4408    (gnus-thread-header h1) (gnus-thread-header h2)))
4409
4410 (defsubst gnus-article-sort-by-lines (h1 h2)
4411   "Sort articles by article Lines header."
4412   (< (mail-header-lines h1)
4413      (mail-header-lines h2)))
4414
4415 (defun gnus-thread-sort-by-lines (h1 h2)
4416   "Sort threads by root article Lines header."
4417   (gnus-article-sort-by-lines
4418    (gnus-thread-header h1) (gnus-thread-header h2)))
4419
4420 (defsubst gnus-article-sort-by-chars (h1 h2)
4421   "Sort articles by octet length."
4422   (< (mail-header-chars h1)
4423      (mail-header-chars h2)))
4424
4425 (defun gnus-thread-sort-by-chars (h1 h2)
4426   "Sort threads by root article octet length."
4427   (gnus-article-sort-by-chars
4428    (gnus-thread-header h1) (gnus-thread-header h2)))
4429
4430 (defsubst gnus-article-sort-by-author (h1 h2)
4431   "Sort articles by root author."
4432   (string-lessp
4433    (let ((addr (car (mime-entity-read-field h1 'From))))
4434      (or (std11-full-name-string addr)
4435          (std11-address-string addr)
4436          ""))
4437    (let ((addr (car (mime-entity-read-field h2 'From))))
4438      (or (std11-full-name-string addr)
4439          (std11-address-string addr)
4440          ""))
4441    ))
4442
4443 (defun gnus-thread-sort-by-author (h1 h2)
4444   "Sort threads by root author."
4445   (gnus-article-sort-by-author
4446    (gnus-thread-header h1)  (gnus-thread-header h2)))
4447
4448 (defsubst gnus-article-sort-by-subject (h1 h2)
4449   "Sort articles by root subject."
4450   (string-lessp
4451    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4452    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4453
4454 (defun gnus-thread-sort-by-subject (h1 h2)
4455   "Sort threads by root subject."
4456   (gnus-article-sort-by-subject
4457    (gnus-thread-header h1) (gnus-thread-header h2)))
4458
4459 (defsubst gnus-article-sort-by-date (h1 h2)
4460   "Sort articles by root article date."
4461   (time-less-p
4462    (gnus-date-get-time (mail-header-date h1))
4463    (gnus-date-get-time (mail-header-date h2))))
4464
4465 (defun gnus-thread-sort-by-date (h1 h2)
4466   "Sort threads by root article date."
4467   (gnus-article-sort-by-date
4468    (gnus-thread-header h1) (gnus-thread-header h2)))
4469
4470 (defsubst gnus-article-sort-by-score (h1 h2)
4471   "Sort articles by root article score.
4472 Unscored articles will be counted as having a score of zero."
4473   (> (or (cdr (assq (mail-header-number h1)
4474                     gnus-newsgroup-scored))
4475          gnus-summary-default-score 0)
4476      (or (cdr (assq (mail-header-number h2)
4477                     gnus-newsgroup-scored))
4478          gnus-summary-default-score 0)))
4479
4480 (defun gnus-thread-sort-by-score (h1 h2)
4481   "Sort threads by root article score."
4482   (gnus-article-sort-by-score
4483    (gnus-thread-header h1) (gnus-thread-header h2)))
4484
4485 (defun gnus-thread-sort-by-total-score (h1 h2)
4486   "Sort threads by the sum of all scores in the thread.
4487 Unscored articles will be counted as having a score of zero."
4488   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4489
4490 (defun gnus-thread-total-score (thread)
4491   ;; This function find the total score of THREAD.
4492   (cond
4493    ((null thread)
4494     0)
4495    ((consp thread)
4496     (if (stringp (car thread))
4497         (apply gnus-thread-score-function 0
4498                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4499       (gnus-thread-total-score-1 thread)))
4500    (t
4501     (gnus-thread-total-score-1 (list thread)))))
4502
4503 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4504   "Sort threads such that the thread with the most recently arrived article comes first."
4505   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4506
4507 (defun gnus-thread-highest-number (thread)
4508   "Return the highest article number in THREAD."
4509   (apply 'max (mapcar (lambda (header)
4510                         (mail-header-number header))
4511                       (message-flatten-list thread))))
4512
4513 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4514   "Sort threads such that the thread with the most recently dated article comes first."
4515   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4516
4517 (defun gnus-thread-latest-date (thread)
4518   "Return the highest article date in THREAD."
4519   (let ((previous-time 0))
4520     (apply 'max
4521            (mapcar
4522             (lambda (header)
4523               (setq previous-time
4524                     (time-to-seconds
4525                      (condition-case ()
4526                          (mail-header-parse-date (mail-header-date header))
4527                        (error previous-time)))))
4528             (sort
4529              (message-flatten-list thread)
4530              (lambda (h1 h2)
4531                (< (mail-header-number h1)
4532                   (mail-header-number h2))))))))
4533
4534 (defun gnus-thread-total-score-1 (root)
4535   ;; This function find the total score of the thread below ROOT.
4536   (setq root (car root))
4537   (apply gnus-thread-score-function
4538          (or (append
4539               (mapcar 'gnus-thread-total-score
4540                       (cdr (gnus-id-to-thread (mail-header-id root))))
4541               (when (> (mail-header-number root) 0)
4542                 (list (or (cdr (assq (mail-header-number root)
4543                                      gnus-newsgroup-scored))
4544                           gnus-summary-default-score 0))))
4545              (list gnus-summary-default-score)
4546              '(0))))
4547
4548 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4549 (defvar gnus-tmp-prev-subject nil)
4550 (defvar gnus-tmp-false-parent nil)
4551 (defvar gnus-tmp-root-expunged nil)
4552 (defvar gnus-tmp-dummy-line nil)
4553
4554 (eval-when-compile (defvar gnus-tmp-header))
4555 (defun gnus-extra-header (type &optional header)
4556   "Return the extra header of TYPE."
4557   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4558       ""))
4559
4560 (defvar gnus-tmp-thread-tree-header-string "")
4561
4562 (defcustom gnus-sum-thread-tree-root "> "
4563   "With %B spec, used for the root of a thread.
4564 If nil, use subject instead."
4565   :type 'string
4566   :group 'gnus-thread)
4567 (defcustom gnus-sum-thread-tree-single-indent ""
4568   "With %B spec, used for a thread with just one message.
4569 If nil, use subject instead."
4570   :type 'string
4571   :group 'gnus-thread)
4572 (defcustom gnus-sum-thread-tree-vertical "| "
4573   "With %B spec, used for drawing a vertical line."
4574   :type 'string
4575   :group 'gnus-thread)
4576 (defcustom gnus-sum-thread-tree-indent "  "
4577   "With %B spec, used for indenting."
4578   :type 'string
4579   :group 'gnus-thread)
4580 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4581   "With %B spec, used for a leaf with brothers."
4582   :type 'string
4583   :group 'gnus-thread)
4584 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4585   "With %B spec, used for a leaf without brothers."
4586   :type 'string
4587   :group 'gnus-thread)
4588
4589 (defun gnus-summary-prepare-threads (threads)
4590   "Prepare summary buffer from THREADS and indentation LEVEL.
4591 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4592 or a straight list of headers."
4593   (gnus-message 7 "Generating summary...")
4594
4595   (setq gnus-newsgroup-threads threads)
4596   (beginning-of-line)
4597
4598   (let ((gnus-tmp-level 0)
4599         (default-score (or gnus-summary-default-score 0))
4600         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4601         (building-line-count gnus-summary-display-while-building)
4602         (building-count (integerp gnus-summary-display-while-building))
4603         thread number subject stack state gnus-tmp-gathered beg-match
4604         new-roots gnus-tmp-new-adopts thread-end simp-subject
4605         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4606         gnus-tmp-replied gnus-tmp-subject-or-nil
4607         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4608         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4609         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4610         tree-stack)
4611
4612     (setq gnus-tmp-prev-subject nil
4613           gnus-tmp-thread-tree-header-string "")
4614
4615     (if (vectorp (car threads))
4616         ;; If this is a straight (sic) list of headers, then a
4617         ;; threaded summary display isn't required, so we just create
4618         ;; an unthreaded one.
4619         (gnus-summary-prepare-unthreaded threads)
4620
4621       ;; Do the threaded display.
4622
4623       (if gnus-summary-display-while-building
4624           (switch-to-buffer (buffer-name)))
4625       (while (or threads stack gnus-tmp-new-adopts new-roots)
4626
4627         (if (and (= gnus-tmp-level 0)
4628                  (or (not stack)
4629                      (= (caar stack) 0))
4630                  (not gnus-tmp-false-parent)
4631                  (or gnus-tmp-new-adopts new-roots))
4632             (if gnus-tmp-new-adopts
4633                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4634                       thread (list (car gnus-tmp-new-adopts))
4635                       gnus-tmp-header (caar thread)
4636                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4637               (when new-roots
4638                 (setq thread (list (car new-roots))
4639                       gnus-tmp-header (caar thread)
4640                       new-roots (cdr new-roots))))
4641
4642           (if threads
4643               ;; If there are some threads, we do them before the
4644               ;; threads on the stack.
4645               (setq thread threads
4646                     gnus-tmp-header (caar thread))
4647             ;; There were no current threads, so we pop something off
4648             ;; the stack.
4649             (setq state (car stack)
4650                   gnus-tmp-level (car state)
4651                   tree-stack (cadr state)
4652                   thread (caddr state)
4653                   stack (cdr stack)
4654                   gnus-tmp-header (caar thread))))
4655
4656         (setq gnus-tmp-false-parent nil)
4657         (setq gnus-tmp-root-expunged nil)
4658         (setq thread-end nil)
4659
4660         (if (stringp gnus-tmp-header)
4661             ;; The header is a dummy root.
4662             (cond
4663              ((eq gnus-summary-make-false-root 'adopt)
4664               ;; We let the first article adopt the rest.
4665               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4666                                                (cddar thread)))
4667               (setq gnus-tmp-gathered
4668                     (nconc (mapcar
4669                             (lambda (h) (mail-header-number (car h)))
4670                             (cddar thread))
4671                            gnus-tmp-gathered))
4672               (setq thread (cons (list (caar thread)
4673                                        (cadar thread))
4674                                  (cdr thread)))
4675               (setq gnus-tmp-level -1
4676                     gnus-tmp-false-parent t))
4677              ((eq gnus-summary-make-false-root 'empty)
4678               ;; We print adopted articles with empty subject fields.
4679               (setq gnus-tmp-gathered
4680                     (nconc (mapcar
4681                             (lambda (h) (mail-header-number (car h)))
4682                             (cddar thread))
4683                            gnus-tmp-gathered))
4684               (setq gnus-tmp-level -1))
4685              ((eq gnus-summary-make-false-root 'dummy)
4686               ;; We remember that we probably want to output a dummy
4687               ;; root.
4688               (setq gnus-tmp-dummy-line gnus-tmp-header)
4689               (setq gnus-tmp-prev-subject gnus-tmp-header))
4690              (t
4691               ;; We do not make a root for the gathered
4692               ;; sub-threads at all.
4693               (setq gnus-tmp-level -1)))
4694
4695           (setq number (mail-header-number gnus-tmp-header)
4696                 subject (mail-header-subject gnus-tmp-header)
4697                 simp-subject (gnus-simplify-subject-fully subject))
4698
4699           (cond
4700            ;; If the thread has changed subject, we might want to make
4701            ;; this subthread into a root.
4702            ((and (null gnus-thread-ignore-subject)
4703                  (not (zerop gnus-tmp-level))
4704                  gnus-tmp-prev-subject
4705                  (not (string= gnus-tmp-prev-subject simp-subject)))
4706             (setq new-roots (nconc new-roots (list (car thread)))
4707                   thread-end t
4708                   gnus-tmp-header nil))
4709            ;; If the article lies outside the current limit,
4710            ;; then we do not display it.
4711            ((not (memq number gnus-newsgroup-limit))
4712             (setq gnus-tmp-gathered
4713                   (nconc (mapcar
4714                           (lambda (h) (mail-header-number (car h)))
4715                           (cdar thread))
4716                          gnus-tmp-gathered))
4717             (setq gnus-tmp-new-adopts (if (cdar thread)
4718                                           (append gnus-tmp-new-adopts
4719                                                   (cdar thread))
4720                                         gnus-tmp-new-adopts)
4721                   thread-end t
4722                   gnus-tmp-header nil)
4723             (when (zerop gnus-tmp-level)
4724               (setq gnus-tmp-root-expunged t)))
4725            ;; Perhaps this article is to be marked as read?
4726            ((and gnus-summary-mark-below
4727                  (< (or (cdr (assq number gnus-newsgroup-scored))
4728                         default-score)
4729                     gnus-summary-mark-below)
4730                  ;; Don't touch sparse articles.
4731                  (not (gnus-summary-article-sparse-p number))
4732                  (not (gnus-summary-article-ancient-p number)))
4733             (setq gnus-newsgroup-unreads
4734                   (delq number gnus-newsgroup-unreads))
4735             (if gnus-newsgroup-auto-expire
4736                 (setq gnus-newsgroup-expirable
4737                       (gnus-add-to-sorted-list
4738                        gnus-newsgroup-expirable number))
4739               (push (cons number gnus-low-score-mark)
4740                     gnus-newsgroup-reads))))
4741
4742           (when gnus-tmp-header
4743             ;; We may have an old dummy line to output before this
4744             ;; article.
4745             (when (and gnus-tmp-dummy-line
4746                        (gnus-subject-equal
4747                         gnus-tmp-dummy-line
4748                         (mail-header-subject gnus-tmp-header)))
4749               (gnus-summary-insert-dummy-line
4750                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4751               (setq gnus-tmp-dummy-line nil))
4752
4753             ;; Compute the mark.
4754             (setq gnus-tmp-unread (gnus-article-mark number))
4755
4756             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4757                                   gnus-tmp-header gnus-tmp-level)
4758                   gnus-newsgroup-data)
4759
4760             ;; Actually insert the line.
4761             (setq
4762              gnus-tmp-subject-or-nil
4763              (cond
4764               ((and gnus-thread-ignore-subject
4765                     gnus-tmp-prev-subject
4766                     (not (string= gnus-tmp-prev-subject simp-subject)))
4767                subject)
4768               ((zerop gnus-tmp-level)
4769                (if (and (eq gnus-summary-make-false-root 'empty)
4770                         (memq number gnus-tmp-gathered)
4771                         gnus-tmp-prev-subject
4772                         (string= gnus-tmp-prev-subject simp-subject))
4773                    gnus-summary-same-subject
4774                  subject))
4775               (t gnus-summary-same-subject)))
4776             (if (and (eq gnus-summary-make-false-root 'adopt)
4777                      (= gnus-tmp-level 1)
4778                      (memq number gnus-tmp-gathered))
4779                 (setq gnus-tmp-opening-bracket ?\<
4780                       gnus-tmp-closing-bracket ?\>)
4781               (setq gnus-tmp-opening-bracket ?\[
4782                     gnus-tmp-closing-bracket ?\]))
4783             (setq
4784              gnus-tmp-indentation
4785              (aref gnus-thread-indent-array gnus-tmp-level)
4786              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4787              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4788                                 gnus-summary-default-score 0)
4789              gnus-tmp-score-char
4790              (if (or (null gnus-summary-default-score)
4791                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4792                          gnus-summary-zcore-fuzz))
4793                  ?\ ;;;Whitespace
4794                (if (< gnus-tmp-score gnus-summary-default-score)
4795                    gnus-score-below-mark gnus-score-over-mark))
4796              gnus-tmp-replied
4797              (cond ((memq number gnus-newsgroup-processable)
4798                     gnus-process-mark)
4799                    ((memq number gnus-newsgroup-cached)
4800                     gnus-cached-mark)
4801                    ((memq number gnus-newsgroup-replied)
4802                     gnus-replied-mark)
4803                    ((memq number gnus-newsgroup-forwarded)
4804                     gnus-forwarded-mark)
4805                    ((memq number gnus-newsgroup-saved)
4806                     gnus-saved-mark)
4807                    ((memq number gnus-newsgroup-recent)
4808                     gnus-recent-mark)
4809                    ((memq number gnus-newsgroup-unseen)
4810                     gnus-unseen-mark)
4811                    (t gnus-no-mark))
4812              gnus-tmp-downloaded
4813              (cond ((memq number gnus-newsgroup-undownloaded) 
4814                     gnus-undownloaded-mark)
4815                    (gnus-newsgroup-agentized
4816                     gnus-downloaded-mark)
4817                    (t
4818                     gnus-no-mark))
4819              gnus-tmp-from (mail-header-from gnus-tmp-header)
4820              gnus-tmp-name
4821              (cond
4822               ((string-match "<[^>]+> *$" gnus-tmp-from)
4823                (setq beg-match (match-beginning 0))
4824                (or (and (string-match "^\".+\"" gnus-tmp-from)
4825                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4826                    (substring gnus-tmp-from 0 beg-match)))
4827               ((string-match "(.+)" gnus-tmp-from)
4828                (substring gnus-tmp-from
4829                           (1+ (match-beginning 0)) (1- (match-end 0))))
4830               (t gnus-tmp-from))
4831
4832              ;; Do the %B string
4833              gnus-tmp-thread-tree-header-string
4834              (cond
4835               ((not gnus-show-threads) "")
4836               ((zerop gnus-tmp-level)
4837                (if (cdar thread)
4838                    (or gnus-sum-thread-tree-root subject)
4839                  (or gnus-sum-thread-tree-single-indent subject)))
4840               (t
4841                (concat (apply 'concat
4842                               (mapcar (lambda (item)
4843                                         (if (= item 1)
4844                                             gnus-sum-thread-tree-vertical
4845                                           gnus-sum-thread-tree-indent))
4846                                       (cdr (reverse tree-stack))))
4847                        (if (nth 1 thread)
4848                            gnus-sum-thread-tree-leaf-with-other
4849                          gnus-sum-thread-tree-single-leaf)))))
4850             (when (string= gnus-tmp-name "")
4851               (setq gnus-tmp-name gnus-tmp-from))
4852             (unless (numberp gnus-tmp-lines)
4853               (setq gnus-tmp-lines -1))
4854             (if (= gnus-tmp-lines -1)
4855                 (setq gnus-tmp-lines "?")
4856               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4857               (gnus-put-text-property
4858              (point)
4859              (progn (eval gnus-summary-line-format-spec) (point))
4860                'gnus-number number)
4861             (when gnus-visual-p
4862               (forward-line -1)
4863               (gnus-run-hooks 'gnus-summary-update-hook)
4864               (forward-line 1))
4865
4866             (setq gnus-tmp-prev-subject simp-subject)))
4867
4868         (when (nth 1 thread)
4869           (push (list (max 0 gnus-tmp-level)
4870                       (copy-list tree-stack)
4871                       (nthcdr 1 thread))
4872                 stack))
4873         (push (if (nth 1 thread) 1 0) tree-stack)
4874         (incf gnus-tmp-level)
4875         (setq threads (if thread-end nil (cdar thread)))
4876         (if gnus-summary-display-while-building
4877             (if building-count
4878                 (progn
4879                   ;; use a set frequency
4880                   (setq building-line-count (1- building-line-count))
4881                   (when (= building-line-count 0)
4882                     (sit-for 0)
4883                     (setq building-line-count
4884                           gnus-summary-display-while-building)))
4885               ;; always
4886               (sit-for 0)))
4887         (unless threads
4888           (setq gnus-tmp-level 0)))))
4889   (gnus-message 7 "Generating summary...done"))
4890
4891 (defun gnus-summary-prepare-unthreaded (headers)
4892   "Generate an unthreaded summary buffer based on HEADERS."
4893   (let (header number mark)
4894
4895     (beginning-of-line)
4896
4897     (while headers
4898       ;; We may have to root out some bad articles...
4899       (when (memq (setq number (mail-header-number
4900                                 (setq header (pop headers))))
4901                   gnus-newsgroup-limit)
4902         ;; Mark article as read when it has a low score.
4903         (when (and gnus-summary-mark-below
4904                    (< (or (cdr (assq number gnus-newsgroup-scored))
4905                           gnus-summary-default-score 0)
4906                       gnus-summary-mark-below)
4907                    (not (gnus-summary-article-ancient-p number)))
4908           (setq gnus-newsgroup-unreads
4909                 (delq number gnus-newsgroup-unreads))
4910           (if gnus-newsgroup-auto-expire
4911               (push number gnus-newsgroup-expirable)
4912             (push (cons number gnus-low-score-mark)
4913                   gnus-newsgroup-reads)))
4914
4915         (setq mark (gnus-article-mark number))
4916         (push (gnus-data-make number mark (1+ (point)) header 0)
4917               gnus-newsgroup-data)
4918         (gnus-summary-insert-line
4919          header 0 number
4920          (memq number gnus-newsgroup-undownloaded)
4921          mark (memq number gnus-newsgroup-replied)
4922          (memq number gnus-newsgroup-expirable)
4923          (mail-header-subject header) nil
4924          (cdr (assq number gnus-newsgroup-scored))
4925          (memq number gnus-newsgroup-processable))))))
4926
4927 (defun gnus-summary-remove-list-identifiers ()
4928   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4929   (let ((regexp (if (consp gnus-list-identifiers)
4930                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4931                   gnus-list-identifiers))
4932         changed subject)
4933     (when regexp
4934       (dolist (header gnus-newsgroup-headers)
4935         (setq subject (mail-header-subject header)
4936               changed nil)
4937         (while (string-match
4938                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4939                 subject)
4940           (setq subject
4941                 (concat (substring subject 0 (match-beginning 2))
4942                         (substring subject (match-end 0)))
4943                 changed t))
4944         (when (and changed
4945                    (string-match
4946                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4947           (setq subject
4948                 (concat (substring subject 0 (match-beginning 1))
4949                         (substring subject (match-end 1)))))
4950         (when changed
4951           (mail-header-set-subject header subject))))))
4952
4953 (defun gnus-fetch-headers (articles)
4954   "Fetch headers of ARTICLES."
4955   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4956     (gnus-message 5 "Fetching headers for %s..." name)
4957     (prog1
4958         (if (eq 'nov
4959                 (setq gnus-headers-retrieved-by
4960                       (gnus-retrieve-headers
4961                        articles gnus-newsgroup-name
4962                        ;; We might want to fetch old headers, but
4963                        ;; not if there is only 1 article.
4964                        (and (or (and
4965                                  (not (eq gnus-fetch-old-headers 'some))
4966                                  (not (numberp gnus-fetch-old-headers)))
4967                                 (> (length articles) 1))
4968                             gnus-fetch-old-headers))))
4969             (gnus-get-newsgroup-headers-xover
4970              articles nil nil gnus-newsgroup-name t)
4971           (gnus-get-newsgroup-headers))
4972       (gnus-message 5 "Fetching headers for %s...done" name))))
4973
4974 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4975   "Select newsgroup GROUP.
4976 If READ-ALL is non-nil, all articles in the group are selected.
4977 If SELECT-ARTICLES, only select those articles from GROUP."
4978   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4979          ;;!!! Dirty hack; should be removed.
4980          (gnus-summary-ignore-duplicates
4981           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4982               t
4983             gnus-summary-ignore-duplicates))
4984          (info (nth 2 entry))
4985          articles fetched-articles cached)
4986
4987     (unless (gnus-check-server
4988              (set (make-local-variable 'gnus-current-select-method)
4989                   (gnus-find-method-for-group group)))
4990       (error "Couldn't open server"))
4991
4992     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4993         (gnus-activate-group group)     ; Or we can activate it...
4994         (progn                          ; Or we bug out.
4995           (when (equal major-mode 'gnus-summary-mode)
4996             (gnus-kill-buffer (current-buffer)))
4997           (error "Couldn't activate group %s: %s"
4998                  group (gnus-status-message group))))
4999
5000     (unless (gnus-request-group group t)
5001       (when (equal major-mode 'gnus-summary-mode)
5002         (gnus-kill-buffer (current-buffer)))
5003       (error "Couldn't request group %s: %s"
5004              group (gnus-status-message group)))
5005
5006     (setq gnus-newsgroup-name group
5007           gnus-newsgroup-unselected nil
5008           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5009
5010     (let ((display (gnus-group-find-parameter group 'display)))
5011       (setq gnus-newsgroup-display
5012             (cond
5013              ((not (zerop (or (car-safe read-all) 0)))
5014               ;; The user entered the group with C-u SPC/RET, let's show
5015               ;; all articles.
5016               'gnus-not-ignore)
5017              ((eq display 'all)
5018               'gnus-not-ignore)
5019              ((arrayp display)
5020               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5021              ((numberp display)
5022               ;; The following is probably the "correct" solution, but
5023               ;; it makes Gnus fetch all headers and then limit the
5024               ;; articles (which is slow), so instead we hack the
5025               ;; select-articles parameter instead. -- Simon Josefsson
5026               ;; <jas@kth.se>
5027               ;;
5028               ;; (gnus-byte-compile
5029               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5030               ;;                         display)))))
5031               (setq select-articles
5032                     (gnus-uncompress-range
5033                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5034                              (if (> tmp 0)
5035                                  tmp
5036                                1))
5037                            (cdr (gnus-active group)))))
5038               nil)
5039              (t
5040               nil))))
5041
5042     (gnus-summary-setup-default-charset)
5043
5044     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5045     (when (gnus-virtual-group-p group)
5046       (setq cached gnus-newsgroup-cached))
5047
5048     (setq gnus-newsgroup-unreads
5049           (gnus-sorted-ndifference
5050            (gnus-sorted-ndifference gnus-newsgroup-unreads
5051                                     gnus-newsgroup-marked)
5052            gnus-newsgroup-dormant))
5053
5054     (setq gnus-newsgroup-processable nil)
5055
5056     (gnus-update-read-articles group gnus-newsgroup-unreads)
5057
5058     ;; Adjust and set lists of article marks.
5059     (when info
5060       (gnus-adjust-marked-articles info))
5061     (if (setq articles select-articles)
5062         (setq gnus-newsgroup-unselected
5063               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5064       (setq articles (gnus-articles-to-read group read-all)))
5065
5066     (cond
5067      ((null articles)
5068       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5069       'quit)
5070      ((eq articles 0) nil)
5071      (t
5072       ;; Init the dependencies hash table.
5073       (setq gnus-newsgroup-dependencies
5074             (gnus-make-hashtable (length articles)))
5075       (gnus-set-global-variables)
5076       ;; Retrieve the headers and read them in.
5077
5078       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5079
5080       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5081       (when cached
5082         (setq gnus-newsgroup-cached cached))
5083
5084       ;; Suppress duplicates?
5085       (when gnus-suppress-duplicates
5086         (gnus-dup-suppress-articles))
5087
5088       ;; Set the initial limit.
5089       (setq gnus-newsgroup-limit (copy-sequence articles))
5090       ;; Remove canceled articles from the list of unread articles.
5091       (setq fetched-articles
5092             (mapcar (lambda (headers) (mail-header-number headers))
5093                     gnus-newsgroup-headers))
5094       (setq gnus-newsgroup-articles fetched-articles)
5095       (setq gnus-newsgroup-unreads
5096             (gnus-sorted-nintersection
5097              gnus-newsgroup-unreads fetched-articles))
5098       (gnus-compute-unseen-list)
5099
5100       ;; Removed marked articles that do not exist.
5101       (gnus-update-missing-marks
5102        (gnus-sorted-difference articles fetched-articles))
5103       ;; We might want to build some more threads first.
5104       (when (and gnus-fetch-old-headers
5105                  (eq gnus-headers-retrieved-by 'nov))
5106         (if (eq gnus-fetch-old-headers 'invisible)
5107             (gnus-build-all-threads)
5108           (gnus-build-old-threads)))
5109       ;; Let the Gnus agent mark articles as read.
5110       (when gnus-agent
5111         (gnus-agent-get-undownloaded-list))
5112       ;; Remove list identifiers from subject
5113       (when gnus-list-identifiers
5114         (gnus-summary-remove-list-identifiers))
5115       ;; Check whether auto-expire is to be done in this group.
5116       (setq gnus-newsgroup-auto-expire
5117             (gnus-group-auto-expirable-p group))
5118       ;; Set up the article buffer now, if necessary.
5119       (unless gnus-single-article-buffer
5120         (gnus-article-setup-buffer))
5121       ;; First and last article in this newsgroup.
5122       (when gnus-newsgroup-headers
5123         (setq gnus-newsgroup-begin
5124               (mail-header-number (car gnus-newsgroup-headers))
5125               gnus-newsgroup-end
5126               (mail-header-number
5127                (gnus-last-element gnus-newsgroup-headers))))
5128       ;; GROUP is successfully selected.
5129       (or gnus-newsgroup-headers t)))))
5130
5131 (defun gnus-compute-unseen-list ()
5132   ;; The `seen' marks are treated specially.
5133   (if (not gnus-newsgroup-seen)
5134       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5135     (setq gnus-newsgroup-unseen
5136           (gnus-inverse-list-range-intersection
5137            gnus-newsgroup-articles gnus-newsgroup-seen))))
5138
5139 (defun gnus-summary-display-make-predicate (display)
5140   (require 'gnus-agent)
5141   (when (= (length display) 1)
5142     (setq display (car display)))
5143   (unless gnus-summary-display-cache
5144     (dolist (elem (append '((unread . unread)
5145                             (read . read)
5146                             (unseen . unseen))
5147                           gnus-article-mark-lists))
5148       (push (cons (cdr elem)
5149                   (gnus-byte-compile
5150                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5151             gnus-summary-display-cache)))
5152   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5153         (gnus-category-predicate-cache gnus-summary-display-cache))
5154     (gnus-get-predicate display)))
5155
5156 ;; Uses the dynamically bound `number' variable.
5157 (eval-when-compile
5158   (defvar number))
5159 (defun gnus-article-marked-p (type &optional article)
5160   (let ((article (or article number)))
5161     (cond
5162      ((eq type 'tick)
5163       (memq article gnus-newsgroup-marked))
5164      ((eq type 'spam)
5165       (memq article gnus-newsgroup-spam-marked))
5166      ((eq type 'unsend)
5167       (memq article gnus-newsgroup-unsendable))
5168      ((eq type 'undownload)
5169       (memq article gnus-newsgroup-undownloaded))
5170      ((eq type 'download)
5171       (memq article gnus-newsgroup-downloadable))
5172      ((eq type 'unread)
5173       (memq article gnus-newsgroup-unreads))
5174      ((eq type 'read)
5175       (memq article gnus-newsgroup-reads))
5176      ((eq type 'dormant)
5177       (memq article gnus-newsgroup-dormant) )
5178      ((eq type 'expire)
5179       (memq article gnus-newsgroup-expirable))
5180      ((eq type 'reply)
5181       (memq article gnus-newsgroup-replied))
5182      ((eq type 'killed)
5183       (memq article gnus-newsgroup-killed))
5184      ((eq type 'bookmark)
5185       (assq article gnus-newsgroup-bookmarks))
5186      ((eq type 'score)
5187       (assq article gnus-newsgroup-scored))
5188      ((eq type 'save)
5189       (memq article gnus-newsgroup-saved))
5190      ((eq type 'cache)
5191       (memq article gnus-newsgroup-cached))
5192      ((eq type 'forward)
5193       (memq article gnus-newsgroup-forwarded))
5194      ((eq type 'seen)
5195       (not (memq article gnus-newsgroup-unseen)))
5196      ((eq type 'recent)
5197       (memq article gnus-newsgroup-recent))
5198      (t t))))
5199
5200 (defun gnus-articles-to-read (group &optional read-all)
5201   "Find out what articles the user wants to read."
5202   (let* ((display (gnus-group-find-parameter group 'display))
5203          (articles
5204           ;; Select all articles if `read-all' is non-nil, or if there
5205           ;; are no unread articles.
5206           (if (or read-all
5207                   (and (zerop (length gnus-newsgroup-marked))
5208                        (zerop (length gnus-newsgroup-unreads)))
5209                   ;; Fetch all if the predicate is non-nil.
5210                   gnus-newsgroup-display)
5211               ;; We want to select the headers for all the articles in
5212               ;; the group, so we select either all the active
5213               ;; articles in the group, or (if that's nil), the
5214               ;; articles in the cache.
5215               (or
5216                (gnus-uncompress-range (gnus-active group))
5217                (gnus-cache-articles-in-group group))
5218             ;; Select only the "normal" subset of articles.
5219             (gnus-sorted-nunion
5220              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5221              gnus-newsgroup-unreads)))
5222          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5223          (scored (length scored-list))
5224          (number (length articles))
5225          (marked (+ (length gnus-newsgroup-marked)
5226                     (length gnus-newsgroup-dormant)))
5227          (select
5228           (cond
5229            ((numberp read-all)
5230             read-all)
5231            ((numberp gnus-newsgroup-display)
5232             gnus-newsgroup-display)
5233            (t
5234             (condition-case ()
5235                 (cond
5236                  ((and (or (<= scored marked) (= scored number))
5237                        (numberp gnus-large-newsgroup)
5238                        (> number gnus-large-newsgroup))
5239                   (let* ((cursor-in-echo-area nil)
5240                          (initial (gnus-parameter-large-newsgroup-initial
5241                                    gnus-newsgroup-name))
5242                          (input
5243                           (read-string
5244                            (format
5245                             "How many articles from %s (%s %d): "
5246                             (gnus-limit-string
5247                              (gnus-group-decoded-name gnus-newsgroup-name)
5248                              35)
5249                             (if initial "max" "default")
5250                             number)
5251                            (if initial
5252                                (cons (number-to-string initial)
5253                                      0)))))
5254                     (if (string-match "^[ \t]*$" input) number input)))
5255                  ((and (> scored marked) (< scored number)
5256                        (> (- scored number) 20))
5257                   (let ((input
5258                          (read-string
5259                           (format "%s %s (%d scored, %d total): "
5260                                   "How many articles from"
5261                                   (gnus-group-decoded-name group)
5262                                   scored number))))
5263                     (if (string-match "^[ \t]*$" input)
5264                         number input)))
5265                  (t number))
5266               (quit
5267                (message "Quit getting the articles to read")
5268                nil))))))
5269     (setq select (if (stringp select) (string-to-number select) select))
5270     (if (or (null select) (zerop select))
5271         select
5272       (if (and (not (zerop scored)) (<= (abs select) scored))
5273           (progn
5274             (setq articles (sort scored-list '<))
5275             (setq number (length articles)))
5276         (setq articles (copy-sequence articles)))
5277
5278       (when (< (abs select) number)
5279         (if (< select 0)
5280             ;; Select the N oldest articles.
5281             (setcdr (nthcdr (1- (abs select)) articles) nil)
5282           ;; Select the N most recent articles.
5283           (setq articles (nthcdr (- number select) articles))))
5284       (setq gnus-newsgroup-unselected
5285             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5286       (when gnus-alter-articles-to-read-function
5287         (setq articles
5288               (sort
5289                (funcall gnus-alter-articles-to-read-function
5290                         gnus-newsgroup-name articles)
5291                '<)))
5292       articles)))
5293
5294 (defun gnus-killed-articles (killed articles)
5295   (let (out)
5296     (while articles
5297       (when (inline (gnus-member-of-range (car articles) killed))
5298         (push (car articles) out))
5299       (setq articles (cdr articles)))
5300     out))
5301
5302 (defun gnus-uncompress-marks (marks)
5303   "Uncompress the mark ranges in MARKS."
5304   (let ((uncompressed '(score bookmark))
5305         out)
5306     (while marks
5307       (if (memq (caar marks) uncompressed)
5308           (push (car marks) out)
5309         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5310       (setq marks (cdr marks)))
5311     out))
5312
5313 (defun gnus-article-mark-to-type (mark)
5314   "Return the type of MARK."
5315   (or (cadr (assq mark gnus-article-special-mark-lists))
5316       'list))
5317
5318 (defun gnus-article-unpropagatable-p (mark)
5319   "Return whether MARK should be propagated to backend."
5320   (memq mark gnus-article-unpropagated-mark-lists))
5321
5322 (defun gnus-adjust-marked-articles (info)
5323   "Set all article lists and remove all marks that are no longer valid."
5324   (let* ((marked-lists (gnus-info-marks info))
5325          (active (gnus-active (gnus-info-group info)))
5326          (min (car active))
5327          (max (cdr active))
5328          (types gnus-article-mark-lists)
5329          marks var articles article mark mark-type)
5330
5331     (dolist (marks marked-lists)
5332       (setq mark (car marks)
5333             mark-type (gnus-article-mark-to-type mark)
5334             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5335
5336       ;; We set the variable according to the type of the marks list,
5337       ;; and then adjust the marks to a subset of the active articles.
5338       (cond
5339        ;; Adjust "simple" lists.
5340        ((eq mark-type 'list)
5341         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5342         (when (memq mark '(tick dormant expire reply save))
5343           (while articles
5344             (when (or (< (setq article (pop articles)) min) (> article max))
5345               (set var (delq article (symbol-value var)))))))
5346        ;; Adjust assocs.
5347        ((eq mark-type 'tuple)
5348         (set var (setq articles (cdr marks)))
5349         (when (not (listp (cdr (symbol-value var))))
5350           (set var (list (symbol-value var))))
5351         (when (not (listp (cdr articles)))
5352           (setq articles (list articles)))
5353         (while articles
5354           (when (or (not (consp (setq article (pop articles))))
5355                     (< (car article) min)
5356                     (> (car article) max))
5357             (set var (delq article (symbol-value var))))))
5358        ;; Adjust ranges (sloppily).
5359        ((eq mark-type 'range)
5360         (cond
5361          ((eq mark 'seen)
5362           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5363           ;; It should be (seen (NUM1 . NUM2)).
5364           (when (numberp (cddr marks))
5365             (setcdr marks (list (cdr marks))))
5366           (setq articles (cdr marks))
5367           (while (and articles
5368                       (or (and (consp (car articles))
5369                                (> min (cdar articles)))
5370                           (and (numberp (car articles))
5371                                (> min (car articles)))))
5372             (pop articles))
5373           (set var articles))))))))
5374
5375 (defun gnus-update-missing-marks (missing)
5376   "Go through the list of MISSING articles and remove them from the mark lists."
5377   (when missing
5378     (let (var m)
5379       ;; Go through all types.
5380       (dolist (elem gnus-article-mark-lists)
5381         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5382           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5383           (when (symbol-value var)
5384             ;; This list has articles.  So we delete all missing
5385             ;; articles from it.
5386             (setq m missing)
5387             (while m
5388               (set var (delq (pop m) (symbol-value var))))))))))
5389
5390 (defun gnus-update-marks ()
5391   "Enter the various lists of marked articles into the newsgroup info list."
5392   (let ((types gnus-article-mark-lists)
5393         (info (gnus-get-info gnus-newsgroup-name))
5394         type list newmarked symbol delta-marks)
5395     (when info
5396       ;; Add all marks lists to the list of marks lists.
5397       (while (setq type (pop types))
5398         (setq list (symbol-value
5399                     (setq symbol
5400                           (intern (format "gnus-newsgroup-%s" (car type))))))
5401
5402         (when list
5403           ;; Get rid of the entries of the articles that have the
5404           ;; default score.
5405           (when (and (eq (cdr type) 'score)
5406                      gnus-save-score
5407                      list)
5408             (let* ((arts list)
5409                    (prev (cons nil list))
5410                    (all prev))
5411               (while arts
5412                 (if (or (not (consp (car arts)))
5413                         (= (cdar arts) gnus-summary-default-score))
5414                     (setcdr prev (cdr arts))
5415                   (setq prev arts))
5416                 (setq arts (cdr arts)))
5417               (setq list (cdr all)))))
5418
5419         (when (eq (cdr type) 'seen)
5420           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5421
5422         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5423           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5424
5425         (when (and (gnus-check-backend-function
5426                     'request-set-mark gnus-newsgroup-name)
5427                    (not (gnus-article-unpropagatable-p (cdr type))))
5428           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5429                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5430                  (add (gnus-remove-from-range
5431                        (gnus-copy-sequence list) old)))
5432             (when add
5433               (push (list add 'add (list (cdr type))) delta-marks))
5434             (when del
5435               (push (list del 'del (list (cdr type))) delta-marks))))
5436
5437         (when list
5438           (push (cons (cdr type) list) newmarked)))
5439
5440       (when delta-marks
5441         (unless (gnus-check-group gnus-newsgroup-name)
5442           (error "Can't open server for %s" gnus-newsgroup-name))
5443         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5444
5445       ;; Enter these new marks into the info of the group.
5446       (if (nthcdr 3 info)
5447           (setcar (nthcdr 3 info) newmarked)
5448         ;; Add the marks lists to the end of the info.
5449         (when newmarked
5450           (setcdr (nthcdr 2 info) (list newmarked))))
5451
5452       ;; Cut off the end of the info if there's nothing else there.
5453       (let ((i 5))
5454         (while (and (> i 2)
5455                     (not (nth i info)))
5456           (when (nthcdr (decf i) info)
5457             (setcdr (nthcdr i info) nil)))))))
5458
5459 (defun gnus-set-mode-line (where)
5460   "Set the mode line of the article or summary buffers.
5461 If WHERE is `summary', the summary mode line format will be used."
5462   ;; Is this mode line one we keep updated?
5463   (when (and (memq where gnus-updated-mode-lines)
5464              (symbol-value
5465               (intern (format "gnus-%s-mode-line-format-spec" where))))
5466     (let (mode-string)
5467       (save-excursion
5468         ;; We evaluate this in the summary buffer since these
5469         ;; variables are buffer-local to that buffer.
5470         (set-buffer gnus-summary-buffer)
5471         ;; We bind all these variables that are used in the `eval' form
5472         ;; below.
5473         (let* ((mformat (symbol-value
5474                          (intern
5475                           (format "gnus-%s-mode-line-format-spec" where))))
5476                (gnus-tmp-group-name (gnus-group-decoded-name
5477                                      gnus-newsgroup-name))
5478                (gnus-tmp-article-number (or gnus-current-article 0))
5479                (gnus-tmp-unread gnus-newsgroup-unreads)
5480                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5481                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5482                (gnus-tmp-unread-and-unselected
5483                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5484                             (zerop gnus-tmp-unselected))
5485                        "")
5486                       ((zerop gnus-tmp-unselected)
5487                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5488                       (t (format "{%d(+%d) more}"
5489                                  gnus-tmp-unread-and-unticked
5490                                  gnus-tmp-unselected))))
5491                (gnus-tmp-subject
5492                 (if (and gnus-current-headers
5493                          (vectorp gnus-current-headers))
5494                     (gnus-mode-string-quote
5495                      (mail-header-subject gnus-current-headers))
5496                   ""))
5497                bufname-length max-len
5498                gnus-tmp-header);; passed as argument to any user-format-funcs
5499           (setq mode-string (eval mformat))
5500           (setq bufname-length (if (string-match "%b" mode-string)
5501                                    (- (length
5502                                        (buffer-name
5503                                         (if (eq where 'summary)
5504                                             nil
5505                                           (get-buffer gnus-article-buffer))))
5506                                       2)
5507                                  0))
5508           (setq max-len (max 4 (if gnus-mode-non-string-length
5509                                    (- (window-width)
5510                                       gnus-mode-non-string-length
5511                                       bufname-length)
5512                                  (length mode-string))))
5513           ;; We might have to chop a bit of the string off...
5514           (when (> (length mode-string) max-len)
5515             (setq mode-string
5516                   (concat (gnus-truncate-string mode-string (- max-len 3))
5517                           "...")))
5518           ;; Pad the mode string a bit.
5519           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5520       ;; Update the mode line.
5521       (setq mode-line-buffer-identification
5522             (gnus-mode-line-buffer-identification (list mode-string)))
5523       (set-buffer-modified-p t))))
5524
5525 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5526   "Go through the HEADERS list and add all Xrefs to a hash table.
5527 The resulting hash table is returned, or nil if no Xrefs were found."
5528   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5529          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5530          (xref-hashtb (gnus-make-hashtable))
5531          start group entry number xrefs header)
5532     (while headers
5533       (setq header (pop headers))
5534       (when (and (setq xrefs (mail-header-xref header))
5535                  (not (memq (setq number (mail-header-number header))
5536                             unreads)))
5537         (setq start 0)
5538         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5539           (setq start (match-end 0))
5540           (setq group (if prefix
5541                           (concat prefix (substring xrefs (match-beginning 1)
5542                                                     (match-end 1)))
5543                         (substring xrefs (match-beginning 1) (match-end 1))))
5544           (setq number
5545                 (string-to-int (substring xrefs (match-beginning 2)
5546                                           (match-end 2))))
5547           (if (setq entry (gnus-gethash group xref-hashtb))
5548               (setcdr entry (cons number (cdr entry)))
5549             (gnus-sethash group (cons number nil) xref-hashtb)))))
5550     (and start xref-hashtb)))
5551
5552 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5553   "Look through all the headers and mark the Xrefs as read."
5554   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5555         name entry info xref-hashtb idlist method nth4)
5556     (save-excursion
5557       (set-buffer gnus-group-buffer)
5558       (when (setq xref-hashtb
5559                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5560         (mapatoms
5561          (lambda (group)
5562            (unless (string= from-newsgroup (setq name (symbol-name group)))
5563              (setq idlist (symbol-value group))
5564              ;; Dead groups are not updated.
5565              (and (prog1
5566                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5567                             info (nth 2 entry))
5568                     (when (stringp (setq nth4 (gnus-info-method info)))
5569                       (setq nth4 (gnus-server-to-method nth4))))
5570                   ;; Only do the xrefs if the group has the same
5571                   ;; select method as the group we have just read.
5572                   (or (gnus-methods-equal-p
5573                        nth4 (gnus-find-method-for-group from-newsgroup))
5574                       virtual
5575                       (equal nth4 (setq method (gnus-find-method-for-group
5576                                                 from-newsgroup)))
5577                       (and (equal (car nth4) (car method))
5578                            (equal (nth 1 nth4) (nth 1 method))))
5579                   gnus-use-cross-reference
5580                   (or (not (eq gnus-use-cross-reference t))
5581                       virtual
5582                       ;; Only do cross-references on subscribed
5583                       ;; groups, if that is what is wanted.
5584                       (<= (gnus-info-level info) gnus-level-subscribed))
5585                   (gnus-group-make-articles-read name idlist))))
5586          xref-hashtb)))))
5587
5588 (defun gnus-compute-read-articles (group articles)
5589   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5590          (info (nth 2 entry))
5591          (active (gnus-active group))
5592          ninfo)
5593     (when entry
5594       ;; First peel off all invalid article numbers.
5595       (when active
5596         (let ((ids articles)
5597               id first)
5598           (while (setq id (pop ids))
5599             (when (and first (> id (cdr active)))
5600               ;; We'll end up in this situation in one particular
5601               ;; obscure situation.  If you re-scan a group and get
5602               ;; a new article that is cross-posted to a different
5603               ;; group that has not been re-scanned, you might get
5604               ;; crossposted article that has a higher number than
5605               ;; Gnus believes possible.  So we re-activate this
5606               ;; group as well.  This might mean doing the
5607               ;; crossposting thingy will *increase* the number
5608               ;; of articles in some groups.  Tsk, tsk.
5609               (setq active (or (gnus-activate-group group) active)))
5610             (when (or (> id (cdr active))
5611                       (< id (car active)))
5612               (setq articles (delq id articles))))))
5613       ;; If the read list is nil, we init it.
5614       (if (and active
5615                (null (gnus-info-read info))
5616                (> (car active) 1))
5617           (setq ninfo (cons 1 (1- (car active))))
5618         (setq ninfo (gnus-info-read info)))
5619       ;; Then we add the read articles to the range.
5620       (gnus-add-to-range
5621        ninfo (setq articles (sort articles '<))))))
5622
5623 (defun gnus-group-make-articles-read (group articles)
5624   "Update the info of GROUP to say that ARTICLES are read."
5625   (let* ((num 0)
5626          (entry (gnus-gethash group gnus-newsrc-hashtb))
5627          (info (nth 2 entry))
5628          (active (gnus-active group))
5629          range)
5630     (when entry
5631       (setq range (gnus-compute-read-articles group articles))
5632       (save-excursion
5633         (set-buffer gnus-group-buffer)
5634         (gnus-undo-register
5635           `(progn
5636              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5637              (gnus-info-set-read ',info ',(gnus-info-read info))
5638              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5639              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5640              (gnus-group-update-group ,group t))))
5641       ;; Add the read articles to the range.
5642       (gnus-info-set-read info range)
5643       (gnus-request-set-mark group (list (list range 'add '(read))))
5644       ;; Then we have to re-compute how many unread
5645       ;; articles there are in this group.
5646       (when active
5647         (cond
5648          ((not range)
5649           (setq num (- (1+ (cdr active)) (car active))))
5650          ((not (listp (cdr range)))
5651           (setq num (- (cdr active) (- (1+ (cdr range))
5652                                        (car range)))))
5653          (t
5654           (while range
5655             (if (numberp (car range))
5656                 (setq num (1+ num))
5657               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5658             (setq range (cdr range)))
5659           (setq num (- (cdr active) num))))
5660         ;; Update the number of unread articles.
5661         (setcar entry num)
5662         ;; Update the group buffer.
5663         (unless (gnus-ephemeral-group-p group)
5664           (gnus-group-update-group group t))))))
5665
5666 (defvar gnus-newsgroup-none-id 0)
5667
5668 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5669   (let ((cur nntp-server-buffer)
5670         (dependencies
5671          (or dependencies
5672              (save-excursion (set-buffer gnus-summary-buffer)
5673                              gnus-newsgroup-dependencies)))
5674         headers id end ref
5675         (mail-parse-charset gnus-newsgroup-charset)
5676         (mail-parse-ignored-charsets
5677          (save-excursion (condition-case nil
5678                              (set-buffer gnus-summary-buffer)
5679                            (error))
5680                          gnus-newsgroup-ignored-charsets)))
5681     (save-excursion
5682       (set-buffer nntp-server-buffer)
5683       ;; Translate all TAB characters into SPACE characters.
5684       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5685       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5686       (gnus-run-hooks 'gnus-parse-headers-hook)
5687       (let ((case-fold-search t)
5688             in-reply-to header p lines chars ctype)
5689         (goto-char (point-min))
5690         ;; Search to the beginning of the next header.  Error messages
5691         ;; do not begin with 2 or 3.
5692         (while (re-search-forward "^[23][0-9]+ " nil t)
5693           (setq id nil
5694                 ref nil)
5695           ;; This implementation of this function, with nine
5696           ;; search-forwards instead of the one re-search-forward and
5697           ;; a case (which basically was the old function) is actually
5698           ;; about twice as fast, even though it looks messier.  You
5699           ;; can't have everything, I guess.  Speed and elegance
5700           ;; doesn't always go hand in hand.
5701           (setq
5702            header
5703            (make-full-mail-header
5704             ;; Number.
5705             (prog1
5706                 (read cur)
5707               (end-of-line)
5708               (setq p (point))
5709               (narrow-to-region (point)
5710                                 (or (and (search-forward "\n.\n" nil t)
5711                                          (- (point) 2))
5712                                     (point))))
5713             ;; Subject.
5714             (progn
5715               (goto-char p)
5716               (if (search-forward "\nsubject:" nil t)
5717                   (nnheader-header-value)
5718                 "(none)"))
5719             ;; From.
5720             (progn
5721               (goto-char p)
5722               (if (search-forward "\nfrom:" nil t)
5723                   (nnheader-header-value)
5724                 "(nobody)"))
5725             ;; Date.
5726             (progn
5727               (goto-char p)
5728               (if (search-forward "\ndate:" nil t)
5729                   (nnheader-header-value) ""))
5730             ;; Message-ID.
5731             (progn
5732               (goto-char p)
5733               (setq id (if (re-search-forward
5734                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5735                            ;; We do it this way to make sure the Message-ID
5736                            ;; is (somewhat) syntactically valid.
5737                            (buffer-substring (match-beginning 1)
5738                                              (match-end 1))
5739                          ;; If there was no message-id, we just fake one
5740                          ;; to make subsequent routines simpler.
5741                          (nnheader-generate-fake-message-id))))
5742             ;; References.
5743             (progn
5744               (goto-char p)
5745               (if (search-forward "\nreferences:" nil t)
5746                   (progn
5747                     (setq end (point))
5748                     (prog1
5749                         (nnheader-header-value)
5750                       (setq ref
5751                             (buffer-substring
5752                              (progn
5753                                ;; (end-of-line)
5754                                (search-backward ">" end t)
5755                                (1+ (point)))
5756                              (progn
5757                                (search-backward "<" end t)
5758                                (point))))))
5759                 ;; Get the references from the in-reply-to header if there
5760                 ;; were no references and the in-reply-to header looks
5761                 ;; promising.
5762                 (if (and (search-forward "\nin-reply-to:" nil t)
5763                          (setq in-reply-to (nnheader-header-value))
5764                          (string-match "<[^>]+>" in-reply-to))
5765                     (let (ref2)
5766                       (setq ref (substring in-reply-to (match-beginning 0)
5767                                            (match-end 0)))
5768                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5769                         (setq ref2 (substring in-reply-to (match-beginning 0)
5770                                               (match-end 0)))
5771                         (when (> (length ref2) (length ref))
5772                           (setq ref ref2)))
5773                       ref)
5774                   (setq ref nil))))
5775             ;; Chars.
5776             (progn
5777               (goto-char p)
5778               (if (search-forward "\nchars: " nil t)
5779                   (if (numberp (setq chars (ignore-errors (read cur))))
5780                       chars -1)
5781                 -1))
5782             ;; Lines.
5783             (progn
5784               (goto-char p)
5785               (if (search-forward "\nlines: " nil t)
5786                   (if (numberp (setq lines (ignore-errors (read cur))))
5787                       lines -1)
5788                 -1))
5789             ;; Xref.
5790             (progn
5791               (goto-char p)
5792               (and (search-forward "\nxref:" nil t)
5793                    (nnheader-header-value)))
5794             ;; Extra.
5795             (when gnus-extra-headers
5796               (let ((extra gnus-extra-headers)
5797                     out)
5798                 (while extra
5799                   (goto-char p)
5800                   (when (search-forward
5801                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5802                     (push (cons (car extra) (nnheader-header-value)) out))
5803                   (pop extra))
5804                 out))))
5805           (goto-char p)
5806           (if (and (search-forward "\ncontent-type: " nil t)
5807                    (setq ctype (nnheader-header-value)))
5808               (mime-entity-set-content-type-internal
5809                header (mime-parse-Content-Type ctype)))
5810           (when (equal id ref)
5811             (setq ref nil))
5812
5813           (when gnus-alter-header-function
5814             (funcall gnus-alter-header-function header)
5815             (setq id (mail-header-id header)
5816                   ref (gnus-parent-id (mail-header-references header))))
5817
5818           (when (setq header
5819                       (gnus-dependencies-add-header
5820                        header dependencies force-new))
5821             (push header headers))
5822           (goto-char (point-max))
5823           (widen))
5824         (nreverse headers)))))
5825
5826 ;; Goes through the xover lines and returns a list of vectors
5827 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5828                                                   force-new dependencies
5829                                                   group also-fetch-heads)
5830   "Parse the news overview data in the server buffer.
5831 Return a list of headers that match SEQUENCE (see
5832 `nntp-retrieve-headers')."
5833   ;; Get the Xref when the users reads the articles since most/some
5834   ;; NNTP servers do not include Xrefs when using XOVER.
5835   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5836   (let ((mail-parse-charset gnus-newsgroup-charset)
5837         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5838         (cur nntp-server-buffer)
5839         (dependencies (or dependencies gnus-newsgroup-dependencies))
5840         (allp (cond
5841                ((eq gnus-read-all-available-headers t)
5842                 t)
5843                ((stringp gnus-read-all-available-headers)
5844                 (string-match gnus-read-all-available-headers group))
5845                (t
5846                 nil)))
5847         number headers header)
5848     (save-excursion
5849       (set-buffer nntp-server-buffer)
5850       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5851       ;; Allow the user to mangle the headers before parsing them.
5852       (gnus-run-hooks 'gnus-parse-headers-hook)
5853       (goto-char (point-min))
5854       (gnus-parse-without-error
5855         (while (and (or sequence allp)
5856                     (not (eobp)))
5857           (setq number (read cur))
5858           (when (not allp)
5859             (while (and sequence
5860                         (< (car sequence) number))
5861               (setq sequence (cdr sequence))))
5862           (when (and (or allp
5863                          (and sequence
5864                               (eq number (car sequence))))
5865                      (progn
5866                        (setq sequence (cdr sequence))
5867                        (setq header (inline
5868                                       (gnus-nov-parse-line
5869                                        number dependencies force-new)))))
5870             (push header headers))
5871           (forward-line 1)))
5872       ;; A common bug in inn is that if you have posted an article and
5873       ;; then retrieves the active file, it will answer correctly --
5874       ;; the new article is included.  However, a NOV entry for the
5875       ;; article may not have been generated yet, so this may fail.
5876       ;; We work around this problem by retrieving the last few
5877       ;; headers using HEAD.
5878       (if (or (not also-fetch-heads)
5879               (not sequence))
5880           ;; We (probably) got all the headers.
5881           (nreverse headers)
5882         (let ((gnus-nov-is-evil t))
5883           (nconc
5884            (nreverse headers)
5885            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5886              (gnus-get-newsgroup-headers))))))))
5887
5888 (defun gnus-article-get-xrefs ()
5889   "Fill in the Xref value in `gnus-current-headers', if necessary.
5890 This is meant to be called in `gnus-article-internal-prepare-hook'."
5891   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5892                                  gnus-current-headers)))
5893     (or (not gnus-use-cross-reference)
5894         (not headers)
5895         (and (mail-header-xref headers)
5896              (not (string= (mail-header-xref headers) "")))
5897         (let ((case-fold-search t)
5898               xref)
5899           (save-restriction
5900             (nnheader-narrow-to-headers)
5901             (goto-char (point-min))
5902             (when (or (and (not (eobp))
5903                            (eq (downcase (char-after)) ?x)
5904                            (looking-at "Xref:"))
5905                       (search-forward "\nXref:" nil t))
5906               (goto-char (1+ (match-end 0)))
5907               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5908               (mail-header-set-xref headers xref)))))))
5909
5910 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5911   "Find article ID and insert the summary line for that article.
5912 OLD-HEADER can either be a header or a line number to insert
5913 the subject line on."
5914   (let* ((line (and (numberp old-header) old-header))
5915          (old-header (and (vectorp old-header) old-header))
5916          (header (cond ((and old-header use-old-header)
5917                         old-header)
5918                        ((and (numberp id)
5919                              (gnus-number-to-header id))
5920                         (gnus-number-to-header id))
5921                        (t
5922                         (gnus-read-header id))))
5923          (number (and (numberp id) id))
5924          d)
5925     (when header
5926       ;; Rebuild the thread that this article is part of and go to the
5927       ;; article we have fetched.
5928       (when (and (not gnus-show-threads)
5929                  old-header)
5930         (when (and number
5931                    (setq d (gnus-data-find (mail-header-number old-header))))
5932           (goto-char (gnus-data-pos d))
5933           (gnus-data-remove
5934            number
5935            (- (gnus-point-at-bol)
5936               (prog1
5937                   (1+ (gnus-point-at-eol))
5938                 (gnus-delete-line))))))
5939       (when old-header
5940         (mail-header-set-number header (mail-header-number old-header)))
5941       (setq gnus-newsgroup-sparse
5942             (delq (setq number (mail-header-number header))
5943                   gnus-newsgroup-sparse))
5944       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5945       (push number gnus-newsgroup-limit)
5946       (gnus-rebuild-thread (mail-header-id header) line)
5947       (gnus-summary-goto-subject number nil t))
5948     (when (and (numberp number)
5949                (> number 0))
5950       ;; We have to update the boundaries even if we can't fetch the
5951       ;; article if ID is a number -- so that the next `P' or `N'
5952       ;; command will fetch the previous (or next) article even
5953       ;; if the one we tried to fetch this time has been canceled.
5954       (when (> number gnus-newsgroup-end)
5955         (setq gnus-newsgroup-end number))
5956       (when (< number gnus-newsgroup-begin)
5957         (setq gnus-newsgroup-begin number))
5958       (setq gnus-newsgroup-unselected
5959             (delq number gnus-newsgroup-unselected)))
5960     ;; Report back a success?
5961     (and header (mail-header-number header))))
5962
5963 ;;; Process/prefix in the summary buffer
5964
5965 (defun gnus-summary-work-articles (n)
5966   "Return a list of articles to be worked upon.
5967 The prefix argument, the list of process marked articles, and the
5968 current article will be taken into consideration."
5969   (save-excursion
5970     (set-buffer gnus-summary-buffer)
5971     (cond
5972      (n
5973       ;; A numerical prefix has been given.
5974       (setq n (prefix-numeric-value n))
5975       (let ((backward (< n 0))
5976             (n (abs (prefix-numeric-value n)))
5977             articles article)
5978         (save-excursion
5979           (while
5980               (and (> n 0)
5981                    (push (setq article (gnus-summary-article-number))
5982                          articles)
5983                    (if backward
5984                        (gnus-summary-find-prev nil article)
5985                      (gnus-summary-find-next nil article)))
5986             (decf n)))
5987         (nreverse articles)))
5988      ((and (gnus-region-active-p) (mark))
5989       (message "region active")
5990       ;; Work on the region between point and mark.
5991       (let ((max (max (point) (mark)))
5992             articles article)
5993         (save-excursion
5994           (goto-char (min (point) (mark)))
5995           (while
5996               (and
5997                (push (setq article (gnus-summary-article-number)) articles)
5998                (gnus-summary-find-next nil article)
5999                (< (point) max)))
6000           (nreverse articles))))
6001      (gnus-newsgroup-processable
6002       ;; There are process-marked articles present.
6003       ;; Save current state.
6004       (gnus-summary-save-process-mark)
6005       ;; Return the list.
6006       (reverse gnus-newsgroup-processable))
6007      (t
6008       ;; Just return the current article.
6009       (list (gnus-summary-article-number))))))
6010
6011 (defmacro gnus-summary-iterate (arg &rest forms)
6012   "Iterate over the process/prefixed articles and do FORMS.
6013 ARG is the interactive prefix given to the command.  FORMS will be
6014 executed with point over the summary line of the articles."
6015   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6016     `(let ((,articles (gnus-summary-work-articles ,arg)))
6017        (while ,articles
6018          (gnus-summary-goto-subject (car ,articles))
6019          ,@forms
6020          (pop ,articles)))))
6021
6022 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6023 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6024
6025 (defun gnus-summary-save-process-mark ()
6026   "Push the current set of process marked articles on the stack."
6027   (interactive)
6028   (push (copy-sequence gnus-newsgroup-processable)
6029         gnus-newsgroup-process-stack))
6030
6031 (defun gnus-summary-kill-process-mark ()
6032   "Push the current set of process marked articles on the stack and unmark."
6033   (interactive)
6034   (gnus-summary-save-process-mark)
6035   (gnus-summary-unmark-all-processable))
6036
6037 (defun gnus-summary-yank-process-mark ()
6038   "Pop the last process mark state off the stack and restore it."
6039   (interactive)
6040   (unless gnus-newsgroup-process-stack
6041     (error "Empty mark stack"))
6042   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6043
6044 (defun gnus-summary-process-mark-set (set)
6045   "Make SET into the current process marked articles."
6046   (gnus-summary-unmark-all-processable)
6047   (while set
6048     (gnus-summary-set-process-mark (pop set))))
6049
6050 ;;; Searching and stuff
6051
6052 (defun gnus-summary-search-group (&optional backward use-level)
6053   "Search for next unread newsgroup.
6054 If optional argument BACKWARD is non-nil, search backward instead."
6055   (save-excursion
6056     (set-buffer gnus-group-buffer)
6057     (when (gnus-group-search-forward
6058            backward nil (if use-level (gnus-group-group-level) nil))
6059       (gnus-group-group-name))))
6060
6061 (defun gnus-summary-best-group (&optional exclude-group)
6062   "Find the name of the best unread group.
6063 If EXCLUDE-GROUP, do not go to this group."
6064   (save-excursion
6065     (set-buffer gnus-group-buffer)
6066     (save-excursion
6067       (gnus-group-best-unread-group exclude-group))))
6068
6069 (defun gnus-summary-find-next (&optional unread article backward)
6070   (if backward (gnus-summary-find-prev unread article)
6071     (let* ((dummy (gnus-summary-article-intangible-p))
6072            (article (or article (gnus-summary-article-number)))
6073            (data (gnus-data-find-list article))
6074            result)
6075       (when (and (not dummy)
6076                  (or (not gnus-summary-check-current)
6077                      (not unread)
6078                      (not (gnus-data-unread-p (car data)))))
6079         (setq data (cdr data)))
6080       (when (setq result
6081                   (if unread
6082                       (progn
6083                         (while data
6084                           (unless (memq (gnus-data-number (car data)) 
6085                                         (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6086                                                gnus-newsgroup-undownloaded)
6087                                               (gnus-plugged
6088                                                nil)
6089                                               ((eq gnus-auto-goto-ignores 'unfetched)
6090                                                gnus-newsgroup-unfetched)
6091                                               ((eq gnus-auto-goto-ignores 'undownloaded)
6092                                                gnus-newsgroup-undownloaded)))
6093                             (when (gnus-data-unread-p (car data))
6094                               (setq result (car data)
6095                                     data nil)))
6096                           (setq data (cdr data)))
6097                         result)
6098                     (car data)))
6099         (goto-char (gnus-data-pos result))
6100         (gnus-data-number result)))))
6101
6102 (defun gnus-summary-find-prev (&optional unread article)
6103   (let* ((eobp (eobp))
6104          (article (or article (gnus-summary-article-number)))
6105          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6106          result)
6107     (when (and (not eobp)
6108                (or (not gnus-summary-check-current)
6109                    (not unread)
6110                    (not (gnus-data-unread-p (car data)))))
6111       (setq data (cdr data)))
6112     (when (setq result
6113                 (if unread
6114                     (progn
6115                       (while data
6116                         (unless (memq (gnus-data-number (car data))
6117                                       (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6118                                              gnus-newsgroup-undownloaded)
6119                                             (gnus-plugged
6120                                              nil)
6121                                             ((eq gnus-auto-goto-ignores 'unfetched)
6122                                              gnus-newsgroup-unfetched)
6123                                             ((eq gnus-auto-goto-ignores 'undownloaded)
6124                                              gnus-newsgroup-undownloaded)))
6125                           (when (gnus-data-unread-p (car data))
6126                             (setq result (car data)
6127                                   data nil)))
6128                         (setq data (cdr data)))
6129                       result)
6130                   (car data)))
6131       (goto-char (gnus-data-pos result))
6132       (gnus-data-number result))))
6133
6134 (defun gnus-summary-find-subject (subject &optional unread backward article)
6135   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6136          (article (or article (gnus-summary-article-number)))
6137          (articles (gnus-data-list backward))
6138          (arts (gnus-data-find-list article articles))
6139          result)
6140     (when (or (not gnus-summary-check-current)
6141               (not unread)
6142               (not (gnus-data-unread-p (car arts))))
6143       (setq arts (cdr arts)))
6144     (while arts
6145       (and (or (not unread)
6146                (gnus-data-unread-p (car arts)))
6147            (vectorp (gnus-data-header (car arts)))
6148            (gnus-subject-equal
6149             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6150            (setq result (car arts)
6151                  arts nil))
6152       (setq arts (cdr arts)))
6153     (and result
6154          (goto-char (gnus-data-pos result))
6155          (gnus-data-number result))))
6156
6157 (defun gnus-summary-search-forward (&optional unread subject backward)
6158   "Search forward for an article.
6159 If UNREAD, look for unread articles.  If SUBJECT, look for
6160 articles with that subject.  If BACKWARD, search backward instead."
6161   (cond (subject (gnus-summary-find-subject subject unread backward))
6162         (backward (gnus-summary-find-prev unread))
6163         (t (gnus-summary-find-next unread))))
6164
6165 (defun gnus-recenter (&optional n)
6166   "Center point in window and redisplay frame.
6167 Also do horizontal recentering."
6168   (interactive "P")
6169   (when (and gnus-auto-center-summary
6170              (not (eq gnus-auto-center-summary 'vertical)))
6171     (gnus-horizontal-recenter))
6172   (recenter n))
6173
6174 (defun gnus-summary-recenter ()
6175   "Center point in the summary window.
6176 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6177 displayed, no centering will be performed."
6178   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6179   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6180   (interactive)
6181   ;; The user has to want it.
6182   (when gnus-auto-center-summary
6183     (let* ((top (cond ((< (window-height) 4) 0)
6184                       ((< (window-height) 7) 1)
6185                       (t (if (numberp gnus-auto-center-summary)
6186                              gnus-auto-center-summary
6187                            2))))
6188            (height (1- (window-height)))
6189            (bottom (save-excursion (goto-char (point-max))
6190                                    (forward-line (- height))
6191                                    (point)))
6192            (window (get-buffer-window (current-buffer))))
6193       (when (get-buffer-window gnus-article-buffer)
6194         ;; Only do recentering when the article buffer is displayed,
6195         ;; Set the window start to either `bottom', which is the biggest
6196         ;; possible valid number, or the second line from the top,
6197         ;; whichever is the least.
6198         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6199           (if (> bottom top-pos)
6200               ;; Keep the second line from the top visible
6201               (set-window-start window top-pos t)
6202             ;; Try to keep the bottom line visible; if it's partially
6203             ;; obscured, either scroll one more line to make it fully
6204             ;; visible, or revert to using TOP-POS.
6205             (save-excursion
6206               (goto-char (point-max))
6207               (forward-line -1)
6208               (let ((last-line-start (point)))
6209                 (goto-char bottom)
6210                 (set-window-start window (point) t)
6211                 (when (not (pos-visible-in-window-p last-line-start window))
6212                   (forward-line 1)
6213                   (set-window-start window (min (point) top-pos) t)))))))
6214       ;; Do horizontal recentering while we're at it.
6215       (when (and (get-buffer-window (current-buffer) t)
6216                  (not (eq gnus-auto-center-summary 'vertical)))
6217         (let ((selected (selected-window)))
6218           (select-window (get-buffer-window (current-buffer) t))
6219           (gnus-summary-position-point)
6220           (gnus-horizontal-recenter)
6221           (select-window selected))))))
6222
6223 (defun gnus-summary-jump-to-group (newsgroup)
6224   "Move point to NEWSGROUP in group mode buffer."
6225   ;; Keep update point of group mode buffer if visible.
6226   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6227       (save-window-excursion
6228         ;; Take care of tree window mode.
6229         (when (get-buffer-window gnus-group-buffer)
6230           (pop-to-buffer gnus-group-buffer))
6231         (gnus-group-jump-to-group newsgroup))
6232     (save-excursion
6233       ;; Take care of tree window mode.
6234       (if (get-buffer-window gnus-group-buffer)
6235           (pop-to-buffer gnus-group-buffer)
6236         (set-buffer gnus-group-buffer))
6237       (gnus-group-jump-to-group newsgroup))))
6238
6239 ;; This function returns a list of article numbers based on the
6240 ;; difference between the ranges of read articles in this group and
6241 ;; the range of active articles.
6242 (defun gnus-list-of-unread-articles (group)
6243   (let* ((read (gnus-info-read (gnus-get-info group)))
6244          (active (or (gnus-active group) (gnus-activate-group group)))
6245          (last (cdr active))
6246          first nlast unread)
6247     ;; If none are read, then all are unread.
6248     (if (not read)
6249         (setq first (car active))
6250       ;; If the range of read articles is a single range, then the
6251       ;; first unread article is the article after the last read
6252       ;; article.  Sounds logical, doesn't it?
6253       (if (and (not (listp (cdr read)))
6254                (or (< (car read) (car active))
6255                    (progn (setq read (list read))
6256                           nil)))
6257           (setq first (max (car active) (1+ (cdr read))))
6258         ;; `read' is a list of ranges.
6259         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6260                                   (caar read)))
6261                   1)
6262           (setq first (car active)))
6263         (while read
6264           (when first
6265             (while (< first nlast)
6266               (push first unread)
6267               (setq first (1+ first))))
6268           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6269           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6270           (setq read (cdr read)))))
6271     ;; And add the last unread articles.
6272     (while (<= first last)
6273       (push first unread)
6274       (setq first (1+ first)))
6275     ;; Return the list of unread articles.
6276     (delq 0 (nreverse unread))))
6277
6278 (defun gnus-list-of-read-articles (group)
6279   "Return a list of unread, unticked and non-dormant articles."
6280   (let* ((info (gnus-get-info group))
6281          (marked (gnus-info-marks info))
6282          (active (gnus-active group)))
6283     (and info active
6284          (gnus-list-range-difference
6285           (gnus-list-range-difference
6286            (gnus-sorted-complement
6287             (gnus-uncompress-range active)
6288             (gnus-list-of-unread-articles group))
6289            (cdr (assq 'dormant marked)))
6290           (cdr (assq 'tick marked))))))
6291
6292 ;; Various summary commands
6293
6294 (defun gnus-summary-select-article-buffer ()
6295   "Reconfigure windows to show article buffer."
6296   (interactive)
6297   (if (not (gnus-buffer-live-p gnus-article-buffer))
6298       (error "There is no article buffer for this summary buffer")
6299     (gnus-configure-windows 'article)
6300     (select-window (get-buffer-window gnus-article-buffer))))
6301
6302 (defun gnus-summary-universal-argument (arg)
6303   "Perform any operation on all articles that are process/prefixed."
6304   (interactive "P")
6305   (let ((articles (gnus-summary-work-articles arg))
6306         func article)
6307     (if (eq
6308          (setq
6309           func
6310           (key-binding
6311            (read-key-sequence
6312             (substitute-command-keys
6313              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6314          'undefined)
6315         (gnus-error 1 "Undefined key")
6316       (save-excursion
6317         (while articles
6318           (gnus-summary-goto-subject (setq article (pop articles)))
6319           (let (gnus-newsgroup-processable)
6320             (command-execute func))
6321           (gnus-summary-remove-process-mark article)))))
6322   (gnus-summary-position-point))
6323
6324 (defun gnus-summary-toggle-truncation (&optional arg)
6325   "Toggle truncation of summary lines.
6326 With arg, turn line truncation on if arg is positive."
6327   (interactive "P")
6328   (setq truncate-lines
6329         (if (null arg) (not truncate-lines)
6330           (> (prefix-numeric-value arg) 0)))
6331   (redraw-display))
6332
6333 (defun gnus-summary-find-for-reselect ()
6334   "Return the number of an article to stay on across a reselect.
6335 The current article is considered, then following articles, then previous
6336 articles.  An article is sought which is not cancelled and isn't a temporary
6337 insertion from another group.  If there's no such then return a dummy 0."
6338   (let (found)
6339     (dolist (rev '(nil t))
6340       (unless found      ; don't demand the reverse list if we don't need it
6341         (let ((data (gnus-data-find-list
6342                      (gnus-summary-article-number) (gnus-data-list rev))))
6343           (while (and data (not found))
6344             (if (and (< 0 (gnus-data-number (car data)))
6345                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6346                 (setq found (gnus-data-number (car data))))
6347             (setq data (cdr data))))))
6348     (or found 0)))
6349
6350 (defun gnus-summary-reselect-current-group (&optional all rescan)
6351   "Exit and then reselect the current newsgroup.
6352 The prefix argument ALL means to select all articles."
6353   (interactive "P")
6354   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6355     (error "Ephemeral groups can't be reselected"))
6356   (let ((current-subject (gnus-summary-find-for-reselect))
6357         (group gnus-newsgroup-name))
6358     (setq gnus-newsgroup-begin nil)
6359     (gnus-summary-exit)
6360     ;; We have to adjust the point of group mode buffer because
6361     ;; point was moved to the next unread newsgroup by exiting.
6362     (gnus-summary-jump-to-group group)
6363     (when rescan
6364       (save-excursion
6365         (save-window-excursion
6366           ;; Don't show group contents.
6367           (set-window-start (selected-window) (point-max))
6368           (gnus-group-get-new-news-this-group 1))))
6369     (gnus-group-read-group all t)
6370     (gnus-summary-goto-subject current-subject nil t)))
6371
6372 (defun gnus-summary-rescan-group (&optional all)
6373   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6374   (interactive "P")
6375   (gnus-summary-reselect-current-group all t))
6376
6377 (defun gnus-summary-update-info (&optional non-destructive)
6378   (save-excursion
6379     (let ((group gnus-newsgroup-name))
6380       (when group
6381         (when gnus-newsgroup-kill-headers
6382           (setq gnus-newsgroup-killed
6383                 (gnus-compress-sequence
6384                  (gnus-sorted-union
6385                   (gnus-list-range-intersection
6386                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6387                   gnus-newsgroup-unreads)
6388                  t)))
6389         (unless (listp (cdr gnus-newsgroup-killed))
6390           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6391         (let ((headers gnus-newsgroup-headers))
6392           ;; Set the new ranges of read articles.
6393           (save-excursion
6394             (set-buffer gnus-group-buffer)
6395             (gnus-undo-force-boundary))
6396           (gnus-update-read-articles
6397            group (gnus-sorted-union
6398                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6399           ;; Set the current article marks.
6400           (let ((gnus-newsgroup-scored
6401                  (if (and (not gnus-save-score)
6402                           (not non-destructive))
6403                      nil
6404                    gnus-newsgroup-scored)))
6405             (save-excursion
6406               (gnus-update-marks)))
6407           ;; Do the cross-ref thing.
6408           (when gnus-use-cross-reference
6409             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6410           ;; Do not switch windows but change the buffer to work.
6411           (set-buffer gnus-group-buffer)
6412           (unless (gnus-ephemeral-group-p group)
6413             (gnus-group-update-group group)))))))
6414
6415 (defun gnus-summary-save-newsrc (&optional force)
6416   "Save the current number of read/marked articles in the dribble buffer.
6417 The dribble buffer will then be saved.
6418 If FORCE (the prefix), also save the .newsrc file(s)."
6419   (interactive "P")
6420   (gnus-summary-update-info t)
6421   (if force
6422       (gnus-save-newsrc-file)
6423     (gnus-dribble-save)))
6424
6425 (defun gnus-summary-exit (&optional temporary)
6426   "Exit reading current newsgroup, and then return to group selection mode.
6427 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6428   (interactive)
6429   (gnus-set-global-variables)
6430   (gnus-kill-save-kill-buffer)
6431   (gnus-async-halt-prefetch)
6432   (let* ((group gnus-newsgroup-name)
6433          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6434          (gnus-group-is-exiting-p t)
6435          (mode major-mode)
6436          (group-point nil)
6437          (buf (current-buffer)))
6438     (unless quit-config
6439       ;; Do adaptive scoring, and possibly save score files.
6440       (when gnus-newsgroup-adaptive
6441         (gnus-score-adaptive))
6442       (when gnus-use-scoring
6443         (gnus-score-save)))
6444     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6445     ;; If we have several article buffers, we kill them at exit.
6446     (unless gnus-single-article-buffer
6447       (gnus-kill-buffer gnus-original-article-buffer)
6448       (setq gnus-article-current nil))
6449     (when gnus-use-cache
6450       (gnus-cache-possibly-remove-articles)
6451       (gnus-cache-save-buffers))
6452     (gnus-async-prefetch-remove-group group)
6453     (when gnus-suppress-duplicates
6454       (gnus-dup-enter-articles))
6455     (when gnus-use-trees
6456       (gnus-tree-close group))
6457     (when gnus-use-cache
6458       (gnus-cache-write-active))
6459     ;; Remove entries for this group.
6460     (nnmail-purge-split-history (gnus-group-real-name group))
6461     ;; Make all changes in this group permanent.
6462     (unless quit-config
6463       (gnus-run-hooks 'gnus-exit-group-hook)
6464       (gnus-summary-update-info))
6465     (gnus-close-group group)
6466     ;; Make sure where we were, and go to next newsgroup.
6467     (set-buffer gnus-group-buffer)
6468     (unless quit-config
6469       (gnus-group-jump-to-group group))
6470     (gnus-run-hooks 'gnus-summary-exit-hook)
6471     (unless (or quit-config
6472                 ;; If this group has disappeared from the summary
6473                 ;; buffer, don't skip forwards.
6474                 (not (string= group (gnus-group-group-name))))
6475       (gnus-group-next-unread-group 1))
6476     (setq group-point (point))
6477     (if temporary
6478         nil                             ;Nothing to do.
6479       ;; If we have several article buffers, we kill them at exit.
6480       (unless gnus-single-article-buffer
6481         (gnus-kill-buffer gnus-article-buffer)
6482         (gnus-kill-buffer gnus-original-article-buffer)
6483         (setq gnus-article-current nil))
6484       (set-buffer buf)
6485       (if (not gnus-kill-summary-on-exit)
6486           (progn
6487             (gnus-deaden-summary)
6488             (setq mode nil))
6489         ;; We set all buffer-local variables to nil.  It is unclear why
6490         ;; this is needed, but if we don't, buffer-local variables are
6491         ;; not garbage-collected, it seems.  This would the lead to en
6492         ;; ever-growing Emacs.
6493         (gnus-summary-clear-local-variables)
6494         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6495           (gnus-summary-clear-local-variables))
6496         (when (get-buffer gnus-article-buffer)
6497           (bury-buffer gnus-article-buffer))
6498         ;; We clear the global counterparts of the buffer-local
6499         ;; variables as well, just to be on the safe side.
6500         (set-buffer gnus-group-buffer)
6501         (gnus-summary-clear-local-variables)
6502         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6503           (gnus-summary-clear-local-variables))
6504         ;; Return to group mode buffer.
6505         (when (eq mode 'gnus-summary-mode)
6506           (gnus-kill-buffer buf)))
6507       (setq gnus-current-select-method gnus-select-method)
6508       (pop-to-buffer gnus-group-buffer)
6509       (if (not quit-config)
6510           (progn
6511             (goto-char group-point)
6512             (gnus-configure-windows 'group 'force)
6513             (unless (pos-visible-in-window-p)
6514               (forward-line (/ (static-if (featurep 'xemacs)
6515                                    (window-displayed-height)
6516                                  (1- (window-height)))
6517                                -2))
6518               (set-window-start (selected-window) (point))
6519               (goto-char group-point)))
6520         (gnus-handle-ephemeral-exit quit-config))
6521       ;; Clear the current group name.
6522       (unless quit-config
6523         (setq gnus-newsgroup-name nil)))))
6524
6525 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6526 (defun gnus-summary-exit-no-update (&optional no-questions)
6527   "Quit reading current newsgroup without updating read article info."
6528   (interactive)
6529   (let* ((group gnus-newsgroup-name)
6530          (gnus-group-is-exiting-p t)
6531          (gnus-group-is-exiting-without-update-p t)
6532          (quit-config (gnus-group-quit-config group)))
6533     (when (or no-questions
6534               gnus-expert-user
6535               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6536       (gnus-async-halt-prefetch)
6537       (run-hooks 'gnus-summary-prepare-exit-hook)
6538       ;; If we have several article buffers, we kill them at exit.
6539       (unless gnus-single-article-buffer
6540         (gnus-kill-buffer gnus-article-buffer)
6541         (gnus-kill-buffer gnus-original-article-buffer)
6542         (setq gnus-article-current nil))
6543       (if (not gnus-kill-summary-on-exit)
6544           (gnus-deaden-summary)
6545         (gnus-close-group group)
6546         (gnus-summary-clear-local-variables)
6547         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6548           (gnus-summary-clear-local-variables))
6549         (set-buffer gnus-group-buffer)
6550         (gnus-summary-clear-local-variables)
6551         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6552           (gnus-summary-clear-local-variables))
6553         (gnus-kill-buffer gnus-summary-buffer))
6554       (unless gnus-single-article-buffer
6555         (setq gnus-article-current nil))
6556       (when gnus-use-trees
6557         (gnus-tree-close group))
6558       (gnus-async-prefetch-remove-group group)
6559       (when (get-buffer gnus-article-buffer)
6560         (bury-buffer gnus-article-buffer))
6561       ;; Return to the group buffer.
6562       (gnus-configure-windows 'group 'force)
6563       ;; Clear the current group name.
6564       (setq gnus-newsgroup-name nil)
6565       (unless (gnus-ephemeral-group-p group)
6566         (gnus-group-update-group group))
6567       (when (equal (gnus-group-group-name) group)
6568         (gnus-group-next-unread-group 1))
6569       (when quit-config
6570         (gnus-handle-ephemeral-exit quit-config)))))
6571
6572 (defun gnus-handle-ephemeral-exit (quit-config)
6573   "Handle movement when leaving an ephemeral group.
6574 The state which existed when entering the ephemeral is reset."
6575   (if (not (buffer-name (car quit-config)))
6576       (gnus-configure-windows 'group 'force)
6577     (set-buffer (car quit-config))
6578     (cond ((eq major-mode 'gnus-summary-mode)
6579            (gnus-set-global-variables))
6580           ((eq major-mode 'gnus-article-mode)
6581            (save-excursion
6582              ;; The `gnus-summary-buffer' variable may point
6583              ;; to the old summary buffer when using a single
6584              ;; article buffer.
6585              (unless (gnus-buffer-live-p gnus-summary-buffer)
6586                (set-buffer gnus-group-buffer))
6587              (set-buffer gnus-summary-buffer)
6588              (gnus-set-global-variables))))
6589     (if (or (eq (cdr quit-config) 'article)
6590             (eq (cdr quit-config) 'pick))
6591         (progn
6592           ;; The current article may be from the ephemeral group
6593           ;; thus it is best that we reload this article
6594           (gnus-summary-show-article)
6595           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6596               (gnus-configure-windows 'pick 'force)
6597             (gnus-configure-windows (cdr quit-config) 'force)))
6598       (gnus-configure-windows (cdr quit-config) 'force))
6599     (when (eq major-mode 'gnus-summary-mode)
6600       (gnus-summary-next-subject 1 nil t)
6601       (gnus-summary-recenter)
6602       (gnus-summary-position-point))))
6603
6604 (defun gnus-summary-preview-mime-message ()
6605   "MIME decode and play this message."
6606   (interactive)
6607   (let ((gnus-break-pages nil)
6608         (gnus-show-mime t))
6609     (gnus-summary-select-article gnus-show-all-headers t))
6610   (let ((w (get-buffer-window gnus-article-buffer)))
6611     (when w
6612       (select-window (get-buffer-window gnus-article-buffer)))))
6613
6614 ;;; Dead summaries.
6615
6616 (defvar gnus-dead-summary-mode-map nil)
6617
6618 (unless gnus-dead-summary-mode-map
6619   (setq gnus-dead-summary-mode-map (make-keymap))
6620   (suppress-keymap gnus-dead-summary-mode-map)
6621   (substitute-key-definition
6622    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6623   (dolist (key '("\C-d" "\r" "\177" [delete]))
6624     (define-key gnus-dead-summary-mode-map
6625       key 'gnus-summary-wake-up-the-dead))
6626   (dolist (key '("q" "Q"))
6627     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6628
6629 (defvar gnus-dead-summary-mode nil
6630   "Minor mode for Gnus summary buffers.")
6631
6632 (defun gnus-dead-summary-mode (&optional arg)
6633   "Minor mode for Gnus summary buffers."
6634   (interactive "P")
6635   (when (eq major-mode 'gnus-summary-mode)
6636     (make-local-variable 'gnus-dead-summary-mode)
6637     (setq gnus-dead-summary-mode
6638           (if (null arg) (not gnus-dead-summary-mode)
6639             (> (prefix-numeric-value arg) 0)))
6640     (when gnus-dead-summary-mode
6641       (gnus-add-minor-mode
6642        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6643
6644 (defun gnus-deaden-summary ()
6645   "Make the current summary buffer into a dead summary buffer."
6646   ;; Kill any previous dead summary buffer.
6647   (when (and gnus-dead-summary
6648              (buffer-name gnus-dead-summary))
6649     (save-excursion
6650       (set-buffer gnus-dead-summary)
6651       (when gnus-dead-summary-mode
6652         (kill-buffer (current-buffer)))))
6653   ;; Make this the current dead summary.
6654   (setq gnus-dead-summary (current-buffer))
6655   (gnus-dead-summary-mode 1)
6656   (let ((name (buffer-name)))
6657     (when (string-match "Summary" name)
6658       (rename-buffer
6659        (concat (substring name 0 (match-beginning 0)) "Dead "
6660                (substring name (match-beginning 0)))
6661        t)
6662       (bury-buffer))))
6663
6664 (defun gnus-kill-or-deaden-summary (buffer)
6665   "Kill or deaden the summary BUFFER."
6666   (save-excursion
6667     (when (and (buffer-name buffer)
6668                (not gnus-single-article-buffer))
6669       (save-excursion
6670         (set-buffer buffer)
6671         (gnus-kill-buffer gnus-article-buffer)
6672         (gnus-kill-buffer gnus-original-article-buffer)))
6673     (cond
6674      ;; Kill the buffer.
6675      (gnus-kill-summary-on-exit
6676       (when (and gnus-use-trees
6677                  (gnus-buffer-exists-p buffer))
6678         (save-excursion
6679           (set-buffer buffer)
6680           (gnus-tree-close gnus-newsgroup-name)))
6681       (gnus-kill-buffer buffer))
6682      ;; Deaden the buffer.
6683      ((gnus-buffer-exists-p buffer)
6684       (save-excursion
6685         (set-buffer buffer)
6686         (gnus-deaden-summary))))))
6687
6688 (defun gnus-summary-wake-up-the-dead (&rest args)
6689   "Wake up the dead summary buffer."
6690   (interactive)
6691   (gnus-dead-summary-mode -1)
6692   (let ((name (buffer-name)))
6693     (when (string-match "Dead " name)
6694       (rename-buffer
6695        (concat (substring name 0 (match-beginning 0))
6696                (substring name (match-end 0)))
6697        t)))
6698   (gnus-message 3 "This dead summary is now alive again"))
6699
6700 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6701 (defun gnus-summary-fetch-faq (&optional faq-dir)
6702   "Fetch the FAQ for the current group.
6703 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6704 in."
6705   (interactive
6706    (list
6707     (when current-prefix-arg
6708       (completing-read
6709        "FAQ dir: " (and (listp gnus-group-faq-directory)
6710                         (mapcar (lambda (file) (list file))
6711                                 gnus-group-faq-directory))))))
6712   (let (gnus-faq-buffer)
6713     (when (setq gnus-faq-buffer
6714                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6715       (gnus-configure-windows 'summary-faq))))
6716
6717 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6718 (defun gnus-summary-describe-group (&optional force)
6719   "Describe the current newsgroup."
6720   (interactive "P")
6721   (gnus-group-describe-group force gnus-newsgroup-name))
6722
6723 (defun gnus-summary-describe-briefly ()
6724   "Describe summary mode commands briefly."
6725   (interactive)
6726   (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")))
6727
6728 ;; Walking around group mode buffer from summary mode.
6729
6730 (defun gnus-summary-next-group (&optional no-article target-group backward)
6731   "Exit current newsgroup and then select next unread newsgroup.
6732 If prefix argument NO-ARTICLE is non-nil, no article is selected
6733 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6734 previous group instead."
6735   (interactive "P")
6736   ;; Stop pre-fetching.
6737   (gnus-async-halt-prefetch)
6738   (let ((current-group gnus-newsgroup-name)
6739         (current-buffer (current-buffer))
6740         entered)
6741     ;; First we semi-exit this group to update Xrefs and all variables.
6742     ;; We can't do a real exit, because the window conf must remain
6743     ;; the same in case the user is prompted for info, and we don't
6744     ;; want the window conf to change before that...
6745     (gnus-summary-exit t)
6746     (while (not entered)
6747       ;; Then we find what group we are supposed to enter.
6748       (set-buffer gnus-group-buffer)
6749       (gnus-group-jump-to-group current-group)
6750       (setq target-group
6751             (or target-group
6752                 (if (eq gnus-keep-same-level 'best)
6753                     (gnus-summary-best-group gnus-newsgroup-name)
6754                   (gnus-summary-search-group backward gnus-keep-same-level))))
6755       (if (not target-group)
6756           ;; There are no further groups, so we return to the group
6757           ;; buffer.
6758           (progn
6759             (gnus-message 5 "Returning to the group buffer")
6760             (setq entered t)
6761             (when (gnus-buffer-live-p current-buffer)
6762               (set-buffer current-buffer)
6763               (gnus-summary-exit))
6764             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6765         ;; We try to enter the target group.
6766         (gnus-group-jump-to-group target-group)
6767         (let ((unreads (gnus-group-group-unread)))
6768           (if (and (or (eq t unreads)
6769                        (and unreads (not (zerop unreads))))
6770                    (gnus-summary-read-group
6771                     target-group nil no-article
6772                     (and (buffer-name current-buffer) current-buffer)
6773                     nil backward))
6774               (setq entered t)
6775             (setq current-group target-group
6776                   target-group nil)))))))
6777
6778 (defun gnus-summary-prev-group (&optional no-article)
6779   "Exit current newsgroup and then select previous unread newsgroup.
6780 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6781   (interactive "P")
6782   (gnus-summary-next-group no-article nil t))
6783
6784 ;; Walking around summary lines.
6785
6786 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6787   "Go to the first subject satisfying any non-nil constraint.
6788 If UNREAD is non-nil, the article should be unread.
6789 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6790 If UNSEED is non-nil, the article should be unseen.
6791 Returns the article selected or nil if there are no matching articles."
6792   (interactive "P")
6793   (cond
6794    ;; Empty summary.
6795    ((null gnus-newsgroup-data)
6796     (gnus-message 3 "No articles in the group")
6797     nil)
6798    ;; Pick the first article.
6799    ((not (or unread undownloaded unseen))
6800     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6801     (gnus-data-number (car gnus-newsgroup-data)))
6802    ;; Find the first unread article.
6803    (t
6804     (let ((data gnus-newsgroup-data))
6805       (while (and data
6806                   (let ((num (gnus-data-number (car data))))
6807                     (or (memq num gnus-newsgroup-unfetched)
6808                         (not (or (and unread
6809                                       (memq num gnus-newsgroup-unreads))
6810                                  (and undownloaded
6811                                       (memq num gnus-newsgroup-undownloaded))
6812                                  (and unseen
6813                                       (memq num gnus-newsgroup-unseen)))))))
6814         (setq data (cdr data)))
6815       (prog1 
6816           (if data
6817               (progn
6818                 (goto-char (gnus-data-pos (car data)))
6819                 (gnus-data-number (car data)))
6820             (gnus-message 3 "No more%s articles"
6821                           (let* ((r (when unread " unread"))
6822                                  (d (when undownloaded " undownloaded"))
6823                                  (s (when unseen " unseen"))
6824                                  (l (delq nil (list r d s))))
6825                             (cond ((= 3 (length l))
6826                                    (concat r "," d ", or" s))
6827                                   ((= 2 (length l))
6828                                    (concat (car l) ", or" (cadr l)))
6829                                   ((= 1 (length l))
6830                                    (car l))
6831                                   (t
6832                                    ""))))
6833             nil
6834             )
6835         (gnus-summary-position-point))))))
6836
6837 (defun gnus-summary-next-subject (n &optional unread dont-display)
6838   "Go to next N'th summary line.
6839 If N is negative, go to the previous N'th subject line.
6840 If UNREAD is non-nil, only unread articles are selected.
6841 The difference between N and the actual number of steps taken is
6842 returned."
6843   (interactive "p")
6844   (let ((backward (< n 0))
6845         (n (abs n)))
6846     (while (and (> n 0)
6847                 (if backward
6848                     (gnus-summary-find-prev unread)
6849                   (gnus-summary-find-next unread)))
6850       (unless (zerop (setq n (1- n)))
6851         (gnus-summary-show-thread)))
6852     (when (/= 0 n)
6853       (gnus-message 7 "No more%s articles"
6854                     (if unread " unread" "")))
6855     (unless dont-display
6856       (gnus-summary-recenter)
6857       (gnus-summary-position-point))
6858     n))
6859
6860 (defun gnus-summary-next-unread-subject (n)
6861   "Go to next N'th unread summary line."
6862   (interactive "p")
6863   (gnus-summary-next-subject n t))
6864
6865 (defun gnus-summary-prev-subject (n &optional unread)
6866   "Go to previous N'th summary line.
6867 If optional argument UNREAD is non-nil, only unread article is selected."
6868   (interactive "p")
6869   (gnus-summary-next-subject (- n) unread))
6870
6871 (defun gnus-summary-prev-unread-subject (n)
6872   "Go to previous N'th unread summary line."
6873   (interactive "p")
6874   (gnus-summary-next-subject (- n) t))
6875
6876 (defun gnus-summary-goto-subjects (articles)
6877   "Insert the subject header for ARTICLES in the current buffer."
6878   (save-excursion
6879     (dolist (article articles)
6880       (gnus-summary-goto-subject article t)))
6881   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6882   (gnus-summary-position-point))
6883  
6884 (defun gnus-summary-goto-subject (article &optional force silent)
6885   "Go the subject line of ARTICLE.
6886 If FORCE, also allow jumping to articles not currently shown."
6887   (interactive "nArticle number: ")
6888   (unless (numberp article)
6889     (error "Article %s is not a number" article))
6890   (let ((b (point))
6891         (data (gnus-data-find article)))
6892     ;; We read in the article if we have to.
6893     (and (not data)
6894          force
6895          (gnus-summary-insert-subject
6896           article
6897           (if (or (numberp force) (vectorp force)) force)
6898           t)
6899          (setq data (gnus-data-find article)))
6900     (goto-char b)
6901     (if (not data)
6902         (progn
6903           (unless silent
6904             (gnus-message 3 "Can't find article %d" article))
6905           nil)
6906       (let ((pt (gnus-data-pos data)))
6907         (goto-char pt)
6908         (gnus-summary-set-article-display-arrow pt))
6909       (gnus-summary-position-point)
6910       article)))
6911
6912 ;; Walking around summary lines with displaying articles.
6913
6914 (defun gnus-summary-expand-window (&optional arg)
6915   "Make the summary buffer take up the entire Emacs frame.
6916 Given a prefix, will force an `article' buffer configuration."
6917   (interactive "P")
6918   (if arg
6919       (gnus-configure-windows 'article 'force)
6920     (gnus-configure-windows 'summary 'force)))
6921
6922 (defun gnus-summary-display-article (article &optional all-header)
6923   "Display ARTICLE in article buffer."
6924   (when (gnus-buffer-live-p gnus-article-buffer)
6925     (with-current-buffer gnus-article-buffer
6926       (set-buffer-multibyte t)))
6927   (gnus-set-global-variables)
6928   (when (gnus-buffer-live-p gnus-article-buffer)
6929     (with-current-buffer gnus-article-buffer
6930       (setq gnus-article-charset gnus-newsgroup-charset)
6931       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6932       (set-buffer-multibyte t)))
6933   (if (null article)
6934       nil
6935     (prog1
6936         (if gnus-summary-display-article-function
6937             (funcall gnus-summary-display-article-function article all-header)
6938           (gnus-article-prepare article all-header))
6939       (with-current-buffer gnus-article-buffer
6940         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6941              nil))
6942       (gnus-run-hooks 'gnus-select-article-hook)
6943       (when (and gnus-current-article
6944                  (not (zerop gnus-current-article)))
6945         (gnus-summary-goto-subject gnus-current-article))
6946       (gnus-summary-recenter)
6947       (when (and gnus-use-trees gnus-show-threads)
6948         (gnus-possibly-generate-tree article)
6949         (gnus-highlight-selected-tree article))
6950       ;; Successfully display article.
6951       (gnus-article-set-window-start
6952        (cdr (assq article gnus-newsgroup-bookmarks))))))
6953
6954 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6955   "Select the current article.
6956 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6957 non-nil, the article will be re-fetched even if it already present in
6958 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6959 be displayed."
6960   ;; Make sure we are in the summary buffer to work around bbdb bug.
6961   (unless (eq major-mode 'gnus-summary-mode)
6962     (set-buffer gnus-summary-buffer))
6963   (let ((article (or article (gnus-summary-article-number)))
6964         (all-headers (not (not all-headers))) ;Must be T or NIL.
6965         gnus-summary-display-article-function)
6966     (and (not pseudo)
6967          (gnus-summary-article-pseudo-p article)
6968          (error "This is a pseudo-article"))
6969     (save-excursion
6970       (set-buffer gnus-summary-buffer)
6971       (if (or (and gnus-single-article-buffer
6972                    (or (null gnus-current-article)
6973                        (null gnus-article-current)
6974                        (null (get-buffer gnus-article-buffer))
6975                        (not (eq article (cdr gnus-article-current)))
6976                        (not (equal (car gnus-article-current)
6977                                    gnus-newsgroup-name))))
6978               (and (not gnus-single-article-buffer)
6979                    (or (null gnus-current-article)
6980                        (not (eq gnus-current-article article))))
6981               force)
6982           ;; The requested article is different from the current article.
6983           (progn
6984             (gnus-summary-display-article article all-headers)
6985             (gnus-article-set-window-start
6986              (cdr (assq article gnus-newsgroup-bookmarks)))
6987             article)
6988         'old))))
6989
6990 (defun gnus-summary-force-verify-and-decrypt ()
6991   "Display buttons for signed/encrypted parts and verify/decrypt them."
6992   (interactive)
6993   (let ((mm-verify-option 'known)
6994         (mm-decrypt-option 'known)
6995         (gnus-buttonized-mime-types (append (list "multipart/signed"
6996                                                   "multipart/encrypted")
6997                                             gnus-buttonized-mime-types)))
6998     (gnus-summary-select-article nil 'force)))
6999
7000 (defun gnus-summary-set-current-mark (&optional current-mark)
7001   "Obsolete function."
7002   nil)
7003
7004 (defun gnus-summary-next-article (&optional unread subject backward push)
7005   "Select the next article.
7006 If UNREAD, only unread articles are selected.
7007 If SUBJECT, only articles with SUBJECT are selected.
7008 If BACKWARD, the previous article is selected instead of the next."
7009   (interactive "P")
7010   (cond
7011    ;; Is there such an article?
7012    ((and (gnus-summary-search-forward unread subject backward)
7013          (or (gnus-summary-display-article (gnus-summary-article-number))
7014              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7015     (gnus-summary-position-point))
7016    ;; If not, we try the first unread, if that is wanted.
7017    ((and subject
7018          gnus-auto-select-same
7019          (gnus-summary-first-unread-article))
7020     (gnus-summary-position-point)
7021     (gnus-message 6 "Wrapped"))
7022    ;; Try to get next/previous article not displayed in this group.
7023    ((and gnus-auto-extend-newsgroup
7024          (not unread) (not subject))
7025     (gnus-summary-goto-article
7026      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7027      nil (count-lines (point-min) (point))))
7028    ;; Go to next/previous group.
7029    (t
7030     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7031       (gnus-summary-jump-to-group gnus-newsgroup-name))
7032     (let ((cmd last-command-char)
7033           (point
7034            (save-excursion
7035              (set-buffer gnus-group-buffer)
7036              (point)))
7037           (group
7038            (if (eq gnus-keep-same-level 'best)
7039                (gnus-summary-best-group gnus-newsgroup-name)
7040              (gnus-summary-search-group backward gnus-keep-same-level))))
7041       ;; For some reason, the group window gets selected.  We change
7042       ;; it back.
7043       (select-window (get-buffer-window (current-buffer)))
7044       ;; Select next unread newsgroup automagically.
7045       (cond
7046        ((or (not gnus-auto-select-next)
7047             (not cmd))
7048         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7049        ((or (eq gnus-auto-select-next 'quietly)
7050             (and (eq gnus-auto-select-next 'slightly-quietly)
7051                  push)
7052             (and (eq gnus-auto-select-next 'almost-quietly)
7053                  (gnus-summary-last-article-p)))
7054         ;; Select quietly.
7055         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7056             (gnus-summary-exit)
7057           (gnus-message 7 "No more%s articles (%s)..."
7058                         (if unread " unread" "")
7059                         (if group (concat "selecting " group)
7060                           "exiting"))
7061           (gnus-summary-next-group nil group backward)))
7062        (t
7063         (when (gnus-key-press-event-p last-input-event)
7064           (gnus-summary-walk-group-buffer
7065            gnus-newsgroup-name cmd unread backward point))))))))
7066
7067 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7068   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7069                       (?\C-p (gnus-group-prev-unread-group 1))))
7070         (cursor-in-echo-area t)
7071         keve key group ended prompt)
7072     (save-excursion
7073       (set-buffer gnus-group-buffer)
7074       (goto-char start)
7075       (setq group
7076             (if (eq gnus-keep-same-level 'best)
7077                 (gnus-summary-best-group gnus-newsgroup-name)
7078               (gnus-summary-search-group backward gnus-keep-same-level))))
7079     (while (not ended)
7080       (setq prompt
7081             (format
7082              "No more%s articles%s " (if unread " unread" "")
7083              (if (and group
7084                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7085                  (format " (Type %s for %s [%s])"
7086                          (single-key-description cmd) group
7087                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7088                (format " (Type %s to exit %s)"
7089                        (single-key-description cmd)
7090                        gnus-newsgroup-name))))
7091       ;; Confirm auto selection.
7092       (setq key (car (setq keve (gnus-read-event-char prompt)))
7093             ended t)
7094       (cond
7095        ((assq key keystrokes)
7096         (let ((obuf (current-buffer)))
7097           (switch-to-buffer gnus-group-buffer)
7098           (when group
7099             (gnus-group-jump-to-group group))
7100           (eval (cadr (assq key keystrokes)))
7101           (setq group (gnus-group-group-name))
7102           (switch-to-buffer obuf))
7103         (setq ended nil))
7104        ((equal key cmd)
7105         (if (or (not group)
7106                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7107             (gnus-summary-exit)
7108           (gnus-summary-next-group nil group backward)))
7109        (t
7110         (push (cdr keve) unread-command-events))))))
7111
7112 (defun gnus-summary-next-unread-article ()
7113   "Select unread article after current one."
7114   (interactive)
7115   (gnus-summary-next-article
7116    (or (not (eq gnus-summary-goto-unread 'never))
7117        (gnus-summary-last-article-p (gnus-summary-article-number)))
7118    (and gnus-auto-select-same
7119         (gnus-summary-article-subject))))
7120
7121 (defun gnus-summary-prev-article (&optional unread subject)
7122   "Select the article after the current one.
7123 If UNREAD is non-nil, only unread articles are selected."
7124   (interactive "P")
7125   (gnus-summary-next-article unread subject t))
7126
7127 (defun gnus-summary-prev-unread-article ()
7128   "Select unread article before current one."
7129   (interactive)
7130   (gnus-summary-prev-article
7131    (or (not (eq gnus-summary-goto-unread 'never))
7132        (gnus-summary-first-article-p (gnus-summary-article-number)))
7133    (and gnus-auto-select-same
7134         (gnus-summary-article-subject))))
7135
7136 (defun gnus-summary-next-page (&optional lines circular stop)
7137   "Show next page of the selected article.
7138 If at the end of the current article, select the next article.
7139 LINES says how many lines should be scrolled up.
7140
7141 If CIRCULAR is non-nil, go to the start of the article instead of
7142 selecting the next article when reaching the end of the current
7143 article.
7144
7145 If STOP is non-nil, just stop when reaching the end of the message."
7146   (interactive "P")
7147   (setq gnus-summary-buffer (current-buffer))
7148   (gnus-set-global-variables)
7149   (let ((article (gnus-summary-article-number))
7150         (article-window (get-buffer-window gnus-article-buffer t))
7151         endp)
7152     ;; If the buffer is empty, we have no article.
7153     (unless article
7154       (error "No article to select"))
7155     (gnus-configure-windows 'article)
7156     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7157         (if (and (eq gnus-summary-goto-unread 'never)
7158                  (not (gnus-summary-last-article-p article)))
7159             (gnus-summary-next-article)
7160           (gnus-summary-next-unread-article))
7161       (if (or (null gnus-current-article)
7162               (null gnus-article-current)
7163               (/= article (cdr gnus-article-current))
7164               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7165           ;; Selected subject is different from current article's.
7166           (gnus-summary-display-article article)
7167         (when article-window
7168           (gnus-eval-in-buffer-window gnus-article-buffer
7169             (setq endp (or (gnus-article-next-page lines)
7170                            (gnus-article-only-boring-p))))
7171           (when endp
7172             (cond (stop
7173                    (gnus-message 3 "End of message"))
7174                   (circular
7175                    (gnus-summary-beginning-of-article))
7176                   (lines
7177                    (gnus-message 3 "End of message"))
7178                   ((null lines)
7179                    (if (and (eq gnus-summary-goto-unread 'never)
7180                             (not (gnus-summary-last-article-p article)))
7181                        (gnus-summary-next-article)
7182                      (gnus-summary-next-unread-article))))))))
7183     (gnus-summary-recenter)
7184     (gnus-summary-position-point)))
7185
7186 (defun gnus-summary-prev-page (&optional lines move)
7187   "Show previous page of selected article.
7188 Argument LINES specifies lines to be scrolled down.
7189 If MOVE, move to the previous unread article if point is at
7190 the beginning of the buffer."
7191   (interactive "P")
7192   (let ((article (gnus-summary-article-number))
7193         (article-window (get-buffer-window gnus-article-buffer t))
7194         endp)
7195     (gnus-configure-windows 'article)
7196     (if (or (null gnus-current-article)
7197             (null gnus-article-current)
7198             (/= article (cdr gnus-article-current))
7199             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7200         ;; Selected subject is different from current article's.
7201         (gnus-summary-display-article article)
7202       (gnus-summary-recenter)
7203       (when article-window
7204         (gnus-eval-in-buffer-window gnus-article-buffer
7205           (setq endp (gnus-article-prev-page lines)))
7206         (when (and move endp)
7207           (cond (lines
7208                  (gnus-message 3 "Beginning of message"))
7209                 ((null lines)
7210                  (if (and (eq gnus-summary-goto-unread 'never)
7211                           (not (gnus-summary-first-article-p article)))
7212                      (gnus-summary-prev-article)
7213                    (gnus-summary-prev-unread-article))))))))
7214   (gnus-summary-position-point))
7215
7216 (defun gnus-summary-prev-page-or-article (&optional lines)
7217   "Show previous page of selected article.
7218 Argument LINES specifies lines to be scrolled down.
7219 If at the beginning of the article, go to the next article."
7220   (interactive "P")
7221   (gnus-summary-prev-page lines t))
7222
7223 (defun gnus-summary-scroll-up (lines)
7224   "Scroll up (or down) one line current article.
7225 Argument LINES specifies lines to be scrolled up (or down if negative)."
7226   (interactive "p")
7227   (gnus-configure-windows 'article)
7228   (gnus-summary-show-thread)
7229   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7230     (gnus-eval-in-buffer-window gnus-article-buffer
7231       (cond ((> lines 0)
7232              (when (gnus-article-next-page lines)
7233                (gnus-message 3 "End of message")))
7234             ((< lines 0)
7235              (gnus-article-prev-page (- lines))))))
7236   (gnus-summary-recenter)
7237   (gnus-summary-position-point))
7238
7239 (defun gnus-summary-scroll-down (lines)
7240   "Scroll down (or up) one line current article.
7241 Argument LINES specifies lines to be scrolled down (or up if negative)."
7242   (interactive "p")
7243   (gnus-summary-scroll-up (- lines)))
7244
7245 (defun gnus-summary-next-same-subject ()
7246   "Select next article which has the same subject as current one."
7247   (interactive)
7248   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7249
7250 (defun gnus-summary-prev-same-subject ()
7251   "Select previous article which has the same subject as current one."
7252   (interactive)
7253   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7254
7255 (defun gnus-summary-next-unread-same-subject ()
7256   "Select next unread article which has the same subject as current one."
7257   (interactive)
7258   (gnus-summary-next-article t (gnus-summary-article-subject)))
7259
7260 (defun gnus-summary-prev-unread-same-subject ()
7261   "Select previous unread article which has the same subject as current one."
7262   (interactive)
7263   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7264
7265 (defun gnus-summary-first-unread-article ()
7266   "Select the first unread article.
7267 Return nil if there are no unread articles."
7268   (interactive)
7269   (prog1
7270       (when (gnus-summary-first-subject t)
7271         (gnus-summary-show-thread)
7272         (gnus-summary-first-subject t)
7273         (gnus-summary-display-article (gnus-summary-article-number)))
7274     (gnus-summary-position-point)))
7275
7276 (defun gnus-summary-first-unread-subject ()
7277   "Place the point on the subject line of the first unread article.
7278 Return nil if there are no unread articles."
7279   (interactive)
7280   (prog1
7281       (when (gnus-summary-first-subject t)
7282         (gnus-summary-show-thread)
7283         (gnus-summary-first-subject t))
7284     (gnus-summary-position-point)))
7285
7286 (defun gnus-summary-first-unseen-subject ()
7287   "Place the point on the subject line of the first unseen article.
7288 Return nil if there are no unseen articles."
7289   (interactive)
7290   (prog1
7291       (when (gnus-summary-first-subject nil nil t)
7292         (gnus-summary-show-thread)
7293         (gnus-summary-first-subject nil nil t))
7294     (gnus-summary-position-point)))
7295
7296 (defun gnus-summary-first-unseen-or-unread-subject ()
7297   "Place the point on the subject line of the first unseen article or,
7298 if all article have been seen, on the subject line of the first unread
7299 article."
7300   (interactive)
7301   (prog1
7302       (unless (when (gnus-summary-first-subject nil nil t)
7303                 (gnus-summary-show-thread)
7304                 (gnus-summary-first-subject nil nil t))
7305         (when (gnus-summary-first-subject t)
7306           (gnus-summary-show-thread)
7307           (gnus-summary-first-subject t)))
7308     (gnus-summary-position-point)))
7309
7310 (defun gnus-summary-first-article ()
7311   "Select the first article.
7312 Return nil if there are no articles."
7313   (interactive)
7314   (prog1
7315       (when (gnus-summary-first-subject)
7316         (gnus-summary-show-thread)
7317         (gnus-summary-first-subject)
7318         (gnus-summary-display-article (gnus-summary-article-number)))
7319     (gnus-summary-position-point)))
7320
7321 (defun gnus-summary-best-unread-article (&optional arg)
7322   "Select the unread article with the highest score.
7323 If given a prefix argument, select the next unread article that has a
7324 score higher than the default score."
7325   (interactive "P")
7326   (let ((article (if arg
7327                      (gnus-summary-better-unread-subject)
7328                    (gnus-summary-best-unread-subject))))
7329     (if article
7330         (gnus-summary-goto-article article)
7331       (error "No unread articles"))))
7332
7333 (defun gnus-summary-best-unread-subject ()
7334   "Select the unread subject with the highest score."
7335   (interactive)
7336   (let ((best -1000000)
7337         (data gnus-newsgroup-data)
7338         article score)
7339     (while data
7340       (and (gnus-data-unread-p (car data))
7341            (> (setq score
7342                     (gnus-summary-article-score (gnus-data-number (car data))))
7343               best)
7344            (setq best score
7345                  article (gnus-data-number (car data))))
7346       (setq data (cdr data)))
7347     (when article
7348       (gnus-summary-goto-subject article))
7349     (gnus-summary-position-point)
7350     article))
7351
7352 (defun gnus-summary-better-unread-subject ()
7353   "Select the first unread subject that has a score over the default score."
7354   (interactive)
7355   (let ((data gnus-newsgroup-data)
7356         article score)
7357     (while (and (setq article (gnus-data-number (car data)))
7358                 (or (gnus-data-read-p (car data))
7359                     (not (> (gnus-summary-article-score article)
7360                             gnus-summary-default-score))))
7361       (setq data (cdr data)))
7362     (when article
7363       (gnus-summary-goto-subject article))
7364     (gnus-summary-position-point)
7365     article))
7366
7367 (defun gnus-summary-last-subject ()
7368   "Go to the last displayed subject line in the group."
7369   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7370     (when article
7371       (gnus-summary-goto-subject article))))
7372
7373 (defun gnus-summary-goto-article (article &optional all-headers force)
7374   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7375 If ALL-HEADERS is non-nil, no header lines are hidden.
7376 If FORCE, go to the article even if it isn't displayed.  If FORCE
7377 is a number, it is the line the article is to be displayed on."
7378   (interactive
7379    (list
7380     (completing-read
7381      "Article number or Message-ID: "
7382      (mapcar (lambda (number) (list (int-to-string number)))
7383              gnus-newsgroup-limit))
7384     current-prefix-arg
7385     t))
7386   (prog1
7387       (if (and (stringp article)
7388                (string-match "@" article))
7389           (gnus-summary-refer-article article)
7390         (when (stringp article)
7391           (setq article (string-to-number article)))
7392         (if (gnus-summary-goto-subject article force)
7393             (gnus-summary-display-article article all-headers)
7394           (gnus-message 4 "Couldn't go to article %s" article) nil))
7395     (gnus-summary-position-point)))
7396
7397 (defun gnus-summary-goto-last-article ()
7398   "Go to the previously read article."
7399   (interactive)
7400   (prog1
7401       (when gnus-last-article
7402         (gnus-summary-goto-article gnus-last-article nil t))
7403     (gnus-summary-position-point)))
7404
7405 (defun gnus-summary-pop-article (number)
7406   "Pop one article off the history and go to the previous.
7407 NUMBER articles will be popped off."
7408   (interactive "p")
7409   (let (to)
7410     (setq gnus-newsgroup-history
7411           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7412     (if to
7413         (gnus-summary-goto-article (car to) nil t)
7414       (error "Article history empty")))
7415   (gnus-summary-position-point))
7416
7417 ;; Summary commands and functions for limiting the summary buffer.
7418
7419 (defun gnus-summary-limit-to-articles (n)
7420   "Limit the summary buffer to the next N articles.
7421 If not given a prefix, use the process marked articles instead."
7422   (interactive "P")
7423   (prog1
7424       (let ((articles (gnus-summary-work-articles n)))
7425         (setq gnus-newsgroup-processable nil)
7426         (gnus-summary-limit articles))
7427     (gnus-summary-position-point)))
7428
7429 (defun gnus-summary-pop-limit (&optional total)
7430   "Restore the previous limit.
7431 If given a prefix, remove all limits."
7432   (interactive "P")
7433   (when total
7434     (setq gnus-newsgroup-limits
7435           (list (mapcar (lambda (h) (mail-header-number h))
7436                         gnus-newsgroup-headers))))
7437   (unless gnus-newsgroup-limits
7438     (error "No limit to pop"))
7439   (prog1
7440       (gnus-summary-limit nil 'pop)
7441     (gnus-summary-position-point)))
7442
7443 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7444   "Limit the summary buffer to articles that have subjects that match a regexp.
7445 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7446   (interactive
7447    (list (read-string (if current-prefix-arg
7448                           "Exclude subject (regexp): "
7449                         "Limit to subject (regexp): "))
7450          nil current-prefix-arg))
7451   (unless header
7452     (setq header "subject"))
7453   (when (not (equal "" subject))
7454     (prog1
7455         (let ((articles (gnus-summary-find-matching
7456                          (or header "subject") subject 'all nil nil
7457                          not-matching)))
7458           (unless articles
7459             (error "Found no matches for \"%s\"" subject))
7460           (gnus-summary-limit articles))
7461       (gnus-summary-position-point))))
7462
7463 (defun gnus-summary-limit-to-author (from &optional not-matching)
7464   "Limit the summary buffer to articles that have authors that match a regexp.
7465 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7466   (interactive
7467    (list (read-string (if current-prefix-arg
7468                           "Exclude author (regexp): "
7469                         "Limit to author (regexp): "))
7470          current-prefix-arg))
7471   (gnus-summary-limit-to-subject from "from" not-matching))
7472
7473 (defun gnus-summary-limit-to-age (age &optional younger-p)
7474   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7475 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7476 articles that are younger than AGE days."
7477   (interactive
7478    (let ((younger current-prefix-arg)
7479          (days-got nil)
7480          days)
7481      (while (not days-got)
7482        (setq days (if younger
7483                       (read-string "Limit to articles younger than (in days, older when negative): ")
7484                     (read-string
7485                      "Limit to articles older than (in days, younger when negative): ")))
7486        (when (> (length days) 0)
7487          (setq days (read days)))
7488        (if (numberp days)
7489            (progn
7490              (setq days-got t)
7491              (if (< days 0)
7492                  (progn
7493                    (setq younger (not younger))
7494                    (setq days (* days -1)))))
7495          (message "Please enter a number.")
7496          (sleep-for 1)))
7497      (list days younger)))
7498   (prog1
7499       (let ((data gnus-newsgroup-data)
7500             (cutoff (days-to-time age))
7501             articles d date is-younger)
7502         (while (setq d (pop data))
7503           (when (and (vectorp (gnus-data-header d))
7504                      (setq date (mail-header-date (gnus-data-header d))))
7505             (setq is-younger (time-less-p
7506                               (time-since (condition-case ()
7507                                               (date-to-time date)
7508                                             (error '(0 0))))
7509                               cutoff))
7510             (when (if younger-p
7511                       is-younger
7512                     (not is-younger))
7513               (push (gnus-data-number d) articles))))
7514         (gnus-summary-limit (nreverse articles)))
7515     (gnus-summary-position-point)))
7516
7517 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7518   "Limit the summary buffer to articles that match an 'extra' header."
7519   (interactive
7520    (let ((header
7521           (intern
7522            (gnus-completing-read-with-default
7523             (symbol-name (car gnus-extra-headers))
7524             (if current-prefix-arg
7525                 "Exclude extra header:"
7526               "Limit extra header:")
7527             (mapcar (lambda (x)
7528                       (cons (symbol-name x) x))
7529                     gnus-extra-headers)
7530             nil
7531             t))))
7532      (list header
7533            (read-string (format "%s header %s (regexp): "
7534                                 (if current-prefix-arg "Exclude" "Limit to")
7535                                 header))
7536            current-prefix-arg)))
7537   (when (not (equal "" regexp))
7538     (prog1
7539         (let ((articles (gnus-summary-find-matching
7540                          (cons 'extra header) regexp 'all nil nil
7541                          not-matching)))
7542           (unless articles
7543             (error "Found no matches for \"%s\"" regexp))
7544           (gnus-summary-limit articles))
7545       (gnus-summary-position-point))))
7546
7547 (defun gnus-summary-limit-to-display-predicate ()
7548   "Limit the summary buffer to the predicated in the `display' group parameter."
7549   (interactive)
7550   (unless gnus-newsgroup-display
7551     (error "There is no `display' group parameter"))
7552   (let (articles)
7553     (dolist (number gnus-newsgroup-articles)
7554       (when (funcall gnus-newsgroup-display)
7555         (push number articles)))
7556     (gnus-summary-limit articles))
7557   (gnus-summary-position-point))
7558
7559 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7560 (make-obsolete
7561  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7562
7563 (defun gnus-summary-limit-to-unread (&optional all)
7564   "Limit the summary buffer to articles that are not marked as read.
7565 If ALL is non-nil, limit strictly to unread articles."
7566   (interactive "P")
7567   (if all
7568       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7569     (gnus-summary-limit-to-marks
7570      ;; Concat all the marks that say that an article is read and have
7571      ;; those removed.
7572      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7573            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7574            gnus-low-score-mark gnus-expirable-mark
7575            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7576            gnus-duplicate-mark gnus-souped-mark)
7577      'reverse)))
7578
7579 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7580 (make-obsolete 'gnus-summary-delete-marked-with
7581                'gnus-summary-limit-exclude-marks)
7582
7583 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7584   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7585 If REVERSE, limit the summary buffer to articles that are marked
7586 with MARKS.  MARKS can either be a string of marks or a list of marks.
7587 Returns how many articles were removed."
7588   (interactive "sMarks: ")
7589   (gnus-summary-limit-to-marks marks t))
7590
7591 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7592   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7593 If REVERSE (the prefix), limit the summary buffer to articles that are
7594 not marked with MARKS.  MARKS can either be a string of marks or a
7595 list of marks.
7596 Returns how many articles were removed."
7597   (interactive "sMarks: \nP")
7598   (prog1
7599       (let ((data gnus-newsgroup-data)
7600             (marks (if (listp marks) marks
7601                      (append marks nil))) ; Transform to list.
7602             articles)
7603         (while data
7604           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7605                   (memq (gnus-data-mark (car data)) marks))
7606             (push (gnus-data-number (car data)) articles))
7607           (setq data (cdr data)))
7608         (gnus-summary-limit articles))
7609     (gnus-summary-position-point)))
7610
7611 (defun gnus-summary-limit-to-score (score)
7612   "Limit to articles with score at or above SCORE."
7613   (interactive "NLimit to articles with score of at least: ")
7614   (let ((data gnus-newsgroup-data)
7615         articles)
7616     (while data
7617       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7618                 score)
7619         (push (gnus-data-number (car data)) articles))
7620       (setq data (cdr data)))
7621     (prog1
7622         (gnus-summary-limit articles)
7623       (gnus-summary-position-point))))
7624
7625 (defun gnus-summary-limit-to-unseen ()
7626   "Limit to unseen articles."
7627   (interactive)
7628   (prog1
7629       (gnus-summary-limit gnus-newsgroup-unseen)
7630     (gnus-summary-position-point)))
7631
7632 (defun gnus-summary-limit-include-thread (id)
7633   "Display all the hidden articles that is in the thread with ID in it.
7634 When called interactively, ID is the Message-ID of the current
7635 article."
7636   (interactive (list (mail-header-id (gnus-summary-article-header))))
7637   (let ((articles (gnus-articles-in-thread
7638                    (gnus-id-to-thread (gnus-root-id id)))))
7639     (prog1
7640         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7641       (gnus-summary-limit-include-matching-articles
7642        "subject"
7643        (regexp-quote (gnus-simplify-subject-re
7644                       (mail-header-subject (gnus-id-to-header id)))))
7645       (gnus-summary-position-point))))
7646
7647 (defun gnus-summary-limit-include-matching-articles (header regexp)
7648   "Display all the hidden articles that have HEADERs that match REGEXP."
7649   (interactive (list (read-string "Match on header: ")
7650                      (read-string "Regexp: ")))
7651   (let ((articles (gnus-find-matching-articles header regexp)))
7652     (prog1
7653         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7654       (gnus-summary-position-point))))
7655
7656 (defun gnus-summary-insert-dormant-articles ()
7657   "Insert all the dormat articles for this group into the current buffer."
7658   (interactive)
7659   (let ((gnus-verbose (max 6 gnus-verbose)))
7660     (if (not gnus-newsgroup-dormant)
7661         (gnus-message 3 "No cached articles for this group")
7662       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7663
7664 (defun gnus-summary-limit-include-dormant ()
7665   "Display all the hidden articles that are marked as dormant.
7666 Note that this command only works on a subset of the articles currently
7667 fetched for this group."
7668   (interactive)
7669   (unless gnus-newsgroup-dormant
7670     (error "There are no dormant articles in this group"))
7671   (prog1
7672       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7673     (gnus-summary-position-point)))
7674
7675 (defun gnus-summary-limit-exclude-dormant ()
7676   "Hide all dormant articles."
7677   (interactive)
7678   (prog1
7679       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7680     (gnus-summary-position-point)))
7681
7682 (defun gnus-summary-limit-exclude-childless-dormant ()
7683   "Hide all dormant articles that have no children."
7684   (interactive)
7685   (let ((data (gnus-data-list t))
7686         articles d children)
7687     ;; Find all articles that are either not dormant or have
7688     ;; children.
7689     (while (setq d (pop data))
7690       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7691                 (and (setq children
7692                            (gnus-article-children (gnus-data-number d)))
7693                      (let (found)
7694                        (while children
7695                          (when (memq (car children) articles)
7696                            (setq children nil
7697                                  found t))
7698                          (pop children))
7699                        found)))
7700         (push (gnus-data-number d) articles)))
7701     ;; Do the limiting.
7702     (prog1
7703         (gnus-summary-limit articles)
7704       (gnus-summary-position-point))))
7705
7706 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7707   "Mark all unread excluded articles as read.
7708 If ALL, mark even excluded ticked and dormants as read."
7709   (interactive "P")
7710   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7711   (let ((articles (gnus-sorted-ndifference
7712                    (sort
7713                     (mapcar (lambda (h) (mail-header-number h))
7714                             gnus-newsgroup-headers)
7715                     '<)
7716                    gnus-newsgroup-limit))
7717         article)
7718     (setq gnus-newsgroup-unreads
7719           (gnus-sorted-intersection gnus-newsgroup-unreads
7720                                     gnus-newsgroup-limit))
7721     (if all
7722         (setq gnus-newsgroup-dormant nil
7723               gnus-newsgroup-marked nil
7724               gnus-newsgroup-reads
7725               (nconc
7726                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7727                gnus-newsgroup-reads))
7728       (while (setq article (pop articles))
7729         (unless (or (memq article gnus-newsgroup-dormant)
7730                     (memq article gnus-newsgroup-marked))
7731           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7732
7733 (defun gnus-summary-limit (articles &optional pop)
7734   (if pop
7735       ;; We pop the previous limit off the stack and use that.
7736       (setq articles (car gnus-newsgroup-limits)
7737             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7738     ;; We use the new limit, so we push the old limit on the stack.
7739     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7740   ;; Set the limit.
7741   (setq gnus-newsgroup-limit articles)
7742   (let ((total (length gnus-newsgroup-data))
7743         (data (gnus-data-find-list (gnus-summary-article-number)))
7744         (gnus-summary-mark-below nil)   ; Inhibit this.
7745         found)
7746     ;; This will do all the work of generating the new summary buffer
7747     ;; according to the new limit.
7748     (gnus-summary-prepare)
7749     ;; Hide any threads, possibly.
7750     (gnus-summary-maybe-hide-threads)
7751     ;; Try to return to the article you were at, or one in the
7752     ;; neighborhood.
7753     (when data
7754       ;; We try to find some article after the current one.
7755       (while data
7756         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7757           (setq data nil
7758                 found t))
7759         (setq data (cdr data))))
7760     (unless found
7761       ;; If there is no data, that means that we were after the last
7762       ;; article.  The same goes when we can't find any articles
7763       ;; after the current one.
7764       (goto-char (point-max))
7765       (gnus-summary-find-prev))
7766     (gnus-set-mode-line 'summary)
7767     ;; We return how many articles were removed from the summary
7768     ;; buffer as a result of the new limit.
7769     (- total (length gnus-newsgroup-data))))
7770
7771 (defsubst gnus-invisible-cut-children (threads)
7772   (let ((num 0))
7773     (while threads
7774       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7775         (incf num))
7776       (pop threads))
7777     (< num 2)))
7778
7779 (defsubst gnus-cut-thread (thread)
7780   "Go forwards in the thread until we find an article that we want to display."
7781   (when (or (eq gnus-fetch-old-headers 'some)
7782             (eq gnus-fetch-old-headers 'invisible)
7783             (numberp gnus-fetch-old-headers)
7784             (eq gnus-build-sparse-threads 'some)
7785             (eq gnus-build-sparse-threads 'more))
7786     ;; Deal with old-fetched headers and sparse threads.
7787     (while (and
7788             thread
7789             (or
7790              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7791              (gnus-summary-article-ancient-p
7792               (mail-header-number (car thread))))
7793             (if (or (<= (length (cdr thread)) 1)
7794                     (eq gnus-fetch-old-headers 'invisible))
7795                 (setq gnus-newsgroup-limit
7796                       (delq (mail-header-number (car thread))
7797                             gnus-newsgroup-limit)
7798                       thread (cadr thread))
7799               (when (gnus-invisible-cut-children (cdr thread))
7800                 (let ((th (cdr thread)))
7801                   (while th
7802                     (if (memq (mail-header-number (caar th))
7803                               gnus-newsgroup-limit)
7804                         (setq thread (car th)
7805                               th nil)
7806                       (setq th (cdr th))))))))))
7807   thread)
7808
7809 (defun gnus-cut-threads (threads)
7810   "Cut off all uninteresting articles from the beginning of threads."
7811   (when (or (eq gnus-fetch-old-headers 'some)
7812             (eq gnus-fetch-old-headers 'invisible)
7813             (numberp gnus-fetch-old-headers)
7814             (eq gnus-build-sparse-threads 'some)
7815             (eq gnus-build-sparse-threads 'more))
7816     (let ((th threads))
7817       (while th
7818         (setcar th (gnus-cut-thread (car th)))
7819         (setq th (cdr th)))))
7820   ;; Remove nixed out threads.
7821   (delq nil threads))
7822
7823 (defun gnus-summary-initial-limit (&optional show-if-empty)
7824   "Figure out what the initial limit is supposed to be on group entry.
7825 This entails weeding out unwanted dormants, low-scored articles,
7826 fetch-old-headers verbiage, and so on."
7827   ;; Most groups have nothing to remove.
7828   (if (or gnus-inhibit-limiting
7829           (and (null gnus-newsgroup-dormant)
7830                (eq gnus-newsgroup-display 'gnus-not-ignore)
7831                (not (eq gnus-fetch-old-headers 'some))
7832                (not (numberp gnus-fetch-old-headers))
7833                (not (eq gnus-fetch-old-headers 'invisible))
7834                (null gnus-summary-expunge-below)
7835                (not (eq gnus-build-sparse-threads 'some))
7836                (not (eq gnus-build-sparse-threads 'more))
7837                (null gnus-thread-expunge-below)
7838                (not gnus-use-nocem)))
7839       ()                                ; Do nothing.
7840     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7841     (setq gnus-newsgroup-limit nil)
7842     (mapatoms
7843      (lambda (node)
7844        (unless (car (symbol-value node))
7845          ;; These threads have no parents -- they are roots.
7846          (let ((nodes (cdr (symbol-value node)))
7847                thread)
7848            (while nodes
7849              (if (and gnus-thread-expunge-below
7850                       (< (gnus-thread-total-score (car nodes))
7851                          gnus-thread-expunge-below))
7852                  (gnus-expunge-thread (pop nodes))
7853                (setq thread (pop nodes))
7854                (gnus-summary-limit-children thread))))))
7855      gnus-newsgroup-dependencies)
7856     ;; If this limitation resulted in an empty group, we might
7857     ;; pop the previous limit and use it instead.
7858     (when (and (not gnus-newsgroup-limit)
7859                show-if-empty)
7860       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7861     gnus-newsgroup-limit))
7862
7863 (defun gnus-summary-limit-children (thread)
7864   "Return 1 if this subthread is visible and 0 if it is not."
7865   ;; First we get the number of visible children to this thread.  This
7866   ;; is done by recursing down the thread using this function, so this
7867   ;; will really go down to a leaf article first, before slowly
7868   ;; working its way up towards the root.
7869   (when thread
7870     (let* ((max-lisp-eval-depth 5000)
7871            (children
7872            (if (cdr thread)
7873                (apply '+ (mapcar 'gnus-summary-limit-children
7874                                  (cdr thread)))
7875              0))
7876           (number (mail-header-number (car thread)))
7877           score)
7878       (if (and
7879            (not (memq number gnus-newsgroup-marked))
7880            (or
7881             ;; If this article is dormant and has absolutely no visible
7882             ;; children, then this article isn't visible.
7883             (and (memq number gnus-newsgroup-dormant)
7884                  (zerop children))
7885             ;; If this is "fetch-old-headered" and there is no
7886             ;; visible children, then we don't want this article.
7887             (and (or (eq gnus-fetch-old-headers 'some)
7888                      (numberp gnus-fetch-old-headers))
7889                  (gnus-summary-article-ancient-p number)
7890                  (zerop children))
7891             ;; If this is "fetch-old-headered" and `invisible', then
7892             ;; we don't want this article.
7893             (and (eq gnus-fetch-old-headers 'invisible)
7894                  (gnus-summary-article-ancient-p number))
7895             ;; If this is a sparsely inserted article with no children,
7896             ;; we don't want it.
7897             (and (eq gnus-build-sparse-threads 'some)
7898                  (gnus-summary-article-sparse-p number)
7899                  (zerop children))
7900             ;; If we use expunging, and this article is really
7901             ;; low-scored, then we don't want this article.
7902             (when (and gnus-summary-expunge-below
7903                        (< (setq score
7904                                 (or (cdr (assq number gnus-newsgroup-scored))
7905                                     gnus-summary-default-score))
7906                           gnus-summary-expunge-below))
7907               ;; We increase the expunge-tally here, but that has
7908               ;; nothing to do with the limits, really.
7909               (incf gnus-newsgroup-expunged-tally)
7910               ;; We also mark as read here, if that's wanted.
7911               (when (and gnus-summary-mark-below
7912                          (< score gnus-summary-mark-below))
7913                 (setq gnus-newsgroup-unreads
7914                       (delq number gnus-newsgroup-unreads))
7915                 (if gnus-newsgroup-auto-expire
7916                     (push number gnus-newsgroup-expirable)
7917                   (push (cons number gnus-low-score-mark)
7918                         gnus-newsgroup-reads)))
7919               t)
7920             ;; Do the `display' group parameter.
7921             (and gnus-newsgroup-display
7922                  (not (funcall gnus-newsgroup-display)))
7923             ;; Check NoCeM things.
7924             (if (and gnus-use-nocem
7925                      (gnus-nocem-unwanted-article-p
7926                       (mail-header-id (car thread))))
7927                 (progn
7928                   (setq gnus-newsgroup-unreads
7929                         (delq number gnus-newsgroup-unreads))
7930                   t))))
7931           ;; Nope, invisible article.
7932           0
7933         ;; Ok, this article is to be visible, so we add it to the limit
7934         ;; and return 1.
7935         (push number gnus-newsgroup-limit)
7936         1))))
7937
7938 (defun gnus-expunge-thread (thread)
7939   "Mark all articles in THREAD as read."
7940   (let* ((number (mail-header-number (car thread))))
7941     (incf gnus-newsgroup-expunged-tally)
7942     ;; We also mark as read here, if that's wanted.
7943     (setq gnus-newsgroup-unreads
7944           (delq number gnus-newsgroup-unreads))
7945     (if gnus-newsgroup-auto-expire
7946         (push number gnus-newsgroup-expirable)
7947       (push (cons number gnus-low-score-mark)
7948             gnus-newsgroup-reads)))
7949   ;; Go recursively through all subthreads.
7950   (mapcar 'gnus-expunge-thread (cdr thread)))
7951
7952 ;; Summary article oriented commands
7953
7954 (defun gnus-summary-refer-parent-article (n)
7955   "Refer parent article N times.
7956 If N is negative, go to ancestor -N instead.
7957 The difference between N and the number of articles fetched is returned."
7958   (interactive "p")
7959   (let ((skip 1)
7960         error header ref)
7961     (when (not (natnump n))
7962       (setq skip (abs n)
7963             n 1))
7964     (while (and (> n 0)
7965                 (not error))
7966       (setq header (gnus-summary-article-header))
7967       (if (and (eq (mail-header-number header)
7968                    (cdr gnus-article-current))
7969                (equal gnus-newsgroup-name
7970                       (car gnus-article-current)))
7971           ;; If we try to find the parent of the currently
7972           ;; displayed article, then we take a look at the actual
7973           ;; References header, since this is slightly more
7974           ;; reliable than the References field we got from the
7975           ;; server.
7976           (save-excursion
7977             (set-buffer gnus-original-article-buffer)
7978             (nnheader-narrow-to-headers)
7979             (unless (setq ref (message-fetch-field "references"))
7980               (setq ref (message-fetch-field "in-reply-to")))
7981             (widen))
7982         (setq ref
7983               ;; It's not the current article, so we take a bet on
7984               ;; the value we got from the server.
7985               (mail-header-references header)))
7986       (if (and ref
7987                (not (equal ref "")))
7988           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7989             (gnus-message 1 "Couldn't find parent"))
7990         (gnus-message 1 "No references in article %d"
7991                       (gnus-summary-article-number))
7992         (setq error t))
7993       (decf n))
7994     (gnus-summary-position-point)
7995     n))
7996
7997 (defun gnus-summary-refer-references ()
7998   "Fetch all articles mentioned in the References header.
7999 Return the number of articles fetched."
8000   (interactive)
8001   (let ((ref (mail-header-references (gnus-summary-article-header)))
8002         (current (gnus-summary-article-number))
8003         (n 0))
8004     (if (or (not ref)
8005             (equal ref ""))
8006         (error "No References in the current article")
8007       ;; For each Message-ID in the References header...
8008       (while (string-match "<[^>]*>" ref)
8009         (incf n)
8010         ;; ... fetch that article.
8011         (gnus-summary-refer-article
8012          (prog1 (match-string 0 ref)
8013            (setq ref (substring ref (match-end 0))))))
8014       (gnus-summary-goto-subject current)
8015       (gnus-summary-position-point)
8016       n)))
8017
8018 (defun gnus-summary-refer-thread (&optional limit)
8019   "Fetch all articles in the current thread.
8020 If LIMIT (the numerical prefix), fetch that many old headers instead
8021 of what's specified by the `gnus-refer-thread-limit' variable."
8022   (interactive "P")
8023   (let ((id (mail-header-id (gnus-summary-article-header)))
8024         (limit (if limit (prefix-numeric-value limit)
8025                  gnus-refer-thread-limit)))
8026     (unless (eq gnus-fetch-old-headers 'invisible)
8027       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8028       ;; Retrieve the headers and read them in.
8029       (if (eq (if (numberp limit)
8030                   (gnus-retrieve-headers
8031                    (list (min
8032                           (+ (mail-header-number
8033                               (gnus-summary-article-header))
8034                              limit)
8035                           gnus-newsgroup-end))
8036                    gnus-newsgroup-name (* limit 2))
8037                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8038                 ;; headers.
8039                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8040                                        gnus-newsgroup-name limit))
8041               'nov)
8042           (gnus-build-all-threads)
8043         (error "Can't fetch thread from backends that don't support NOV"))
8044       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8045     (gnus-summary-limit-include-thread id)))
8046
8047 (defun gnus-summary-refer-article (message-id)
8048   "Fetch an article specified by MESSAGE-ID."
8049   (interactive "sMessage-ID: ")
8050   (when (and (stringp message-id)
8051              (not (zerop (length message-id))))
8052     ;; Construct the correct Message-ID if necessary.
8053     ;; Suggested by tale@pawl.rpi.edu.
8054     (unless (string-match "^<" message-id)
8055       (setq message-id (concat "<" message-id)))
8056     (unless (string-match ">$" message-id)
8057       (setq message-id (concat message-id ">")))
8058     (let* ((header (gnus-id-to-header message-id))
8059            (sparse (and header
8060                         (gnus-summary-article-sparse-p
8061                          (mail-header-number header))
8062                         (memq (mail-header-number header)
8063                               gnus-newsgroup-limit)))
8064            number)
8065       (cond
8066        ;; If the article is present in the buffer we just go to it.
8067        ((and header
8068              (or (not (gnus-summary-article-sparse-p
8069                        (mail-header-number header)))
8070                  sparse))
8071         (prog1
8072             (gnus-summary-goto-article
8073              (mail-header-number header) nil t)
8074           (when sparse
8075             (gnus-summary-update-article (mail-header-number header)))))
8076        (t
8077         ;; We fetch the article.
8078         (catch 'found
8079           (dolist (gnus-override-method (gnus-refer-article-methods))
8080             (when (and (gnus-check-server gnus-override-method)
8081                        ;; Fetch the header,
8082                        (setq number (gnus-summary-insert-subject message-id)))
8083               ;; and display the article.
8084               (gnus-summary-select-article nil nil nil number)
8085               (throw 'found t)))
8086           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8087
8088 (defun gnus-refer-article-methods ()
8089   "Return a list of referable methods."
8090   (cond
8091    ;; No method, so we default to current and native.
8092    ((null gnus-refer-article-method)
8093     (list gnus-current-select-method gnus-select-method))
8094    ;; Current.
8095    ((eq 'current gnus-refer-article-method)
8096     (list gnus-current-select-method))
8097    ;; List of select methods.
8098    ((not (and (symbolp (car gnus-refer-article-method))
8099               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8100     (let (out)
8101       (dolist (method gnus-refer-article-method)
8102         (push (if (eq 'current method)
8103                   gnus-current-select-method
8104                 method)
8105               out))
8106       (nreverse out)))
8107    ;; One single select method.
8108    (t
8109     (list gnus-refer-article-method))))
8110
8111 (defun gnus-summary-edit-parameters ()
8112   "Edit the group parameters of the current group."
8113   (interactive)
8114   (gnus-group-edit-group gnus-newsgroup-name 'params))
8115
8116 (defun gnus-summary-customize-parameters ()
8117   "Customize the group parameters of the current group."
8118   (interactive)
8119   (gnus-group-customize gnus-newsgroup-name))
8120
8121 (defun gnus-summary-enter-digest-group (&optional force)
8122   "Enter an nndoc group based on the current article.
8123 If FORCE, force a digest interpretation.  If not, try
8124 to guess what the document format is."
8125   (interactive "P")
8126   (let ((conf gnus-current-window-configuration))
8127     (save-excursion
8128       (gnus-summary-select-article))
8129     (setq gnus-current-window-configuration conf)
8130     (let* ((name (format "%s-%d"
8131                          (gnus-group-prefixed-name
8132                           gnus-newsgroup-name (list 'nndoc ""))
8133                          (save-excursion
8134                            (set-buffer gnus-summary-buffer)
8135                            gnus-current-article)))
8136            (ogroup gnus-newsgroup-name)
8137            (params (append (gnus-info-params (gnus-get-info ogroup))
8138                            (list (cons 'to-group ogroup))
8139                            (list (cons 'save-article-group ogroup))))
8140            (case-fold-search t)
8141            (buf (current-buffer))
8142            dig to-address)
8143       (save-excursion
8144         (set-buffer gnus-original-article-buffer)
8145         ;; Have the digest group inherit the main mail address of
8146         ;; the parent article.
8147         (when (setq to-address (or (gnus-fetch-field "reply-to")
8148                                    (gnus-fetch-field "from")))
8149           (setq params (append
8150                         (list (cons 'to-address
8151                                     (funcall gnus-decode-encoded-word-function
8152                                              to-address))))))
8153         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8154         (insert-buffer-substring gnus-original-article-buffer)
8155         ;; Remove lines that may lead nndoc to misinterpret the
8156         ;; document type.
8157         (narrow-to-region
8158          (goto-char (point-min))
8159          (or (search-forward "\n\n" nil t) (point)))
8160         (goto-char (point-min))
8161         (delete-matching-lines "^Path:\\|^From ")
8162         (widen))
8163       (unwind-protect
8164           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8165                     (gnus-newsgroup-ephemeral-ignored-charsets
8166                      gnus-newsgroup-ignored-charsets))
8167                 (gnus-group-read-ephemeral-group
8168                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8169                               (nndoc-article-type
8170                                ,(if force 'mbox 'guess)))
8171                  t nil nil nil
8172                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8173                                                         "ADAPT")))))
8174               ;; Make all postings to this group go to the parent group.
8175               (nconc (gnus-info-params (gnus-get-info name))
8176                      params)
8177             ;; Couldn't select this doc group.
8178             (switch-to-buffer buf)
8179             (gnus-set-global-variables)
8180             (gnus-configure-windows 'summary)
8181             (gnus-message 3 "Article couldn't be entered?"))
8182         (kill-buffer dig)))))
8183
8184 (defun gnus-summary-read-document (n)
8185   "Open a new group based on the current article(s).
8186 This will allow you to read digests and other similar
8187 documents as newsgroups.
8188 Obeys the standard process/prefix convention."
8189   (interactive "P")
8190   (let* ((articles (gnus-summary-work-articles n))
8191          (ogroup gnus-newsgroup-name)
8192          (params (append (gnus-info-params (gnus-get-info ogroup))
8193                          (list (cons 'to-group ogroup))))
8194          article group egroup groups vgroup)
8195     (while (setq article (pop articles))
8196       (setq group (format "%s-%d" gnus-newsgroup-name article))
8197       (gnus-summary-remove-process-mark article)
8198       (when (gnus-summary-display-article article)
8199         (save-excursion
8200           (with-temp-buffer
8201             (insert-buffer-substring gnus-original-article-buffer)
8202             ;; Remove some headers that may lead nndoc to make
8203             ;; the wrong guess.
8204             (message-narrow-to-head)
8205             (goto-char (point-min))
8206             (delete-matching-lines "^\\(Path\\):\\|^From ")
8207             (widen)
8208             (if (setq egroup
8209                       (gnus-group-read-ephemeral-group
8210                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8211                                      (nndoc-article-type guess))
8212                        t nil t))
8213                 (progn
8214                   ;; Make all postings to this group go to the parent group.
8215                   (nconc (gnus-info-params (gnus-get-info egroup))
8216                          params)
8217                   (push egroup groups))
8218               ;; Couldn't select this doc group.
8219               (gnus-error 3 "Article couldn't be entered"))))))
8220     ;; Now we have selected all the documents.
8221     (cond
8222      ((not groups)
8223       (error "None of the articles could be interpreted as documents"))
8224      ((gnus-group-read-ephemeral-group
8225        (setq vgroup (format
8226                      "nnvirtual:%s-%s" gnus-newsgroup-name
8227                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8228        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8229        t
8230        (cons (current-buffer) 'summary)))
8231      (t
8232       (error "Couldn't select virtual nndoc group")))))
8233
8234 (defun gnus-summary-isearch-article (&optional regexp-p)
8235   "Do incremental search forward on the current article.
8236 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8237   (interactive "P")
8238   (let* ((gnus-inhibit-treatment t)
8239          (old (gnus-summary-select-article)))
8240     (gnus-configure-windows 'article)
8241     (gnus-eval-in-buffer-window gnus-article-buffer
8242       (save-restriction
8243         (widen)
8244         (when (eq 'old old)
8245           (gnus-article-show-all-headers))
8246         (goto-char (point-min))
8247         (isearch-forward regexp-p)))))
8248
8249 (defun gnus-summary-search-article-forward (regexp &optional backward)
8250   "Search for an article containing REGEXP forward.
8251 If BACKWARD, search backward instead."
8252   (interactive
8253    (list (read-string
8254           (format "Search article %s (regexp%s): "
8255                   (if current-prefix-arg "backward" "forward")
8256                   (if gnus-last-search-regexp
8257                       (concat ", default " gnus-last-search-regexp)
8258                     "")))
8259          current-prefix-arg))
8260   (if (string-equal regexp "")
8261       (setq regexp (or gnus-last-search-regexp ""))
8262     (setq gnus-last-search-regexp regexp)
8263     (setq gnus-article-before-search gnus-current-article))
8264   ;; Intentionally set gnus-last-article.
8265   (setq gnus-last-article gnus-article-before-search)
8266   (let ((gnus-last-article gnus-last-article))
8267     (if (gnus-summary-search-article regexp backward)
8268         (gnus-summary-show-thread)
8269       (error "Search failed: \"%s\"" regexp))))
8270
8271 (defun gnus-summary-search-article-backward (regexp)
8272   "Search for an article containing REGEXP backward."
8273   (interactive
8274    (list (read-string
8275           (format "Search article backward (regexp%s): "
8276                   (if gnus-last-search-regexp
8277                       (concat ", default " gnus-last-search-regexp)
8278                     "")))))
8279   (gnus-summary-search-article-forward regexp 'backward))
8280
8281 (eval-when-compile
8282   (defmacro gnus-summary-search-article-position-point (regexp backward)
8283     "Dehighlight the last matched text and goto the beginning position."
8284     (` (if (and gnus-summary-search-article-matched-data
8285                 (let ((text (caddr gnus-summary-search-article-matched-data))
8286                       (inhibit-read-only t)
8287                       buffer-read-only)
8288                   (delete-region
8289                    (goto-char (car gnus-summary-search-article-matched-data))
8290                    (cadr gnus-summary-search-article-matched-data))
8291                   (insert text)
8292                   (string-match (, regexp) text)))
8293            (if (, backward) (beginning-of-line) (end-of-line))
8294          (goto-char (if (, backward) (point-max) (point-min))))))
8295
8296   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8297     "Place point where X-Face image is displayed."
8298     (if (featurep 'xemacs)
8299         (` (let ((end (if (search-forward "\n\n" nil t)
8300                           (goto-char (1- (point)))
8301                         (point-min)))
8302                  extent)
8303              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8304              (unless (and (re-search-forward "^From:" end t)
8305                           (setq extent (extent-at (point)))
8306                           (extent-begin-glyph extent))
8307                (goto-char (, opoint)))))
8308       (` (let ((end (if (search-forward "\n\n" nil t)
8309                         (goto-char (1- (point)))
8310                       (point-min)))
8311                (start (or (search-backward "\n\n" nil t) (point-min))))
8312            (goto-char
8313             (or (text-property-any start end 'x-face-image t);; x-face-e21
8314                 (text-property-any start end 'x-face-mule-bitmap-image t)
8315                 (, opoint)))))))
8316
8317   (defmacro gnus-summary-search-article-highlight-matched-text
8318     (backward treated x-face)
8319     "Highlight matched text in the function `gnus-summary-search-article'."
8320     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8321              (end (set-marker (make-marker) (match-end 0)))
8322              (inhibit-read-only t)
8323              buffer-read-only)
8324          (unless treated
8325            (let ((,@
8326                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8327                     (mapcar
8328                      (lambda (item) (setq items (delq item items)))
8329                      '(gnus-treat-buttonize
8330                        gnus-treat-fill-article
8331                        gnus-treat-fill-long-lines
8332                        gnus-treat-emphasize
8333                        gnus-treat-highlight-headers
8334                        gnus-treat-highlight-citation
8335                        gnus-treat-highlight-signature
8336                        gnus-treat-overstrike
8337                        gnus-treat-display-xface
8338                        gnus-treat-buttonize-head
8339                        gnus-treat-decode-article-as-default-mime-charset))
8340                     (static-if (featurep 'xemacs)
8341                         items
8342                       (cons '(x-face-mule-delete-x-face-field
8343                               (quote never))
8344                             items))))
8345                  (gnus-treat-display-xface
8346                   (when (, x-face) gnus-treat-display-xface)))
8347              (gnus-article-prepare-mime-display)))
8348          (goto-char (if (, backward) start end))
8349          (when (, x-face)
8350            (gnus-summary-search-article-highlight-goto-x-face (point)))
8351          (setq gnus-summary-search-article-matched-data
8352                (list start end (buffer-substring start end)))
8353          (unless (eq start end);; matched text has been deleted. :-<
8354            (put-text-property start end 'face
8355                               (or (find-face 'isearch)
8356                                   'secondary-selection))))))
8357   )
8358
8359 (defun gnus-summary-search-article (regexp &optional backward)
8360   "Search for an article containing REGEXP.
8361 Optional argument BACKWARD means do search for backward.
8362 `gnus-select-article-hook' is not called during the search."
8363   ;; We have to require this here to make sure that the following
8364   ;; dynamic binding isn't shadowed by autoloading.
8365   (require 'gnus-async)
8366   (require 'gnus-art)
8367   (let ((gnus-select-article-hook nil)  ;Disable hook.
8368         (gnus-article-prepare-hook nil)
8369         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8370         (gnus-use-article-prefetch nil)
8371         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8372         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8373         (gnus-visual nil)
8374         (gnus-keep-backlog nil)
8375         (gnus-break-pages nil)
8376         (gnus-summary-display-arrow nil)
8377         (gnus-updated-mode-lines nil)
8378         (gnus-auto-center-summary nil)
8379         (sum (current-buffer))
8380         (found nil)
8381         point treated)
8382     (gnus-save-hidden-threads
8383       (static-if (featurep 'xemacs)
8384           (let ((gnus-inhibit-treatment t))
8385             (setq treated (eq 'old (gnus-summary-select-article)))
8386             (when (and treated
8387                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8388                                  (window-live-p (get-buffer-window
8389                                                  gnus-article-buffer t)))))
8390               (gnus-summary-select-article nil t)
8391               (setq treated nil)))
8392         (let ((gnus-inhibit-treatment t)
8393               (x-face-mule-delete-x-face-field 'never))
8394           (setq treated (eq 'old (gnus-summary-select-article)))
8395           (when (and treated
8396                      (not
8397                       (and (gnus-buffer-live-p gnus-article-buffer)
8398                            (window-live-p (get-buffer-window
8399                                            gnus-article-buffer t))
8400                            (or (not (string-match "^\\^X-Face:" regexp))
8401                                (with-current-buffer gnus-article-buffer
8402                                  gnus-summary-search-article-matched-data)))))
8403             (gnus-summary-select-article nil t)
8404             (setq treated nil))))
8405       (set-buffer gnus-article-buffer)
8406       (widen)
8407       (if treated
8408           (progn
8409             (gnus-article-show-all-headers)
8410             (gnus-summary-search-article-position-point regexp backward))
8411         (goto-char (if backward (point-max) (point-min))))
8412       (while (not found)
8413         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8414         (if (if backward
8415                 (re-search-backward regexp nil t)
8416               (re-search-forward regexp nil t))
8417             ;; We found the regexp.
8418             (progn
8419               (gnus-summary-search-article-highlight-matched-text
8420                backward treated (string-match "^\\^X-Face:" regexp))
8421               (setq found 'found)
8422               (forward-line
8423                (/ (- 2 (window-height
8424                         (get-buffer-window gnus-article-buffer t)))
8425                   2))
8426               (set-window-start
8427                (get-buffer-window (current-buffer))
8428                (point))
8429               (set-buffer sum)
8430               (setq point (point)))
8431           ;; We didn't find it, so we go to the next article.
8432           (set-buffer sum)
8433           (setq found 'not)
8434           (while (eq found 'not)
8435             (if (not (if backward (gnus-summary-find-prev)
8436                        (gnus-summary-find-next)))
8437                 ;; No more articles.
8438                 (setq found t)
8439               ;; Select the next article and adjust point.
8440               (unless (gnus-summary-article-sparse-p
8441                        (gnus-summary-article-number))
8442                 (setq found nil)
8443                 (let ((gnus-inhibit-treatment t))
8444                   (gnus-summary-select-article))
8445                 (setq treated nil)
8446                 (set-buffer gnus-article-buffer)
8447                 (widen)
8448                 (goto-char (if backward (point-max) (point-min))))))))
8449       (gnus-message 7 ""))
8450     ;; Return whether we found the regexp.
8451     (when (eq found 'found)
8452       (goto-char point)
8453       (gnus-summary-show-thread)
8454       (gnus-summary-goto-subject gnus-current-article)
8455       (gnus-summary-position-point)
8456       t)))
8457
8458 (defun gnus-find-matching-articles (header regexp)
8459   "Return a list of all articles that match REGEXP on HEADER.
8460 This search includes all articles in the current group that Gnus has
8461 fetched headers for, whether they are displayed or not."
8462   (let ((articles nil)
8463         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8464         (case-fold-search t))
8465     (dolist (header gnus-newsgroup-headers)
8466       (when (string-match regexp (funcall func header))
8467         (push (mail-header-number header) articles)))
8468     (nreverse articles)))
8469
8470 (defun gnus-summary-find-matching (header regexp &optional backward unread
8471                                           not-case-fold not-matching)
8472   "Return a list of all articles that match REGEXP on HEADER.
8473 The search stars on the current article and goes forwards unless
8474 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8475 If UNREAD is non-nil, only unread articles will
8476 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8477 in the comparisons. If NOT-MATCHING, return a list of all articles that
8478 not match REGEXP on HEADER."
8479   (let ((case-fold-search (not not-case-fold))
8480         articles d func)
8481     (if (consp header)
8482         (if (eq (car header) 'extra)
8483             (setq func
8484                   `(lambda (h)
8485                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8486                          "")))
8487           (error "%s is an invalid header" header))
8488       (unless (fboundp (intern (concat "mail-header-" header)))
8489         (error "%s is not a valid header" header))
8490       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8491     (dolist (d (if (eq backward 'all)
8492                    gnus-newsgroup-data
8493                  (gnus-data-find-list
8494                   (gnus-summary-article-number)
8495                   (gnus-data-list backward))))
8496       (when (and (or (not unread)       ; We want all articles...
8497                      (gnus-data-unread-p d)) ; Or just unreads.
8498                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8499                  (if not-matching
8500                      (not (string-match
8501                            regexp
8502                            (funcall func (gnus-data-header d))))
8503                    (string-match regexp
8504                                  (funcall func (gnus-data-header d)))))
8505         (push (gnus-data-number d) articles))) ; Success!
8506     (nreverse articles)))
8507
8508 (defun gnus-summary-execute-command (header regexp command &optional backward)
8509   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8510 If HEADER is an empty string (or nil), the match is done on the entire
8511 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8512   (interactive
8513    (list (let ((completion-ignore-case t))
8514            (completing-read
8515             "Header name: "
8516             (mapcar (lambda (header) (list (format "%s" header)))
8517                     (append
8518                      '("Number" "Subject" "From" "Lines" "Date"
8519                        "Message-ID" "Xref" "References" "Body")
8520                      gnus-extra-headers))
8521             nil 'require-match))
8522          (read-string "Regexp: ")
8523          (read-key-sequence "Command: ")
8524          current-prefix-arg))
8525   (when (equal header "Body")
8526     (setq header ""))
8527   ;; Hidden thread subtrees must be searched as well.
8528   (gnus-summary-show-all-threads)
8529   ;; We don't want to change current point nor window configuration.
8530   (save-excursion
8531     (save-window-excursion
8532       (let (gnus-visual
8533             gnus-treat-strip-trailing-blank-lines
8534             gnus-treat-strip-leading-blank-lines
8535             gnus-treat-strip-multiple-blank-lines
8536             gnus-treat-hide-boring-headers
8537             gnus-treat-fold-newsgroups
8538             gnus-article-prepare-hook)
8539         (gnus-message 6 "Executing %s..." (key-description command))
8540         ;; We'd like to execute COMMAND interactively so as to give arguments.
8541         (gnus-execute header regexp
8542                       `(call-interactively ',(key-binding command))
8543                       backward)
8544         (gnus-message 6 "Executing %s...done" (key-description command))))))
8545
8546 (defun gnus-summary-beginning-of-article ()
8547   "Scroll the article back to the beginning."
8548   (interactive)
8549   (gnus-summary-select-article)
8550   (gnus-configure-windows 'article)
8551   (gnus-eval-in-buffer-window gnus-article-buffer
8552     (widen)
8553     (goto-char (point-min))
8554     (when gnus-page-broken
8555       (gnus-narrow-to-page))))
8556
8557 (defun gnus-summary-end-of-article ()
8558   "Scroll to the end of the article."
8559   (interactive)
8560   (gnus-summary-select-article)
8561   (gnus-configure-windows 'article)
8562   (gnus-eval-in-buffer-window gnus-article-buffer
8563     (widen)
8564     (goto-char (point-max))
8565     (recenter -3)
8566     (when gnus-page-broken
8567       (gnus-narrow-to-page))))
8568
8569 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8570   "Truncate to LEN and quote all \"(\"'s in STRING."
8571   (gnus-replace-in-string (if (and len (> (length string) len))
8572                               (substring string 0 len)
8573                             string)
8574                           "[()]" "\\\\\\&"))
8575
8576 (defun gnus-summary-print-article (&optional filename n)
8577   "Generate and print a PostScript image of the N next (mail) articles.
8578
8579 If N is negative, print the N previous articles.  If N is nil and articles
8580 have been marked with the process mark, print these instead.
8581
8582 If the optional first argument FILENAME is nil, send the image to the
8583 printer.  If FILENAME is a string, save the PostScript image in a file with
8584 that name.  If FILENAME is a number, prompt the user for the name of the file
8585 to save in."
8586   (interactive (list (ps-print-preprint current-prefix-arg)))
8587   (dolist (article (gnus-summary-work-articles n))
8588     (gnus-summary-select-article nil nil 'pseudo article)
8589     (gnus-eval-in-buffer-window gnus-article-buffer
8590       (gnus-print-buffer))
8591     (gnus-summary-remove-process-mark article))
8592   (ps-despool filename))
8593
8594 (defun gnus-print-buffer ()
8595   (let ((buffer (generate-new-buffer " *print*")))
8596     (unwind-protect
8597         (progn
8598           (copy-to-buffer buffer (point-min) (point-max))
8599           (set-buffer buffer)
8600           (gnus-article-delete-invisible-text)
8601           (gnus-remove-text-with-property 'gnus-decoration)
8602           (when (gnus-visual-p 'article-highlight 'highlight)
8603             ;; Copy-to-buffer doesn't copy overlay.  So redo
8604             ;; highlight.
8605             (let ((gnus-article-buffer buffer))
8606               (gnus-article-highlight-citation t)
8607               (gnus-article-highlight-signature)))
8608           (let ((ps-left-header
8609                  (list
8610                   (concat "("
8611                           (gnus-summary-print-truncate-and-quote
8612                            (mail-header-subject gnus-current-headers)
8613                            66) ")")
8614                   (concat "("
8615                           (gnus-summary-print-truncate-and-quote
8616                            (mail-header-from gnus-current-headers)
8617                            45) ")")))
8618                 (ps-right-header
8619                  (list
8620                   "/pagenumberstring load"
8621                   (concat "("
8622                           (mail-header-date gnus-current-headers) ")"))))
8623             (gnus-run-hooks 'gnus-ps-print-hook)
8624             (save-excursion
8625               (if window-system
8626                   (ps-spool-buffer-with-faces)
8627                 (ps-spool-buffer)))))
8628       (kill-buffer buffer))))
8629
8630 (defun gnus-summary-show-article (&optional arg)
8631   "Force redisplaying of the current article.
8632 If ARG (the prefix) is a number, show the article with the charset
8633 defined in `gnus-summary-show-article-charset-alist', or the charset
8634 input.
8635 If ARG (the prefix) is non-nil and not a number, show the raw article
8636 without any article massaging functions being run.  Normally, the key strokes
8637 are `C-u g'."
8638   (interactive "P")
8639   (cond
8640    ((numberp arg)
8641     (gnus-summary-show-article t)
8642     (let* ((gnus-newsgroup-charset
8643             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8644                 (mm-read-coding-system
8645                  "View as charset: " ;; actually it is coding system.
8646                  (save-excursion
8647                    (set-buffer gnus-article-buffer)
8648                    (mm-detect-coding-region (point) (point-max))))))
8649            (default-mime-charset gnus-newsgroup-charset)
8650            (gnus-newsgroup-ignored-charsets 'gnus-all))
8651       (gnus-summary-select-article nil 'force)
8652       (let ((deps gnus-newsgroup-dependencies)
8653             head header lines)
8654         (save-excursion
8655           (set-buffer gnus-original-article-buffer)
8656           (save-restriction
8657             (message-narrow-to-head)
8658             (setq head (buffer-string))
8659             (goto-char (point-min))
8660             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8661               (goto-char (point-max))
8662               (widen)
8663               (setq lines (1- (count-lines (point) (point-max))))))
8664           (with-temp-buffer
8665             (insert (format "211 %d Article retrieved.\n"
8666                             (cdr gnus-article-current)))
8667             (insert head)
8668             (if lines (insert (format "Lines: %d\n" lines)))
8669             (insert ".\n")
8670             (let ((nntp-server-buffer (current-buffer)))
8671               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8672         (gnus-data-set-header
8673          (gnus-data-find (cdr gnus-article-current))
8674          header)
8675         (gnus-summary-update-article-line
8676          (cdr gnus-article-current) header)
8677         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8678           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8679    ((not arg)
8680     ;; Select the article the normal way.
8681     (gnus-summary-select-article nil 'force))
8682    (t
8683     ;; We have to require this here to make sure that the following
8684     ;; dynamic binding isn't shadowed by autoloading.
8685     (require 'gnus-async)
8686     (require 'gnus-art)
8687     ;; Bind the article treatment functions to nil.
8688     (let ((gnus-have-all-headers t)
8689           gnus-article-prepare-hook
8690           gnus-article-decode-hook
8691           gnus-break-pages
8692           gnus-show-mime
8693           (gnus-inhibit-treatment t))
8694       (gnus-summary-select-article nil 'force))))
8695   (gnus-summary-goto-subject gnus-current-article)
8696   (gnus-summary-position-point))
8697
8698 (defun gnus-summary-show-raw-article ()
8699   "Show the raw article without any article massaging functions being run."
8700   (interactive)
8701   (gnus-summary-show-article t))
8702
8703 (defun gnus-summary-verbose-headers (&optional arg)
8704   "Toggle permanent full header display.
8705 If ARG is a positive number, turn header display on.
8706 If ARG is a negative number, turn header display off."
8707   (interactive "P")
8708   (setq gnus-show-all-headers
8709         (cond ((or (not (numberp arg))
8710                    (zerop arg))
8711                (not gnus-show-all-headers))
8712               ((natnump arg)
8713                t)))
8714   (gnus-summary-show-article))
8715
8716 (defun gnus-summary-toggle-header (&optional arg)
8717   "Show the headers if they are hidden, or hide them if they are shown.
8718 If ARG is a positive number, show the entire header.
8719 If ARG is a negative number, hide the unwanted header lines."
8720   (interactive "P")
8721   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8722                      (get-buffer-window gnus-article-buffer t))))
8723     (with-current-buffer gnus-article-buffer
8724       (widen)
8725       (article-narrow-to-head)
8726       (let* ((buffer-read-only nil)
8727              (inhibit-point-motion-hooks t)
8728              (hidden (if (numberp arg)
8729                          (>= arg 0)
8730                        (gnus-article-hidden-text-p 'headers)))
8731              s e)
8732         (delete-region (point-min) (point-max))
8733         (with-current-buffer gnus-original-article-buffer
8734           (goto-char (setq s (point-min)))
8735           (setq e (if (search-forward "\n\n" nil t)
8736                       (1- (point))
8737                     (point-max))))
8738         (insert-buffer-substring gnus-original-article-buffer s e)
8739         (run-hooks 'gnus-article-decode-hook)
8740         (if hidden
8741             (let ((gnus-treat-hide-headers nil)
8742                   (gnus-treat-hide-boring-headers nil))
8743               (gnus-delete-wash-type 'headers)
8744               (gnus-treat-article 'head))
8745           (gnus-treat-article 'head))
8746         (widen)
8747         (if window
8748             (set-window-start window (goto-char (point-min))))
8749         (setq gnus-page-broken
8750               (when gnus-break-pages
8751                 (gnus-narrow-to-page)
8752                 t))
8753         (gnus-set-mode-line 'article)))))
8754
8755 (defun gnus-summary-show-all-headers ()
8756   "Make all header lines visible."
8757   (interactive)
8758   (gnus-summary-toggle-header 1))
8759
8760 (defun gnus-summary-toggle-mime (&optional arg)
8761   "Toggle MIME processing.
8762 If ARG is a positive number, turn MIME processing on."
8763   (interactive "P")
8764   (setq gnus-show-mime
8765         (if (null arg)
8766             (not gnus-show-mime)
8767           (> (prefix-numeric-value arg) 0)))
8768   (gnus-summary-select-article t 'force))
8769
8770 (defun gnus-summary-caesar-message (&optional arg)
8771   "Caesar rotate the current article by 13.
8772 The numerical prefix specifies how many places to rotate each letter
8773 forward."
8774   (interactive "P")
8775   (gnus-summary-select-article)
8776   (let ((mail-header-separator ""))
8777     (gnus-eval-in-buffer-window gnus-article-buffer
8778       (save-restriction
8779         (widen)
8780         (let ((start (window-start))
8781               buffer-read-only)
8782           (message-caesar-buffer-body arg)
8783           (set-window-start (get-buffer-window (current-buffer)) start))))))
8784
8785 (autoload 'unmorse-region "morse"
8786   "Convert morse coded text in region to ordinary ASCII text."
8787   t)
8788
8789 (defun gnus-summary-morse-message (&optional arg)
8790   "Morse decode the current article."
8791   (interactive "P")
8792   (gnus-summary-select-article)
8793   (let ((mail-header-separator ""))
8794     (gnus-eval-in-buffer-window gnus-article-buffer
8795       (save-excursion
8796         (save-restriction
8797           (widen)
8798           (let ((pos (window-start))
8799                 buffer-read-only)
8800             (goto-char (point-min))
8801             (when (message-goto-body)
8802               (gnus-narrow-to-body))
8803             (goto-char (point-min))
8804             (while (re-search-forward "·" (point-max) t)
8805               (replace-match "."))
8806             (unmorse-region (point-min) (point-max))
8807             (widen)
8808             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8809
8810 (defun gnus-summary-stop-page-breaking ()
8811   "Stop page breaking in the current article."
8812   (interactive)
8813   (gnus-summary-select-article)
8814   (gnus-eval-in-buffer-window gnus-article-buffer
8815     (widen)
8816     (when (gnus-visual-p 'page-marker)
8817       (let ((buffer-read-only nil))
8818         (gnus-remove-text-with-property 'gnus-prev)
8819         (gnus-remove-text-with-property 'gnus-next))
8820       (setq gnus-page-broken nil))))
8821
8822 (defun gnus-summary-move-article (&optional n to-newsgroup
8823                                             select-method action)
8824   "Move the current article to a different newsgroup.
8825 If N is a positive number, move the N next articles.
8826 If N is a negative number, move the N previous articles.
8827 If N is nil and any articles have been marked with the process mark,
8828 move those articles instead.
8829 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8830 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8831 re-spool using this method.
8832
8833 When called interactively with TO-NEWSGROUP being nil, the value of
8834 the variable `gnus-move-split-methods' is used for finding a default
8835 for the target newsgroup.
8836
8837 For this function to work, both the current newsgroup and the
8838 newsgroup that you want to move to have to support the `request-move'
8839 and `request-accept' functions.
8840
8841 ACTION can be either `move' (the default), `crosspost' or `copy'."
8842   (interactive "P")
8843   (unless action
8844     (setq action 'move))
8845   ;; Check whether the source group supports the required functions.
8846   (cond ((and (eq action 'move)
8847               (not (gnus-check-backend-function
8848                     'request-move-article gnus-newsgroup-name)))
8849          (error "The current group does not support article moving"))
8850         ((and (eq action 'crosspost)
8851               (not (gnus-check-backend-function
8852                     'request-replace-article gnus-newsgroup-name)))
8853          (error "The current group does not support article editing")))
8854   (let ((articles (gnus-summary-work-articles n))
8855         (prefix (if (gnus-check-backend-function
8856                      'request-move-article gnus-newsgroup-name)
8857                     (gnus-group-real-prefix gnus-newsgroup-name)
8858                   ""))
8859         (names '((move "Move" "Moving")
8860                  (copy "Copy" "Copying")
8861                  (crosspost "Crosspost" "Crossposting")))
8862         (copy-buf (save-excursion
8863                     (nnheader-set-temp-buffer " *copy article*")))
8864         (default-marks gnus-article-mark-lists)
8865         (no-expire-marks (delete '(expirable . expire)
8866                                  (copy-sequence gnus-article-mark-lists)))
8867         art-group to-method new-xref article to-groups)
8868     (unless (assq action names)
8869       (error "Unknown action %s" action))
8870     ;; Read the newsgroup name.
8871     (when (and (not to-newsgroup)
8872                (not select-method))
8873       (if (and gnus-move-split-methods
8874                (not
8875                 (and (memq gnus-current-article articles)
8876                      (gnus-buffer-live-p gnus-original-article-buffer))))
8877           ;; When `gnus-move-split-methods' is non-nil, we have to
8878           ;; select an article to give `gnus-read-move-group-name' an
8879           ;; opportunity to suggest an appropriate default.  However,
8880           ;; we needn't render or mark the article.
8881           (let ((gnus-display-mime-function nil)
8882                 (gnus-article-prepare-hook nil)
8883                 (gnus-mark-article-hook nil))
8884             (gnus-summary-select-article nil nil nil (car articles))))
8885       (setq to-newsgroup
8886             (gnus-read-move-group-name
8887              (cadr (assq action names))
8888              (symbol-value (intern (format "gnus-current-%s-group" action)))
8889              articles prefix))
8890       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8891     (setq to-method (or select-method
8892                         (gnus-server-to-method
8893                          (gnus-group-method to-newsgroup))))
8894     ;; Check the method we are to move this article to...
8895     (unless (gnus-check-backend-function
8896              'request-accept-article (car to-method))
8897       (error "%s does not support article copying" (car to-method)))
8898     (unless (gnus-check-server to-method)
8899       (error "Can't open server %s" (car to-method)))
8900     (gnus-message 6 "%s to %s: %s..."
8901                   (caddr (assq action names))
8902                   (or (car select-method) to-newsgroup) articles)
8903     (while articles
8904       (setq article (pop articles))
8905       (setq
8906        art-group
8907        (cond
8908         ;; Move the article.
8909         ((eq action 'move)
8910          ;; Remove this article from future suppression.
8911          (gnus-dup-unsuppress-article article)
8912          (gnus-request-move-article
8913           article                       ; Article to move
8914           gnus-newsgroup-name           ; From newsgroup
8915           (nth 1 (gnus-find-method-for-group
8916                   gnus-newsgroup-name)) ; Server
8917           (list 'gnus-request-accept-article
8918                 to-newsgroup (list 'quote select-method)
8919                 (not articles) t)       ; Accept form
8920           (not articles)))              ; Only save nov last time
8921         ;; Copy the article.
8922         ((eq action 'copy)
8923          (save-excursion
8924            (set-buffer copy-buf)
8925            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8926              (gnus-request-accept-article
8927               to-newsgroup select-method (not articles) t))))
8928         ;; Crosspost the article.
8929         ((eq action 'crosspost)
8930          (let ((xref (message-tokenize-header
8931                       (mail-header-xref (gnus-summary-article-header article))
8932                       " ")))
8933            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8934                                   ":" (number-to-string article)))
8935            (unless xref
8936              (setq xref (list (system-name))))
8937            (setq new-xref
8938                  (concat
8939                   (mapconcat 'identity
8940                              (delete "Xref:" (delete new-xref xref))
8941                              " ")
8942                   " " new-xref))
8943            (save-excursion
8944              (set-buffer copy-buf)
8945              ;; First put the article in the destination group.
8946              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8947              (when (consp (setq art-group
8948                                 (gnus-request-accept-article
8949                                  to-newsgroup select-method (not articles))))
8950                (setq new-xref (concat new-xref " " (car art-group)
8951                                       ":"
8952                                       (number-to-string (cdr art-group))))
8953                ;; Now we have the new Xrefs header, so we insert
8954                ;; it and replace the new article.
8955                (nnheader-replace-header "Xref" new-xref)
8956                (gnus-request-replace-article
8957                 (cdr art-group) to-newsgroup (current-buffer))
8958                art-group))))))
8959       (cond
8960        ((not art-group)
8961         (gnus-message 1 "Couldn't %s article %s: %s"
8962                       (cadr (assq action names)) article
8963                       (nnheader-get-report (car to-method))))
8964        ((eq art-group 'junk)
8965         (when (eq action 'move)
8966           (gnus-summary-mark-article article gnus-canceled-mark)
8967           (gnus-message 4 "Deleted article %s" article)
8968           ;; run the delete hook
8969           (run-hook-with-args 'gnus-summary-article-delete-hook
8970                               action
8971                               (gnus-data-header
8972                                (assoc article (gnus-data-list nil)))
8973                               gnus-newsgroup-name nil
8974                               select-method)))
8975        (t
8976         (let* ((pto-group (gnus-group-prefixed-name
8977                            (car art-group) to-method))
8978                (entry
8979                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8980                (info (nth 2 entry))
8981                (to-group (gnus-info-group info))
8982                to-marks)
8983           ;; Update the group that has been moved to.
8984           (when (and info
8985                      (memq action '(move copy)))
8986             (unless (member to-group to-groups)
8987               (push to-group to-groups))
8988
8989             (unless (memq article gnus-newsgroup-unreads)
8990               (push 'read to-marks)
8991               (gnus-info-set-read
8992                info (gnus-add-to-range (gnus-info-read info)
8993                                        (list (cdr art-group)))))
8994
8995             ;; See whether the article is to be put in the cache.
8996             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8997                              default-marks
8998                            no-expire-marks))
8999                   (to-article (cdr art-group)))
9000
9001               ;; Enter the article into the cache in the new group,
9002               ;; if that is required.
9003               (when gnus-use-cache
9004                 (gnus-cache-possibly-enter-article
9005                  to-group to-article
9006                  (let ((header (copy-sequence
9007                                 (gnus-summary-article-header article))))
9008                    (mail-header-set-number header to-article)
9009                    header)
9010                  (memq article gnus-newsgroup-marked)
9011                  (memq article gnus-newsgroup-dormant)
9012                  (memq article gnus-newsgroup-unreads)))
9013
9014               (when gnus-preserve-marks
9015                 ;; Copy any marks over to the new group.
9016                 (when (and (equal to-group gnus-newsgroup-name)
9017                            (not (memq article gnus-newsgroup-unreads)))
9018                   ;; Mark this article as read in this group.
9019                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9020                   (setcdr (gnus-active to-group) to-article)
9021                   (setcdr gnus-newsgroup-active to-article))
9022
9023                 (while marks
9024                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9025                     (when (memq article (symbol-value
9026                                          (intern (format "gnus-newsgroup-%s"
9027                                                          (caar marks)))))
9028                       (push (cdar marks) to-marks)
9029                       ;; If the other group is the same as this group,
9030                       ;; then we have to add the mark to the list.
9031                       (when (equal to-group gnus-newsgroup-name)
9032                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9033                              (cons to-article
9034                                    (symbol-value
9035                                     (intern (format "gnus-newsgroup-%s"
9036                                                     (caar marks)))))))
9037                       ;; Copy the marks to other group.
9038                       (gnus-add-marked-articles
9039                        to-group (cdar marks) (list to-article) info)))
9040                   (setq marks (cdr marks)))
9041
9042                 (gnus-request-set-mark
9043                  to-group (list (list (list to-article) 'add to-marks))))
9044
9045               (gnus-dribble-enter
9046                (concat "(gnus-group-set-info '"
9047                        (gnus-prin1-to-string (gnus-get-info to-group))
9048                        ")"))))
9049
9050           ;; Update the Xref header in this article to point to
9051           ;; the new crossposted article we have just created.
9052           (when (eq action 'crosspost)
9053             (save-excursion
9054               (set-buffer copy-buf)
9055               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9056               (nnheader-replace-header "Xref" new-xref)
9057               (gnus-request-replace-article
9058                article gnus-newsgroup-name (current-buffer))))
9059
9060           ;; run the move/copy/crosspost/respool hook
9061           (run-hook-with-args 'gnus-summary-article-move-hook 
9062                               action
9063                               (gnus-data-header 
9064                                (assoc article (gnus-data-list nil)))
9065                               gnus-newsgroup-name
9066                               to-newsgroup
9067                               select-method))
9068
9069         ;;;!!!Why is this necessary?
9070         (set-buffer gnus-summary-buffer)
9071         
9072         (gnus-summary-goto-subject article)
9073         (when (eq action 'move)
9074           (gnus-summary-mark-article article gnus-canceled-mark))))
9075       (gnus-summary-remove-process-mark article))
9076     ;; Re-activate all groups that have been moved to.
9077     (save-excursion
9078       (set-buffer gnus-group-buffer)
9079       (let ((gnus-group-marked to-groups))
9080         (gnus-group-get-new-news-this-group nil t)))
9081
9082     (gnus-kill-buffer copy-buf)
9083     (gnus-summary-position-point)
9084     (gnus-set-mode-line 'summary)))
9085
9086 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9087   "Move the current article to a different newsgroup.
9088 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9089 When called interactively, if TO-NEWSGROUP is nil, use the value of
9090 the variable `gnus-move-split-methods' for finding a default target
9091 newsgroup.
9092 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9093 re-spool using this method."
9094   (interactive "P")
9095   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9096
9097 (defun gnus-summary-crosspost-article (&optional n)
9098   "Crosspost the current article to some other group."
9099   (interactive "P")
9100   (gnus-summary-move-article n nil nil 'crosspost))
9101
9102 (defcustom gnus-summary-respool-default-method nil
9103   "Default method type for respooling an article.
9104 If nil, use to the current newsgroup method."
9105   :type 'symbol
9106   :group 'gnus-summary-mail)
9107
9108 (defcustom gnus-summary-display-while-building nil
9109   "If not-nil, show and update the summary buffer as it's being built.
9110 If the value is t, update the buffer after every line is inserted.  If
9111 the value is an integer (N), update the display every N lines."
9112   :group 'gnus-thread
9113   :type '(choice (const :tag "off" nil)
9114                  number
9115                  (const :tag "frequently" t)))
9116
9117 (defun gnus-summary-respool-article (&optional n method)
9118   "Respool the current article.
9119 The article will be squeezed through the mail spooling process again,
9120 which means that it will be put in some mail newsgroup or other
9121 depending on `nnmail-split-methods'.
9122 If N is a positive number, respool the N next articles.
9123 If N is a negative number, respool the N previous articles.
9124 If N is nil and any articles have been marked with the process mark,
9125 respool those articles instead.
9126
9127 Respooling can be done both from mail groups and \"real\" newsgroups.
9128 In the former case, the articles in question will be moved from the
9129 current group into whatever groups they are destined to.  In the
9130 latter case, they will be copied into the relevant groups."
9131   (interactive
9132    (list current-prefix-arg
9133          (let* ((methods (gnus-methods-using 'respool))
9134                 (methname
9135                  (symbol-name (or gnus-summary-respool-default-method
9136                                   (car (gnus-find-method-for-group
9137                                         gnus-newsgroup-name)))))
9138                 (method
9139                  (gnus-completing-read-with-default
9140                   methname "What backend do you want to use when respooling?"
9141                   methods nil t nil 'gnus-mail-method-history))
9142                 ms)
9143            (cond
9144             ((zerop (length (setq ms (gnus-servers-using-backend
9145                                       (intern method)))))
9146              (list (intern method) ""))
9147             ((= 1 (length ms))
9148              (car ms))
9149             (t
9150              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9151                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9152                            ms-alist))))))))
9153   (unless method
9154     (error "No method given for respooling"))
9155   (if (assoc (symbol-name
9156               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9157              (gnus-methods-using 'respool))
9158       (gnus-summary-move-article n nil method)
9159     (gnus-summary-copy-article n nil method)))
9160
9161 (defun gnus-summary-import-article (file &optional edit)
9162   "Import an arbitrary file into a mail newsgroup."
9163   (interactive "fImport file: \nP")
9164   (let ((group gnus-newsgroup-name)
9165         (now (current-time))
9166         atts lines group-art)
9167     (unless (gnus-check-backend-function 'request-accept-article group)
9168       (error "%s does not support article importing" group))
9169     (or (file-readable-p file)
9170         (not (file-regular-p file))
9171         (error "Can't read %s" file))
9172     (save-excursion
9173       (set-buffer (gnus-get-buffer-create " *import file*"))
9174       (erase-buffer)
9175       (nnheader-insert-file-contents file)
9176       (goto-char (point-min))
9177       (if (nnheader-article-p)
9178           (save-restriction
9179             (goto-char (point-min))
9180             (search-forward "\n\n" nil t)
9181             (narrow-to-region (point-min) (1- (point)))
9182             (goto-char (point-min))
9183             (unless (re-search-forward "^date:" nil t)
9184               (goto-char (point-max))
9185               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9186         ;; This doesn't look like an article, so we fudge some headers.
9187         (setq atts (file-attributes file)
9188               lines (count-lines (point-min) (point-max)))
9189         (insert "From: " (read-string "From: ") "\n"
9190                 "Subject: " (read-string "Subject: ") "\n"
9191                 "Date: " (message-make-date (nth 5 atts)) "\n"
9192                 "Message-ID: " (message-make-message-id) "\n"
9193                 "Lines: " (int-to-string lines) "\n"
9194                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9195       (setq group-art (gnus-request-accept-article group nil t))
9196       (kill-buffer (current-buffer)))
9197     (setq gnus-newsgroup-active (gnus-activate-group group))
9198     (forward-line 1)
9199     (gnus-summary-goto-article (cdr group-art) nil t)
9200     (when edit
9201       (gnus-summary-edit-article))))
9202
9203 (defun gnus-summary-create-article ()
9204   "Create an article in a mail newsgroup."
9205   (interactive)
9206   (let ((group gnus-newsgroup-name)
9207         (now (current-time))
9208         group-art)
9209     (unless (gnus-check-backend-function 'request-accept-article group)
9210       (error "%s does not support article importing" group))
9211     (save-excursion
9212       (set-buffer (gnus-get-buffer-create " *import file*"))
9213       (erase-buffer)
9214       (goto-char (point-min))
9215       ;; This doesn't look like an article, so we fudge some headers.
9216       (insert "From: " (read-string "From: ") "\n"
9217               "Subject: " (read-string "Subject: ") "\n"
9218               "Date: " (message-make-date now) "\n"
9219               "Message-ID: " (message-make-message-id) "\n")
9220       (setq group-art (gnus-request-accept-article group nil t))
9221       (kill-buffer (current-buffer)))
9222     (setq gnus-newsgroup-active (gnus-activate-group group))
9223     (forward-line 1)
9224     (gnus-summary-goto-article (cdr group-art) nil t)
9225     (gnus-summary-edit-article)))
9226
9227 (defun gnus-summary-article-posted-p ()
9228   "Say whether the current (mail) article is available from news as well.
9229 This will be the case if the article has both been mailed and posted."
9230   (interactive)
9231   (let ((id (mail-header-references (gnus-summary-article-header)))
9232         (gnus-override-method (car (gnus-refer-article-methods))))
9233     (if (gnus-request-head id "")
9234         (gnus-message 2 "The current message was found on %s"
9235                       gnus-override-method)
9236       (gnus-message 2 "The current message couldn't be found on %s"
9237                     gnus-override-method)
9238       nil)))
9239
9240 (defun gnus-summary-expire-articles (&optional now)
9241   "Expire all articles that are marked as expirable in the current group."
9242   (interactive)
9243   (when (and (not gnus-group-is-exiting-without-update-p)
9244              (gnus-check-backend-function
9245               'request-expire-articles gnus-newsgroup-name))
9246     ;; This backend supports expiry.
9247     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9248            (expirable (if total
9249                           (progn
9250                             ;; We need to update the info for
9251                             ;; this group for `gnus-list-of-read-articles'
9252                             ;; to give us the right answer.
9253                             (gnus-run-hooks 'gnus-exit-group-hook)
9254                             (gnus-summary-update-info)
9255                             (gnus-list-of-read-articles gnus-newsgroup-name))
9256                         (setq gnus-newsgroup-expirable
9257                               (sort gnus-newsgroup-expirable '<))))
9258            (expiry-wait (if now 'immediate
9259                           (gnus-group-find-parameter
9260                            gnus-newsgroup-name 'expiry-wait)))
9261            (nnmail-expiry-target
9262             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9263                 nnmail-expiry-target))
9264            es)
9265       (when expirable
9266         ;; There are expirable articles in this group, so we run them
9267         ;; through the expiry process.
9268         (gnus-message 6 "Expiring articles...")
9269         (unless (gnus-check-group gnus-newsgroup-name)
9270           (error "Can't open server for %s" gnus-newsgroup-name))
9271         ;; The list of articles that weren't expired is returned.
9272         (save-excursion
9273           (if expiry-wait
9274               (let ((nnmail-expiry-wait-function nil)
9275                     (nnmail-expiry-wait expiry-wait))
9276                 (setq es (gnus-request-expire-articles
9277                           expirable gnus-newsgroup-name)))
9278             (setq es (gnus-request-expire-articles
9279                       expirable gnus-newsgroup-name)))
9280           (unless total
9281             (setq gnus-newsgroup-expirable es))
9282           ;; We go through the old list of expirable, and mark all
9283           ;; really expired articles as nonexistent.
9284           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9285             (let ((gnus-use-cache nil))
9286               (dolist (article expirable)
9287                 (when (and (not (memq article es))
9288                            (gnus-data-find article))
9289                   (gnus-summary-mark-article article gnus-canceled-mark)
9290                   (run-hook-with-args 'gnus-summary-article-expire-hook
9291                                       'delete
9292                                       (gnus-data-header
9293                                        (assoc article (gnus-data-list nil)))
9294                                       gnus-newsgroup-name
9295                                       nil
9296                                       nil))))))
9297         (gnus-message 6 "Expiring articles...done")))))
9298
9299 (defun gnus-summary-expire-articles-now ()
9300   "Expunge all expirable articles in the current group.
9301 This means that *all* articles that are marked as expirable will be
9302 deleted forever, right now."
9303   (interactive)
9304   (or gnus-expert-user
9305       (gnus-yes-or-no-p
9306        "Are you really, really, really sure you want to delete all these messages? ")
9307       (error "Phew!"))
9308   (gnus-summary-expire-articles t))
9309
9310 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9311 (defun gnus-summary-delete-article (&optional n)
9312   "Delete the N next (mail) articles.
9313 This command actually deletes articles.  This is not a marking
9314 command.  The article will disappear forever from your life, never to
9315 return.
9316 If N is negative, delete backwards.
9317 If N is nil and articles have been marked with the process mark,
9318 delete these instead."
9319   (interactive "P")
9320   (unless (gnus-check-backend-function 'request-expire-articles
9321                                        gnus-newsgroup-name)
9322     (error "The current newsgroup does not support article deletion"))
9323   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9324     (error "Couldn't open server"))
9325   ;; Compute the list of articles to delete.
9326   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9327         (nnmail-expiry-target 'delete)
9328         not-deleted)
9329     (if (and gnus-novice-user
9330              (not (gnus-yes-or-no-p
9331                    (format "Do you really want to delete %s forever? "
9332                            (if (> (length articles) 1)
9333                                (format "these %s articles" (length articles))
9334                              "this article")))))
9335         ()
9336       ;; Delete the articles.
9337       (setq not-deleted (gnus-request-expire-articles
9338                          articles gnus-newsgroup-name 'force))
9339       (while articles
9340         (gnus-summary-remove-process-mark (car articles))
9341         ;; The backend might not have been able to delete the article
9342         ;; after all.
9343         (unless (memq (car articles) not-deleted)
9344           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9345         (let* ((article (car articles))
9346                (id (mail-header-id (gnus-data-header 
9347                                     (assoc article (gnus-data-list nil))))))
9348           (run-hook-with-args 'gnus-summary-article-delete-hook
9349                               'delete id gnus-newsgroup-name nil
9350                               nil))
9351         (setq articles (cdr articles)))
9352       (when not-deleted
9353         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9354     (gnus-summary-position-point)
9355     (gnus-set-mode-line 'summary)
9356     not-deleted))
9357
9358 (defun gnus-summary-edit-article (&optional force)
9359   "Edit the current article.
9360 This will have permanent effect only in mail groups.
9361 If FORCE is non-nil, allow editing of articles even in read-only
9362 groups."
9363   (interactive "P")
9364   (save-excursion
9365     (set-buffer gnus-summary-buffer)
9366     (let ((mail-parse-charset gnus-newsgroup-charset)
9367           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9368       (gnus-set-global-variables)
9369       (when (and (not force)
9370                  (gnus-group-read-only-p))
9371         (error "The current newsgroup does not support article editing"))
9372       (gnus-summary-show-article t)
9373       (gnus-article-edit-article
9374        'ignore
9375        `(lambda (no-highlight)
9376           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9377                 (message-options message-options)
9378                 (message-options-set-recipient)
9379                 (mail-parse-ignored-charsets
9380                  ',gnus-newsgroup-ignored-charsets))
9381             (gnus-summary-edit-article-done
9382              ,(or (mail-header-references gnus-current-headers) "")
9383              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9384
9385 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9386
9387 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9388                                                  no-highlight)
9389   "Make edits to the current article permanent."
9390   (interactive)
9391   (save-excursion
9392     ;; The buffer restriction contains the entire article if it exists.
9393     (when (article-goto-body)
9394       (let ((lines (count-lines (point) (point-max)))
9395             (length (- (point-max) (point)))
9396             (case-fold-search t)
9397             (body (copy-marker (point))))
9398         (goto-char (point-min))
9399         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9400           (delete-region (match-beginning 1) (match-end 1))
9401           (insert (number-to-string length)))
9402         (goto-char (point-min))
9403         (when (re-search-forward
9404                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9405           (delete-region (match-beginning 1) (match-end 1))
9406           (insert (number-to-string length)))
9407         (goto-char (point-min))
9408         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9409           (delete-region (match-beginning 1) (match-end 1))
9410           (insert (number-to-string lines))))))
9411   ;; Replace the article.
9412   (let ((buf (current-buffer)))
9413     (with-temp-buffer
9414       (insert-buffer-substring buf)
9415
9416       (if (and (not read-only)
9417                (not (gnus-request-replace-article
9418                      (cdr gnus-article-current) (car gnus-article-current)
9419                      (current-buffer) t)))
9420           (error "Couldn't replace article")
9421         ;; Update the summary buffer.
9422         (if (and references
9423                  (equal (message-tokenize-header references " ")
9424                         (message-tokenize-header
9425                          (or (message-fetch-field "references") "") " ")))
9426             ;; We only have to update this line.
9427             (save-excursion
9428               (save-restriction
9429                 (message-narrow-to-head)
9430                 (let ((head (buffer-string))
9431                       header)
9432                   (with-temp-buffer
9433                     (insert (format "211 %d Article retrieved.\n"
9434                                     (cdr gnus-article-current)))
9435                     (insert head)
9436                     (insert ".\n")
9437                     (let ((nntp-server-buffer (current-buffer)))
9438                       (setq header (car (gnus-get-newsgroup-headers
9439                                          nil t))))
9440                     (save-excursion
9441                       (set-buffer gnus-summary-buffer)
9442                       (gnus-data-set-header
9443                        (gnus-data-find (cdr gnus-article-current))
9444                        header)
9445                       (gnus-summary-update-article-line
9446                        (cdr gnus-article-current) header)
9447                       (if (gnus-summary-goto-subject
9448                            (cdr gnus-article-current) nil t)
9449                           (gnus-summary-update-secondary-mark
9450                            (cdr gnus-article-current))))))))
9451           ;; Update threads.
9452           (set-buffer (or buffer gnus-summary-buffer))
9453           (gnus-summary-update-article (cdr gnus-article-current))
9454           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9455               (gnus-summary-update-secondary-mark
9456                (cdr gnus-article-current))))
9457         ;; Prettify the article buffer again.
9458         (unless no-highlight
9459           (save-excursion
9460             (set-buffer gnus-article-buffer)
9461             ;;;!!! Fix this -- article should be rehighlighted.
9462             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9463             (set-buffer gnus-original-article-buffer)
9464             (gnus-request-article
9465              (cdr gnus-article-current)
9466              (car gnus-article-current) (current-buffer))))
9467         ;; Prettify the summary buffer line.
9468         (when (gnus-visual-p 'summary-highlight 'highlight)
9469           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9470
9471 (defun gnus-summary-edit-wash (key)
9472   "Perform editing command KEY in the article buffer."
9473   (interactive
9474    (list
9475     (progn
9476       (message "%s" (concat (this-command-keys) "- "))
9477       (read-char))))
9478   (message "")
9479   (gnus-summary-edit-article)
9480   (execute-kbd-macro (concat (this-command-keys) key))
9481   (gnus-article-edit-done))
9482
9483 ;;; Respooling
9484
9485 (defun gnus-summary-respool-query (&optional silent trace)
9486   "Query where the respool algorithm would put this article."
9487   (interactive)
9488   (let (gnus-mark-article-hook)
9489     (gnus-summary-select-article)
9490     (save-excursion
9491       (set-buffer gnus-original-article-buffer)
9492       (save-restriction
9493         (message-narrow-to-head)
9494         (let ((groups (nnmail-article-group 'identity trace)))
9495           (unless silent
9496             (if groups
9497                 (message "This message would go to %s"
9498                          (mapconcat 'car groups ", "))
9499               (message "This message would go to no groups"))
9500             groups))))))
9501
9502 (defun gnus-summary-respool-trace ()
9503   "Trace where the respool algorithm would put this article.
9504 Display a buffer showing all fancy splitting patterns which matched."
9505   (interactive)
9506   (gnus-summary-respool-query nil t))
9507
9508 ;; Summary marking commands.
9509
9510 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9511   "Mark articles which has the same subject as read, and then select the next.
9512 If UNMARK is positive, remove any kind of mark.
9513 If UNMARK is negative, tick articles."
9514   (interactive "P")
9515   (when unmark
9516     (setq unmark (prefix-numeric-value unmark)))
9517   (let ((count
9518          (gnus-summary-mark-same-subject
9519           (gnus-summary-article-subject) unmark)))
9520     ;; Select next unread article.  If auto-select-same mode, should
9521     ;; select the first unread article.
9522     (gnus-summary-next-article t (and gnus-auto-select-same
9523                                       (gnus-summary-article-subject)))
9524     (gnus-message 7 "%d article%s marked as %s"
9525                   count (if (= count 1) " is" "s are")
9526                   (if unmark "unread" "read"))))
9527
9528 (defun gnus-summary-kill-same-subject (&optional unmark)
9529   "Mark articles which has the same subject as read.
9530 If UNMARK is positive, remove any kind of mark.
9531 If UNMARK is negative, tick articles."
9532   (interactive "P")
9533   (when unmark
9534     (setq unmark (prefix-numeric-value unmark)))
9535   (let ((count
9536          (gnus-summary-mark-same-subject
9537           (gnus-summary-article-subject) unmark)))
9538     ;; If marked as read, go to next unread subject.
9539     (when (null unmark)
9540       ;; Go to next unread subject.
9541       (gnus-summary-next-subject 1 t))
9542     (gnus-message 7 "%d articles are marked as %s"
9543                   count (if unmark "unread" "read"))))
9544
9545 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9546   "Mark articles with same SUBJECT as read, and return marked number.
9547 If optional argument UNMARK is positive, remove any kinds of marks.
9548 If optional argument UNMARK is negative, mark articles as unread instead."
9549   (let ((count 1))
9550     (save-excursion
9551       (cond
9552        ((null unmark)                   ; Mark as read.
9553         (while (and
9554                 (progn
9555                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9556                   (gnus-summary-show-thread) t)
9557                 (gnus-summary-find-subject subject))
9558           (setq count (1+ count))))
9559        ((> unmark 0)                    ; Tick.
9560         (while (and
9561                 (progn
9562                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9563                   (gnus-summary-show-thread) t)
9564                 (gnus-summary-find-subject subject))
9565           (setq count (1+ count))))
9566        (t                               ; Mark as unread.
9567         (while (and
9568                 (progn
9569                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9570                   (gnus-summary-show-thread) t)
9571                 (gnus-summary-find-subject subject))
9572           (setq count (1+ count)))))
9573       (gnus-set-mode-line 'summary)
9574       ;; Return the number of marked articles.
9575       count)))
9576
9577 (defun gnus-summary-mark-as-processable (n &optional unmark)
9578   "Set the process mark on the next N articles.
9579 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9580 the process mark instead.  The difference between N and the actual
9581 number of articles marked is returned."
9582   (interactive "P")
9583   (if (and (null n) (gnus-region-active-p))
9584       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9585     (setq n (prefix-numeric-value n))
9586     (let ((backward (< n 0))
9587           (n (abs n)))
9588       (while (and
9589               (> n 0)
9590               (if unmark
9591                   (gnus-summary-remove-process-mark
9592                    (gnus-summary-article-number))
9593                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9594               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9595         (setq n (1- n)))
9596       (when (/= 0 n)
9597         (gnus-message 7 "No more articles"))
9598       (gnus-summary-recenter)
9599       (gnus-summary-position-point)
9600       n)))
9601
9602 (defun gnus-summary-unmark-as-processable (n)
9603   "Remove the process mark from the next N articles.
9604 If N is negative, unmark backward instead.  The difference between N and
9605 the actual number of articles unmarked is returned."
9606   (interactive "P")
9607   (gnus-summary-mark-as-processable n t))
9608
9609 (defun gnus-summary-unmark-all-processable ()
9610   "Remove the process mark from all articles."
9611   (interactive)
9612   (save-excursion
9613     (while gnus-newsgroup-processable
9614       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9615   (gnus-summary-position-point))
9616
9617 (defun gnus-summary-add-mark (article type)
9618   "Mark ARTICLE with a mark of TYPE."
9619   (let ((vtype (car (assq type gnus-article-mark-lists)))
9620         var)
9621     (if (not vtype)
9622         (error "No such mark type: %s" type)
9623       (setq var (intern (format "gnus-newsgroup-%s" type)))
9624       (set var (cons article (symbol-value var)))
9625       (if (memq type '(processable cached replied forwarded recent saved))
9626           (gnus-summary-update-secondary-mark article)
9627         ;;; !!! This is bogus.  We should find out what primary
9628         ;;; !!! mark we want to set.
9629         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9630
9631 (defun gnus-summary-mark-as-expirable (n)
9632   "Mark N articles forward as expirable.
9633 If N is negative, mark backward instead.  The difference between N and
9634 the actual number of articles marked is returned."
9635   (interactive "p")
9636   (gnus-summary-mark-forward n gnus-expirable-mark))
9637
9638 (defun gnus-summary-mark-as-spam (n)
9639   "Mark N articles forward as spam.
9640 If N is negative, mark backward instead.  The difference between N and
9641 the actual number of articles marked is returned."
9642   (interactive "p")
9643   (gnus-summary-mark-forward n gnus-spam-mark))
9644
9645 (defun gnus-summary-mark-article-as-replied (article)
9646   "Mark ARTICLE as replied to and update the summary line.
9647 ARTICLE can also be a list of articles."
9648   (interactive (list (gnus-summary-article-number)))
9649   (let ((articles (if (listp article) article (list article))))
9650     (dolist (article articles)
9651       (unless (numberp article)
9652         (error "%s is not a number" article))
9653       (push article gnus-newsgroup-replied)
9654       (let ((buffer-read-only nil))
9655         (when (gnus-summary-goto-subject article nil t)
9656           (gnus-summary-update-secondary-mark article))))))
9657
9658 (defun gnus-summary-mark-article-as-forwarded (article)
9659   "Mark ARTICLE as forwarded and update the summary line.
9660 ARTICLE can also be a list of articles."
9661   (let ((articles (if (listp article) article (list article))))
9662     (dolist (article articles)
9663       (push article gnus-newsgroup-forwarded)
9664       (let ((buffer-read-only nil))
9665         (when (gnus-summary-goto-subject article nil t)
9666           (gnus-summary-update-secondary-mark article))))))
9667
9668 (defun gnus-summary-set-bookmark (article)
9669   "Set a bookmark in current article."
9670   (interactive (list (gnus-summary-article-number)))
9671   (when (or (not (get-buffer gnus-article-buffer))
9672             (not gnus-current-article)
9673             (not gnus-article-current)
9674             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9675     (error "No current article selected"))
9676   ;; Remove old bookmark, if one exists.
9677   (gnus-pull article gnus-newsgroup-bookmarks)
9678   ;; Set the new bookmark, which is on the form
9679   ;; (article-number . line-number-in-body).
9680   (push
9681    (cons article
9682          (save-excursion
9683            (set-buffer gnus-article-buffer)
9684            (count-lines
9685             (min (point)
9686                  (save-excursion
9687                    (article-goto-body)
9688                    (point)))
9689             (point))))
9690    gnus-newsgroup-bookmarks)
9691   (gnus-message 6 "A bookmark has been added to the current article."))
9692
9693 (defun gnus-summary-remove-bookmark (article)
9694   "Remove the bookmark from the current article."
9695   (interactive (list (gnus-summary-article-number)))
9696   ;; Remove old bookmark, if one exists.
9697   (if (not (assq article gnus-newsgroup-bookmarks))
9698       (gnus-message 6 "No bookmark in current article.")
9699     (gnus-pull article gnus-newsgroup-bookmarks)
9700     (gnus-message 6 "Removed bookmark.")))
9701
9702 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9703 (defun gnus-summary-mark-as-dormant (n)
9704   "Mark N articles forward as dormant.
9705 If N is negative, mark backward instead.  The difference between N and
9706 the actual number of articles marked is returned."
9707   (interactive "p")
9708   (gnus-summary-mark-forward n gnus-dormant-mark))
9709
9710 (defun gnus-summary-set-process-mark (article)
9711   "Set the process mark on ARTICLE and update the summary line."
9712   (setq gnus-newsgroup-processable
9713         (cons article
9714               (delq article gnus-newsgroup-processable)))
9715   (when (gnus-summary-goto-subject article)
9716     (gnus-summary-show-thread)
9717     (gnus-summary-goto-subject article)
9718     (gnus-summary-update-secondary-mark article)))
9719
9720 (defun gnus-summary-remove-process-mark (article)
9721   "Remove the process mark from ARTICLE and update the summary line."
9722   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9723   (when (gnus-summary-goto-subject article)
9724     (gnus-summary-show-thread)
9725     (gnus-summary-goto-subject article)
9726     (gnus-summary-update-secondary-mark article)))
9727
9728 (defun gnus-summary-set-saved-mark (article)
9729   "Set the process mark on ARTICLE and update the summary line."
9730   (push article gnus-newsgroup-saved)
9731   (when (gnus-summary-goto-subject article)
9732     (gnus-summary-update-secondary-mark article)))
9733
9734 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9735   "Mark N articles as read forwards.
9736 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9737 The difference between N and the actual number of articles marked is
9738 returned.
9739 If NO-EXPIRE, auto-expiry will be inhibited."
9740   (interactive "p")
9741   (gnus-summary-show-thread)
9742   (let ((backward (< n 0))
9743         (gnus-summary-goto-unread
9744          (and gnus-summary-goto-unread
9745               (not (eq gnus-summary-goto-unread 'never))
9746               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9747                                     gnus-ticked-mark gnus-dormant-mark)))))
9748         (n (abs n))
9749         (mark (or mark gnus-del-mark)))
9750     (while (and (> n 0)
9751                 (gnus-summary-mark-article nil mark no-expire)
9752                 (zerop (gnus-summary-next-subject
9753                         (if backward -1 1)
9754                         (and gnus-summary-goto-unread
9755                              (not (eq gnus-summary-goto-unread 'never)))
9756                         t)))
9757       (setq n (1- n)))
9758     (when (/= 0 n)
9759       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9760     (gnus-summary-recenter)
9761     (gnus-summary-position-point)
9762     (gnus-set-mode-line 'summary)
9763     n))
9764
9765 (defun gnus-summary-mark-article-as-read (mark)
9766   "Mark the current article quickly as read with MARK."
9767   (let ((article (gnus-summary-article-number)))
9768     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9769     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9770     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9771     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9772     (push (cons article mark) gnus-newsgroup-reads)
9773     ;; Possibly remove from cache, if that is used.
9774     (when gnus-use-cache
9775       (gnus-cache-enter-remove-article article))
9776     ;; Allow the backend to change the mark.
9777     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9778     ;; Check for auto-expiry.
9779     (when (and gnus-newsgroup-auto-expire
9780                (memq mark gnus-auto-expirable-marks))
9781       (setq mark gnus-expirable-mark)
9782       ;; Let the backend know about the mark change.
9783       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9784       (push article gnus-newsgroup-expirable))
9785     ;; Set the mark in the buffer.
9786     (gnus-summary-update-mark mark 'unread)
9787     t))
9788
9789 (defun gnus-summary-mark-article-as-unread (mark)
9790   "Mark the current article quickly as unread with MARK."
9791   (let* ((article (gnus-summary-article-number))
9792          (old-mark (gnus-summary-article-mark article)))
9793     ;; Allow the backend to change the mark.
9794     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9795     (if (eq mark old-mark)
9796         t
9797       (if (<= article 0)
9798           (progn
9799             (gnus-error 1 "Can't mark negative article numbers")
9800             nil)
9801         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9802         (setq gnus-newsgroup-spam-marked
9803               (delq article gnus-newsgroup-spam-marked))
9804         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9805         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9806         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9807         (cond ((= mark gnus-ticked-mark)
9808                (setq gnus-newsgroup-marked
9809                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9810                                               article)))
9811               ((= mark gnus-spam-mark)
9812                (setq gnus-newsgroup-spam-marked
9813                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9814                                               article)))
9815               ((= mark gnus-dormant-mark)
9816                (setq gnus-newsgroup-dormant
9817                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9818                                               article)))
9819               (t
9820                (setq gnus-newsgroup-unreads
9821                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9822                                               article))))
9823         (gnus-pull article gnus-newsgroup-reads)
9824
9825         ;; See whether the article is to be put in the cache.
9826         (and gnus-use-cache
9827              (vectorp (gnus-summary-article-header article))
9828              (save-excursion
9829                (gnus-cache-possibly-enter-article
9830                 gnus-newsgroup-name article
9831                 (gnus-summary-article-header article)
9832                 (= mark gnus-ticked-mark)
9833                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9834
9835         ;; Fix the mark.
9836         (gnus-summary-update-mark mark 'unread)
9837         t))))
9838
9839 (defun gnus-summary-mark-article (&optional article mark no-expire)
9840   "Mark ARTICLE with MARK.  MARK can be any character.
9841 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9842 `??' (dormant) and `?E' (expirable).
9843 If MARK is nil, then the default character `?r' is used.
9844 If ARTICLE is nil, then the article on the current line will be
9845 marked.
9846 If NO-EXPIRE, auto-expiry will be inhibited."
9847   ;; The mark might be a string.
9848   (when (stringp mark)
9849     (setq mark (aref mark 0)))
9850   ;; If no mark is given, then we check auto-expiring.
9851   (when (null mark)
9852     (setq mark gnus-del-mark))
9853   (when (and (not no-expire)
9854              gnus-newsgroup-auto-expire
9855              (memq mark gnus-auto-expirable-marks))
9856     (setq mark gnus-expirable-mark))
9857   (let ((article (or article (gnus-summary-article-number)))
9858         (old-mark (gnus-summary-article-mark article)))
9859     ;; Allow the backend to change the mark.
9860     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9861     (if (eq mark old-mark)
9862         t
9863       (unless article
9864         (error "No article on current line"))
9865       (if (not (if (or (= mark gnus-unread-mark)
9866                        (= mark gnus-ticked-mark)
9867                        (= mark gnus-spam-mark)
9868                        (= mark gnus-dormant-mark))
9869                    (gnus-mark-article-as-unread article mark)
9870                  (gnus-mark-article-as-read article mark)))
9871           t
9872         ;; See whether the article is to be put in the cache.
9873         (and gnus-use-cache
9874              (not (= mark gnus-canceled-mark))
9875              (vectorp (gnus-summary-article-header article))
9876              (save-excursion
9877                (gnus-cache-possibly-enter-article
9878                 gnus-newsgroup-name article
9879                 (gnus-summary-article-header article)
9880                 (= mark gnus-ticked-mark)
9881                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9882
9883         (when (gnus-summary-goto-subject article nil t)
9884           (let ((buffer-read-only nil))
9885             (gnus-summary-show-thread)
9886             ;; Fix the mark.
9887             (gnus-summary-update-mark mark 'unread)
9888             t))))))
9889
9890 (defun gnus-summary-update-secondary-mark (article)
9891   "Update the secondary (read, process, cache) mark."
9892   (gnus-summary-update-mark
9893    (cond ((memq article gnus-newsgroup-processable)
9894           gnus-process-mark)
9895          ((memq article gnus-newsgroup-cached)
9896           gnus-cached-mark)
9897          ((memq article gnus-newsgroup-replied)
9898           gnus-replied-mark)
9899          ((memq article gnus-newsgroup-forwarded)
9900           gnus-forwarded-mark)
9901          ((memq article gnus-newsgroup-saved)
9902           gnus-saved-mark)
9903          ((memq article gnus-newsgroup-recent)
9904           gnus-recent-mark)
9905          ((memq article gnus-newsgroup-unseen)
9906           gnus-unseen-mark)
9907          (t gnus-no-mark))
9908    'replied)
9909   (when (gnus-visual-p 'summary-highlight 'highlight)
9910     (gnus-run-hooks 'gnus-summary-update-hook))
9911   t)
9912
9913 (defun gnus-summary-update-download-mark (article)
9914   "Update the download mark."
9915   (gnus-summary-update-mark
9916    (cond ((memq article gnus-newsgroup-undownloaded) 
9917           gnus-undownloaded-mark)
9918          (gnus-newsgroup-agentized
9919           gnus-downloaded-mark)
9920          (t
9921           gnus-no-mark))
9922    'download)
9923   (gnus-summary-update-line t)
9924   t)
9925
9926 (defun gnus-summary-update-mark (mark type)
9927   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9928         (buffer-read-only nil))
9929     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9930     (when forward
9931       (when (looking-at "\r")
9932         (incf forward))
9933       (when (<= (+ forward (point)) (point-max))
9934         ;; Go to the right position on the line.
9935         (goto-char (+ forward (point)))
9936         ;; Replace the old mark with the new mark.
9937         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9938         ;; Optionally update the marks by some user rule.
9939         (when (eq type 'unread)
9940           (gnus-data-set-mark
9941            (gnus-data-find (gnus-summary-article-number)) mark)
9942           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9943
9944 (defun gnus-mark-article-as-read (article &optional mark)
9945   "Enter ARTICLE in the pertinent lists and remove it from others."
9946   ;; Make the article expirable.
9947   (let ((mark (or mark gnus-del-mark)))
9948     (setq gnus-newsgroup-expirable
9949           (if (= mark gnus-expirable-mark)
9950               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9951             (delq article gnus-newsgroup-expirable)))
9952     ;; Remove from unread and marked lists.
9953     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9954     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9955     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9956     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9957     (push (cons article mark) gnus-newsgroup-reads)
9958     ;; Possibly remove from cache, if that is used.
9959     (when gnus-use-cache
9960       (gnus-cache-enter-remove-article article))
9961     t))
9962
9963 (defun gnus-mark-article-as-unread (article &optional mark)
9964   "Enter ARTICLE in the pertinent lists and remove it from others."
9965   (let ((mark (or mark gnus-ticked-mark)))
9966     (if (<= article 0)
9967         (progn
9968           (gnus-error 1 "Can't mark negative article numbers")
9969           nil)
9970       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9971             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9972             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9973             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9974             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9975
9976       ;; Unsuppress duplicates?
9977       (when gnus-suppress-duplicates
9978         (gnus-dup-unsuppress-article article))
9979
9980       (cond ((= mark gnus-ticked-mark)
9981              (setq gnus-newsgroup-marked
9982                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9983             ((= mark gnus-spam-mark)
9984              (setq gnus-newsgroup-spam-marked
9985                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9986                                             article)))
9987             ((= mark gnus-dormant-mark)
9988              (setq gnus-newsgroup-dormant
9989                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9990             (t
9991              (setq gnus-newsgroup-unreads
9992                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9993       (gnus-pull article gnus-newsgroup-reads)
9994       t)))
9995
9996 (defalias 'gnus-summary-mark-as-unread-forward
9997   'gnus-summary-tick-article-forward)
9998 (make-obsolete 'gnus-summary-mark-as-unread-forward
9999                'gnus-summary-tick-article-forward)
10000 (defun gnus-summary-tick-article-forward (n)
10001   "Tick N articles forwards.
10002 If N is negative, tick backwards instead.
10003 The difference between N and the number of articles ticked is returned."
10004   (interactive "p")
10005   (gnus-summary-mark-forward n gnus-ticked-mark))
10006
10007 (defalias 'gnus-summary-mark-as-unread-backward
10008   'gnus-summary-tick-article-backward)
10009 (make-obsolete 'gnus-summary-mark-as-unread-backward
10010                'gnus-summary-tick-article-backward)
10011 (defun gnus-summary-tick-article-backward (n)
10012   "Tick N articles backwards.
10013 The difference between N and the number of articles ticked is returned."
10014   (interactive "p")
10015   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10016
10017 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10018 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10019 (defun gnus-summary-tick-article (&optional article clear-mark)
10020   "Mark current article as unread.
10021 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10022 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10023   (interactive)
10024   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10025                                        gnus-ticked-mark)))
10026
10027 (defun gnus-summary-mark-as-read-forward (n)
10028   "Mark N articles as read forwards.
10029 If N is negative, mark backwards instead.
10030 The difference between N and the actual number of articles marked is
10031 returned."
10032   (interactive "p")
10033   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10034
10035 (defun gnus-summary-mark-as-read-backward (n)
10036   "Mark the N articles as read backwards.
10037 The difference between N and the actual number of articles marked is
10038 returned."
10039   (interactive "p")
10040   (gnus-summary-mark-forward
10041    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10042
10043 (defun gnus-summary-mark-as-read (&optional article mark)
10044   "Mark current article as read.
10045 ARTICLE specifies the article to be marked as read.
10046 MARK specifies a string to be inserted at the beginning of the line."
10047   (gnus-summary-mark-article article mark))
10048
10049 (defun gnus-summary-clear-mark-forward (n)
10050   "Clear marks from N articles forward.
10051 If N is negative, clear backward instead.
10052 The difference between N and the number of marks cleared is returned."
10053   (interactive "p")
10054   (gnus-summary-mark-forward n gnus-unread-mark))
10055
10056 (defun gnus-summary-clear-mark-backward (n)
10057   "Clear marks from N articles backward.
10058 The difference between N and the number of marks cleared is returned."
10059   (interactive "p")
10060   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10061
10062 (defun gnus-summary-mark-unread-as-read ()
10063   "Intended to be used by `gnus-summary-mark-article-hook'."
10064   (when (memq gnus-current-article gnus-newsgroup-unreads)
10065     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10066
10067 (defun gnus-summary-mark-read-and-unread-as-read ()
10068   "Intended to be used by `gnus-summary-mark-article-hook'."
10069   (let ((mark (gnus-summary-article-mark)))
10070     (when (or (gnus-unread-mark-p mark)
10071               (gnus-read-mark-p mark))
10072       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
10073
10074 (defun gnus-summary-mark-unread-as-ticked ()
10075   "Intended to be used by `gnus-summary-mark-article-hook'."
10076   (when (memq gnus-current-article gnus-newsgroup-unreads)
10077     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10078
10079 (defun gnus-summary-mark-region-as-read (point mark all)
10080   "Mark all unread articles between point and mark as read.
10081 If given a prefix, mark all articles between point and mark as read,
10082 even ticked and dormant ones."
10083   (interactive "r\nP")
10084   (save-excursion
10085     (let (article)
10086       (goto-char point)
10087       (beginning-of-line)
10088       (while (and
10089               (< (point) mark)
10090               (progn
10091                 (when (or all
10092                           (memq (setq article (gnus-summary-article-number))
10093                                 gnus-newsgroup-unreads))
10094                   (gnus-summary-mark-article article gnus-del-mark))
10095                 t)
10096               (gnus-summary-find-next))))))
10097
10098 (defun gnus-summary-mark-below (score mark)
10099   "Mark articles with score less than SCORE with MARK."
10100   (interactive "P\ncMark: ")
10101   (setq score (if score
10102                   (prefix-numeric-value score)
10103                 (or gnus-summary-default-score 0)))
10104   (save-excursion
10105     (set-buffer gnus-summary-buffer)
10106     (goto-char (point-min))
10107     (while
10108         (progn
10109           (and (< (gnus-summary-article-score) score)
10110                (gnus-summary-mark-article nil mark))
10111           (gnus-summary-find-next)))))
10112
10113 (defun gnus-summary-kill-below (&optional score)
10114   "Mark articles with score below SCORE as read."
10115   (interactive "P")
10116   (gnus-summary-mark-below score gnus-killed-mark))
10117
10118 (defun gnus-summary-clear-above (&optional score)
10119   "Clear all marks from articles with score above SCORE."
10120   (interactive "P")
10121   (gnus-summary-mark-above score gnus-unread-mark))
10122
10123 (defun gnus-summary-tick-above (&optional score)
10124   "Tick all articles with score above SCORE."
10125   (interactive "P")
10126   (gnus-summary-mark-above score gnus-ticked-mark))
10127
10128 (defun gnus-summary-mark-above (score mark)
10129   "Mark articles with score over SCORE with MARK."
10130   (interactive "P\ncMark: ")
10131   (setq score (if score
10132                   (prefix-numeric-value score)
10133                 (or gnus-summary-default-score 0)))
10134   (save-excursion
10135     (set-buffer gnus-summary-buffer)
10136     (goto-char (point-min))
10137     (while (and (progn
10138                   (when (> (gnus-summary-article-score) score)
10139                     (gnus-summary-mark-article nil mark))
10140                   t)
10141                 (gnus-summary-find-next)))))
10142
10143 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10144 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10145 (defun gnus-summary-limit-include-expunged (&optional no-error)
10146   "Display all the hidden articles that were expunged for low scores."
10147   (interactive)
10148   (let ((buffer-read-only nil))
10149     (let ((scored gnus-newsgroup-scored)
10150           headers h)
10151       (while scored
10152         (unless (gnus-summary-article-header (caar scored))
10153           (and (setq h (gnus-number-to-header (caar scored)))
10154                (< (cdar scored) gnus-summary-expunge-below)
10155                (push h headers)))
10156         (setq scored (cdr scored)))
10157       (if (not headers)
10158           (when (not no-error)
10159             (error "No expunged articles hidden"))
10160         (goto-char (point-min))
10161         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10162         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10163         (mapcar (lambda (x) (push (mail-header-number x)
10164                                   gnus-newsgroup-limit))
10165                 headers)
10166         (gnus-summary-prepare-unthreaded (nreverse headers))
10167         (goto-char (point-min))
10168         (gnus-summary-position-point)
10169         t))))
10170
10171 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10172   "Mark all unread articles in this newsgroup as read.
10173 If prefix argument ALL is non-nil, ticked and dormant articles will
10174 also be marked as read.
10175 If QUIETLY is non-nil, no questions will be asked.
10176 If TO-HERE is non-nil, it should be a point in the buffer.  All
10177 articles before (after, if REVERSE is set) this point will be marked as read.
10178 Note that this function will only catch up the unread article
10179 in the current summary buffer limitation.
10180 The number of articles marked as read is returned."
10181   (interactive "P")
10182   (prog1
10183       (save-excursion
10184         (when (or quietly
10185                   (not gnus-interactive-catchup) ;Without confirmation?
10186                   gnus-expert-user
10187                   (gnus-y-or-n-p
10188                    (if all
10189                        "Mark absolutely all articles as read? "
10190                      "Mark all unread articles as read? ")))
10191           (if (and not-mark
10192                    (not gnus-newsgroup-adaptive)
10193                    (not gnus-newsgroup-auto-expire)
10194                    (not gnus-suppress-duplicates)
10195                    (or (not gnus-use-cache)
10196                        (eq gnus-use-cache 'passive)))
10197               (progn
10198                 (when all
10199                   (setq gnus-newsgroup-marked nil
10200                         gnus-newsgroup-spam-marked nil
10201                         gnus-newsgroup-dormant nil))
10202                 (setq gnus-newsgroup-unreads
10203                       (gnus-sorted-nunion
10204                        (gnus-intersection gnus-newsgroup-unreads
10205                                           gnus-newsgroup-downloadable)
10206                        gnus-newsgroup-unfetched)))
10207             ;; We actually mark all articles as canceled, which we
10208             ;; have to do when using auto-expiry or adaptive scoring.
10209             (gnus-summary-show-all-threads)
10210             (if (and to-here reverse)
10211                 (progn
10212                   (goto-char to-here)
10213                   (while (and
10214                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10215                           (gnus-summary-find-next (not all)))))
10216               (when (gnus-summary-first-subject (not all))
10217                 (while (and
10218                         (if to-here (< (point) to-here) t)
10219                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10220                         (gnus-summary-find-next (not all))))))
10221             (gnus-set-mode-line 'summary))
10222           t))
10223     (gnus-summary-position-point)))
10224
10225 (defun gnus-summary-catchup-to-here (&optional all)
10226   "Mark all unticked articles before the current one as read.
10227 If ALL is non-nil, also mark ticked and dormant articles as read."
10228   (interactive "P")
10229   (save-excursion
10230     (gnus-save-hidden-threads
10231       (let ((beg (point)))
10232         ;; We check that there are unread articles.
10233         (when (or all (gnus-summary-find-prev))
10234           (gnus-summary-catchup all t beg)))))
10235   (gnus-summary-position-point))
10236
10237 (defun gnus-summary-catchup-from-here (&optional all)
10238   "Mark all unticked articles after the current one as read.
10239 If ALL is non-nil, also mark ticked and dormant articles as read."
10240   (interactive "P")
10241   (save-excursion
10242     (gnus-save-hidden-threads
10243       (let ((beg (point)))
10244         ;; We check that there are unread articles.
10245         (when (or all (gnus-summary-find-next))
10246           (gnus-summary-catchup all t beg nil t)))))
10247   (gnus-summary-position-point))
10248
10249 (defun gnus-summary-catchup-all (&optional quietly)
10250   "Mark all articles in this newsgroup as read.
10251 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10252 instead, which marks only unread articles as read."
10253   (interactive "P")
10254   (gnus-summary-catchup t quietly))
10255
10256 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10257   "Mark all unread articles in this group as read, then exit.
10258 If prefix argument ALL is non-nil, all articles are marked as read.
10259 If QUIETLY is non-nil, no questions will be asked."
10260   (interactive "P")
10261   (when (gnus-summary-catchup all quietly nil 'fast)
10262     ;; Select next newsgroup or exit.
10263     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10264              (eq gnus-auto-select-next 'quietly))
10265         (gnus-summary-next-group nil)
10266       (gnus-summary-exit))))
10267
10268 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10269   "Mark all articles in this newsgroup as read, and then exit.
10270 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10271 instead, which marks only unread articles as read."
10272   (interactive "P")
10273   (gnus-summary-catchup-and-exit t quietly))
10274
10275 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10276   "Mark all articles in this group as read and select the next group.
10277 If given a prefix, mark all articles, unread as well as ticked, as
10278 read."
10279   (interactive "P")
10280   (save-excursion
10281     (gnus-summary-catchup all))
10282   (gnus-summary-next-group))
10283
10284 ;;;
10285 ;;; with article
10286 ;;;
10287
10288 (defmacro gnus-with-article (article &rest forms)
10289   "Select ARTICLE and perform FORMS in the original article buffer.
10290 Then replace the article with the result."
10291   `(progn
10292      ;; We don't want the article to be marked as read.
10293      (let (gnus-mark-article-hook)
10294        (gnus-summary-select-article t t nil ,article))
10295      (set-buffer gnus-original-article-buffer)
10296      ,@forms
10297      (if (not (gnus-check-backend-function
10298                'request-replace-article (car gnus-article-current)))
10299          (gnus-message 5 "Read-only group; not replacing")
10300        (unless (gnus-request-replace-article
10301                 ,article (car gnus-article-current)
10302                 (current-buffer) t)
10303          (error "Couldn't replace article")))
10304      ;; The cache and backlog have to be flushed somewhat.
10305      (when gnus-keep-backlog
10306        (gnus-backlog-remove-article
10307         (car gnus-article-current) (cdr gnus-article-current)))
10308      (when gnus-use-cache
10309        (gnus-cache-update-article
10310         (car gnus-article-current) (cdr gnus-article-current)))))
10311
10312 (put 'gnus-with-article 'lisp-indent-function 1)
10313 (put 'gnus-with-article 'edebug-form-spec '(form body))
10314
10315 ;; Thread-based commands.
10316
10317 (defun gnus-summary-articles-in-thread (&optional article)
10318   "Return a list of all articles in the current thread.
10319 If ARTICLE is non-nil, return all articles in the thread that starts
10320 with that article."
10321   (let* ((article (or article (gnus-summary-article-number)))
10322          (data (gnus-data-find-list article))
10323          (top-level (gnus-data-level (car data)))
10324          (top-subject
10325           (cond ((null gnus-thread-operation-ignore-subject)
10326                  (gnus-simplify-subject-re
10327                   (mail-header-subject (gnus-data-header (car data)))))
10328                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10329                  (gnus-simplify-subject-fuzzy
10330                   (mail-header-subject (gnus-data-header (car data)))))
10331                 (t nil)))
10332          (end-point (save-excursion
10333                       (if (gnus-summary-go-to-next-thread)
10334                           (point) (point-max))))
10335          articles)
10336     (while (and data
10337                 (< (gnus-data-pos (car data)) end-point))
10338       (when (or (not top-subject)
10339                 (string= top-subject
10340                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10341                              (gnus-simplify-subject-fuzzy
10342                               (mail-header-subject
10343                                (gnus-data-header (car data))))
10344                            (gnus-simplify-subject-re
10345                             (mail-header-subject
10346                              (gnus-data-header (car data)))))))
10347         (push (gnus-data-number (car data)) articles))
10348       (unless (and (setq data (cdr data))
10349                    (> (gnus-data-level (car data)) top-level))
10350         (setq data nil)))
10351     ;; Return the list of articles.
10352     (nreverse articles)))
10353
10354 (defun gnus-summary-rethread-current ()
10355   "Rethread the thread the current article is part of."
10356   (interactive)
10357   (let* ((gnus-show-threads t)
10358          (article (gnus-summary-article-number))
10359          (id (mail-header-id (gnus-summary-article-header)))
10360          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10361     (unless id
10362       (error "No article on the current line"))
10363     (gnus-rebuild-thread id)
10364     (gnus-summary-goto-subject article)))
10365
10366 (defun gnus-summary-reparent-thread ()
10367   "Make the current article child of the marked (or previous) article.
10368
10369 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10370 is non-nil or the Subject: of both articles are the same."
10371   (interactive)
10372   (unless (not (gnus-group-read-only-p))
10373     (error "The current newsgroup does not support article editing"))
10374   (unless (<= (length gnus-newsgroup-processable) 1)
10375     (error "No more than one article may be marked"))
10376   (save-window-excursion
10377     (let ((gnus-article-buffer " *reparent*")
10378           (current-article (gnus-summary-article-number))
10379           ;; First grab the marked article, otherwise one line up.
10380           (parent-article (if (not (null gnus-newsgroup-processable))
10381                               (car gnus-newsgroup-processable)
10382                             (save-excursion
10383                               (if (eq (forward-line -1) 0)
10384                                   (gnus-summary-article-number)
10385                                 (error "Beginning of summary buffer"))))))
10386       (unless (not (eq current-article parent-article))
10387         (error "An article may not be self-referential"))
10388       (let ((message-id (mail-header-id
10389                          (gnus-summary-article-header parent-article))))
10390         (unless (and message-id (not (equal message-id "")))
10391           (error "No message-id in desired parent"))
10392         (gnus-with-article current-article
10393           (save-restriction
10394             (goto-char (point-min))
10395             (message-narrow-to-head)
10396             (if (re-search-forward "^References: " nil t)
10397                 (progn
10398                   (re-search-forward "^[^ \t]" nil t)
10399                   (forward-line -1)
10400                   (end-of-line)
10401                   (insert " " message-id))
10402               (insert "References: " message-id "\n"))))
10403         (set-buffer gnus-summary-buffer)
10404         (gnus-summary-unmark-all-processable)
10405         (gnus-summary-update-article current-article)
10406         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10407             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10408         (gnus-summary-rethread-current)
10409         (gnus-message 3 "Article %d is now the child of article %d"
10410                       current-article parent-article)))))
10411
10412 (defun gnus-summary-toggle-threads (&optional arg)
10413   "Toggle showing conversation threads.
10414 If ARG is positive number, turn showing conversation threads on."
10415   (interactive "P")
10416   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10417     (setq gnus-show-threads
10418           (if (null arg) (not gnus-show-threads)
10419             (> (prefix-numeric-value arg) 0)))
10420     (gnus-summary-prepare)
10421     (gnus-summary-goto-subject current)
10422     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10423     (gnus-summary-position-point)))
10424
10425 (defun gnus-summary-show-all-threads ()
10426   "Show all threads."
10427   (interactive)
10428   (save-excursion
10429     (let ((buffer-read-only nil))
10430       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10431   (gnus-summary-position-point))
10432
10433 (defun gnus-summary-show-thread ()
10434   "Show thread subtrees.
10435 Returns nil if no thread was there to be shown."
10436   (interactive)
10437   (let ((buffer-read-only nil)
10438         (orig (point))
10439         (end (gnus-point-at-eol))
10440         ;; Leave point at bol
10441         (beg (progn (beginning-of-line) (point))))
10442     (prog1
10443         ;; Any hidden lines here?
10444         (search-forward "\r" end t)
10445       (subst-char-in-region beg end ?\^M ?\n t)
10446       (goto-char orig)
10447       (gnus-summary-position-point))))
10448
10449 (defun gnus-summary-maybe-hide-threads ()
10450   "If requested, hide the threads that should be hidden."
10451   (when (and gnus-show-threads
10452              gnus-thread-hide-subtree)
10453     (gnus-summary-hide-all-threads
10454      (if (or (consp gnus-thread-hide-subtree)
10455              (gnus-functionp gnus-thread-hide-subtree))
10456          (gnus-make-predicate gnus-thread-hide-subtree)
10457        nil))))
10458
10459 ;;; Hiding predicates.
10460
10461 (defun gnus-article-unread-p (header)
10462   (memq (mail-header-number header) gnus-newsgroup-unreads))
10463
10464 (defun gnus-article-unseen-p (header)
10465   (memq (mail-header-number header) gnus-newsgroup-unseen))
10466
10467 (defun gnus-map-articles (predicate articles)
10468   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10469   (apply 'gnus-or (mapcar predicate
10470                           (mapcar 'gnus-summary-article-header articles))))
10471
10472 (defun gnus-summary-hide-all-threads (&optional predicate)
10473   "Hide all thread subtrees.
10474 If PREDICATE is supplied, threads that satisfy this predicate
10475 will not be hidden."
10476   (interactive)
10477   (save-excursion
10478     (goto-char (point-min))
10479     (let ((end nil))
10480       (while (not end)
10481         (when (or (not predicate)
10482                   (gnus-map-articles
10483                    predicate (gnus-summary-article-children)))
10484             (gnus-summary-hide-thread))
10485         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10486   (gnus-summary-position-point))
10487
10488 (defun gnus-summary-hide-thread ()
10489   "Hide thread subtrees.
10490 If PREDICATE is supplied, threads that satisfy this predicate
10491 will not be hidden.
10492 Returns nil if no threads were there to be hidden."
10493   (interactive)
10494   (let ((buffer-read-only nil)
10495         (start (point))
10496         (article (gnus-summary-article-number)))
10497     (goto-char start)
10498     ;; Go forward until either the buffer ends or the subthread
10499     ;; ends.
10500     (when (and (not (eobp))
10501                (or (zerop (gnus-summary-next-thread 1 t))
10502                    (goto-char (point-max))))
10503       (prog1
10504           (if (and (> (point) start)
10505                    (search-backward "\n" start t))
10506               (progn
10507                 (subst-char-in-region start (point) ?\n ?\^M)
10508                 (gnus-summary-goto-subject article))
10509             (goto-char start)
10510             nil)))))
10511
10512 (defun gnus-summary-go-to-next-thread (&optional previous)
10513   "Go to the same level (or less) next thread.
10514 If PREVIOUS is non-nil, go to previous thread instead.
10515 Return the article number moved to, or nil if moving was impossible."
10516   (let ((level (gnus-summary-thread-level))
10517         (way (if previous -1 1))
10518         (beg (point)))
10519     (forward-line way)
10520     (while (and (not (eobp))
10521                 (< level (gnus-summary-thread-level)))
10522       (forward-line way))
10523     (if (eobp)
10524         (progn
10525           (goto-char beg)
10526           nil)
10527       (setq beg (point))
10528       (prog1
10529           (gnus-summary-article-number)
10530         (goto-char beg)))))
10531
10532 (defun gnus-summary-next-thread (n &optional silent)
10533   "Go to the same level next N'th thread.
10534 If N is negative, search backward instead.
10535 Returns the difference between N and the number of skips actually
10536 done.
10537
10538 If SILENT, don't output messages."
10539   (interactive "p")
10540   (let ((backward (< n 0))
10541         (n (abs n)))
10542     (while (and (> n 0)
10543                 (gnus-summary-go-to-next-thread backward))
10544       (decf n))
10545     (unless silent
10546       (gnus-summary-position-point))
10547     (when (and (not silent) (/= 0 n))
10548       (gnus-message 7 "No more threads"))
10549     n))
10550
10551 (defun gnus-summary-prev-thread (n)
10552   "Go to the same level previous N'th thread.
10553 Returns the difference between N and the number of skips actually
10554 done."
10555   (interactive "p")
10556   (gnus-summary-next-thread (- n)))
10557
10558 (defun gnus-summary-go-down-thread ()
10559   "Go down one level in the current thread."
10560   (let ((children (gnus-summary-article-children)))
10561     (when children
10562       (gnus-summary-goto-subject (car children)))))
10563
10564 (defun gnus-summary-go-up-thread ()
10565   "Go up one level in the current thread."
10566   (let ((parent (gnus-summary-article-parent)))
10567     (when parent
10568       (gnus-summary-goto-subject parent))))
10569
10570 (defun gnus-summary-down-thread (n)
10571   "Go down thread N steps.
10572 If N is negative, go up instead.
10573 Returns the difference between N and how many steps down that were
10574 taken."
10575   (interactive "p")
10576   (let ((up (< n 0))
10577         (n (abs n)))
10578     (while (and (> n 0)
10579                 (if up (gnus-summary-go-up-thread)
10580                   (gnus-summary-go-down-thread)))
10581       (setq n (1- n)))
10582     (gnus-summary-position-point)
10583     (when (/= 0 n)
10584       (gnus-message 7 "Can't go further"))
10585     n))
10586
10587 (defun gnus-summary-up-thread (n)
10588   "Go up thread N steps.
10589 If N is negative, go down instead.
10590 Returns the difference between N and how many steps down that were
10591 taken."
10592   (interactive "p")
10593   (gnus-summary-down-thread (- n)))
10594
10595 (defun gnus-summary-top-thread ()
10596   "Go to the top of the thread."
10597   (interactive)
10598   (while (gnus-summary-go-up-thread))
10599   (gnus-summary-article-number))
10600
10601 (defun gnus-summary-kill-thread (&optional unmark)
10602   "Mark articles under current thread as read.
10603 If the prefix argument is positive, remove any kinds of marks.
10604 If the prefix argument is negative, tick articles instead."
10605   (interactive "P")
10606   (when unmark
10607     (setq unmark (prefix-numeric-value unmark)))
10608   (let ((articles (gnus-summary-articles-in-thread)))
10609     (save-excursion
10610       ;; Expand the thread.
10611       (gnus-summary-show-thread)
10612       ;; Mark all the articles.
10613       (while articles
10614         (gnus-summary-goto-subject (car articles))
10615         (cond ((null unmark)
10616                (gnus-summary-mark-article-as-read gnus-killed-mark))
10617               ((> unmark 0)
10618                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10619               (t
10620                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10621         (setq articles (cdr articles))))
10622     ;; Hide killed subtrees.
10623     (and (null unmark)
10624          gnus-thread-hide-killed
10625          (gnus-summary-hide-thread))
10626     ;; If marked as read, go to next unread subject.
10627     (when (null unmark)
10628       ;; Go to next unread subject.
10629       (gnus-summary-next-subject 1 t)))
10630   (gnus-set-mode-line 'summary))
10631
10632 ;; Summary sorting commands
10633
10634 (defun gnus-summary-sort-by-number (&optional reverse)
10635   "Sort the summary buffer by article number.
10636 Argument REVERSE means reverse order."
10637   (interactive "P")
10638   (gnus-summary-sort 'number reverse))
10639
10640 (defun gnus-summary-sort-by-random (&optional reverse)
10641   "Randomize the order in the summary buffer.
10642 Argument REVERSE means to randomize in reverse order."
10643   (interactive "P")
10644   (gnus-summary-sort 'random reverse))
10645
10646 (defun gnus-summary-sort-by-author (&optional reverse)
10647   "Sort the summary buffer by author name alphabetically.
10648 If `case-fold-search' is non-nil, case of letters is ignored.
10649 Argument REVERSE means reverse order."
10650   (interactive "P")
10651   (gnus-summary-sort 'author reverse))
10652
10653 (defun gnus-summary-sort-by-subject (&optional reverse)
10654   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10655 If `case-fold-search' is non-nil, case of letters is ignored.
10656 Argument REVERSE means reverse order."
10657   (interactive "P")
10658   (gnus-summary-sort 'subject reverse))
10659
10660 (defun gnus-summary-sort-by-date (&optional reverse)
10661   "Sort the summary buffer by date.
10662 Argument REVERSE means reverse order."
10663   (interactive "P")
10664   (gnus-summary-sort 'date reverse))
10665
10666 (defun gnus-summary-sort-by-score (&optional reverse)
10667   "Sort the summary buffer by score.
10668 Argument REVERSE means reverse order."
10669   (interactive "P")
10670   (gnus-summary-sort 'score reverse))
10671
10672 (defun gnus-summary-sort-by-lines (&optional reverse)
10673   "Sort the summary buffer by the number of lines.
10674 Argument REVERSE means reverse order."
10675   (interactive "P")
10676   (gnus-summary-sort 'lines reverse))
10677
10678 (defun gnus-summary-sort-by-chars (&optional reverse)
10679   "Sort the summary buffer by article length.
10680 Argument REVERSE means reverse order."
10681   (interactive "P")
10682   (gnus-summary-sort 'chars reverse))
10683
10684 (defun gnus-summary-sort-by-original (&optional reverse)
10685   "Sort the summary buffer using the default sorting method.
10686 Argument REVERSE means reverse order."
10687   (interactive "P")
10688   (let* ((buffer-read-only)
10689          (gnus-summary-prepare-hook nil))
10690     ;; We do the sorting by regenerating the threads.
10691     (gnus-summary-prepare)
10692     ;; Hide subthreads if needed.
10693     (gnus-summary-maybe-hide-threads)))
10694
10695 (defun gnus-summary-sort (predicate reverse)
10696   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10697   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10698          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10699          (gnus-thread-sort-functions
10700           (if (not reverse)
10701               thread
10702             `(lambda (t1 t2)
10703                (,thread t2 t1))))
10704          (gnus-sort-gathered-threads-function
10705           gnus-thread-sort-functions)
10706          (gnus-article-sort-functions
10707           (if (not reverse)
10708               article
10709             `(lambda (t1 t2)
10710                (,article t2 t1))))
10711          (buffer-read-only)
10712          (gnus-summary-prepare-hook nil))
10713     ;; We do the sorting by regenerating the threads.
10714     (gnus-summary-prepare)
10715     ;; Hide subthreads if needed.
10716     (gnus-summary-maybe-hide-threads)))
10717
10718 ;; Summary saving commands.
10719
10720 (defun gnus-summary-save-article (&optional n not-saved)
10721   "Save the current article using the default saver function.
10722 If N is a positive number, save the N next articles.
10723 If N is a negative number, save the N previous articles.
10724 If N is nil and any articles have been marked with the process mark,
10725 save those articles instead.
10726 The variable `gnus-default-article-saver' specifies the saver function."
10727   (interactive "P")
10728   (let* ((articles (gnus-summary-work-articles n))
10729          (save-buffer (save-excursion
10730                         (nnheader-set-temp-buffer " *Gnus Save*")))
10731          (num (length articles))
10732          header file)
10733     (dolist (article articles)
10734       (setq header (gnus-summary-article-header article))
10735       (if (not (vectorp header))
10736           ;; This is a pseudo-article.
10737           (if (assq 'name header)
10738               (gnus-copy-file (cdr (assq 'name header)))
10739             (gnus-message 1 "Article %d is unsaveable" article))
10740         ;; This is a real article.
10741         (save-window-excursion
10742           (let ((gnus-display-mime-function nil)
10743                 (gnus-article-prepare-hook nil))
10744             (gnus-summary-select-article t nil nil article)))
10745         (save-excursion
10746           (set-buffer save-buffer)
10747           (erase-buffer)
10748           (insert-buffer-substring gnus-original-article-buffer))
10749         (setq file (gnus-article-save save-buffer file num))
10750         (gnus-summary-remove-process-mark article)
10751         (unless not-saved
10752           (gnus-summary-set-saved-mark article))))
10753     (gnus-kill-buffer save-buffer)
10754     (gnus-summary-position-point)
10755     (gnus-set-mode-line 'summary)
10756     n))
10757
10758 (defun gnus-summary-pipe-output (&optional arg headers)
10759   "Pipe the current article to a subprocess.
10760 If N is a positive number, pipe the N next articles.
10761 If N is a negative number, pipe the N previous articles.
10762 If N is nil and any articles have been marked with the process mark,
10763 pipe those articles instead.
10764 If HEADERS (the symbolic prefix), include the headers, too."
10765   (interactive (gnus-interactive "P\ny"))
10766   (require 'gnus-art)
10767   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10768         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10769     (gnus-summary-save-article arg t))
10770   (let ((buffer (get-buffer "*Shell Command Output*")))
10771     (when (and buffer
10772                (not (zerop (buffer-size buffer))))
10773       (gnus-configure-windows 'pipe))))
10774
10775 (defun gnus-summary-save-article-mail (&optional arg)
10776   "Append the current article to an mail file.
10777 If N is a positive number, save the N next articles.
10778 If N is a negative number, save the N previous articles.
10779 If N is nil and any articles have been marked with the process mark,
10780 save those articles instead."
10781   (interactive "P")
10782   (require 'gnus-art)
10783   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10784     (gnus-summary-save-article arg)))
10785
10786 (defun gnus-summary-save-article-rmail (&optional arg)
10787   "Append the current article to an rmail file.
10788 If N is a positive number, save the N next articles.
10789 If N is a negative number, save the N previous articles.
10790 If N is nil and any articles have been marked with the process mark,
10791 save those articles instead."
10792   (interactive "P")
10793   (require 'gnus-art)
10794   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10795     (gnus-summary-save-article arg)))
10796
10797 (defun gnus-summary-save-article-file (&optional arg)
10798   "Append the current article to a file.
10799 If N is a positive number, save the N next articles.
10800 If N is a negative number, save the N previous articles.
10801 If N is nil and any articles have been marked with the process mark,
10802 save those articles instead."
10803   (interactive "P")
10804   (require 'gnus-art)
10805   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10806     (gnus-summary-save-article arg)))
10807
10808 (defun gnus-summary-write-article-file (&optional arg)
10809   "Write the current article to a file, deleting the previous file.
10810 If N is a positive number, save the N next articles.
10811 If N is a negative number, save the N previous articles.
10812 If N is nil and any articles have been marked with the process mark,
10813 save those articles instead."
10814   (interactive "P")
10815   (require 'gnus-art)
10816   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10817     (gnus-summary-save-article arg)))
10818
10819 (defun gnus-summary-save-article-body-file (&optional arg)
10820   "Append the current article body to a file.
10821 If N is a positive number, save the N next articles.
10822 If N is a negative number, save the N previous articles.
10823 If N is nil and any articles have been marked with the process mark,
10824 save those articles instead."
10825   (interactive "P")
10826   (require 'gnus-art)
10827   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10828     (gnus-summary-save-article arg)))
10829
10830 (defun gnus-summary-muttprint (&optional arg)
10831   "Print the current article using Muttprint.
10832 If N is a positive number, save the N next articles.
10833 If N is a negative number, save the N previous articles.
10834 If N is nil and any articles have been marked with the process mark,
10835 save those articles instead."
10836   (interactive "P")
10837   (require 'gnus-art)
10838   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10839     (gnus-summary-save-article arg t)))
10840
10841 (defun gnus-summary-pipe-message (program)
10842   "Pipe the current article through PROGRAM."
10843   (interactive "sProgram: ")
10844   (gnus-summary-select-article)
10845   (let ((mail-header-separator ""))
10846     (gnus-eval-in-buffer-window gnus-article-buffer
10847       (save-restriction
10848         (widen)
10849         (let ((start (window-start))
10850               buffer-read-only)
10851           (message-pipe-buffer-body program)
10852           (set-window-start (get-buffer-window (current-buffer)) start))))))
10853
10854 (defun gnus-get-split-value (methods)
10855   "Return a value based on the split METHODS."
10856   (let (split-name method result match)
10857     (when methods
10858       (save-excursion
10859         (set-buffer gnus-original-article-buffer)
10860         (save-restriction
10861           (nnheader-narrow-to-headers)
10862           (while (and methods (not split-name))
10863             (goto-char (point-min))
10864             (setq method (pop methods))
10865             (setq match (car method))
10866             (when (cond
10867                    ((stringp match)
10868                     ;; Regular expression.
10869                     (ignore-errors
10870                       (re-search-forward match nil t)))
10871                    ((gnus-functionp match)
10872                     ;; Function.
10873                     (save-restriction
10874                       (widen)
10875                       (setq result (funcall match gnus-newsgroup-name))))
10876                    ((consp match)
10877                     ;; Form.
10878                     (save-restriction
10879                       (widen)
10880                       (setq result (eval match)))))
10881               (setq split-name (cdr method))
10882               (cond ((stringp result)
10883                      (push (expand-file-name
10884                             result gnus-article-save-directory)
10885                            split-name))
10886                     ((consp result)
10887                      (setq split-name (append result split-name)))))))))
10888     (nreverse split-name)))
10889
10890 (defun gnus-valid-move-group-p (group)
10891   (and (boundp group)
10892        (symbol-name group)
10893        (symbol-value group)
10894        (gnus-get-function (gnus-find-method-for-group
10895                            (symbol-name group)) 'request-accept-article t)))
10896
10897 (defun gnus-read-move-group-name (prompt default articles prefix)
10898   "Read a group name."
10899   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10900          (minibuffer-confirm-incomplete nil) ; XEmacs
10901          (prom
10902           (format "%s %s to:"
10903                   prompt
10904                   (if (> (length articles) 1)
10905                       (format "these %d articles" (length articles))
10906                     "this article")))
10907          (to-newsgroup
10908           (cond
10909            ((null split-name)
10910             (gnus-completing-read-with-default
10911              default prom
10912              gnus-active-hashtb
10913              'gnus-valid-move-group-p
10914              nil prefix
10915              'gnus-group-history))
10916            ((= 1 (length split-name))
10917             (gnus-completing-read-with-default
10918              (car split-name) prom
10919              gnus-active-hashtb
10920              'gnus-valid-move-group-p
10921              nil nil
10922              'gnus-group-history))
10923            (t
10924             (gnus-completing-read-with-default
10925              nil prom
10926              (mapcar (lambda (el) (list el))
10927                      (nreverse split-name))
10928              nil nil nil
10929              'gnus-group-history))))
10930          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10931     (when to-newsgroup
10932       (if (or (string= to-newsgroup "")
10933               (string= to-newsgroup prefix))
10934           (setq to-newsgroup default))
10935       (unless to-newsgroup
10936         (error "No group name entered"))
10937       (or (gnus-active to-newsgroup)
10938           (gnus-activate-group to-newsgroup nil nil to-method)
10939           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10940                                      to-newsgroup))
10941               (or (and (gnus-request-create-group to-newsgroup to-method)
10942                        (gnus-activate-group
10943                         to-newsgroup nil nil to-method)
10944                        (gnus-subscribe-group to-newsgroup))
10945                   (error "Couldn't create group %s" to-newsgroup)))
10946           (error "No such group: %s" to-newsgroup)))
10947     to-newsgroup))
10948
10949 (defun gnus-summary-save-parts (type dir n &optional reverse)
10950   "Save parts matching TYPE to DIR.
10951 If REVERSE, save parts that do not match TYPE."
10952   (interactive
10953    (list (read-string "Save parts of type: "
10954                       (or (car gnus-summary-save-parts-type-history)
10955                           gnus-summary-save-parts-default-mime)
10956                       'gnus-summary-save-parts-type-history)
10957          (setq gnus-summary-save-parts-last-directory
10958                (read-file-name "Save to directory: "
10959                                gnus-summary-save-parts-last-directory
10960                                nil t))
10961          current-prefix-arg))
10962   (gnus-summary-iterate n
10963     (let ((gnus-display-mime-function nil)
10964           (gnus-inhibit-treatment t))
10965       (gnus-summary-select-article))
10966     (save-excursion
10967       (set-buffer gnus-article-buffer)
10968       (let ((handles (or gnus-article-mime-handles
10969                          (mm-dissect-buffer nil gnus-article-loose-mime)
10970                          (and gnus-article-emulate-mime
10971                               (mm-uu-dissect)))))
10972         (when handles
10973           (gnus-summary-save-parts-1 type dir handles reverse)
10974           (unless gnus-article-mime-handles ;; Don't destroy this case.
10975             (mm-destroy-parts handles)))))))
10976
10977 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10978   (if (stringp (car handle))
10979       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10980               (cdr handle))
10981     (when (if reverse
10982               (not (string-match type (mm-handle-media-type handle)))
10983             (string-match type (mm-handle-media-type handle)))
10984       (let ((file (expand-file-name
10985                    (file-name-nondirectory
10986                     (or
10987                      (mail-content-type-get
10988                       (mm-handle-disposition handle) 'filename)
10989                      (concat gnus-newsgroup-name
10990                              "." (number-to-string
10991                                   (cdr gnus-article-current)))))
10992                    dir)))
10993         (unless (file-exists-p file)
10994           (mm-save-part-to-file handle file))))))
10995
10996 ;; Summary extract commands
10997
10998 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10999   (let ((buffer-read-only nil)
11000         (article (gnus-summary-article-number))
11001         after-article b e)
11002     (unless (gnus-summary-goto-subject article)
11003       (error "No such article: %d" article))
11004     (gnus-summary-position-point)
11005     ;; If all commands are to be bunched up on one line, we collect
11006     ;; them here.
11007     (unless gnus-view-pseudos-separately
11008       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11009             files action)
11010         (while ps
11011           (setq action (cdr (assq 'action (car ps))))
11012           (setq files (list (cdr (assq 'name (car ps)))))
11013           (while (and ps (cdr ps)
11014                       (string= (or action "1")
11015                                (or (cdr (assq 'action (cadr ps))) "2")))
11016             (push (cdr (assq 'name (cadr ps))) files)
11017             (setcdr ps (cddr ps)))
11018           (when files
11019             (when (not (string-match "%s" action))
11020               (push " " files))
11021             (push " " files)
11022             (when (assq 'execute (car ps))
11023               (setcdr (assq 'execute (car ps))
11024                       (funcall (if (string-match "%s" action)
11025                                    'format 'concat)
11026                                action
11027                                (mapconcat
11028                                 (lambda (f)
11029                                   (if (equal f " ")
11030                                       f
11031                                     (gnus-quote-arg-for-sh-or-csh f)))
11032                                 files " ")))))
11033           (setq ps (cdr ps)))))
11034     (if (and gnus-view-pseudos (not not-view))
11035         (while pslist
11036           (when (assq 'execute (car pslist))
11037             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11038                                   (eq gnus-view-pseudos 'not-confirm)))
11039           (setq pslist (cdr pslist)))
11040       (save-excursion
11041         (while pslist
11042           (setq after-article (or (cdr (assq 'article (car pslist)))
11043                                   (gnus-summary-article-number)))
11044           (gnus-summary-goto-subject after-article)
11045           (forward-line 1)
11046           (setq b (point))
11047           (insert "    " (file-name-nondirectory
11048                           (cdr (assq 'name (car pslist))))
11049                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11050           (setq e (point))
11051           (forward-line -1)             ; back to `b'
11052           (gnus-add-text-properties
11053            b (1- e) (list 'gnus-number gnus-reffed-article-number
11054                           gnus-mouse-face-prop gnus-mouse-face))
11055           (gnus-data-enter
11056            after-article gnus-reffed-article-number
11057            gnus-unread-mark b (car pslist) 0 (- e b))
11058           (setq gnus-newsgroup-unreads
11059                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11060                                          gnus-reffed-article-number))
11061           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11062           (setq pslist (cdr pslist)))))))
11063
11064 (defun gnus-pseudos< (p1 p2)
11065   (let ((c1 (cdr (assq 'action p1)))
11066         (c2 (cdr (assq 'action p2))))
11067     (and c1 c2 (string< c1 c2))))
11068
11069 (defun gnus-request-pseudo-article (props)
11070   (cond ((assq 'execute props)
11071          (gnus-execute-command (cdr (assq 'execute props)))))
11072   (let ((gnus-current-article (gnus-summary-article-number)))
11073     (gnus-run-hooks 'gnus-mark-article-hook)))
11074
11075 (defun gnus-execute-command (command &optional automatic)
11076   (save-excursion
11077     (gnus-article-setup-buffer)
11078     (set-buffer gnus-article-buffer)
11079     (setq buffer-read-only nil)
11080     (let ((command (if automatic command
11081                      (read-string "Command: " (cons command 0)))))
11082       (erase-buffer)
11083       (insert "$ " command "\n\n")
11084       (if gnus-view-pseudo-asynchronously
11085           (start-process "gnus-execute" (current-buffer) shell-file-name
11086                          shell-command-switch command)
11087         (call-process shell-file-name nil t nil
11088                       shell-command-switch command)))))
11089
11090 ;; Summary kill commands.
11091
11092 (defun gnus-summary-edit-global-kill (article)
11093   "Edit the \"global\" kill file."
11094   (interactive (list (gnus-summary-article-number)))
11095   (gnus-group-edit-global-kill article))
11096
11097 (defun gnus-summary-edit-local-kill ()
11098   "Edit a local kill file applied to the current newsgroup."
11099   (interactive)
11100   (setq gnus-current-headers (gnus-summary-article-header))
11101   (gnus-group-edit-local-kill
11102    (gnus-summary-article-number) gnus-newsgroup-name))
11103
11104 ;;; Header reading.
11105
11106 (defun gnus-read-header (id &optional header)
11107   "Read the headers of article ID and enter them into the Gnus system."
11108   (let ((group gnus-newsgroup-name)
11109         (gnus-override-method
11110          (or
11111           gnus-override-method
11112           (and (gnus-news-group-p gnus-newsgroup-name)
11113                (car (gnus-refer-article-methods)))))
11114         where)
11115     ;; First we check to see whether the header in question is already
11116     ;; fetched.
11117     (if (stringp id)
11118         ;; This is a Message-ID.
11119         (setq header (or header (gnus-id-to-header id)))
11120       ;; This is an article number.
11121       (setq header (or header (gnus-summary-article-header id))))
11122     (if (and header
11123              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11124         ;; We have found the header.
11125         header
11126       ;; If this is a sparse article, we have to nix out its
11127       ;; previous entry in the thread hashtb.
11128       (when (and header
11129                  (gnus-summary-article-sparse-p (mail-header-number header)))
11130         (let* ((parent (gnus-parent-id (mail-header-references header)))
11131                (thread (and parent (gnus-id-to-thread parent))))
11132           (when thread
11133             (delq (assq header thread) thread))))
11134       ;; We have to really fetch the header to this article.
11135       (save-excursion
11136         (set-buffer nntp-server-buffer)
11137         (when (setq where (gnus-request-head id group))
11138           (nnheader-fold-continuation-lines)
11139           (goto-char (point-max))
11140           (insert ".\n")
11141           (goto-char (point-min))
11142           (insert "211 ")
11143           (princ (cond
11144                   ((numberp id) id)
11145                   ((cdr where) (cdr where))
11146                   (header (mail-header-number header))
11147                   (t gnus-reffed-article-number))
11148                  (current-buffer))
11149           (insert " Article retrieved.\n"))
11150         (if (or (not where)
11151                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11152             ()                          ; Malformed head.
11153           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11154             (when (and (stringp id)
11155                        (not (string= (gnus-group-real-name group)
11156                                      (car where))))
11157               ;; If we fetched by Message-ID and the article came
11158               ;; from a different group, we fudge some bogus article
11159               ;; numbers for this article.
11160               (mail-header-set-number header gnus-reffed-article-number))
11161             (save-excursion
11162               (set-buffer gnus-summary-buffer)
11163               (decf gnus-reffed-article-number)
11164               (gnus-remove-header (mail-header-number header))
11165               (push header gnus-newsgroup-headers)
11166               (setq gnus-current-headers header)
11167               (push (mail-header-number header) gnus-newsgroup-limit)))
11168           header)))))
11169
11170 (defun gnus-remove-header (number)
11171   "Remove header NUMBER from `gnus-newsgroup-headers'."
11172   (if (and gnus-newsgroup-headers
11173            (= number (mail-header-number (car gnus-newsgroup-headers))))
11174       (pop gnus-newsgroup-headers)
11175     (let ((headers gnus-newsgroup-headers))
11176       (while (and (cdr headers)
11177                   (not (= number (mail-header-number (cadr headers)))))
11178         (pop headers))
11179       (when (cdr headers)
11180         (setcdr headers (cddr headers))))))
11181
11182 ;;;
11183 ;;; summary highlights
11184 ;;;
11185
11186 (defun gnus-highlight-selected-summary ()
11187   "Highlight selected article in summary buffer."
11188   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11189   (when gnus-summary-selected-face
11190     (save-excursion
11191       (let* ((beg (gnus-point-at-bol))
11192              (end (gnus-point-at-eol))
11193              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11194              (from (if (get-text-property beg gnus-mouse-face-prop)
11195                        beg
11196                      (or (next-single-property-change
11197                           beg gnus-mouse-face-prop nil end)
11198                          beg)))
11199              (to
11200               (if (= from end)
11201                   (- from 2)
11202                 (or (next-single-property-change
11203                      from gnus-mouse-face-prop nil end)
11204                     end))))
11205         ;; If no mouse-face prop on line we will have to = from = end,
11206         ;; so we highlight the entire line instead.
11207         (when (= (+ to 2) from)
11208           (setq from beg)
11209           (setq to end))
11210         (if gnus-newsgroup-selected-overlay
11211             ;; Move old overlay.
11212             (gnus-move-overlay
11213              gnus-newsgroup-selected-overlay from to (current-buffer))
11214           ;; Create new overlay.
11215           (gnus-overlay-put
11216            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11217            'face gnus-summary-selected-face))))))
11218
11219 (defvar gnus-summary-highlight-line-cached nil)
11220 (defvar gnus-summary-highlight-line-trigger nil)
11221
11222 (defun gnus-summary-highlight-line-0 ()
11223   (if (and (eq gnus-summary-highlight-line-trigger 
11224                gnus-summary-highlight)
11225            gnus-summary-highlight-line-cached)
11226       gnus-summary-highlight-line-cached
11227     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11228           gnus-summary-highlight-line-cached
11229           (let* ((cond (list 'cond))
11230                  (c cond)
11231                  (list gnus-summary-highlight))
11232             (while list
11233               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11234                               nil))
11235               (setq c (cdr c)
11236                     list (cdr list)))
11237             (gnus-byte-compile (list 'lambda nil cond))))))
11238
11239 (defun gnus-summary-highlight-line ()
11240   "Highlight current line according to `gnus-summary-highlight'."
11241   (let* ((beg (gnus-point-at-bol))
11242          (article (or (gnus-summary-article-number) gnus-current-article))
11243          (score (or (cdr (assq article
11244                                gnus-newsgroup-scored))
11245                     gnus-summary-default-score 0))
11246          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11247          (inhibit-read-only t)
11248          (default gnus-summary-default-score)
11249          (default-high gnus-summary-default-high-score)
11250          (default-low gnus-summary-default-low-score)
11251          (uncached (memq article gnus-newsgroup-undownloaded))
11252          (downloaded (not uncached)))
11253     (let ((face (funcall (gnus-summary-highlight-line-0))))
11254       (unless (eq face (get-text-property beg 'face))
11255         (gnus-put-text-property-excluding-characters-with-faces
11256          beg (gnus-point-at-eol) 'face
11257          (setq face (if (boundp face) (symbol-value face) face)))
11258         (when gnus-summary-highlight-line-function
11259           (funcall gnus-summary-highlight-line-function article face))))))
11260
11261 (defun gnus-update-read-articles (group unread &optional compute)
11262   "Update the list of read articles in GROUP.
11263 UNREAD is a sorted list."
11264   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11265          (entry (gnus-gethash group gnus-newsrc-hashtb))
11266          (info (nth 2 entry))
11267          (prev 1)
11268          read)
11269     (if (or (not info) (not active))
11270         ;; There is no info on this group if it was, in fact,
11271         ;; killed.  Gnus stores no information on killed groups, so
11272         ;; there's nothing to be done.
11273         ;; One could store the information somewhere temporarily,
11274         ;; perhaps...  Hmmm...
11275         ()
11276       ;; Remove any negative articles numbers.
11277       (while (and unread (< (car unread) 0))
11278         (setq unread (cdr unread)))
11279       ;; Remove any expired article numbers
11280       (while (and unread (< (car unread) (car active)))
11281         (setq unread (cdr unread)))
11282       ;; Compute the ranges of read articles by looking at the list of
11283       ;; unread articles.
11284       (while unread
11285         (when (/= (car unread) prev)
11286           (push (if (= prev (1- (car unread))) prev
11287                   (cons prev (1- (car unread))))
11288                 read))
11289         (setq prev (1+ (car unread)))
11290         (setq unread (cdr unread)))
11291       (when (<= prev (cdr active))
11292         (push (cons prev (cdr active)) read))
11293       (setq read (if (> (length read) 1) (nreverse read) read))
11294       (if compute
11295           read
11296         (save-excursion
11297           (let (setmarkundo)
11298             ;; Propagate the read marks to the backend.
11299             (when (gnus-check-backend-function 'request-set-mark group)
11300               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11301                     (add (gnus-remove-from-range read (gnus-info-read info))))
11302                 (when (or add del)
11303                   (unless (gnus-check-group group)
11304                     (error "Can't open server for %s" group))
11305                   (gnus-request-set-mark
11306                    group (delq nil (list (if add (list add 'add '(read)))
11307                                          (if del (list del 'del '(read))))))
11308                   (setq setmarkundo
11309                         `(gnus-request-set-mark
11310                           ,group
11311                           ',(delq nil (list
11312                                        (if del (list del 'add '(read)))
11313                                        (if add (list add 'del '(read))))))))))
11314             (set-buffer gnus-group-buffer)
11315             (gnus-undo-register
11316               `(progn
11317                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11318                  (gnus-info-set-read ',info ',(gnus-info-read info))
11319                  (gnus-get-unread-articles-in-group ',info
11320                                                     (gnus-active ,group))
11321                  (gnus-group-update-group ,group t)
11322                  ,setmarkundo))))
11323         ;; Enter this list into the group info.
11324         (gnus-info-set-read info read)
11325         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11326         (gnus-get-unread-articles-in-group info (gnus-active group))
11327         t))))
11328
11329 (defun gnus-offer-save-summaries ()
11330   "Offer to save all active summary buffers."
11331   (let (buffers)
11332     ;; Go through all buffers and find all summaries.
11333     (dolist (buffer (buffer-list))
11334       (when (and (setq buffer (buffer-name buffer))
11335                  (string-match "Summary" buffer)
11336                  (save-excursion
11337                    (set-buffer buffer)
11338                    ;; We check that this is, indeed, a summary buffer.
11339                    (and (eq major-mode 'gnus-summary-mode)
11340                         ;; Also make sure this isn't bogus.
11341                         gnus-newsgroup-prepared
11342                         ;; Also make sure that this isn't a
11343                         ;; dead summary buffer.
11344                         (not gnus-dead-summary-mode))))
11345         (push buffer buffers)))
11346     ;; Go through all these summary buffers and offer to save them.
11347     (when buffers
11348       (save-excursion
11349         (map-y-or-n-p
11350          "Update summary buffer %s? "
11351          (lambda (buf)
11352            (switch-to-buffer buf)
11353            (gnus-summary-exit))
11354          buffers)))))
11355
11356
11357 ;;; @ for mime-partial
11358 ;;;
11359
11360 (defun gnus-request-partial-message ()
11361   (save-excursion
11362     (let ((number (gnus-summary-article-number))
11363           (group gnus-newsgroup-name)
11364           (mother gnus-article-buffer))
11365       (set-buffer (get-buffer-create " *Partial Article*"))
11366       (erase-buffer)
11367       (setq mime-preview-buffer mother)
11368       (gnus-request-article-this-buffer number group)
11369       (mime-parse-buffer)
11370       )))
11371
11372 (autoload 'mime-combine-message/partial-pieces-automatically
11373   "mime-partial"
11374   "Internal method to combine message/partial messages automatically.")
11375
11376 (mime-add-condition
11377  'action '((type . message)(subtype . partial)
11378            (major-mode . gnus-original-article-mode)
11379            (method . mime-combine-message/partial-pieces-automatically)
11380            (summary-buffer-exp . gnus-summary-buffer)
11381            (request-partial-message-method . gnus-request-partial-message)
11382            ))
11383
11384
11385 ;;; @ for message/rfc822
11386 ;;;
11387
11388 (defun gnus-mime-extract-message/rfc822 (entity situation)
11389   "Burst a forwarded article."
11390   (save-excursion
11391     (set-buffer gnus-summary-buffer)
11392     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11393                                    gnus-newsgroup-name 'gnus-group-history))
11394            (gnus-group-marked (list group))
11395            article info)
11396       (with-temp-buffer
11397         (mime-insert-entity-content entity)
11398         (setq article (gnus-request-accept-article group)))
11399       (when (and (consp article)
11400                  (numberp (setq article (cdr article))))
11401         (setq info (gnus-get-info group))
11402         (gnus-info-set-read info
11403                             (gnus-remove-from-range (gnus-info-read info)
11404                                                     (list article)))
11405         (when (string-equal group gnus-newsgroup-name)
11406           (forward-line 1)
11407           (let (gnus-show-threads)
11408             (gnus-summary-goto-subject article t))
11409           (gnus-summary-clear-mark-forward 1))
11410         (set-buffer gnus-group-buffer)
11411         (gnus-group-get-new-news-this-group nil t)))))
11412
11413 (mime-add-condition
11414  'action '((type . message)(subtype . rfc822)
11415            (major-mode . gnus-original-article-mode)
11416            (method . gnus-mime-extract-message/rfc822)
11417            (mode . "extract")
11418            ))
11419
11420 (mime-add-condition
11421  'action '((type . message)(subtype . news)
11422            (major-mode . gnus-original-article-mode)
11423            (method . gnus-mime-extract-message/rfc822)
11424            (mode . "extract")
11425            ))
11426
11427 (defun gnus-mime-extract-multipart (entity situation)
11428   (let ((children (mime-entity-children entity))
11429         mime-acting-situation-to-override
11430         f)
11431     (while children
11432       (mime-play-entity (car children)
11433                         (cons (assq 'mode situation)
11434                               mime-acting-situation-to-override))
11435       (setq children (cdr children)))
11436     (if (setq f (cdr (assq 'after-method
11437                            mime-acting-situation-to-override)))
11438         (eval f)
11439       )))
11440
11441 (mime-add-condition
11442  'action '((type . multipart)
11443            (method . gnus-mime-extract-multipart)
11444            (mode . "extract")
11445            )
11446  'with-default)
11447
11448
11449 ;;; @ end
11450 ;;;
11451
11452 (defun gnus-summary-inherit-default-charset ()
11453   "Import `default-mime-charset' from summary buffer.
11454 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11455 of FLIM is used."
11456   (if (buffer-live-p gnus-summary-buffer)
11457       (let (d-m-c d-m-c-u)
11458         (with-current-buffer gnus-summary-buffer
11459           (setq d-m-c (if (local-variable-p 'default-mime-charset
11460                                             gnus-summary-buffer)
11461                           default-mime-charset
11462                         t)
11463                 ;; LIMIT
11464                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11465                                               gnus-summary-buffer)
11466                             (symbol-value 'default-mime-charset-unlimited)
11467                           t)))
11468         (if (eq t d-m-c)
11469             (kill-local-variable 'default-mime-charset)
11470           (set (make-local-variable 'default-mime-charset) d-m-c))
11471         (if (eq t d-m-c-u)
11472             (kill-local-variable 'default-mime-charset-unlimited)
11473           (set (make-local-variable 'default-mime-charset-unlimited)
11474                d-m-c-u)))))
11475
11476 (defun gnus-summary-setup-default-charset ()
11477   "Setup newsgroup default charset."
11478   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11479       (progn
11480         (setq gnus-newsgroup-charset nil)
11481         (set (make-local-variable 'default-mime-charset) nil)
11482         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11483           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11484     (let ((ignored-charsets
11485            (or gnus-newsgroup-ephemeral-ignored-charsets
11486                (append
11487                 (and gnus-newsgroup-name
11488                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11489                 gnus-newsgroup-ignored-charsets)))
11490           charset)
11491       (setq gnus-newsgroup-charset
11492             (or gnus-newsgroup-ephemeral-charset
11493                 (when (and gnus-newsgroup-name
11494                            (setq charset (gnus-parameter-charset
11495                                           gnus-newsgroup-name)))
11496                   (make-local-variable 'default-mime-charset)
11497                   (setq default-mime-charset charset))
11498                 gnus-default-charset))
11499       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11500            ignored-charsets))))
11501
11502 ;;;
11503 ;;; Mime Commands
11504 ;;;
11505
11506 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11507   "Display the current article buffer fully MIME-buttonized.
11508 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11509 treated as multipart/mixed."
11510   (interactive "P")
11511   (require 'gnus-art)
11512   (let ((gnus-unbuttonized-mime-types nil)
11513         (gnus-mime-display-multipart-as-mixed show-all-parts))
11514     (gnus-summary-show-article)))
11515
11516 (defun gnus-summary-repair-multipart (article)
11517   "Add a Content-Type header to a multipart article without one."
11518   (interactive (list (gnus-summary-article-number)))
11519   (gnus-with-article article
11520     (message-narrow-to-head)
11521     (message-remove-header "Mime-Version")
11522     (goto-char (point-max))
11523     (insert "Mime-Version: 1.0\n")
11524     (widen)
11525     (when (search-forward "\n--" nil t)
11526       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11527         (message-narrow-to-head)
11528         (message-remove-header "Content-Type")
11529         (goto-char (point-max))
11530         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11531                         separator))
11532         (widen))))
11533   (let (gnus-mark-article-hook)
11534     (gnus-summary-select-article t t nil article)))
11535
11536 (defun gnus-summary-toggle-display-buttonized ()
11537   "Toggle the buttonizing of the article buffer."
11538   (interactive)
11539   (require 'gnus-art)
11540   (if (setq gnus-inhibit-mime-unbuttonizing
11541             (not gnus-inhibit-mime-unbuttonizing))
11542       (let ((gnus-unbuttonized-mime-types nil))
11543         (gnus-summary-show-article))
11544     (gnus-summary-show-article)))
11545
11546 ;;;
11547 ;;; Intelli-mouse commmands
11548 ;;;
11549
11550 (defun gnus-wheel-summary-scroll (event)
11551   (interactive "e")
11552   (let ((amount (if (memq 'shift (event-modifiers event))
11553                     (car gnus-wheel-scroll-amount)
11554                   (cdr gnus-wheel-scroll-amount)))
11555         (direction (- (* (static-if (featurep 'xemacs)
11556                              (event-button event)
11557                            (cond ((eq 'mouse-4 (event-basic-type event))
11558                                   4)
11559                                  ((eq 'mouse-5 (event-basic-type event))
11560                                   5)))
11561                          2) 9))
11562         edge)
11563     (gnus-summary-scroll-up (* amount direction))
11564     (when (gnus-eval-in-buffer-window gnus-article-buffer
11565             (save-restriction
11566               (widen)
11567               (and (if (< 0 direction)
11568                        (gnus-article-next-page 0)
11569                      (gnus-article-prev-page 0)
11570                      (bobp))
11571                    (if (setq edge (get-text-property
11572                                    (point-min) 'gnus-wheel-edge))
11573                        (setq edge (* edge direction))
11574                      (setq edge -1))
11575                    (or (plusp edge)
11576                        (let ((buffer-read-only nil)
11577                              (inhibit-read-only t))
11578                          (put-text-property (point-min) (point-max)
11579                                             'gnus-wheel-edge direction)
11580                          nil))
11581                    (or (> edge gnus-wheel-edge-resistance)
11582                        (let ((buffer-read-only nil)
11583                              (inhibit-read-only t))
11584                          (put-text-property (point-min) (point-max)
11585                                             'gnus-wheel-edge
11586                                             (* (1+ edge) direction))
11587                          nil))
11588                    (eq last-command 'gnus-wheel-summary-scroll))))
11589       (gnus-summary-next-article nil nil (minusp direction)))))
11590
11591 (defun gnus-wheel-install ()
11592   "Enable mouse wheel support on summary window."
11593   (when gnus-use-wheel
11594     (let ((keys
11595            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11596       (dolist (key keys)
11597         (define-key gnus-summary-mode-map key
11598           'gnus-wheel-summary-scroll)))))
11599
11600 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11601
11602 ;;;
11603 ;;; Traditional PGP commmands
11604 ;;;
11605
11606 (defun gnus-summary-decrypt-article (&optional force)
11607   "Decrypt the current article in traditional PGP way.
11608 This will have permanent effect only in mail groups.
11609 If FORCE is non-nil, allow editing of articles even in read-only
11610 groups."
11611   (interactive "P")
11612   (gnus-summary-select-article t)
11613   (gnus-eval-in-buffer-window gnus-article-buffer
11614     (save-excursion
11615       (save-restriction
11616         (widen)
11617         (goto-char (point-min))
11618         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11619           (error "Not a traditional PGP message!"))
11620         (let ((armor-start (match-beginning 0)))
11621           (if (and (pgg-decrypt-region armor-start (point-max))
11622                    (or force (not (gnus-group-read-only-p))))
11623               (let ((inhibit-read-only t)
11624                     buffer-read-only)
11625                 (delete-region armor-start
11626                                (progn
11627                                  (re-search-forward "^-+END PGP" nil t)
11628                                  (beginning-of-line 2)
11629                                  (point)))
11630                 (insert-buffer-substring pgg-output-buffer))))))))
11631
11632 (defun gnus-summary-verify-article ()
11633   "Verify the current article in traditional PGP way."
11634   (interactive)
11635   (save-excursion
11636     (set-buffer gnus-original-article-buffer)
11637     (goto-char (point-min))
11638     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11639       (error "Not a traditional PGP message!"))
11640     (re-search-forward "^-+END PGP" nil t)
11641     (beginning-of-line 2)
11642     (call-interactively (function pgg-verify-region))))
11643
11644 ;;;
11645 ;;; Generic summary marking commands
11646 ;;;
11647
11648 (defvar gnus-summary-marking-alist
11649   '((read gnus-del-mark "d")
11650     (unread gnus-unread-mark "u")
11651     (ticked gnus-ticked-mark "!")
11652     (dormant gnus-dormant-mark "?")
11653     (expirable gnus-expirable-mark "e"))
11654   "An alist of names/marks/keystrokes.")
11655
11656 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11657 (defvar gnus-summary-mark-map)
11658
11659 (defun gnus-summary-make-all-marking-commands ()
11660   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11661   (dolist (elem gnus-summary-marking-alist)
11662     (apply 'gnus-summary-make-marking-command elem)))
11663
11664 (defun gnus-summary-make-marking-command (name mark keystroke)
11665   (let ((map (make-sparse-keymap)))
11666     (define-key gnus-summary-generic-mark-map keystroke map)
11667     (dolist (lway `((next "next" next nil "n")
11668                     (next-unread "next unread" next t "N")
11669                     (prev "previous" prev nil "p")
11670                     (prev-unread "previous unread" prev t "P")
11671                     (nomove "" nil nil ,keystroke)))
11672       (let ((func (gnus-summary-make-marking-command-1
11673                    mark (car lway) lway name)))
11674         (setq func (eval func))
11675         (define-key map (nth 4 lway) func)))))
11676
11677 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11678   `(defun ,(intern
11679             (format "gnus-summary-put-mark-as-%s%s"
11680                     name (if (eq way 'nomove)
11681                              ""
11682                            (concat "-" (symbol-name way)))))
11683      (n)
11684      ,(format
11685        "Mark the current article as %s%s.
11686 If N, the prefix, then repeat N times.
11687 If N is negative, move in reverse order.
11688 The difference between N and the actual number of articles marked is
11689 returned."
11690        name (car (cdr lway)))
11691      (interactive "p")
11692      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11693
11694 (defun gnus-summary-generic-mark (n mark move unread)
11695   "Mark N articles with MARK."
11696   (unless (eq major-mode 'gnus-summary-mode)
11697     (error "This command can only be used in the summary buffer"))
11698   (gnus-summary-show-thread)
11699   (let ((nummove
11700          (cond
11701           ((eq move 'next) 1)
11702           ((eq move 'prev) -1)
11703           (t 0))))
11704     (if (zerop nummove)
11705         (setq n 1)
11706       (when (< n 0)
11707         (setq n (abs n)
11708               nummove (* -1 nummove))))
11709     (while (and (> n 0)
11710                 (gnus-summary-mark-article nil mark)
11711                 (zerop (gnus-summary-next-subject nummove unread t)))
11712       (setq n (1- n)))
11713     (when (/= 0 n)
11714       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11715     (gnus-summary-recenter)
11716     (gnus-summary-position-point)
11717     (gnus-set-mode-line 'summary)
11718     n))
11719
11720 (defun gnus-summary-insert-articles (articles)
11721   (when (setq articles
11722               (gnus-sorted-difference articles
11723                                       (mapcar (lambda (h)
11724                                                 (mail-header-number h))
11725                                               gnus-newsgroup-headers)))
11726     (setq gnus-newsgroup-headers
11727           (merge 'list
11728                  gnus-newsgroup-headers
11729                  (gnus-fetch-headers articles)
11730                  'gnus-article-sort-by-number))
11731     ;; Suppress duplicates?
11732     (when gnus-suppress-duplicates
11733       (gnus-dup-suppress-articles))
11734
11735     ;; We might want to build some more threads first.
11736     (when (and gnus-fetch-old-headers
11737                (eq gnus-headers-retrieved-by 'nov))
11738       (if (eq gnus-fetch-old-headers 'invisible)
11739           (gnus-build-all-threads)
11740         (gnus-build-old-threads)))
11741     ;; Let the Gnus agent mark articles as read.
11742     (when gnus-agent
11743       (gnus-agent-get-undownloaded-list))
11744     ;; Remove list identifiers from subject
11745     (when gnus-list-identifiers
11746       (gnus-summary-remove-list-identifiers))
11747     ;; First and last article in this newsgroup.
11748     (when gnus-newsgroup-headers
11749       (setq gnus-newsgroup-begin
11750             (mail-header-number (car gnus-newsgroup-headers))
11751             gnus-newsgroup-end
11752             (mail-header-number
11753              (gnus-last-element gnus-newsgroup-headers))))
11754     (when gnus-use-scoring
11755       (gnus-possibly-score-headers))))
11756
11757 (defun gnus-summary-insert-old-articles (&optional all)
11758   "Insert all old articles in this group.
11759 If ALL is non-nil, already read articles become readable.
11760 If ALL is a number, fetch this number of articles."
11761   (interactive "P")
11762   (prog1
11763       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11764             older len)
11765         (setq older
11766               ;; Some nntp servers lie about their active range.  When
11767               ;; this happens, the active range can be in the millions.
11768               ;; Use a compressed range to avoid creating a huge list.
11769               (gnus-range-difference (list gnus-newsgroup-active) old))
11770         (setq len (gnus-range-length older))
11771         (cond
11772          ((null older) nil)
11773          ((numberp all)
11774           (if (< all len)
11775               (let ((older-range (nreverse older)))
11776                 (setq older nil)
11777
11778                 (while (> all 0)
11779                   (let* ((r (pop older-range))
11780                          (min (if (numberp r) r (car r)))
11781                          (max (if (numberp r) r (cdr r))))
11782                     (while (and (<= min max)
11783                                 (> all 0))
11784                       (push max older)
11785                       (setq all (1- all)
11786                             max (1- max))))))
11787             (setq older (gnus-uncompress-range older))))
11788          (all
11789           (setq older (gnus-uncompress-range older)))
11790          (t
11791           (when (and (numberp gnus-large-newsgroup)
11792                    (> len gnus-large-newsgroup))
11793               (let* ((cursor-in-echo-area nil)
11794                      (initial (gnus-parameter-large-newsgroup-initial
11795                                gnus-newsgroup-name))
11796                      (input
11797                       (read-string
11798                        (format
11799                         "How many articles from %s (%s %d): "
11800                         (gnus-limit-string
11801                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11802                         (if initial "max" "default")
11803                         len)
11804                        (if initial
11805                            (cons (number-to-string initial)
11806                                  0)))))
11807                 (unless (string-match "^[ \t]*$" input)
11808                   (setq all (string-to-number input))
11809                   (if (< all len)
11810                       (let ((older-range (nreverse older)))
11811                         (setq older nil)
11812
11813                         (while (> all 0)
11814                           (let* ((r (pop older-range))
11815                                  (min (if (numberp r) r (car r)))
11816                                  (max (if (numberp r) r (cdr r))))
11817                             (while (and (<= min max)
11818                                         (> all 0))
11819                               (push max older)
11820                               (setq all (1- all)
11821                                     max (1- max))))))))))
11822           (setq older (gnus-uncompress-range older))))
11823         (if (not older)
11824             (message "No old news.")
11825           (gnus-summary-insert-articles older)
11826           (gnus-summary-limit (gnus-sorted-nunion old older))))
11827     (gnus-summary-position-point)))
11828
11829 (defun gnus-summary-insert-new-articles ()
11830   "Insert all new articles in this group."
11831   (interactive)
11832   (prog1
11833       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11834             (old-active gnus-newsgroup-active)
11835             (nnmail-fetched-sources (list t))
11836             i new)
11837         (setq gnus-newsgroup-active
11838               (gnus-activate-group gnus-newsgroup-name 'scan))
11839         (setq i (cdr gnus-newsgroup-active))
11840         (while (> i (cdr old-active))
11841           (push i new)
11842           (decf i))
11843         (if (not new)
11844             (message "No gnus is bad news.")
11845           (gnus-summary-insert-articles new)
11846           (setq gnus-newsgroup-unreads
11847                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11848           (gnus-summary-limit (gnus-sorted-nunion old new))))
11849     (gnus-summary-position-point)))
11850
11851 (gnus-summary-make-all-marking-commands)
11852
11853 (gnus-ems-redefine)
11854
11855 (provide 'gnus-sum)
11856
11857 (run-hooks 'gnus-sum-load-hook)
11858
11859 ;;; gnus-sum.el ends here