60012542860a696dfe63dee9318fd474e8464365
[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 (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'mm-uu-dissect "mm-uu")
57 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
58   "Deuglify broken Outlook (Express) articles and redisplay."
59   t)
60 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
61 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
62 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
63
64 (defcustom gnus-kill-summary-on-exit t
65   "*If non-nil, kill the summary buffer when you exit from it.
66 If nil, the summary will become a \"*Dead Summary*\" buffer, and
67 it will be killed sometime later."
68   :group 'gnus-summary-exit
69   :type 'boolean)
70
71 (defcustom gnus-fetch-old-headers nil
72   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
73 If an unread article in the group refers to an older, already read (or
74 just marked as read) article, the old article will not normally be
75 displayed in the Summary buffer.  If this variable is non-nil, Gnus
76 will attempt to grab the headers to the old articles, and thereby
77 build complete threads.  If it has the value `some', only enough
78 headers to connect otherwise loose threads will be displayed.  This
79 variable can also be a number.  In that case, no more than that number
80 of old headers will be fetched.  If it has the value `invisible', all
81 old headers will be fetched, but none will be displayed.
82
83 The server has to support NOV for any of this to work."
84   :group 'gnus-thread
85   :type '(choice (const :tag "off" nil)
86                  (const some)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :group 'gnus-thread
129   :type 'boolean)
130
131 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
132   "*A regexp to match subjects to be excluded from loose thread gathering.
133 As loose thread gathering is done on subjects only, that means that
134 there can be many false gatherings performed.  By rooting out certain
135 common subjects, gathering might become saner."
136   :group 'gnus-thread
137   :type 'regexp)
138
139 (defcustom gnus-summary-gather-subject-limit nil
140   "*Maximum length of subject comparisons when gathering loose threads.
141 Use nil to compare full subjects.  Setting this variable to a low
142 number will help gather threads that have been corrupted by
143 newsreaders chopping off subject lines, but it might also mean that
144 unrelated articles that have subject that happen to begin with the
145 same few characters will be incorrectly gathered.
146
147 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
148 comparing subjects."
149   :group 'gnus-thread
150   :type '(choice (const :tag "off" nil)
151                  (const fuzzy)
152                  (sexp :menu-tag "on" t)))
153
154 (defcustom gnus-simplify-subject-functions nil
155   "List of functions taking a string argument that simplify subjects.
156 The functions are applied recursively.
157
158 Useful functions to put in this list include:
159 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
160 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
161   :group 'gnus-thread
162   :type '(repeat function))
163
164 (defcustom gnus-simplify-ignored-prefixes nil
165   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  regexp))
169
170 (defcustom gnus-build-sparse-threads nil
171   "*If non-nil, fill in the gaps in threads.
172 If `some', only fill in the gaps that are needed to tie loose threads
173 together.  If `more', fill in all leaf nodes that Gnus can find.  If
174 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  (const some)
178                  (const more)
179                  (sexp :menu-tag "all" t)))
180
181 (defcustom gnus-summary-thread-gathering-function
182   'gnus-gather-threads-by-subject
183   "*Function used for gathering loose threads.
184 There are two pre-defined functions: `gnus-gather-threads-by-subject',
185 which only takes Subjects into consideration; and
186 `gnus-gather-threads-by-references', which compared the References
187 headers of the articles to find matches."
188   :group 'gnus-thread
189   :type '(radio (function-item gnus-gather-threads-by-subject)
190                 (function-item gnus-gather-threads-by-references)
191                 (function :tag "other")))
192
193 (defcustom gnus-summary-same-subject ""
194   "*String indicating that the current article has the same subject as the previous.
195 This variable will only be used if the value of
196 `gnus-summary-make-false-root' is `empty'."
197   :group 'gnus-summary-format
198   :type 'string)
199
200 (defcustom gnus-summary-goto-unread t
201   "*If t, many commands will go to the next unread article.
202 This applies to marking commands as well as other commands that
203 \"naturally\" select the next article, like, for instance, `SPC' at
204 the end of an article.
205
206 If nil, the marking commands do NOT go to the next unread article
207 \(they go to the next article instead).  If `never', commands that
208 usually go to the next unread article, will go to the next article,
209 whether it is read or not."
210   :group 'gnus-summary-marks
211   :link '(custom-manual "(gnus)Setting Marks")
212   :type '(choice (const :tag "off" nil)
213                  (const never)
214                  (sexp :menu-tag "on" t)))
215
216 (defcustom gnus-summary-default-score 0
217   "*Default article score level.
218 All scores generated by the score files will be added to this score.
219 If this variable is nil, scoring will be disabled."
220   :group 'gnus-score-default
221   :type '(choice (const :tag "disable")
222                  integer))
223
224 (defcustom gnus-summary-default-high-score 0
225   "*Default threshold for a high scored article.
226 An article will be highlighted as high scored if its score is greater
227 than this score."
228   :group 'gnus-score-default
229   :type 'integer)
230
231 (defcustom gnus-summary-default-low-score 0
232   "*Default threshold for a low scored article.
233 An article will be highlighted as low scored if its score is smaller
234 than this score."
235   :group 'gnus-score-default
236   :type 'integer)
237
238 (defcustom gnus-summary-zcore-fuzz 0
239   "*Fuzziness factor for the zcore in the summary buffer.
240 Articles with scores closer than this to `gnus-summary-default-score'
241 will not be marked."
242   :group 'gnus-summary-format
243   :type 'integer)
244
245 (defcustom gnus-simplify-subject-fuzzy-regexp nil
246   "*Strings to be removed when doing fuzzy matches.
247 This can either be a regular expression or list of regular expressions
248 that will be removed from subject strings if fuzzy subject
249 simplification is selected."
250   :group 'gnus-thread
251   :type '(repeat regexp))
252
253 (defcustom gnus-show-threads t
254   "*If non-nil, display threads in summary mode."
255   :group 'gnus-thread
256   :type 'boolean)
257
258 (defcustom gnus-thread-hide-subtree nil
259   "*If non-nil, hide all threads initially.
260 This can be a predicate specifier which says which threads to hide.
261 If threads are hidden, you have to run the command
262 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
263 to expose hidden threads."
264   :group 'gnus-thread
265   :type 'boolean)
266
267 (defcustom gnus-thread-hide-killed t
268   "*If non-nil, hide killed threads automatically."
269   :group 'gnus-thread
270   :type 'boolean)
271
272 (defcustom gnus-thread-ignore-subject t
273   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
274 If nil, articles that have different subjects from their parents will
275 start separate threads."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-operation-ignore-subject t
280   "*If non-nil, subjects will be ignored when doing thread commands.
281 This affects commands like `gnus-summary-kill-thread' and
282 `gnus-summary-lower-thread'.
283
284 If this variable is nil, articles in the same thread with different
285 subjects will not be included in the operation in question.  If this
286 variable is `fuzzy', only articles that have subjects that are fuzzily
287 equal will be included."
288   :group 'gnus-thread
289   :type '(choice (const :tag "off" nil)
290                  (const fuzzy)
291                  (sexp :tag "on" t)))
292
293 (defcustom gnus-thread-indent-level 4
294   "*Number that says how much each sub-thread should be indented."
295   :group 'gnus-thread
296   :type 'integer)
297
298 (defcustom gnus-auto-extend-newsgroup t
299   "*If non-nil, extend newsgroup forward and backward when requested."
300   :group 'gnus-summary-choose
301   :type 'boolean)
302
303 (defcustom gnus-auto-select-first t
304   "*If non-nil, select the article under point.
305 Which article this is is controlled by the `gnus-auto-select-subject'
306 variable.
307
308 If you want to prevent automatic selection of articles in some
309 newsgroups, set the variable to nil in `gnus-select-group-hook'."
310   :group 'gnus-group-select
311   :type '(choice (const :tag "none" nil)
312                  (sexp :menu-tag "first" t)))
313
314 (defcustom gnus-auto-select-subject 'unread
315   "*Says what subject to place under point when entering a group.
316
317 This variable can either be the symbols `first' (place point on the
318 first subject), `unread' (place point on the subject line of the first
319 unread article), `best' (place point on the subject line of the
320 higest-scored article), `unseen' (place point on the subject line of
321 the first unseen article), 'unseen-or-unread' (place point on the subject
322 line of the first unseen article or, if all article have been seen, on the
323 subject line of the first unread article), or a function to be called to
324 place point on some subject line."
325   :group 'gnus-group-select
326   :type '(choice (const best)
327                  (const unread)
328                  (const first)
329                  (const unseen)
330                  (const unseen-or-unread)))
331
332 (defcustom gnus-dont-select-after-jump-to-other-group nil
333   "If non-nil, don't select the first unread article after entering the
334 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
335 it is depend on the value of `gnus-auto-select-first' whether to select
336 or not."
337   :group 'gnus-group-select
338   :type 'boolean)
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols `nil' (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :group 'gnus-summary-maneuvering
377   :type '(choice (const :tag "None" nil)
378                  (const :tag "Undownloaded when unplugged" undownloaded)
379                  (const :tag "Undownloaded" always-undownloaded)
380                  (const :tag "Unfetched" unfetched)))
381
382 (defcustom gnus-summary-check-current nil
383   "*If non-nil, consider the current article when moving.
384 The \"unread\" movement commands will stay on the same line if the
385 current article is unread."
386   :group 'gnus-summary-maneuvering
387   :type 'boolean)
388
389 (defcustom gnus-auto-center-summary t
390   "*If non-nil, always center the current summary buffer.
391 In particular, if `vertical' do only vertical recentering.  If non-nil
392 and non-`vertical', do both horizontal and vertical recentering."
393   :group 'gnus-summary-maneuvering
394   :type '(choice (const :tag "none" nil)
395                  (const vertical)
396                  (integer :tag "height")
397                  (sexp :menu-tag "both" t)))
398
399 (defvar gnus-auto-center-group t
400   "*If non-nil, always center the group buffer.")
401
402 (defcustom gnus-show-all-headers nil
403   "*If non-nil, don't hide any headers."
404   :group 'gnus-article-hiding
405   :group 'gnus-article-headers
406   :type 'boolean)
407
408 (defcustom gnus-summary-ignore-duplicates nil
409   "*If non-nil, ignore articles with identical Message-ID headers."
410   :group 'gnus-summary
411   :type 'boolean)
412
413 (defcustom gnus-single-article-buffer t
414   "*If non-nil, display all articles in the same buffer.
415 If nil, each group will get its own article buffer."
416   :group 'gnus-article-various
417   :type 'boolean)
418
419 (defcustom gnus-break-pages t
420   "*If non-nil, do page breaking on articles.
421 The page delimiter is specified by the `gnus-page-delimiter'
422 variable."
423   :group 'gnus-article-various
424   :type 'boolean)
425
426 (defcustom gnus-show-mime t
427   "*If non-nil, do mime processing of articles.
428 The articles will simply be fed to the function given by
429 `gnus-article-display-method-for-mime'."
430   :group 'gnus-article-mime
431   :type 'boolean)
432
433 (defcustom gnus-move-split-methods nil
434   "*Variable used to suggest where articles are to be moved to.
435 It uses the same syntax as the `gnus-split-methods' variable.
436 However, whereas `gnus-split-methods' specifies file names as targets,
437 this variable specifies group names."
438   :group 'gnus-summary-mail
439   :type '(repeat (choice (list :value (fun) function)
440                          (cons :value ("" "") regexp (repeat string))
441                          (sexp :value nil))))
442
443 (defcustom gnus-unread-mark ?\ ;;;Whitespace
444   "*Mark used for unread articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-ticked-mark ?!
449   "*Mark used for ticked articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-dormant-mark ??
454   "*Mark used for dormant articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-del-mark ?r
459   "*Mark used for del'd articles."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-read-mark ?R
464   "*Mark used for read articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-expirable-mark ?E
469   "*Mark used for expirable articles."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-killed-mark ?K
474   "*Mark used for killed articles."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-spam-mark ?$
479   "*Mark used for spam articles."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-recent-mark ?N
514   "*Mark used for articles that are recent."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-cached-mark ?*
519   "*Mark used for articles that are in the cache."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-saved-mark ?S
524   "*Mark used for articles that have been saved."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-unseen-mark ?.
529   "*Mark used for articles that haven't been seen."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-no-mark ?\ ;;;Whitespace
534   "*Mark used for articles that have no other secondary mark."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-ancient-mark ?O
539   "*Mark used for ancient articles."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-sparse-mark ?Q
544   "*Mark used for sparsely reffed articles."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-canceled-mark ?G
549   "*Mark used for canceled articles."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-duplicate-mark ?M
554   "*Mark used for duplicate articles."
555   :group 'gnus-summary-marks
556   :type 'character)
557
558 (defcustom gnus-undownloaded-mark ?-
559   "*Mark used for articles that weren't downloaded."
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-downloaded-mark ?+
564   "*Mark used for articles that were downloaded."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloadable-mark ?%
569   "*Mark used for articles that are to be downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unsendable-mark ?=
574   "*Mark used for articles that won't be sent."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-score-over-mark ?+
579   "*Score mark used for articles with high scores."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-below-mark ?-
584   "*Score mark used for articles with low scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
589   "*There is no thread under the article."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-not-empty-thread-mark ?=
594   "*There is a thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-view-pseudo-asynchronously nil
599   "*If non-nil, Gnus will view pseudo-articles asynchronously."
600   :group 'gnus-extract-view
601   :type 'boolean)
602
603 (defcustom gnus-auto-expirable-marks
604   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
605         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
606         gnus-souped-mark gnus-duplicate-mark)
607   "*The list of marks converted into expiration if a group is auto-expirable."
608   :version "21.1"
609   :group 'gnus-summary
610   :type '(repeat character))
611
612 (defcustom gnus-inhibit-user-auto-expire t
613   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
614   :version "21.1"
615   :group 'gnus-summary
616   :type 'boolean)
617
618 (defcustom gnus-view-pseudos nil
619   "*If `automatic', pseudo-articles will be viewed automatically.
620 If `not-confirm', pseudos will be viewed automatically, and the user
621 will not be asked to confirm the command."
622   :group 'gnus-extract-view
623   :type '(choice (const :tag "off" nil)
624                  (const automatic)
625                  (const not-confirm)))
626
627 (defcustom gnus-view-pseudos-separately t
628   "*If non-nil, one pseudo-article will be created for each file to be viewed.
629 If nil, all files that use the same viewing command will be given as a
630 list of parameters to that command."
631   :group 'gnus-extract-view
632   :type 'boolean)
633
634 (defcustom gnus-insert-pseudo-articles t
635   "*If non-nil, insert pseudo-articles when decoding articles."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-summary-dummy-line-format
640   "   %(:                             :%) %S\n"
641   "*The format specification for the dummy roots in the summary buffer.
642 It works along the same lines as a normal formatting string,
643 with some simple extensions.
644
645 %S  The subject
646
647 General format specifiers can also be used.
648 See `(gnus)Formatting Variables'."
649   :link '(custom-manual "(gnus)Formatting Variables")
650   :group 'gnus-threading
651   :type 'string)
652
653 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
654   "*The format specification for the summary mode line.
655 It works along the same lines as a normal formatting string,
656 with some simple extensions:
657
658 %G  Group name
659 %p  Unprefixed group name
660 %A  Current article number
661 %z  Current article score
662 %V  Gnus version
663 %U  Number of unread articles in the group
664 %e  Number of unselected articles in the group
665 %Z  A string with unread/unselected article counts
666 %g  Shortish group name
667 %S  Subject of the current article
668 %u  User-defined spec
669 %s  Current score file name
670 %d  Number of dormant articles
671 %r  Number of articles that have been marked as read in this session
672 %E  Number of articles expunged by the score files"
673   :group 'gnus-summary-format
674   :type 'string)
675
676 (defcustom gnus-list-identifiers nil
677   "Regexp that matches list identifiers to be removed from subject.
678 This can also be a list of regexps."
679   :version "21.1"
680   :group 'gnus-summary-format
681   :group 'gnus-article-hiding
682   :type '(choice (const :tag "none" nil)
683                  (regexp :value ".*")
684                  (repeat :value (".*") regexp)))
685
686 (defcustom gnus-summary-mark-below 0
687   "*Mark all articles with a score below this variable as read.
688 This variable is local to each summary buffer and usually set by the
689 score file."
690   :group 'gnus-score-default
691   :type 'integer)
692
693 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
694   "*List of functions used for sorting articles in the summary buffer.
695
696 Each function takes two articles and returns non-nil if the first
697 article should be sorted before the other.  If you use more than one
698 function, the primary sort function should be the last.  You should
699 probably always include `gnus-article-sort-by-number' in the list of
700 sorting functions -- preferably first.  Also note that sorting by date
701 is often much slower than sorting by number, and the sorting order is
702 very similar.  (Sorting by date means sorting by the time the message
703 was sent, sorting by number means sorting by arrival time.)
704
705 Ready-made functions include `gnus-article-sort-by-number',
706 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
707 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
708 and `gnus-article-sort-by-score'.
709
710 When threading is turned on, the variable `gnus-thread-sort-functions'
711 controls how articles are sorted."
712   :group 'gnus-summary-sort
713   :type '(repeat (choice (function-item gnus-article-sort-by-number)
714                          (function-item gnus-article-sort-by-author)
715                          (function-item gnus-article-sort-by-subject)
716                          (function-item gnus-article-sort-by-date)
717                          (function-item gnus-article-sort-by-score)
718                          (function-item gnus-article-sort-by-random)
719                          (function :tag "other"))))
720
721 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
722   "*List of functions used for sorting threads in the summary buffer.
723 By default, threads are sorted by article number.
724
725 Each function takes two threads and returns non-nil if the first
726 thread should be sorted before the other.  If you use more than one
727 function, the primary sort function should be the last.  You should
728 probably always include `gnus-thread-sort-by-number' in the list of
729 sorting functions -- preferably first.  Also note that sorting by date
730 is often much slower than sorting by number, and the sorting order is
731 very similar.  (Sorting by date means sorting by the time the message
732 was sent, sorting by number means sorting by arrival time.)
733
734 Ready-made functions include `gnus-thread-sort-by-number',
735 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
736 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
737 `gnus-thread-sort-by-most-recent-number',
738 `gnus-thread-sort-by-most-recent-date',
739 `gnus-thread-sort-by-random', and
740 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
741
742 When threading is turned off, the variable
743 `gnus-article-sort-functions' controls how articles are sorted."
744   :group 'gnus-summary-sort
745   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
746                          (function-item gnus-thread-sort-by-author)
747                          (function-item gnus-thread-sort-by-subject)
748                          (function-item gnus-thread-sort-by-date)
749                          (function-item gnus-thread-sort-by-score)
750                          (function-item gnus-thread-sort-by-total-score)
751                          (function-item gnus-thread-sort-by-random)
752                          (function :tag "other"))))
753
754 (defcustom gnus-thread-score-function '+
755   "*Function used for calculating the total score of a thread.
756
757 The function is called with the scores of the article and each
758 subthread and should then return the score of the thread.
759
760 Some functions you can use are `+', `max', or `min'."
761   :group 'gnus-summary-sort
762   :type 'function)
763
764 (defcustom gnus-summary-expunge-below nil
765   "All articles that have a score less than this variable will be expunged.
766 This variable is local to the summary buffers."
767   :group 'gnus-score-default
768   :type '(choice (const :tag "off" nil)
769                  integer))
770
771 (defcustom gnus-thread-expunge-below nil
772   "All threads that have a total score less than this variable will be expunged.
773 See `gnus-thread-score-function' for en explanation of what a
774 \"thread score\" is.
775
776 This variable is local to the summary buffers."
777   :group 'gnus-threading
778   :group 'gnus-score-default
779   :type '(choice (const :tag "off" nil)
780                  integer))
781
782 (defcustom gnus-summary-mode-hook nil
783   "*A hook for Gnus summary mode.
784 This hook is run before any variables are set in the summary buffer."
785   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
786   :group 'gnus-summary-various
787   :type 'hook)
788
789 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
790 (when (featurep 'xemacs)
791   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
792   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
793   (add-hook 'gnus-summary-mode-hook
794             'gnus-xmas-switch-horizontal-scrollbar-off))
795
796 (defcustom gnus-summary-menu-hook nil
797   "*Hook run after the creation of the summary mode menu."
798   :group 'gnus-summary-visual
799   :type 'hook)
800
801 (defcustom gnus-summary-exit-hook nil
802   "*A hook called on exit from the summary buffer.
803 It will be called with point in the group buffer."
804   :group 'gnus-summary-exit
805   :type 'hook)
806
807 (defcustom gnus-summary-prepare-hook nil
808   "*A hook called after the summary buffer has been generated.
809 If you want to modify the summary buffer, you can use this hook."
810   :group 'gnus-summary-various
811   :type 'hook)
812
813 (defcustom gnus-summary-prepared-hook nil
814   "*A hook called as the last thing after the summary buffer has been generated."
815   :group 'gnus-summary-various
816   :type 'hook)
817
818 (defcustom gnus-summary-generate-hook nil
819   "*A hook run just before generating the summary buffer.
820 This hook is commonly used to customize threading variables and the
821 like."
822   :group 'gnus-summary-various
823   :type 'hook)
824
825 (defcustom gnus-select-group-hook nil
826   "*A hook called when a newsgroup is selected.
827
828 If you'd like to simplify subjects like the
829 `gnus-summary-next-same-subject' command does, you can use the
830 following hook:
831
832  (add-hook gnus-select-group-hook
833            (lambda ()
834              (mapcar (lambda (header)
835                        (mail-header-set-subject
836                         header
837                         (gnus-simplify-subject
838                          (mail-header-subject header) 're-only)))
839                      gnus-newsgroup-headers)))"
840   :group 'gnus-group-select
841   :type 'hook)
842
843 (defcustom gnus-select-article-hook nil
844   "*A hook called when an article is selected."
845   :group 'gnus-summary-choose
846   :options '(gnus-agent-fetch-selected-article)
847   :type 'hook)
848
849 (defcustom gnus-visual-mark-article-hook
850   (list 'gnus-highlight-selected-summary)
851   "*Hook run after selecting an article in the summary buffer.
852 It is meant to be used for highlighting the article in some way.  It
853 is not run if `gnus-visual' is nil."
854   :group 'gnus-summary-visual
855   :type 'hook)
856
857 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
858   "*A hook called before parsing the headers."
859   :group 'gnus-various
860   :type 'hook)
861
862 (defcustom gnus-exit-group-hook nil
863   "*A hook called when exiting summary mode.
864 This hook is not called from the non-updating exit commands like `Q'."
865   :group 'gnus-various
866   :type 'hook)
867
868 (defcustom gnus-summary-update-hook
869   (list 'gnus-summary-highlight-line)
870   "*A hook called when a summary line is changed.
871 The hook will not be called if `gnus-visual' is nil.
872
873 The default function `gnus-summary-highlight-line' will
874 highlight the line according to the `gnus-summary-highlight'
875 variable."
876   :group 'gnus-summary-visual
877   :type 'hook)
878
879 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
880   "*A hook called when an article is selected for the first time.
881 The hook is intended to mark an article as read (or unread)
882 automatically when it is selected."
883   :group 'gnus-summary-choose
884   :type 'hook)
885
886 (defcustom gnus-group-no-more-groups-hook nil
887   "*A hook run when returning to group mode having no more (unread) groups."
888   :group 'gnus-group-select
889   :type 'hook)
890
891 (defcustom gnus-ps-print-hook nil
892   "*A hook run before ps-printing something from Gnus."
893   :group 'gnus-summary
894   :type 'hook)
895
896 (defcustom gnus-summary-article-move-hook nil
897   "*A hook called after an article is moved, copied, respooled, or crossposted."
898   :group 'gnus-summary
899   :type 'hook)
900
901 (defcustom gnus-summary-article-delete-hook nil
902   "*A hook called after an article is deleted."
903   :group 'gnus-summary
904   :type 'hook)
905
906 (defcustom gnus-summary-article-expire-hook nil
907   "*A hook called after an article is expired."
908   :group 'gnus-summary
909   :type 'hook)
910
911 (defcustom gnus-summary-display-arrow
912   (and (fboundp 'display-graphic-p)
913        (display-graphic-p))
914   "*If non-nil, display an arrow highlighting the current article."
915   :version "21.1"
916   :group 'gnus-summary
917   :type 'boolean)
918
919 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
920   "Face used for highlighting the current article in the summary buffer."
921   :group 'gnus-summary-visual
922   :type 'face)
923
924 (defvar gnus-tmp-downloaded nil)
925
926 (defcustom gnus-summary-highlight
927   '(((eq mark gnus-canceled-mark)
928      . gnus-summary-cancelled-face)
929     ((and uncached (> score default-high))
930      . gnus-summary-high-undownloaded-face)
931     ((and uncached (< score default-low))
932      . gnus-summary-low-undownloaded-face)
933     (uncached
934      . gnus-summary-normal-undownloaded-face)
935     ((and (> score default-high)
936           (or (eq mark gnus-dormant-mark)
937               (eq mark gnus-ticked-mark)))
938      . gnus-summary-high-ticked-face)
939     ((and (< score default-low)
940           (or (eq mark gnus-dormant-mark)
941               (eq mark gnus-ticked-mark)))
942      . gnus-summary-low-ticked-face)
943     ((or (eq mark gnus-dormant-mark)
944          (eq mark gnus-ticked-mark))
945      . gnus-summary-normal-ticked-face)
946     ((and (> score default-high) (eq mark gnus-ancient-mark))
947      . gnus-summary-high-ancient-face)
948     ((and (< score default-low) (eq mark gnus-ancient-mark))
949      . gnus-summary-low-ancient-face)
950     ((eq mark gnus-ancient-mark)
951      . gnus-summary-normal-ancient-face)
952     ((and (> score default-high) (eq mark gnus-unread-mark))
953      . gnus-summary-high-unread-face)
954     ((and (< score default-low) (eq mark gnus-unread-mark))
955      . gnus-summary-low-unread-face)
956     ((eq mark gnus-unread-mark)
957      . gnus-summary-normal-unread-face)
958     ((> score default-high)
959      . gnus-summary-high-read-face)
960     ((< score default-low)
961      . gnus-summary-low-read-face)
962     (t
963      . gnus-summary-normal-read-face))
964   "*Controls the highlighting of summary buffer lines.
965
966 A list of (FORM . FACE) pairs.  When deciding how a a particular
967 summary line should be displayed, each form is evaluated.  The content
968 of the face field after the first true form is used.  You can change
969 how those summary lines are displayed, by editing the face field.
970
971 You can use the following variables in the FORM field.
972
973 score:        The article's score
974 default:      The default article score.
975 default-high: The default score for high scored articles.
976 default-low:  The default score for low scored articles.
977 below:        The score below which articles are automatically marked as read.
978 mark:         The articles mark."
979   :group 'gnus-summary-visual
980   :type '(repeat (cons (sexp :tag "Form" nil)
981                        face)))
982
983 (defcustom gnus-alter-header-function nil
984   "Function called to allow alteration of article header structures.
985 The function is called with one parameter, the article header vector,
986 which it may alter in any way."
987   :type '(choice (const :tag "None" nil)
988                  function)
989   :group 'gnus-summary)
990
991 (defvar gnus-decode-encoded-word-function
992   (mime-find-field-decoder 'From 'nov)
993   "Variable that says which function should be used to decode a string with encoded words.")
994
995 (defcustom gnus-extra-headers '(To Newsgroups)
996   "*Extra headers to parse."
997   :version "21.1"
998   :group 'gnus-summary
999   :type '(repeat symbol))
1000
1001 (defcustom gnus-ignored-from-addresses
1002   (and user-mail-address (regexp-quote user-mail-address))
1003   "*Regexp of From headers that may be suppressed in favor of To headers."
1004   :version "21.1"
1005   :group 'gnus-summary
1006   :type 'regexp)
1007
1008 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1009   "List of charsets that should be ignored.
1010 When these charsets are used in the \"charset\" parameter, the
1011 default charset will be used instead."
1012   :version "21.1"
1013   :type '(repeat symbol)
1014   :group 'gnus-charset)
1015
1016 (gnus-define-group-parameter
1017  ignored-charsets
1018  :type list
1019  :function-document
1020  "Return the ignored charsets of GROUP."
1021  :variable gnus-group-ignored-charsets-alist
1022  :variable-default
1023  '(("alt\\.chinese\\.text" iso-8859-1))
1024  :variable-document
1025  "Alist of regexps (to match group names) and charsets that should be ignored.
1026 When these charsets are used in the \"charset\" parameter, the
1027 default charset will be used instead."
1028  :variable-group gnus-charset
1029  :variable-type '(repeat (cons (regexp :tag "Group")
1030                                (repeat symbol)))
1031  :parameter-type '(choice :tag "Ignored charsets"
1032                           :value nil
1033                           (repeat (symbol)))
1034  :parameter-document       "\
1035 List of charsets that should be ignored.
1036
1037 When these charsets are used in the \"charset\" parameter, the
1038 default charset will be used instead.")
1039
1040 (defcustom gnus-group-highlight-words-alist nil
1041   "Alist of group regexps and highlight regexps.
1042 This variable uses the same syntax as `gnus-emphasis-alist'."
1043   :version "21.1"
1044   :type '(repeat (cons (regexp :tag "Group")
1045                        (repeat (list (regexp :tag "Highlight regexp")
1046                                      (number :tag "Group for entire word" 0)
1047                                      (number :tag "Group for displayed part" 0)
1048                                      (symbol :tag "Face"
1049                                              gnus-emphasis-highlight-words)))))
1050   :group 'gnus-summary-visual)
1051
1052 (defcustom gnus-use-wheel nil
1053   "Use Intelli-mouse on summary movement"
1054   :type 'boolean
1055   :group 'gnus-summary-maneuvering)
1056
1057 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1058   "Amount to scroll messages by spinning the mouse wheel.
1059 This is actually a cons cell, where the first item is the amount to scroll
1060 on a normal wheel event, and the second is the amount to scroll when the
1061 wheel is moved with the shift key depressed."
1062   :type '(cons (integer :tag "Shift") integer)
1063   :group 'gnus-summary-maneuvering)
1064
1065 (defcustom gnus-wheel-edge-resistance 2
1066   "How hard it should be to change the current article
1067 by moving the mouse over the edge of the article window."
1068   :type 'integer
1069   :group 'gnus-summary-maneuvering)
1070
1071 (defcustom gnus-summary-show-article-charset-alist
1072   nil
1073   "Alist of number and charset.
1074 The article will be shown with the charset corresponding to the
1075 numbered argument.
1076 For example: ((1 . cn-gb-2312) (2 . big5))."
1077   :version "21.1"
1078   :type '(repeat (cons (number :tag "Argument" 1)
1079                        (symbol :tag "Charset")))
1080   :group 'gnus-charset)
1081
1082 (defcustom gnus-preserve-marks t
1083   "Whether marks are preserved when moving, copying and respooling messages."
1084   :version "21.1"
1085   :type 'boolean
1086   :group 'gnus-summary-marks)
1087
1088 (defcustom gnus-alter-articles-to-read-function nil
1089   "Function to be called to alter the list of articles to be selected."
1090   :type '(choice (const nil) function)
1091   :group 'gnus-summary)
1092
1093 (defcustom gnus-orphan-score nil
1094   "*All orphans get this score added.  Set in the score file."
1095   :group 'gnus-score-default
1096   :type '(choice (const nil)
1097                  integer))
1098
1099 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1100   "*A regexp to match MIME parts when saving multiple parts of a
1101 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1102 This regexp will be used by default when prompting the user for which
1103 type of files to save."
1104   :group 'gnus-summary
1105   :type 'regexp)
1106
1107 (defcustom gnus-read-all-available-headers nil
1108   "Whether Gnus should parse all headers made available to it.
1109 This is mostly relevant for slow backends where the user may
1110 wish to widen the summary buffer to include all headers
1111 that were fetched.  Say, for nnultimate groups."
1112   :group 'gnus-summary
1113   :type '(choice boolean regexp))
1114
1115 (defcustom gnus-summary-muttprint-program "muttprint"
1116   "Command (and optional arguments) used to run Muttprint."
1117   :version "21.3"
1118   :group 'gnus-summary
1119   :type 'string)
1120
1121 (defcustom gnus-article-loose-mime nil
1122   "If non-nil, don't require MIME-Version header.
1123 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1124 supply the MIME-Version header or deliberately strip it From the mail.
1125 Set it to non-nil, Gnus will treat some articles as MIME even if
1126 the MIME-Version header is missed."
1127   :version "21.3"
1128   :type 'boolean
1129   :group 'gnus-article-mime)
1130
1131 (defcustom gnus-article-emulate-mime t
1132   "If non-nil, use MIME emulation for uuencode and the like.
1133 This means that Gnus will search message bodies for text that look
1134 like uuencoded bits, yEncoded bits, and so on, and present that using
1135 the normal Gnus MIME machinery."
1136   :type 'boolean
1137   :group 'gnus-article-mime)
1138
1139 ;;; Internal variables
1140
1141 (defvar gnus-summary-display-cache nil)
1142 (defvar gnus-article-mime-handles nil)
1143 (defvar gnus-article-decoded-p nil)
1144 (defvar gnus-article-charset nil)
1145 (defvar gnus-article-ignored-charsets nil)
1146 (defvar gnus-scores-exclude-files nil)
1147 (defvar gnus-page-broken nil)
1148
1149 (defvar gnus-original-article nil)
1150 (defvar gnus-article-internal-prepare-hook nil)
1151 (defvar gnus-newsgroup-process-stack nil)
1152
1153 (defvar gnus-thread-indent-array nil)
1154 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1155 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1156   "Function called to sort the articles within a thread after it has been gathered together.")
1157
1158 (defvar gnus-summary-save-parts-type-history nil)
1159 (defvar gnus-summary-save-parts-last-directory nil)
1160
1161 ;; Avoid highlighting in kill files.
1162 (defvar gnus-summary-inhibit-highlight nil)
1163 (defvar gnus-newsgroup-selected-overlay nil)
1164 (defvar gnus-inhibit-limiting nil)
1165 (defvar gnus-newsgroup-adaptive-score-file nil)
1166 (defvar gnus-current-score-file nil)
1167 (defvar gnus-current-move-group nil)
1168 (defvar gnus-current-copy-group nil)
1169 (defvar gnus-current-crosspost-group nil)
1170 (defvar gnus-newsgroup-display nil)
1171
1172 (defvar gnus-newsgroup-dependencies nil)
1173 (defvar gnus-newsgroup-adaptive nil)
1174 (defvar gnus-summary-display-article-function nil)
1175 (defvar gnus-summary-highlight-line-function nil
1176   "Function called after highlighting a summary line.")
1177
1178 (defvar gnus-summary-line-format-alist
1179   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1180     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1181     (?s gnus-tmp-subject-or-nil ?s)
1182     (?n gnus-tmp-name ?s)
1183     (?A (std11-address-string
1184          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1185     (?a (or (std11-full-name-string
1186              (car (mime-entity-read-field gnus-tmp-header 'From)))
1187             gnus-tmp-from) ?s)
1188     (?F gnus-tmp-from ?s)
1189     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1190     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1191     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1192     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1193     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1194     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1195     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1196     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1197     (?L gnus-tmp-lines ?s)
1198     (?O gnus-tmp-downloaded ?c)
1199     (?I gnus-tmp-indentation ?s)
1200     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1201     (?R gnus-tmp-replied ?c)
1202     (?\[ gnus-tmp-opening-bracket ?c)
1203     (?\] gnus-tmp-closing-bracket ?c)
1204     (?\> (make-string gnus-tmp-level ? ) ?s)
1205     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1206     (?i gnus-tmp-score ?d)
1207     (?z gnus-tmp-score-char ?c)
1208     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1209     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1210     (?U gnus-tmp-unread ?c)
1211     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1212         ?s)
1213     (?t (gnus-summary-number-of-articles-in-thread
1214          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1215         ?d)
1216     (?e (gnus-summary-number-of-articles-in-thread
1217          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1218         ?c)
1219     (?u gnus-tmp-user-defined ?s)
1220     (?P (gnus-pick-line-number) ?d)
1221     (?B gnus-tmp-thread-tree-header-string ?s)
1222     (user-date (gnus-user-date
1223                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1224   "An alist of format specifications that can appear in summary lines.
1225 These are paired with what variables they correspond with, along with
1226 the type of the variable (string, integer, character, etc).")
1227
1228 (defvar gnus-summary-dummy-line-format-alist
1229   `((?S gnus-tmp-subject ?s)
1230     (?N gnus-tmp-number ?d)
1231     (?u gnus-tmp-user-defined ?s)))
1232
1233 (defvar gnus-summary-mode-line-format-alist
1234   `((?G gnus-tmp-group-name ?s)
1235     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1236     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1237     (?A gnus-tmp-article-number ?d)
1238     (?Z gnus-tmp-unread-and-unselected ?s)
1239     (?V gnus-version ?s)
1240     (?U gnus-tmp-unread-and-unticked ?d)
1241     (?S gnus-tmp-subject ?s)
1242     (?e gnus-tmp-unselected ?d)
1243     (?u gnus-tmp-user-defined ?s)
1244     (?d (length gnus-newsgroup-dormant) ?d)
1245     (?t (length gnus-newsgroup-marked) ?d)
1246     (?h (length gnus-newsgroup-spam-marked) ?d)
1247     (?r (length gnus-newsgroup-reads) ?d)
1248     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1249     (?E gnus-newsgroup-expunged-tally ?d)
1250     (?s (gnus-current-score-file-nondirectory) ?s)))
1251
1252 (defvar gnus-last-search-regexp nil
1253   "Default regexp for article search command.")
1254
1255 (defvar gnus-summary-search-article-matched-data nil
1256   "Last matched data of article search command.  It is the local variable
1257 in `gnus-article-buffer' which consists of the list of start position,
1258 end position and text.")
1259
1260 (defvar gnus-last-shell-command nil
1261   "Default shell command on article.")
1262
1263 (defvar gnus-newsgroup-agentized nil
1264   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1265 (defvar gnus-newsgroup-begin nil)
1266 (defvar gnus-newsgroup-end nil)
1267 (defvar gnus-newsgroup-last-rmail nil)
1268 (defvar gnus-newsgroup-last-mail nil)
1269 (defvar gnus-newsgroup-last-folder nil)
1270 (defvar gnus-newsgroup-last-file nil)
1271 (defvar gnus-newsgroup-auto-expire nil)
1272 (defvar gnus-newsgroup-active nil)
1273
1274 (defvar gnus-newsgroup-data nil)
1275 (defvar gnus-newsgroup-data-reverse nil)
1276 (defvar gnus-newsgroup-limit nil)
1277 (defvar gnus-newsgroup-limits nil)
1278
1279 (defvar gnus-newsgroup-unreads nil
1280   "Sorted list of unread articles in the current newsgroup.")
1281
1282 (defvar gnus-newsgroup-unselected nil
1283   "Sorted list of unselected unread articles in the current newsgroup.")
1284
1285 (defvar gnus-newsgroup-reads nil
1286   "Alist of read articles and article marks in the current newsgroup.")
1287
1288 (defvar gnus-newsgroup-expunged-tally nil)
1289
1290 (defvar gnus-newsgroup-marked nil
1291   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1292
1293 (defvar gnus-newsgroup-spam-marked nil
1294   "List of ranges of articles that have been marked as spam.")
1295
1296 (defvar gnus-newsgroup-killed nil
1297   "List of ranges of articles that have been through the scoring process.")
1298
1299 (defvar gnus-newsgroup-cached nil
1300   "Sorted list of articles that come from the article cache.")
1301
1302 (defvar gnus-newsgroup-saved nil
1303   "List of articles that have been saved.")
1304
1305 (defvar gnus-newsgroup-kill-headers nil)
1306
1307 (defvar gnus-newsgroup-replied nil
1308   "List of articles that have been replied to in the current newsgroup.")
1309
1310 (defvar gnus-newsgroup-forwarded nil
1311   "List of articles that have been forwarded in the current newsgroup.")
1312
1313 (defvar gnus-newsgroup-recent nil
1314   "List of articles that have are recent in the current newsgroup.")
1315
1316 (defvar gnus-newsgroup-expirable nil
1317   "Sorted list of articles in the current newsgroup that can be expired.")
1318
1319 (defvar gnus-newsgroup-processable nil
1320   "List of articles in the current newsgroup that can be processed.")
1321
1322 (defvar gnus-newsgroup-downloadable nil
1323   "Sorted list of articles in the current newsgroup that can be processed.")
1324
1325 (defvar gnus-newsgroup-unfetched nil
1326   "Sorted list of articles in the current newsgroup whose headers have
1327 not been fetched into the agent.
1328
1329 This list will always be a subset of gnus-newsgroup-undownloaded.")
1330
1331 (defvar gnus-newsgroup-undownloaded nil
1332   "List of articles in the current newsgroup that haven't been downloaded.")
1333
1334 (defvar gnus-newsgroup-unsendable nil
1335   "List of articles in the current newsgroup that won't be sent.")
1336
1337 (defvar gnus-newsgroup-bookmarks nil
1338   "List of articles in the current newsgroup that have bookmarks.")
1339
1340 (defvar gnus-newsgroup-dormant nil
1341   "Sorted list of dormant articles in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-unseen nil
1344   "List of unseen articles in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-seen nil
1347   "Range of seen articles in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-articles nil
1350   "List of articles in the current newsgroup.")
1351
1352 (defvar gnus-newsgroup-scored nil
1353   "List of scored articles in the current newsgroup.")
1354
1355 (defvar gnus-newsgroup-incorporated nil
1356   "List of incorporated articles in the current newsgroup.")
1357
1358 (defvar gnus-newsgroup-headers nil
1359   "List of article headers in the current newsgroup.")
1360
1361 (defvar gnus-newsgroup-threads nil)
1362
1363 (defvar gnus-newsgroup-prepared nil
1364   "Whether the current group has been prepared properly.")
1365
1366 (defvar gnus-newsgroup-ancient nil
1367   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1368
1369 (defvar gnus-newsgroup-sparse nil)
1370
1371 (defvar gnus-current-article nil)
1372 (defvar gnus-article-current nil)
1373 (defvar gnus-current-headers nil)
1374 (defvar gnus-have-all-headers nil)
1375 (defvar gnus-last-article nil)
1376 (defvar gnus-newsgroup-history nil)
1377 (defvar gnus-newsgroup-charset nil)
1378 (defvar gnus-newsgroup-ephemeral-charset nil)
1379 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1380
1381 (defvar gnus-article-before-search nil)
1382
1383 (defconst gnus-summary-local-variables
1384   '(gnus-newsgroup-name
1385     gnus-newsgroup-begin gnus-newsgroup-end
1386     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1387     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1388     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1389     gnus-newsgroup-unselected gnus-newsgroup-marked
1390     gnus-newsgroup-spam-marked
1391     gnus-newsgroup-reads gnus-newsgroup-saved
1392     gnus-newsgroup-replied gnus-newsgroup-forwarded
1393     gnus-newsgroup-recent
1394     gnus-newsgroup-expirable
1395     gnus-newsgroup-processable gnus-newsgroup-killed
1396     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1397     gnus-newsgroup-unfetched
1398     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1399     gnus-newsgroup-seen gnus-newsgroup-articles
1400     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1401     gnus-newsgroup-headers gnus-newsgroup-threads
1402     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1403     gnus-current-article gnus-current-headers gnus-have-all-headers
1404     gnus-last-article gnus-article-internal-prepare-hook
1405     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1406     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1407     gnus-thread-expunge-below
1408     gnus-score-alist gnus-current-score-file
1409     (gnus-summary-expunge-below . global)
1410     (gnus-summary-mark-below . global)
1411     (gnus-orphan-score . global)
1412     gnus-newsgroup-active gnus-scores-exclude-files
1413     gnus-newsgroup-history gnus-newsgroup-ancient
1414     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1415     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1416     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1417     (gnus-newsgroup-expunged-tally . 0)
1418     gnus-cache-removable-articles gnus-newsgroup-cached
1419     gnus-newsgroup-data gnus-newsgroup-data-reverse
1420     gnus-newsgroup-limit gnus-newsgroup-limits
1421     gnus-newsgroup-charset gnus-newsgroup-display
1422     gnus-newsgroup-incorporated)
1423   "Variables that are buffer-local to the summary buffers.")
1424
1425 (defvar gnus-newsgroup-variables nil
1426   "A list of variables that have separate values in different newsgroups.
1427 A list of newsgroup (summary buffer) local variables, or cons of
1428 variables and their default values (when the default values are not
1429 nil), that should be made global while the summary buffer is active.
1430 These variables can be used to set variables in the group parameters
1431 while still allowing them to affect operations done in other
1432 buffers. For example:
1433
1434 \(setq gnus-newsgroup-variables
1435      '(message-use-followup-to
1436        (gnus-visible-headers .
1437          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1438 ")
1439
1440 ;; Byte-compiler warning.
1441 (eval-when-compile
1442   ;; Bind features so that require will believe that gnus-sum has
1443   ;; already been loaded (avoids infinite recursion)
1444   (let ((features (cons 'gnus-sum features)))
1445     ;; Several of the declarations in gnus-sum are needed to load the
1446     ;; following files. Right now, these definitions have been
1447     ;; compiled but not defined (evaluated).  We could either do a
1448     ;; eval-and-compile about all of the declarations or evaluate the
1449     ;; source file.
1450     (if (boundp 'gnus-newsgroup-variables)
1451         nil
1452       (load "gnus-sum.el" t t t t))
1453     (require 'gnus)
1454     (require 'gnus-agent)
1455     (require 'gnus-art)))
1456
1457 ;; Subject simplification.
1458
1459 (defun gnus-simplify-whitespace (str)
1460   "Remove excessive whitespace from STR."
1461   ;; Multiple spaces.
1462   (while (string-match "[ \t][ \t]+" str)
1463     (setq str (concat (substring str 0 (match-beginning 0))
1464                         " "
1465                         (substring str (match-end 0)))))
1466   ;; Leading spaces.
1467   (when (string-match "^[ \t]+" str)
1468     (setq str (substring str (match-end 0))))
1469   ;; Trailing spaces.
1470   (when (string-match "[ \t]+$" str)
1471     (setq str (substring str 0 (match-beginning 0))))
1472   str)
1473
1474 (defun gnus-simplify-all-whitespace (str)
1475   "Remove all whitespace from STR."
1476   (while (string-match "[ \t\n]+" str)
1477     (setq str (replace-match "" nil nil str)))
1478   str)
1479
1480 (defsubst gnus-simplify-subject-re (subject)
1481   "Remove \"Re:\" from subject lines."
1482   (if (string-match message-subject-re-regexp subject)
1483       (substring subject (match-end 0))
1484     subject))
1485
1486 (defun gnus-simplify-subject (subject &optional re-only)
1487   "Remove `Re:' and words in parentheses.
1488 If RE-ONLY is non-nil, strip leading `Re:'s only."
1489   (let ((case-fold-search t))           ;Ignore case.
1490     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1491     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1492       (setq subject (substring subject (match-end 0))))
1493     ;; Remove uninteresting prefixes.
1494     (when (and (not re-only)
1495                gnus-simplify-ignored-prefixes
1496                (string-match gnus-simplify-ignored-prefixes subject))
1497       (setq subject (substring subject (match-end 0))))
1498     ;; Remove words in parentheses from end.
1499     (unless re-only
1500       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1501         (setq subject (substring subject 0 (match-beginning 0)))))
1502     ;; Return subject string.
1503     subject))
1504
1505 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1506 ;; all whitespace.
1507 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1508   (goto-char (point-min))
1509   (while (re-search-forward regexp nil t)
1510     (replace-match (or newtext ""))))
1511
1512 (defun gnus-simplify-buffer-fuzzy ()
1513   "Simplify string in the buffer fuzzily.
1514 The string in the accessible portion of the current buffer is simplified.
1515 It is assumed to be a single-line subject.
1516 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1517 matter is removed.  Additional things can be deleted by setting
1518 `gnus-simplify-subject-fuzzy-regexp'."
1519   (let ((case-fold-search t)
1520         (modified-tick))
1521     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1522
1523     (while (not (eq modified-tick (buffer-modified-tick)))
1524       (setq modified-tick (buffer-modified-tick))
1525       (cond
1526        ((listp gnus-simplify-subject-fuzzy-regexp)
1527         (mapcar 'gnus-simplify-buffer-fuzzy-step
1528                 gnus-simplify-subject-fuzzy-regexp))
1529        (gnus-simplify-subject-fuzzy-regexp
1530         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1531       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1532       (gnus-simplify-buffer-fuzzy-step
1533        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1534       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1535
1536     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1537     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1538     (gnus-simplify-buffer-fuzzy-step " $")
1539     (gnus-simplify-buffer-fuzzy-step "^ +")))
1540
1541 (defun gnus-simplify-subject-fuzzy (subject)
1542   "Simplify a subject string fuzzily.
1543 See `gnus-simplify-buffer-fuzzy' for details."
1544   (save-excursion
1545     (gnus-set-work-buffer)
1546     (let ((case-fold-search t))
1547       ;; Remove uninteresting prefixes.
1548       (when (and gnus-simplify-ignored-prefixes
1549                  (string-match gnus-simplify-ignored-prefixes subject))
1550         (setq subject (substring subject (match-end 0))))
1551       (insert subject)
1552       (inline (gnus-simplify-buffer-fuzzy))
1553       (buffer-string))))
1554
1555 (defsubst gnus-simplify-subject-fully (subject)
1556   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1557   (cond
1558    (gnus-simplify-subject-functions
1559     (gnus-map-function gnus-simplify-subject-functions subject))
1560    ((null gnus-summary-gather-subject-limit)
1561     (gnus-simplify-subject-re subject))
1562    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1563     (gnus-simplify-subject-fuzzy subject))
1564    ((numberp gnus-summary-gather-subject-limit)
1565     (gnus-limit-string (gnus-simplify-subject-re subject)
1566                        gnus-summary-gather-subject-limit))
1567    (t
1568     subject)))
1569
1570 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1571   "Check whether two subjects are equal.
1572 If optional argument SIMPLE-FIRST is t, first argument is already
1573 simplified."
1574   (cond
1575    ((null simple-first)
1576     (equal (gnus-simplify-subject-fully s1)
1577            (gnus-simplify-subject-fully s2)))
1578    (t
1579     (equal s1
1580            (gnus-simplify-subject-fully s2)))))
1581
1582 (defun gnus-summary-bubble-group ()
1583   "Increase the score of the current group.
1584 This is a handy function to add to `gnus-summary-exit-hook' to
1585 increase the score of each group you read."
1586   (gnus-group-add-score gnus-newsgroup-name))
1587
1588 \f
1589 ;;;
1590 ;;; Gnus summary mode
1591 ;;;
1592
1593 (put 'gnus-summary-mode 'mode-class 'special)
1594
1595 (defvar gnus-article-commands-menu)
1596
1597 ;; Non-orthogonal keys
1598
1599 (gnus-define-keys gnus-summary-mode-map
1600   " " gnus-summary-next-page
1601   "\177" gnus-summary-prev-page
1602   [delete] gnus-summary-prev-page
1603   [backspace] gnus-summary-prev-page
1604   "\r" gnus-summary-scroll-up
1605   "\M-\r" gnus-summary-scroll-down
1606   "n" gnus-summary-next-unread-article
1607   "p" gnus-summary-prev-unread-article
1608   "N" gnus-summary-next-article
1609   "P" gnus-summary-prev-article
1610   "\M-\C-n" gnus-summary-next-same-subject
1611   "\M-\C-p" gnus-summary-prev-same-subject
1612   "\M-n" gnus-summary-next-unread-subject
1613   "\M-p" gnus-summary-prev-unread-subject
1614   "." gnus-summary-first-unread-article
1615   "," gnus-summary-best-unread-article
1616   "\M-s" gnus-summary-search-article-forward
1617   "\M-r" gnus-summary-search-article-backward
1618   "<" gnus-summary-beginning-of-article
1619   ">" gnus-summary-end-of-article
1620   "j" gnus-summary-goto-article
1621   "^" gnus-summary-refer-parent-article
1622   "\M-^" gnus-summary-refer-article
1623   "u" gnus-summary-tick-article-forward
1624   "!" gnus-summary-tick-article-forward
1625   "U" gnus-summary-tick-article-backward
1626   "d" gnus-summary-mark-as-read-forward
1627   "D" gnus-summary-mark-as-read-backward
1628   "E" gnus-summary-mark-as-expirable
1629   "\M-u" gnus-summary-clear-mark-forward
1630   "\M-U" gnus-summary-clear-mark-backward
1631   "k" gnus-summary-kill-same-subject-and-select
1632   "\C-k" gnus-summary-kill-same-subject
1633   "\M-\C-k" gnus-summary-kill-thread
1634   "\M-\C-l" gnus-summary-lower-thread
1635   "e" gnus-summary-edit-article
1636   "#" gnus-summary-mark-as-processable
1637   "\M-#" gnus-summary-unmark-as-processable
1638   "\M-\C-t" gnus-summary-toggle-threads
1639   "\M-\C-s" gnus-summary-show-thread
1640   "\M-\C-h" gnus-summary-hide-thread
1641   "\M-\C-f" gnus-summary-next-thread
1642   "\M-\C-b" gnus-summary-prev-thread
1643   [(meta down)] gnus-summary-next-thread
1644   [(meta up)] gnus-summary-prev-thread
1645   "\M-\C-u" gnus-summary-up-thread
1646   "\M-\C-d" gnus-summary-down-thread
1647   "&" gnus-summary-execute-command
1648   "c" gnus-summary-catchup-and-exit
1649   "\C-w" gnus-summary-mark-region-as-read
1650   "\C-t" gnus-summary-toggle-truncation
1651   "?" gnus-summary-mark-as-dormant
1652   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1653   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1654   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1655   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1656   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1657   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1658   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1659   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1660   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1661   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1662   "=" gnus-summary-expand-window
1663   "\C-x\C-s" gnus-summary-reselect-current-group
1664   "\M-g" gnus-summary-rescan-group
1665   "w" gnus-summary-stop-page-breaking
1666   "\C-c\C-r" gnus-summary-caesar-message
1667   "\M-t" gnus-summary-toggle-mime
1668   "f" gnus-summary-followup
1669   "F" gnus-summary-followup-with-original
1670   "C" gnus-summary-cancel-article
1671   "r" gnus-summary-reply
1672   "R" gnus-summary-reply-with-original
1673   "\C-c\C-f" gnus-summary-mail-forward
1674   "o" gnus-summary-save-article
1675   "\C-o" gnus-summary-save-article-mail
1676   "|" gnus-summary-pipe-output
1677   "\M-k" gnus-summary-edit-local-kill
1678   "\M-K" gnus-summary-edit-global-kill
1679   ;; "V" gnus-version
1680   "\C-c\C-d" gnus-summary-describe-group
1681   "q" gnus-summary-exit
1682   "Q" gnus-summary-exit-no-update
1683   "\C-c\C-i" gnus-info-find-node
1684   gnus-mouse-2 gnus-mouse-pick-article
1685   "m" gnus-summary-mail-other-window
1686   "a" gnus-summary-post-news
1687   "i" gnus-summary-news-other-window
1688   "x" gnus-summary-limit-to-unread
1689   "s" gnus-summary-isearch-article
1690   "t" gnus-summary-toggle-header
1691   "g" gnus-summary-show-article
1692   "l" gnus-summary-goto-last-article
1693   "v" gnus-summary-preview-mime-message
1694   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1695   "\C-d" gnus-summary-enter-digest-group
1696   "\M-\C-d" gnus-summary-read-document
1697   "\M-\C-e" gnus-summary-edit-parameters
1698   "\M-\C-a" gnus-summary-customize-parameters
1699   "\C-c\C-b" gnus-bug
1700   "\C-c\C-n" gnus-namazu-search
1701   "*" gnus-cache-enter-article
1702   "\M-*" gnus-cache-remove-article
1703   "\M-&" gnus-summary-universal-argument
1704   "\C-l" gnus-recenter
1705   "I" gnus-summary-increase-score
1706   "L" gnus-summary-lower-score
1707   "\M-i" gnus-symbolic-argument
1708   "h" gnus-summary-select-article-buffer
1709
1710   "V" gnus-summary-score-map
1711   "X" gnus-uu-extract-map
1712   "S" gnus-summary-send-map)
1713
1714   ;; Sort of orthogonal keymap
1715 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1716   "t" gnus-summary-tick-article-forward
1717   "!" gnus-summary-tick-article-forward
1718   "d" gnus-summary-mark-as-read-forward
1719   "r" gnus-summary-mark-as-read-forward
1720   "c" gnus-summary-clear-mark-forward
1721   " " gnus-summary-clear-mark-forward
1722   "e" gnus-summary-mark-as-expirable
1723   "x" gnus-summary-mark-as-expirable
1724   "?" gnus-summary-mark-as-dormant
1725   "b" gnus-summary-set-bookmark
1726   "B" gnus-summary-remove-bookmark
1727   "#" gnus-summary-mark-as-processable
1728   "\M-#" gnus-summary-unmark-as-processable
1729   "S" gnus-summary-limit-include-expunged
1730   "C" gnus-summary-catchup
1731   "H" gnus-summary-catchup-to-here
1732   "h" gnus-summary-catchup-from-here
1733   "\C-c" gnus-summary-catchup-all
1734   "k" gnus-summary-kill-same-subject-and-select
1735   "K" gnus-summary-kill-same-subject
1736   "P" gnus-uu-mark-map)
1737
1738 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1739   "c" gnus-summary-clear-above
1740   "u" gnus-summary-tick-above
1741   "m" gnus-summary-mark-above
1742   "k" gnus-summary-kill-below)
1743
1744 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1745   "/" gnus-summary-limit-to-subject
1746   "n" gnus-summary-limit-to-articles
1747   "w" gnus-summary-pop-limit
1748   "s" gnus-summary-limit-to-subject
1749   "a" gnus-summary-limit-to-author
1750   "u" gnus-summary-limit-to-unread
1751   "m" gnus-summary-limit-to-marks
1752   "M" gnus-summary-limit-exclude-marks
1753   "v" gnus-summary-limit-to-score
1754   "*" gnus-summary-limit-include-cached
1755   "D" gnus-summary-limit-include-dormant
1756   "T" gnus-summary-limit-include-thread
1757   "d" gnus-summary-limit-exclude-dormant
1758   "t" gnus-summary-limit-to-age
1759   "." gnus-summary-limit-to-unseen
1760   "x" gnus-summary-limit-to-extra
1761   "p" gnus-summary-limit-to-display-predicate
1762   "E" gnus-summary-limit-include-expunged
1763   "c" gnus-summary-limit-exclude-childless-dormant
1764   "C" gnus-summary-limit-mark-excluded-as-read
1765   "o" gnus-summary-insert-old-articles
1766   "N" gnus-summary-insert-new-articles)
1767
1768 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1769   "n" gnus-summary-next-unread-article
1770   "p" gnus-summary-prev-unread-article
1771   "N" gnus-summary-next-article
1772   "P" gnus-summary-prev-article
1773   "\C-n" gnus-summary-next-same-subject
1774   "\C-p" gnus-summary-prev-same-subject
1775   "\M-n" gnus-summary-next-unread-subject
1776   "\M-p" gnus-summary-prev-unread-subject
1777   "f" gnus-summary-first-unread-article
1778   "b" gnus-summary-best-unread-article
1779   "j" gnus-summary-goto-article
1780   "g" gnus-summary-goto-subject
1781   "l" gnus-summary-goto-last-article
1782   "o" gnus-summary-pop-article)
1783
1784 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1785   "k" gnus-summary-kill-thread
1786   "l" gnus-summary-lower-thread
1787   "i" gnus-summary-raise-thread
1788   "T" gnus-summary-toggle-threads
1789   "t" gnus-summary-rethread-current
1790   "^" gnus-summary-reparent-thread
1791   "s" gnus-summary-show-thread
1792   "S" gnus-summary-show-all-threads
1793   "h" gnus-summary-hide-thread
1794   "H" gnus-summary-hide-all-threads
1795   "n" gnus-summary-next-thread
1796   "p" gnus-summary-prev-thread
1797   "u" gnus-summary-up-thread
1798   "o" gnus-summary-top-thread
1799   "d" gnus-summary-down-thread
1800   "#" gnus-uu-mark-thread
1801   "\M-#" gnus-uu-unmark-thread)
1802
1803 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1804   "g" gnus-summary-prepare
1805   "c" gnus-summary-insert-cached-articles
1806   "d" gnus-summary-insert-dormant-articles)
1807
1808 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1809   "c" gnus-summary-catchup-and-exit
1810   "C" gnus-summary-catchup-all-and-exit
1811   "E" gnus-summary-exit-no-update
1812   "J" gnus-summary-jump-to-other-group
1813   "Q" gnus-summary-exit
1814   "Z" gnus-summary-exit
1815   "n" gnus-summary-catchup-and-goto-next-group
1816   "R" gnus-summary-reselect-current-group
1817   "G" gnus-summary-rescan-group
1818   "N" gnus-summary-next-group
1819   "s" gnus-summary-save-newsrc
1820   "P" gnus-summary-prev-group)
1821
1822 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1823   " " gnus-summary-next-page
1824   "n" gnus-summary-next-page
1825   "\177" gnus-summary-prev-page
1826   [delete] gnus-summary-prev-page
1827   "p" gnus-summary-prev-page
1828   "\r" gnus-summary-scroll-up
1829   "\M-\r" gnus-summary-scroll-down
1830   "<" gnus-summary-beginning-of-article
1831   ">" gnus-summary-end-of-article
1832   "b" gnus-summary-beginning-of-article
1833   "e" gnus-summary-end-of-article
1834   "^" gnus-summary-refer-parent-article
1835   "r" gnus-summary-refer-parent-article
1836   "D" gnus-summary-enter-digest-group
1837   "R" gnus-summary-refer-references
1838   "T" gnus-summary-refer-thread
1839   "g" gnus-summary-show-article
1840   "s" gnus-summary-isearch-article
1841   "P" gnus-summary-print-article
1842   "M" gnus-mailing-list-insinuate
1843   "t" gnus-article-babel)
1844
1845 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1846   "b" gnus-article-add-buttons
1847   "B" gnus-article-add-buttons-to-head
1848   "o" gnus-article-treat-overstrike
1849   "e" gnus-article-emphasize
1850   "w" gnus-article-fill-cited-article
1851   "Q" gnus-article-fill-long-lines
1852   "C" gnus-article-capitalize-sentences
1853   "c" gnus-article-remove-cr
1854   "Z" gnus-article-decode-HZ
1855   "h" gnus-article-wash-html
1856   "u" gnus-article-unsplit-urls
1857   "f" gnus-article-display-x-face
1858   "l" gnus-summary-stop-page-breaking
1859   "r" gnus-summary-caesar-message
1860   "m" gnus-summary-morse-message
1861   "t" gnus-summary-toggle-header
1862   "g" gnus-treat-smiley
1863   "v" gnus-summary-verbose-headers
1864   "m" gnus-summary-toggle-mime
1865   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1866   "p" gnus-article-verify-x-pgp-sig
1867   "d" gnus-article-treat-dumbquotes)
1868
1869 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1870   ;; mnemonic: deuglif*Y*
1871   "u" gnus-article-outlook-unwrap-lines
1872   "a" gnus-article-outlook-repair-attribution
1873   "c" gnus-article-outlook-rearrange-citation
1874   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1875
1876 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1877   "a" gnus-article-hide
1878   "h" gnus-article-hide-headers
1879   "b" gnus-article-hide-boring-headers
1880   "s" gnus-article-hide-signature
1881   "c" gnus-article-hide-citation
1882   "C" gnus-article-hide-citation-in-followups
1883   "l" gnus-article-hide-list-identifiers
1884   "B" gnus-article-strip-banner
1885   "P" gnus-article-hide-pem
1886   "\C-c" gnus-article-hide-citation-maybe)
1887
1888 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1889   "a" gnus-article-highlight
1890   "h" gnus-article-highlight-headers
1891   "c" gnus-article-highlight-citation
1892   "s" gnus-article-highlight-signature)
1893
1894 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1895   "f" gnus-article-treat-fold-headers
1896   "u" gnus-article-treat-unfold-headers
1897   "n" gnus-article-treat-fold-newsgroups)
1898
1899 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1900   "x" gnus-article-display-x-face
1901   "d" gnus-article-display-face
1902   "s" gnus-treat-smiley
1903   "D" gnus-article-remove-images
1904   "f" gnus-treat-from-picon
1905   "m" gnus-treat-mail-picon
1906   "n" gnus-treat-newsgroups-picon)
1907
1908 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1909   "z" gnus-article-date-ut
1910   "u" gnus-article-date-ut
1911   "l" gnus-article-date-local
1912   "p" gnus-article-date-english
1913   "e" gnus-article-date-lapsed
1914   "o" gnus-article-date-original
1915   "i" gnus-article-date-iso8601
1916   "s" gnus-article-date-user)
1917
1918 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1919   "t" gnus-article-remove-trailing-blank-lines
1920   "l" gnus-article-strip-leading-blank-lines
1921   "m" gnus-article-strip-multiple-blank-lines
1922   "a" gnus-article-strip-blank-lines
1923   "A" gnus-article-strip-all-blank-lines
1924   "s" gnus-article-strip-leading-space
1925   "e" gnus-article-strip-trailing-space
1926   "w" gnus-article-remove-leading-whitespace)
1927
1928 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1929   "v" gnus-version
1930   "f" gnus-summary-fetch-faq
1931   "d" gnus-summary-describe-group
1932   "h" gnus-summary-describe-briefly
1933   "i" gnus-info-find-node
1934   "c" gnus-group-fetch-charter
1935   "C" gnus-group-fetch-control)
1936
1937 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1938   "e" gnus-summary-expire-articles
1939   "\M-\C-e" gnus-summary-expire-articles-now
1940   "\177" gnus-summary-delete-article
1941   [delete] gnus-summary-delete-article
1942   [backspace] gnus-summary-delete-article
1943   "m" gnus-summary-move-article
1944   "r" gnus-summary-respool-article
1945   "w" gnus-summary-edit-article
1946   "c" gnus-summary-copy-article
1947   "B" gnus-summary-crosspost-article
1948   "q" gnus-summary-respool-query
1949   "t" gnus-summary-respool-trace
1950   "i" gnus-summary-import-article
1951   "I" gnus-summary-create-article
1952   "p" gnus-summary-article-posted-p)
1953
1954 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1955   "o" gnus-summary-save-article
1956   "m" gnus-summary-save-article-mail
1957   "F" gnus-summary-write-article-file
1958   "r" gnus-summary-save-article-rmail
1959   "f" gnus-summary-save-article-file
1960   "b" gnus-summary-save-article-body-file
1961   "h" gnus-summary-save-article-folder
1962   "v" gnus-summary-save-article-vm
1963   "p" gnus-summary-pipe-output
1964   "P" gnus-summary-muttprint
1965   "s" gnus-soup-add-article)
1966
1967 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1968   "b" gnus-summary-display-buttonized
1969   "m" gnus-summary-repair-multipart
1970   "v" gnus-article-view-part
1971   "o" gnus-article-save-part
1972   "c" gnus-article-copy-part
1973   "C" gnus-article-view-part-as-charset
1974   "e" gnus-article-view-part-externally
1975   "E" gnus-article-encrypt-body
1976   "i" gnus-article-inline-part
1977   "|" gnus-article-pipe-part)
1978
1979 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1980   "p" gnus-summary-mark-as-processable
1981   "u" gnus-summary-unmark-as-processable
1982   "U" gnus-summary-unmark-all-processable
1983   "v" gnus-uu-mark-over
1984   "s" gnus-uu-mark-series
1985   "r" gnus-uu-mark-region
1986   "g" gnus-uu-unmark-region
1987   "R" gnus-uu-mark-by-regexp
1988   "G" gnus-uu-unmark-by-regexp
1989   "t" gnus-uu-mark-thread
1990   "T" gnus-uu-unmark-thread
1991   "a" gnus-uu-mark-all
1992   "b" gnus-uu-mark-buffer
1993   "S" gnus-uu-mark-sparse
1994   "k" gnus-summary-kill-process-mark
1995   "y" gnus-summary-yank-process-mark
1996   "w" gnus-summary-save-process-mark
1997   "i" gnus-uu-invert-processable)
1998
1999 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2000   ;;"x" gnus-uu-extract-any
2001   "m" gnus-summary-save-parts
2002   "u" gnus-uu-decode-uu
2003   "U" gnus-uu-decode-uu-and-save
2004   "s" gnus-uu-decode-unshar
2005   "S" gnus-uu-decode-unshar-and-save
2006   "o" gnus-uu-decode-save
2007   "O" gnus-uu-decode-save
2008   "b" gnus-uu-decode-binhex
2009   "B" gnus-uu-decode-binhex
2010   "p" gnus-uu-decode-postscript
2011   "P" gnus-uu-decode-postscript-and-save)
2012
2013 (gnus-define-keys
2014     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2015   "u" gnus-uu-decode-uu-view
2016   "U" gnus-uu-decode-uu-and-save-view
2017   "s" gnus-uu-decode-unshar-view
2018   "S" gnus-uu-decode-unshar-and-save-view
2019   "o" gnus-uu-decode-save-view
2020   "O" gnus-uu-decode-save-view
2021   "b" gnus-uu-decode-binhex-view
2022   "B" gnus-uu-decode-binhex-view
2023   "p" gnus-uu-decode-postscript-view
2024   "P" gnus-uu-decode-postscript-and-save-view)
2025
2026 (defvar gnus-article-post-menu nil)
2027
2028 (defconst gnus-summary-menu-maxlen 20)
2029
2030 (defun gnus-summary-menu-split (menu)
2031   ;; If we have lots of elements, divide them into groups of 20
2032   ;; and make a pane (or submenu) for each one.
2033   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2034       (let ((menu menu) sublists next
2035             (i 1))
2036         (while menu
2037           ;; Pull off the next gnus-summary-menu-maxlen elements
2038           ;; and make them the next element of sublist.
2039           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2040           (if next
2041               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2042                       nil))
2043           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2044                                              (aref (car (last menu)) 0)) menu)
2045                                sublists))
2046           (setq i (1+ i))
2047           (setq menu next))
2048         (nreverse sublists))
2049     ;; Few elements--put them all in one pane.
2050     menu))
2051
2052 (defun gnus-summary-make-menu-bar ()
2053   (gnus-turn-off-edit-menu 'summary)
2054
2055   (unless (boundp 'gnus-summary-misc-menu)
2056
2057     (easy-menu-define
2058      gnus-summary-kill-menu gnus-summary-mode-map ""
2059      (cons
2060       "Score"
2061       (nconc
2062        (list
2063         ["Customize" gnus-score-customize t])
2064        (gnus-make-score-map 'increase)
2065        (gnus-make-score-map 'lower)
2066        '(("Mark"
2067           ["Kill below" gnus-summary-kill-below t]
2068           ["Mark above" gnus-summary-mark-above t]
2069           ["Tick above" gnus-summary-tick-above t]
2070           ["Clear above" gnus-summary-clear-above t])
2071          ["Current score" gnus-summary-current-score t]
2072          ["Set score" gnus-summary-set-score t]
2073          ["Switch current score file..." gnus-score-change-score-file t]
2074          ["Set mark below..." gnus-score-set-mark-below t]
2075          ["Set expunge below..." gnus-score-set-expunge-below t]
2076          ["Edit current score file" gnus-score-edit-current-scores t]
2077          ["Edit score file" gnus-score-edit-file t]
2078          ["Trace score" gnus-score-find-trace t]
2079          ["Find words" gnus-score-find-favourite-words t]
2080          ["Rescore buffer" gnus-summary-rescore t]
2081          ["Increase score..." gnus-summary-increase-score t]
2082          ["Lower score..." gnus-summary-lower-score t]))))
2083
2084     ;; Define both the Article menu in the summary buffer and the
2085     ;; equivalent Commands menu in the article buffer here for
2086     ;; consistency.
2087     (let ((innards
2088            `(("Hide"
2089               ["All" gnus-article-hide t]
2090               ["Headers" gnus-article-hide-headers t]
2091               ["Signature" gnus-article-hide-signature t]
2092               ["Citation" gnus-article-hide-citation t]
2093               ["List identifiers" gnus-article-hide-list-identifiers t]
2094               ["Banner" gnus-article-strip-banner t]
2095               ["Boring headers" gnus-article-hide-boring-headers t])
2096              ("Highlight"
2097               ["All" gnus-article-highlight t]
2098               ["Headers" gnus-article-highlight-headers t]
2099               ["Signature" gnus-article-highlight-signature t]
2100               ["Citation" gnus-article-highlight-citation t])
2101              ("Date"
2102               ["Local" gnus-article-date-local t]
2103               ["ISO8601" gnus-article-date-iso8601 t]
2104               ["UT" gnus-article-date-ut t]
2105               ["Original" gnus-article-date-original t]
2106               ["Lapsed" gnus-article-date-lapsed t]
2107               ["User-defined" gnus-article-date-user t])
2108              ("Display"
2109               ["Remove images" gnus-article-remove-images t]
2110               ["Toggle smiley" gnus-treat-smiley t]
2111               ["Show X-Face" gnus-article-display-x-face t]
2112               ["Show picons in From" gnus-treat-from-picon t]
2113               ["Show picons in mail headers" gnus-treat-mail-picon t]
2114               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2115               ("View as different encoding"
2116                ,@(gnus-summary-menu-split
2117                   (mapcar
2118                    (lambda (cs)
2119                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2120                      ;; forms for menu commands, we should provide intern'ed
2121                      ;; function symbols.
2122                      (let ((command (intern (format "\
2123 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2124                        (fset command
2125                              `(lambda ()
2126                                 (interactive)
2127                                 (let ((gnus-summary-show-article-charset-alist
2128                                        '((1 . ,cs))))
2129                                   (gnus-summary-show-article 1))))
2130                        `[,(symbol-name cs) ,command t]))
2131                    (sort (if (fboundp 'coding-system-list)
2132                              (coding-system-list)
2133                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2134                            )
2135                          'string<)))))
2136              ("Washing"
2137               ("Remove Blanks"
2138                ["Leading" gnus-article-strip-leading-blank-lines t]
2139                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2140                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2141                ["All of the above" gnus-article-strip-blank-lines t]
2142                ["All" gnus-article-strip-all-blank-lines t]
2143                ["Leading space" gnus-article-strip-leading-space t]
2144                ["Trailing space" gnus-article-strip-trailing-space t]
2145                ["Leading space in headers"
2146                 gnus-article-remove-leading-whitespace t])
2147               ["Overstrike" gnus-article-treat-overstrike t]
2148               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2149               ["Emphasis" gnus-article-emphasize t]
2150               ["Word wrap" gnus-article-fill-cited-article t]
2151               ["Fill long lines" gnus-article-fill-long-lines t]
2152               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2153               ["CR" gnus-article-remove-cr t]
2154               ["Rot 13" gnus-summary-caesar-message
2155                ,@(if (featurep 'xemacs) '(t)
2156                    '(:help "\"Caesar rotate\" article by 13"))]
2157               ["Morse decode" gnus-summary-morse-message t]
2158               ["Unix pipe..." gnus-summary-pipe-message t]
2159               ["Add buttons" gnus-article-add-buttons t]
2160               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2161               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2162               ["Toggle MIME" gnus-summary-toggle-mime t]
2163               ["Verbose header" gnus-summary-verbose-headers t]
2164               ["Toggle header" gnus-summary-toggle-header t]
2165               ["Unfold headers" gnus-article-treat-unfold-headers t]
2166               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2167               ["Html" gnus-article-wash-html t]
2168               ["URLs" gnus-article-unsplit-urls t]
2169               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2170               ["HZ" gnus-article-decode-HZ t]
2171               ("(Outlook) Deuglify"
2172                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2173                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2174                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2175                ["Full (Outlook) deuglify"
2176                 gnus-article-outlook-deuglify-article t])
2177               )
2178              ("Output"
2179               ["Save in default format" gnus-summary-save-article
2180                ,@(if (featurep 'xemacs) '(t)
2181                    '(:help "Save article using default method"))]
2182               ["Save in file" gnus-summary-save-article-file
2183                ,@(if (featurep 'xemacs) '(t)
2184                    '(:help "Save article in file"))]
2185               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2186               ["Save in MH folder" gnus-summary-save-article-folder t]
2187               ["Save in VM folder" gnus-summary-save-article-vm t]
2188               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2189               ["Save body in file" gnus-summary-save-article-body-file t]
2190               ["Pipe through a filter" gnus-summary-pipe-output t]
2191               ["Add to SOUP packet" gnus-soup-add-article t]
2192               ["Print with Muttprint" gnus-summary-muttprint t]
2193               ["Print" gnus-summary-print-article t])
2194              ("Backend"
2195               ["Respool article..." gnus-summary-respool-article t]
2196               ["Move article..." gnus-summary-move-article
2197                (gnus-check-backend-function
2198                 'request-move-article gnus-newsgroup-name)]
2199               ["Copy article..." gnus-summary-copy-article t]
2200               ["Crosspost article..." gnus-summary-crosspost-article
2201                (gnus-check-backend-function
2202                 'request-replace-article gnus-newsgroup-name)]
2203               ["Import file..." gnus-summary-import-article t]
2204               ["Create article..." gnus-summary-create-article t]
2205               ["Check if posted" gnus-summary-article-posted-p t]
2206               ["Edit article" gnus-summary-edit-article
2207                (not (gnus-group-read-only-p))]
2208               ["Delete article" gnus-summary-delete-article
2209                (gnus-check-backend-function
2210                 'request-expire-articles gnus-newsgroup-name)]
2211               ["Query respool" gnus-summary-respool-query t]
2212               ["Trace respool" gnus-summary-respool-trace t]
2213               ["Delete expirable articles" gnus-summary-expire-articles-now
2214                (gnus-check-backend-function
2215                 'request-expire-articles gnus-newsgroup-name)])
2216              ("Extract"
2217               ["Uudecode" gnus-uu-decode-uu
2218                ,@(if (featurep 'xemacs) '(t)
2219                    '(:help "Decode uuencoded article(s)"))]
2220               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2221               ["Unshar" gnus-uu-decode-unshar t]
2222               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2223               ["Save" gnus-uu-decode-save t]
2224               ["Binhex" gnus-uu-decode-binhex t]
2225               ["Postscript" gnus-uu-decode-postscript t])
2226              ("Cache"
2227               ["Enter article" gnus-cache-enter-article t]
2228               ["Remove article" gnus-cache-remove-article t])
2229              ["Translate" gnus-article-babel t]
2230              ["Select article buffer" gnus-summary-select-article-buffer t]
2231              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2232              ["Isearch article..." gnus-summary-isearch-article t]
2233              ["Beginning of the article" gnus-summary-beginning-of-article t]
2234              ["End of the article" gnus-summary-end-of-article t]
2235              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2236              ["Fetch referenced articles" gnus-summary-refer-references t]
2237              ["Fetch current thread" gnus-summary-refer-thread t]
2238              ["Fetch article with id..." gnus-summary-refer-article t]
2239              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2240              ["Redisplay" gnus-summary-show-article t]
2241              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2242       (easy-menu-define
2243        gnus-summary-article-menu gnus-summary-mode-map ""
2244        (cons "Article" innards))
2245
2246       (if (not (keymapp gnus-summary-article-menu))
2247           (easy-menu-define
2248            gnus-article-commands-menu gnus-article-mode-map ""
2249            (cons "Commands" innards))
2250         ;; in Emacs, don't share menu.
2251         (setq gnus-article-commands-menu
2252               (copy-keymap gnus-summary-article-menu))
2253         (define-key gnus-article-mode-map [menu-bar commands]
2254           (cons "Commands" gnus-article-commands-menu))))
2255
2256     (easy-menu-define
2257      gnus-summary-thread-menu gnus-summary-mode-map ""
2258      '("Threads"
2259        ["Find all messages in thread" gnus-summary-refer-thread t]
2260        ["Toggle threading" gnus-summary-toggle-threads t]
2261        ["Hide threads" gnus-summary-hide-all-threads t]
2262        ["Show threads" gnus-summary-show-all-threads t]
2263        ["Hide thread" gnus-summary-hide-thread t]
2264        ["Show thread" gnus-summary-show-thread t]
2265        ["Go to next thread" gnus-summary-next-thread t]
2266        ["Go to previous thread" gnus-summary-prev-thread t]
2267        ["Go down thread" gnus-summary-down-thread t]
2268        ["Go up thread" gnus-summary-up-thread t]
2269        ["Top of thread" gnus-summary-top-thread t]
2270        ["Mark thread as read" gnus-summary-kill-thread t]
2271        ["Lower thread score" gnus-summary-lower-thread t]
2272        ["Raise thread score" gnus-summary-raise-thread t]
2273        ["Rethread current" gnus-summary-rethread-current t]))
2274
2275     (easy-menu-define
2276      gnus-summary-post-menu gnus-summary-mode-map ""
2277      `("Post"
2278        ["Send a message (mail or news)" gnus-summary-post-news
2279         ,@(if (featurep 'xemacs) '(t)
2280             '(:help "Post an article"))]
2281        ["Followup" gnus-summary-followup
2282         ,@(if (featurep 'xemacs) '(t)
2283             '(:help "Post followup to this article"))]
2284        ["Followup and yank" gnus-summary-followup-with-original
2285         ,@(if (featurep 'xemacs) '(t)
2286             '(:help "Post followup to this article, quoting its contents"))]
2287        ["Supersede article" gnus-summary-supersede-article t]
2288        ["Cancel article" gnus-summary-cancel-article
2289         ,@(if (featurep 'xemacs) '(t)
2290             '(:help "Cancel an article you posted"))]
2291        ["Reply" gnus-summary-reply t]
2292        ["Reply and yank" gnus-summary-reply-with-original t]
2293        ["Wide reply" gnus-summary-wide-reply t]
2294        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2295         ,@(if (featurep 'xemacs) '(t)
2296             '(:help "Mail a reply, quoting this article"))]
2297        ["Very wide reply" gnus-summary-very-wide-reply t]
2298        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2299         ,@(if (featurep 'xemacs) '(t)
2300             '(:help "Mail a very wide reply, quoting this article"))]
2301        ["Mail forward" gnus-summary-mail-forward t]
2302        ["Post forward" gnus-summary-post-forward t]
2303        ["Digest and mail" gnus-summary-digest-mail-forward t]
2304        ["Digest and post" gnus-summary-digest-post-forward t]
2305        ["Resend message" gnus-summary-resend-message t]
2306        ["Resend message edit" gnus-summary-resend-message-edit t]
2307        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2308        ["Send a mail" gnus-summary-mail-other-window t]
2309        ["Create a local message" gnus-summary-news-other-window t]
2310        ["Uuencode and post" gnus-uu-post-news
2311         ,@(if (featurep 'xemacs) '(t)
2312             '(:help "Post a uuencoded article"))]
2313        ["Followup via news" gnus-summary-followup-to-mail t]
2314        ["Followup via news and yank"
2315         gnus-summary-followup-to-mail-with-original t]
2316        ;;("Draft"
2317        ;;["Send" gnus-summary-send-draft t]
2318        ;;["Send bounced" gnus-resend-bounced-mail t])
2319        ))
2320
2321     (cond
2322      ((not (keymapp gnus-summary-post-menu))
2323       (setq gnus-article-post-menu gnus-summary-post-menu))
2324      ((not gnus-article-post-menu)
2325       ;; Don't share post menu.
2326       (setq gnus-article-post-menu
2327             (copy-keymap gnus-summary-post-menu))))
2328     (define-key gnus-article-mode-map [menu-bar post]
2329       (cons "Post" gnus-article-post-menu))
2330
2331     (easy-menu-define
2332      gnus-summary-misc-menu gnus-summary-mode-map ""
2333      `("Gnus"
2334        ("Mark Read"
2335         ["Mark as read" gnus-summary-mark-as-read-forward t]
2336         ["Mark same subject and select"
2337          gnus-summary-kill-same-subject-and-select t]
2338         ["Mark same subject" gnus-summary-kill-same-subject t]
2339         ["Catchup" gnus-summary-catchup
2340          ,@(if (featurep 'xemacs) '(t)
2341              '(:help "Mark unread articles in this group as read"))]
2342         ["Catchup all" gnus-summary-catchup-all t]
2343         ["Catchup to here" gnus-summary-catchup-to-here t]
2344         ["Catchup from here" gnus-summary-catchup-from-here t]
2345         ["Catchup region" gnus-summary-mark-region-as-read
2346          (gnus-mark-active-p)]
2347         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2348        ("Mark Various"
2349         ["Tick" gnus-summary-tick-article-forward t]
2350         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2351         ["Remove marks" gnus-summary-clear-mark-forward t]
2352         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2353         ["Set bookmark" gnus-summary-set-bookmark t]
2354         ["Remove bookmark" gnus-summary-remove-bookmark t])
2355        ("Limit to"
2356         ["Marks..." gnus-summary-limit-to-marks t]
2357         ["Subject..." gnus-summary-limit-to-subject t]
2358         ["Author..." gnus-summary-limit-to-author t]
2359         ["Age..." gnus-summary-limit-to-age t]
2360         ["Extra..." gnus-summary-limit-to-extra t]
2361         ["Score..." gnus-summary-limit-to-score t]
2362         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2363         ["Unread" gnus-summary-limit-to-unread t]
2364         ["Unseen" gnus-summary-limit-to-unseen t]
2365         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2366         ["Next articles" gnus-summary-limit-to-articles t]
2367         ["Pop limit" gnus-summary-pop-limit t]
2368         ["Show dormant" gnus-summary-limit-include-dormant t]
2369         ["Hide childless dormant"
2370          gnus-summary-limit-exclude-childless-dormant t]
2371         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2372         ["Hide marked" gnus-summary-limit-exclude-marks t]
2373         ["Show expunged" gnus-summary-limit-include-expunged t])
2374        ("Process Mark"
2375         ["Set mark" gnus-summary-mark-as-processable t]
2376         ["Remove mark" gnus-summary-unmark-as-processable t]
2377         ["Remove all marks" gnus-summary-unmark-all-processable t]
2378         ["Mark above" gnus-uu-mark-over t]
2379         ["Mark series" gnus-uu-mark-series t]
2380         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2381         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2382         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2383         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2384         ["Mark all" gnus-uu-mark-all t]
2385         ["Mark buffer" gnus-uu-mark-buffer t]
2386         ["Mark sparse" gnus-uu-mark-sparse t]
2387         ["Mark thread" gnus-uu-mark-thread t]
2388         ["Unmark thread" gnus-uu-unmark-thread t]
2389         ("Process Mark Sets"
2390          ["Kill" gnus-summary-kill-process-mark t]
2391          ["Yank" gnus-summary-yank-process-mark
2392           gnus-newsgroup-process-stack]
2393          ["Save" gnus-summary-save-process-mark t]
2394          ["Run command on marked..." gnus-summary-universal-argument t]))
2395        ("Scroll article"
2396         ["Page forward" gnus-summary-next-page
2397          ,@(if (featurep 'xemacs) '(t)
2398              '(:help "Show next page of article"))]
2399         ["Page backward" gnus-summary-prev-page
2400          ,@(if (featurep 'xemacs) '(t)
2401              '(:help "Show previous page of article"))]
2402         ["Line forward" gnus-summary-scroll-up t])
2403        ("Move"
2404         ["Next unread article" gnus-summary-next-unread-article t]
2405         ["Previous unread article" gnus-summary-prev-unread-article t]
2406         ["Next article" gnus-summary-next-article t]
2407         ["Previous article" gnus-summary-prev-article t]
2408         ["Next unread subject" gnus-summary-next-unread-subject t]
2409         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2410         ["Next article same subject" gnus-summary-next-same-subject t]
2411         ["Previous article same subject" gnus-summary-prev-same-subject t]
2412         ["First unread article" gnus-summary-first-unread-article t]
2413         ["Best unread article" gnus-summary-best-unread-article t]
2414         ["Go to subject number..." gnus-summary-goto-subject t]
2415         ["Go to article number..." gnus-summary-goto-article t]
2416         ["Go to the last article" gnus-summary-goto-last-article t]
2417         ["Pop article off history" gnus-summary-pop-article t])
2418        ("Sort"
2419         ["Sort by number" gnus-summary-sort-by-number t]
2420         ["Sort by author" gnus-summary-sort-by-author t]
2421         ["Sort by subject" gnus-summary-sort-by-subject t]
2422         ["Sort by date" gnus-summary-sort-by-date t]
2423         ["Sort by score" gnus-summary-sort-by-score t]
2424         ["Sort by lines" gnus-summary-sort-by-lines t]
2425         ["Sort by characters" gnus-summary-sort-by-chars t]
2426         ["Randomize" gnus-summary-sort-by-random t]
2427         ["Original sort" gnus-summary-sort-by-original t])
2428        ("Help"
2429         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2430         ["Describe group" gnus-summary-describe-group t]
2431         ["Fetch charter" gnus-group-fetch-charter
2432          ,@(if (featurep 'xemacs) nil
2433              '(:help "Display the charter of the current group"))]
2434         ["Fetch control message" gnus-group-fetch-control
2435          ,@(if (featurep 'xemacs) nil
2436              '(:help "Display the archived control message for the current group"))]
2437         ["Read manual" gnus-info-find-node t])
2438        ("Modes"
2439         ["Pick and read" gnus-pick-mode t]
2440         ["Binary" gnus-binary-mode t])
2441        ("Regeneration"
2442         ["Regenerate" gnus-summary-prepare t]
2443         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2444         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2445         ["Toggle threading" gnus-summary-toggle-threads t])
2446        ["See old articles" gnus-summary-insert-old-articles t]
2447        ["See new articles" gnus-summary-insert-new-articles t]
2448        ["Filter articles..." gnus-summary-execute-command t]
2449        ["Run command on articles..." gnus-summary-universal-argument t]
2450        ["Search articles forward..." gnus-summary-search-article-forward t]
2451        ["Search articles backward..." gnus-summary-search-article-backward t]
2452        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2453        ["Expand window" gnus-summary-expand-window t]
2454        ["Expire expirable articles" gnus-summary-expire-articles
2455         (gnus-check-backend-function
2456          'request-expire-articles gnus-newsgroup-name)]
2457        ["Edit local kill file" gnus-summary-edit-local-kill t]
2458        ["Edit main kill file" gnus-summary-edit-global-kill t]
2459        ["Edit group parameters" gnus-summary-edit-parameters t]
2460        ["Customize group parameters" gnus-summary-customize-parameters t]
2461        ["Send a bug report" gnus-bug t]
2462        ("Exit"
2463         ["Catchup and exit" gnus-summary-catchup-and-exit
2464          ,@(if (featurep 'xemacs) '(t)
2465              '(:help "Mark unread articles in this group as read, then exit"))]
2466         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2467         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2468         ["Exit group" gnus-summary-exit
2469          ,@(if (featurep 'xemacs) '(t)
2470              '(:help "Exit current group, return to group selection mode"))]
2471         ["Exit group without updating" gnus-summary-exit-no-update t]
2472         ["Exit and goto next group" gnus-summary-next-group t]
2473         ["Exit and goto prev group" gnus-summary-prev-group t]
2474         ["Reselect group" gnus-summary-reselect-current-group t]
2475         ["Rescan group" gnus-summary-rescan-group t]
2476         ["Update dribble" gnus-summary-save-newsrc t])))
2477
2478     (gnus-run-hooks 'gnus-summary-menu-hook)))
2479
2480 (defvar gnus-summary-tool-bar-map nil)
2481
2482 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2483 (defun gnus-summary-make-tool-bar ()
2484   (if (and (fboundp 'tool-bar-add-item-from-menu)
2485            (default-value 'tool-bar-mode)
2486            (not gnus-summary-tool-bar-map))
2487       (setq gnus-summary-tool-bar-map
2488             (let ((tool-bar-map (make-sparse-keymap))
2489                   (load-path (mm-image-load-path)))
2490               (tool-bar-add-item-from-menu
2491                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2492               (tool-bar-add-item-from-menu
2493                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2494               (tool-bar-add-item-from-menu
2495                'gnus-summary-post-news "post" gnus-summary-mode-map)
2496               (tool-bar-add-item-from-menu
2497                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2498               (tool-bar-add-item-from-menu
2499                'gnus-summary-followup "followup" gnus-summary-mode-map)
2500               (tool-bar-add-item-from-menu
2501                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2502               (tool-bar-add-item-from-menu
2503                'gnus-summary-reply "reply" gnus-summary-mode-map)
2504               (tool-bar-add-item-from-menu
2505                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2506               (tool-bar-add-item-from-menu
2507                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2520               tool-bar-map)))
2521   (if gnus-summary-tool-bar-map
2522       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2523
2524 (defun gnus-score-set-default (var value)
2525   "A version of set that updates the GNU Emacs menu-bar."
2526   (set var value)
2527   ;; It is the message that forces the active status to be updated.
2528   (message ""))
2529
2530 (defun gnus-make-score-map (type)
2531   "Make a summary score map of type TYPE."
2532   (if t
2533       nil
2534     (let ((headers '(("author" "from" string)
2535                      ("subject" "subject" string)
2536                      ("article body" "body" string)
2537                      ("article head" "head" string)
2538                      ("xref" "xref" string)
2539                      ("extra header" "extra" string)
2540                      ("lines" "lines" number)
2541                      ("followups to author" "followup" string)))
2542           (types '((number ("less than" <)
2543                            ("greater than" >)
2544                            ("equal" =))
2545                    (string ("substring" s)
2546                            ("exact string" e)
2547                            ("fuzzy string" f)
2548                            ("regexp" r))))
2549           (perms '(("temporary" (current-time-string))
2550                    ("permanent" nil)
2551                    ("immediate" now)))
2552           header)
2553       (list
2554        (apply
2555         'nconc
2556         (list
2557          (if (eq type 'lower)
2558              "Lower score"
2559            "Increase score"))
2560         (let (outh)
2561           (while headers
2562             (setq header (car headers))
2563             (setq outh
2564                   (cons
2565                    (apply
2566                     'nconc
2567                     (list (car header))
2568                     (let ((ts (cdr (assoc (nth 2 header) types)))
2569                           outt)
2570                       (while ts
2571                         (setq outt
2572                               (cons
2573                                (apply
2574                                 'nconc
2575                                 (list (caar ts))
2576                                 (let ((ps perms)
2577                                       outp)
2578                                   (while ps
2579                                     (setq outp
2580                                           (cons
2581                                            (vector
2582                                             (caar ps)
2583                                             (list
2584                                              'gnus-summary-score-entry
2585                                              (nth 1 header)
2586                                              (if (or (string= (nth 1 header)
2587                                                               "head")
2588                                                      (string= (nth 1 header)
2589                                                               "body"))
2590                                                  ""
2591                                                (list 'gnus-summary-header
2592                                                      (nth 1 header)))
2593                                              (list 'quote (nth 1 (car ts)))
2594                                              (list 'gnus-score-delta-default
2595                                                    nil)
2596                                              (nth 1 (car ps))
2597                                              t)
2598                                             t)
2599                                            outp))
2600                                     (setq ps (cdr ps)))
2601                                   (list (nreverse outp))))
2602                                outt))
2603                         (setq ts (cdr ts)))
2604                       (list (nreverse outt))))
2605                    outh))
2606             (setq headers (cdr headers)))
2607           (list (nreverse outh))))))))
2608
2609 \f
2610
2611 (defun gnus-summary-mode (&optional group)
2612   "Major mode for reading articles.
2613
2614 All normal editing commands are switched off.
2615 \\<gnus-summary-mode-map>
2616 Each line in this buffer represents one article.  To read an
2617 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2618 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2619 respectively.
2620
2621 You can also post articles and send mail from this buffer.  To
2622 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2623 of an article, type `\\[gnus-summary-reply]'.
2624
2625 There are approx. one gazillion commands you can execute in this
2626 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2627
2628 The following commands are available:
2629
2630 \\{gnus-summary-mode-map}"
2631   (interactive)
2632   (kill-all-local-variables)
2633   (when (gnus-visual-p 'summary-menu 'menu)
2634     (gnus-summary-make-menu-bar)
2635     (gnus-summary-make-tool-bar))
2636   (gnus-summary-make-local-variables)
2637   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2638     (gnus-summary-make-local-variables))
2639   (gnus-make-thread-indent-array)
2640   (gnus-simplify-mode-line)
2641   (setq major-mode 'gnus-summary-mode)
2642   (setq mode-name "Summary")
2643   (make-local-variable 'minor-mode-alist)
2644   (use-local-map gnus-summary-mode-map)
2645   (buffer-disable-undo)
2646   (setq buffer-read-only t)             ;Disable modification
2647   (setq truncate-lines t)
2648   (setq selective-display t)
2649   (setq selective-display-ellipses t)   ;Display `...'
2650   (gnus-summary-set-display-table)
2651   (gnus-set-default-directory)
2652   (setq gnus-newsgroup-name group)
2653   (unless (gnus-news-group-p group)
2654     (setq gnus-newsgroup-incorporated
2655           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2656   (make-local-variable 'gnus-summary-line-format)
2657   (make-local-variable 'gnus-summary-line-format-spec)
2658   (make-local-variable 'gnus-summary-dummy-line-format)
2659   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2660   (make-local-variable 'gnus-summary-mark-positions)
2661   (make-local-hook 'pre-command-hook)
2662   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2663   (gnus-run-hooks 'gnus-summary-mode-hook)
2664   (turn-on-gnus-mailing-list-mode)
2665   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2666   (gnus-update-summary-mark-positions))
2667
2668 (defun gnus-summary-make-local-variables ()
2669   "Make all the local summary buffer variables."
2670   (let (global)
2671     (dolist (local gnus-summary-local-variables)
2672       (if (consp local)
2673           (progn
2674             (if (eq (cdr local) 'global)
2675                 ;; Copy the global value of the variable.
2676                 (setq global (symbol-value (car local)))
2677               ;; Use the value from the list.
2678               (setq global (eval (cdr local))))
2679             (set (make-local-variable (car local)) global))
2680         ;; Simple nil-valued local variable.
2681         (set (make-local-variable local) nil)))))
2682
2683 (defun gnus-summary-clear-local-variables ()
2684   (let ((locals gnus-summary-local-variables))
2685     (while locals
2686       (if (consp (car locals))
2687           (and (vectorp (caar locals))
2688                (set (caar locals) nil))
2689         (and (vectorp (car locals))
2690              (set (car locals) nil)))
2691       (setq locals (cdr locals)))))
2692
2693 ;; Summary data functions.
2694
2695 (defmacro gnus-data-number (data)
2696   `(car ,data))
2697
2698 (defmacro gnus-data-set-number (data number)
2699   `(setcar ,data ,number))
2700
2701 (defmacro gnus-data-mark (data)
2702   `(nth 1 ,data))
2703
2704 (defmacro gnus-data-set-mark (data mark)
2705   `(setcar (nthcdr 1 ,data) ,mark))
2706
2707 (defmacro gnus-data-pos (data)
2708   `(nth 2 ,data))
2709
2710 (defmacro gnus-data-set-pos (data pos)
2711   `(setcar (nthcdr 2 ,data) ,pos))
2712
2713 (defmacro gnus-data-header (data)
2714   `(nth 3 ,data))
2715
2716 (defmacro gnus-data-set-header (data header)
2717   `(setcar (nthcdr 3 ,data) ,header))
2718
2719 (defmacro gnus-data-level (data)
2720   `(nth 4 ,data))
2721
2722 (defmacro gnus-data-unread-p (data)
2723   `(= (nth 1 ,data) gnus-unread-mark))
2724
2725 (defmacro gnus-data-read-p (data)
2726   `(/= (nth 1 ,data) gnus-unread-mark))
2727
2728 (defmacro gnus-data-pseudo-p (data)
2729   `(consp (nth 3 ,data)))
2730
2731 (defmacro gnus-data-find (number)
2732   `(assq ,number gnus-newsgroup-data))
2733
2734 (defmacro gnus-data-find-list (number &optional data)
2735   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2736      (memq (assq ,number bdata)
2737            bdata)))
2738
2739 (defmacro gnus-data-make (number mark pos header level)
2740   `(list ,number ,mark ,pos ,header ,level))
2741
2742 (defun gnus-data-enter (after-article number mark pos header level offset)
2743   (let ((data (gnus-data-find-list after-article)))
2744     (unless data
2745       (error "No such article: %d" after-article))
2746     (setcdr data (cons (gnus-data-make number mark pos header level)
2747                        (cdr data)))
2748     (setq gnus-newsgroup-data-reverse nil)
2749     (gnus-data-update-list (cddr data) offset)))
2750
2751 (defun gnus-data-enter-list (after-article list &optional offset)
2752   (when list
2753     (let ((data (and after-article (gnus-data-find-list after-article)))
2754           (ilist list))
2755       (if (not (or data
2756                    after-article))
2757           (let ((odata gnus-newsgroup-data))
2758             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2759             (when offset
2760               (gnus-data-update-list odata offset)))
2761         ;; Find the last element in the list to be spliced into the main
2762         ;; list.
2763         (while (cdr list)
2764           (setq list (cdr list)))
2765         (if (not data)
2766             (progn
2767               (setcdr list gnus-newsgroup-data)
2768               (setq gnus-newsgroup-data ilist)
2769               (when offset
2770                 (gnus-data-update-list (cdr list) offset)))
2771           (setcdr list (cdr data))
2772           (setcdr data ilist)
2773           (when offset
2774             (gnus-data-update-list (cdr list) offset))))
2775       (setq gnus-newsgroup-data-reverse nil))))
2776
2777 (defun gnus-data-remove (article &optional offset)
2778   (let ((data gnus-newsgroup-data))
2779     (if (= (gnus-data-number (car data)) article)
2780         (progn
2781           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2782                 gnus-newsgroup-data-reverse nil)
2783           (when offset
2784             (gnus-data-update-list gnus-newsgroup-data offset)))
2785       (while (cdr data)
2786         (when (= (gnus-data-number (cadr data)) article)
2787           (setcdr data (cddr data))
2788           (when offset
2789             (gnus-data-update-list (cdr data) offset))
2790           (setq data nil
2791                 gnus-newsgroup-data-reverse nil))
2792         (setq data (cdr data))))))
2793
2794 (defmacro gnus-data-list (backward)
2795   `(if ,backward
2796        (or gnus-newsgroup-data-reverse
2797            (setq gnus-newsgroup-data-reverse
2798                  (reverse gnus-newsgroup-data)))
2799      gnus-newsgroup-data))
2800
2801 (defun gnus-data-update-list (data offset)
2802   "Add OFFSET to the POS of all data entries in DATA."
2803   (setq gnus-newsgroup-data-reverse nil)
2804   (while data
2805     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2806     (setq data (cdr data))))
2807
2808 (defun gnus-summary-article-pseudo-p (article)
2809   "Say whether this article is a pseudo article or not."
2810   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2811
2812 (defmacro gnus-summary-article-sparse-p (article)
2813   "Say whether this article is a sparse article or not."
2814   `(memq ,article gnus-newsgroup-sparse))
2815
2816 (defmacro gnus-summary-article-ancient-p (article)
2817   "Say whether this article is a sparse article or not."
2818   `(memq ,article gnus-newsgroup-ancient))
2819
2820 (defun gnus-article-parent-p (number)
2821   "Say whether this article is a parent or not."
2822   (let ((data (gnus-data-find-list number)))
2823     (and (cdr data)                     ; There has to be an article after...
2824          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2825             (gnus-data-level (nth 1 data))))))
2826
2827 (defun gnus-article-children (number)
2828   "Return a list of all children to NUMBER."
2829   (let* ((data (gnus-data-find-list number))
2830          (level (gnus-data-level (car data)))
2831          children)
2832     (setq data (cdr data))
2833     (while (and data
2834                 (= (gnus-data-level (car data)) (1+ level)))
2835       (push (gnus-data-number (car data)) children)
2836       (setq data (cdr data)))
2837     children))
2838
2839 (defmacro gnus-summary-skip-intangible ()
2840   "If the current article is intangible, then jump to a different article."
2841   '(let ((to (get-text-property (point) 'gnus-intangible)))
2842      (and to (gnus-summary-goto-subject to))))
2843
2844 (defmacro gnus-summary-article-intangible-p ()
2845   "Say whether this article is intangible or not."
2846   '(get-text-property (point) 'gnus-intangible))
2847
2848 (defun gnus-article-read-p (article)
2849   "Say whether ARTICLE is read or not."
2850   (not (or (memq article gnus-newsgroup-marked)
2851            (memq article gnus-newsgroup-spam-marked)
2852            (memq article gnus-newsgroup-unreads)
2853            (memq article gnus-newsgroup-unselected)
2854            (memq article gnus-newsgroup-dormant))))
2855
2856 ;; Some summary mode macros.
2857
2858 (defmacro gnus-summary-article-number ()
2859   "The article number of the article on the current line.
2860 If there isn't an article number here, then we return the current
2861 article number."
2862   '(progn
2863      (gnus-summary-skip-intangible)
2864      (or (get-text-property (point) 'gnus-number)
2865          (gnus-summary-last-subject))))
2866
2867 (defmacro gnus-summary-article-header (&optional number)
2868   "Return the header of article NUMBER."
2869   `(gnus-data-header (gnus-data-find
2870                       ,(or number '(gnus-summary-article-number)))))
2871
2872 (defmacro gnus-summary-thread-level (&optional number)
2873   "Return the level of thread that starts with article NUMBER."
2874   `(if (and (eq gnus-summary-make-false-root 'dummy)
2875             (get-text-property (point) 'gnus-intangible))
2876        0
2877      (gnus-data-level (gnus-data-find
2878                        ,(or number '(gnus-summary-article-number))))))
2879
2880 (defmacro gnus-summary-article-mark (&optional number)
2881   "Return the mark of article NUMBER."
2882   `(gnus-data-mark (gnus-data-find
2883                     ,(or number '(gnus-summary-article-number)))))
2884
2885 (defmacro gnus-summary-article-pos (&optional number)
2886   "Return the position of the line of article NUMBER."
2887   `(gnus-data-pos (gnus-data-find
2888                    ,(or number '(gnus-summary-article-number)))))
2889
2890 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2891 (defmacro gnus-summary-article-subject (&optional number)
2892   "Return current subject string or nil if nothing."
2893   `(let ((headers
2894           ,(if number
2895                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2896              '(gnus-data-header (assq (gnus-summary-article-number)
2897                                       gnus-newsgroup-data)))))
2898      (and headers
2899           (vectorp headers)
2900           (mail-header-subject headers))))
2901
2902 (defmacro gnus-summary-article-score (&optional number)
2903   "Return current article score."
2904   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2905                   gnus-newsgroup-scored))
2906        gnus-summary-default-score 0))
2907
2908 (defun gnus-summary-article-children (&optional number)
2909   "Return a list of article numbers that are children of article NUMBER."
2910   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2911          (level (gnus-data-level (car data)))
2912          l children)
2913     (while (and (setq data (cdr data))
2914                 (> (setq l (gnus-data-level (car data))) level))
2915       (and (= (1+ level) l)
2916            (push (gnus-data-number (car data))
2917                  children)))
2918     (nreverse children)))
2919
2920 (defun gnus-summary-article-parent (&optional number)
2921   "Return the article number of the parent of article NUMBER."
2922   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2923                                     (gnus-data-list t)))
2924          (level (gnus-data-level (car data))))
2925     (if (zerop level)
2926         ()                              ; This is a root.
2927       ;; We search until we find an article with a level less than
2928       ;; this one.  That function has to be the parent.
2929       (while (and (setq data (cdr data))
2930                   (not (< (gnus-data-level (car data)) level))))
2931       (and data (gnus-data-number (car data))))))
2932
2933 (defun gnus-unread-mark-p (mark)
2934   "Say whether MARK is the unread mark."
2935   (= mark gnus-unread-mark))
2936
2937 (defun gnus-read-mark-p (mark)
2938   "Say whether MARK is one of the marks that mark as read.
2939 This is all marks except unread, ticked, dormant, and expirable."
2940   (not (or (= mark gnus-unread-mark)
2941            (= mark gnus-ticked-mark)
2942            (= mark gnus-spam-mark)
2943            (= mark gnus-dormant-mark)
2944            (= mark gnus-expirable-mark))))
2945
2946 (defmacro gnus-article-mark (number)
2947   "Return the MARK of article NUMBER.
2948 This macro should only be used when computing the mark the \"first\"
2949 time; i.e., when generating the summary lines.  After that,
2950 `gnus-summary-article-mark' should be used to examine the
2951 marks of articles."
2952   `(cond
2953     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2954     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2955     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2956     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2957     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2958     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2959     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2960     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2961            gnus-ancient-mark))))
2962
2963 ;; Saving hidden threads.
2964
2965 (defmacro gnus-save-hidden-threads (&rest forms)
2966   "Save hidden threads, eval FORMS, and restore the hidden threads."
2967   (let ((config (make-symbol "config")))
2968     `(let ((,config (gnus-hidden-threads-configuration)))
2969        (unwind-protect
2970            (save-excursion
2971              ,@forms)
2972          (gnus-restore-hidden-threads-configuration ,config)))))
2973 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2974 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2975
2976 (defun gnus-data-compute-positions ()
2977   "Compute the positions of all articles."
2978   (setq gnus-newsgroup-data-reverse nil)
2979   (let ((data gnus-newsgroup-data))
2980     (save-excursion
2981       (gnus-save-hidden-threads
2982         (gnus-summary-show-all-threads)
2983         (goto-char (point-min))
2984         (while data
2985           (while (get-text-property (point) 'gnus-intangible)
2986             (forward-line 1))
2987           (gnus-data-set-pos (car data) (+ (point) 3))
2988           (setq data (cdr data))
2989           (forward-line 1))))))
2990
2991 (defun gnus-hidden-threads-configuration ()
2992   "Return the current hidden threads configuration."
2993   (save-excursion
2994     (let (config)
2995       (goto-char (point-min))
2996       (while (search-forward "\r" nil t)
2997         (push (1- (point)) config))
2998       config)))
2999
3000 (defun gnus-restore-hidden-threads-configuration (config)
3001   "Restore hidden threads configuration from CONFIG."
3002   (save-excursion
3003     (let (point buffer-read-only)
3004       (while (setq point (pop config))
3005         (when (and (< point (point-max))
3006                    (goto-char point)
3007                    (eq (char-after) ?\n))
3008           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3009
3010 ;; Various summary mode internalish functions.
3011
3012 (defun gnus-mouse-pick-article (e)
3013   (interactive "e")
3014   (mouse-set-point e)
3015   (gnus-summary-next-page nil t))
3016
3017 (defun gnus-summary-set-display-table ()
3018   "Change the display table.
3019 Odd characters have a tendency to mess
3020 up nicely formatted displays - we make all possible glyphs
3021 display only a single character."
3022
3023   ;; We start from the standard display table, if any.
3024   (let ((table (or (copy-sequence standard-display-table)
3025                    (make-display-table)))
3026         (i 32))
3027     ;; Nix out all the control chars...
3028     (while (>= (setq i (1- i)) 0)
3029       (aset table i [??]))
3030     ;; ... but not newline and cr, of course.  (cr is necessary for the
3031     ;; selective display).
3032     (aset table ?\n nil)
3033     (aset table ?\r nil)
3034     ;; We keep TAB as well.
3035     (aset table ?\t nil)
3036     ;; We nix out any glyphs over 126 that are not set already.
3037     (let ((i 256))
3038       (while (>= (setq i (1- i)) 127)
3039         ;; Only modify if the entry is nil.
3040         (unless (aref table i)
3041           (aset table i [??]))))
3042     (setq buffer-display-table table)))
3043
3044 (defun gnus-summary-set-article-display-arrow (pos)
3045   "Update the overlay arrow to point to line at position POS."
3046   (when (and gnus-summary-display-arrow
3047              (boundp 'overlay-arrow-position)
3048              (boundp 'overlay-arrow-string))
3049     (save-excursion
3050       (goto-char pos)
3051       (beginning-of-line)
3052       (unless overlay-arrow-position
3053         (setq overlay-arrow-position (make-marker)))
3054       (setq overlay-arrow-string "=>"
3055             overlay-arrow-position (set-marker overlay-arrow-position
3056                                                (point)
3057                                                (current-buffer))))))
3058
3059 (defun gnus-summary-setup-buffer (group)
3060   "Initialize summary buffer."
3061   (let ((buffer (gnus-summary-buffer-name group))
3062         (dead-name (concat "*Dead Summary "
3063                            (gnus-group-decoded-name group) "*")))
3064     ;; If a dead summary buffer exists, we kill it.
3065     (when (gnus-buffer-live-p dead-name)
3066       (gnus-kill-buffer dead-name))
3067     (if (get-buffer buffer)
3068         (progn
3069           (set-buffer buffer)
3070           (setq gnus-summary-buffer (current-buffer))
3071           (not gnus-newsgroup-prepared))
3072       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3073       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3074       (gnus-summary-mode group)
3075       (when gnus-carpal
3076         (gnus-carpal-setup-buffer 'summary))
3077       (unless gnus-single-article-buffer
3078         (make-local-variable 'gnus-article-buffer)
3079         (make-local-variable 'gnus-article-current)
3080         (make-local-variable 'gnus-original-article-buffer))
3081       (setq gnus-newsgroup-name group)
3082       ;; Set any local variables in the group parameters.
3083       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3084       t)))
3085
3086 (defun gnus-set-global-variables ()
3087   "Set the global equivalents of the buffer-local variables.
3088 They are set to the latest values they had.  These reflect the summary
3089 buffer that was in action when the last article was fetched."
3090   (when (eq major-mode 'gnus-summary-mode)
3091     (setq gnus-summary-buffer (current-buffer))
3092     (let ((name gnus-newsgroup-name)
3093           (marked gnus-newsgroup-marked)
3094           (spam gnus-newsgroup-spam-marked)
3095           (unread gnus-newsgroup-unreads)
3096           (headers gnus-current-headers)
3097           (data gnus-newsgroup-data)
3098           (summary gnus-summary-buffer)
3099           (article-buffer gnus-article-buffer)
3100           (original gnus-original-article-buffer)
3101           (gac gnus-article-current)
3102           (reffed gnus-reffed-article-number)
3103           (score-file gnus-current-score-file)
3104           (default-charset gnus-newsgroup-charset)
3105           vlist)
3106       (let ((locals gnus-newsgroup-variables))
3107         (while locals
3108           (if (consp (car locals))
3109               (push (eval (caar locals)) vlist)
3110             (push (eval (car locals)) vlist))
3111           (setq locals (cdr locals)))
3112         (setq vlist (nreverse vlist)))
3113       (save-excursion
3114         (set-buffer gnus-group-buffer)
3115         (setq gnus-newsgroup-name name
3116               gnus-newsgroup-marked marked
3117               gnus-newsgroup-spam-marked spam
3118               gnus-newsgroup-unreads unread
3119               gnus-current-headers headers
3120               gnus-newsgroup-data data
3121               gnus-article-current gac
3122               gnus-summary-buffer summary
3123               gnus-article-buffer article-buffer
3124               gnus-original-article-buffer original
3125               gnus-reffed-article-number reffed
3126               gnus-current-score-file score-file
3127               gnus-newsgroup-charset default-charset)
3128         (let ((locals gnus-newsgroup-variables))
3129           (while locals
3130             (if (consp (car locals))
3131                 (set (caar locals) (pop vlist))
3132               (set (car locals) (pop vlist)))
3133             (setq locals (cdr locals))))
3134         ;; The article buffer also has local variables.
3135         (when (gnus-buffer-live-p gnus-article-buffer)
3136           (set-buffer gnus-article-buffer)
3137           (setq gnus-summary-buffer summary))))))
3138
3139 (defun gnus-summary-article-unread-p (article)
3140   "Say whether ARTICLE is unread or not."
3141   (memq article gnus-newsgroup-unreads))
3142
3143 (defun gnus-summary-first-article-p (&optional article)
3144   "Return whether ARTICLE is the first article in the buffer."
3145   (if (not (setq article (or article (gnus-summary-article-number))))
3146       nil
3147     (eq article (caar gnus-newsgroup-data))))
3148
3149 (defun gnus-summary-last-article-p (&optional article)
3150   "Return whether ARTICLE is the last article in the buffer."
3151   (if (not (setq article (or article (gnus-summary-article-number))))
3152       ;; All non-existent numbers are the last article.  :-)
3153       t
3154     (not (cdr (gnus-data-find-list article)))))
3155
3156 (defun gnus-make-thread-indent-array ()
3157   (let ((n 200))
3158     (unless (and gnus-thread-indent-array
3159                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3160       (setq gnus-thread-indent-array (make-vector 201 "")
3161             gnus-thread-indent-array-level gnus-thread-indent-level)
3162       (while (>= n 0)
3163         (aset gnus-thread-indent-array n
3164               (make-string (* n gnus-thread-indent-level) ? ))
3165         (setq n (1- n))))))
3166
3167 (defun gnus-update-summary-mark-positions ()
3168   "Compute where the summary marks are to go."
3169   (save-excursion
3170     (when (gnus-buffer-exists-p gnus-summary-buffer)
3171       (set-buffer gnus-summary-buffer))
3172     (let ((gnus-replied-mark 129)
3173           (gnus-score-below-mark 130)
3174           (gnus-score-over-mark 130)
3175           (gnus-undownloaded-mark 131)
3176           (spec gnus-summary-line-format-spec)
3177           gnus-visual pos)
3178       (save-excursion
3179         (gnus-set-work-buffer)
3180         (let ((gnus-summary-line-format-spec spec)
3181               (gnus-newsgroup-downloadable '(0)))
3182           (gnus-summary-insert-line
3183            (make-full-mail-header 0 "" "nobody"
3184                                   "05 Apr 2001 23:33:09 +0400"
3185                                   "" "" 0 0 "" nil)
3186            0 nil t 128 t nil "" nil 1)
3187           (goto-char (point-min))
3188           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3189                                              (- (point) (point-min) 1)))))
3190           (goto-char (point-min))
3191           (push (cons 'replied (and (search-forward "\201" nil t)
3192                                     (- (point) (point-min) 1)))
3193                 pos)
3194           (goto-char (point-min))
3195           (push (cons 'score (and (search-forward "\202" nil t)
3196                                   (- (point) (point-min) 1)))
3197                 pos)
3198           (goto-char (point-min))
3199           (push (cons 'download
3200                       (and (search-forward "\203" nil t)
3201                            (- (point) (point-min) 1)))
3202                 pos)))
3203       (setq gnus-summary-mark-positions pos))))
3204
3205 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3206   "Insert a dummy root in the summary buffer."
3207   (beginning-of-line)
3208   (gnus-add-text-properties
3209    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3210    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3211
3212 (defun gnus-summary-extract-address-component (from)
3213   (or (car (funcall gnus-extract-address-components from))
3214       from))
3215
3216 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3217   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3218                                 default-mime-charset)))
3219     ;; Is it really necessary to do this next part for each summary line?
3220     ;; Luckily, doesn't seem to slow things down much.
3221     (or
3222      (and gnus-ignored-from-addresses
3223           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3224           (let ((extra-headers (mail-header-extra header))
3225                 to
3226                 newsgroups)
3227             (cond
3228              ((setq to (cdr (assq 'To extra-headers)))
3229               (concat "-> "
3230                       (inline
3231                         (gnus-summary-extract-address-component
3232                          (funcall gnus-decode-encoded-word-function to)))))
3233              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3234               (concat "=> " newsgroups)))))
3235      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3236
3237 (defun gnus-summary-insert-line (gnus-tmp-header
3238                                  gnus-tmp-level gnus-tmp-current
3239                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3240                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3241                                  &optional gnus-tmp-dummy gnus-tmp-score
3242                                  gnus-tmp-process)
3243   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3244          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3245          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3246          (gnus-tmp-score-char
3247           (if (or (null gnus-summary-default-score)
3248                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3249                       gnus-summary-zcore-fuzz))
3250               ?\ ;;;Whitespace
3251             (if (< gnus-tmp-score gnus-summary-default-score)
3252                 gnus-score-below-mark gnus-score-over-mark)))
3253          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3254          (gnus-tmp-replied
3255           (cond (gnus-tmp-process gnus-process-mark)
3256                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3257                  gnus-cached-mark)
3258                 (gnus-tmp-replied gnus-replied-mark)
3259                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3260                  gnus-forwarded-mark)
3261                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3262                  gnus-saved-mark)
3263                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3264                  gnus-recent-mark)
3265                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3266                  gnus-unseen-mark)
3267                 (t gnus-no-mark)))
3268          (gnus-tmp-downloaded
3269           (cond (undownloaded 
3270                  gnus-undownloaded-mark)
3271                 (gnus-newsgroup-agentized
3272                  gnus-downloaded-mark)
3273                 (t
3274                  gnus-no-mark)))
3275          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3276          (gnus-tmp-name
3277           (cond
3278            ((string-match "<[^>]+> *$" gnus-tmp-from)
3279             (let ((beg (match-beginning 0)))
3280               (or (and (string-match "^\".+\"" gnus-tmp-from)
3281                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3282                   (substring gnus-tmp-from 0 beg))))
3283            ((string-match "(.+)" gnus-tmp-from)
3284             (substring gnus-tmp-from
3285                        (1+ (match-beginning 0)) (1- (match-end 0))))
3286            (t gnus-tmp-from)))
3287          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3288          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3289          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3290          (buffer-read-only nil))
3291     (when (string= gnus-tmp-name "")
3292       (setq gnus-tmp-name gnus-tmp-from))
3293     (unless (numberp gnus-tmp-lines)
3294       (setq gnus-tmp-lines -1))
3295     (if (= gnus-tmp-lines -1)
3296         (setq gnus-tmp-lines "?")
3297       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3298     (gnus-put-text-property-excluding-characters-with-faces
3299      (point)
3300      (progn (eval gnus-summary-line-format-spec) (point))
3301      'gnus-number gnus-tmp-number)
3302     (when (gnus-visual-p 'summary-highlight 'highlight)
3303       (forward-line -1)
3304       (gnus-run-hooks 'gnus-summary-update-hook)
3305       (forward-line 1))))
3306
3307 (defun gnus-summary-update-line (&optional dont-update)
3308   "Update summary line after change."
3309   (when (and gnus-summary-default-score
3310              (not gnus-summary-inhibit-highlight))
3311     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3312            (article (gnus-summary-article-number))
3313            (score (gnus-summary-article-score article)))
3314       (unless dont-update
3315         (if (and gnus-summary-mark-below
3316                  (< (gnus-summary-article-score)
3317                     gnus-summary-mark-below))
3318             ;; This article has a low score, so we mark it as read.
3319             (when (memq article gnus-newsgroup-unreads)
3320               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3321           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3322             ;; This article was previously marked as read on account
3323             ;; of a low score, but now it has risen, so we mark it as
3324             ;; unread.
3325             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3326         (gnus-summary-update-mark
3327          (if (or (null gnus-summary-default-score)
3328                  (<= (abs (- score gnus-summary-default-score))
3329                      gnus-summary-zcore-fuzz))
3330              ?\ ;;;Whitespace
3331            (if (< score gnus-summary-default-score)
3332                gnus-score-below-mark gnus-score-over-mark))
3333          'score))
3334       ;; Do visual highlighting.
3335       (when (gnus-visual-p 'summary-highlight 'highlight)
3336         (gnus-run-hooks 'gnus-summary-update-hook)))))
3337
3338 (defvar gnus-tmp-new-adopts nil)
3339
3340 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3341   "Return the number of articles in THREAD.
3342 This may be 0 in some cases -- if none of the articles in
3343 the thread are to be displayed."
3344   (let* ((number
3345           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3346           (cond
3347            ((not (listp thread))
3348             1)
3349            ((and (consp thread) (cdr thread))
3350             (apply
3351              '+ 1 (mapcar
3352                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3353            ((null thread)
3354             1)
3355            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3356             1)
3357            (t 0))))
3358     (when (and level (zerop level) gnus-tmp-new-adopts)
3359       (incf number
3360             (apply '+ (mapcar
3361                        'gnus-summary-number-of-articles-in-thread
3362                        gnus-tmp-new-adopts))))
3363     (if char
3364         (if (> number 1) gnus-not-empty-thread-mark
3365           gnus-empty-thread-mark)
3366       number)))
3367
3368 (defsubst gnus-summary-line-message-size (head)
3369   "Return pretty-printed version of message size.
3370 This function is intended to be used in
3371 `gnus-summary-line-format-alist', which see."
3372   (let ((c (or (mail-header-chars head) -1)))
3373     (cond ((< c 0) "n/a")               ; chars not available
3374           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3375           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3376           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3377           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3378
3379
3380 (defun gnus-summary-set-local-parameters (group)
3381   "Go through the local params of GROUP and set all variable specs in that list."
3382   (let ((params (gnus-group-find-parameter group))
3383         (vars '(quit-config))           ; Ignore quit-config.
3384         elem)
3385     (while params
3386       (setq elem (car params)
3387             params (cdr params))
3388       (and (consp elem)                 ; Has to be a cons.
3389            (consp (cdr elem))           ; The cdr has to be a list.
3390            (symbolp (car elem))         ; Has to be a symbol in there.
3391            (not (memq (car elem) vars))
3392            (ignore-errors               ; So we set it.
3393              (push (car elem) vars)
3394              (make-local-variable (car elem))
3395              (set (car elem) (eval (nth 1 elem))))))))
3396
3397 (defun gnus-summary-read-group (group &optional show-all no-article
3398                                       kill-buffer no-display backward
3399                                       select-articles)
3400   "Start reading news in newsgroup GROUP.
3401 If SHOW-ALL is non-nil, already read articles are also listed.
3402 If NO-ARTICLE is non-nil, no article is selected initially.
3403 If NO-DISPLAY, don't generate a summary buffer."
3404   (let (result)
3405     (while (and group
3406                 (null (setq result
3407                             (let ((gnus-auto-select-next nil))
3408                               (or (gnus-summary-read-group-1
3409                                    group show-all no-article
3410                                    kill-buffer no-display
3411                                    select-articles)
3412                                   (setq show-all nil
3413                                         select-articles nil)))))
3414                 (eq gnus-auto-select-next 'quietly))
3415       (set-buffer gnus-group-buffer)
3416       ;; The entry function called above goes to the next
3417       ;; group automatically, so we go two groups back
3418       ;; if we are searching for the previous group.
3419       (when backward
3420         (gnus-group-prev-unread-group 2))
3421       (if (not (equal group (gnus-group-group-name)))
3422           (setq group (gnus-group-group-name))
3423         (setq group nil)))
3424     result))
3425
3426 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3427   "Directly jump to the other GROUP from summary buffer.
3428 If SHOW-ALL is non-nil, already read articles are also listed."
3429   (interactive
3430    (if (eq gnus-summary-buffer (current-buffer))
3431        (list (completing-read
3432               "Group: " gnus-active-hashtb nil t
3433               (when (and gnus-newsgroup-name
3434                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3435                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3436               'gnus-group-history)
3437              current-prefix-arg)
3438      (error "%s must be invoked from a gnus summary buffer." this-command)))
3439   (unless (or (zerop (length group))
3440               (and gnus-newsgroup-name
3441                    (string-equal gnus-newsgroup-name group)))
3442     (gnus-summary-exit)
3443     (gnus-summary-read-group group show-all
3444                              gnus-dont-select-after-jump-to-other-group)))
3445
3446 (defun gnus-summary-read-group-1 (group show-all no-article
3447                                         kill-buffer no-display
3448                                         &optional select-articles)
3449   ;; Killed foreign groups can't be entered.
3450   ;;  (when (and (not (gnus-group-native-p group))
3451   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3452   ;;    (error "Dead non-native groups can't be entered"))
3453   (gnus-message 5 "Retrieving newsgroup: %s..."
3454                 (gnus-group-decoded-name group))
3455   (let* ((new-group (gnus-summary-setup-buffer group))
3456          (quit-config (gnus-group-quit-config group))
3457          (did-select (and new-group (gnus-select-newsgroup
3458                                      group show-all select-articles))))
3459     (cond
3460      ;; This summary buffer exists already, so we just select it.
3461      ((not new-group)
3462       (gnus-set-global-variables)
3463       (when kill-buffer
3464         (gnus-kill-or-deaden-summary kill-buffer))
3465       (gnus-configure-windows 'summary 'force)
3466       (gnus-set-mode-line 'summary)
3467       (gnus-summary-position-point)
3468       (message "")
3469       t)
3470      ;; We couldn't select this group.
3471      ((null did-select)
3472       (when (and (eq major-mode 'gnus-summary-mode)
3473                  (not (equal (current-buffer) kill-buffer)))
3474         (kill-buffer (current-buffer))
3475         (if (not quit-config)
3476             (progn
3477               ;; Update the info -- marks might need to be removed,
3478               ;; for instance.
3479               (gnus-summary-update-info)
3480               (set-buffer gnus-group-buffer)
3481               (gnus-group-jump-to-group group)
3482               (gnus-group-next-unread-group 1))
3483           (gnus-handle-ephemeral-exit quit-config)))
3484       (let ((grpinfo (gnus-get-info group)))
3485         (if (null (gnus-info-read grpinfo))
3486             (gnus-message 3 "Group %s contains no messages"
3487                           (gnus-group-decoded-name group))
3488           (gnus-message 3 "Can't select group")))
3489       nil)
3490      ;; The user did a `C-g' while prompting for number of articles,
3491      ;; so we exit this group.
3492      ((eq did-select 'quit)
3493       (and (eq major-mode 'gnus-summary-mode)
3494            (not (equal (current-buffer) kill-buffer))
3495            (kill-buffer (current-buffer)))
3496       (when kill-buffer
3497         (gnus-kill-or-deaden-summary kill-buffer))
3498       (if (not quit-config)
3499           (progn
3500             (set-buffer gnus-group-buffer)
3501             (gnus-group-jump-to-group group)
3502             (gnus-group-next-unread-group 1)
3503             (gnus-configure-windows 'group 'force))
3504         (gnus-handle-ephemeral-exit quit-config))
3505       ;; Finally signal the quit.
3506       (signal 'quit nil))
3507      ;; The group was successfully selected.
3508      (t
3509       (gnus-set-global-variables)
3510       ;; Save the active value in effect when the group was entered.
3511       (setq gnus-newsgroup-active
3512             (gnus-copy-sequence
3513              (gnus-active gnus-newsgroup-name)))
3514       ;; You can change the summary buffer in some way with this hook.
3515       (gnus-run-hooks 'gnus-select-group-hook)
3516       (gnus-update-format-specifications
3517        nil 'summary 'summary-mode 'summary-dummy)
3518       (gnus-update-summary-mark-positions)
3519       ;; Do score processing.
3520       (when gnus-use-scoring
3521         (gnus-possibly-score-headers))
3522       ;; Check whether to fill in the gaps in the threads.
3523       (when gnus-build-sparse-threads
3524         (gnus-build-sparse-threads))
3525       ;; Find the initial limit.
3526       (if gnus-show-threads
3527           (if show-all
3528               (let ((gnus-newsgroup-dormant nil))
3529                 (gnus-summary-initial-limit show-all))
3530             (gnus-summary-initial-limit show-all))
3531         ;; When unthreaded, all articles are always shown.
3532         (setq gnus-newsgroup-limit
3533               (mapcar
3534                (lambda (header) (mail-header-number header))
3535                gnus-newsgroup-headers)))
3536       ;; Generate the summary buffer.
3537       (unless no-display
3538         (gnus-summary-prepare))
3539       (when gnus-use-trees
3540         (gnus-tree-open group)
3541         (setq gnus-summary-highlight-line-function
3542               'gnus-tree-highlight-article))
3543       ;; If the summary buffer is empty, but there are some low-scored
3544       ;; articles or some excluded dormants, we include these in the
3545       ;; buffer.
3546       (when (and (zerop (buffer-size))
3547                  (not no-display))
3548         (cond (gnus-newsgroup-dormant
3549                (gnus-summary-limit-include-dormant))
3550               ((and gnus-newsgroup-scored show-all)
3551                (gnus-summary-limit-include-expunged t))))
3552       ;; Function `gnus-apply-kill-file' must be called in this hook.
3553       (gnus-run-hooks 'gnus-apply-kill-hook)
3554       (if (and (zerop (buffer-size))
3555                (not no-display))
3556           (progn
3557             ;; This newsgroup is empty.
3558             (gnus-summary-catchup-and-exit nil t)
3559             (gnus-message 6 "No unread news")
3560             (when kill-buffer
3561               (gnus-kill-or-deaden-summary kill-buffer))
3562             ;; Return nil from this function.
3563             nil)
3564         ;; Hide conversation thread subtrees.  We cannot do this in
3565         ;; gnus-summary-prepare-hook since kill processing may not
3566         ;; work with hidden articles.
3567         (gnus-summary-maybe-hide-threads)
3568         (when kill-buffer
3569           (gnus-kill-or-deaden-summary kill-buffer))
3570         (gnus-summary-auto-select-subject)
3571         ;; Show first unread article if requested.
3572         (if (and (not no-article)
3573                  (not no-display)
3574                  gnus-newsgroup-unreads
3575                  gnus-auto-select-first)
3576             (progn
3577               (gnus-configure-windows 'summary)
3578               (let ((art (gnus-summary-article-number)))
3579                 (unless (and (not gnus-plugged)
3580                              (or (memq art gnus-newsgroup-undownloaded)
3581                                  (memq art gnus-newsgroup-downloadable)))
3582                   (gnus-summary-goto-article art))))
3583           ;; Don't select any articles.
3584           (gnus-summary-position-point)
3585           (gnus-configure-windows 'summary 'force)
3586           (gnus-set-mode-line 'summary))
3587         (when (and gnus-auto-center-group
3588                    (get-buffer-window gnus-group-buffer t))
3589           ;; Gotta use windows, because recenter does weird stuff if
3590           ;; the current buffer ain't the displayed window.
3591           (let ((owin (selected-window)))
3592             (select-window (get-buffer-window gnus-group-buffer t))
3593             (when (gnus-group-goto-group group)
3594               (recenter))
3595             (select-window owin)))
3596         ;; Mark this buffer as "prepared".
3597         (setq gnus-newsgroup-prepared t)
3598         (gnus-run-hooks 'gnus-summary-prepared-hook)
3599         (unless (gnus-ephemeral-group-p group)
3600           (gnus-group-update-group group))
3601         t)))))
3602
3603 (defun gnus-summary-auto-select-subject ()
3604   "Select the subject line on initial group entry."
3605   (goto-char (point-min))
3606   (cond
3607    ((eq gnus-auto-select-subject 'best)
3608     (gnus-summary-best-unread-subject))
3609    ((eq gnus-auto-select-subject 'unread)
3610     (gnus-summary-first-unread-subject))
3611    ((eq gnus-auto-select-subject 'unseen)
3612     (gnus-summary-first-unseen-subject))
3613    ((eq gnus-auto-select-subject 'unseen-or-unread)
3614     (gnus-summary-first-unseen-or-unread-subject))
3615    ((eq gnus-auto-select-subject 'first)
3616     ;; Do nothing.
3617     )
3618    ((gnus-functionp gnus-auto-select-subject)
3619     (funcall gnus-auto-select-subject))))
3620
3621 (defun gnus-summary-prepare ()
3622   "Generate the summary buffer."
3623   (interactive)
3624   (let ((buffer-read-only nil))
3625     (erase-buffer)
3626     (setq gnus-newsgroup-data nil
3627           gnus-newsgroup-data-reverse nil)
3628     (gnus-run-hooks 'gnus-summary-generate-hook)
3629     ;; Generate the buffer, either with threads or without.
3630     (when gnus-newsgroup-headers
3631       (gnus-summary-prepare-threads
3632        (if gnus-show-threads
3633            (gnus-sort-gathered-threads
3634             (funcall gnus-summary-thread-gathering-function
3635                      (gnus-sort-threads
3636                       (gnus-cut-threads (gnus-make-threads)))))
3637          ;; Unthreaded display.
3638          (gnus-sort-articles gnus-newsgroup-headers))))
3639     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3640     ;; Call hooks for modifying summary buffer.
3641     (goto-char (point-min))
3642     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3643
3644 (defsubst gnus-general-simplify-subject (subject)
3645   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3646   (setq subject
3647         (cond
3648          ;; Truncate the subject.
3649          (gnus-simplify-subject-functions
3650           (gnus-map-function gnus-simplify-subject-functions subject))
3651          ((numberp gnus-summary-gather-subject-limit)
3652           (setq subject (gnus-simplify-subject-re subject))
3653           (if (> (length subject) gnus-summary-gather-subject-limit)
3654               (substring subject 0 gnus-summary-gather-subject-limit)
3655             subject))
3656          ;; Fuzzily simplify it.
3657          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3658           (gnus-simplify-subject-fuzzy subject))
3659          ;; Just remove the leading "Re:".
3660          (t
3661           (gnus-simplify-subject-re subject))))
3662
3663   (if (and gnus-summary-gather-exclude-subject
3664            (string-match gnus-summary-gather-exclude-subject subject))
3665       nil                               ; This article shouldn't be gathered
3666     subject))
3667
3668 (defun gnus-summary-simplify-subject-query ()
3669   "Query where the respool algorithm would put this article."
3670   (interactive)
3671   (gnus-summary-select-article)
3672   (message "%s"
3673            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3674
3675 (defun gnus-gather-threads-by-subject (threads)
3676   "Gather threads by looking at Subject headers."
3677   (if (not gnus-summary-make-false-root)
3678       threads
3679     (let ((hashtb (gnus-make-hashtable 1024))
3680           (prev threads)
3681           (result threads)
3682           subject hthread whole-subject)
3683       (while threads
3684         (setq subject (gnus-general-simplify-subject
3685                        (setq whole-subject (mail-header-subject
3686                                             (caar threads)))))
3687         (when subject
3688           (if (setq hthread (gnus-gethash subject hashtb))
3689               (progn
3690                 ;; We enter a dummy root into the thread, if we
3691                 ;; haven't done that already.
3692                 (unless (stringp (caar hthread))
3693                   (setcar hthread (list whole-subject (car hthread))))
3694                 ;; We add this new gathered thread to this gathered
3695                 ;; thread.
3696                 (setcdr (car hthread)
3697                         (nconc (cdar hthread) (list (car threads))))
3698                 ;; Remove it from the list of threads.
3699                 (setcdr prev (cdr threads))
3700                 (setq threads prev))
3701             ;; Enter this thread into the hash table.
3702             (gnus-sethash subject
3703                           (if gnus-summary-make-false-root-always
3704                               (progn
3705                                 ;; If you want a dummy root above all
3706                                 ;; threads...
3707                                 (setcar threads (list whole-subject
3708                                                       (car threads)))
3709                                 threads)
3710                             threads)
3711                           hashtb)))
3712         (setq prev threads)
3713         (setq threads (cdr threads)))
3714       result)))
3715
3716 (defun gnus-gather-threads-by-references (threads)
3717   "Gather threads by looking at References headers."
3718   (let ((idhashtb (gnus-make-hashtable 1024))
3719         (thhashtb (gnus-make-hashtable 1024))
3720         (prev threads)
3721         (result threads)
3722         ids references id gthread gid entered ref)
3723     (while threads
3724       (when (setq references (mail-header-references (caar threads)))
3725         (setq id (mail-header-id (caar threads))
3726               ids (inline (gnus-split-references references))
3727               entered nil)
3728         (while (setq ref (pop ids))
3729           (setq ids (delete ref ids))
3730           (if (not (setq gid (gnus-gethash ref idhashtb)))
3731               (progn
3732                 (gnus-sethash ref id idhashtb)
3733                 (gnus-sethash id threads thhashtb))
3734             (setq gthread (gnus-gethash gid thhashtb))
3735             (unless entered
3736               ;; We enter a dummy root into the thread, if we
3737               ;; haven't done that already.
3738               (unless (stringp (caar gthread))
3739                 (setcar gthread (list (mail-header-subject (caar gthread))
3740                                       (car gthread))))
3741               ;; We add this new gathered thread to this gathered
3742               ;; thread.
3743               (setcdr (car gthread)
3744                       (nconc (cdar gthread) (list (car threads)))))
3745             ;; Add it into the thread hash table.
3746             (gnus-sethash id gthread thhashtb)
3747             (setq entered t)
3748             ;; Remove it from the list of threads.
3749             (setcdr prev (cdr threads))
3750             (setq threads prev))))
3751       (setq prev threads)
3752       (setq threads (cdr threads)))
3753     result))
3754
3755 (defun gnus-sort-gathered-threads (threads)
3756   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3757   (let ((result threads))
3758     (while threads
3759       (when (stringp (caar threads))
3760         (setcdr (car threads)
3761                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3762       (setq threads (cdr threads)))
3763     result))
3764
3765 (defun gnus-thread-loop-p (root thread)
3766   "Say whether ROOT is in THREAD."
3767   (let ((stack (list thread))
3768         (infloop 0)
3769         th)
3770     (while (setq thread (pop stack))
3771       (setq th (cdr thread))
3772       (while (and th
3773                   (not (eq (caar th) root)))
3774         (pop th))
3775       (if th
3776           ;; We have found a loop.
3777           (let (ref-dep)
3778             (setcdr thread (delq (car th) (cdr thread)))
3779             (if (boundp (setq ref-dep (intern "none"
3780                                               gnus-newsgroup-dependencies)))
3781                 (setcdr (symbol-value ref-dep)
3782                         (nconc (cdr (symbol-value ref-dep))
3783                                (list (car th))))
3784               (set ref-dep (list nil (car th))))
3785             (setq infloop 1
3786                   stack nil))
3787         ;; Push all the subthreads onto the stack.
3788         (push (cdr thread) stack)))
3789     infloop))
3790
3791 (defun gnus-make-threads ()
3792   "Go through the dependency hashtb and find the roots.  Return all threads."
3793   (let (threads)
3794     (while (catch 'infloop
3795              (mapatoms
3796               (lambda (refs)
3797                 ;; Deal with self-referencing References loops.
3798                 (when (and (car (symbol-value refs))
3799                            (not (zerop
3800                                  (apply
3801                                   '+
3802                                   (mapcar
3803                                    (lambda (thread)
3804                                      (gnus-thread-loop-p
3805                                       (car (symbol-value refs)) thread))
3806                                    (cdr (symbol-value refs)))))))
3807                   (setq threads nil)
3808                   (throw 'infloop t))
3809                 (unless (car (symbol-value refs))
3810                   ;; These threads do not refer back to any other articles,
3811                   ;; so they're roots.
3812                   (setq threads (append (cdr (symbol-value refs)) threads))))
3813               gnus-newsgroup-dependencies)))
3814     threads))
3815
3816 ;; Build the thread tree.
3817 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3818   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3819
3820 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3821 if it was already present.
3822
3823 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3824 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3825 Message-IDs will be renamed to a unique Message-ID before being
3826 entered.
3827
3828 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3829   (let* ((id (mail-header-id header))
3830          (id-dep (and id (intern id dependencies)))
3831          parent-id ref ref-dep ref-header replaced)
3832     ;; Enter this `header' in the `dependencies' table.
3833     (cond
3834      ((not id-dep)
3835       (setq header nil))
3836      ;; The first two cases do the normal part: enter a new `header'
3837      ;; in the `dependencies' table.
3838      ((not (boundp id-dep))
3839       (set id-dep (list header)))
3840      ((null (car (symbol-value id-dep)))
3841       (setcar (symbol-value id-dep) header))
3842
3843      ;; From here the `header' was already present in the
3844      ;; `dependencies' table.
3845      (force-new
3846       ;; Overrides an existing entry;
3847       ;; just set the header part of the entry.
3848       (setcar (symbol-value id-dep) header)
3849       (setq replaced t))
3850
3851      ;; Renames the existing `header' to a unique Message-ID.
3852      ((not gnus-summary-ignore-duplicates)
3853       ;; An article with this Message-ID has already been seen.
3854       ;; We rename the Message-ID.
3855       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3856            (list header))
3857       (mail-header-set-id header id))
3858
3859      ;; The last case ignores an existing entry, except it adds any
3860      ;; additional Xrefs (in case the two articles came from different
3861      ;; servers.
3862      ;; Also sets `header' to `nil' meaning that the `dependencies'
3863      ;; table was *not* modified.
3864      (t
3865       (mail-header-set-xref
3866        (car (symbol-value id-dep))
3867        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3868                    "")
3869                (or (mail-header-xref header) "")))
3870       (setq header nil)))
3871
3872     (when (and header (not replaced))
3873       ;; First check that we are not creating a References loop.
3874       (setq parent-id (gnus-parent-id (mail-header-references header)))
3875       (setq ref parent-id)
3876       (while (and ref
3877                   (setq ref-dep (intern-soft ref dependencies))
3878                   (boundp ref-dep)
3879                   (setq ref-header (car (symbol-value ref-dep))))
3880         (if (string= id ref)
3881             ;; Yuk!  This is a reference loop.  Make the article be a
3882             ;; root article.
3883             (progn
3884               (mail-header-set-references (car (symbol-value id-dep)) "none")
3885               (setq ref nil)
3886               (setq parent-id nil))
3887           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3888       (setq ref-dep (intern (or parent-id "none") dependencies))
3889       (if (boundp ref-dep)
3890           (setcdr (symbol-value ref-dep)
3891                   (nconc (cdr (symbol-value ref-dep))
3892                          (list (symbol-value id-dep))))
3893         (set ref-dep (list nil (symbol-value id-dep)))))
3894     header))
3895
3896 (defun gnus-extract-message-id-from-in-reply-to (string)
3897   (if (string-match "<[^>]+>" string)
3898       (substring string (match-beginning 0) (match-end 0))
3899     nil))
3900
3901 (defun gnus-build-sparse-threads ()
3902   (let ((headers gnus-newsgroup-headers)
3903         (mail-parse-charset gnus-newsgroup-charset)
3904         (gnus-summary-ignore-duplicates t)
3905         header references generation relations
3906         subject child end new-child date)
3907     ;; First we create an alist of generations/relations, where
3908     ;; generations is how much we trust the relation, and the relation
3909     ;; is parent/child.
3910     (gnus-message 7 "Making sparse threads...")
3911     (save-excursion
3912       (nnheader-set-temp-buffer " *gnus sparse threads*")
3913       (while (setq header (pop headers))
3914         (when (and (setq references (mail-header-references header))
3915                    (not (string= references "")))
3916           (insert references)
3917           (setq child (mail-header-id header)
3918                 subject (mail-header-subject header)
3919                 date (mail-header-date header)
3920                 generation 0)
3921           (while (search-backward ">" nil t)
3922             (setq end (1+ (point)))
3923             (when (search-backward "<" nil t)
3924               (setq new-child (buffer-substring (point) end))
3925               (push (list (incf generation)
3926                           child (setq child new-child)
3927                           subject date)
3928                     relations)))
3929           (when child
3930             (push (list (1+ generation) child nil subject) relations))
3931           (erase-buffer)))
3932       (kill-buffer (current-buffer)))
3933     ;; Sort over trustworthiness.
3934     (mapcar
3935      (lambda (relation)
3936        (when (gnus-dependencies-add-header
3937               (make-full-mail-header-from-decoded-header
3938                gnus-reffed-article-number
3939                (nth 3 relation) "" (or (nth 4 relation) "")
3940                (nth 1 relation)
3941                (or (nth 2 relation) "") 0 0 "")
3942               gnus-newsgroup-dependencies nil)
3943          (push gnus-reffed-article-number gnus-newsgroup-limit)
3944          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3945          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3946                gnus-newsgroup-reads)
3947          (decf gnus-reffed-article-number)))
3948      (sort relations 'car-less-than-car))
3949     (gnus-message 7 "Making sparse threads...done")))
3950
3951 (defun gnus-build-old-threads ()
3952   ;; Look at all the articles that refer back to old articles, and
3953   ;; fetch the headers for the articles that aren't there.  This will
3954   ;; build complete threads - if the roots haven't been expired by the
3955   ;; server, that is.
3956   (let ((mail-parse-charset gnus-newsgroup-charset)
3957         id heads)
3958     (mapatoms
3959      (lambda (refs)
3960        (when (not (car (symbol-value refs)))
3961          (setq heads (cdr (symbol-value refs)))
3962          (while heads
3963            (if (memq (mail-header-number (caar heads))
3964                      gnus-newsgroup-dormant)
3965                (setq heads (cdr heads))
3966              (setq id (symbol-name refs))
3967              (while (and (setq id (gnus-build-get-header id))
3968                          (not (car (gnus-id-to-thread id)))))
3969              (setq heads nil)))))
3970      gnus-newsgroup-dependencies)))
3971
3972 ;; This function has to be called with point after the article number
3973 ;; on the beginning of the line.
3974 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3975   (let ((eol (gnus-point-at-eol))
3976         (buffer (current-buffer))
3977         header references in-reply-to)
3978
3979     ;; overview: [num subject from date id refs chars lines misc]
3980     (unwind-protect
3981         (progn
3982           (narrow-to-region (point) eol)
3983           (unless (eobp)
3984             (forward-char))
3985
3986           (setq header
3987                 (make-full-mail-header
3988                  number                         ; number
3989                  (nnheader-nov-field)           ; subject
3990                  (nnheader-nov-field)           ; from
3991                  (nnheader-nov-field)           ; date
3992                  (nnheader-nov-read-message-id) ; id
3993                  (nnheader-nov-field)           ; refs
3994                  (nnheader-nov-read-integer)    ; chars
3995                  (nnheader-nov-read-integer)    ; lines
3996                  (unless (eobp)
3997                    (if (looking-at "Xref: ")
3998                        (goto-char (match-end 0)))
3999                    (nnheader-nov-field))        ; Xref
4000                  (nnheader-nov-parse-extra))))  ; extra
4001
4002       (widen))
4003
4004     (when (and (string= references "")
4005                (setq in-reply-to (mail-header-extra header))
4006                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4007       (mail-header-set-references
4008        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4009
4010     (when gnus-alter-header-function
4011       (funcall gnus-alter-header-function header))
4012     (gnus-dependencies-add-header header dependencies force-new)))
4013
4014 (defun gnus-build-get-header (id)
4015   "Look through the buffer of NOV lines and find the header to ID.
4016 Enter this line into the dependencies hash table, and return
4017 the id of the parent article (if any)."
4018   (let ((deps gnus-newsgroup-dependencies)
4019         found header)
4020     (prog1
4021         (save-excursion
4022           (set-buffer nntp-server-buffer)
4023           (let ((case-fold-search nil))
4024             (goto-char (point-min))
4025             (while (and (not found)
4026                         (search-forward id nil t))
4027               (beginning-of-line)
4028               (setq found (looking-at
4029                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4030                                    (regexp-quote id))))
4031               (or found (beginning-of-line 2)))
4032             (when found
4033               (beginning-of-line)
4034               (and
4035                (setq header (gnus-nov-parse-line
4036                              (read (current-buffer)) deps))
4037                (gnus-parent-id (mail-header-references header))))))
4038       (when header
4039         (let ((number (mail-header-number header)))
4040           (push number gnus-newsgroup-limit)
4041           (push header gnus-newsgroup-headers)
4042           (if (memq number gnus-newsgroup-unselected)
4043               (progn
4044                 (setq gnus-newsgroup-unreads
4045                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4046                                                number))
4047                 (setq gnus-newsgroup-unselected
4048                       (delq number gnus-newsgroup-unselected)))
4049             (push number gnus-newsgroup-ancient)))))))
4050
4051 (defun gnus-build-all-threads ()
4052   "Read all the headers."
4053   (let ((gnus-summary-ignore-duplicates t)
4054         (mail-parse-charset gnus-newsgroup-charset)
4055         (dependencies gnus-newsgroup-dependencies)
4056         header article)
4057     (save-excursion
4058       (set-buffer nntp-server-buffer)
4059       (let ((case-fold-search nil))
4060         (goto-char (point-min))
4061         (while (not (eobp))
4062           (ignore-errors
4063             (setq article (read (current-buffer))
4064                   header (gnus-nov-parse-line article dependencies)))
4065           (when header
4066             (save-excursion
4067               (set-buffer gnus-summary-buffer)
4068               (push header gnus-newsgroup-headers)
4069               (if (memq (setq article (mail-header-number header))
4070                         gnus-newsgroup-unselected)
4071                   (progn
4072                     (setq gnus-newsgroup-unreads
4073                           (gnus-add-to-sorted-list
4074                            gnus-newsgroup-unreads article))
4075                     (setq gnus-newsgroup-unselected
4076                           (delq article gnus-newsgroup-unselected)))
4077                 (push article gnus-newsgroup-ancient)))
4078             (forward-line 1)))))))
4079
4080 (defun gnus-summary-update-article-line (article header)
4081   "Update the line for ARTICLE using HEADERS."
4082   (let* ((id (mail-header-id header))
4083          (thread (gnus-id-to-thread id)))
4084     (unless thread
4085       (error "Article in no thread"))
4086     ;; Update the thread.
4087     (setcar thread header)
4088     (gnus-summary-goto-subject article)
4089     (let* ((datal (gnus-data-find-list article))
4090            (data (car datal))
4091            (buffer-read-only nil)
4092            (level (gnus-summary-thread-level)))
4093       (gnus-delete-line)
4094       (let ((inserted (- (point)
4095                          (progn
4096                            (gnus-summary-insert-line
4097                             header level nil 
4098                             (memq article gnus-newsgroup-undownloaded)
4099                             (gnus-article-mark article)
4100                             (memq article gnus-newsgroup-replied)
4101                             (memq article gnus-newsgroup-expirable)
4102                             ;; Only insert the Subject string when it's different
4103                             ;; from the previous Subject string.
4104                             (if (and
4105                                  gnus-show-threads
4106                                  (gnus-subject-equal
4107                                   (condition-case ()
4108                                       (mail-header-subject
4109                                        (gnus-data-header
4110                                         (cadr
4111                                          (gnus-data-find-list
4112                                           article
4113                                           (gnus-data-list t)))))
4114                                     ;; Error on the side of excessive subjects.
4115                                     (error ""))
4116                                   (mail-header-subject header)))
4117                                 ""
4118                               (mail-header-subject header))
4119                             nil (cdr (assq article gnus-newsgroup-scored))
4120                             (memq article gnus-newsgroup-processable))
4121                            (point)))))
4122         (when (cdr datal)
4123           (gnus-data-update-list
4124            (cdr datal) 
4125            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4126
4127 (defun gnus-summary-update-article (article &optional iheader)
4128   "Update ARTICLE in the summary buffer."
4129   (set-buffer gnus-summary-buffer)
4130   (let* ((header (gnus-summary-article-header article))
4131          (id (mail-header-id header))
4132          (data (gnus-data-find article))
4133          (thread (gnus-id-to-thread id))
4134          (references (mail-header-references header))
4135          (parent
4136           (gnus-id-to-thread
4137            (or (gnus-parent-id
4138                 (when (and references
4139                            (not (equal "" references)))
4140                   references))
4141                "none")))
4142          (buffer-read-only nil)
4143          (old (car thread)))
4144     (when thread
4145       (unless iheader
4146         (setcar thread nil)
4147         (when parent
4148           (delq thread parent)))
4149       (if (gnus-summary-insert-subject id header)
4150           ;; Set the (possibly) new article number in the data structure.
4151           (gnus-data-set-number data (gnus-id-to-article id))
4152         (setcar thread old)
4153         nil))))
4154
4155 (defun gnus-rebuild-thread (id &optional line)
4156   "Rebuild the thread containing ID.
4157 If LINE, insert the rebuilt thread starting on line LINE."
4158   (let ((buffer-read-only nil)
4159         old-pos current thread data)
4160     (if (not gnus-show-threads)
4161         (setq thread (list (car (gnus-id-to-thread id))))
4162       ;; Get the thread this article is part of.
4163       (setq thread (gnus-remove-thread id)))
4164     (setq old-pos (gnus-point-at-bol))
4165     (setq current (save-excursion
4166                     (and (re-search-backward "[\r\n]" nil t)
4167                          (gnus-summary-article-number))))
4168     ;; If this is a gathered thread, we have to go some re-gathering.
4169     (when (stringp (car thread))
4170       (let ((subject (car thread))
4171             roots thr)
4172         (setq thread (cdr thread))
4173         (while thread
4174           (unless (memq (setq thr (gnus-id-to-thread
4175                                    (gnus-root-id
4176                                     (mail-header-id (caar thread)))))
4177                         roots)
4178             (push thr roots))
4179           (setq thread (cdr thread)))
4180         ;; We now have all (unique) roots.
4181         (if (= (length roots) 1)
4182             ;; All the loose roots are now one solid root.
4183             (setq thread (car roots))
4184           (setq thread (cons subject (gnus-sort-threads roots))))))
4185     (let (threads)
4186       ;; We then insert this thread into the summary buffer.
4187       (when line
4188         (goto-char (point-min))
4189         (forward-line (1- line)))
4190       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4191         (if gnus-show-threads
4192             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4193           (gnus-summary-prepare-unthreaded thread))
4194         (setq data (nreverse gnus-newsgroup-data))
4195         (setq threads gnus-newsgroup-threads))
4196       ;; We splice the new data into the data structure.
4197       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4198       ;;!!! then we want to insert at the beginning of the buffer.
4199       ;;!!! That happens to be true with Gnus now, but that may
4200       ;;!!! change in the future.  Perhaps.
4201       (gnus-data-enter-list
4202        (if line nil current) data (- (point) old-pos))
4203       (setq gnus-newsgroup-threads
4204             (nconc threads gnus-newsgroup-threads))
4205       (gnus-data-compute-positions))))
4206
4207 (defun gnus-number-to-header (number)
4208   "Return the header for article NUMBER."
4209   (let ((headers gnus-newsgroup-headers))
4210     (while (and headers
4211                 (not (= number (mail-header-number (car headers)))))
4212       (pop headers))
4213     (when headers
4214       (car headers))))
4215
4216 (defun gnus-parent-headers (in-headers &optional generation)
4217   "Return the headers of the GENERATIONeth parent of HEADERS."
4218   (unless generation
4219     (setq generation 1))
4220   (let ((parent t)
4221         (headers in-headers)
4222         references)
4223     (while (and parent
4224                 (not (zerop generation))
4225                 (setq references (mail-header-references headers)))
4226       (setq headers (if (and references
4227                              (setq parent (gnus-parent-id references)))
4228                         (car (gnus-id-to-thread parent))
4229                       nil))
4230       (decf generation))
4231     (and (not (eq headers in-headers))
4232          headers)))
4233
4234 (defun gnus-id-to-thread (id)
4235   "Return the (sub-)thread where ID appears."
4236   (gnus-gethash id gnus-newsgroup-dependencies))
4237
4238 (defun gnus-id-to-article (id)
4239   "Return the article number of ID."
4240   (let ((thread (gnus-id-to-thread id)))
4241     (when (and thread
4242                (car thread))
4243       (mail-header-number (car thread)))))
4244
4245 (defun gnus-id-to-header (id)
4246   "Return the article headers of ID."
4247   (car (gnus-id-to-thread id)))
4248
4249 (defun gnus-article-displayed-root-p (article)
4250   "Say whether ARTICLE is a root(ish) article."
4251   (let ((level (gnus-summary-thread-level article))
4252         (refs (mail-header-references  (gnus-summary-article-header article)))
4253         particle)
4254     (cond
4255      ((null level) nil)
4256      ((zerop level) t)
4257      ((null refs) t)
4258      ((null (gnus-parent-id refs)) t)
4259      ((and (= 1 level)
4260            (null (setq particle (gnus-id-to-article
4261                                  (gnus-parent-id refs))))
4262            (null (gnus-summary-thread-level particle)))))))
4263
4264 (defun gnus-root-id (id)
4265   "Return the id of the root of the thread where ID appears."
4266   (let (last-id prev)
4267     (while (and id (setq prev (car (gnus-id-to-thread id))))
4268       (setq last-id id
4269             id (gnus-parent-id (mail-header-references prev))))
4270     last-id))
4271
4272 (defun gnus-articles-in-thread (thread)
4273   "Return the list of articles in THREAD."
4274   (cons (mail-header-number (car thread))
4275         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4276
4277 (defun gnus-remove-thread (id &optional dont-remove)
4278   "Remove the thread that has ID in it."
4279   (let (headers thread last-id)
4280     ;; First go up in this thread until we find the root.
4281     (setq last-id (gnus-root-id id)
4282           headers (message-flatten-list (gnus-id-to-thread last-id)))
4283     ;; We have now found the real root of this thread.  It might have
4284     ;; been gathered into some loose thread, so we have to search
4285     ;; through the threads to find the thread we wanted.
4286     (let ((threads gnus-newsgroup-threads)
4287           sub)
4288       (while threads
4289         (setq sub (car threads))
4290         (if (stringp (car sub))
4291             ;; This is a gathered thread, so we look at the roots
4292             ;; below it to find whether this article is in this
4293             ;; gathered root.
4294             (progn
4295               (setq sub (cdr sub))
4296               (while sub
4297                 (when (member (caar sub) headers)
4298                   (setq thread (car threads)
4299                         threads nil
4300                         sub nil))
4301                 (setq sub (cdr sub))))
4302           ;; It's an ordinary thread, so we check it.
4303           (when (eq (car sub) (car headers))
4304             (setq thread sub
4305                   threads nil)))
4306         (setq threads (cdr threads)))
4307       ;; If this article is in no thread, then it's a root.
4308       (if thread
4309           (unless dont-remove
4310             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4311         (setq thread (gnus-id-to-thread last-id)))
4312       (when thread
4313         (prog1
4314             thread                      ; We return this thread.
4315           (unless dont-remove
4316             (if (stringp (car thread))
4317                 (progn
4318                   ;; If we use dummy roots, then we have to remove the
4319                   ;; dummy root as well.
4320                   (when (eq gnus-summary-make-false-root 'dummy)
4321                     ;; We go to the dummy root by going to
4322                     ;; the first sub-"thread", and then one line up.
4323                     (gnus-summary-goto-article
4324                      (mail-header-number (caadr thread)))
4325                     (forward-line -1)
4326                     (gnus-delete-line)
4327                     (gnus-data-compute-positions))
4328                   (setq thread (cdr thread))
4329                   (while thread
4330                     (gnus-remove-thread-1 (car thread))
4331                     (setq thread (cdr thread))))
4332               (gnus-remove-thread-1 thread))))))))
4333
4334 (defun gnus-remove-thread-1 (thread)
4335   "Remove the thread THREAD recursively."
4336   (let ((number (mail-header-number (pop thread)))
4337         d)
4338     (setq thread (reverse thread))
4339     (while thread
4340       (gnus-remove-thread-1 (pop thread)))
4341     (when (setq d (gnus-data-find number))
4342       (goto-char (gnus-data-pos d))
4343       (gnus-summary-show-thread)
4344       (gnus-data-remove
4345        number
4346        (- (gnus-point-at-bol)
4347           (prog1
4348               (1+ (gnus-point-at-eol))
4349             (gnus-delete-line)))))))
4350
4351 (defun gnus-sort-threads-1 (threads func)
4352   (sort (mapcar (lambda (thread)
4353                   (cons (car thread)
4354                         (and (cdr thread)
4355                              (gnus-sort-threads-1 (cdr thread) func))))
4356                 threads) func))
4357
4358 (defun gnus-sort-threads (threads)
4359   "Sort THREADS."
4360   (if (not gnus-thread-sort-functions)
4361       threads
4362     (gnus-message 8 "Sorting threads...")
4363     (let ((max-lisp-eval-depth 5000))
4364       (prog1 (gnus-sort-threads-1
4365          threads
4366          (gnus-make-sort-function gnus-thread-sort-functions))
4367         (gnus-message 8 "Sorting threads...done")))))
4368
4369 (defun gnus-sort-articles (articles)
4370   "Sort ARTICLES."
4371   (when gnus-article-sort-functions
4372     (gnus-message 7 "Sorting articles...")
4373     (prog1
4374         (setq gnus-newsgroup-headers
4375               (sort articles (gnus-make-sort-function
4376                               gnus-article-sort-functions)))
4377       (gnus-message 7 "Sorting articles...done"))))
4378
4379 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4380 (defmacro gnus-thread-header (thread)
4381   "Return header of first article in THREAD.
4382 Note that THREAD must never, ever be anything else than a variable -
4383 using some other form will lead to serious barfage."
4384   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4385   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4386   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4387         (vector thread) 2))
4388
4389 (defsubst gnus-article-sort-by-number (h1 h2)
4390   "Sort articles by article number."
4391   (< (mail-header-number h1)
4392      (mail-header-number h2)))
4393
4394 (defun gnus-thread-sort-by-number (h1 h2)
4395   "Sort threads by root article number."
4396   (gnus-article-sort-by-number
4397    (gnus-thread-header h1) (gnus-thread-header h2)))
4398
4399 (defsubst gnus-article-sort-by-random (h1 h2)
4400   "Sort articles by article number."
4401   (zerop (random 2)))
4402
4403 (defun gnus-thread-sort-by-random (h1 h2)
4404   "Sort threads by root article number."
4405   (gnus-article-sort-by-random
4406    (gnus-thread-header h1) (gnus-thread-header h2)))
4407
4408 (defsubst gnus-article-sort-by-lines (h1 h2)
4409   "Sort articles by article Lines header."
4410   (< (mail-header-lines h1)
4411      (mail-header-lines h2)))
4412
4413 (defun gnus-thread-sort-by-lines (h1 h2)
4414   "Sort threads by root article Lines header."
4415   (gnus-article-sort-by-lines
4416    (gnus-thread-header h1) (gnus-thread-header h2)))
4417
4418 (defsubst gnus-article-sort-by-chars (h1 h2)
4419   "Sort articles by octet length."
4420   (< (mail-header-chars h1)
4421      (mail-header-chars h2)))
4422
4423 (defun gnus-thread-sort-by-chars (h1 h2)
4424   "Sort threads by root article octet length."
4425   (gnus-article-sort-by-chars
4426    (gnus-thread-header h1) (gnus-thread-header h2)))
4427
4428 (defsubst gnus-article-sort-by-author (h1 h2)
4429   "Sort articles by root author."
4430   (string-lessp
4431    (let ((addr (car (mime-entity-read-field h1 'From))))
4432      (or (std11-full-name-string addr)
4433          (std11-address-string addr)
4434          ""))
4435    (let ((addr (car (mime-entity-read-field h2 'From))))
4436      (or (std11-full-name-string addr)
4437          (std11-address-string addr)
4438          ""))
4439    ))
4440
4441 (defun gnus-thread-sort-by-author (h1 h2)
4442   "Sort threads by root author."
4443   (gnus-article-sort-by-author
4444    (gnus-thread-header h1)  (gnus-thread-header h2)))
4445
4446 (defsubst gnus-article-sort-by-subject (h1 h2)
4447   "Sort articles by root subject."
4448   (string-lessp
4449    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4450    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4451
4452 (defun gnus-thread-sort-by-subject (h1 h2)
4453   "Sort threads by root subject."
4454   (gnus-article-sort-by-subject
4455    (gnus-thread-header h1) (gnus-thread-header h2)))
4456
4457 (defsubst gnus-article-sort-by-date (h1 h2)
4458   "Sort articles by root article date."
4459   (time-less-p
4460    (gnus-date-get-time (mail-header-date h1))
4461    (gnus-date-get-time (mail-header-date h2))))
4462
4463 (defun gnus-thread-sort-by-date (h1 h2)
4464   "Sort threads by root article date."
4465   (gnus-article-sort-by-date
4466    (gnus-thread-header h1) (gnus-thread-header h2)))
4467
4468 (defsubst gnus-article-sort-by-score (h1 h2)
4469   "Sort articles by root article score.
4470 Unscored articles will be counted as having a score of zero."
4471   (> (or (cdr (assq (mail-header-number h1)
4472                     gnus-newsgroup-scored))
4473          gnus-summary-default-score 0)
4474      (or (cdr (assq (mail-header-number h2)
4475                     gnus-newsgroup-scored))
4476          gnus-summary-default-score 0)))
4477
4478 (defun gnus-thread-sort-by-score (h1 h2)
4479   "Sort threads by root article score."
4480   (gnus-article-sort-by-score
4481    (gnus-thread-header h1) (gnus-thread-header h2)))
4482
4483 (defun gnus-thread-sort-by-total-score (h1 h2)
4484   "Sort threads by the sum of all scores in the thread.
4485 Unscored articles will be counted as having a score of zero."
4486   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4487
4488 (defun gnus-thread-total-score (thread)
4489   ;; This function find the total score of THREAD.
4490   (cond
4491    ((null thread)
4492     0)
4493    ((consp thread)
4494     (if (stringp (car thread))
4495         (apply gnus-thread-score-function 0
4496                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4497       (gnus-thread-total-score-1 thread)))
4498    (t
4499     (gnus-thread-total-score-1 (list thread)))))
4500
4501 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4502   "Sort threads such that the thread with the most recently arrived article comes first."
4503   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4504
4505 (defun gnus-thread-highest-number (thread)
4506   "Return the highest article number in THREAD."
4507   (apply 'max (mapcar (lambda (header)
4508                         (mail-header-number header))
4509                       (message-flatten-list thread))))
4510
4511 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4512   "Sort threads such that the thread with the most recently dated article comes first."
4513   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4514
4515 (defun gnus-thread-latest-date (thread)
4516   "Return the highest article date in THREAD."
4517   (let ((previous-time 0))
4518     (apply 'max
4519            (mapcar
4520             (lambda (header)
4521               (setq previous-time
4522                     (time-to-seconds
4523                      (condition-case ()
4524                          (mail-header-parse-date (mail-header-date header))
4525                        (error previous-time)))))
4526             (sort
4527              (message-flatten-list thread)
4528              (lambda (h1 h2)
4529                (< (mail-header-number h1)
4530                   (mail-header-number h2))))))))
4531
4532 (defun gnus-thread-total-score-1 (root)
4533   ;; This function find the total score of the thread below ROOT.
4534   (setq root (car root))
4535   (apply gnus-thread-score-function
4536          (or (append
4537               (mapcar 'gnus-thread-total-score
4538                       (cdr (gnus-id-to-thread (mail-header-id root))))
4539               (when (> (mail-header-number root) 0)
4540                 (list (or (cdr (assq (mail-header-number root)
4541                                      gnus-newsgroup-scored))
4542                           gnus-summary-default-score 0))))
4543              (list gnus-summary-default-score)
4544              '(0))))
4545
4546 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4547 (defvar gnus-tmp-prev-subject nil)
4548 (defvar gnus-tmp-false-parent nil)
4549 (defvar gnus-tmp-root-expunged nil)
4550 (defvar gnus-tmp-dummy-line nil)
4551
4552 (eval-when-compile (defvar gnus-tmp-header))
4553 (defun gnus-extra-header (type &optional header)
4554   "Return the extra header of TYPE."
4555   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4556       ""))
4557
4558 (defvar gnus-tmp-thread-tree-header-string "")
4559
4560 (defcustom gnus-sum-thread-tree-root "> "
4561   "With %B spec, used for the root of a thread.
4562 If nil, use subject instead."
4563   :type 'string
4564   :group 'gnus-thread)
4565 (defcustom gnus-sum-thread-tree-single-indent ""
4566   "With %B spec, used for a thread with just one message.
4567 If nil, use subject instead."
4568   :type 'string
4569   :group 'gnus-thread)
4570 (defcustom gnus-sum-thread-tree-vertical "| "
4571   "With %B spec, used for drawing a vertical line."
4572   :type 'string
4573   :group 'gnus-thread)
4574 (defcustom gnus-sum-thread-tree-indent "  "
4575   "With %B spec, used for indenting."
4576   :type 'string
4577   :group 'gnus-thread)
4578 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4579   "With %B spec, used for a leaf with brothers."
4580   :type 'string
4581   :group 'gnus-thread)
4582 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4583   "With %B spec, used for a leaf without brothers."
4584   :type 'string
4585   :group 'gnus-thread)
4586
4587 (defun gnus-summary-prepare-threads (threads)
4588   "Prepare summary buffer from THREADS and indentation LEVEL.
4589 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4590 or a straight list of headers."
4591   (gnus-message 7 "Generating summary...")
4592
4593   (setq gnus-newsgroup-threads threads)
4594   (beginning-of-line)
4595
4596   (let ((gnus-tmp-level 0)
4597         (default-score (or gnus-summary-default-score 0))
4598         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4599         (building-line-count gnus-summary-display-while-building)
4600         (building-count (integerp gnus-summary-display-while-building))
4601         thread number subject stack state gnus-tmp-gathered beg-match
4602         new-roots gnus-tmp-new-adopts thread-end simp-subject
4603         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4604         gnus-tmp-replied gnus-tmp-subject-or-nil
4605         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4606         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4607         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4608         tree-stack)
4609
4610     (setq gnus-tmp-prev-subject nil
4611           gnus-tmp-thread-tree-header-string "")
4612
4613     (if (vectorp (car threads))
4614         ;; If this is a straight (sic) list of headers, then a
4615         ;; threaded summary display isn't required, so we just create
4616         ;; an unthreaded one.
4617         (gnus-summary-prepare-unthreaded threads)
4618
4619       ;; Do the threaded display.
4620
4621       (if gnus-summary-display-while-building
4622           (switch-to-buffer (buffer-name)))
4623       (while (or threads stack gnus-tmp-new-adopts new-roots)
4624
4625         (if (and (= gnus-tmp-level 0)
4626                  (or (not stack)
4627                      (= (caar stack) 0))
4628                  (not gnus-tmp-false-parent)
4629                  (or gnus-tmp-new-adopts new-roots))
4630             (if gnus-tmp-new-adopts
4631                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4632                       thread (list (car gnus-tmp-new-adopts))
4633                       gnus-tmp-header (caar thread)
4634                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4635               (when new-roots
4636                 (setq thread (list (car new-roots))
4637                       gnus-tmp-header (caar thread)
4638                       new-roots (cdr new-roots))))
4639
4640           (if threads
4641               ;; If there are some threads, we do them before the
4642               ;; threads on the stack.
4643               (setq thread threads
4644                     gnus-tmp-header (caar thread))
4645             ;; There were no current threads, so we pop something off
4646             ;; the stack.
4647             (setq state (car stack)
4648                   gnus-tmp-level (car state)
4649                   tree-stack (cadr state)
4650                   thread (caddr state)
4651                   stack (cdr stack)
4652                   gnus-tmp-header (caar thread))))
4653
4654         (setq gnus-tmp-false-parent nil)
4655         (setq gnus-tmp-root-expunged nil)
4656         (setq thread-end nil)
4657
4658         (if (stringp gnus-tmp-header)
4659             ;; The header is a dummy root.
4660             (cond
4661              ((eq gnus-summary-make-false-root 'adopt)
4662               ;; We let the first article adopt the rest.
4663               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4664                                                (cddar thread)))
4665               (setq gnus-tmp-gathered
4666                     (nconc (mapcar
4667                             (lambda (h) (mail-header-number (car h)))
4668                             (cddar thread))
4669                            gnus-tmp-gathered))
4670               (setq thread (cons (list (caar thread)
4671                                        (cadar thread))
4672                                  (cdr thread)))
4673               (setq gnus-tmp-level -1
4674                     gnus-tmp-false-parent t))
4675              ((eq gnus-summary-make-false-root 'empty)
4676               ;; We print adopted articles with empty subject fields.
4677               (setq gnus-tmp-gathered
4678                     (nconc (mapcar
4679                             (lambda (h) (mail-header-number (car h)))
4680                             (cddar thread))
4681                            gnus-tmp-gathered))
4682               (setq gnus-tmp-level -1))
4683              ((eq gnus-summary-make-false-root 'dummy)
4684               ;; We remember that we probably want to output a dummy
4685               ;; root.
4686               (setq gnus-tmp-dummy-line gnus-tmp-header)
4687               (setq gnus-tmp-prev-subject gnus-tmp-header))
4688              (t
4689               ;; We do not make a root for the gathered
4690               ;; sub-threads at all.
4691               (setq gnus-tmp-level -1)))
4692
4693           (setq number (mail-header-number gnus-tmp-header)
4694                 subject (mail-header-subject gnus-tmp-header)
4695                 simp-subject (gnus-simplify-subject-fully subject))
4696
4697           (cond
4698            ;; If the thread has changed subject, we might want to make
4699            ;; this subthread into a root.
4700            ((and (null gnus-thread-ignore-subject)
4701                  (not (zerop gnus-tmp-level))
4702                  gnus-tmp-prev-subject
4703                  (not (string= gnus-tmp-prev-subject simp-subject)))
4704             (setq new-roots (nconc new-roots (list (car thread)))
4705                   thread-end t
4706                   gnus-tmp-header nil))
4707            ;; If the article lies outside the current limit,
4708            ;; then we do not display it.
4709            ((not (memq number gnus-newsgroup-limit))
4710             (setq gnus-tmp-gathered
4711                   (nconc (mapcar
4712                           (lambda (h) (mail-header-number (car h)))
4713                           (cdar thread))
4714                          gnus-tmp-gathered))
4715             (setq gnus-tmp-new-adopts (if (cdar thread)
4716                                           (append gnus-tmp-new-adopts
4717                                                   (cdar thread))
4718                                         gnus-tmp-new-adopts)
4719                   thread-end t
4720                   gnus-tmp-header nil)
4721             (when (zerop gnus-tmp-level)
4722               (setq gnus-tmp-root-expunged t)))
4723            ;; Perhaps this article is to be marked as read?
4724            ((and gnus-summary-mark-below
4725                  (< (or (cdr (assq number gnus-newsgroup-scored))
4726                         default-score)
4727                     gnus-summary-mark-below)
4728                  ;; Don't touch sparse articles.
4729                  (not (gnus-summary-article-sparse-p number))
4730                  (not (gnus-summary-article-ancient-p number)))
4731             (setq gnus-newsgroup-unreads
4732                   (delq number gnus-newsgroup-unreads))
4733             (if gnus-newsgroup-auto-expire
4734                 (setq gnus-newsgroup-expirable
4735                       (gnus-add-to-sorted-list
4736                        gnus-newsgroup-expirable number))
4737               (push (cons number gnus-low-score-mark)
4738                     gnus-newsgroup-reads))))
4739
4740           (when gnus-tmp-header
4741             ;; We may have an old dummy line to output before this
4742             ;; article.
4743             (when (and gnus-tmp-dummy-line
4744                        (gnus-subject-equal
4745                         gnus-tmp-dummy-line
4746                         (mail-header-subject gnus-tmp-header)))
4747               (gnus-summary-insert-dummy-line
4748                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4749               (setq gnus-tmp-dummy-line nil))
4750
4751             ;; Compute the mark.
4752             (setq gnus-tmp-unread (gnus-article-mark number))
4753
4754             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4755                                   gnus-tmp-header gnus-tmp-level)
4756                   gnus-newsgroup-data)
4757
4758             ;; Actually insert the line.
4759             (setq
4760              gnus-tmp-subject-or-nil
4761              (cond
4762               ((and gnus-thread-ignore-subject
4763                     gnus-tmp-prev-subject
4764                     (not (string= gnus-tmp-prev-subject simp-subject)))
4765                subject)
4766               ((zerop gnus-tmp-level)
4767                (if (and (eq gnus-summary-make-false-root 'empty)
4768                         (memq number gnus-tmp-gathered)
4769                         gnus-tmp-prev-subject
4770                         (string= gnus-tmp-prev-subject simp-subject))
4771                    gnus-summary-same-subject
4772                  subject))
4773               (t gnus-summary-same-subject)))
4774             (if (and (eq gnus-summary-make-false-root 'adopt)
4775                      (= gnus-tmp-level 1)
4776                      (memq number gnus-tmp-gathered))
4777                 (setq gnus-tmp-opening-bracket ?\<
4778                       gnus-tmp-closing-bracket ?\>)
4779               (setq gnus-tmp-opening-bracket ?\[
4780                     gnus-tmp-closing-bracket ?\]))
4781             (setq
4782              gnus-tmp-indentation
4783              (aref gnus-thread-indent-array gnus-tmp-level)
4784              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4785              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4786                                 gnus-summary-default-score 0)
4787              gnus-tmp-score-char
4788              (if (or (null gnus-summary-default-score)
4789                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4790                          gnus-summary-zcore-fuzz))
4791                  ?\ ;;;Whitespace
4792                (if (< gnus-tmp-score gnus-summary-default-score)
4793                    gnus-score-below-mark gnus-score-over-mark))
4794              gnus-tmp-replied
4795              (cond ((memq number gnus-newsgroup-processable)
4796                     gnus-process-mark)
4797                    ((memq number gnus-newsgroup-cached)
4798                     gnus-cached-mark)
4799                    ((memq number gnus-newsgroup-replied)
4800                     gnus-replied-mark)
4801                    ((memq number gnus-newsgroup-forwarded)
4802                     gnus-forwarded-mark)
4803                    ((memq number gnus-newsgroup-saved)
4804                     gnus-saved-mark)
4805                    ((memq number gnus-newsgroup-recent)
4806                     gnus-recent-mark)
4807                    ((memq number gnus-newsgroup-unseen)
4808                     gnus-unseen-mark)
4809                    (t gnus-no-mark))
4810              gnus-tmp-downloaded
4811              (cond ((memq number gnus-newsgroup-undownloaded) 
4812                     gnus-undownloaded-mark)
4813                    (gnus-newsgroup-agentized
4814                     gnus-downloaded-mark)
4815                    (t
4816                     gnus-no-mark))
4817              gnus-tmp-from (mail-header-from gnus-tmp-header)
4818              gnus-tmp-name
4819              (cond
4820               ((string-match "<[^>]+> *$" gnus-tmp-from)
4821                (setq beg-match (match-beginning 0))
4822                (or (and (string-match "^\".+\"" gnus-tmp-from)
4823                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4824                    (substring gnus-tmp-from 0 beg-match)))
4825               ((string-match "(.+)" gnus-tmp-from)
4826                (substring gnus-tmp-from
4827                           (1+ (match-beginning 0)) (1- (match-end 0))))
4828               (t gnus-tmp-from))
4829
4830              ;; Do the %B string
4831              gnus-tmp-thread-tree-header-string
4832              (cond
4833               ((not gnus-show-threads) "")
4834               ((zerop gnus-tmp-level)
4835                (if (cdar thread)
4836                    (or gnus-sum-thread-tree-root subject)
4837                  (or gnus-sum-thread-tree-single-indent subject)))
4838               (t
4839                (concat (apply 'concat
4840                               (mapcar (lambda (item)
4841                                         (if (= item 1)
4842                                             gnus-sum-thread-tree-vertical
4843                                           gnus-sum-thread-tree-indent))
4844                                       (cdr (reverse tree-stack))))
4845                        (if (nth 1 thread)
4846                            gnus-sum-thread-tree-leaf-with-other
4847                          gnus-sum-thread-tree-single-leaf)))))
4848             (when (string= gnus-tmp-name "")
4849               (setq gnus-tmp-name gnus-tmp-from))
4850             (unless (numberp gnus-tmp-lines)
4851               (setq gnus-tmp-lines -1))
4852             (if (= gnus-tmp-lines -1)
4853                 (setq gnus-tmp-lines "?")
4854               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4855               (gnus-put-text-property
4856              (point)
4857              (progn (eval gnus-summary-line-format-spec) (point))
4858                'gnus-number number)
4859             (when gnus-visual-p
4860               (forward-line -1)
4861               (gnus-run-hooks 'gnus-summary-update-hook)
4862               (forward-line 1))
4863
4864             (setq gnus-tmp-prev-subject simp-subject)))
4865
4866         (when (nth 1 thread)
4867           (push (list (max 0 gnus-tmp-level)
4868                       (copy-list tree-stack)
4869                       (nthcdr 1 thread))
4870                 stack))
4871         (push (if (nth 1 thread) 1 0) tree-stack)
4872         (incf gnus-tmp-level)
4873         (setq threads (if thread-end nil (cdar thread)))
4874         (if gnus-summary-display-while-building
4875             (if building-count
4876                 (progn
4877                   ;; use a set frequency
4878                   (setq building-line-count (1- building-line-count))
4879                   (when (= building-line-count 0)
4880                     (sit-for 0)
4881                     (setq building-line-count
4882                           gnus-summary-display-while-building)))
4883               ;; always
4884               (sit-for 0)))
4885         (unless threads
4886           (setq gnus-tmp-level 0)))))
4887   (gnus-message 7 "Generating summary...done"))
4888
4889 (defun gnus-summary-prepare-unthreaded (headers)
4890   "Generate an unthreaded summary buffer based on HEADERS."
4891   (let (header number mark)
4892
4893     (beginning-of-line)
4894
4895     (while headers
4896       ;; We may have to root out some bad articles...
4897       (when (memq (setq number (mail-header-number
4898                                 (setq header (pop headers))))
4899                   gnus-newsgroup-limit)
4900         ;; Mark article as read when it has a low score.
4901         (when (and gnus-summary-mark-below
4902                    (< (or (cdr (assq number gnus-newsgroup-scored))
4903                           gnus-summary-default-score 0)
4904                       gnus-summary-mark-below)
4905                    (not (gnus-summary-article-ancient-p number)))
4906           (setq gnus-newsgroup-unreads
4907                 (delq number gnus-newsgroup-unreads))
4908           (if gnus-newsgroup-auto-expire
4909               (push number gnus-newsgroup-expirable)
4910             (push (cons number gnus-low-score-mark)
4911                   gnus-newsgroup-reads)))
4912
4913         (setq mark (gnus-article-mark number))
4914         (push (gnus-data-make number mark (1+ (point)) header 0)
4915               gnus-newsgroup-data)
4916         (gnus-summary-insert-line
4917          header 0 number
4918          (memq number gnus-newsgroup-undownloaded)
4919          mark (memq number gnus-newsgroup-replied)
4920          (memq number gnus-newsgroup-expirable)
4921          (mail-header-subject header) nil
4922          (cdr (assq number gnus-newsgroup-scored))
4923          (memq number gnus-newsgroup-processable))))))
4924
4925 (defun gnus-summary-remove-list-identifiers ()
4926   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4927   (let ((regexp (if (consp gnus-list-identifiers)
4928                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4929                   gnus-list-identifiers))
4930         changed subject)
4931     (when regexp
4932       (dolist (header gnus-newsgroup-headers)
4933         (setq subject (mail-header-subject header)
4934               changed nil)
4935         (while (string-match
4936                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4937                 subject)
4938           (setq subject
4939                 (concat (substring subject 0 (match-beginning 2))
4940                         (substring subject (match-end 0)))
4941                 changed t))
4942         (when (and changed
4943                    (string-match
4944                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4945           (setq subject
4946                 (concat (substring subject 0 (match-beginning 1))
4947                         (substring subject (match-end 1)))))
4948         (when changed
4949           (mail-header-set-subject header subject))))))
4950
4951 (defun gnus-fetch-headers (articles)
4952   "Fetch headers of ARTICLES."
4953   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4954     (gnus-message 5 "Fetching headers for %s..." name)
4955     (prog1
4956         (if (eq 'nov
4957                 (setq gnus-headers-retrieved-by
4958                       (gnus-retrieve-headers
4959                        articles gnus-newsgroup-name
4960                        ;; We might want to fetch old headers, but
4961                        ;; not if there is only 1 article.
4962                        (and (or (and
4963                                  (not (eq gnus-fetch-old-headers 'some))
4964                                  (not (numberp gnus-fetch-old-headers)))
4965                                 (> (length articles) 1))
4966                             gnus-fetch-old-headers))))
4967             (gnus-get-newsgroup-headers-xover
4968              articles nil nil gnus-newsgroup-name t)
4969           (gnus-get-newsgroup-headers))
4970       (gnus-message 5 "Fetching headers for %s...done" name))))
4971
4972 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4973   "Select newsgroup GROUP.
4974 If READ-ALL is non-nil, all articles in the group are selected.
4975 If SELECT-ARTICLES, only select those articles from GROUP."
4976   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4977          ;;!!! Dirty hack; should be removed.
4978          (gnus-summary-ignore-duplicates
4979           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4980               t
4981             gnus-summary-ignore-duplicates))
4982          (info (nth 2 entry))
4983          articles fetched-articles cached)
4984
4985     (unless (gnus-check-server
4986              (set (make-local-variable 'gnus-current-select-method)
4987                   (gnus-find-method-for-group group)))
4988       (error "Couldn't open server"))
4989
4990     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4991         (gnus-activate-group group)     ; Or we can activate it...
4992         (progn                          ; Or we bug out.
4993           (when (equal major-mode 'gnus-summary-mode)
4994             (gnus-kill-buffer (current-buffer)))
4995           (error "Couldn't activate group %s: %s"
4996                  group (gnus-status-message group))))
4997
4998     (unless (gnus-request-group group t)
4999       (when (equal major-mode 'gnus-summary-mode)
5000         (gnus-kill-buffer (current-buffer)))
5001       (error "Couldn't request group %s: %s"
5002              group (gnus-status-message group)))
5003
5004     (setq gnus-newsgroup-name group
5005           gnus-newsgroup-unselected nil
5006           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5007
5008     (let ((display (gnus-group-find-parameter group 'display)))
5009       (setq gnus-newsgroup-display
5010             (cond
5011              ((not (zerop (or (car-safe read-all) 0)))
5012               ;; The user entered the group with C-u SPC/RET, let's show
5013               ;; all articles.
5014               'gnus-not-ignore)
5015              ((eq display 'all)
5016               'gnus-not-ignore)
5017              ((arrayp display)
5018               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5019              ((numberp display)
5020               ;; The following is probably the "correct" solution, but
5021               ;; it makes Gnus fetch all headers and then limit the
5022               ;; articles (which is slow), so instead we hack the
5023               ;; select-articles parameter instead. -- Simon Josefsson
5024               ;; <jas@kth.se>
5025               ;;
5026               ;; (gnus-byte-compile
5027               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5028               ;;                         display)))))
5029               (setq select-articles
5030                     (gnus-uncompress-range
5031                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5032                              (if (> tmp 0)
5033                                  tmp
5034                                1))
5035                            (cdr (gnus-active group)))))
5036               nil)
5037              (t
5038               nil))))
5039
5040     (gnus-summary-setup-default-charset)
5041
5042     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5043     (when (gnus-virtual-group-p group)
5044       (setq cached gnus-newsgroup-cached))
5045
5046     (setq gnus-newsgroup-unreads
5047           (gnus-sorted-ndifference
5048            (gnus-sorted-ndifference gnus-newsgroup-unreads
5049                                     gnus-newsgroup-marked)
5050            gnus-newsgroup-dormant))
5051
5052     (setq gnus-newsgroup-processable nil)
5053
5054     (gnus-update-read-articles group gnus-newsgroup-unreads)
5055
5056     ;; Adjust and set lists of article marks.
5057     (when info
5058       (gnus-adjust-marked-articles info))
5059     (if (setq articles select-articles)
5060         (setq gnus-newsgroup-unselected
5061               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5062       (setq articles (gnus-articles-to-read group read-all)))
5063
5064     (cond
5065      ((null articles)
5066       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5067       'quit)
5068      ((eq articles 0) nil)
5069      (t
5070       ;; Init the dependencies hash table.
5071       (setq gnus-newsgroup-dependencies
5072             (gnus-make-hashtable (length articles)))
5073       (gnus-set-global-variables)
5074       ;; Retrieve the headers and read them in.
5075
5076       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5077
5078       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5079       (when cached
5080         (setq gnus-newsgroup-cached cached))
5081
5082       ;; Suppress duplicates?
5083       (when gnus-suppress-duplicates
5084         (gnus-dup-suppress-articles))
5085
5086       ;; Set the initial limit.
5087       (setq gnus-newsgroup-limit (copy-sequence articles))
5088       ;; Remove canceled articles from the list of unread articles.
5089       (setq fetched-articles
5090             (mapcar (lambda (headers) (mail-header-number headers))
5091                     gnus-newsgroup-headers))
5092       (setq gnus-newsgroup-articles fetched-articles)
5093       (setq gnus-newsgroup-unreads
5094             (gnus-sorted-nintersection
5095              gnus-newsgroup-unreads fetched-articles))
5096       (gnus-compute-unseen-list)
5097
5098       ;; Removed marked articles that do not exist.
5099       (gnus-update-missing-marks
5100        (gnus-sorted-difference articles fetched-articles))
5101       ;; We might want to build some more threads first.
5102       (when (and gnus-fetch-old-headers
5103                  (eq gnus-headers-retrieved-by 'nov))
5104         (if (eq gnus-fetch-old-headers 'invisible)
5105             (gnus-build-all-threads)
5106           (gnus-build-old-threads)))
5107       ;; Let the Gnus agent mark articles as read.
5108       (when gnus-agent
5109         (gnus-agent-get-undownloaded-list))
5110       ;; Remove list identifiers from subject
5111       (when gnus-list-identifiers
5112         (gnus-summary-remove-list-identifiers))
5113       ;; Check whether auto-expire is to be done in this group.
5114       (setq gnus-newsgroup-auto-expire
5115             (gnus-group-auto-expirable-p group))
5116       ;; Set up the article buffer now, if necessary.
5117       (unless gnus-single-article-buffer
5118         (gnus-article-setup-buffer))
5119       ;; First and last article in this newsgroup.
5120       (when gnus-newsgroup-headers
5121         (setq gnus-newsgroup-begin
5122               (mail-header-number (car gnus-newsgroup-headers))
5123               gnus-newsgroup-end
5124               (mail-header-number
5125                (gnus-last-element gnus-newsgroup-headers))))
5126       ;; GROUP is successfully selected.
5127       (or gnus-newsgroup-headers t)))))
5128
5129 (defun gnus-compute-unseen-list ()
5130   ;; The `seen' marks are treated specially.
5131   (if (not gnus-newsgroup-seen)
5132       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5133     (setq gnus-newsgroup-unseen
5134           (gnus-inverse-list-range-intersection
5135            gnus-newsgroup-articles gnus-newsgroup-seen))))
5136
5137 (defun gnus-summary-display-make-predicate (display)
5138   (require 'gnus-agent)
5139   (when (= (length display) 1)
5140     (setq display (car display)))
5141   (unless gnus-summary-display-cache
5142     (dolist (elem (append '((unread . unread)
5143                             (read . read)
5144                             (unseen . unseen))
5145                           gnus-article-mark-lists))
5146       (push (cons (cdr elem)
5147                   (gnus-byte-compile
5148                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5149             gnus-summary-display-cache)))
5150   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5151         (gnus-category-predicate-cache gnus-summary-display-cache))
5152     (gnus-get-predicate display)))
5153
5154 ;; Uses the dynamically bound `number' variable.
5155 (eval-when-compile
5156   (defvar number))
5157 (defun gnus-article-marked-p (type &optional article)
5158   (let ((article (or article number)))
5159     (cond
5160      ((eq type 'tick)
5161       (memq article gnus-newsgroup-marked))
5162      ((eq type 'spam)
5163       (memq article gnus-newsgroup-spam-marked))
5164      ((eq type 'unsend)
5165       (memq article gnus-newsgroup-unsendable))
5166      ((eq type 'undownload)
5167       (memq article gnus-newsgroup-undownloaded))
5168      ((eq type 'download)
5169       (memq article gnus-newsgroup-downloadable))
5170      ((eq type 'unread)
5171       (memq article gnus-newsgroup-unreads))
5172      ((eq type 'read)
5173       (memq article gnus-newsgroup-reads))
5174      ((eq type 'dormant)
5175       (memq article gnus-newsgroup-dormant) )
5176      ((eq type 'expire)
5177       (memq article gnus-newsgroup-expirable))
5178      ((eq type 'reply)
5179       (memq article gnus-newsgroup-replied))
5180      ((eq type 'killed)
5181       (memq article gnus-newsgroup-killed))
5182      ((eq type 'bookmark)
5183       (assq article gnus-newsgroup-bookmarks))
5184      ((eq type 'score)
5185       (assq article gnus-newsgroup-scored))
5186      ((eq type 'save)
5187       (memq article gnus-newsgroup-saved))
5188      ((eq type 'cache)
5189       (memq article gnus-newsgroup-cached))
5190      ((eq type 'forward)
5191       (memq article gnus-newsgroup-forwarded))
5192      ((eq type 'seen)
5193       (not (memq article gnus-newsgroup-unseen)))
5194      ((eq type 'recent)
5195       (memq article gnus-newsgroup-recent))
5196      (t t))))
5197
5198 (defun gnus-articles-to-read (group &optional read-all)
5199   "Find out what articles the user wants to read."
5200   (let* ((display (gnus-group-find-parameter group 'display))
5201          (articles
5202           ;; Select all articles if `read-all' is non-nil, or if there
5203           ;; are no unread articles.
5204           (if (or read-all
5205                   (and (zerop (length gnus-newsgroup-marked))
5206                        (zerop (length gnus-newsgroup-unreads)))
5207                   ;; Fetch all if the predicate is non-nil.
5208                   gnus-newsgroup-display)
5209               ;; We want to select the headers for all the articles in
5210               ;; the group, so we select either all the active
5211               ;; articles in the group, or (if that's nil), the
5212               ;; articles in the cache.
5213               (or
5214                (gnus-uncompress-range (gnus-active group))
5215                (gnus-cache-articles-in-group group))
5216             ;; Select only the "normal" subset of articles.
5217             (gnus-sorted-nunion
5218              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5219              gnus-newsgroup-unreads)))
5220          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5221          (scored (length scored-list))
5222          (number (length articles))
5223          (marked (+ (length gnus-newsgroup-marked)
5224                     (length gnus-newsgroup-dormant)))
5225          (select
5226           (cond
5227            ((numberp read-all)
5228             read-all)
5229            ((numberp gnus-newsgroup-display)
5230             gnus-newsgroup-display)
5231            (t
5232             (condition-case ()
5233                 (cond
5234                  ((and (or (<= scored marked) (= scored number))
5235                        (numberp gnus-large-newsgroup)
5236                        (> number gnus-large-newsgroup))
5237                   (let* ((cursor-in-echo-area nil)
5238                          (initial (gnus-parameter-large-newsgroup-initial
5239                                    gnus-newsgroup-name))
5240                          (input
5241                           (read-string
5242                            (format
5243                             "How many articles from %s (%s %d): "
5244                             (gnus-limit-string
5245                              (gnus-group-decoded-name gnus-newsgroup-name)
5246                              35)
5247                             (if initial "max" "default")
5248                             number)
5249                            (if initial
5250                                (cons (number-to-string initial)
5251                                      0)))))
5252                     (if (string-match "^[ \t]*$" input) number input)))
5253                  ((and (> scored marked) (< scored number)
5254                        (> (- scored number) 20))
5255                   (let ((input
5256                          (read-string
5257                           (format "%s %s (%d scored, %d total): "
5258                                   "How many articles from"
5259                                   (gnus-group-decoded-name group)
5260                                   scored number))))
5261                     (if (string-match "^[ \t]*$" input)
5262                         number input)))
5263                  (t number))
5264               (quit
5265                (message "Quit getting the articles to read")
5266                nil))))))
5267     (setq select (if (stringp select) (string-to-number select) select))
5268     (if (or (null select) (zerop select))
5269         select
5270       (if (and (not (zerop scored)) (<= (abs select) scored))
5271           (progn
5272             (setq articles (sort scored-list '<))
5273             (setq number (length articles)))
5274         (setq articles (copy-sequence articles)))
5275
5276       (when (< (abs select) number)
5277         (if (< select 0)
5278             ;; Select the N oldest articles.
5279             (setcdr (nthcdr (1- (abs select)) articles) nil)
5280           ;; Select the N most recent articles.
5281           (setq articles (nthcdr (- number select) articles))))
5282       (setq gnus-newsgroup-unselected
5283             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5284       (when gnus-alter-articles-to-read-function
5285         (setq articles
5286               (sort
5287                (funcall gnus-alter-articles-to-read-function
5288                         gnus-newsgroup-name articles)
5289                '<)))
5290       articles)))
5291
5292 (defun gnus-killed-articles (killed articles)
5293   (let (out)
5294     (while articles
5295       (when (inline (gnus-member-of-range (car articles) killed))
5296         (push (car articles) out))
5297       (setq articles (cdr articles)))
5298     out))
5299
5300 (defun gnus-uncompress-marks (marks)
5301   "Uncompress the mark ranges in MARKS."
5302   (let ((uncompressed '(score bookmark))
5303         out)
5304     (while marks
5305       (if (memq (caar marks) uncompressed)
5306           (push (car marks) out)
5307         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5308       (setq marks (cdr marks)))
5309     out))
5310
5311 (defun gnus-article-mark-to-type (mark)
5312   "Return the type of MARK."
5313   (or (cadr (assq mark gnus-article-special-mark-lists))
5314       'list))
5315
5316 (defun gnus-article-unpropagatable-p (mark)
5317   "Return whether MARK should be propagated to backend."
5318   (memq mark gnus-article-unpropagated-mark-lists))
5319
5320 (defun gnus-adjust-marked-articles (info)
5321   "Set all article lists and remove all marks that are no longer valid."
5322   (let* ((marked-lists (gnus-info-marks info))
5323          (active (gnus-active (gnus-info-group info)))
5324          (min (car active))
5325          (max (cdr active))
5326          (types gnus-article-mark-lists)
5327          marks var articles article mark mark-type)
5328
5329     (dolist (marks marked-lists)
5330       (setq mark (car marks)
5331             mark-type (gnus-article-mark-to-type mark)
5332             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5333
5334       ;; We set the variable according to the type of the marks list,
5335       ;; and then adjust the marks to a subset of the active articles.
5336       (cond
5337        ;; Adjust "simple" lists.
5338        ((eq mark-type 'list)
5339         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5340         (when (memq mark '(tick dormant expire reply save))
5341           (while articles
5342             (when (or (< (setq article (pop articles)) min) (> article max))
5343               (set var (delq article (symbol-value var)))))))
5344        ;; Adjust assocs.
5345        ((eq mark-type 'tuple)
5346         (set var (setq articles (cdr marks)))
5347         (when (not (listp (cdr (symbol-value var))))
5348           (set var (list (symbol-value var))))
5349         (when (not (listp (cdr articles)))
5350           (setq articles (list articles)))
5351         (while articles
5352           (when (or (not (consp (setq article (pop articles))))
5353                     (< (car article) min)
5354                     (> (car article) max))
5355             (set var (delq article (symbol-value var))))))
5356        ;; Adjust ranges (sloppily).
5357        ((eq mark-type 'range)
5358         (cond
5359          ((eq mark 'seen)
5360           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5361           ;; It should be (seen (NUM1 . NUM2)).
5362           (when (numberp (cddr marks))
5363             (setcdr marks (list (cdr marks))))
5364           (setq articles (cdr marks))
5365           (while (and articles
5366                       (or (and (consp (car articles))
5367                                (> min (cdar articles)))
5368                           (and (numberp (car articles))
5369                                (> min (car articles)))))
5370             (pop articles))
5371           (set var articles))))))))
5372
5373 (defun gnus-update-missing-marks (missing)
5374   "Go through the list of MISSING articles and remove them from the mark lists."
5375   (when missing
5376     (let (var m)
5377       ;; Go through all types.
5378       (dolist (elem gnus-article-mark-lists)
5379         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5380           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5381           (when (symbol-value var)
5382             ;; This list has articles.  So we delete all missing
5383             ;; articles from it.
5384             (setq m missing)
5385             (while m
5386               (set var (delq (pop m) (symbol-value var))))))))))
5387
5388 (defun gnus-update-marks ()
5389   "Enter the various lists of marked articles into the newsgroup info list."
5390   (let ((types gnus-article-mark-lists)
5391         (info (gnus-get-info gnus-newsgroup-name))
5392         type list newmarked symbol delta-marks)
5393     (when info
5394       ;; Add all marks lists to the list of marks lists.
5395       (while (setq type (pop types))
5396         (setq list (symbol-value
5397                     (setq symbol
5398                           (intern (format "gnus-newsgroup-%s" (car type))))))
5399
5400         (when list
5401           ;; Get rid of the entries of the articles that have the
5402           ;; default score.
5403           (when (and (eq (cdr type) 'score)
5404                      gnus-save-score
5405                      list)
5406             (let* ((arts list)
5407                    (prev (cons nil list))
5408                    (all prev))
5409               (while arts
5410                 (if (or (not (consp (car arts)))
5411                         (= (cdar arts) gnus-summary-default-score))
5412                     (setcdr prev (cdr arts))
5413                   (setq prev arts))
5414                 (setq arts (cdr arts)))
5415               (setq list (cdr all)))))
5416
5417         (when (eq (cdr type) 'seen)
5418           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5419
5420         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5421           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5422
5423         (when (and (gnus-check-backend-function
5424                     'request-set-mark gnus-newsgroup-name)
5425                    (not (gnus-article-unpropagatable-p (cdr type))))
5426           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5427                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5428                  (add (gnus-remove-from-range
5429                        (gnus-copy-sequence list) old)))
5430             (when add
5431               (push (list add 'add (list (cdr type))) delta-marks))
5432             (when del
5433               (push (list del 'del (list (cdr type))) delta-marks))))
5434
5435         (when list
5436           (push (cons (cdr type) list) newmarked)))
5437
5438       (when delta-marks
5439         (unless (gnus-check-group gnus-newsgroup-name)
5440           (error "Can't open server for %s" gnus-newsgroup-name))
5441         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5442
5443       ;; Enter these new marks into the info of the group.
5444       (if (nthcdr 3 info)
5445           (setcar (nthcdr 3 info) newmarked)
5446         ;; Add the marks lists to the end of the info.
5447         (when newmarked
5448           (setcdr (nthcdr 2 info) (list newmarked))))
5449
5450       ;; Cut off the end of the info if there's nothing else there.
5451       (let ((i 5))
5452         (while (and (> i 2)
5453                     (not (nth i info)))
5454           (when (nthcdr (decf i) info)
5455             (setcdr (nthcdr i info) nil)))))))
5456
5457 (defun gnus-set-mode-line (where)
5458   "Set the mode line of the article or summary buffers.
5459 If WHERE is `summary', the summary mode line format will be used."
5460   ;; Is this mode line one we keep updated?
5461   (when (and (memq where gnus-updated-mode-lines)
5462              (symbol-value
5463               (intern (format "gnus-%s-mode-line-format-spec" where))))
5464     (let (mode-string)
5465       (save-excursion
5466         ;; We evaluate this in the summary buffer since these
5467         ;; variables are buffer-local to that buffer.
5468         (set-buffer gnus-summary-buffer)
5469         ;; We bind all these variables that are used in the `eval' form
5470         ;; below.
5471         (let* ((mformat (symbol-value
5472                          (intern
5473                           (format "gnus-%s-mode-line-format-spec" where))))
5474                (gnus-tmp-group-name (gnus-group-decoded-name
5475                                      gnus-newsgroup-name))
5476                (gnus-tmp-article-number (or gnus-current-article 0))
5477                (gnus-tmp-unread gnus-newsgroup-unreads)
5478                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5479                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5480                (gnus-tmp-unread-and-unselected
5481                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5482                             (zerop gnus-tmp-unselected))
5483                        "")
5484                       ((zerop gnus-tmp-unselected)
5485                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5486                       (t (format "{%d(+%d) more}"
5487                                  gnus-tmp-unread-and-unticked
5488                                  gnus-tmp-unselected))))
5489                (gnus-tmp-subject
5490                 (if (and gnus-current-headers
5491                          (vectorp gnus-current-headers))
5492                     (gnus-mode-string-quote
5493                      (mail-header-subject gnus-current-headers))
5494                   ""))
5495                bufname-length max-len
5496                gnus-tmp-header);; passed as argument to any user-format-funcs
5497           (setq mode-string (eval mformat))
5498           (setq bufname-length (if (string-match "%b" mode-string)
5499                                    (- (length
5500                                        (buffer-name
5501                                         (if (eq where 'summary)
5502                                             nil
5503                                           (get-buffer gnus-article-buffer))))
5504                                       2)
5505                                  0))
5506           (setq max-len (max 4 (if gnus-mode-non-string-length
5507                                    (- (window-width)
5508                                       gnus-mode-non-string-length
5509                                       bufname-length)
5510                                  (length mode-string))))
5511           ;; We might have to chop a bit of the string off...
5512           (when (> (length mode-string) max-len)
5513             (setq mode-string
5514                   (concat (gnus-truncate-string mode-string (- max-len 3))
5515                           "...")))
5516           ;; Pad the mode string a bit.
5517           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5518       ;; Update the mode line.
5519       (setq mode-line-buffer-identification
5520             (gnus-mode-line-buffer-identification (list mode-string)))
5521       (set-buffer-modified-p t))))
5522
5523 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5524   "Go through the HEADERS list and add all Xrefs to a hash table.
5525 The resulting hash table is returned, or nil if no Xrefs were found."
5526   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5527          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5528          (xref-hashtb (gnus-make-hashtable))
5529          start group entry number xrefs header)
5530     (while headers
5531       (setq header (pop headers))
5532       (when (and (setq xrefs (mail-header-xref header))
5533                  (not (memq (setq number (mail-header-number header))
5534                             unreads)))
5535         (setq start 0)
5536         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5537           (setq start (match-end 0))
5538           (setq group (if prefix
5539                           (concat prefix (substring xrefs (match-beginning 1)
5540                                                     (match-end 1)))
5541                         (substring xrefs (match-beginning 1) (match-end 1))))
5542           (setq number
5543                 (string-to-int (substring xrefs (match-beginning 2)
5544                                           (match-end 2))))
5545           (if (setq entry (gnus-gethash group xref-hashtb))
5546               (setcdr entry (cons number (cdr entry)))
5547             (gnus-sethash group (cons number nil) xref-hashtb)))))
5548     (and start xref-hashtb)))
5549
5550 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5551   "Look through all the headers and mark the Xrefs as read."
5552   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5553         name entry info xref-hashtb idlist method nth4)
5554     (save-excursion
5555       (set-buffer gnus-group-buffer)
5556       (when (setq xref-hashtb
5557                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5558         (mapatoms
5559          (lambda (group)
5560            (unless (string= from-newsgroup (setq name (symbol-name group)))
5561              (setq idlist (symbol-value group))
5562              ;; Dead groups are not updated.
5563              (and (prog1
5564                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5565                             info (nth 2 entry))
5566                     (when (stringp (setq nth4 (gnus-info-method info)))
5567                       (setq nth4 (gnus-server-to-method nth4))))
5568                   ;; Only do the xrefs if the group has the same
5569                   ;; select method as the group we have just read.
5570                   (or (gnus-methods-equal-p
5571                        nth4 (gnus-find-method-for-group from-newsgroup))
5572                       virtual
5573                       (equal nth4 (setq method (gnus-find-method-for-group
5574                                                 from-newsgroup)))
5575                       (and (equal (car nth4) (car method))
5576                            (equal (nth 1 nth4) (nth 1 method))))
5577                   gnus-use-cross-reference
5578                   (or (not (eq gnus-use-cross-reference t))
5579                       virtual
5580                       ;; Only do cross-references on subscribed
5581                       ;; groups, if that is what is wanted.
5582                       (<= (gnus-info-level info) gnus-level-subscribed))
5583                   (gnus-group-make-articles-read name idlist))))
5584          xref-hashtb)))))
5585
5586 (defun gnus-compute-read-articles (group articles)
5587   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5588          (info (nth 2 entry))
5589          (active (gnus-active group))
5590          ninfo)
5591     (when entry
5592       ;; First peel off all invalid article numbers.
5593       (when active
5594         (let ((ids articles)
5595               id first)
5596           (while (setq id (pop ids))
5597             (when (and first (> id (cdr active)))
5598               ;; We'll end up in this situation in one particular
5599               ;; obscure situation.  If you re-scan a group and get
5600               ;; a new article that is cross-posted to a different
5601               ;; group that has not been re-scanned, you might get
5602               ;; crossposted article that has a higher number than
5603               ;; Gnus believes possible.  So we re-activate this
5604               ;; group as well.  This might mean doing the
5605               ;; crossposting thingy will *increase* the number
5606               ;; of articles in some groups.  Tsk, tsk.
5607               (setq active (or (gnus-activate-group group) active)))
5608             (when (or (> id (cdr active))
5609                       (< id (car active)))
5610               (setq articles (delq id articles))))))
5611       ;; If the read list is nil, we init it.
5612       (if (and active
5613                (null (gnus-info-read info))
5614                (> (car active) 1))
5615           (setq ninfo (cons 1 (1- (car active))))
5616         (setq ninfo (gnus-info-read info)))
5617       ;; Then we add the read articles to the range.
5618       (gnus-add-to-range
5619        ninfo (setq articles (sort articles '<))))))
5620
5621 (defun gnus-group-make-articles-read (group articles)
5622   "Update the info of GROUP to say that ARTICLES are read."
5623   (let* ((num 0)
5624          (entry (gnus-gethash group gnus-newsrc-hashtb))
5625          (info (nth 2 entry))
5626          (active (gnus-active group))
5627          range)
5628     (when entry
5629       (setq range (gnus-compute-read-articles group articles))
5630       (save-excursion
5631         (set-buffer gnus-group-buffer)
5632         (gnus-undo-register
5633           `(progn
5634              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5635              (gnus-info-set-read ',info ',(gnus-info-read info))
5636              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5637              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5638              (gnus-group-update-group ,group t))))
5639       ;; Add the read articles to the range.
5640       (gnus-info-set-read info range)
5641       (gnus-request-set-mark group (list (list range 'add '(read))))
5642       ;; Then we have to re-compute how many unread
5643       ;; articles there are in this group.
5644       (when active
5645         (cond
5646          ((not range)
5647           (setq num (- (1+ (cdr active)) (car active))))
5648          ((not (listp (cdr range)))
5649           (setq num (- (cdr active) (- (1+ (cdr range))
5650                                        (car range)))))
5651          (t
5652           (while range
5653             (if (numberp (car range))
5654                 (setq num (1+ num))
5655               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5656             (setq range (cdr range)))
5657           (setq num (- (cdr active) num))))
5658         ;; Update the number of unread articles.
5659         (setcar entry num)
5660         ;; Update the group buffer.
5661         (unless (gnus-ephemeral-group-p group)
5662           (gnus-group-update-group group t))))))
5663
5664 (defvar gnus-newsgroup-none-id 0)
5665
5666 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5667   (let ((cur nntp-server-buffer)
5668         (dependencies
5669          (or dependencies
5670              (save-excursion (set-buffer gnus-summary-buffer)
5671                              gnus-newsgroup-dependencies)))
5672         headers id end ref
5673         (mail-parse-charset gnus-newsgroup-charset)
5674         (mail-parse-ignored-charsets
5675          (save-excursion (condition-case nil
5676                              (set-buffer gnus-summary-buffer)
5677                            (error))
5678                          gnus-newsgroup-ignored-charsets)))
5679     (save-excursion
5680       (set-buffer nntp-server-buffer)
5681       ;; Translate all TAB characters into SPACE characters.
5682       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5683       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5684       (gnus-run-hooks 'gnus-parse-headers-hook)
5685       (let ((case-fold-search t)
5686             in-reply-to header p lines chars ctype)
5687         (goto-char (point-min))
5688         ;; Search to the beginning of the next header.  Error messages
5689         ;; do not begin with 2 or 3.
5690         (while (re-search-forward "^[23][0-9]+ " nil t)
5691           (setq id nil
5692                 ref nil)
5693           ;; This implementation of this function, with nine
5694           ;; search-forwards instead of the one re-search-forward and
5695           ;; a case (which basically was the old function) is actually
5696           ;; about twice as fast, even though it looks messier.  You
5697           ;; can't have everything, I guess.  Speed and elegance
5698           ;; doesn't always go hand in hand.
5699           (setq
5700            header
5701            (make-full-mail-header
5702             ;; Number.
5703             (prog1
5704                 (read cur)
5705               (end-of-line)
5706               (setq p (point))
5707               (narrow-to-region (point)
5708                                 (or (and (search-forward "\n.\n" nil t)
5709                                          (- (point) 2))
5710                                     (point))))
5711             ;; Subject.
5712             (progn
5713               (goto-char p)
5714               (if (search-forward "\nsubject:" nil t)
5715                   (nnheader-header-value)
5716                 "(none)"))
5717             ;; From.
5718             (progn
5719               (goto-char p)
5720               (if (search-forward "\nfrom:" nil t)
5721                   (nnheader-header-value)
5722                 "(nobody)"))
5723             ;; Date.
5724             (progn
5725               (goto-char p)
5726               (if (search-forward "\ndate:" nil t)
5727                   (nnheader-header-value) ""))
5728             ;; Message-ID.
5729             (progn
5730               (goto-char p)
5731               (setq id (if (re-search-forward
5732                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5733                            ;; We do it this way to make sure the Message-ID
5734                            ;; is (somewhat) syntactically valid.
5735                            (buffer-substring (match-beginning 1)
5736                                              (match-end 1))
5737                          ;; If there was no message-id, we just fake one
5738                          ;; to make subsequent routines simpler.
5739                          (nnheader-generate-fake-message-id))))
5740             ;; References.
5741             (progn
5742               (goto-char p)
5743               (if (search-forward "\nreferences:" nil t)
5744                   (progn
5745                     (setq end (point))
5746                     (prog1
5747                         (nnheader-header-value)
5748                       (setq ref
5749                             (buffer-substring
5750                              (progn
5751                                ;; (end-of-line)
5752                                (search-backward ">" end t)
5753                                (1+ (point)))
5754                              (progn
5755                                (search-backward "<" end t)
5756                                (point))))))
5757                 ;; Get the references from the in-reply-to header if there
5758                 ;; were no references and the in-reply-to header looks
5759                 ;; promising.
5760                 (if (and (search-forward "\nin-reply-to:" nil t)
5761                          (setq in-reply-to (nnheader-header-value))
5762                          (string-match "<[^>]+>" in-reply-to))
5763                     (let (ref2)
5764                       (setq ref (substring in-reply-to (match-beginning 0)
5765                                            (match-end 0)))
5766                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5767                         (setq ref2 (substring in-reply-to (match-beginning 0)
5768                                               (match-end 0)))
5769                         (when (> (length ref2) (length ref))
5770                           (setq ref ref2)))
5771                       ref)
5772                   (setq ref nil))))
5773             ;; Chars.
5774             (progn
5775               (goto-char p)
5776               (if (search-forward "\nchars: " nil t)
5777                   (if (numberp (setq chars (ignore-errors (read cur))))
5778                       chars -1)
5779                 -1))
5780             ;; Lines.
5781             (progn
5782               (goto-char p)
5783               (if (search-forward "\nlines: " nil t)
5784                   (if (numberp (setq lines (ignore-errors (read cur))))
5785                       lines -1)
5786                 -1))
5787             ;; Xref.
5788             (progn
5789               (goto-char p)
5790               (and (search-forward "\nxref:" nil t)
5791                    (nnheader-header-value)))
5792             ;; Extra.
5793             (when gnus-extra-headers
5794               (let ((extra gnus-extra-headers)
5795                     out)
5796                 (while extra
5797                   (goto-char p)
5798                   (when (search-forward
5799                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5800                     (push (cons (car extra) (nnheader-header-value)) out))
5801                   (pop extra))
5802                 out))))
5803           (goto-char p)
5804           (if (and (search-forward "\ncontent-type: " nil t)
5805                    (setq ctype (nnheader-header-value)))
5806               (mime-entity-set-content-type-internal
5807                header (mime-parse-Content-Type ctype)))
5808           (when (equal id ref)
5809             (setq ref nil))
5810
5811           (when gnus-alter-header-function
5812             (funcall gnus-alter-header-function header)
5813             (setq id (mail-header-id header)
5814                   ref (gnus-parent-id (mail-header-references header))))
5815
5816           (when (setq header
5817                       (gnus-dependencies-add-header
5818                        header dependencies force-new))
5819             (push header headers))
5820           (goto-char (point-max))
5821           (widen))
5822         (nreverse headers)))))
5823
5824 ;; Goes through the xover lines and returns a list of vectors
5825 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5826                                                   force-new dependencies
5827                                                   group also-fetch-heads)
5828   "Parse the news overview data in the server buffer.
5829 Return a list of headers that match SEQUENCE (see
5830 `nntp-retrieve-headers')."
5831   ;; Get the Xref when the users reads the articles since most/some
5832   ;; NNTP servers do not include Xrefs when using XOVER.
5833   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5834   (let ((mail-parse-charset gnus-newsgroup-charset)
5835         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5836         (cur nntp-server-buffer)
5837         (dependencies (or dependencies gnus-newsgroup-dependencies))
5838         (allp (cond
5839                ((eq gnus-read-all-available-headers t)
5840                 t)
5841                ((stringp gnus-read-all-available-headers)
5842                 (string-match gnus-read-all-available-headers group))
5843                (t
5844                 nil)))
5845         number headers header)
5846     (save-excursion
5847       (set-buffer nntp-server-buffer)
5848       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5849       ;; Allow the user to mangle the headers before parsing them.
5850       (gnus-run-hooks 'gnus-parse-headers-hook)
5851       (goto-char (point-min))
5852       (gnus-parse-without-error
5853         (while (and (or sequence allp)
5854                     (not (eobp)))
5855           (setq number (read cur))
5856           (when (not allp)
5857             (while (and sequence
5858                         (< (car sequence) number))
5859               (setq sequence (cdr sequence))))
5860           (when (and (or allp
5861                          (and sequence
5862                               (eq number (car sequence))))
5863                      (progn
5864                        (setq sequence (cdr sequence))
5865                        (setq header (inline
5866                                       (gnus-nov-parse-line
5867                                        number dependencies force-new)))))
5868             (push header headers))
5869           (forward-line 1)))
5870       ;; A common bug in inn is that if you have posted an article and
5871       ;; then retrieves the active file, it will answer correctly --
5872       ;; the new article is included.  However, a NOV entry for the
5873       ;; article may not have been generated yet, so this may fail.
5874       ;; We work around this problem by retrieving the last few
5875       ;; headers using HEAD.
5876       (if (or (not also-fetch-heads)
5877               (not sequence))
5878           ;; We (probably) got all the headers.
5879           (nreverse headers)
5880         (let ((gnus-nov-is-evil t))
5881           (nconc
5882            (nreverse headers)
5883            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5884              (gnus-get-newsgroup-headers))))))))
5885
5886 (defun gnus-article-get-xrefs ()
5887   "Fill in the Xref value in `gnus-current-headers', if necessary.
5888 This is meant to be called in `gnus-article-internal-prepare-hook'."
5889   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5890                                  gnus-current-headers)))
5891     (or (not gnus-use-cross-reference)
5892         (not headers)
5893         (and (mail-header-xref headers)
5894              (not (string= (mail-header-xref headers) "")))
5895         (let ((case-fold-search t)
5896               xref)
5897           (save-restriction
5898             (nnheader-narrow-to-headers)
5899             (goto-char (point-min))
5900             (when (or (and (not (eobp))
5901                            (eq (downcase (char-after)) ?x)
5902                            (looking-at "Xref:"))
5903                       (search-forward "\nXref:" nil t))
5904               (goto-char (1+ (match-end 0)))
5905               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5906               (mail-header-set-xref headers xref)))))))
5907
5908 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5909   "Find article ID and insert the summary line for that article.
5910 OLD-HEADER can either be a header or a line number to insert
5911 the subject line on."
5912   (let* ((line (and (numberp old-header) old-header))
5913          (old-header (and (vectorp old-header) old-header))
5914          (header (cond ((and old-header use-old-header)
5915                         old-header)
5916                        ((and (numberp id)
5917                              (gnus-number-to-header id))
5918                         (gnus-number-to-header id))
5919                        (t
5920                         (gnus-read-header id))))
5921          (number (and (numberp id) id))
5922          d)
5923     (when header
5924       ;; Rebuild the thread that this article is part of and go to the
5925       ;; article we have fetched.
5926       (when (and (not gnus-show-threads)
5927                  old-header)
5928         (when (and number
5929                    (setq d (gnus-data-find (mail-header-number old-header))))
5930           (goto-char (gnus-data-pos d))
5931           (gnus-data-remove
5932            number
5933            (- (gnus-point-at-bol)
5934               (prog1
5935                   (1+ (gnus-point-at-eol))
5936                 (gnus-delete-line))))))
5937       (when old-header
5938         (mail-header-set-number header (mail-header-number old-header)))
5939       (setq gnus-newsgroup-sparse
5940             (delq (setq number (mail-header-number header))
5941                   gnus-newsgroup-sparse))
5942       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5943       (push number gnus-newsgroup-limit)
5944       (gnus-rebuild-thread (mail-header-id header) line)
5945       (gnus-summary-goto-subject number nil t))
5946     (when (and (numberp number)
5947                (> number 0))
5948       ;; We have to update the boundaries even if we can't fetch the
5949       ;; article if ID is a number -- so that the next `P' or `N'
5950       ;; command will fetch the previous (or next) article even
5951       ;; if the one we tried to fetch this time has been canceled.
5952       (when (> number gnus-newsgroup-end)
5953         (setq gnus-newsgroup-end number))
5954       (when (< number gnus-newsgroup-begin)
5955         (setq gnus-newsgroup-begin number))
5956       (setq gnus-newsgroup-unselected
5957             (delq number gnus-newsgroup-unselected)))
5958     ;; Report back a success?
5959     (and header (mail-header-number header))))
5960
5961 ;;; Process/prefix in the summary buffer
5962
5963 (defun gnus-summary-work-articles (n)
5964   "Return a list of articles to be worked upon.
5965 The prefix argument, the list of process marked articles, and the
5966 current article will be taken into consideration."
5967   (save-excursion
5968     (set-buffer gnus-summary-buffer)
5969     (cond
5970      (n
5971       ;; A numerical prefix has been given.
5972       (setq n (prefix-numeric-value n))
5973       (let ((backward (< n 0))
5974             (n (abs (prefix-numeric-value n)))
5975             articles article)
5976         (save-excursion
5977           (while
5978               (and (> n 0)
5979                    (push (setq article (gnus-summary-article-number))
5980                          articles)
5981                    (if backward
5982                        (gnus-summary-find-prev nil article)
5983                      (gnus-summary-find-next nil article)))
5984             (decf n)))
5985         (nreverse articles)))
5986      ((and (gnus-region-active-p) (mark))
5987       (message "region active")
5988       ;; Work on the region between point and mark.
5989       (let ((max (max (point) (mark)))
5990             articles article)
5991         (save-excursion
5992           (goto-char (min (point) (mark)))
5993           (while
5994               (and
5995                (push (setq article (gnus-summary-article-number)) articles)
5996                (gnus-summary-find-next nil article)
5997                (< (point) max)))
5998           (nreverse articles))))
5999      (gnus-newsgroup-processable
6000       ;; There are process-marked articles present.
6001       ;; Save current state.
6002       (gnus-summary-save-process-mark)
6003       ;; Return the list.
6004       (reverse gnus-newsgroup-processable))
6005      (t
6006       ;; Just return the current article.
6007       (list (gnus-summary-article-number))))))
6008
6009 (defmacro gnus-summary-iterate (arg &rest forms)
6010   "Iterate over the process/prefixed articles and do FORMS.
6011 ARG is the interactive prefix given to the command.  FORMS will be
6012 executed with point over the summary line of the articles."
6013   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6014     `(let ((,articles (gnus-summary-work-articles ,arg)))
6015        (while ,articles
6016          (gnus-summary-goto-subject (car ,articles))
6017          ,@forms
6018          (pop ,articles)))))
6019
6020 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6021 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6022
6023 (defun gnus-summary-save-process-mark ()
6024   "Push the current set of process marked articles on the stack."
6025   (interactive)
6026   (push (copy-sequence gnus-newsgroup-processable)
6027         gnus-newsgroup-process-stack))
6028
6029 (defun gnus-summary-kill-process-mark ()
6030   "Push the current set of process marked articles on the stack and unmark."
6031   (interactive)
6032   (gnus-summary-save-process-mark)
6033   (gnus-summary-unmark-all-processable))
6034
6035 (defun gnus-summary-yank-process-mark ()
6036   "Pop the last process mark state off the stack and restore it."
6037   (interactive)
6038   (unless gnus-newsgroup-process-stack
6039     (error "Empty mark stack"))
6040   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6041
6042 (defun gnus-summary-process-mark-set (set)
6043   "Make SET into the current process marked articles."
6044   (gnus-summary-unmark-all-processable)
6045   (while set
6046     (gnus-summary-set-process-mark (pop set))))
6047
6048 ;;; Searching and stuff
6049
6050 (defun gnus-summary-search-group (&optional backward use-level)
6051   "Search for next unread newsgroup.
6052 If optional argument BACKWARD is non-nil, search backward instead."
6053   (save-excursion
6054     (set-buffer gnus-group-buffer)
6055     (when (gnus-group-search-forward
6056            backward nil (if use-level (gnus-group-group-level) nil))
6057       (gnus-group-group-name))))
6058
6059 (defun gnus-summary-best-group (&optional exclude-group)
6060   "Find the name of the best unread group.
6061 If EXCLUDE-GROUP, do not go to this group."
6062   (save-excursion
6063     (set-buffer gnus-group-buffer)
6064     (save-excursion
6065       (gnus-group-best-unread-group exclude-group))))
6066
6067 (defun gnus-summary-find-next (&optional unread article backward)
6068   (if backward (gnus-summary-find-prev unread article)
6069     (let* ((dummy (gnus-summary-article-intangible-p))
6070            (article (or article (gnus-summary-article-number)))
6071            (data (gnus-data-find-list article))
6072            result)
6073       (when (and (not dummy)
6074                  (or (not gnus-summary-check-current)
6075                      (not unread)
6076                      (not (gnus-data-unread-p (car data)))))
6077         (setq data (cdr data)))
6078       (when (setq result
6079                   (if unread
6080                       (progn
6081                         (while data
6082                           (unless (memq (gnus-data-number (car data)) 
6083                                         (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6084                                                gnus-newsgroup-undownloaded)
6085                                               (gnus-plugged
6086                                                nil)
6087                                               ((eq gnus-auto-goto-ignores 'unfetched)
6088                                                gnus-newsgroup-unfetched)
6089                                               ((eq gnus-auto-goto-ignores 'undownloaded)
6090                                                gnus-newsgroup-undownloaded)))
6091                             (when (gnus-data-unread-p (car data))
6092                               (setq result (car data)
6093                                     data nil)))
6094                           (setq data (cdr data)))
6095                         result)
6096                     (car data)))
6097         (goto-char (gnus-data-pos result))
6098         (gnus-data-number result)))))
6099
6100 (defun gnus-summary-find-prev (&optional unread article)
6101   (let* ((eobp (eobp))
6102          (article (or article (gnus-summary-article-number)))
6103          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6104          result)
6105     (when (and (not eobp)
6106                (or (not gnus-summary-check-current)
6107                    (not unread)
6108                    (not (gnus-data-unread-p (car data)))))
6109       (setq data (cdr data)))
6110     (when (setq result
6111                 (if unread
6112                     (progn
6113                       (while data
6114                         (unless (memq (gnus-data-number (car data))
6115                                       (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6116                                              gnus-newsgroup-undownloaded)
6117                                             (gnus-plugged
6118                                              nil)
6119                                             ((eq gnus-auto-goto-ignores 'unfetched)
6120                                              gnus-newsgroup-unfetched)
6121                                             ((eq gnus-auto-goto-ignores 'undownloaded)
6122                                              gnus-newsgroup-undownloaded)))
6123                           (when (gnus-data-unread-p (car data))
6124                             (setq result (car data)
6125                                   data nil)))
6126                         (setq data (cdr data)))
6127                       result)
6128                   (car data)))
6129       (goto-char (gnus-data-pos result))
6130       (gnus-data-number result))))
6131
6132 (defun gnus-summary-find-subject (subject &optional unread backward article)
6133   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6134          (article (or article (gnus-summary-article-number)))
6135          (articles (gnus-data-list backward))
6136          (arts (gnus-data-find-list article articles))
6137          result)
6138     (when (or (not gnus-summary-check-current)
6139               (not unread)
6140               (not (gnus-data-unread-p (car arts))))
6141       (setq arts (cdr arts)))
6142     (while arts
6143       (and (or (not unread)
6144                (gnus-data-unread-p (car arts)))
6145            (vectorp (gnus-data-header (car arts)))
6146            (gnus-subject-equal
6147             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6148            (setq result (car arts)
6149                  arts nil))
6150       (setq arts (cdr arts)))
6151     (and result
6152          (goto-char (gnus-data-pos result))
6153          (gnus-data-number result))))
6154
6155 (defun gnus-summary-search-forward (&optional unread subject backward)
6156   "Search forward for an article.
6157 If UNREAD, look for unread articles.  If SUBJECT, look for
6158 articles with that subject.  If BACKWARD, search backward instead."
6159   (cond (subject (gnus-summary-find-subject subject unread backward))
6160         (backward (gnus-summary-find-prev unread))
6161         (t (gnus-summary-find-next unread))))
6162
6163 (defun gnus-recenter (&optional n)
6164   "Center point in window and redisplay frame.
6165 Also do horizontal recentering."
6166   (interactive "P")
6167   (when (and gnus-auto-center-summary
6168              (not (eq gnus-auto-center-summary 'vertical)))
6169     (gnus-horizontal-recenter))
6170   (recenter n))
6171
6172 (defun gnus-summary-recenter ()
6173   "Center point in the summary window.
6174 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6175 displayed, no centering will be performed."
6176   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6177   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6178   (interactive)
6179   ;; The user has to want it.
6180   (when gnus-auto-center-summary
6181     (let* ((top (cond ((< (window-height) 4) 0)
6182                       ((< (window-height) 7) 1)
6183                       (t (if (numberp gnus-auto-center-summary)
6184                              gnus-auto-center-summary
6185                            2))))
6186            (height (1- (window-height)))
6187            (bottom (save-excursion (goto-char (point-max))
6188                                    (forward-line (- height))
6189                                    (point)))
6190            (window (get-buffer-window (current-buffer))))
6191       (when (get-buffer-window gnus-article-buffer)
6192         ;; Only do recentering when the article buffer is displayed,
6193         ;; Set the window start to either `bottom', which is the biggest
6194         ;; possible valid number, or the second line from the top,
6195         ;; whichever is the least.
6196         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6197           (if (> bottom top-pos)
6198               ;; Keep the second line from the top visible
6199               (set-window-start window top-pos t)
6200             ;; Try to keep the bottom line visible; if it's partially
6201             ;; obscured, either scroll one more line to make it fully
6202             ;; visible, or revert to using TOP-POS.
6203             (save-excursion
6204               (goto-char (point-max))
6205               (forward-line -1)
6206               (let ((last-line-start (point)))
6207                 (goto-char bottom)
6208                 (set-window-start window (point) t)
6209                 (when (not (pos-visible-in-window-p last-line-start window))
6210                   (forward-line 1)
6211                   (set-window-start window (min (point) top-pos) t)))))))
6212       ;; Do horizontal recentering while we're at it.
6213       (when (and (get-buffer-window (current-buffer) t)
6214                  (not (eq gnus-auto-center-summary 'vertical)))
6215         (let ((selected (selected-window)))
6216           (select-window (get-buffer-window (current-buffer) t))
6217           (gnus-summary-position-point)
6218           (gnus-horizontal-recenter)
6219           (select-window selected))))))
6220
6221 (defun gnus-summary-jump-to-group (newsgroup)
6222   "Move point to NEWSGROUP in group mode buffer."
6223   ;; Keep update point of group mode buffer if visible.
6224   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6225       (save-window-excursion
6226         ;; Take care of tree window mode.
6227         (when (get-buffer-window gnus-group-buffer)
6228           (pop-to-buffer gnus-group-buffer))
6229         (gnus-group-jump-to-group newsgroup))
6230     (save-excursion
6231       ;; Take care of tree window mode.
6232       (if (get-buffer-window gnus-group-buffer)
6233           (pop-to-buffer gnus-group-buffer)
6234         (set-buffer gnus-group-buffer))
6235       (gnus-group-jump-to-group newsgroup))))
6236
6237 ;; This function returns a list of article numbers based on the
6238 ;; difference between the ranges of read articles in this group and
6239 ;; the range of active articles.
6240 (defun gnus-list-of-unread-articles (group)
6241   (let* ((read (gnus-info-read (gnus-get-info group)))
6242          (active (or (gnus-active group) (gnus-activate-group group)))
6243          (last (cdr active))
6244          first nlast unread)
6245     ;; If none are read, then all are unread.
6246     (if (not read)
6247         (setq first (car active))
6248       ;; If the range of read articles is a single range, then the
6249       ;; first unread article is the article after the last read
6250       ;; article.  Sounds logical, doesn't it?
6251       (if (and (not (listp (cdr read)))
6252                (or (< (car read) (car active))
6253                    (progn (setq read (list read))
6254                           nil)))
6255           (setq first (max (car active) (1+ (cdr read))))
6256         ;; `read' is a list of ranges.
6257         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6258                                   (caar read)))
6259                   1)
6260           (setq first (car active)))
6261         (while read
6262           (when first
6263             (while (< first nlast)
6264               (push first unread)
6265               (setq first (1+ first))))
6266           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6267           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6268           (setq read (cdr read)))))
6269     ;; And add the last unread articles.
6270     (while (<= first last)
6271       (push first unread)
6272       (setq first (1+ first)))
6273     ;; Return the list of unread articles.
6274     (delq 0 (nreverse unread))))
6275
6276 (defun gnus-list-of-read-articles (group)
6277   "Return a list of unread, unticked and non-dormant articles."
6278   (let* ((info (gnus-get-info group))
6279          (marked (gnus-info-marks info))
6280          (active (gnus-active group)))
6281     (and info active
6282          (gnus-list-range-difference
6283           (gnus-list-range-difference
6284            (gnus-sorted-complement
6285             (gnus-uncompress-range active)
6286             (gnus-list-of-unread-articles group))
6287            (cdr (assq 'dormant marked)))
6288           (cdr (assq 'tick marked))))))
6289
6290 ;; Various summary commands
6291
6292 (defun gnus-summary-select-article-buffer ()
6293   "Reconfigure windows to show article buffer."
6294   (interactive)
6295   (if (not (gnus-buffer-live-p gnus-article-buffer))
6296       (error "There is no article buffer for this summary buffer")
6297     (gnus-configure-windows 'article)
6298     (select-window (get-buffer-window gnus-article-buffer))))
6299
6300 (defun gnus-summary-universal-argument (arg)
6301   "Perform any operation on all articles that are process/prefixed."
6302   (interactive "P")
6303   (let ((articles (gnus-summary-work-articles arg))
6304         func article)
6305     (if (eq
6306          (setq
6307           func
6308           (key-binding
6309            (read-key-sequence
6310             (substitute-command-keys
6311              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6312          'undefined)
6313         (gnus-error 1 "Undefined key")
6314       (save-excursion
6315         (while articles
6316           (gnus-summary-goto-subject (setq article (pop articles)))
6317           (let (gnus-newsgroup-processable)
6318             (command-execute func))
6319           (gnus-summary-remove-process-mark article)))))
6320   (gnus-summary-position-point))
6321
6322 (defun gnus-summary-toggle-truncation (&optional arg)
6323   "Toggle truncation of summary lines.
6324 With arg, turn line truncation on if arg is positive."
6325   (interactive "P")
6326   (setq truncate-lines
6327         (if (null arg) (not truncate-lines)
6328           (> (prefix-numeric-value arg) 0)))
6329   (redraw-display))
6330
6331 (defun gnus-summary-find-for-reselect ()
6332   "Return the number of an article to stay on across a reselect.
6333 The current article is considered, then following articles, then previous
6334 articles.  An article is sought which is not cancelled and isn't a temporary
6335 insertion from another group.  If there's no such then return a dummy 0."
6336   (let (found)
6337     (dolist (rev '(nil t))
6338       (unless found      ; don't demand the reverse list if we don't need it
6339         (let ((data (gnus-data-find-list
6340                      (gnus-summary-article-number) (gnus-data-list rev))))
6341           (while (and data (not found))
6342             (if (and (< 0 (gnus-data-number (car data)))
6343                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6344                 (setq found (gnus-data-number (car data))))
6345             (setq data (cdr data))))))
6346     (or found 0)))
6347
6348 (defun gnus-summary-reselect-current-group (&optional all rescan)
6349   "Exit and then reselect the current newsgroup.
6350 The prefix argument ALL means to select all articles."
6351   (interactive "P")
6352   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6353     (error "Ephemeral groups can't be reselected"))
6354   (let ((current-subject (gnus-summary-find-for-reselect))
6355         (group gnus-newsgroup-name))
6356     (setq gnus-newsgroup-begin nil)
6357     (gnus-summary-exit)
6358     ;; We have to adjust the point of group mode buffer because
6359     ;; point was moved to the next unread newsgroup by exiting.
6360     (gnus-summary-jump-to-group group)
6361     (when rescan
6362       (save-excursion
6363         (save-window-excursion
6364           ;; Don't show group contents.
6365           (set-window-start (selected-window) (point-max))
6366           (gnus-group-get-new-news-this-group 1))))
6367     (gnus-group-read-group all t)
6368     (gnus-summary-goto-subject current-subject nil t)))
6369
6370 (defun gnus-summary-rescan-group (&optional all)
6371   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6372   (interactive "P")
6373   (gnus-summary-reselect-current-group all t))
6374
6375 (defun gnus-summary-update-info (&optional non-destructive)
6376   (save-excursion
6377     (let ((group gnus-newsgroup-name))
6378       (when group
6379         (when gnus-newsgroup-kill-headers
6380           (setq gnus-newsgroup-killed
6381                 (gnus-compress-sequence
6382                  (gnus-sorted-union
6383                   (gnus-list-range-intersection
6384                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6385                   gnus-newsgroup-unreads)
6386                  t)))
6387         (unless (listp (cdr gnus-newsgroup-killed))
6388           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6389         (let ((headers gnus-newsgroup-headers))
6390           ;; Set the new ranges of read articles.
6391           (save-excursion
6392             (set-buffer gnus-group-buffer)
6393             (gnus-undo-force-boundary))
6394           (gnus-update-read-articles
6395            group (gnus-sorted-union
6396                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6397           ;; Set the current article marks.
6398           (let ((gnus-newsgroup-scored
6399                  (if (and (not gnus-save-score)
6400                           (not non-destructive))
6401                      nil
6402                    gnus-newsgroup-scored)))
6403             (save-excursion
6404               (gnus-update-marks)))
6405           ;; Do the cross-ref thing.
6406           (when gnus-use-cross-reference
6407             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6408           ;; Do not switch windows but change the buffer to work.
6409           (set-buffer gnus-group-buffer)
6410           (unless (gnus-ephemeral-group-p group)
6411             (gnus-group-update-group group)))))))
6412
6413 (defun gnus-summary-save-newsrc (&optional force)
6414   "Save the current number of read/marked articles in the dribble buffer.
6415 The dribble buffer will then be saved.
6416 If FORCE (the prefix), also save the .newsrc file(s)."
6417   (interactive "P")
6418   (gnus-summary-update-info t)
6419   (if force
6420       (gnus-save-newsrc-file)
6421     (gnus-dribble-save)))
6422
6423 (defun gnus-summary-exit (&optional temporary)
6424   "Exit reading current newsgroup, and then return to group selection mode.
6425 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6426   (interactive)
6427   (gnus-set-global-variables)
6428   (gnus-kill-save-kill-buffer)
6429   (gnus-async-halt-prefetch)
6430   (let* ((group gnus-newsgroup-name)
6431          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6432          (gnus-group-is-exiting-p t)
6433          (mode major-mode)
6434          (group-point nil)
6435          (buf (current-buffer)))
6436     (unless quit-config
6437       ;; Do adaptive scoring, and possibly save score files.
6438       (when gnus-newsgroup-adaptive
6439         (gnus-score-adaptive))
6440       (when gnus-use-scoring
6441         (gnus-score-save)))
6442     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6443     ;; If we have several article buffers, we kill them at exit.
6444     (unless gnus-single-article-buffer
6445       (gnus-kill-buffer gnus-original-article-buffer)
6446       (setq gnus-article-current nil))
6447     (when gnus-use-cache
6448       (gnus-cache-possibly-remove-articles)
6449       (gnus-cache-save-buffers))
6450     (gnus-async-prefetch-remove-group group)
6451     (when gnus-suppress-duplicates
6452       (gnus-dup-enter-articles))
6453     (when gnus-use-trees
6454       (gnus-tree-close group))
6455     (when gnus-use-cache
6456       (gnus-cache-write-active))
6457     ;; Remove entries for this group.
6458     (nnmail-purge-split-history (gnus-group-real-name group))
6459     ;; Make all changes in this group permanent.
6460     (unless quit-config
6461       (gnus-run-hooks 'gnus-exit-group-hook)
6462       (gnus-summary-update-info))
6463     (gnus-close-group group)
6464     ;; Make sure where we were, and go to next newsgroup.
6465     (set-buffer gnus-group-buffer)
6466     (unless quit-config
6467       (gnus-group-jump-to-group group))
6468     (gnus-run-hooks 'gnus-summary-exit-hook)
6469     (unless (or quit-config
6470                 ;; If this group has disappeared from the summary
6471                 ;; buffer, don't skip forwards.
6472                 (not (string= group (gnus-group-group-name))))
6473       (gnus-group-next-unread-group 1))
6474     (setq group-point (point))
6475     (if temporary
6476         nil                             ;Nothing to do.
6477       ;; If we have several article buffers, we kill them at exit.
6478       (unless gnus-single-article-buffer
6479         (gnus-kill-buffer gnus-article-buffer)
6480         (gnus-kill-buffer gnus-original-article-buffer)
6481         (setq gnus-article-current nil))
6482       (set-buffer buf)
6483       (if (not gnus-kill-summary-on-exit)
6484           (progn
6485             (gnus-deaden-summary)
6486             (setq mode nil))
6487         ;; We set all buffer-local variables to nil.  It is unclear why
6488         ;; this is needed, but if we don't, buffer-local variables are
6489         ;; not garbage-collected, it seems.  This would the lead to en
6490         ;; ever-growing Emacs.
6491         (gnus-summary-clear-local-variables)
6492         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6493           (gnus-summary-clear-local-variables))
6494         (when (get-buffer gnus-article-buffer)
6495           (bury-buffer gnus-article-buffer))
6496         ;; We clear the global counterparts of the buffer-local
6497         ;; variables as well, just to be on the safe side.
6498         (set-buffer gnus-group-buffer)
6499         (gnus-summary-clear-local-variables)
6500         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6501           (gnus-summary-clear-local-variables))
6502         ;; Return to group mode buffer.
6503         (when (eq mode 'gnus-summary-mode)
6504           (gnus-kill-buffer buf)))
6505       (setq gnus-current-select-method gnus-select-method)
6506       (pop-to-buffer gnus-group-buffer)
6507       (if (not quit-config)
6508           (progn
6509             (goto-char group-point)
6510             (gnus-configure-windows 'group 'force)
6511             (unless (pos-visible-in-window-p)
6512               (forward-line (/ (static-if (featurep 'xemacs)
6513                                    (window-displayed-height)
6514                                  (1- (window-height)))
6515                                -2))
6516               (set-window-start (selected-window) (point))
6517               (goto-char group-point)))
6518         (gnus-handle-ephemeral-exit quit-config))
6519       ;; Clear the current group name.
6520       (unless quit-config
6521         (setq gnus-newsgroup-name nil)))))
6522
6523 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6524 (defun gnus-summary-exit-no-update (&optional no-questions)
6525   "Quit reading current newsgroup without updating read article info."
6526   (interactive)
6527   (let* ((group gnus-newsgroup-name)
6528          (gnus-group-is-exiting-p t)
6529          (gnus-group-is-exiting-without-update-p t)
6530          (quit-config (gnus-group-quit-config group)))
6531     (when (or no-questions
6532               gnus-expert-user
6533               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6534       (gnus-async-halt-prefetch)
6535       (run-hooks 'gnus-summary-prepare-exit-hook)
6536       ;; If we have several article buffers, we kill them at exit.
6537       (unless gnus-single-article-buffer
6538         (gnus-kill-buffer gnus-article-buffer)
6539         (gnus-kill-buffer gnus-original-article-buffer)
6540         (setq gnus-article-current nil))
6541       (if (not gnus-kill-summary-on-exit)
6542           (gnus-deaden-summary)
6543         (gnus-close-group group)
6544         (gnus-summary-clear-local-variables)
6545         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6546           (gnus-summary-clear-local-variables))
6547         (set-buffer gnus-group-buffer)
6548         (gnus-summary-clear-local-variables)
6549         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6550           (gnus-summary-clear-local-variables))
6551         (gnus-kill-buffer gnus-summary-buffer))
6552       (unless gnus-single-article-buffer
6553         (setq gnus-article-current nil))
6554       (when gnus-use-trees
6555         (gnus-tree-close group))
6556       (gnus-async-prefetch-remove-group group)
6557       (when (get-buffer gnus-article-buffer)
6558         (bury-buffer gnus-article-buffer))
6559       ;; Return to the group buffer.
6560       (gnus-configure-windows 'group 'force)
6561       ;; Clear the current group name.
6562       (setq gnus-newsgroup-name nil)
6563       (unless (gnus-ephemeral-group-p group)
6564         (gnus-group-update-group group))
6565       (when (equal (gnus-group-group-name) group)
6566         (gnus-group-next-unread-group 1))
6567       (when quit-config
6568         (gnus-handle-ephemeral-exit quit-config)))))
6569
6570 (defun gnus-handle-ephemeral-exit (quit-config)
6571   "Handle movement when leaving an ephemeral group.
6572 The state which existed when entering the ephemeral is reset."
6573   (if (not (buffer-name (car quit-config)))
6574       (gnus-configure-windows 'group 'force)
6575     (set-buffer (car quit-config))
6576     (cond ((eq major-mode 'gnus-summary-mode)
6577            (gnus-set-global-variables))
6578           ((eq major-mode 'gnus-article-mode)
6579            (save-excursion
6580              ;; The `gnus-summary-buffer' variable may point
6581              ;; to the old summary buffer when using a single
6582              ;; article buffer.
6583              (unless (gnus-buffer-live-p gnus-summary-buffer)
6584                (set-buffer gnus-group-buffer))
6585              (set-buffer gnus-summary-buffer)
6586              (gnus-set-global-variables))))
6587     (if (or (eq (cdr quit-config) 'article)
6588             (eq (cdr quit-config) 'pick))
6589         (progn
6590           ;; The current article may be from the ephemeral group
6591           ;; thus it is best that we reload this article
6592           (gnus-summary-show-article)
6593           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6594               (gnus-configure-windows 'pick 'force)
6595             (gnus-configure-windows (cdr quit-config) 'force)))
6596       (gnus-configure-windows (cdr quit-config) 'force))
6597     (when (eq major-mode 'gnus-summary-mode)
6598       (gnus-summary-next-subject 1 nil t)
6599       (gnus-summary-recenter)
6600       (gnus-summary-position-point))))
6601
6602 (defun gnus-summary-preview-mime-message ()
6603   "MIME decode and play this message."
6604   (interactive)
6605   (let ((gnus-break-pages nil)
6606         (gnus-show-mime t))
6607     (gnus-summary-select-article gnus-show-all-headers t))
6608   (let ((w (get-buffer-window gnus-article-buffer)))
6609     (when w
6610       (select-window (get-buffer-window gnus-article-buffer)))))
6611
6612 ;;; Dead summaries.
6613
6614 (defvar gnus-dead-summary-mode-map nil)
6615
6616 (unless gnus-dead-summary-mode-map
6617   (setq gnus-dead-summary-mode-map (make-keymap))
6618   (suppress-keymap gnus-dead-summary-mode-map)
6619   (substitute-key-definition
6620    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6621   (dolist (key '("\C-d" "\r" "\177" [delete]))
6622     (define-key gnus-dead-summary-mode-map
6623       key 'gnus-summary-wake-up-the-dead))
6624   (dolist (key '("q" "Q"))
6625     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6626
6627 (defvar gnus-dead-summary-mode nil
6628   "Minor mode for Gnus summary buffers.")
6629
6630 (defun gnus-dead-summary-mode (&optional arg)
6631   "Minor mode for Gnus summary buffers."
6632   (interactive "P")
6633   (when (eq major-mode 'gnus-summary-mode)
6634     (make-local-variable 'gnus-dead-summary-mode)
6635     (setq gnus-dead-summary-mode
6636           (if (null arg) (not gnus-dead-summary-mode)
6637             (> (prefix-numeric-value arg) 0)))
6638     (when gnus-dead-summary-mode
6639       (gnus-add-minor-mode
6640        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6641
6642 (defun gnus-deaden-summary ()
6643   "Make the current summary buffer into a dead summary buffer."
6644   ;; Kill any previous dead summary buffer.
6645   (when (and gnus-dead-summary
6646              (buffer-name gnus-dead-summary))
6647     (save-excursion
6648       (set-buffer gnus-dead-summary)
6649       (when gnus-dead-summary-mode
6650         (kill-buffer (current-buffer)))))
6651   ;; Make this the current dead summary.
6652   (setq gnus-dead-summary (current-buffer))
6653   (gnus-dead-summary-mode 1)
6654   (let ((name (buffer-name)))
6655     (when (string-match "Summary" name)
6656       (rename-buffer
6657        (concat (substring name 0 (match-beginning 0)) "Dead "
6658                (substring name (match-beginning 0)))
6659        t)
6660       (bury-buffer))))
6661
6662 (defun gnus-kill-or-deaden-summary (buffer)
6663   "Kill or deaden the summary BUFFER."
6664   (save-excursion
6665     (when (and (buffer-name buffer)
6666                (not gnus-single-article-buffer))
6667       (save-excursion
6668         (set-buffer buffer)
6669         (gnus-kill-buffer gnus-article-buffer)
6670         (gnus-kill-buffer gnus-original-article-buffer)))
6671     (cond
6672      ;; Kill the buffer.
6673      (gnus-kill-summary-on-exit
6674       (when (and gnus-use-trees
6675                  (gnus-buffer-exists-p buffer))
6676         (save-excursion
6677           (set-buffer buffer)
6678           (gnus-tree-close gnus-newsgroup-name)))
6679       (gnus-kill-buffer buffer))
6680      ;; Deaden the buffer.
6681      ((gnus-buffer-exists-p buffer)
6682       (save-excursion
6683         (set-buffer buffer)
6684         (gnus-deaden-summary))))))
6685
6686 (defun gnus-summary-wake-up-the-dead (&rest args)
6687   "Wake up the dead summary buffer."
6688   (interactive)
6689   (gnus-dead-summary-mode -1)
6690   (let ((name (buffer-name)))
6691     (when (string-match "Dead " name)
6692       (rename-buffer
6693        (concat (substring name 0 (match-beginning 0))
6694                (substring name (match-end 0)))
6695        t)))
6696   (gnus-message 3 "This dead summary is now alive again"))
6697
6698 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6699 (defun gnus-summary-fetch-faq (&optional faq-dir)
6700   "Fetch the FAQ for the current group.
6701 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6702 in."
6703   (interactive
6704    (list
6705     (when current-prefix-arg
6706       (completing-read
6707        "FAQ dir: " (and (listp gnus-group-faq-directory)
6708                         (mapcar (lambda (file) (list file))
6709                                 gnus-group-faq-directory))))))
6710   (let (gnus-faq-buffer)
6711     (when (setq gnus-faq-buffer
6712                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6713       (gnus-configure-windows 'summary-faq))))
6714
6715 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6716 (defun gnus-summary-describe-group (&optional force)
6717   "Describe the current newsgroup."
6718   (interactive "P")
6719   (gnus-group-describe-group force gnus-newsgroup-name))
6720
6721 (defun gnus-summary-describe-briefly ()
6722   "Describe summary mode commands briefly."
6723   (interactive)
6724   (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")))
6725
6726 ;; Walking around group mode buffer from summary mode.
6727
6728 (defun gnus-summary-next-group (&optional no-article target-group backward)
6729   "Exit current newsgroup and then select next unread newsgroup.
6730 If prefix argument NO-ARTICLE is non-nil, no article is selected
6731 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6732 previous group instead."
6733   (interactive "P")
6734   ;; Stop pre-fetching.
6735   (gnus-async-halt-prefetch)
6736   (let ((current-group gnus-newsgroup-name)
6737         (current-buffer (current-buffer))
6738         entered)
6739     ;; First we semi-exit this group to update Xrefs and all variables.
6740     ;; We can't do a real exit, because the window conf must remain
6741     ;; the same in case the user is prompted for info, and we don't
6742     ;; want the window conf to change before that...
6743     (gnus-summary-exit t)
6744     (while (not entered)
6745       ;; Then we find what group we are supposed to enter.
6746       (set-buffer gnus-group-buffer)
6747       (gnus-group-jump-to-group current-group)
6748       (setq target-group
6749             (or target-group
6750                 (if (eq gnus-keep-same-level 'best)
6751                     (gnus-summary-best-group gnus-newsgroup-name)
6752                   (gnus-summary-search-group backward gnus-keep-same-level))))
6753       (if (not target-group)
6754           ;; There are no further groups, so we return to the group
6755           ;; buffer.
6756           (progn
6757             (gnus-message 5 "Returning to the group buffer")
6758             (setq entered t)
6759             (when (gnus-buffer-live-p current-buffer)
6760               (set-buffer current-buffer)
6761               (gnus-summary-exit))
6762             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6763         ;; We try to enter the target group.
6764         (gnus-group-jump-to-group target-group)
6765         (let ((unreads (gnus-group-group-unread)))
6766           (if (and (or (eq t unreads)
6767                        (and unreads (not (zerop unreads))))
6768                    (gnus-summary-read-group
6769                     target-group nil no-article
6770                     (and (buffer-name current-buffer) current-buffer)
6771                     nil backward))
6772               (setq entered t)
6773             (setq current-group target-group
6774                   target-group nil)))))))
6775
6776 (defun gnus-summary-prev-group (&optional no-article)
6777   "Exit current newsgroup and then select previous unread newsgroup.
6778 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6779   (interactive "P")
6780   (gnus-summary-next-group no-article nil t))
6781
6782 ;; Walking around summary lines.
6783
6784 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6785   "Go to the first subject satisfying any non-nil constraint.
6786 If UNREAD is non-nil, the article should be unread.
6787 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6788 If UNSEED is non-nil, the article should be unseen.
6789 Returns the article selected or nil if there are no matching articles."
6790   (interactive "P")
6791   (cond
6792    ;; Empty summary.
6793    ((null gnus-newsgroup-data)
6794     (gnus-message 3 "No articles in the group")
6795     nil)
6796    ;; Pick the first article.
6797    ((not (or unread undownloaded unseen))
6798     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6799     (gnus-data-number (car gnus-newsgroup-data)))
6800    ;; Find the first unread article.
6801    (t
6802     (let ((data gnus-newsgroup-data))
6803       (while (and data
6804                   (let ((num (gnus-data-number (car data))))
6805                     (or (memq num gnus-newsgroup-unfetched)
6806                         (not (or (and unread
6807                                       (memq num gnus-newsgroup-unreads))
6808                                  (and undownloaded
6809                                       (memq num gnus-newsgroup-undownloaded))
6810                                  (and unseen
6811                                       (memq num gnus-newsgroup-unseen)))))))
6812         (setq data (cdr data)))
6813       (prog1 
6814           (if data
6815               (progn
6816                 (goto-char (gnus-data-pos (car data)))
6817                 (gnus-data-number (car data)))
6818             (gnus-message 3 "No more%s articles"
6819                           (let* ((r (when unread " unread"))
6820                                  (d (when undownloaded " undownloaded"))
6821                                  (s (when unseen " unseen"))
6822                                  (l (delq nil (list r d s))))
6823                             (cond ((= 3 (length l))
6824                                    (concat r "," d ", or" s))
6825                                   ((= 2 (length l))
6826                                    (concat (car l) ", or" (cadr l)))
6827                                   ((= 1 (length l))
6828                                    (car l))
6829                                   (t
6830                                    ""))))
6831             nil
6832             )
6833         (gnus-summary-position-point))))))
6834
6835 (defun gnus-summary-next-subject (n &optional unread dont-display)
6836   "Go to next N'th summary line.
6837 If N is negative, go to the previous N'th subject line.
6838 If UNREAD is non-nil, only unread articles are selected.
6839 The difference between N and the actual number of steps taken is
6840 returned."
6841   (interactive "p")
6842   (let ((backward (< n 0))
6843         (n (abs n)))
6844     (while (and (> n 0)
6845                 (if backward
6846                     (gnus-summary-find-prev unread)
6847                   (gnus-summary-find-next unread)))
6848       (unless (zerop (setq n (1- n)))
6849         (gnus-summary-show-thread)))
6850     (when (/= 0 n)
6851       (gnus-message 7 "No more%s articles"
6852                     (if unread " unread" "")))
6853     (unless dont-display
6854       (gnus-summary-recenter)
6855       (gnus-summary-position-point))
6856     n))
6857
6858 (defun gnus-summary-next-unread-subject (n)
6859   "Go to next N'th unread summary line."
6860   (interactive "p")
6861   (gnus-summary-next-subject n t))
6862
6863 (defun gnus-summary-prev-subject (n &optional unread)
6864   "Go to previous N'th summary line.
6865 If optional argument UNREAD is non-nil, only unread article is selected."
6866   (interactive "p")
6867   (gnus-summary-next-subject (- n) unread))
6868
6869 (defun gnus-summary-prev-unread-subject (n)
6870   "Go to previous N'th unread summary line."
6871   (interactive "p")
6872   (gnus-summary-next-subject (- n) t))
6873
6874 (defun gnus-summary-goto-subjects (articles)
6875   "Insert the subject header for ARTICLES in the current buffer."
6876   (save-excursion
6877     (dolist (article articles)
6878       (gnus-summary-goto-subject article t)))
6879   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6880   (gnus-summary-position-point))
6881  
6882 (defun gnus-summary-goto-subject (article &optional force silent)
6883   "Go the subject line of ARTICLE.
6884 If FORCE, also allow jumping to articles not currently shown."
6885   (interactive "nArticle number: ")
6886   (unless (numberp article)
6887     (error "Article %s is not a number" article))
6888   (let ((b (point))
6889         (data (gnus-data-find article)))
6890     ;; We read in the article if we have to.
6891     (and (not data)
6892          force
6893          (gnus-summary-insert-subject
6894           article
6895           (if (or (numberp force) (vectorp force)) force)
6896           t)
6897          (setq data (gnus-data-find article)))
6898     (goto-char b)
6899     (if (not data)
6900         (progn
6901           (unless silent
6902             (gnus-message 3 "Can't find article %d" article))
6903           nil)
6904       (let ((pt (gnus-data-pos data)))
6905         (goto-char pt)
6906         (gnus-summary-set-article-display-arrow pt))
6907       (gnus-summary-position-point)
6908       article)))
6909
6910 ;; Walking around summary lines with displaying articles.
6911
6912 (defun gnus-summary-expand-window (&optional arg)
6913   "Make the summary buffer take up the entire Emacs frame.
6914 Given a prefix, will force an `article' buffer configuration."
6915   (interactive "P")
6916   (if arg
6917       (gnus-configure-windows 'article 'force)
6918     (gnus-configure-windows 'summary 'force)))
6919
6920 (defun gnus-summary-display-article (article &optional all-header)
6921   "Display ARTICLE in article buffer."
6922   (when (gnus-buffer-live-p gnus-article-buffer)
6923     (with-current-buffer gnus-article-buffer
6924       (set-buffer-multibyte t)))
6925   (gnus-set-global-variables)
6926   (when (gnus-buffer-live-p gnus-article-buffer)
6927     (with-current-buffer gnus-article-buffer
6928       (setq gnus-article-charset gnus-newsgroup-charset)
6929       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6930       (set-buffer-multibyte t)))
6931   (if (null article)
6932       nil
6933     (prog1
6934         (if gnus-summary-display-article-function
6935             (funcall gnus-summary-display-article-function article all-header)
6936           (gnus-article-prepare article all-header))
6937       (with-current-buffer gnus-article-buffer
6938         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6939              nil))
6940       (gnus-run-hooks 'gnus-select-article-hook)
6941       (when (and gnus-current-article
6942                  (not (zerop gnus-current-article)))
6943         (gnus-summary-goto-subject gnus-current-article))
6944       (gnus-summary-recenter)
6945       (when (and gnus-use-trees gnus-show-threads)
6946         (gnus-possibly-generate-tree article)
6947         (gnus-highlight-selected-tree article))
6948       ;; Successfully display article.
6949       (gnus-article-set-window-start
6950        (cdr (assq article gnus-newsgroup-bookmarks))))))
6951
6952 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6953   "Select the current article.
6954 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6955 non-nil, the article will be re-fetched even if it already present in
6956 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6957 be displayed."
6958   ;; Make sure we are in the summary buffer to work around bbdb bug.
6959   (unless (eq major-mode 'gnus-summary-mode)
6960     (set-buffer gnus-summary-buffer))
6961   (let ((article (or article (gnus-summary-article-number)))
6962         (all-headers (not (not all-headers))) ;Must be T or NIL.
6963         gnus-summary-display-article-function)
6964     (and (not pseudo)
6965          (gnus-summary-article-pseudo-p article)
6966          (error "This is a pseudo-article"))
6967     (save-excursion
6968       (set-buffer gnus-summary-buffer)
6969       (if (or (and gnus-single-article-buffer
6970                    (or (null gnus-current-article)
6971                        (null gnus-article-current)
6972                        (null (get-buffer gnus-article-buffer))
6973                        (not (eq article (cdr gnus-article-current)))
6974                        (not (equal (car gnus-article-current)
6975                                    gnus-newsgroup-name))))
6976               (and (not gnus-single-article-buffer)
6977                    (or (null gnus-current-article)
6978                        (not (eq gnus-current-article article))))
6979               force)
6980           ;; The requested article is different from the current article.
6981           (progn
6982             (gnus-summary-display-article article all-headers)
6983             (gnus-article-set-window-start
6984              (cdr (assq article gnus-newsgroup-bookmarks)))
6985             article)
6986         'old))))
6987
6988 (defun gnus-summary-force-verify-and-decrypt ()
6989   "Display buttons for signed/encrypted parts and verify/decrypt them."
6990   (interactive)
6991   (let ((mm-verify-option 'known)
6992         (mm-decrypt-option 'known)
6993         (gnus-buttonized-mime-types (append (list "multipart/signed"
6994                                                   "multipart/encrypted")
6995                                             gnus-buttonized-mime-types)))
6996     (gnus-summary-select-article nil 'force)))
6997
6998 (defun gnus-summary-set-current-mark (&optional current-mark)
6999   "Obsolete function."
7000   nil)
7001
7002 (defun gnus-summary-next-article (&optional unread subject backward push)
7003   "Select the next article.
7004 If UNREAD, only unread articles are selected.
7005 If SUBJECT, only articles with SUBJECT are selected.
7006 If BACKWARD, the previous article is selected instead of the next."
7007   (interactive "P")
7008   (cond
7009    ;; Is there such an article?
7010    ((and (gnus-summary-search-forward unread subject backward)
7011          (or (gnus-summary-display-article (gnus-summary-article-number))
7012              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7013     (gnus-summary-position-point))
7014    ;; If not, we try the first unread, if that is wanted.
7015    ((and subject
7016          gnus-auto-select-same
7017          (gnus-summary-first-unread-article))
7018     (gnus-summary-position-point)
7019     (gnus-message 6 "Wrapped"))
7020    ;; Try to get next/previous article not displayed in this group.
7021    ((and gnus-auto-extend-newsgroup
7022          (not unread) (not subject))
7023     (gnus-summary-goto-article
7024      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7025      nil (count-lines (point-min) (point))))
7026    ;; Go to next/previous group.
7027    (t
7028     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7029       (gnus-summary-jump-to-group gnus-newsgroup-name))
7030     (let ((cmd last-command-char)
7031           (point
7032            (save-excursion
7033              (set-buffer gnus-group-buffer)
7034              (point)))
7035           (group
7036            (if (eq gnus-keep-same-level 'best)
7037                (gnus-summary-best-group gnus-newsgroup-name)
7038              (gnus-summary-search-group backward gnus-keep-same-level))))
7039       ;; For some reason, the group window gets selected.  We change
7040       ;; it back.
7041       (select-window (get-buffer-window (current-buffer)))
7042       ;; Select next unread newsgroup automagically.
7043       (cond
7044        ((or (not gnus-auto-select-next)
7045             (not cmd))
7046         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7047        ((or (eq gnus-auto-select-next 'quietly)
7048             (and (eq gnus-auto-select-next 'slightly-quietly)
7049                  push)
7050             (and (eq gnus-auto-select-next 'almost-quietly)
7051                  (gnus-summary-last-article-p)))
7052         ;; Select quietly.
7053         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7054             (gnus-summary-exit)
7055           (gnus-message 7 "No more%s articles (%s)..."
7056                         (if unread " unread" "")
7057                         (if group (concat "selecting " group)
7058                           "exiting"))
7059           (gnus-summary-next-group nil group backward)))
7060        (t
7061         (when (gnus-key-press-event-p last-input-event)
7062           (gnus-summary-walk-group-buffer
7063            gnus-newsgroup-name cmd unread backward point))))))))
7064
7065 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7066   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7067                       (?\C-p (gnus-group-prev-unread-group 1))))
7068         (cursor-in-echo-area t)
7069         keve key group ended prompt)
7070     (save-excursion
7071       (set-buffer gnus-group-buffer)
7072       (goto-char start)
7073       (setq group
7074             (if (eq gnus-keep-same-level 'best)
7075                 (gnus-summary-best-group gnus-newsgroup-name)
7076               (gnus-summary-search-group backward gnus-keep-same-level))))
7077     (while (not ended)
7078       (setq prompt
7079             (format
7080              "No more%s articles%s " (if unread " unread" "")
7081              (if (and group
7082                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7083                  (format " (Type %s for %s [%s])"
7084                          (single-key-description cmd) group
7085                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7086                (format " (Type %s to exit %s)"
7087                        (single-key-description cmd)
7088                        gnus-newsgroup-name))))
7089       ;; Confirm auto selection.
7090       (setq key (car (setq keve (gnus-read-event-char prompt)))
7091             ended t)
7092       (cond
7093        ((assq key keystrokes)
7094         (let ((obuf (current-buffer)))
7095           (switch-to-buffer gnus-group-buffer)
7096           (when group
7097             (gnus-group-jump-to-group group))
7098           (eval (cadr (assq key keystrokes)))
7099           (setq group (gnus-group-group-name))
7100           (switch-to-buffer obuf))
7101         (setq ended nil))
7102        ((equal key cmd)
7103         (if (or (not group)
7104                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7105             (gnus-summary-exit)
7106           (gnus-summary-next-group nil group backward)))
7107        (t
7108         (push (cdr keve) unread-command-events))))))
7109
7110 (defun gnus-summary-next-unread-article ()
7111   "Select unread article after current one."
7112   (interactive)
7113   (gnus-summary-next-article
7114    (or (not (eq gnus-summary-goto-unread 'never))
7115        (gnus-summary-last-article-p (gnus-summary-article-number)))
7116    (and gnus-auto-select-same
7117         (gnus-summary-article-subject))))
7118
7119 (defun gnus-summary-prev-article (&optional unread subject)
7120   "Select the article after the current one.
7121 If UNREAD is non-nil, only unread articles are selected."
7122   (interactive "P")
7123   (gnus-summary-next-article unread subject t))
7124
7125 (defun gnus-summary-prev-unread-article ()
7126   "Select unread article before current one."
7127   (interactive)
7128   (gnus-summary-prev-article
7129    (or (not (eq gnus-summary-goto-unread 'never))
7130        (gnus-summary-first-article-p (gnus-summary-article-number)))
7131    (and gnus-auto-select-same
7132         (gnus-summary-article-subject))))
7133
7134 (defun gnus-summary-next-page (&optional lines circular stop)
7135   "Show next page of the selected article.
7136 If at the end of the current article, select the next article.
7137 LINES says how many lines should be scrolled up.
7138
7139 If CIRCULAR is non-nil, go to the start of the article instead of
7140 selecting the next article when reaching the end of the current
7141 article.
7142
7143 If STOP is non-nil, just stop when reaching the end of the message."
7144   (interactive "P")
7145   (setq gnus-summary-buffer (current-buffer))
7146   (gnus-set-global-variables)
7147   (let ((article (gnus-summary-article-number))
7148         (article-window (get-buffer-window gnus-article-buffer t))
7149         endp)
7150     ;; If the buffer is empty, we have no article.
7151     (unless article
7152       (error "No article to select"))
7153     (gnus-configure-windows 'article)
7154     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7155         (if (and (eq gnus-summary-goto-unread 'never)
7156                  (not (gnus-summary-last-article-p article)))
7157             (gnus-summary-next-article)
7158           (gnus-summary-next-unread-article))
7159       (if (or (null gnus-current-article)
7160               (null gnus-article-current)
7161               (/= article (cdr gnus-article-current))
7162               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7163           ;; Selected subject is different from current article's.
7164           (gnus-summary-display-article article)
7165         (when article-window
7166           (gnus-eval-in-buffer-window gnus-article-buffer
7167             (setq endp (or (gnus-article-next-page lines)
7168                            (gnus-article-only-boring-p))))
7169           (when endp
7170             (cond (stop
7171                    (gnus-message 3 "End of message"))
7172                   (circular
7173                    (gnus-summary-beginning-of-article))
7174                   (lines
7175                    (gnus-message 3 "End of message"))
7176                   ((null lines)
7177                    (if (and (eq gnus-summary-goto-unread 'never)
7178                             (not (gnus-summary-last-article-p article)))
7179                        (gnus-summary-next-article)
7180                      (gnus-summary-next-unread-article))))))))
7181     (gnus-summary-recenter)
7182     (gnus-summary-position-point)))
7183
7184 (defun gnus-summary-prev-page (&optional lines move)
7185   "Show previous page of selected article.
7186 Argument LINES specifies lines to be scrolled down.
7187 If MOVE, move to the previous unread article if point is at
7188 the beginning of the buffer."
7189   (interactive "P")
7190   (let ((article (gnus-summary-article-number))
7191         (article-window (get-buffer-window gnus-article-buffer t))
7192         endp)
7193     (gnus-configure-windows 'article)
7194     (if (or (null gnus-current-article)
7195             (null gnus-article-current)
7196             (/= article (cdr gnus-article-current))
7197             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7198         ;; Selected subject is different from current article's.
7199         (gnus-summary-display-article article)
7200       (gnus-summary-recenter)
7201       (when article-window
7202         (gnus-eval-in-buffer-window gnus-article-buffer
7203           (setq endp (gnus-article-prev-page lines)))
7204         (when (and move endp)
7205           (cond (lines
7206                  (gnus-message 3 "Beginning of message"))
7207                 ((null lines)
7208                  (if (and (eq gnus-summary-goto-unread 'never)
7209                           (not (gnus-summary-first-article-p article)))
7210                      (gnus-summary-prev-article)
7211                    (gnus-summary-prev-unread-article))))))))
7212   (gnus-summary-position-point))
7213
7214 (defun gnus-summary-prev-page-or-article (&optional lines)
7215   "Show previous page of selected article.
7216 Argument LINES specifies lines to be scrolled down.
7217 If at the beginning of the article, go to the next article."
7218   (interactive "P")
7219   (gnus-summary-prev-page lines t))
7220
7221 (defun gnus-summary-scroll-up (lines)
7222   "Scroll up (or down) one line current article.
7223 Argument LINES specifies lines to be scrolled up (or down if negative)."
7224   (interactive "p")
7225   (gnus-configure-windows 'article)
7226   (gnus-summary-show-thread)
7227   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7228     (gnus-eval-in-buffer-window gnus-article-buffer
7229       (cond ((> lines 0)
7230              (when (gnus-article-next-page lines)
7231                (gnus-message 3 "End of message")))
7232             ((< lines 0)
7233              (gnus-article-prev-page (- lines))))))
7234   (gnus-summary-recenter)
7235   (gnus-summary-position-point))
7236
7237 (defun gnus-summary-scroll-down (lines)
7238   "Scroll down (or up) one line current article.
7239 Argument LINES specifies lines to be scrolled down (or up if negative)."
7240   (interactive "p")
7241   (gnus-summary-scroll-up (- lines)))
7242
7243 (defun gnus-summary-next-same-subject ()
7244   "Select next article which has the same subject as current one."
7245   (interactive)
7246   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7247
7248 (defun gnus-summary-prev-same-subject ()
7249   "Select previous article which has the same subject as current one."
7250   (interactive)
7251   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7252
7253 (defun gnus-summary-next-unread-same-subject ()
7254   "Select next unread article which has the same subject as current one."
7255   (interactive)
7256   (gnus-summary-next-article t (gnus-summary-article-subject)))
7257
7258 (defun gnus-summary-prev-unread-same-subject ()
7259   "Select previous unread article which has the same subject as current one."
7260   (interactive)
7261   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7262
7263 (defun gnus-summary-first-unread-article ()
7264   "Select the first unread article.
7265 Return nil if there are no unread articles."
7266   (interactive)
7267   (prog1
7268       (when (gnus-summary-first-subject t)
7269         (gnus-summary-show-thread)
7270         (gnus-summary-first-subject t)
7271         (gnus-summary-display-article (gnus-summary-article-number)))
7272     (gnus-summary-position-point)))
7273
7274 (defun gnus-summary-first-unread-subject ()
7275   "Place the point on the subject line of the first unread article.
7276 Return nil if there are no unread articles."
7277   (interactive)
7278   (prog1
7279       (when (gnus-summary-first-subject t)
7280         (gnus-summary-show-thread)
7281         (gnus-summary-first-subject t))
7282     (gnus-summary-position-point)))
7283
7284 (defun gnus-summary-first-unseen-subject ()
7285   "Place the point on the subject line of the first unseen article.
7286 Return nil if there are no unseen articles."
7287   (interactive)
7288   (prog1
7289       (when (gnus-summary-first-subject nil nil t)
7290         (gnus-summary-show-thread)
7291         (gnus-summary-first-subject nil nil t))
7292     (gnus-summary-position-point)))
7293
7294 (defun gnus-summary-first-unseen-or-unread-subject ()
7295   "Place the point on the subject line of the first unseen article or,
7296 if all article have been seen, on the subject line of the first unread
7297 article."
7298   (interactive)
7299   (prog1
7300       (unless (when (gnus-summary-first-subject nil nil t)
7301                 (gnus-summary-show-thread)
7302                 (gnus-summary-first-subject nil nil t))
7303         (when (gnus-summary-first-subject t)
7304           (gnus-summary-show-thread)
7305           (gnus-summary-first-subject t)))
7306     (gnus-summary-position-point)))
7307
7308 (defun gnus-summary-first-article ()
7309   "Select the first article.
7310 Return nil if there are no articles."
7311   (interactive)
7312   (prog1
7313       (when (gnus-summary-first-subject)
7314         (gnus-summary-show-thread)
7315         (gnus-summary-first-subject)
7316         (gnus-summary-display-article (gnus-summary-article-number)))
7317     (gnus-summary-position-point)))
7318
7319 (defun gnus-summary-best-unread-article (&optional arg)
7320   "Select the unread article with the highest score.
7321 If given a prefix argument, select the next unread article that has a
7322 score higher than the default score."
7323   (interactive "P")
7324   (let ((article (if arg
7325                      (gnus-summary-better-unread-subject)
7326                    (gnus-summary-best-unread-subject))))
7327     (if article
7328         (gnus-summary-goto-article article)
7329       (error "No unread articles"))))
7330
7331 (defun gnus-summary-best-unread-subject ()
7332   "Select the unread subject with the highest score."
7333   (interactive)
7334   (let ((best -1000000)
7335         (data gnus-newsgroup-data)
7336         article score)
7337     (while data
7338       (and (gnus-data-unread-p (car data))
7339            (> (setq score
7340                     (gnus-summary-article-score (gnus-data-number (car data))))
7341               best)
7342            (setq best score
7343                  article (gnus-data-number (car data))))
7344       (setq data (cdr data)))
7345     (when article
7346       (gnus-summary-goto-subject article))
7347     (gnus-summary-position-point)
7348     article))
7349
7350 (defun gnus-summary-better-unread-subject ()
7351   "Select the first unread subject that has a score over the default score."
7352   (interactive)
7353   (let ((data gnus-newsgroup-data)
7354         article score)
7355     (while (and (setq article (gnus-data-number (car data)))
7356                 (or (gnus-data-read-p (car data))
7357                     (not (> (gnus-summary-article-score article)
7358                             gnus-summary-default-score))))
7359       (setq data (cdr data)))
7360     (when article
7361       (gnus-summary-goto-subject article))
7362     (gnus-summary-position-point)
7363     article))
7364
7365 (defun gnus-summary-last-subject ()
7366   "Go to the last displayed subject line in the group."
7367   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7368     (when article
7369       (gnus-summary-goto-subject article))))
7370
7371 (defun gnus-summary-goto-article (article &optional all-headers force)
7372   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7373 If ALL-HEADERS is non-nil, no header lines are hidden.
7374 If FORCE, go to the article even if it isn't displayed.  If FORCE
7375 is a number, it is the line the article is to be displayed on."
7376   (interactive
7377    (list
7378     (completing-read
7379      "Article number or Message-ID: "
7380      (mapcar (lambda (number) (list (int-to-string number)))
7381              gnus-newsgroup-limit))
7382     current-prefix-arg
7383     t))
7384   (prog1
7385       (if (and (stringp article)
7386                (string-match "@" article))
7387           (gnus-summary-refer-article article)
7388         (when (stringp article)
7389           (setq article (string-to-number article)))
7390         (if (gnus-summary-goto-subject article force)
7391             (gnus-summary-display-article article all-headers)
7392           (gnus-message 4 "Couldn't go to article %s" article) nil))
7393     (gnus-summary-position-point)))
7394
7395 (defun gnus-summary-goto-last-article ()
7396   "Go to the previously read article."
7397   (interactive)
7398   (prog1
7399       (when gnus-last-article
7400         (gnus-summary-goto-article gnus-last-article nil t))
7401     (gnus-summary-position-point)))
7402
7403 (defun gnus-summary-pop-article (number)
7404   "Pop one article off the history and go to the previous.
7405 NUMBER articles will be popped off."
7406   (interactive "p")
7407   (let (to)
7408     (setq gnus-newsgroup-history
7409           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7410     (if to
7411         (gnus-summary-goto-article (car to) nil t)
7412       (error "Article history empty")))
7413   (gnus-summary-position-point))
7414
7415 ;; Summary commands and functions for limiting the summary buffer.
7416
7417 (defun gnus-summary-limit-to-articles (n)
7418   "Limit the summary buffer to the next N articles.
7419 If not given a prefix, use the process marked articles instead."
7420   (interactive "P")
7421   (prog1
7422       (let ((articles (gnus-summary-work-articles n)))
7423         (setq gnus-newsgroup-processable nil)
7424         (gnus-summary-limit articles))
7425     (gnus-summary-position-point)))
7426
7427 (defun gnus-summary-pop-limit (&optional total)
7428   "Restore the previous limit.
7429 If given a prefix, remove all limits."
7430   (interactive "P")
7431   (when total
7432     (setq gnus-newsgroup-limits
7433           (list (mapcar (lambda (h) (mail-header-number h))
7434                         gnus-newsgroup-headers))))
7435   (unless gnus-newsgroup-limits
7436     (error "No limit to pop"))
7437   (prog1
7438       (gnus-summary-limit nil 'pop)
7439     (gnus-summary-position-point)))
7440
7441 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7442   "Limit the summary buffer to articles that have subjects that match a regexp.
7443 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7444   (interactive
7445    (list (read-string (if current-prefix-arg
7446                           "Exclude subject (regexp): "
7447                         "Limit to subject (regexp): "))
7448          nil current-prefix-arg))
7449   (unless header
7450     (setq header "subject"))
7451   (when (not (equal "" subject))
7452     (prog1
7453         (let ((articles (gnus-summary-find-matching
7454                          (or header "subject") subject 'all nil nil
7455                          not-matching)))
7456           (unless articles
7457             (error "Found no matches for \"%s\"" subject))
7458           (gnus-summary-limit articles))
7459       (gnus-summary-position-point))))
7460
7461 (defun gnus-summary-limit-to-author (from &optional not-matching)
7462   "Limit the summary buffer to articles that have authors that match a regexp.
7463 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7464   (interactive
7465    (list (read-string (if current-prefix-arg
7466                           "Exclude author (regexp): "
7467                         "Limit to author (regexp): "))
7468          current-prefix-arg))
7469   (gnus-summary-limit-to-subject from "from" not-matching))
7470
7471 (defun gnus-summary-limit-to-age (age &optional younger-p)
7472   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7473 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7474 articles that are younger than AGE days."
7475   (interactive
7476    (let ((younger current-prefix-arg)
7477          (days-got nil)
7478          days)
7479      (while (not days-got)
7480        (setq days (if younger
7481                       (read-string "Limit to articles younger than (in days, older when negative): ")
7482                     (read-string
7483                      "Limit to articles older than (in days, younger when negative): ")))
7484        (when (> (length days) 0)
7485          (setq days (read days)))
7486        (if (numberp days)
7487            (progn
7488              (setq days-got t)
7489              (if (< days 0)
7490                  (progn
7491                    (setq younger (not younger))
7492                    (setq days (* days -1)))))
7493          (message "Please enter a number.")
7494          (sleep-for 1)))
7495      (list days younger)))
7496   (prog1
7497       (let ((data gnus-newsgroup-data)
7498             (cutoff (days-to-time age))
7499             articles d date is-younger)
7500         (while (setq d (pop data))
7501           (when (and (vectorp (gnus-data-header d))
7502                      (setq date (mail-header-date (gnus-data-header d))))
7503             (setq is-younger (time-less-p
7504                               (time-since (condition-case ()
7505                                               (date-to-time date)
7506                                             (error '(0 0))))
7507                               cutoff))
7508             (when (if younger-p
7509                       is-younger
7510                     (not is-younger))
7511               (push (gnus-data-number d) articles))))
7512         (gnus-summary-limit (nreverse articles)))
7513     (gnus-summary-position-point)))
7514
7515 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7516   "Limit the summary buffer to articles that match an 'extra' header."
7517   (interactive
7518    (let ((header
7519           (intern
7520            (gnus-completing-read-with-default
7521             (symbol-name (car gnus-extra-headers))
7522             (if current-prefix-arg
7523                 "Exclude extra header:"
7524               "Limit extra header:")
7525             (mapcar (lambda (x)
7526                       (cons (symbol-name x) x))
7527                     gnus-extra-headers)
7528             nil
7529             t))))
7530      (list header
7531            (read-string (format "%s header %s (regexp): "
7532                                 (if current-prefix-arg "Exclude" "Limit to")
7533                                 header))
7534            current-prefix-arg)))
7535   (when (not (equal "" regexp))
7536     (prog1
7537         (let ((articles (gnus-summary-find-matching
7538                          (cons 'extra header) regexp 'all nil nil
7539                          not-matching)))
7540           (unless articles
7541             (error "Found no matches for \"%s\"" regexp))
7542           (gnus-summary-limit articles))
7543       (gnus-summary-position-point))))
7544
7545 (defun gnus-summary-limit-to-display-predicate ()
7546   "Limit the summary buffer to the predicated in the `display' group parameter."
7547   (interactive)
7548   (unless gnus-newsgroup-display
7549     (error "There is no `display' group parameter"))
7550   (let (articles)
7551     (dolist (number gnus-newsgroup-articles)
7552       (when (funcall gnus-newsgroup-display)
7553         (push number articles)))
7554     (gnus-summary-limit articles))
7555   (gnus-summary-position-point))
7556
7557 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7558 (make-obsolete
7559  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7560
7561 (defun gnus-summary-limit-to-unread (&optional all)
7562   "Limit the summary buffer to articles that are not marked as read.
7563 If ALL is non-nil, limit strictly to unread articles."
7564   (interactive "P")
7565   (if all
7566       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7567     (gnus-summary-limit-to-marks
7568      ;; Concat all the marks that say that an article is read and have
7569      ;; those removed.
7570      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7571            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7572            gnus-low-score-mark gnus-expirable-mark
7573            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7574            gnus-duplicate-mark gnus-souped-mark)
7575      'reverse)))
7576
7577 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7578 (make-obsolete 'gnus-summary-delete-marked-with
7579                'gnus-summary-limit-exclude-marks)
7580
7581 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7582   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7583 If REVERSE, limit the summary buffer to articles that are marked
7584 with MARKS.  MARKS can either be a string of marks or a list of marks.
7585 Returns how many articles were removed."
7586   (interactive "sMarks: ")
7587   (gnus-summary-limit-to-marks marks t))
7588
7589 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7590   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7591 If REVERSE (the prefix), limit the summary buffer to articles that are
7592 not marked with MARKS.  MARKS can either be a string of marks or a
7593 list of marks.
7594 Returns how many articles were removed."
7595   (interactive "sMarks: \nP")
7596   (prog1
7597       (let ((data gnus-newsgroup-data)
7598             (marks (if (listp marks) marks
7599                      (append marks nil))) ; Transform to list.
7600             articles)
7601         (while data
7602           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7603                   (memq (gnus-data-mark (car data)) marks))
7604             (push (gnus-data-number (car data)) articles))
7605           (setq data (cdr data)))
7606         (gnus-summary-limit articles))
7607     (gnus-summary-position-point)))
7608
7609 (defun gnus-summary-limit-to-score (score)
7610   "Limit to articles with score at or above SCORE."
7611   (interactive "NLimit to articles with score of at least: ")
7612   (let ((data gnus-newsgroup-data)
7613         articles)
7614     (while data
7615       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7616                 score)
7617         (push (gnus-data-number (car data)) articles))
7618       (setq data (cdr data)))
7619     (prog1
7620         (gnus-summary-limit articles)
7621       (gnus-summary-position-point))))
7622
7623 (defun gnus-summary-limit-to-unseen ()
7624   "Limit to unseen articles."
7625   (interactive)
7626   (prog1
7627       (gnus-summary-limit gnus-newsgroup-unseen)
7628     (gnus-summary-position-point)))
7629
7630 (defun gnus-summary-limit-include-thread (id)
7631   "Display all the hidden articles that is in the thread with ID in it.
7632 When called interactively, ID is the Message-ID of the current
7633 article."
7634   (interactive (list (mail-header-id (gnus-summary-article-header))))
7635   (let ((articles (gnus-articles-in-thread
7636                    (gnus-id-to-thread (gnus-root-id id)))))
7637     (prog1
7638         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7639       (gnus-summary-limit-include-matching-articles
7640        "subject"
7641        (regexp-quote (gnus-simplify-subject-re
7642                       (mail-header-subject (gnus-id-to-header id)))))
7643       (gnus-summary-position-point))))
7644
7645 (defun gnus-summary-limit-include-matching-articles (header regexp)
7646   "Display all the hidden articles that have HEADERs that match REGEXP."
7647   (interactive (list (read-string "Match on header: ")
7648                      (read-string "Regexp: ")))
7649   (let ((articles (gnus-find-matching-articles header regexp)))
7650     (prog1
7651         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7652       (gnus-summary-position-point))))
7653
7654 (defun gnus-summary-insert-dormant-articles ()
7655   "Insert all the dormat articles for this group into the current buffer."
7656   (interactive)
7657   (let ((gnus-verbose (max 6 gnus-verbose)))
7658     (if (not gnus-newsgroup-dormant)
7659         (gnus-message 3 "No cached articles for this group")
7660       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7661
7662 (defun gnus-summary-limit-include-dormant ()
7663   "Display all the hidden articles that are marked as dormant.
7664 Note that this command only works on a subset of the articles currently
7665 fetched for this group."
7666   (interactive)
7667   (unless gnus-newsgroup-dormant
7668     (error "There are no dormant articles in this group"))
7669   (prog1
7670       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7671     (gnus-summary-position-point)))
7672
7673 (defun gnus-summary-limit-exclude-dormant ()
7674   "Hide all dormant articles."
7675   (interactive)
7676   (prog1
7677       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-limit-exclude-childless-dormant ()
7681   "Hide all dormant articles that have no children."
7682   (interactive)
7683   (let ((data (gnus-data-list t))
7684         articles d children)
7685     ;; Find all articles that are either not dormant or have
7686     ;; children.
7687     (while (setq d (pop data))
7688       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7689                 (and (setq children
7690                            (gnus-article-children (gnus-data-number d)))
7691                      (let (found)
7692                        (while children
7693                          (when (memq (car children) articles)
7694                            (setq children nil
7695                                  found t))
7696                          (pop children))
7697                        found)))
7698         (push (gnus-data-number d) articles)))
7699     ;; Do the limiting.
7700     (prog1
7701         (gnus-summary-limit articles)
7702       (gnus-summary-position-point))))
7703
7704 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7705   "Mark all unread excluded articles as read.
7706 If ALL, mark even excluded ticked and dormants as read."
7707   (interactive "P")
7708   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7709   (let ((articles (gnus-sorted-ndifference
7710                    (sort
7711                     (mapcar (lambda (h) (mail-header-number h))
7712                             gnus-newsgroup-headers)
7713                     '<)
7714                    gnus-newsgroup-limit))
7715         article)
7716     (setq gnus-newsgroup-unreads
7717           (gnus-sorted-intersection gnus-newsgroup-unreads
7718                                     gnus-newsgroup-limit))
7719     (if all
7720         (setq gnus-newsgroup-dormant nil
7721               gnus-newsgroup-marked nil
7722               gnus-newsgroup-reads
7723               (nconc
7724                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7725                gnus-newsgroup-reads))
7726       (while (setq article (pop articles))
7727         (unless (or (memq article gnus-newsgroup-dormant)
7728                     (memq article gnus-newsgroup-marked))
7729           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7730
7731 (defun gnus-summary-limit (articles &optional pop)
7732   (if pop
7733       ;; We pop the previous limit off the stack and use that.
7734       (setq articles (car gnus-newsgroup-limits)
7735             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7736     ;; We use the new limit, so we push the old limit on the stack.
7737     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7738   ;; Set the limit.
7739   (setq gnus-newsgroup-limit articles)
7740   (let ((total (length gnus-newsgroup-data))
7741         (data (gnus-data-find-list (gnus-summary-article-number)))
7742         (gnus-summary-mark-below nil)   ; Inhibit this.
7743         found)
7744     ;; This will do all the work of generating the new summary buffer
7745     ;; according to the new limit.
7746     (gnus-summary-prepare)
7747     ;; Hide any threads, possibly.
7748     (gnus-summary-maybe-hide-threads)
7749     ;; Try to return to the article you were at, or one in the
7750     ;; neighborhood.
7751     (when data
7752       ;; We try to find some article after the current one.
7753       (while data
7754         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7755           (setq data nil
7756                 found t))
7757         (setq data (cdr data))))
7758     (unless found
7759       ;; If there is no data, that means that we were after the last
7760       ;; article.  The same goes when we can't find any articles
7761       ;; after the current one.
7762       (goto-char (point-max))
7763       (gnus-summary-find-prev))
7764     (gnus-set-mode-line 'summary)
7765     ;; We return how many articles were removed from the summary
7766     ;; buffer as a result of the new limit.
7767     (- total (length gnus-newsgroup-data))))
7768
7769 (defsubst gnus-invisible-cut-children (threads)
7770   (let ((num 0))
7771     (while threads
7772       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7773         (incf num))
7774       (pop threads))
7775     (< num 2)))
7776
7777 (defsubst gnus-cut-thread (thread)
7778   "Go forwards in the thread until we find an article that we want to display."
7779   (when (or (eq gnus-fetch-old-headers 'some)
7780             (eq gnus-fetch-old-headers 'invisible)
7781             (numberp gnus-fetch-old-headers)
7782             (eq gnus-build-sparse-threads 'some)
7783             (eq gnus-build-sparse-threads 'more))
7784     ;; Deal with old-fetched headers and sparse threads.
7785     (while (and
7786             thread
7787             (or
7788              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7789              (gnus-summary-article-ancient-p
7790               (mail-header-number (car thread))))
7791             (if (or (<= (length (cdr thread)) 1)
7792                     (eq gnus-fetch-old-headers 'invisible))
7793                 (setq gnus-newsgroup-limit
7794                       (delq (mail-header-number (car thread))
7795                             gnus-newsgroup-limit)
7796                       thread (cadr thread))
7797               (when (gnus-invisible-cut-children (cdr thread))
7798                 (let ((th (cdr thread)))
7799                   (while th
7800                     (if (memq (mail-header-number (caar th))
7801                               gnus-newsgroup-limit)
7802                         (setq thread (car th)
7803                               th nil)
7804                       (setq th (cdr th))))))))))
7805   thread)
7806
7807 (defun gnus-cut-threads (threads)
7808   "Cut off all uninteresting articles from the beginning of threads."
7809   (when (or (eq gnus-fetch-old-headers 'some)
7810             (eq gnus-fetch-old-headers 'invisible)
7811             (numberp gnus-fetch-old-headers)
7812             (eq gnus-build-sparse-threads 'some)
7813             (eq gnus-build-sparse-threads 'more))
7814     (let ((th threads))
7815       (while th
7816         (setcar th (gnus-cut-thread (car th)))
7817         (setq th (cdr th)))))
7818   ;; Remove nixed out threads.
7819   (delq nil threads))
7820
7821 (defun gnus-summary-initial-limit (&optional show-if-empty)
7822   "Figure out what the initial limit is supposed to be on group entry.
7823 This entails weeding out unwanted dormants, low-scored articles,
7824 fetch-old-headers verbiage, and so on."
7825   ;; Most groups have nothing to remove.
7826   (if (or gnus-inhibit-limiting
7827           (and (null gnus-newsgroup-dormant)
7828                (eq gnus-newsgroup-display 'gnus-not-ignore)
7829                (not (eq gnus-fetch-old-headers 'some))
7830                (not (numberp gnus-fetch-old-headers))
7831                (not (eq gnus-fetch-old-headers 'invisible))
7832                (null gnus-summary-expunge-below)
7833                (not (eq gnus-build-sparse-threads 'some))
7834                (not (eq gnus-build-sparse-threads 'more))
7835                (null gnus-thread-expunge-below)
7836                (not gnus-use-nocem)))
7837       ()                                ; Do nothing.
7838     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7839     (setq gnus-newsgroup-limit nil)
7840     (mapatoms
7841      (lambda (node)
7842        (unless (car (symbol-value node))
7843          ;; These threads have no parents -- they are roots.
7844          (let ((nodes (cdr (symbol-value node)))
7845                thread)
7846            (while nodes
7847              (if (and gnus-thread-expunge-below
7848                       (< (gnus-thread-total-score (car nodes))
7849                          gnus-thread-expunge-below))
7850                  (gnus-expunge-thread (pop nodes))
7851                (setq thread (pop nodes))
7852                (gnus-summary-limit-children thread))))))
7853      gnus-newsgroup-dependencies)
7854     ;; If this limitation resulted in an empty group, we might
7855     ;; pop the previous limit and use it instead.
7856     (when (and (not gnus-newsgroup-limit)
7857                show-if-empty)
7858       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7859     gnus-newsgroup-limit))
7860
7861 (defun gnus-summary-limit-children (thread)
7862   "Return 1 if this subthread is visible and 0 if it is not."
7863   ;; First we get the number of visible children to this thread.  This
7864   ;; is done by recursing down the thread using this function, so this
7865   ;; will really go down to a leaf article first, before slowly
7866   ;; working its way up towards the root.
7867   (when thread
7868     (let* ((max-lisp-eval-depth 5000)
7869            (children
7870            (if (cdr thread)
7871                (apply '+ (mapcar 'gnus-summary-limit-children
7872                                  (cdr thread)))
7873              0))
7874           (number (mail-header-number (car thread)))
7875           score)
7876       (if (and
7877            (not (memq number gnus-newsgroup-marked))
7878            (or
7879             ;; If this article is dormant and has absolutely no visible
7880             ;; children, then this article isn't visible.
7881             (and (memq number gnus-newsgroup-dormant)
7882                  (zerop children))
7883             ;; If this is "fetch-old-headered" and there is no
7884             ;; visible children, then we don't want this article.
7885             (and (or (eq gnus-fetch-old-headers 'some)
7886                      (numberp gnus-fetch-old-headers))
7887                  (gnus-summary-article-ancient-p number)
7888                  (zerop children))
7889             ;; If this is "fetch-old-headered" and `invisible', then
7890             ;; we don't want this article.
7891             (and (eq gnus-fetch-old-headers 'invisible)
7892                  (gnus-summary-article-ancient-p number))
7893             ;; If this is a sparsely inserted article with no children,
7894             ;; we don't want it.
7895             (and (eq gnus-build-sparse-threads 'some)
7896                  (gnus-summary-article-sparse-p number)
7897                  (zerop children))
7898             ;; If we use expunging, and this article is really
7899             ;; low-scored, then we don't want this article.
7900             (when (and gnus-summary-expunge-below
7901                        (< (setq score
7902                                 (or (cdr (assq number gnus-newsgroup-scored))
7903                                     gnus-summary-default-score))
7904                           gnus-summary-expunge-below))
7905               ;; We increase the expunge-tally here, but that has
7906               ;; nothing to do with the limits, really.
7907               (incf gnus-newsgroup-expunged-tally)
7908               ;; We also mark as read here, if that's wanted.
7909               (when (and gnus-summary-mark-below
7910                          (< score gnus-summary-mark-below))
7911                 (setq gnus-newsgroup-unreads
7912                       (delq number gnus-newsgroup-unreads))
7913                 (if gnus-newsgroup-auto-expire
7914                     (push number gnus-newsgroup-expirable)
7915                   (push (cons number gnus-low-score-mark)
7916                         gnus-newsgroup-reads)))
7917               t)
7918             ;; Do the `display' group parameter.
7919             (and gnus-newsgroup-display
7920                  (not (funcall gnus-newsgroup-display)))
7921             ;; Check NoCeM things.
7922             (if (and gnus-use-nocem
7923                      (gnus-nocem-unwanted-article-p
7924                       (mail-header-id (car thread))))
7925                 (progn
7926                   (setq gnus-newsgroup-unreads
7927                         (delq number gnus-newsgroup-unreads))
7928                   t))))
7929           ;; Nope, invisible article.
7930           0
7931         ;; Ok, this article is to be visible, so we add it to the limit
7932         ;; and return 1.
7933         (push number gnus-newsgroup-limit)
7934         1))))
7935
7936 (defun gnus-expunge-thread (thread)
7937   "Mark all articles in THREAD as read."
7938   (let* ((number (mail-header-number (car thread))))
7939     (incf gnus-newsgroup-expunged-tally)
7940     ;; We also mark as read here, if that's wanted.
7941     (setq gnus-newsgroup-unreads
7942           (delq number gnus-newsgroup-unreads))
7943     (if gnus-newsgroup-auto-expire
7944         (push number gnus-newsgroup-expirable)
7945       (push (cons number gnus-low-score-mark)
7946             gnus-newsgroup-reads)))
7947   ;; Go recursively through all subthreads.
7948   (mapcar 'gnus-expunge-thread (cdr thread)))
7949
7950 ;; Summary article oriented commands
7951
7952 (defun gnus-summary-refer-parent-article (n)
7953   "Refer parent article N times.
7954 If N is negative, go to ancestor -N instead.
7955 The difference between N and the number of articles fetched is returned."
7956   (interactive "p")
7957   (let ((skip 1)
7958         error header ref)
7959     (when (not (natnump n))
7960       (setq skip (abs n)
7961             n 1))
7962     (while (and (> n 0)
7963                 (not error))
7964       (setq header (gnus-summary-article-header))
7965       (if (and (eq (mail-header-number header)
7966                    (cdr gnus-article-current))
7967                (equal gnus-newsgroup-name
7968                       (car gnus-article-current)))
7969           ;; If we try to find the parent of the currently
7970           ;; displayed article, then we take a look at the actual
7971           ;; References header, since this is slightly more
7972           ;; reliable than the References field we got from the
7973           ;; server.
7974           (save-excursion
7975             (set-buffer gnus-original-article-buffer)
7976             (nnheader-narrow-to-headers)
7977             (unless (setq ref (message-fetch-field "references"))
7978               (setq ref (message-fetch-field "in-reply-to")))
7979             (widen))
7980         (setq ref
7981               ;; It's not the current article, so we take a bet on
7982               ;; the value we got from the server.
7983               (mail-header-references header)))
7984       (if (and ref
7985                (not (equal ref "")))
7986           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7987             (gnus-message 1 "Couldn't find parent"))
7988         (gnus-message 1 "No references in article %d"
7989                       (gnus-summary-article-number))
7990         (setq error t))
7991       (decf n))
7992     (gnus-summary-position-point)
7993     n))
7994
7995 (defun gnus-summary-refer-references ()
7996   "Fetch all articles mentioned in the References header.
7997 Return the number of articles fetched."
7998   (interactive)
7999   (let ((ref (mail-header-references (gnus-summary-article-header)))
8000         (current (gnus-summary-article-number))
8001         (n 0))
8002     (if (or (not ref)
8003             (equal ref ""))
8004         (error "No References in the current article")
8005       ;; For each Message-ID in the References header...
8006       (while (string-match "<[^>]*>" ref)
8007         (incf n)
8008         ;; ... fetch that article.
8009         (gnus-summary-refer-article
8010          (prog1 (match-string 0 ref)
8011            (setq ref (substring ref (match-end 0))))))
8012       (gnus-summary-goto-subject current)
8013       (gnus-summary-position-point)
8014       n)))
8015
8016 (defun gnus-summary-refer-thread (&optional limit)
8017   "Fetch all articles in the current thread.
8018 If LIMIT (the numerical prefix), fetch that many old headers instead
8019 of what's specified by the `gnus-refer-thread-limit' variable."
8020   (interactive "P")
8021   (let ((id (mail-header-id (gnus-summary-article-header)))
8022         (limit (if limit (prefix-numeric-value limit)
8023                  gnus-refer-thread-limit)))
8024     (unless (eq gnus-fetch-old-headers 'invisible)
8025       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8026       ;; Retrieve the headers and read them in.
8027       (if (eq (if (numberp limit)
8028                   (gnus-retrieve-headers
8029                    (list (min
8030                           (+ (mail-header-number
8031                               (gnus-summary-article-header))
8032                              limit)
8033                           gnus-newsgroup-end))
8034                    gnus-newsgroup-name (* limit 2))
8035                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8036                 ;; headers.
8037                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8038                                        gnus-newsgroup-name limit))
8039               'nov)
8040           (gnus-build-all-threads)
8041         (error "Can't fetch thread from backends that don't support NOV"))
8042       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8043     (gnus-summary-limit-include-thread id)))
8044
8045 (defun gnus-summary-refer-article (message-id)
8046   "Fetch an article specified by MESSAGE-ID."
8047   (interactive "sMessage-ID: ")
8048   (when (and (stringp message-id)
8049              (not (zerop (length message-id))))
8050     ;; Construct the correct Message-ID if necessary.
8051     ;; Suggested by tale@pawl.rpi.edu.
8052     (unless (string-match "^<" message-id)
8053       (setq message-id (concat "<" message-id)))
8054     (unless (string-match ">$" message-id)
8055       (setq message-id (concat message-id ">")))
8056     (let* ((header (gnus-id-to-header message-id))
8057            (sparse (and header
8058                         (gnus-summary-article-sparse-p
8059                          (mail-header-number header))
8060                         (memq (mail-header-number header)
8061                               gnus-newsgroup-limit)))
8062            number)
8063       (cond
8064        ;; If the article is present in the buffer we just go to it.
8065        ((and header
8066              (or (not (gnus-summary-article-sparse-p
8067                        (mail-header-number header)))
8068                  sparse))
8069         (prog1
8070             (gnus-summary-goto-article
8071              (mail-header-number header) nil t)
8072           (when sparse
8073             (gnus-summary-update-article (mail-header-number header)))))
8074        (t
8075         ;; We fetch the article.
8076         (catch 'found
8077           (dolist (gnus-override-method (gnus-refer-article-methods))
8078             (when (and (gnus-check-server gnus-override-method)
8079                        ;; Fetch the header,
8080                        (setq number (gnus-summary-insert-subject message-id)))
8081               ;; and display the article.
8082               (gnus-summary-select-article nil nil nil number)
8083               (throw 'found t)))
8084           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8085
8086 (defun gnus-refer-article-methods ()
8087   "Return a list of referable methods."
8088   (cond
8089    ;; No method, so we default to current and native.
8090    ((null gnus-refer-article-method)
8091     (list gnus-current-select-method gnus-select-method))
8092    ;; Current.
8093    ((eq 'current gnus-refer-article-method)
8094     (list gnus-current-select-method))
8095    ;; List of select methods.
8096    ((not (and (symbolp (car gnus-refer-article-method))
8097               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8098     (let (out)
8099       (dolist (method gnus-refer-article-method)
8100         (push (if (eq 'current method)
8101                   gnus-current-select-method
8102                 method)
8103               out))
8104       (nreverse out)))
8105    ;; One single select method.
8106    (t
8107     (list gnus-refer-article-method))))
8108
8109 (defun gnus-summary-edit-parameters ()
8110   "Edit the group parameters of the current group."
8111   (interactive)
8112   (gnus-group-edit-group gnus-newsgroup-name 'params))
8113
8114 (defun gnus-summary-customize-parameters ()
8115   "Customize the group parameters of the current group."
8116   (interactive)
8117   (gnus-group-customize gnus-newsgroup-name))
8118
8119 (defun gnus-summary-enter-digest-group (&optional force)
8120   "Enter an nndoc group based on the current article.
8121 If FORCE, force a digest interpretation.  If not, try
8122 to guess what the document format is."
8123   (interactive "P")
8124   (let ((conf gnus-current-window-configuration))
8125     (save-excursion
8126       (gnus-summary-select-article))
8127     (setq gnus-current-window-configuration conf)
8128     (let* ((name (format "%s-%d"
8129                          (gnus-group-prefixed-name
8130                           gnus-newsgroup-name (list 'nndoc ""))
8131                          (save-excursion
8132                            (set-buffer gnus-summary-buffer)
8133                            gnus-current-article)))
8134            (ogroup gnus-newsgroup-name)
8135            (params (append (gnus-info-params (gnus-get-info ogroup))
8136                            (list (cons 'to-group ogroup))
8137                            (list (cons 'save-article-group ogroup))))
8138            (case-fold-search t)
8139            (buf (current-buffer))
8140            dig to-address)
8141       (save-excursion
8142         (set-buffer gnus-original-article-buffer)
8143         ;; Have the digest group inherit the main mail address of
8144         ;; the parent article.
8145         (when (setq to-address (or (gnus-fetch-field "reply-to")
8146                                    (gnus-fetch-field "from")))
8147           (setq params (append
8148                         (list (cons 'to-address
8149                                     (funcall gnus-decode-encoded-word-function
8150                                              to-address))))))
8151         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8152         (insert-buffer-substring gnus-original-article-buffer)
8153         ;; Remove lines that may lead nndoc to misinterpret the
8154         ;; document type.
8155         (narrow-to-region
8156          (goto-char (point-min))
8157          (or (search-forward "\n\n" nil t) (point)))
8158         (goto-char (point-min))
8159         (delete-matching-lines "^Path:\\|^From ")
8160         (widen))
8161       (unwind-protect
8162           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8163                     (gnus-newsgroup-ephemeral-ignored-charsets
8164                      gnus-newsgroup-ignored-charsets))
8165                 (gnus-group-read-ephemeral-group
8166                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8167                               (nndoc-article-type
8168                                ,(if force 'mbox 'guess)))
8169                  t nil nil nil
8170                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8171                                                         "ADAPT")))))
8172               ;; Make all postings to this group go to the parent group.
8173               (nconc (gnus-info-params (gnus-get-info name))
8174                      params)
8175             ;; Couldn't select this doc group.
8176             (switch-to-buffer buf)
8177             (gnus-set-global-variables)
8178             (gnus-configure-windows 'summary)
8179             (gnus-message 3 "Article couldn't be entered?"))
8180         (kill-buffer dig)))))
8181
8182 (defun gnus-summary-read-document (n)
8183   "Open a new group based on the current article(s).
8184 This will allow you to read digests and other similar
8185 documents as newsgroups.
8186 Obeys the standard process/prefix convention."
8187   (interactive "P")
8188   (let* ((articles (gnus-summary-work-articles n))
8189          (ogroup gnus-newsgroup-name)
8190          (params (append (gnus-info-params (gnus-get-info ogroup))
8191                          (list (cons 'to-group ogroup))))
8192          article group egroup groups vgroup)
8193     (while (setq article (pop articles))
8194       (setq group (format "%s-%d" gnus-newsgroup-name article))
8195       (gnus-summary-remove-process-mark article)
8196       (when (gnus-summary-display-article article)
8197         (save-excursion
8198           (with-temp-buffer
8199             (insert-buffer-substring gnus-original-article-buffer)
8200             ;; Remove some headers that may lead nndoc to make
8201             ;; the wrong guess.
8202             (message-narrow-to-head)
8203             (goto-char (point-min))
8204             (delete-matching-lines "^\\(Path\\):\\|^From ")
8205             (widen)
8206             (if (setq egroup
8207                       (gnus-group-read-ephemeral-group
8208                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8209                                      (nndoc-article-type guess))
8210                        t nil t))
8211                 (progn
8212                   ;; Make all postings to this group go to the parent group.
8213                   (nconc (gnus-info-params (gnus-get-info egroup))
8214                          params)
8215                   (push egroup groups))
8216               ;; Couldn't select this doc group.
8217               (gnus-error 3 "Article couldn't be entered"))))))
8218     ;; Now we have selected all the documents.
8219     (cond
8220      ((not groups)
8221       (error "None of the articles could be interpreted as documents"))
8222      ((gnus-group-read-ephemeral-group
8223        (setq vgroup (format
8224                      "nnvirtual:%s-%s" gnus-newsgroup-name
8225                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8226        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8227        t
8228        (cons (current-buffer) 'summary)))
8229      (t
8230       (error "Couldn't select virtual nndoc group")))))
8231
8232 (defun gnus-summary-isearch-article (&optional regexp-p)
8233   "Do incremental search forward on the current article.
8234 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8235   (interactive "P")
8236   (let* ((gnus-inhibit-treatment t)
8237          (old (gnus-summary-select-article)))
8238     (gnus-configure-windows 'article)
8239     (gnus-eval-in-buffer-window gnus-article-buffer
8240       (save-restriction
8241         (widen)
8242         (when (eq 'old old)
8243           (gnus-article-show-all-headers))
8244         (goto-char (point-min))
8245         (isearch-forward regexp-p)))))
8246
8247 (defun gnus-summary-search-article-forward (regexp &optional backward)
8248   "Search for an article containing REGEXP forward.
8249 If BACKWARD, search backward instead."
8250   (interactive
8251    (list (read-string
8252           (format "Search article %s (regexp%s): "
8253                   (if current-prefix-arg "backward" "forward")
8254                   (if gnus-last-search-regexp
8255                       (concat ", default " gnus-last-search-regexp)
8256                     "")))
8257          current-prefix-arg))
8258   (if (string-equal regexp "")
8259       (setq regexp (or gnus-last-search-regexp ""))
8260     (setq gnus-last-search-regexp regexp)
8261     (setq gnus-article-before-search gnus-current-article))
8262   ;; Intentionally set gnus-last-article.
8263   (setq gnus-last-article gnus-article-before-search)
8264   (let ((gnus-last-article gnus-last-article))
8265     (if (gnus-summary-search-article regexp backward)
8266         (gnus-summary-show-thread)
8267       (error "Search failed: \"%s\"" regexp))))
8268
8269 (defun gnus-summary-search-article-backward (regexp)
8270   "Search for an article containing REGEXP backward."
8271   (interactive
8272    (list (read-string
8273           (format "Search article backward (regexp%s): "
8274                   (if gnus-last-search-regexp
8275                       (concat ", default " gnus-last-search-regexp)
8276                     "")))))
8277   (gnus-summary-search-article-forward regexp 'backward))
8278
8279 (eval-when-compile
8280   (defmacro gnus-summary-search-article-position-point (regexp backward)
8281     "Dehighlight the last matched text and goto the beginning position."
8282     (` (if (and gnus-summary-search-article-matched-data
8283                 (let ((text (caddr gnus-summary-search-article-matched-data))
8284                       (inhibit-read-only t)
8285                       buffer-read-only)
8286                   (delete-region
8287                    (goto-char (car gnus-summary-search-article-matched-data))
8288                    (cadr gnus-summary-search-article-matched-data))
8289                   (insert text)
8290                   (string-match (, regexp) text)))
8291            (if (, backward) (beginning-of-line) (end-of-line))
8292          (goto-char (if (, backward) (point-max) (point-min))))))
8293
8294   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8295     "Place point where X-Face image is displayed."
8296     (if (featurep 'xemacs)
8297         (` (let ((end (if (search-forward "\n\n" nil t)
8298                           (goto-char (1- (point)))
8299                         (point-min)))
8300                  extent)
8301              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8302              (unless (and (re-search-forward "^From:" end t)
8303                           (setq extent (extent-at (point)))
8304                           (extent-begin-glyph extent))
8305                (goto-char (, opoint)))))
8306       (` (let ((end (if (search-forward "\n\n" nil t)
8307                         (goto-char (1- (point)))
8308                       (point-min)))
8309                (start (or (search-backward "\n\n" nil t) (point-min))))
8310            (goto-char
8311             (or (text-property-any start end 'x-face-image t);; x-face-e21
8312                 (text-property-any start end 'x-face-mule-bitmap-image t)
8313                 (, opoint)))))))
8314
8315   (defmacro gnus-summary-search-article-highlight-matched-text
8316     (backward treated x-face)
8317     "Highlight matched text in the function `gnus-summary-search-article'."
8318     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8319              (end (set-marker (make-marker) (match-end 0)))
8320              (inhibit-read-only t)
8321              buffer-read-only)
8322          (unless treated
8323            (let ((,@
8324                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8325                     (mapcar
8326                      (lambda (item) (setq items (delq item items)))
8327                      '(gnus-treat-buttonize
8328                        gnus-treat-fill-article
8329                        gnus-treat-fill-long-lines
8330                        gnus-treat-emphasize
8331                        gnus-treat-highlight-headers
8332                        gnus-treat-highlight-citation
8333                        gnus-treat-highlight-signature
8334                        gnus-treat-overstrike
8335                        gnus-treat-display-xface
8336                        gnus-treat-buttonize-head
8337                        gnus-treat-decode-article-as-default-mime-charset))
8338                     (static-if (featurep 'xemacs)
8339                         items
8340                       (cons '(x-face-mule-delete-x-face-field
8341                               (quote never))
8342                             items))))
8343                  (gnus-treat-display-xface
8344                   (when (, x-face) gnus-treat-display-xface)))
8345              (gnus-article-prepare-mime-display)))
8346          (goto-char (if (, backward) start end))
8347          (when (, x-face)
8348            (gnus-summary-search-article-highlight-goto-x-face (point)))
8349          (setq gnus-summary-search-article-matched-data
8350                (list start end (buffer-substring start end)))
8351          (unless (eq start end);; matched text has been deleted. :-<
8352            (put-text-property start end 'face
8353                               (or (find-face 'isearch)
8354                                   'secondary-selection))))))
8355   )
8356
8357 (defun gnus-summary-search-article (regexp &optional backward)
8358   "Search for an article containing REGEXP.
8359 Optional argument BACKWARD means do search for backward.
8360 `gnus-select-article-hook' is not called during the search."
8361   ;; We have to require this here to make sure that the following
8362   ;; dynamic binding isn't shadowed by autoloading.
8363   (require 'gnus-async)
8364   (require 'gnus-art)
8365   (let ((gnus-select-article-hook nil)  ;Disable hook.
8366         (gnus-article-prepare-hook nil)
8367         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8368         (gnus-use-article-prefetch nil)
8369         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8370         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8371         (gnus-visual nil)
8372         (gnus-keep-backlog nil)
8373         (gnus-break-pages nil)
8374         (gnus-summary-display-arrow nil)
8375         (gnus-updated-mode-lines nil)
8376         (gnus-auto-center-summary nil)
8377         (sum (current-buffer))
8378         (found nil)
8379         point treated)
8380     (gnus-save-hidden-threads
8381       (static-if (featurep 'xemacs)
8382           (let ((gnus-inhibit-treatment t))
8383             (setq treated (eq 'old (gnus-summary-select-article)))
8384             (when (and treated
8385                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8386                                  (window-live-p (get-buffer-window
8387                                                  gnus-article-buffer t)))))
8388               (gnus-summary-select-article nil t)
8389               (setq treated nil)))
8390         (let ((gnus-inhibit-treatment t)
8391               (x-face-mule-delete-x-face-field 'never))
8392           (setq treated (eq 'old (gnus-summary-select-article)))
8393           (when (and treated
8394                      (not
8395                       (and (gnus-buffer-live-p gnus-article-buffer)
8396                            (window-live-p (get-buffer-window
8397                                            gnus-article-buffer t))
8398                            (or (not (string-match "^\\^X-Face:" regexp))
8399                                (with-current-buffer gnus-article-buffer
8400                                  gnus-summary-search-article-matched-data)))))
8401             (gnus-summary-select-article nil t)
8402             (setq treated nil))))
8403       (set-buffer gnus-article-buffer)
8404       (widen)
8405       (if treated
8406           (progn
8407             (gnus-article-show-all-headers)
8408             (gnus-summary-search-article-position-point regexp backward))
8409         (goto-char (if backward (point-max) (point-min))))
8410       (while (not found)
8411         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8412         (if (if backward
8413                 (re-search-backward regexp nil t)
8414               (re-search-forward regexp nil t))
8415             ;; We found the regexp.
8416             (progn
8417               (gnus-summary-search-article-highlight-matched-text
8418                backward treated (string-match "^\\^X-Face:" regexp))
8419               (setq found 'found)
8420               (forward-line
8421                (/ (- 2 (window-height
8422                         (get-buffer-window gnus-article-buffer t)))
8423                   2))
8424               (set-window-start
8425                (get-buffer-window (current-buffer))
8426                (point))
8427               (set-buffer sum)
8428               (setq point (point)))
8429           ;; We didn't find it, so we go to the next article.
8430           (set-buffer sum)
8431           (setq found 'not)
8432           (while (eq found 'not)
8433             (if (not (if backward (gnus-summary-find-prev)
8434                        (gnus-summary-find-next)))
8435                 ;; No more articles.
8436                 (setq found t)
8437               ;; Select the next article and adjust point.
8438               (unless (gnus-summary-article-sparse-p
8439                        (gnus-summary-article-number))
8440                 (setq found nil)
8441                 (let ((gnus-inhibit-treatment t))
8442                   (gnus-summary-select-article))
8443                 (setq treated nil)
8444                 (set-buffer gnus-article-buffer)
8445                 (widen)
8446                 (goto-char (if backward (point-max) (point-min))))))))
8447       (gnus-message 7 ""))
8448     ;; Return whether we found the regexp.
8449     (when (eq found 'found)
8450       (goto-char point)
8451       (gnus-summary-show-thread)
8452       (gnus-summary-goto-subject gnus-current-article)
8453       (gnus-summary-position-point)
8454       t)))
8455
8456 (defun gnus-find-matching-articles (header regexp)
8457   "Return a list of all articles that match REGEXP on HEADER.
8458 This search includes all articles in the current group that Gnus has
8459 fetched headers for, whether they are displayed or not."
8460   (let ((articles nil)
8461         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8462         (case-fold-search t))
8463     (dolist (header gnus-newsgroup-headers)
8464       (when (string-match regexp (funcall func header))
8465         (push (mail-header-number header) articles)))
8466     (nreverse articles)))
8467
8468 (defun gnus-summary-find-matching (header regexp &optional backward unread
8469                                           not-case-fold not-matching)
8470   "Return a list of all articles that match REGEXP on HEADER.
8471 The search stars on the current article and goes forwards unless
8472 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8473 If UNREAD is non-nil, only unread articles will
8474 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8475 in the comparisons. If NOT-MATCHING, return a list of all articles that
8476 not match REGEXP on HEADER."
8477   (let ((case-fold-search (not not-case-fold))
8478         articles d func)
8479     (if (consp header)
8480         (if (eq (car header) 'extra)
8481             (setq func
8482                   `(lambda (h)
8483                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8484                          "")))
8485           (error "%s is an invalid header" header))
8486       (unless (fboundp (intern (concat "mail-header-" header)))
8487         (error "%s is not a valid header" header))
8488       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8489     (dolist (d (if (eq backward 'all)
8490                    gnus-newsgroup-data
8491                  (gnus-data-find-list
8492                   (gnus-summary-article-number)
8493                   (gnus-data-list backward))))
8494       (when (and (or (not unread)       ; We want all articles...
8495                      (gnus-data-unread-p d)) ; Or just unreads.
8496                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8497                  (if not-matching
8498                      (not (string-match
8499                            regexp
8500                            (funcall func (gnus-data-header d))))
8501                    (string-match regexp
8502                                  (funcall func (gnus-data-header d)))))
8503         (push (gnus-data-number d) articles))) ; Success!
8504     (nreverse articles)))
8505
8506 (defun gnus-summary-execute-command (header regexp command &optional backward)
8507   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8508 If HEADER is an empty string (or nil), the match is done on the entire
8509 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8510   (interactive
8511    (list (let ((completion-ignore-case t))
8512            (completing-read
8513             "Header name: "
8514             (mapcar (lambda (header) (list (format "%s" header)))
8515                     (append
8516                      '("Number" "Subject" "From" "Lines" "Date"
8517                        "Message-ID" "Xref" "References" "Body")
8518                      gnus-extra-headers))
8519             nil 'require-match))
8520          (read-string "Regexp: ")
8521          (read-key-sequence "Command: ")
8522          current-prefix-arg))
8523   (when (equal header "Body")
8524     (setq header ""))
8525   ;; Hidden thread subtrees must be searched as well.
8526   (gnus-summary-show-all-threads)
8527   ;; We don't want to change current point nor window configuration.
8528   (save-excursion
8529     (save-window-excursion
8530       (let (gnus-visual
8531             gnus-treat-strip-trailing-blank-lines
8532             gnus-treat-strip-leading-blank-lines
8533             gnus-treat-strip-multiple-blank-lines
8534             gnus-treat-hide-boring-headers
8535             gnus-treat-fold-newsgroups
8536             gnus-article-prepare-hook)
8537         (gnus-message 6 "Executing %s..." (key-description command))
8538         ;; We'd like to execute COMMAND interactively so as to give arguments.
8539         (gnus-execute header regexp
8540                       `(call-interactively ',(key-binding command))
8541                       backward)
8542         (gnus-message 6 "Executing %s...done" (key-description command))))))
8543
8544 (defun gnus-summary-beginning-of-article ()
8545   "Scroll the article back to the beginning."
8546   (interactive)
8547   (gnus-summary-select-article)
8548   (gnus-configure-windows 'article)
8549   (gnus-eval-in-buffer-window gnus-article-buffer
8550     (widen)
8551     (goto-char (point-min))
8552     (when gnus-page-broken
8553       (gnus-narrow-to-page))))
8554
8555 (defun gnus-summary-end-of-article ()
8556   "Scroll to the end of the article."
8557   (interactive)
8558   (gnus-summary-select-article)
8559   (gnus-configure-windows 'article)
8560   (gnus-eval-in-buffer-window gnus-article-buffer
8561     (widen)
8562     (goto-char (point-max))
8563     (recenter -3)
8564     (when gnus-page-broken
8565       (gnus-narrow-to-page))))
8566
8567 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8568   "Truncate to LEN and quote all \"(\"'s in STRING."
8569   (gnus-replace-in-string (if (and len (> (length string) len))
8570                               (substring string 0 len)
8571                             string)
8572                           "[()]" "\\\\\\&"))
8573
8574 (defun gnus-summary-print-article (&optional filename n)
8575   "Generate and print a PostScript image of the N next (mail) articles.
8576
8577 If N is negative, print the N previous articles.  If N is nil and articles
8578 have been marked with the process mark, print these instead.
8579
8580 If the optional first argument FILENAME is nil, send the image to the
8581 printer.  If FILENAME is a string, save the PostScript image in a file with
8582 that name.  If FILENAME is a number, prompt the user for the name of the file
8583 to save in."
8584   (interactive (list (ps-print-preprint current-prefix-arg)))
8585   (dolist (article (gnus-summary-work-articles n))
8586     (gnus-summary-select-article nil nil 'pseudo article)
8587     (gnus-eval-in-buffer-window gnus-article-buffer
8588       (gnus-print-buffer))
8589     (gnus-summary-remove-process-mark article))
8590   (ps-despool filename))
8591
8592 (defun gnus-print-buffer ()
8593   (let ((buffer (generate-new-buffer " *print*")))
8594     (unwind-protect
8595         (progn
8596           (copy-to-buffer buffer (point-min) (point-max))
8597           (set-buffer buffer)
8598           (gnus-article-delete-invisible-text)
8599           (gnus-remove-text-with-property 'gnus-decoration)
8600           (when (gnus-visual-p 'article-highlight 'highlight)
8601             ;; Copy-to-buffer doesn't copy overlay.  So redo
8602             ;; highlight.
8603             (let ((gnus-article-buffer buffer))
8604               (gnus-article-highlight-citation t)
8605               (gnus-article-highlight-signature)))
8606           (let ((ps-left-header
8607                  (list
8608                   (concat "("
8609                           (gnus-summary-print-truncate-and-quote
8610                            (mail-header-subject gnus-current-headers)
8611                            66) ")")
8612                   (concat "("
8613                           (gnus-summary-print-truncate-and-quote
8614                            (mail-header-from gnus-current-headers)
8615                            45) ")")))
8616                 (ps-right-header
8617                  (list
8618                   "/pagenumberstring load"
8619                   (concat "("
8620                           (mail-header-date gnus-current-headers) ")"))))
8621             (gnus-run-hooks 'gnus-ps-print-hook)
8622             (save-excursion
8623               (if window-system
8624                   (ps-spool-buffer-with-faces)
8625                 (ps-spool-buffer)))))
8626       (kill-buffer buffer))))
8627
8628 (defun gnus-summary-show-article (&optional arg)
8629   "Force redisplaying of the current article.
8630 If ARG (the prefix) is a number, show the article with the charset
8631 defined in `gnus-summary-show-article-charset-alist', or the charset
8632 input.
8633 If ARG (the prefix) is non-nil and not a number, show the raw article
8634 without any article massaging functions being run.  Normally, the key strokes
8635 are `C-u g'."
8636   (interactive "P")
8637   (cond
8638    ((numberp arg)
8639     (gnus-summary-show-article t)
8640     (let* ((gnus-newsgroup-charset
8641             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8642                 (mm-read-coding-system
8643                  "View as charset: " ;; actually it is coding system.
8644                  (save-excursion
8645                    (set-buffer gnus-article-buffer)
8646                    (mm-detect-coding-region (point) (point-max))))))
8647            (default-mime-charset gnus-newsgroup-charset)
8648            (gnus-newsgroup-ignored-charsets 'gnus-all))
8649       (gnus-summary-select-article nil 'force)
8650       (let ((deps gnus-newsgroup-dependencies)
8651             head header lines)
8652         (save-excursion
8653           (set-buffer gnus-original-article-buffer)
8654           (save-restriction
8655             (message-narrow-to-head)
8656             (setq head (buffer-string))
8657             (goto-char (point-min))
8658             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8659               (goto-char (point-max))
8660               (widen)
8661               (setq lines (1- (count-lines (point) (point-max))))))
8662           (with-temp-buffer
8663             (insert (format "211 %d Article retrieved.\n"
8664                             (cdr gnus-article-current)))
8665             (insert head)
8666             (if lines (insert (format "Lines: %d\n" lines)))
8667             (insert ".\n")
8668             (let ((nntp-server-buffer (current-buffer)))
8669               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8670         (gnus-data-set-header
8671          (gnus-data-find (cdr gnus-article-current))
8672          header)
8673         (gnus-summary-update-article-line
8674          (cdr gnus-article-current) header)
8675         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8676           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8677    ((not arg)
8678     ;; Select the article the normal way.
8679     (gnus-summary-select-article nil 'force))
8680    (t
8681     ;; We have to require this here to make sure that the following
8682     ;; dynamic binding isn't shadowed by autoloading.
8683     (require 'gnus-async)
8684     (require 'gnus-art)
8685     ;; Bind the article treatment functions to nil.
8686     (let ((gnus-have-all-headers t)
8687           gnus-article-prepare-hook
8688           gnus-article-decode-hook
8689           gnus-break-pages
8690           gnus-show-mime
8691           (gnus-inhibit-treatment t))
8692       (gnus-summary-select-article nil 'force))))
8693   (gnus-summary-goto-subject gnus-current-article)
8694   (gnus-summary-position-point))
8695
8696 (defun gnus-summary-show-raw-article ()
8697   "Show the raw article without any article massaging functions being run."
8698   (interactive)
8699   (gnus-summary-show-article t))
8700
8701 (defun gnus-summary-verbose-headers (&optional arg)
8702   "Toggle permanent full header display.
8703 If ARG is a positive number, turn header display on.
8704 If ARG is a negative number, turn header display off."
8705   (interactive "P")
8706   (setq gnus-show-all-headers
8707         (cond ((or (not (numberp arg))
8708                    (zerop arg))
8709                (not gnus-show-all-headers))
8710               ((natnump arg)
8711                t)))
8712   (gnus-summary-show-article))
8713
8714 (defun gnus-summary-toggle-header (&optional arg)
8715   "Show the headers if they are hidden, or hide them if they are shown.
8716 If ARG is a positive number, show the entire header.
8717 If ARG is a negative number, hide the unwanted header lines."
8718   (interactive "P")
8719   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8720                      (get-buffer-window gnus-article-buffer t))))
8721     (with-current-buffer gnus-article-buffer
8722       (widen)
8723       (article-narrow-to-head)
8724       (let* ((buffer-read-only nil)
8725              (inhibit-point-motion-hooks t)
8726              (hidden (if (numberp arg)
8727                          (>= arg 0)
8728                        (gnus-article-hidden-text-p 'headers)))
8729              s e)
8730         (delete-region (point-min) (point-max))
8731         (with-current-buffer gnus-original-article-buffer
8732           (goto-char (setq s (point-min)))
8733           (setq e (if (search-forward "\n\n" nil t)
8734                       (1- (point))
8735                     (point-max))))
8736         (insert-buffer-substring gnus-original-article-buffer s e)
8737         (run-hooks 'gnus-article-decode-hook)
8738         (if hidden
8739             (let ((gnus-treat-hide-headers nil)
8740                   (gnus-treat-hide-boring-headers nil))
8741               (gnus-delete-wash-type 'headers)
8742               (gnus-treat-article 'head))
8743           (gnus-treat-article 'head))
8744         (widen)
8745         (if window
8746             (set-window-start window (goto-char (point-min))))
8747         (setq gnus-page-broken
8748               (when gnus-break-pages
8749                 (gnus-narrow-to-page)
8750                 t))
8751         (gnus-set-mode-line 'article)))))
8752
8753 (defun gnus-summary-show-all-headers ()
8754   "Make all header lines visible."
8755   (interactive)
8756   (gnus-summary-toggle-header 1))
8757
8758 (defun gnus-summary-toggle-mime (&optional arg)
8759   "Toggle MIME processing.
8760 If ARG is a positive number, turn MIME processing on."
8761   (interactive "P")
8762   (setq gnus-show-mime
8763         (if (null arg)
8764             (not gnus-show-mime)
8765           (> (prefix-numeric-value arg) 0)))
8766   (gnus-summary-select-article t 'force))
8767
8768 (defun gnus-summary-caesar-message (&optional arg)
8769   "Caesar rotate the current article by 13.
8770 The numerical prefix specifies how many places to rotate each letter
8771 forward."
8772   (interactive "P")
8773   (gnus-summary-select-article)
8774   (let ((mail-header-separator ""))
8775     (gnus-eval-in-buffer-window gnus-article-buffer
8776       (save-restriction
8777         (widen)
8778         (let ((start (window-start))
8779               buffer-read-only)
8780           (message-caesar-buffer-body arg)
8781           (set-window-start (get-buffer-window (current-buffer)) start))))))
8782
8783 (autoload 'unmorse-region "morse"
8784   "Convert morse coded text in region to ordinary ASCII text."
8785   t)
8786
8787 (defun gnus-summary-morse-message (&optional arg)
8788   "Morse decode the current article."
8789   (interactive "P")
8790   (gnus-summary-select-article)
8791   (let ((mail-header-separator ""))
8792     (gnus-eval-in-buffer-window gnus-article-buffer
8793       (save-excursion
8794         (save-restriction
8795           (widen)
8796           (let ((pos (window-start))
8797                 buffer-read-only)
8798             (goto-char (point-min))
8799             (when (message-goto-body)
8800               (gnus-narrow-to-body))
8801             (goto-char (point-min))
8802             (while (re-search-forward "·" (point-max) t)
8803               (replace-match "."))
8804             (unmorse-region (point-min) (point-max))
8805             (widen)
8806             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8807
8808 (defun gnus-summary-stop-page-breaking ()
8809   "Stop page breaking in the current article."
8810   (interactive)
8811   (gnus-summary-select-article)
8812   (gnus-eval-in-buffer-window gnus-article-buffer
8813     (widen)
8814     (when (gnus-visual-p 'page-marker)
8815       (let ((buffer-read-only nil))
8816         (gnus-remove-text-with-property 'gnus-prev)
8817         (gnus-remove-text-with-property 'gnus-next))
8818       (setq gnus-page-broken nil))))
8819
8820 (defun gnus-summary-move-article (&optional n to-newsgroup
8821                                             select-method action)
8822   "Move the current article to a different newsgroup.
8823 If N is a positive number, move the N next articles.
8824 If N is a negative number, move the N previous articles.
8825 If N is nil and any articles have been marked with the process mark,
8826 move those articles instead.
8827 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8828 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8829 re-spool using this method.
8830
8831 When called interactively with TO-NEWSGROUP being nil, the value of
8832 the variable `gnus-move-split-methods' is used for finding a default
8833 for the target newsgroup.
8834
8835 For this function to work, both the current newsgroup and the
8836 newsgroup that you want to move to have to support the `request-move'
8837 and `request-accept' functions.
8838
8839 ACTION can be either `move' (the default), `crosspost' or `copy'."
8840   (interactive "P")
8841   (unless action
8842     (setq action 'move))
8843   ;; Check whether the source group supports the required functions.
8844   (cond ((and (eq action 'move)
8845               (not (gnus-check-backend-function
8846                     'request-move-article gnus-newsgroup-name)))
8847          (error "The current group does not support article moving"))
8848         ((and (eq action 'crosspost)
8849               (not (gnus-check-backend-function
8850                     'request-replace-article gnus-newsgroup-name)))
8851          (error "The current group does not support article editing")))
8852   (let ((articles (gnus-summary-work-articles n))
8853         (prefix (if (gnus-check-backend-function
8854                      'request-move-article gnus-newsgroup-name)
8855                     (gnus-group-real-prefix gnus-newsgroup-name)
8856                   ""))
8857         (names '((move "Move" "Moving")
8858                  (copy "Copy" "Copying")
8859                  (crosspost "Crosspost" "Crossposting")))
8860         (copy-buf (save-excursion
8861                     (nnheader-set-temp-buffer " *copy article*")))
8862         (default-marks gnus-article-mark-lists)
8863         (no-expire-marks (delete '(expirable . expire)
8864                                  (copy-sequence gnus-article-mark-lists)))
8865         art-group to-method new-xref article to-groups)
8866     (unless (assq action names)
8867       (error "Unknown action %s" action))
8868     ;; Read the newsgroup name.
8869     (when (and (not to-newsgroup)
8870                (not select-method))
8871       (if (and gnus-move-split-methods
8872                (not
8873                 (and (memq gnus-current-article articles)
8874                      (gnus-buffer-live-p gnus-original-article-buffer))))
8875           ;; When `gnus-move-split-methods' is non-nil, we have to
8876           ;; select an article to give `gnus-read-move-group-name' an
8877           ;; opportunity to suggest an appropriate default.  However,
8878           ;; we needn't render or mark the article.
8879           (let ((gnus-display-mime-function nil)
8880                 (gnus-article-prepare-hook nil)
8881                 (gnus-mark-article-hook nil))
8882             (gnus-summary-select-article nil nil nil (car articles))))
8883       (setq to-newsgroup
8884             (gnus-read-move-group-name
8885              (cadr (assq action names))
8886              (symbol-value (intern (format "gnus-current-%s-group" action)))
8887              articles prefix))
8888       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8889     (setq to-method (or select-method
8890                         (gnus-server-to-method
8891                          (gnus-group-method to-newsgroup))))
8892     ;; Check the method we are to move this article to...
8893     (unless (gnus-check-backend-function
8894              'request-accept-article (car to-method))
8895       (error "%s does not support article copying" (car to-method)))
8896     (unless (gnus-check-server to-method)
8897       (error "Can't open server %s" (car to-method)))
8898     (gnus-message 6 "%s to %s: %s..."
8899                   (caddr (assq action names))
8900                   (or (car select-method) to-newsgroup) articles)
8901     (while articles
8902       (setq article (pop articles))
8903       (setq
8904        art-group
8905        (cond
8906         ;; Move the article.
8907         ((eq action 'move)
8908          ;; Remove this article from future suppression.
8909          (gnus-dup-unsuppress-article article)
8910          (gnus-request-move-article
8911           article                       ; Article to move
8912           gnus-newsgroup-name           ; From newsgroup
8913           (nth 1 (gnus-find-method-for-group
8914                   gnus-newsgroup-name)) ; Server
8915           (list 'gnus-request-accept-article
8916                 to-newsgroup (list 'quote select-method)
8917                 (not articles) t)       ; Accept form
8918           (not articles)))              ; Only save nov last time
8919         ;; Copy the article.
8920         ((eq action 'copy)
8921          (save-excursion
8922            (set-buffer copy-buf)
8923            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8924              (gnus-request-accept-article
8925               to-newsgroup select-method (not articles) t))))
8926         ;; Crosspost the article.
8927         ((eq action 'crosspost)
8928          (let ((xref (message-tokenize-header
8929                       (mail-header-xref (gnus-summary-article-header article))
8930                       " ")))
8931            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8932                                   ":" (number-to-string article)))
8933            (unless xref
8934              (setq xref (list (system-name))))
8935            (setq new-xref
8936                  (concat
8937                   (mapconcat 'identity
8938                              (delete "Xref:" (delete new-xref xref))
8939                              " ")
8940                   " " new-xref))
8941            (save-excursion
8942              (set-buffer copy-buf)
8943              ;; First put the article in the destination group.
8944              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8945              (when (consp (setq art-group
8946                                 (gnus-request-accept-article
8947                                  to-newsgroup select-method (not articles))))
8948                (setq new-xref (concat new-xref " " (car art-group)
8949                                       ":"
8950                                       (number-to-string (cdr art-group))))
8951                ;; Now we have the new Xrefs header, so we insert
8952                ;; it and replace the new article.
8953                (nnheader-replace-header "Xref" new-xref)
8954                (gnus-request-replace-article
8955                 (cdr art-group) to-newsgroup (current-buffer))
8956                art-group))))))
8957       (cond
8958        ((not art-group)
8959         (gnus-message 1 "Couldn't %s article %s: %s"
8960                       (cadr (assq action names)) article
8961                       (nnheader-get-report (car to-method))))
8962        ((eq art-group 'junk)
8963         (when (eq action 'move)
8964           (gnus-summary-mark-article article gnus-canceled-mark)
8965           (gnus-message 4 "Deleted article %s" article)
8966           ;; run the delete hook
8967           (run-hook-with-args 'gnus-summary-article-delete-hook
8968                               action
8969                               (gnus-data-header
8970                                (assoc article (gnus-data-list nil)))
8971                               gnus-newsgroup-name nil
8972                               select-method)))
8973        (t
8974         (let* ((pto-group (gnus-group-prefixed-name
8975                            (car art-group) to-method))
8976                (entry
8977                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8978                (info (nth 2 entry))
8979                (to-group (gnus-info-group info))
8980                to-marks)
8981           ;; Update the group that has been moved to.
8982           (when (and info
8983                      (memq action '(move copy)))
8984             (unless (member to-group to-groups)
8985               (push to-group to-groups))
8986
8987             (unless (memq article gnus-newsgroup-unreads)
8988               (push 'read to-marks)
8989               (gnus-info-set-read
8990                info (gnus-add-to-range (gnus-info-read info)
8991                                        (list (cdr art-group)))))
8992
8993             ;; See whether the article is to be put in the cache.
8994             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8995                              default-marks
8996                            no-expire-marks))
8997                   (to-article (cdr art-group)))
8998
8999               ;; Enter the article into the cache in the new group,
9000               ;; if that is required.
9001               (when gnus-use-cache
9002                 (gnus-cache-possibly-enter-article
9003                  to-group to-article
9004                  (let ((header (copy-sequence
9005                                 (gnus-summary-article-header article))))
9006                    (mail-header-set-number header to-article)
9007                    header)
9008                  (memq article gnus-newsgroup-marked)
9009                  (memq article gnus-newsgroup-dormant)
9010                  (memq article gnus-newsgroup-unreads)))
9011
9012               (when gnus-preserve-marks
9013                 ;; Copy any marks over to the new group.
9014                 (when (and (equal to-group gnus-newsgroup-name)
9015                            (not (memq article gnus-newsgroup-unreads)))
9016                   ;; Mark this article as read in this group.
9017                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9018                   (setcdr (gnus-active to-group) to-article)
9019                   (setcdr gnus-newsgroup-active to-article))
9020
9021                 (while marks
9022                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9023                     (when (memq article (symbol-value
9024                                          (intern (format "gnus-newsgroup-%s"
9025                                                          (caar marks)))))
9026                       (push (cdar marks) to-marks)
9027                       ;; If the other group is the same as this group,
9028                       ;; then we have to add the mark to the list.
9029                       (when (equal to-group gnus-newsgroup-name)
9030                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9031                              (cons to-article
9032                                    (symbol-value
9033                                     (intern (format "gnus-newsgroup-%s"
9034                                                     (caar marks)))))))
9035                       ;; Copy the marks to other group.
9036                       (gnus-add-marked-articles
9037                        to-group (cdar marks) (list to-article) info)))
9038                   (setq marks (cdr marks)))
9039
9040                 (gnus-request-set-mark
9041                  to-group (list (list (list to-article) 'add to-marks))))
9042
9043               (gnus-dribble-enter
9044                (concat "(gnus-group-set-info '"
9045                        (gnus-prin1-to-string (gnus-get-info to-group))
9046                        ")"))))
9047
9048           ;; Update the Xref header in this article to point to
9049           ;; the new crossposted article we have just created.
9050           (when (eq action 'crosspost)
9051             (save-excursion
9052               (set-buffer copy-buf)
9053               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9054               (nnheader-replace-header "Xref" new-xref)
9055               (gnus-request-replace-article
9056                article gnus-newsgroup-name (current-buffer))))
9057
9058           ;; run the move/copy/crosspost/respool hook
9059           (run-hook-with-args 'gnus-summary-article-move-hook 
9060                               action
9061                               (gnus-data-header 
9062                                (assoc article (gnus-data-list nil)))
9063                               gnus-newsgroup-name
9064                               to-newsgroup
9065                               select-method))
9066
9067         ;;;!!!Why is this necessary?
9068         (set-buffer gnus-summary-buffer)
9069         
9070         (gnus-summary-goto-subject article)
9071         (when (eq action 'move)
9072           (gnus-summary-mark-article article gnus-canceled-mark))))
9073       (gnus-summary-remove-process-mark article))
9074     ;; Re-activate all groups that have been moved to.
9075     (save-excursion
9076       (set-buffer gnus-group-buffer)
9077       (let ((gnus-group-marked to-groups))
9078         (gnus-group-get-new-news-this-group nil t)))
9079
9080     (gnus-kill-buffer copy-buf)
9081     (gnus-summary-position-point)
9082     (gnus-set-mode-line 'summary)))
9083
9084 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9085   "Move the current article to a different newsgroup.
9086 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9087 When called interactively, if TO-NEWSGROUP is nil, use the value of
9088 the variable `gnus-move-split-methods' for finding a default target
9089 newsgroup.
9090 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9091 re-spool using this method."
9092   (interactive "P")
9093   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9094
9095 (defun gnus-summary-crosspost-article (&optional n)
9096   "Crosspost the current article to some other group."
9097   (interactive "P")
9098   (gnus-summary-move-article n nil nil 'crosspost))
9099
9100 (defcustom gnus-summary-respool-default-method nil
9101   "Default method type for respooling an article.
9102 If nil, use to the current newsgroup method."
9103   :type 'symbol
9104   :group 'gnus-summary-mail)
9105
9106 (defcustom gnus-summary-display-while-building nil
9107   "If not-nil, show and update the summary buffer as it's being built.
9108 If the value is t, update the buffer after every line is inserted.  If
9109 the value is an integer (N), update the display every N lines."
9110   :group 'gnus-thread
9111   :type '(choice (const :tag "off" nil)
9112                  number
9113                  (const :tag "frequently" t)))
9114
9115 (defun gnus-summary-respool-article (&optional n method)
9116   "Respool the current article.
9117 The article will be squeezed through the mail spooling process again,
9118 which means that it will be put in some mail newsgroup or other
9119 depending on `nnmail-split-methods'.
9120 If N is a positive number, respool the N next articles.
9121 If N is a negative number, respool the N previous articles.
9122 If N is nil and any articles have been marked with the process mark,
9123 respool those articles instead.
9124
9125 Respooling can be done both from mail groups and \"real\" newsgroups.
9126 In the former case, the articles in question will be moved from the
9127 current group into whatever groups they are destined to.  In the
9128 latter case, they will be copied into the relevant groups."
9129   (interactive
9130    (list current-prefix-arg
9131          (let* ((methods (gnus-methods-using 'respool))
9132                 (methname
9133                  (symbol-name (or gnus-summary-respool-default-method
9134                                   (car (gnus-find-method-for-group
9135                                         gnus-newsgroup-name)))))
9136                 (method
9137                  (gnus-completing-read-with-default
9138                   methname "What backend do you want to use when respooling?"
9139                   methods nil t nil 'gnus-mail-method-history))
9140                 ms)
9141            (cond
9142             ((zerop (length (setq ms (gnus-servers-using-backend
9143                                       (intern method)))))
9144              (list (intern method) ""))
9145             ((= 1 (length ms))
9146              (car ms))
9147             (t
9148              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9149                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9150                            ms-alist))))))))
9151   (unless method
9152     (error "No method given for respooling"))
9153   (if (assoc (symbol-name
9154               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9155              (gnus-methods-using 'respool))
9156       (gnus-summary-move-article n nil method)
9157     (gnus-summary-copy-article n nil method)))
9158
9159 (defun gnus-summary-import-article (file &optional edit)
9160   "Import an arbitrary file into a mail newsgroup."
9161   (interactive "fImport file: \nP")
9162   (let ((group gnus-newsgroup-name)
9163         (now (current-time))
9164         atts lines group-art)
9165     (unless (gnus-check-backend-function 'request-accept-article group)
9166       (error "%s does not support article importing" group))
9167     (or (file-readable-p file)
9168         (not (file-regular-p file))
9169         (error "Can't read %s" file))
9170     (save-excursion
9171       (set-buffer (gnus-get-buffer-create " *import file*"))
9172       (erase-buffer)
9173       (nnheader-insert-file-contents file)
9174       (goto-char (point-min))
9175       (if (nnheader-article-p)
9176           (save-restriction
9177             (goto-char (point-min))
9178             (search-forward "\n\n" nil t)
9179             (narrow-to-region (point-min) (1- (point)))
9180             (goto-char (point-min))
9181             (unless (re-search-forward "^date:" nil t)
9182               (goto-char (point-max))
9183               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9184         ;; This doesn't look like an article, so we fudge some headers.
9185         (setq atts (file-attributes file)
9186               lines (count-lines (point-min) (point-max)))
9187         (insert "From: " (read-string "From: ") "\n"
9188                 "Subject: " (read-string "Subject: ") "\n"
9189                 "Date: " (message-make-date (nth 5 atts)) "\n"
9190                 "Message-ID: " (message-make-message-id) "\n"
9191                 "Lines: " (int-to-string lines) "\n"
9192                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9193       (setq group-art (gnus-request-accept-article group nil t))
9194       (kill-buffer (current-buffer)))
9195     (setq gnus-newsgroup-active (gnus-activate-group group))
9196     (forward-line 1)
9197     (gnus-summary-goto-article (cdr group-art) nil t)
9198     (when edit
9199       (gnus-summary-edit-article))))
9200
9201 (defun gnus-summary-create-article ()
9202   "Create an article in a mail newsgroup."
9203   (interactive)
9204   (let ((group gnus-newsgroup-name)
9205         (now (current-time))
9206         group-art)
9207     (unless (gnus-check-backend-function 'request-accept-article group)
9208       (error "%s does not support article importing" group))
9209     (save-excursion
9210       (set-buffer (gnus-get-buffer-create " *import file*"))
9211       (erase-buffer)
9212       (goto-char (point-min))
9213       ;; This doesn't look like an article, so we fudge some headers.
9214       (insert "From: " (read-string "From: ") "\n"
9215               "Subject: " (read-string "Subject: ") "\n"
9216               "Date: " (message-make-date now) "\n"
9217               "Message-ID: " (message-make-message-id) "\n")
9218       (setq group-art (gnus-request-accept-article group nil t))
9219       (kill-buffer (current-buffer)))
9220     (setq gnus-newsgroup-active (gnus-activate-group group))
9221     (forward-line 1)
9222     (gnus-summary-goto-article (cdr group-art) nil t)
9223     (gnus-summary-edit-article)))
9224
9225 (defun gnus-summary-article-posted-p ()
9226   "Say whether the current (mail) article is available from news as well.
9227 This will be the case if the article has both been mailed and posted."
9228   (interactive)
9229   (let ((id (mail-header-references (gnus-summary-article-header)))
9230         (gnus-override-method (car (gnus-refer-article-methods))))
9231     (if (gnus-request-head id "")
9232         (gnus-message 2 "The current message was found on %s"
9233                       gnus-override-method)
9234       (gnus-message 2 "The current message couldn't be found on %s"
9235                     gnus-override-method)
9236       nil)))
9237
9238 (defun gnus-summary-expire-articles (&optional now)
9239   "Expire all articles that are marked as expirable in the current group."
9240   (interactive)
9241   (when (and (not gnus-group-is-exiting-without-update-p)
9242              (gnus-check-backend-function
9243               'request-expire-articles gnus-newsgroup-name))
9244     ;; This backend supports expiry.
9245     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9246            (expirable (if total
9247                           (progn
9248                             ;; We need to update the info for
9249                             ;; this group for `gnus-list-of-read-articles'
9250                             ;; to give us the right answer.
9251                             (gnus-run-hooks 'gnus-exit-group-hook)
9252                             (gnus-summary-update-info)
9253                             (gnus-list-of-read-articles gnus-newsgroup-name))
9254                         (setq gnus-newsgroup-expirable
9255                               (sort gnus-newsgroup-expirable '<))))
9256            (expiry-wait (if now 'immediate
9257                           (gnus-group-find-parameter
9258                            gnus-newsgroup-name 'expiry-wait)))
9259            (nnmail-expiry-target
9260             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9261                 nnmail-expiry-target))
9262            es)
9263       (when expirable
9264         ;; There are expirable articles in this group, so we run them
9265         ;; through the expiry process.
9266         (gnus-message 6 "Expiring articles...")
9267         (unless (gnus-check-group gnus-newsgroup-name)
9268           (error "Can't open server for %s" gnus-newsgroup-name))
9269         ;; The list of articles that weren't expired is returned.
9270         (save-excursion
9271           (if expiry-wait
9272               (let ((nnmail-expiry-wait-function nil)
9273                     (nnmail-expiry-wait expiry-wait))
9274                 (setq es (gnus-request-expire-articles
9275                           expirable gnus-newsgroup-name)))
9276             (setq es (gnus-request-expire-articles
9277                       expirable gnus-newsgroup-name)))
9278           (unless total
9279             (setq gnus-newsgroup-expirable es))
9280           ;; We go through the old list of expirable, and mark all
9281           ;; really expired articles as nonexistent.
9282           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9283             (let ((gnus-use-cache nil))
9284               (dolist (article expirable)
9285                 (when (and (not (memq article es))
9286                            (gnus-data-find article))
9287                   (gnus-summary-mark-article article gnus-canceled-mark)
9288                   (run-hook-with-args 'gnus-summary-article-expire-hook
9289                                       'delete
9290                                       (gnus-data-header
9291                                        (assoc article (gnus-data-list nil)))
9292                                       gnus-newsgroup-name
9293                                       nil
9294                                       nil))))))
9295         (gnus-message 6 "Expiring articles...done")))))
9296
9297 (defun gnus-summary-expire-articles-now ()
9298   "Expunge all expirable articles in the current group.
9299 This means that *all* articles that are marked as expirable will be
9300 deleted forever, right now."
9301   (interactive)
9302   (or gnus-expert-user
9303       (gnus-yes-or-no-p
9304        "Are you really, really, really sure you want to delete all these messages? ")
9305       (error "Phew!"))
9306   (gnus-summary-expire-articles t))
9307
9308 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9309 (defun gnus-summary-delete-article (&optional n)
9310   "Delete the N next (mail) articles.
9311 This command actually deletes articles.  This is not a marking
9312 command.  The article will disappear forever from your life, never to
9313 return.
9314 If N is negative, delete backwards.
9315 If N is nil and articles have been marked with the process mark,
9316 delete these instead."
9317   (interactive "P")
9318   (unless (gnus-check-backend-function 'request-expire-articles
9319                                        gnus-newsgroup-name)
9320     (error "The current newsgroup does not support article deletion"))
9321   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9322     (error "Couldn't open server"))
9323   ;; Compute the list of articles to delete.
9324   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9325         (nnmail-expiry-target 'delete)
9326         not-deleted)
9327     (if (and gnus-novice-user
9328              (not (gnus-yes-or-no-p
9329                    (format "Do you really want to delete %s forever? "
9330                            (if (> (length articles) 1)
9331                                (format "these %s articles" (length articles))
9332                              "this article")))))
9333         ()
9334       ;; Delete the articles.
9335       (setq not-deleted (gnus-request-expire-articles
9336                          articles gnus-newsgroup-name 'force))
9337       (while articles
9338         (gnus-summary-remove-process-mark (car articles))
9339         ;; The backend might not have been able to delete the article
9340         ;; after all.
9341         (unless (memq (car articles) not-deleted)
9342           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9343         (let* ((article (car articles))
9344                (id (mail-header-id (gnus-data-header 
9345                                     (assoc article (gnus-data-list nil))))))
9346           (run-hook-with-args 'gnus-summary-article-delete-hook
9347                               'delete id gnus-newsgroup-name nil
9348                               nil))
9349         (setq articles (cdr articles)))
9350       (when not-deleted
9351         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9352     (gnus-summary-position-point)
9353     (gnus-set-mode-line 'summary)
9354     not-deleted))
9355
9356 (defun gnus-summary-edit-article (&optional force)
9357   "Edit the current article.
9358 This will have permanent effect only in mail groups.
9359 If FORCE is non-nil, allow editing of articles even in read-only
9360 groups."
9361   (interactive "P")
9362   (save-excursion
9363     (set-buffer gnus-summary-buffer)
9364     (let ((mail-parse-charset gnus-newsgroup-charset)
9365           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9366       (gnus-set-global-variables)
9367       (when (and (not force)
9368                  (gnus-group-read-only-p))
9369         (error "The current newsgroup does not support article editing"))
9370       (gnus-summary-show-article t)
9371       (gnus-article-edit-article
9372        'ignore
9373        `(lambda (no-highlight)
9374           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9375                 (message-options message-options)
9376                 (message-options-set-recipient)
9377                 (mail-parse-ignored-charsets
9378                  ',gnus-newsgroup-ignored-charsets))
9379             (gnus-summary-edit-article-done
9380              ,(or (mail-header-references gnus-current-headers) "")
9381              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9382
9383 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9384
9385 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9386                                                  no-highlight)
9387   "Make edits to the current article permanent."
9388   (interactive)
9389   (save-excursion
9390     ;; The buffer restriction contains the entire article if it exists.
9391     (when (article-goto-body)
9392       (let ((lines (count-lines (point) (point-max)))
9393             (length (- (point-max) (point)))
9394             (case-fold-search t)
9395             (body (copy-marker (point))))
9396         (goto-char (point-min))
9397         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9398           (delete-region (match-beginning 1) (match-end 1))
9399           (insert (number-to-string length)))
9400         (goto-char (point-min))
9401         (when (re-search-forward
9402                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9403           (delete-region (match-beginning 1) (match-end 1))
9404           (insert (number-to-string length)))
9405         (goto-char (point-min))
9406         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9407           (delete-region (match-beginning 1) (match-end 1))
9408           (insert (number-to-string lines))))))
9409   ;; Replace the article.
9410   (let ((buf (current-buffer)))
9411     (with-temp-buffer
9412       (insert-buffer-substring buf)
9413
9414       (if (and (not read-only)
9415                (not (gnus-request-replace-article
9416                      (cdr gnus-article-current) (car gnus-article-current)
9417                      (current-buffer) t)))
9418           (error "Couldn't replace article")
9419         ;; Update the summary buffer.
9420         (if (and references
9421                  (equal (message-tokenize-header references " ")
9422                         (message-tokenize-header
9423                          (or (message-fetch-field "references") "") " ")))
9424             ;; We only have to update this line.
9425             (save-excursion
9426               (save-restriction
9427                 (message-narrow-to-head)
9428                 (let ((head (buffer-string))
9429                       header)
9430                   (with-temp-buffer
9431                     (insert (format "211 %d Article retrieved.\n"
9432                                     (cdr gnus-article-current)))
9433                     (insert head)
9434                     (insert ".\n")
9435                     (let ((nntp-server-buffer (current-buffer)))
9436                       (setq header (car (gnus-get-newsgroup-headers
9437                                          nil t))))
9438                     (save-excursion
9439                       (set-buffer gnus-summary-buffer)
9440                       (gnus-data-set-header
9441                        (gnus-data-find (cdr gnus-article-current))
9442                        header)
9443                       (gnus-summary-update-article-line
9444                        (cdr gnus-article-current) header)
9445                       (if (gnus-summary-goto-subject
9446                            (cdr gnus-article-current) nil t)
9447                           (gnus-summary-update-secondary-mark
9448                            (cdr gnus-article-current))))))))
9449           ;; Update threads.
9450           (set-buffer (or buffer gnus-summary-buffer))
9451           (gnus-summary-update-article (cdr gnus-article-current))
9452           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9453               (gnus-summary-update-secondary-mark
9454                (cdr gnus-article-current))))
9455         ;; Prettify the article buffer again.
9456         (unless no-highlight
9457           (save-excursion
9458             (set-buffer gnus-article-buffer)
9459             ;;;!!! Fix this -- article should be rehighlighted.
9460             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9461             (set-buffer gnus-original-article-buffer)
9462             (gnus-request-article
9463              (cdr gnus-article-current)
9464              (car gnus-article-current) (current-buffer))))
9465         ;; Prettify the summary buffer line.
9466         (when (gnus-visual-p 'summary-highlight 'highlight)
9467           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9468
9469 (defun gnus-summary-edit-wash (key)
9470   "Perform editing command KEY in the article buffer."
9471   (interactive
9472    (list
9473     (progn
9474       (message "%s" (concat (this-command-keys) "- "))
9475       (read-char))))
9476   (message "")
9477   (gnus-summary-edit-article)
9478   (execute-kbd-macro (concat (this-command-keys) key))
9479   (gnus-article-edit-done))
9480
9481 ;;; Respooling
9482
9483 (defun gnus-summary-respool-query (&optional silent trace)
9484   "Query where the respool algorithm would put this article."
9485   (interactive)
9486   (let (gnus-mark-article-hook)
9487     (gnus-summary-select-article)
9488     (save-excursion
9489       (set-buffer gnus-original-article-buffer)
9490       (save-restriction
9491         (message-narrow-to-head)
9492         (let ((groups (nnmail-article-group 'identity trace)))
9493           (unless silent
9494             (if groups
9495                 (message "This message would go to %s"
9496                          (mapconcat 'car groups ", "))
9497               (message "This message would go to no groups"))
9498             groups))))))
9499
9500 (defun gnus-summary-respool-trace ()
9501   "Trace where the respool algorithm would put this article.
9502 Display a buffer showing all fancy splitting patterns which matched."
9503   (interactive)
9504   (gnus-summary-respool-query nil t))
9505
9506 ;; Summary marking commands.
9507
9508 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9509   "Mark articles which has the same subject as read, and then select the next.
9510 If UNMARK is positive, remove any kind of mark.
9511 If UNMARK is negative, tick articles."
9512   (interactive "P")
9513   (when unmark
9514     (setq unmark (prefix-numeric-value unmark)))
9515   (let ((count
9516          (gnus-summary-mark-same-subject
9517           (gnus-summary-article-subject) unmark)))
9518     ;; Select next unread article.  If auto-select-same mode, should
9519     ;; select the first unread article.
9520     (gnus-summary-next-article t (and gnus-auto-select-same
9521                                       (gnus-summary-article-subject)))
9522     (gnus-message 7 "%d article%s marked as %s"
9523                   count (if (= count 1) " is" "s are")
9524                   (if unmark "unread" "read"))))
9525
9526 (defun gnus-summary-kill-same-subject (&optional unmark)
9527   "Mark articles which has the same subject as read.
9528 If UNMARK is positive, remove any kind of mark.
9529 If UNMARK is negative, tick articles."
9530   (interactive "P")
9531   (when unmark
9532     (setq unmark (prefix-numeric-value unmark)))
9533   (let ((count
9534          (gnus-summary-mark-same-subject
9535           (gnus-summary-article-subject) unmark)))
9536     ;; If marked as read, go to next unread subject.
9537     (when (null unmark)
9538       ;; Go to next unread subject.
9539       (gnus-summary-next-subject 1 t))
9540     (gnus-message 7 "%d articles are marked as %s"
9541                   count (if unmark "unread" "read"))))
9542
9543 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9544   "Mark articles with same SUBJECT as read, and return marked number.
9545 If optional argument UNMARK is positive, remove any kinds of marks.
9546 If optional argument UNMARK is negative, mark articles as unread instead."
9547   (let ((count 1))
9548     (save-excursion
9549       (cond
9550        ((null unmark)                   ; Mark as read.
9551         (while (and
9552                 (progn
9553                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9554                   (gnus-summary-show-thread) t)
9555                 (gnus-summary-find-subject subject))
9556           (setq count (1+ count))))
9557        ((> unmark 0)                    ; Tick.
9558         (while (and
9559                 (progn
9560                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9561                   (gnus-summary-show-thread) t)
9562                 (gnus-summary-find-subject subject))
9563           (setq count (1+ count))))
9564        (t                               ; Mark as unread.
9565         (while (and
9566                 (progn
9567                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9568                   (gnus-summary-show-thread) t)
9569                 (gnus-summary-find-subject subject))
9570           (setq count (1+ count)))))
9571       (gnus-set-mode-line 'summary)
9572       ;; Return the number of marked articles.
9573       count)))
9574
9575 (defun gnus-summary-mark-as-processable (n &optional unmark)
9576   "Set the process mark on the next N articles.
9577 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9578 the process mark instead.  The difference between N and the actual
9579 number of articles marked is returned."
9580   (interactive "P")
9581   (if (and (null n) (gnus-region-active-p))
9582       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9583     (setq n (prefix-numeric-value n))
9584     (let ((backward (< n 0))
9585           (n (abs n)))
9586       (while (and
9587               (> n 0)
9588               (if unmark
9589                   (gnus-summary-remove-process-mark
9590                    (gnus-summary-article-number))
9591                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9592               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9593         (setq n (1- n)))
9594       (when (/= 0 n)
9595         (gnus-message 7 "No more articles"))
9596       (gnus-summary-recenter)
9597       (gnus-summary-position-point)
9598       n)))
9599
9600 (defun gnus-summary-unmark-as-processable (n)
9601   "Remove the process mark from the next N articles.
9602 If N is negative, unmark backward instead.  The difference between N and
9603 the actual number of articles unmarked is returned."
9604   (interactive "P")
9605   (gnus-summary-mark-as-processable n t))
9606
9607 (defun gnus-summary-unmark-all-processable ()
9608   "Remove the process mark from all articles."
9609   (interactive)
9610   (save-excursion
9611     (while gnus-newsgroup-processable
9612       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9613   (gnus-summary-position-point))
9614
9615 (defun gnus-summary-add-mark (article type)
9616   "Mark ARTICLE with a mark of TYPE."
9617   (let ((vtype (car (assq type gnus-article-mark-lists)))
9618         var)
9619     (if (not vtype)
9620         (error "No such mark type: %s" type)
9621       (setq var (intern (format "gnus-newsgroup-%s" type)))
9622       (set var (cons article (symbol-value var)))
9623       (if (memq type '(processable cached replied forwarded recent saved))
9624           (gnus-summary-update-secondary-mark article)
9625         ;;; !!! This is bogus.  We should find out what primary
9626         ;;; !!! mark we want to set.
9627         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9628
9629 (defun gnus-summary-mark-as-expirable (n)
9630   "Mark N articles forward as expirable.
9631 If N is negative, mark backward instead.  The difference between N and
9632 the actual number of articles marked is returned."
9633   (interactive "p")
9634   (gnus-summary-mark-forward n gnus-expirable-mark))
9635
9636 (defun gnus-summary-mark-as-spam (n)
9637   "Mark N articles forward as spam.
9638 If N is negative, mark backward instead.  The difference between N and
9639 the actual number of articles marked is returned."
9640   (interactive "p")
9641   (gnus-summary-mark-forward n gnus-spam-mark))
9642
9643 (defun gnus-summary-mark-article-as-replied (article)
9644   "Mark ARTICLE as replied to and update the summary line.
9645 ARTICLE can also be a list of articles."
9646   (interactive (list (gnus-summary-article-number)))
9647   (let ((articles (if (listp article) article (list article))))
9648     (dolist (article articles)
9649       (unless (numberp article)
9650         (error "%s is not a number" article))
9651       (push article gnus-newsgroup-replied)
9652       (let ((buffer-read-only nil))
9653         (when (gnus-summary-goto-subject article nil t)
9654           (gnus-summary-update-secondary-mark article))))))
9655
9656 (defun gnus-summary-mark-article-as-forwarded (article)
9657   "Mark ARTICLE as forwarded and update the summary line.
9658 ARTICLE can also be a list of articles."
9659   (let ((articles (if (listp article) article (list article))))
9660     (dolist (article articles)
9661       (push article gnus-newsgroup-forwarded)
9662       (let ((buffer-read-only nil))
9663         (when (gnus-summary-goto-subject article nil t)
9664           (gnus-summary-update-secondary-mark article))))))
9665
9666 (defun gnus-summary-set-bookmark (article)
9667   "Set a bookmark in current article."
9668   (interactive (list (gnus-summary-article-number)))
9669   (when (or (not (get-buffer gnus-article-buffer))
9670             (not gnus-current-article)
9671             (not gnus-article-current)
9672             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9673     (error "No current article selected"))
9674   ;; Remove old bookmark, if one exists.
9675   (gnus-pull article gnus-newsgroup-bookmarks)
9676   ;; Set the new bookmark, which is on the form
9677   ;; (article-number . line-number-in-body).
9678   (push
9679    (cons article
9680          (save-excursion
9681            (set-buffer gnus-article-buffer)
9682            (count-lines
9683             (min (point)
9684                  (save-excursion
9685                    (article-goto-body)
9686                    (point)))
9687             (point))))
9688    gnus-newsgroup-bookmarks)
9689   (gnus-message 6 "A bookmark has been added to the current article."))
9690
9691 (defun gnus-summary-remove-bookmark (article)
9692   "Remove the bookmark from the current article."
9693   (interactive (list (gnus-summary-article-number)))
9694   ;; Remove old bookmark, if one exists.
9695   (if (not (assq article gnus-newsgroup-bookmarks))
9696       (gnus-message 6 "No bookmark in current article.")
9697     (gnus-pull article gnus-newsgroup-bookmarks)
9698     (gnus-message 6 "Removed bookmark.")))
9699
9700 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9701 (defun gnus-summary-mark-as-dormant (n)
9702   "Mark N articles forward as dormant.
9703 If N is negative, mark backward instead.  The difference between N and
9704 the actual number of articles marked is returned."
9705   (interactive "p")
9706   (gnus-summary-mark-forward n gnus-dormant-mark))
9707
9708 (defun gnus-summary-set-process-mark (article)
9709   "Set the process mark on ARTICLE and update the summary line."
9710   (setq gnus-newsgroup-processable
9711         (cons article
9712               (delq article gnus-newsgroup-processable)))
9713   (when (gnus-summary-goto-subject article)
9714     (gnus-summary-show-thread)
9715     (gnus-summary-goto-subject article)
9716     (gnus-summary-update-secondary-mark article)))
9717
9718 (defun gnus-summary-remove-process-mark (article)
9719   "Remove the process mark from ARTICLE and update the summary line."
9720   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9721   (when (gnus-summary-goto-subject article)
9722     (gnus-summary-show-thread)
9723     (gnus-summary-goto-subject article)
9724     (gnus-summary-update-secondary-mark article)))
9725
9726 (defun gnus-summary-set-saved-mark (article)
9727   "Set the process mark on ARTICLE and update the summary line."
9728   (push article gnus-newsgroup-saved)
9729   (when (gnus-summary-goto-subject article)
9730     (gnus-summary-update-secondary-mark article)))
9731
9732 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9733   "Mark N articles as read forwards.
9734 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9735 The difference between N and the actual number of articles marked is
9736 returned.
9737 If NO-EXPIRE, auto-expiry will be inhibited."
9738   (interactive "p")
9739   (gnus-summary-show-thread)
9740   (let ((backward (< n 0))
9741         (gnus-summary-goto-unread
9742          (and gnus-summary-goto-unread
9743               (not (eq gnus-summary-goto-unread 'never))
9744               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9745                                     gnus-ticked-mark gnus-dormant-mark)))))
9746         (n (abs n))
9747         (mark (or mark gnus-del-mark)))
9748     (while (and (> n 0)
9749                 (gnus-summary-mark-article nil mark no-expire)
9750                 (zerop (gnus-summary-next-subject
9751                         (if backward -1 1)
9752                         (and gnus-summary-goto-unread
9753                              (not (eq gnus-summary-goto-unread 'never)))
9754                         t)))
9755       (setq n (1- n)))
9756     (when (/= 0 n)
9757       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9758     (gnus-summary-recenter)
9759     (gnus-summary-position-point)
9760     (gnus-set-mode-line 'summary)
9761     n))
9762
9763 (defun gnus-summary-mark-article-as-read (mark)
9764   "Mark the current article quickly as read with MARK."
9765   (let ((article (gnus-summary-article-number)))
9766     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9767     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9768     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9769     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9770     (push (cons article mark) gnus-newsgroup-reads)
9771     ;; Possibly remove from cache, if that is used.
9772     (when gnus-use-cache
9773       (gnus-cache-enter-remove-article article))
9774     ;; Allow the backend to change the mark.
9775     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9776     ;; Check for auto-expiry.
9777     (when (and gnus-newsgroup-auto-expire
9778                (memq mark gnus-auto-expirable-marks))
9779       (setq mark gnus-expirable-mark)
9780       ;; Let the backend know about the mark change.
9781       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9782       (push article gnus-newsgroup-expirable))
9783     ;; Set the mark in the buffer.
9784     (gnus-summary-update-mark mark 'unread)
9785     t))
9786
9787 (defun gnus-summary-mark-article-as-unread (mark)
9788   "Mark the current article quickly as unread with MARK."
9789   (let* ((article (gnus-summary-article-number))
9790          (old-mark (gnus-summary-article-mark article)))
9791     ;; Allow the backend to change the mark.
9792     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9793     (if (eq mark old-mark)
9794         t
9795       (if (<= article 0)
9796           (progn
9797             (gnus-error 1 "Can't mark negative article numbers")
9798             nil)
9799         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9800         (setq gnus-newsgroup-spam-marked
9801               (delq article gnus-newsgroup-spam-marked))
9802         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9803         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9804         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9805         (cond ((= mark gnus-ticked-mark)
9806                (setq gnus-newsgroup-marked
9807                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9808                                               article)))
9809               ((= mark gnus-spam-mark)
9810                (setq gnus-newsgroup-spam-marked
9811                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9812                                               article)))
9813               ((= mark gnus-dormant-mark)
9814                (setq gnus-newsgroup-dormant
9815                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9816                                               article)))
9817               (t
9818                (setq gnus-newsgroup-unreads
9819                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9820                                               article))))
9821         (gnus-pull article gnus-newsgroup-reads)
9822
9823         ;; See whether the article is to be put in the cache.
9824         (and gnus-use-cache
9825              (vectorp (gnus-summary-article-header article))
9826              (save-excursion
9827                (gnus-cache-possibly-enter-article
9828                 gnus-newsgroup-name article
9829                 (gnus-summary-article-header article)
9830                 (= mark gnus-ticked-mark)
9831                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9832
9833         ;; Fix the mark.
9834         (gnus-summary-update-mark mark 'unread)
9835         t))))
9836
9837 (defun gnus-summary-mark-article (&optional article mark no-expire)
9838   "Mark ARTICLE with MARK.  MARK can be any character.
9839 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9840 `??' (dormant) and `?E' (expirable).
9841 If MARK is nil, then the default character `?r' is used.
9842 If ARTICLE is nil, then the article on the current line will be
9843 marked.
9844 If NO-EXPIRE, auto-expiry will be inhibited."
9845   ;; The mark might be a string.
9846   (when (stringp mark)
9847     (setq mark (aref mark 0)))
9848   ;; If no mark is given, then we check auto-expiring.
9849   (when (null mark)
9850     (setq mark gnus-del-mark))
9851   (when (and (not no-expire)
9852              gnus-newsgroup-auto-expire
9853              (memq mark gnus-auto-expirable-marks))
9854     (setq mark gnus-expirable-mark))
9855   (let ((article (or article (gnus-summary-article-number)))
9856         (old-mark (gnus-summary-article-mark article)))
9857     ;; Allow the backend to change the mark.
9858     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9859     (if (eq mark old-mark)
9860         t
9861       (unless article
9862         (error "No article on current line"))
9863       (if (not (if (or (= mark gnus-unread-mark)
9864                        (= mark gnus-ticked-mark)
9865                        (= mark gnus-spam-mark)
9866                        (= mark gnus-dormant-mark))
9867                    (gnus-mark-article-as-unread article mark)
9868                  (gnus-mark-article-as-read article mark)))
9869           t
9870         ;; See whether the article is to be put in the cache.
9871         (and gnus-use-cache
9872              (not (= mark gnus-canceled-mark))
9873              (vectorp (gnus-summary-article-header article))
9874              (save-excursion
9875                (gnus-cache-possibly-enter-article
9876                 gnus-newsgroup-name article
9877                 (gnus-summary-article-header article)
9878                 (= mark gnus-ticked-mark)
9879                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9880
9881         (when (gnus-summary-goto-subject article nil t)
9882           (let ((buffer-read-only nil))
9883             (gnus-summary-show-thread)
9884             ;; Fix the mark.
9885             (gnus-summary-update-mark mark 'unread)
9886             t))))))
9887
9888 (defun gnus-summary-update-secondary-mark (article)
9889   "Update the secondary (read, process, cache) mark."
9890   (gnus-summary-update-mark
9891    (cond ((memq article gnus-newsgroup-processable)
9892           gnus-process-mark)
9893          ((memq article gnus-newsgroup-cached)
9894           gnus-cached-mark)
9895          ((memq article gnus-newsgroup-replied)
9896           gnus-replied-mark)
9897          ((memq article gnus-newsgroup-forwarded)
9898           gnus-forwarded-mark)
9899          ((memq article gnus-newsgroup-saved)
9900           gnus-saved-mark)
9901          ((memq article gnus-newsgroup-recent)
9902           gnus-recent-mark)
9903          ((memq article gnus-newsgroup-unseen)
9904           gnus-unseen-mark)
9905          (t gnus-no-mark))
9906    'replied)
9907   (when (gnus-visual-p 'summary-highlight 'highlight)
9908     (gnus-run-hooks 'gnus-summary-update-hook))
9909   t)
9910
9911 (defun gnus-summary-update-download-mark (article)
9912   "Update the download mark."
9913   (gnus-summary-update-mark
9914    (cond ((memq article gnus-newsgroup-undownloaded) 
9915           gnus-undownloaded-mark)
9916          (gnus-newsgroup-agentized
9917           gnus-downloaded-mark)
9918          (t
9919           gnus-no-mark))
9920    'download)
9921   (gnus-summary-update-line t)
9922   t)
9923
9924 (defun gnus-summary-update-mark (mark type)
9925   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9926         (buffer-read-only nil))
9927     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9928     (when forward
9929       (when (looking-at "\r")
9930         (incf forward))
9931       (when (<= (+ forward (point)) (point-max))
9932         ;; Go to the right position on the line.
9933         (goto-char (+ forward (point)))
9934         ;; Replace the old mark with the new mark.
9935         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9936         ;; Optionally update the marks by some user rule.
9937         (when (eq type 'unread)
9938           (gnus-data-set-mark
9939            (gnus-data-find (gnus-summary-article-number)) mark)
9940           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9941
9942 (defun gnus-mark-article-as-read (article &optional mark)
9943   "Enter ARTICLE in the pertinent lists and remove it from others."
9944   ;; Make the article expirable.
9945   (let ((mark (or mark gnus-del-mark)))
9946     (setq gnus-newsgroup-expirable
9947           (if (= mark gnus-expirable-mark)
9948               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9949             (delq article gnus-newsgroup-expirable)))
9950     ;; Remove from unread and marked lists.
9951     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9952     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9953     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9954     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9955     (push (cons article mark) gnus-newsgroup-reads)
9956     ;; Possibly remove from cache, if that is used.
9957     (when gnus-use-cache
9958       (gnus-cache-enter-remove-article article))
9959     t))
9960
9961 (defun gnus-mark-article-as-unread (article &optional mark)
9962   "Enter ARTICLE in the pertinent lists and remove it from others."
9963   (let ((mark (or mark gnus-ticked-mark)))
9964     (if (<= article 0)
9965         (progn
9966           (gnus-error 1 "Can't mark negative article numbers")
9967           nil)
9968       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9969             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9970             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9971             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9972             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9973
9974       ;; Unsuppress duplicates?
9975       (when gnus-suppress-duplicates
9976         (gnus-dup-unsuppress-article article))
9977
9978       (cond ((= mark gnus-ticked-mark)
9979              (setq gnus-newsgroup-marked
9980                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9981             ((= mark gnus-spam-mark)
9982              (setq gnus-newsgroup-spam-marked
9983                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9984                                             article)))
9985             ((= mark gnus-dormant-mark)
9986              (setq gnus-newsgroup-dormant
9987                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9988             (t
9989              (setq gnus-newsgroup-unreads
9990                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9991       (gnus-pull article gnus-newsgroup-reads)
9992       t)))
9993
9994 (defalias 'gnus-summary-mark-as-unread-forward
9995   'gnus-summary-tick-article-forward)
9996 (make-obsolete 'gnus-summary-mark-as-unread-forward
9997                'gnus-summary-tick-article-forward)
9998 (defun gnus-summary-tick-article-forward (n)
9999   "Tick N articles forwards.
10000 If N is negative, tick backwards instead.
10001 The difference between N and the number of articles ticked is returned."
10002   (interactive "p")
10003   (gnus-summary-mark-forward n gnus-ticked-mark))
10004
10005 (defalias 'gnus-summary-mark-as-unread-backward
10006   'gnus-summary-tick-article-backward)
10007 (make-obsolete 'gnus-summary-mark-as-unread-backward
10008                'gnus-summary-tick-article-backward)
10009 (defun gnus-summary-tick-article-backward (n)
10010   "Tick N articles backwards.
10011 The difference between N and the number of articles ticked is returned."
10012   (interactive "p")
10013   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10014
10015 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10016 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10017 (defun gnus-summary-tick-article (&optional article clear-mark)
10018   "Mark current article as unread.
10019 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10020 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10021   (interactive)
10022   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10023                                        gnus-ticked-mark)))
10024
10025 (defun gnus-summary-mark-as-read-forward (n)
10026   "Mark N articles as read forwards.
10027 If N is negative, mark backwards instead.
10028 The difference between N and the actual number of articles marked is
10029 returned."
10030   (interactive "p")
10031   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10032
10033 (defun gnus-summary-mark-as-read-backward (n)
10034   "Mark the N articles as read backwards.
10035 The difference between N and the actual number of articles marked is
10036 returned."
10037   (interactive "p")
10038   (gnus-summary-mark-forward
10039    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10040
10041 (defun gnus-summary-mark-as-read (&optional article mark)
10042   "Mark current article as read.
10043 ARTICLE specifies the article to be marked as read.
10044 MARK specifies a string to be inserted at the beginning of the line."
10045   (gnus-summary-mark-article article mark))
10046
10047 (defun gnus-summary-clear-mark-forward (n)
10048   "Clear marks from N articles forward.
10049 If N is negative, clear backward instead.
10050 The difference between N and the number of marks cleared is returned."
10051   (interactive "p")
10052   (gnus-summary-mark-forward n gnus-unread-mark))
10053
10054 (defun gnus-summary-clear-mark-backward (n)
10055   "Clear marks from N articles backward.
10056 The difference between N and the number of marks cleared is returned."
10057   (interactive "p")
10058   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10059
10060 (defun gnus-summary-mark-unread-as-read ()
10061   "Intended to be used by `gnus-summary-mark-article-hook'."
10062   (when (memq gnus-current-article gnus-newsgroup-unreads)
10063     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10064
10065 (defun gnus-summary-mark-read-and-unread-as-read ()
10066   "Intended to be used by `gnus-summary-mark-article-hook'."
10067   (let ((mark (gnus-summary-article-mark)))
10068     (when (or (gnus-unread-mark-p mark)
10069               (gnus-read-mark-p mark))
10070       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
10071
10072 (defun gnus-summary-mark-unread-as-ticked ()
10073   "Intended to be used by `gnus-summary-mark-article-hook'."
10074   (when (memq gnus-current-article gnus-newsgroup-unreads)
10075     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10076
10077 (defun gnus-summary-mark-region-as-read (point mark all)
10078   "Mark all unread articles between point and mark as read.
10079 If given a prefix, mark all articles between point and mark as read,
10080 even ticked and dormant ones."
10081   (interactive "r\nP")
10082   (save-excursion
10083     (let (article)
10084       (goto-char point)
10085       (beginning-of-line)
10086       (while (and
10087               (< (point) mark)
10088               (progn
10089                 (when (or all
10090                           (memq (setq article (gnus-summary-article-number))
10091                                 gnus-newsgroup-unreads))
10092                   (gnus-summary-mark-article article gnus-del-mark))
10093                 t)
10094               (gnus-summary-find-next))))))
10095
10096 (defun gnus-summary-mark-below (score mark)
10097   "Mark articles with score less than SCORE with MARK."
10098   (interactive "P\ncMark: ")
10099   (setq score (if score
10100                   (prefix-numeric-value score)
10101                 (or gnus-summary-default-score 0)))
10102   (save-excursion
10103     (set-buffer gnus-summary-buffer)
10104     (goto-char (point-min))
10105     (while
10106         (progn
10107           (and (< (gnus-summary-article-score) score)
10108                (gnus-summary-mark-article nil mark))
10109           (gnus-summary-find-next)))))
10110
10111 (defun gnus-summary-kill-below (&optional score)
10112   "Mark articles with score below SCORE as read."
10113   (interactive "P")
10114   (gnus-summary-mark-below score gnus-killed-mark))
10115
10116 (defun gnus-summary-clear-above (&optional score)
10117   "Clear all marks from articles with score above SCORE."
10118   (interactive "P")
10119   (gnus-summary-mark-above score gnus-unread-mark))
10120
10121 (defun gnus-summary-tick-above (&optional score)
10122   "Tick all articles with score above SCORE."
10123   (interactive "P")
10124   (gnus-summary-mark-above score gnus-ticked-mark))
10125
10126 (defun gnus-summary-mark-above (score mark)
10127   "Mark articles with score over SCORE with MARK."
10128   (interactive "P\ncMark: ")
10129   (setq score (if score
10130                   (prefix-numeric-value score)
10131                 (or gnus-summary-default-score 0)))
10132   (save-excursion
10133     (set-buffer gnus-summary-buffer)
10134     (goto-char (point-min))
10135     (while (and (progn
10136                   (when (> (gnus-summary-article-score) score)
10137                     (gnus-summary-mark-article nil mark))
10138                   t)
10139                 (gnus-summary-find-next)))))
10140
10141 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10142 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10143 (defun gnus-summary-limit-include-expunged (&optional no-error)
10144   "Display all the hidden articles that were expunged for low scores."
10145   (interactive)
10146   (let ((buffer-read-only nil))
10147     (let ((scored gnus-newsgroup-scored)
10148           headers h)
10149       (while scored
10150         (unless (gnus-summary-article-header (caar scored))
10151           (and (setq h (gnus-number-to-header (caar scored)))
10152                (< (cdar scored) gnus-summary-expunge-below)
10153                (push h headers)))
10154         (setq scored (cdr scored)))
10155       (if (not headers)
10156           (when (not no-error)
10157             (error "No expunged articles hidden"))
10158         (goto-char (point-min))
10159         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10160         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10161         (mapcar (lambda (x) (push (mail-header-number x)
10162                                   gnus-newsgroup-limit))
10163                 headers)
10164         (gnus-summary-prepare-unthreaded (nreverse headers))
10165         (goto-char (point-min))
10166         (gnus-summary-position-point)
10167         t))))
10168
10169 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10170   "Mark all unread articles in this newsgroup as read.
10171 If prefix argument ALL is non-nil, ticked and dormant articles will
10172 also be marked as read.
10173 If QUIETLY is non-nil, no questions will be asked.
10174 If TO-HERE is non-nil, it should be a point in the buffer.  All
10175 articles before (after, if REVERSE is set) this point will be marked as read.
10176 Note that this function will only catch up the unread article
10177 in the current summary buffer limitation.
10178 The number of articles marked as read is returned."
10179   (interactive "P")
10180   (prog1
10181       (save-excursion
10182         (when (or quietly
10183                   (not gnus-interactive-catchup) ;Without confirmation?
10184                   gnus-expert-user
10185                   (gnus-y-or-n-p
10186                    (if all
10187                        "Mark absolutely all articles as read? "
10188                      "Mark all unread articles as read? ")))
10189           (if (and not-mark
10190                    (not gnus-newsgroup-adaptive)
10191                    (not gnus-newsgroup-auto-expire)
10192                    (not gnus-suppress-duplicates)
10193                    (or (not gnus-use-cache)
10194                        (eq gnus-use-cache 'passive)))
10195               (progn
10196                 (when all
10197                   (setq gnus-newsgroup-marked nil
10198                         gnus-newsgroup-spam-marked nil
10199                         gnus-newsgroup-dormant nil))
10200                 (setq gnus-newsgroup-unreads
10201                       (gnus-sorted-nunion
10202                        (gnus-intersection gnus-newsgroup-unreads
10203                                           gnus-newsgroup-downloadable)
10204                        gnus-newsgroup-unfetched)))
10205             ;; We actually mark all articles as canceled, which we
10206             ;; have to do when using auto-expiry or adaptive scoring.
10207             (gnus-summary-show-all-threads)
10208             (if (and to-here reverse)
10209                 (progn
10210                   (goto-char to-here)
10211                   (while (and
10212                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10213                           (gnus-summary-find-next (not all)))))
10214               (when (gnus-summary-first-subject (not all))
10215                 (while (and
10216                         (if to-here (< (point) to-here) t)
10217                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10218                         (gnus-summary-find-next (not all))))))
10219             (gnus-set-mode-line 'summary))
10220           t))
10221     (gnus-summary-position-point)))
10222
10223 (defun gnus-summary-catchup-to-here (&optional all)
10224   "Mark all unticked articles before the current one as read.
10225 If ALL is non-nil, also mark ticked and dormant articles as read."
10226   (interactive "P")
10227   (save-excursion
10228     (gnus-save-hidden-threads
10229       (let ((beg (point)))
10230         ;; We check that there are unread articles.
10231         (when (or all (gnus-summary-find-prev))
10232           (gnus-summary-catchup all t beg)))))
10233   (gnus-summary-position-point))
10234
10235 (defun gnus-summary-catchup-from-here (&optional all)
10236   "Mark all unticked articles after the current one as read.
10237 If ALL is non-nil, also mark ticked and dormant articles as read."
10238   (interactive "P")
10239   (save-excursion
10240     (gnus-save-hidden-threads
10241       (let ((beg (point)))
10242         ;; We check that there are unread articles.
10243         (when (or all (gnus-summary-find-next))
10244           (gnus-summary-catchup all t beg nil t)))))
10245   (gnus-summary-position-point))
10246
10247 (defun gnus-summary-catchup-all (&optional quietly)
10248   "Mark all articles in this newsgroup as read.
10249 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10250 instead, which marks only unread articles as read."
10251   (interactive "P")
10252   (gnus-summary-catchup t quietly))
10253
10254 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10255   "Mark all unread articles in this group as read, then exit.
10256 If prefix argument ALL is non-nil, all articles are marked as read.
10257 If QUIETLY is non-nil, no questions will be asked."
10258   (interactive "P")
10259   (when (gnus-summary-catchup all quietly nil 'fast)
10260     ;; Select next newsgroup or exit.
10261     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10262              (eq gnus-auto-select-next 'quietly))
10263         (gnus-summary-next-group nil)
10264       (gnus-summary-exit))))
10265
10266 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10267   "Mark all articles in this newsgroup as read, and then exit.
10268 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10269 instead, which marks only unread articles as read."
10270   (interactive "P")
10271   (gnus-summary-catchup-and-exit t quietly))
10272
10273 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10274   "Mark all articles in this group as read and select the next group.
10275 If given a prefix, mark all articles, unread as well as ticked, as
10276 read."
10277   (interactive "P")
10278   (save-excursion
10279     (gnus-summary-catchup all))
10280   (gnus-summary-next-group))
10281
10282 ;;;
10283 ;;; with article
10284 ;;;
10285
10286 (defmacro gnus-with-article (article &rest forms)
10287   "Select ARTICLE and perform FORMS in the original article buffer.
10288 Then replace the article with the result."
10289   `(progn
10290      ;; We don't want the article to be marked as read.
10291      (let (gnus-mark-article-hook)
10292        (gnus-summary-select-article t t nil ,article))
10293      (set-buffer gnus-original-article-buffer)
10294      ,@forms
10295      (if (not (gnus-check-backend-function
10296                'request-replace-article (car gnus-article-current)))
10297          (gnus-message 5 "Read-only group; not replacing")
10298        (unless (gnus-request-replace-article
10299                 ,article (car gnus-article-current)
10300                 (current-buffer) t)
10301          (error "Couldn't replace article")))
10302      ;; The cache and backlog have to be flushed somewhat.
10303      (when gnus-keep-backlog
10304        (gnus-backlog-remove-article
10305         (car gnus-article-current) (cdr gnus-article-current)))
10306      (when gnus-use-cache
10307        (gnus-cache-update-article
10308         (car gnus-article-current) (cdr gnus-article-current)))))
10309
10310 (put 'gnus-with-article 'lisp-indent-function 1)
10311 (put 'gnus-with-article 'edebug-form-spec '(form body))
10312
10313 ;; Thread-based commands.
10314
10315 (defun gnus-summary-articles-in-thread (&optional article)
10316   "Return a list of all articles in the current thread.
10317 If ARTICLE is non-nil, return all articles in the thread that starts
10318 with that article."
10319   (let* ((article (or article (gnus-summary-article-number)))
10320          (data (gnus-data-find-list article))
10321          (top-level (gnus-data-level (car data)))
10322          (top-subject
10323           (cond ((null gnus-thread-operation-ignore-subject)
10324                  (gnus-simplify-subject-re
10325                   (mail-header-subject (gnus-data-header (car data)))))
10326                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10327                  (gnus-simplify-subject-fuzzy
10328                   (mail-header-subject (gnus-data-header (car data)))))
10329                 (t nil)))
10330          (end-point (save-excursion
10331                       (if (gnus-summary-go-to-next-thread)
10332                           (point) (point-max))))
10333          articles)
10334     (while (and data
10335                 (< (gnus-data-pos (car data)) end-point))
10336       (when (or (not top-subject)
10337                 (string= top-subject
10338                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10339                              (gnus-simplify-subject-fuzzy
10340                               (mail-header-subject
10341                                (gnus-data-header (car data))))
10342                            (gnus-simplify-subject-re
10343                             (mail-header-subject
10344                              (gnus-data-header (car data)))))))
10345         (push (gnus-data-number (car data)) articles))
10346       (unless (and (setq data (cdr data))
10347                    (> (gnus-data-level (car data)) top-level))
10348         (setq data nil)))
10349     ;; Return the list of articles.
10350     (nreverse articles)))
10351
10352 (defun gnus-summary-rethread-current ()
10353   "Rethread the thread the current article is part of."
10354   (interactive)
10355   (let* ((gnus-show-threads t)
10356          (article (gnus-summary-article-number))
10357          (id (mail-header-id (gnus-summary-article-header)))
10358          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10359     (unless id
10360       (error "No article on the current line"))
10361     (gnus-rebuild-thread id)
10362     (gnus-summary-goto-subject article)))
10363
10364 (defun gnus-summary-reparent-thread ()
10365   "Make the current article child of the marked (or previous) article.
10366
10367 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10368 is non-nil or the Subject: of both articles are the same."
10369   (interactive)
10370   (unless (not (gnus-group-read-only-p))
10371     (error "The current newsgroup does not support article editing"))
10372   (unless (<= (length gnus-newsgroup-processable) 1)
10373     (error "No more than one article may be marked"))
10374   (save-window-excursion
10375     (let ((gnus-article-buffer " *reparent*")
10376           (current-article (gnus-summary-article-number))
10377           ;; First grab the marked article, otherwise one line up.
10378           (parent-article (if (not (null gnus-newsgroup-processable))
10379                               (car gnus-newsgroup-processable)
10380                             (save-excursion
10381                               (if (eq (forward-line -1) 0)
10382                                   (gnus-summary-article-number)
10383                                 (error "Beginning of summary buffer"))))))
10384       (unless (not (eq current-article parent-article))
10385         (error "An article may not be self-referential"))
10386       (let ((message-id (mail-header-id
10387                          (gnus-summary-article-header parent-article))))
10388         (unless (and message-id (not (equal message-id "")))
10389           (error "No message-id in desired parent"))
10390         (gnus-with-article current-article
10391           (save-restriction
10392             (goto-char (point-min))
10393             (message-narrow-to-head)
10394             (if (re-search-forward "^References: " nil t)
10395                 (progn
10396                   (re-search-forward "^[^ \t]" nil t)
10397                   (forward-line -1)
10398                   (end-of-line)
10399                   (insert " " message-id))
10400               (insert "References: " message-id "\n"))))
10401         (set-buffer gnus-summary-buffer)
10402         (gnus-summary-unmark-all-processable)
10403         (gnus-summary-update-article current-article)
10404         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10405             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10406         (gnus-summary-rethread-current)
10407         (gnus-message 3 "Article %d is now the child of article %d"
10408                       current-article parent-article)))))
10409
10410 (defun gnus-summary-toggle-threads (&optional arg)
10411   "Toggle showing conversation threads.
10412 If ARG is positive number, turn showing conversation threads on."
10413   (interactive "P")
10414   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10415     (setq gnus-show-threads
10416           (if (null arg) (not gnus-show-threads)
10417             (> (prefix-numeric-value arg) 0)))
10418     (gnus-summary-prepare)
10419     (gnus-summary-goto-subject current)
10420     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10421     (gnus-summary-position-point)))
10422
10423 (defun gnus-summary-show-all-threads ()
10424   "Show all threads."
10425   (interactive)
10426   (save-excursion
10427     (let ((buffer-read-only nil))
10428       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10429   (gnus-summary-position-point))
10430
10431 (defun gnus-summary-show-thread ()
10432   "Show thread subtrees.
10433 Returns nil if no thread was there to be shown."
10434   (interactive)
10435   (let ((buffer-read-only nil)
10436         (orig (point))
10437         (end (gnus-point-at-eol))
10438         ;; Leave point at bol
10439         (beg (progn (beginning-of-line) (point))))
10440     (prog1
10441         ;; Any hidden lines here?
10442         (search-forward "\r" end t)
10443       (subst-char-in-region beg end ?\^M ?\n t)
10444       (goto-char orig)
10445       (gnus-summary-position-point))))
10446
10447 (defun gnus-summary-maybe-hide-threads ()
10448   "If requested, hide the threads that should be hidden."
10449   (when (and gnus-show-threads
10450              gnus-thread-hide-subtree)
10451     (gnus-summary-hide-all-threads
10452      (if (or (consp gnus-thread-hide-subtree)
10453              (gnus-functionp gnus-thread-hide-subtree))
10454          (gnus-make-predicate gnus-thread-hide-subtree)
10455        nil))))
10456
10457 ;;; Hiding predicates.
10458
10459 (defun gnus-article-unread-p (header)
10460   (memq (mail-header-number header) gnus-newsgroup-unreads))
10461
10462 (defun gnus-article-unseen-p (header)
10463   (memq (mail-header-number header) gnus-newsgroup-unseen))
10464
10465 (defun gnus-map-articles (predicate articles)
10466   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10467   (apply 'gnus-or (mapcar predicate
10468                           (mapcar 'gnus-summary-article-header articles))))
10469
10470 (defun gnus-summary-hide-all-threads (&optional predicate)
10471   "Hide all thread subtrees.
10472 If PREDICATE is supplied, threads that satisfy this predicate
10473 will not be hidden."
10474   (interactive)
10475   (save-excursion
10476     (goto-char (point-min))
10477     (let ((end nil))
10478       (while (not end)
10479         (when (or (not predicate)
10480                   (gnus-map-articles
10481                    predicate (gnus-summary-article-children)))
10482             (gnus-summary-hide-thread))
10483         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10484   (gnus-summary-position-point))
10485
10486 (defun gnus-summary-hide-thread ()
10487   "Hide thread subtrees.
10488 If PREDICATE is supplied, threads that satisfy this predicate
10489 will not be hidden.
10490 Returns nil if no threads were there to be hidden."
10491   (interactive)
10492   (let ((buffer-read-only nil)
10493         (start (point))
10494         (article (gnus-summary-article-number)))
10495     (goto-char start)
10496     ;; Go forward until either the buffer ends or the subthread
10497     ;; ends.
10498     (when (and (not (eobp))
10499                (or (zerop (gnus-summary-next-thread 1 t))
10500                    (goto-char (point-max))))
10501       (prog1
10502           (if (and (> (point) start)
10503                    (search-backward "\n" start t))
10504               (progn
10505                 (subst-char-in-region start (point) ?\n ?\^M)
10506                 (gnus-summary-goto-subject article))
10507             (goto-char start)
10508             nil)))))
10509
10510 (defun gnus-summary-go-to-next-thread (&optional previous)
10511   "Go to the same level (or less) next thread.
10512 If PREVIOUS is non-nil, go to previous thread instead.
10513 Return the article number moved to, or nil if moving was impossible."
10514   (let ((level (gnus-summary-thread-level))
10515         (way (if previous -1 1))
10516         (beg (point)))
10517     (forward-line way)
10518     (while (and (not (eobp))
10519                 (< level (gnus-summary-thread-level)))
10520       (forward-line way))
10521     (if (eobp)
10522         (progn
10523           (goto-char beg)
10524           nil)
10525       (setq beg (point))
10526       (prog1
10527           (gnus-summary-article-number)
10528         (goto-char beg)))))
10529
10530 (defun gnus-summary-next-thread (n &optional silent)
10531   "Go to the same level next N'th thread.
10532 If N is negative, search backward instead.
10533 Returns the difference between N and the number of skips actually
10534 done.
10535
10536 If SILENT, don't output messages."
10537   (interactive "p")
10538   (let ((backward (< n 0))
10539         (n (abs n)))
10540     (while (and (> n 0)
10541                 (gnus-summary-go-to-next-thread backward))
10542       (decf n))
10543     (unless silent
10544       (gnus-summary-position-point))
10545     (when (and (not silent) (/= 0 n))
10546       (gnus-message 7 "No more threads"))
10547     n))
10548
10549 (defun gnus-summary-prev-thread (n)
10550   "Go to the same level previous N'th thread.
10551 Returns the difference between N and the number of skips actually
10552 done."
10553   (interactive "p")
10554   (gnus-summary-next-thread (- n)))
10555
10556 (defun gnus-summary-go-down-thread ()
10557   "Go down one level in the current thread."
10558   (let ((children (gnus-summary-article-children)))
10559     (when children
10560       (gnus-summary-goto-subject (car children)))))
10561
10562 (defun gnus-summary-go-up-thread ()
10563   "Go up one level in the current thread."
10564   (let ((parent (gnus-summary-article-parent)))
10565     (when parent
10566       (gnus-summary-goto-subject parent))))
10567
10568 (defun gnus-summary-down-thread (n)
10569   "Go down thread N steps.
10570 If N is negative, go up instead.
10571 Returns the difference between N and how many steps down that were
10572 taken."
10573   (interactive "p")
10574   (let ((up (< n 0))
10575         (n (abs n)))
10576     (while (and (> n 0)
10577                 (if up (gnus-summary-go-up-thread)
10578                   (gnus-summary-go-down-thread)))
10579       (setq n (1- n)))
10580     (gnus-summary-position-point)
10581     (when (/= 0 n)
10582       (gnus-message 7 "Can't go further"))
10583     n))
10584
10585 (defun gnus-summary-up-thread (n)
10586   "Go up thread N steps.
10587 If N is negative, go down instead.
10588 Returns the difference between N and how many steps down that were
10589 taken."
10590   (interactive "p")
10591   (gnus-summary-down-thread (- n)))
10592
10593 (defun gnus-summary-top-thread ()
10594   "Go to the top of the thread."
10595   (interactive)
10596   (while (gnus-summary-go-up-thread))
10597   (gnus-summary-article-number))
10598
10599 (defun gnus-summary-kill-thread (&optional unmark)
10600   "Mark articles under current thread as read.
10601 If the prefix argument is positive, remove any kinds of marks.
10602 If the prefix argument is negative, tick articles instead."
10603   (interactive "P")
10604   (when unmark
10605     (setq unmark (prefix-numeric-value unmark)))
10606   (let ((articles (gnus-summary-articles-in-thread)))
10607     (save-excursion
10608       ;; Expand the thread.
10609       (gnus-summary-show-thread)
10610       ;; Mark all the articles.
10611       (while articles
10612         (gnus-summary-goto-subject (car articles))
10613         (cond ((null unmark)
10614                (gnus-summary-mark-article-as-read gnus-killed-mark))
10615               ((> unmark 0)
10616                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10617               (t
10618                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10619         (setq articles (cdr articles))))
10620     ;; Hide killed subtrees.
10621     (and (null unmark)
10622          gnus-thread-hide-killed
10623          (gnus-summary-hide-thread))
10624     ;; If marked as read, go to next unread subject.
10625     (when (null unmark)
10626       ;; Go to next unread subject.
10627       (gnus-summary-next-subject 1 t)))
10628   (gnus-set-mode-line 'summary))
10629
10630 ;; Summary sorting commands
10631
10632 (defun gnus-summary-sort-by-number (&optional reverse)
10633   "Sort the summary buffer by article number.
10634 Argument REVERSE means reverse order."
10635   (interactive "P")
10636   (gnus-summary-sort 'number reverse))
10637
10638 (defun gnus-summary-sort-by-random (&optional reverse)
10639   "Randomize the order in the summary buffer.
10640 Argument REVERSE means to randomize in reverse order."
10641   (interactive "P")
10642   (gnus-summary-sort 'random reverse))
10643
10644 (defun gnus-summary-sort-by-author (&optional reverse)
10645   "Sort the summary buffer by author name alphabetically.
10646 If `case-fold-search' is non-nil, case of letters is ignored.
10647 Argument REVERSE means reverse order."
10648   (interactive "P")
10649   (gnus-summary-sort 'author reverse))
10650
10651 (defun gnus-summary-sort-by-subject (&optional reverse)
10652   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10653 If `case-fold-search' is non-nil, case of letters is ignored.
10654 Argument REVERSE means reverse order."
10655   (interactive "P")
10656   (gnus-summary-sort 'subject reverse))
10657
10658 (defun gnus-summary-sort-by-date (&optional reverse)
10659   "Sort the summary buffer by date.
10660 Argument REVERSE means reverse order."
10661   (interactive "P")
10662   (gnus-summary-sort 'date reverse))
10663
10664 (defun gnus-summary-sort-by-score (&optional reverse)
10665   "Sort the summary buffer by score.
10666 Argument REVERSE means reverse order."
10667   (interactive "P")
10668   (gnus-summary-sort 'score reverse))
10669
10670 (defun gnus-summary-sort-by-lines (&optional reverse)
10671   "Sort the summary buffer by the number of lines.
10672 Argument REVERSE means reverse order."
10673   (interactive "P")
10674   (gnus-summary-sort 'lines reverse))
10675
10676 (defun gnus-summary-sort-by-chars (&optional reverse)
10677   "Sort the summary buffer by article length.
10678 Argument REVERSE means reverse order."
10679   (interactive "P")
10680   (gnus-summary-sort 'chars reverse))
10681
10682 (defun gnus-summary-sort-by-original (&optional reverse)
10683   "Sort the summary buffer using the default sorting method.
10684 Argument REVERSE means reverse order."
10685   (interactive "P")
10686   (let* ((buffer-read-only)
10687          (gnus-summary-prepare-hook nil))
10688     ;; We do the sorting by regenerating the threads.
10689     (gnus-summary-prepare)
10690     ;; Hide subthreads if needed.
10691     (gnus-summary-maybe-hide-threads)))
10692
10693 (defun gnus-summary-sort (predicate reverse)
10694   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10695   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10696          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10697          (gnus-thread-sort-functions
10698           (if (not reverse)
10699               thread
10700             `(lambda (t1 t2)
10701                (,thread t2 t1))))
10702          (gnus-sort-gathered-threads-function
10703           gnus-thread-sort-functions)
10704          (gnus-article-sort-functions
10705           (if (not reverse)
10706               article
10707             `(lambda (t1 t2)
10708                (,article t2 t1))))
10709          (buffer-read-only)
10710          (gnus-summary-prepare-hook nil))
10711     ;; We do the sorting by regenerating the threads.
10712     (gnus-summary-prepare)
10713     ;; Hide subthreads if needed.
10714     (gnus-summary-maybe-hide-threads)))
10715
10716 ;; Summary saving commands.
10717
10718 (defun gnus-summary-save-article (&optional n not-saved)
10719   "Save the current article using the default saver function.
10720 If N is a positive number, save the N next articles.
10721 If N is a negative number, save the N previous articles.
10722 If N is nil and any articles have been marked with the process mark,
10723 save those articles instead.
10724 The variable `gnus-default-article-saver' specifies the saver function."
10725   (interactive "P")
10726   (let* ((articles (gnus-summary-work-articles n))
10727          (save-buffer (save-excursion
10728                         (nnheader-set-temp-buffer " *Gnus Save*")))
10729          (num (length articles))
10730          header file)
10731     (dolist (article articles)
10732       (setq header (gnus-summary-article-header article))
10733       (if (not (vectorp header))
10734           ;; This is a pseudo-article.
10735           (if (assq 'name header)
10736               (gnus-copy-file (cdr (assq 'name header)))
10737             (gnus-message 1 "Article %d is unsaveable" article))
10738         ;; This is a real article.
10739         (save-window-excursion
10740           (let ((gnus-display-mime-function nil)
10741                 (gnus-article-prepare-hook nil))
10742             (gnus-summary-select-article t nil nil article)))
10743         (save-excursion
10744           (set-buffer save-buffer)
10745           (erase-buffer)
10746           (insert-buffer-substring gnus-original-article-buffer))
10747         (setq file (gnus-article-save save-buffer file num))
10748         (gnus-summary-remove-process-mark article)
10749         (unless not-saved
10750           (gnus-summary-set-saved-mark article))))
10751     (gnus-kill-buffer save-buffer)
10752     (gnus-summary-position-point)
10753     (gnus-set-mode-line 'summary)
10754     n))
10755
10756 (defun gnus-summary-pipe-output (&optional arg headers)
10757   "Pipe the current article to a subprocess.
10758 If N is a positive number, pipe the N next articles.
10759 If N is a negative number, pipe the N previous articles.
10760 If N is nil and any articles have been marked with the process mark,
10761 pipe those articles instead.
10762 If HEADERS (the symbolic prefix), include the headers, too."
10763   (interactive (gnus-interactive "P\ny"))
10764   (require 'gnus-art)
10765   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10766         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10767     (gnus-summary-save-article arg t))
10768   (let ((buffer (get-buffer "*Shell Command Output*")))
10769     (when (and buffer
10770                (not (zerop (buffer-size buffer))))
10771       (gnus-configure-windows 'pipe))))
10772
10773 (defun gnus-summary-save-article-mail (&optional arg)
10774   "Append the current article to an mail file.
10775 If N is a positive number, save the N next articles.
10776 If N is a negative number, save the N previous articles.
10777 If N is nil and any articles have been marked with the process mark,
10778 save those articles instead."
10779   (interactive "P")
10780   (require 'gnus-art)
10781   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10782     (gnus-summary-save-article arg)))
10783
10784 (defun gnus-summary-save-article-rmail (&optional arg)
10785   "Append the current article to an rmail file.
10786 If N is a positive number, save the N next articles.
10787 If N is a negative number, save the N previous articles.
10788 If N is nil and any articles have been marked with the process mark,
10789 save those articles instead."
10790   (interactive "P")
10791   (require 'gnus-art)
10792   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10793     (gnus-summary-save-article arg)))
10794
10795 (defun gnus-summary-save-article-file (&optional arg)
10796   "Append the current article to a file.
10797 If N is a positive number, save the N next articles.
10798 If N is a negative number, save the N previous articles.
10799 If N is nil and any articles have been marked with the process mark,
10800 save those articles instead."
10801   (interactive "P")
10802   (require 'gnus-art)
10803   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10804     (gnus-summary-save-article arg)))
10805
10806 (defun gnus-summary-write-article-file (&optional arg)
10807   "Write the current article to a file, deleting the previous file.
10808 If N is a positive number, save the N next articles.
10809 If N is a negative number, save the N previous articles.
10810 If N is nil and any articles have been marked with the process mark,
10811 save those articles instead."
10812   (interactive "P")
10813   (require 'gnus-art)
10814   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10815     (gnus-summary-save-article arg)))
10816
10817 (defun gnus-summary-save-article-body-file (&optional arg)
10818   "Append the current article body to a file.
10819 If N is a positive number, save the N next articles.
10820 If N is a negative number, save the N previous articles.
10821 If N is nil and any articles have been marked with the process mark,
10822 save those articles instead."
10823   (interactive "P")
10824   (require 'gnus-art)
10825   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10826     (gnus-summary-save-article arg)))
10827
10828 (defun gnus-summary-muttprint (&optional arg)
10829   "Print the current article using Muttprint.
10830 If N is a positive number, save the N next articles.
10831 If N is a negative number, save the N previous articles.
10832 If N is nil and any articles have been marked with the process mark,
10833 save those articles instead."
10834   (interactive "P")
10835   (require 'gnus-art)
10836   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10837     (gnus-summary-save-article arg t)))
10838
10839 (defun gnus-summary-pipe-message (program)
10840   "Pipe the current article through PROGRAM."
10841   (interactive "sProgram: ")
10842   (gnus-summary-select-article)
10843   (let ((mail-header-separator ""))
10844     (gnus-eval-in-buffer-window gnus-article-buffer
10845       (save-restriction
10846         (widen)
10847         (let ((start (window-start))
10848               buffer-read-only)
10849           (message-pipe-buffer-body program)
10850           (set-window-start (get-buffer-window (current-buffer)) start))))))
10851
10852 (defun gnus-get-split-value (methods)
10853   "Return a value based on the split METHODS."
10854   (let (split-name method result match)
10855     (when methods
10856       (save-excursion
10857         (set-buffer gnus-original-article-buffer)
10858         (save-restriction
10859           (nnheader-narrow-to-headers)
10860           (while (and methods (not split-name))
10861             (goto-char (point-min))
10862             (setq method (pop methods))
10863             (setq match (car method))
10864             (when (cond
10865                    ((stringp match)
10866                     ;; Regular expression.
10867                     (ignore-errors
10868                       (re-search-forward match nil t)))
10869                    ((gnus-functionp match)
10870                     ;; Function.
10871                     (save-restriction
10872                       (widen)
10873                       (setq result (funcall match gnus-newsgroup-name))))
10874                    ((consp match)
10875                     ;; Form.
10876                     (save-restriction
10877                       (widen)
10878                       (setq result (eval match)))))
10879               (setq split-name (cdr method))
10880               (cond ((stringp result)
10881                      (push (expand-file-name
10882                             result gnus-article-save-directory)
10883                            split-name))
10884                     ((consp result)
10885                      (setq split-name (append result split-name)))))))))
10886     (nreverse split-name)))
10887
10888 (defun gnus-valid-move-group-p (group)
10889   (and (boundp group)
10890        (symbol-name group)
10891        (symbol-value group)
10892        (gnus-get-function (gnus-find-method-for-group
10893                            (symbol-name group)) 'request-accept-article t)))
10894
10895 (defun gnus-read-move-group-name (prompt default articles prefix)
10896   "Read a group name."
10897   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10898          (minibuffer-confirm-incomplete nil) ; XEmacs
10899          (prom
10900           (format "%s %s to:"
10901                   prompt
10902                   (if (> (length articles) 1)
10903                       (format "these %d articles" (length articles))
10904                     "this article")))
10905          (to-newsgroup
10906           (cond
10907            ((null split-name)
10908             (gnus-completing-read-with-default
10909              default prom
10910              gnus-active-hashtb
10911              'gnus-valid-move-group-p
10912              nil prefix
10913              'gnus-group-history))
10914            ((= 1 (length split-name))
10915             (gnus-completing-read-with-default
10916              (car split-name) prom
10917              gnus-active-hashtb
10918              'gnus-valid-move-group-p
10919              nil nil
10920              'gnus-group-history))
10921            (t
10922             (gnus-completing-read-with-default
10923              nil prom
10924              (mapcar (lambda (el) (list el))
10925                      (nreverse split-name))
10926              nil nil nil
10927              'gnus-group-history))))
10928          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10929     (when to-newsgroup
10930       (if (or (string= to-newsgroup "")
10931               (string= to-newsgroup prefix))
10932           (setq to-newsgroup default))
10933       (unless to-newsgroup
10934         (error "No group name entered"))
10935       (or (gnus-active to-newsgroup)
10936           (gnus-activate-group to-newsgroup nil nil to-method)
10937           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10938                                      to-newsgroup))
10939               (or (and (gnus-request-create-group to-newsgroup to-method)
10940                        (gnus-activate-group
10941                         to-newsgroup nil nil to-method)
10942                        (gnus-subscribe-group to-newsgroup))
10943                   (error "Couldn't create group %s" to-newsgroup)))
10944           (error "No such group: %s" to-newsgroup)))
10945     to-newsgroup))
10946
10947 (defun gnus-summary-save-parts (type dir n &optional reverse)
10948   "Save parts matching TYPE to DIR.
10949 If REVERSE, save parts that do not match TYPE."
10950   (interactive
10951    (list (read-string "Save parts of type: "
10952                       (or (car gnus-summary-save-parts-type-history)
10953                           gnus-summary-save-parts-default-mime)
10954                       'gnus-summary-save-parts-type-history)
10955          (setq gnus-summary-save-parts-last-directory
10956                (read-file-name "Save to directory: "
10957                                gnus-summary-save-parts-last-directory
10958                                nil t))
10959          current-prefix-arg))
10960   (gnus-summary-iterate n
10961     (let ((gnus-display-mime-function nil)
10962           (gnus-inhibit-treatment t))
10963       (gnus-summary-select-article))
10964     (save-excursion
10965       (set-buffer gnus-article-buffer)
10966       (let ((handles (or gnus-article-mime-handles
10967                          (mm-dissect-buffer nil gnus-article-loose-mime)
10968                          (and gnus-article-emulate-mime
10969                               (mm-uu-dissect)))))
10970         (when handles
10971           (gnus-summary-save-parts-1 type dir handles reverse)
10972           (unless gnus-article-mime-handles ;; Don't destroy this case.
10973             (mm-destroy-parts handles)))))))
10974
10975 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10976   (if (stringp (car handle))
10977       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10978               (cdr handle))
10979     (when (if reverse
10980               (not (string-match type (mm-handle-media-type handle)))
10981             (string-match type (mm-handle-media-type handle)))
10982       (let ((file (expand-file-name
10983                    (file-name-nondirectory
10984                     (or
10985                      (mail-content-type-get
10986                       (mm-handle-disposition handle) 'filename)
10987                      (concat gnus-newsgroup-name
10988                              "." (number-to-string
10989                                   (cdr gnus-article-current)))))
10990                    dir)))
10991         (unless (file-exists-p file)
10992           (mm-save-part-to-file handle file))))))
10993
10994 ;; Summary extract commands
10995
10996 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10997   (let ((buffer-read-only nil)
10998         (article (gnus-summary-article-number))
10999         after-article b e)
11000     (unless (gnus-summary-goto-subject article)
11001       (error "No such article: %d" article))
11002     (gnus-summary-position-point)
11003     ;; If all commands are to be bunched up on one line, we collect
11004     ;; them here.
11005     (unless gnus-view-pseudos-separately
11006       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11007             files action)
11008         (while ps
11009           (setq action (cdr (assq 'action (car ps))))
11010           (setq files (list (cdr (assq 'name (car ps)))))
11011           (while (and ps (cdr ps)
11012                       (string= (or action "1")
11013                                (or (cdr (assq 'action (cadr ps))) "2")))
11014             (push (cdr (assq 'name (cadr ps))) files)
11015             (setcdr ps (cddr ps)))
11016           (when files
11017             (when (not (string-match "%s" action))
11018               (push " " files))
11019             (push " " files)
11020             (when (assq 'execute (car ps))
11021               (setcdr (assq 'execute (car ps))
11022                       (funcall (if (string-match "%s" action)
11023                                    'format 'concat)
11024                                action
11025                                (mapconcat
11026                                 (lambda (f)
11027                                   (if (equal f " ")
11028                                       f
11029                                     (gnus-quote-arg-for-sh-or-csh f)))
11030                                 files " ")))))
11031           (setq ps (cdr ps)))))
11032     (if (and gnus-view-pseudos (not not-view))
11033         (while pslist
11034           (when (assq 'execute (car pslist))
11035             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11036                                   (eq gnus-view-pseudos 'not-confirm)))
11037           (setq pslist (cdr pslist)))
11038       (save-excursion
11039         (while pslist
11040           (setq after-article (or (cdr (assq 'article (car pslist)))
11041                                   (gnus-summary-article-number)))
11042           (gnus-summary-goto-subject after-article)
11043           (forward-line 1)
11044           (setq b (point))
11045           (insert "    " (file-name-nondirectory
11046                           (cdr (assq 'name (car pslist))))
11047                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11048           (setq e (point))
11049           (forward-line -1)             ; back to `b'
11050           (gnus-add-text-properties
11051            b (1- e) (list 'gnus-number gnus-reffed-article-number
11052                           gnus-mouse-face-prop gnus-mouse-face))
11053           (gnus-data-enter
11054            after-article gnus-reffed-article-number
11055            gnus-unread-mark b (car pslist) 0 (- e b))
11056           (setq gnus-newsgroup-unreads
11057                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11058                                          gnus-reffed-article-number))
11059           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11060           (setq pslist (cdr pslist)))))))
11061
11062 (defun gnus-pseudos< (p1 p2)
11063   (let ((c1 (cdr (assq 'action p1)))
11064         (c2 (cdr (assq 'action p2))))
11065     (and c1 c2 (string< c1 c2))))
11066
11067 (defun gnus-request-pseudo-article (props)
11068   (cond ((assq 'execute props)
11069          (gnus-execute-command (cdr (assq 'execute props)))))
11070   (let ((gnus-current-article (gnus-summary-article-number)))
11071     (gnus-run-hooks 'gnus-mark-article-hook)))
11072
11073 (defun gnus-execute-command (command &optional automatic)
11074   (save-excursion
11075     (gnus-article-setup-buffer)
11076     (set-buffer gnus-article-buffer)
11077     (setq buffer-read-only nil)
11078     (let ((command (if automatic command
11079                      (read-string "Command: " (cons command 0)))))
11080       (erase-buffer)
11081       (insert "$ " command "\n\n")
11082       (if gnus-view-pseudo-asynchronously
11083           (start-process "gnus-execute" (current-buffer) shell-file-name
11084                          shell-command-switch command)
11085         (call-process shell-file-name nil t nil
11086                       shell-command-switch command)))))
11087
11088 ;; Summary kill commands.
11089
11090 (defun gnus-summary-edit-global-kill (article)
11091   "Edit the \"global\" kill file."
11092   (interactive (list (gnus-summary-article-number)))
11093   (gnus-group-edit-global-kill article))
11094
11095 (defun gnus-summary-edit-local-kill ()
11096   "Edit a local kill file applied to the current newsgroup."
11097   (interactive)
11098   (setq gnus-current-headers (gnus-summary-article-header))
11099   (gnus-group-edit-local-kill
11100    (gnus-summary-article-number) gnus-newsgroup-name))
11101
11102 ;;; Header reading.
11103
11104 (defun gnus-read-header (id &optional header)
11105   "Read the headers of article ID and enter them into the Gnus system."
11106   (let ((group gnus-newsgroup-name)
11107         (gnus-override-method
11108          (or
11109           gnus-override-method
11110           (and (gnus-news-group-p gnus-newsgroup-name)
11111                (car (gnus-refer-article-methods)))))
11112         where)
11113     ;; First we check to see whether the header in question is already
11114     ;; fetched.
11115     (if (stringp id)
11116         ;; This is a Message-ID.
11117         (setq header (or header (gnus-id-to-header id)))
11118       ;; This is an article number.
11119       (setq header (or header (gnus-summary-article-header id))))
11120     (if (and header
11121              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11122         ;; We have found the header.
11123         header
11124       ;; If this is a sparse article, we have to nix out its
11125       ;; previous entry in the thread hashtb.
11126       (when (and header
11127                  (gnus-summary-article-sparse-p (mail-header-number header)))
11128         (let* ((parent (gnus-parent-id (mail-header-references header)))
11129                (thread (and parent (gnus-id-to-thread parent))))
11130           (when thread
11131             (delq (assq header thread) thread))))
11132       ;; We have to really fetch the header to this article.
11133       (save-excursion
11134         (set-buffer nntp-server-buffer)
11135         (when (setq where (gnus-request-head id group))
11136           (nnheader-fold-continuation-lines)
11137           (goto-char (point-max))
11138           (insert ".\n")
11139           (goto-char (point-min))
11140           (insert "211 ")
11141           (princ (cond
11142                   ((numberp id) id)
11143                   ((cdr where) (cdr where))
11144                   (header (mail-header-number header))
11145                   (t gnus-reffed-article-number))
11146                  (current-buffer))
11147           (insert " Article retrieved.\n"))
11148         (if (or (not where)
11149                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11150             ()                          ; Malformed head.
11151           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11152             (when (and (stringp id)
11153                        (not (string= (gnus-group-real-name group)
11154                                      (car where))))
11155               ;; If we fetched by Message-ID and the article came
11156               ;; from a different group, we fudge some bogus article
11157               ;; numbers for this article.
11158               (mail-header-set-number header gnus-reffed-article-number))
11159             (save-excursion
11160               (set-buffer gnus-summary-buffer)
11161               (decf gnus-reffed-article-number)
11162               (gnus-remove-header (mail-header-number header))
11163               (push header gnus-newsgroup-headers)
11164               (setq gnus-current-headers header)
11165               (push (mail-header-number header) gnus-newsgroup-limit)))
11166           header)))))
11167
11168 (defun gnus-remove-header (number)
11169   "Remove header NUMBER from `gnus-newsgroup-headers'."
11170   (if (and gnus-newsgroup-headers
11171            (= number (mail-header-number (car gnus-newsgroup-headers))))
11172       (pop gnus-newsgroup-headers)
11173     (let ((headers gnus-newsgroup-headers))
11174       (while (and (cdr headers)
11175                   (not (= number (mail-header-number (cadr headers)))))
11176         (pop headers))
11177       (when (cdr headers)
11178         (setcdr headers (cddr headers))))))
11179
11180 ;;;
11181 ;;; summary highlights
11182 ;;;
11183
11184 (defun gnus-highlight-selected-summary ()
11185   "Highlight selected article in summary buffer."
11186   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11187   (when gnus-summary-selected-face
11188     (save-excursion
11189       (let* ((beg (gnus-point-at-bol))
11190              (end (gnus-point-at-eol))
11191              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11192              (from (if (get-text-property beg gnus-mouse-face-prop)
11193                        beg
11194                      (or (next-single-property-change
11195                           beg gnus-mouse-face-prop nil end)
11196                          beg)))
11197              (to
11198               (if (= from end)
11199                   (- from 2)
11200                 (or (next-single-property-change
11201                      from gnus-mouse-face-prop nil end)
11202                     end))))
11203         ;; If no mouse-face prop on line we will have to = from = end,
11204         ;; so we highlight the entire line instead.
11205         (when (= (+ to 2) from)
11206           (setq from beg)
11207           (setq to end))
11208         (if gnus-newsgroup-selected-overlay
11209             ;; Move old overlay.
11210             (gnus-move-overlay
11211              gnus-newsgroup-selected-overlay from to (current-buffer))
11212           ;; Create new overlay.
11213           (gnus-overlay-put
11214            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11215            'face gnus-summary-selected-face))))))
11216
11217 (defvar gnus-summary-highlight-line-cached nil)
11218 (defvar gnus-summary-highlight-line-trigger nil)
11219
11220 (defun gnus-summary-highlight-line-0 ()
11221   (if (and (eq gnus-summary-highlight-line-trigger 
11222                gnus-summary-highlight)
11223            gnus-summary-highlight-line-cached)
11224       gnus-summary-highlight-line-cached
11225     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11226           gnus-summary-highlight-line-cached
11227           (let* ((cond (list 'cond))
11228                  (c cond)
11229                  (list gnus-summary-highlight))
11230             (while list
11231               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11232                               nil))
11233               (setq c (cdr c)
11234                     list (cdr list)))
11235             (gnus-byte-compile (list 'lambda nil cond))))))
11236
11237 (defun gnus-summary-highlight-line ()
11238   "Highlight current line according to `gnus-summary-highlight'."
11239   (let* ((beg (gnus-point-at-bol))
11240          (article (or (gnus-summary-article-number) gnus-current-article))
11241          (score (or (cdr (assq article
11242                                gnus-newsgroup-scored))
11243                     gnus-summary-default-score 0))
11244          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11245          (inhibit-read-only t)
11246          (default gnus-summary-default-score)
11247          (default-high gnus-summary-default-high-score)
11248          (default-low gnus-summary-default-low-score)
11249          (uncached (memq article gnus-newsgroup-undownloaded))
11250          (downloaded (not uncached)))
11251     (let ((face (funcall (gnus-summary-highlight-line-0))))
11252       (unless (eq face (get-text-property beg 'face))
11253         (gnus-put-text-property-excluding-characters-with-faces
11254          beg (gnus-point-at-eol) 'face
11255          (setq face (if (boundp face) (symbol-value face) face)))
11256         (when gnus-summary-highlight-line-function
11257           (funcall gnus-summary-highlight-line-function article face))))))
11258
11259 (defun gnus-update-read-articles (group unread &optional compute)
11260   "Update the list of read articles in GROUP.
11261 UNREAD is a sorted list."
11262   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11263          (entry (gnus-gethash group gnus-newsrc-hashtb))
11264          (info (nth 2 entry))
11265          (prev 1)
11266          read)
11267     (if (or (not info) (not active))
11268         ;; There is no info on this group if it was, in fact,
11269         ;; killed.  Gnus stores no information on killed groups, so
11270         ;; there's nothing to be done.
11271         ;; One could store the information somewhere temporarily,
11272         ;; perhaps...  Hmmm...
11273         ()
11274       ;; Remove any negative articles numbers.
11275       (while (and unread (< (car unread) 0))
11276         (setq unread (cdr unread)))
11277       ;; Remove any expired article numbers
11278       (while (and unread (< (car unread) (car active)))
11279         (setq unread (cdr unread)))
11280       ;; Compute the ranges of read articles by looking at the list of
11281       ;; unread articles.
11282       (while unread
11283         (when (/= (car unread) prev)
11284           (push (if (= prev (1- (car unread))) prev
11285                   (cons prev (1- (car unread))))
11286                 read))
11287         (setq prev (1+ (car unread)))
11288         (setq unread (cdr unread)))
11289       (when (<= prev (cdr active))
11290         (push (cons prev (cdr active)) read))
11291       (setq read (if (> (length read) 1) (nreverse read) read))
11292       (if compute
11293           read
11294         (save-excursion
11295           (let (setmarkundo)
11296             ;; Propagate the read marks to the backend.
11297             (when (gnus-check-backend-function 'request-set-mark group)
11298               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11299                     (add (gnus-remove-from-range read (gnus-info-read info))))
11300                 (when (or add del)
11301                   (unless (gnus-check-group group)
11302                     (error "Can't open server for %s" group))
11303                   (gnus-request-set-mark
11304                    group (delq nil (list (if add (list add 'add '(read)))
11305                                          (if del (list del 'del '(read))))))
11306                   (setq setmarkundo
11307                         `(gnus-request-set-mark
11308                           ,group
11309                           ',(delq nil (list
11310                                        (if del (list del 'add '(read)))
11311                                        (if add (list add 'del '(read))))))))))
11312             (set-buffer gnus-group-buffer)
11313             (gnus-undo-register
11314               `(progn
11315                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11316                  (gnus-info-set-read ',info ',(gnus-info-read info))
11317                  (gnus-get-unread-articles-in-group ',info
11318                                                     (gnus-active ,group))
11319                  (gnus-group-update-group ,group t)
11320                  ,setmarkundo))))
11321         ;; Enter this list into the group info.
11322         (gnus-info-set-read info read)
11323         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11324         (gnus-get-unread-articles-in-group info (gnus-active group))
11325         t))))
11326
11327 (defun gnus-offer-save-summaries ()
11328   "Offer to save all active summary buffers."
11329   (let (buffers)
11330     ;; Go through all buffers and find all summaries.
11331     (dolist (buffer (buffer-list))
11332       (when (and (setq buffer (buffer-name buffer))
11333                  (string-match "Summary" buffer)
11334                  (save-excursion
11335                    (set-buffer buffer)
11336                    ;; We check that this is, indeed, a summary buffer.
11337                    (and (eq major-mode 'gnus-summary-mode)
11338                         ;; Also make sure this isn't bogus.
11339                         gnus-newsgroup-prepared
11340                         ;; Also make sure that this isn't a
11341                         ;; dead summary buffer.
11342                         (not gnus-dead-summary-mode))))
11343         (push buffer buffers)))
11344     ;; Go through all these summary buffers and offer to save them.
11345     (when buffers
11346       (save-excursion
11347         (map-y-or-n-p
11348          "Update summary buffer %s? "
11349          (lambda (buf)
11350            (switch-to-buffer buf)
11351            (gnus-summary-exit))
11352          buffers)))))
11353
11354
11355 ;;; @ for mime-partial
11356 ;;;
11357
11358 (defun gnus-request-partial-message ()
11359   (save-excursion
11360     (let ((number (gnus-summary-article-number))
11361           (group gnus-newsgroup-name)
11362           (mother gnus-article-buffer))
11363       (set-buffer (get-buffer-create " *Partial Article*"))
11364       (erase-buffer)
11365       (setq mime-preview-buffer mother)
11366       (gnus-request-article-this-buffer number group)
11367       (mime-parse-buffer)
11368       )))
11369
11370 (autoload 'mime-combine-message/partial-pieces-automatically
11371   "mime-partial"
11372   "Internal method to combine message/partial messages automatically.")
11373
11374 (mime-add-condition
11375  'action '((type . message)(subtype . partial)
11376            (major-mode . gnus-original-article-mode)
11377            (method . mime-combine-message/partial-pieces-automatically)
11378            (summary-buffer-exp . gnus-summary-buffer)
11379            (request-partial-message-method . gnus-request-partial-message)
11380            ))
11381
11382
11383 ;;; @ for message/rfc822
11384 ;;;
11385
11386 (defun gnus-mime-extract-message/rfc822 (entity situation)
11387   "Burst a forwarded article."
11388   (save-excursion
11389     (set-buffer gnus-summary-buffer)
11390     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11391                                    gnus-newsgroup-name 'gnus-group-history))
11392            (gnus-group-marked (list group))
11393            article info)
11394       (with-temp-buffer
11395         (mime-insert-entity-content entity)
11396         (setq article (gnus-request-accept-article group)))
11397       (when (and (consp article)
11398                  (numberp (setq article (cdr article))))
11399         (setq info (gnus-get-info group))
11400         (gnus-info-set-read info
11401                             (gnus-remove-from-range (gnus-info-read info)
11402                                                     (list article)))
11403         (when (string-equal group gnus-newsgroup-name)
11404           (forward-line 1)
11405           (let (gnus-show-threads)
11406             (gnus-summary-goto-subject article t))
11407           (gnus-summary-clear-mark-forward 1))
11408         (set-buffer gnus-group-buffer)
11409         (gnus-group-get-new-news-this-group nil t)))))
11410
11411 (mime-add-condition
11412  'action '((type . message)(subtype . rfc822)
11413            (major-mode . gnus-original-article-mode)
11414            (method . gnus-mime-extract-message/rfc822)
11415            (mode . "extract")
11416            ))
11417
11418 (mime-add-condition
11419  'action '((type . message)(subtype . news)
11420            (major-mode . gnus-original-article-mode)
11421            (method . gnus-mime-extract-message/rfc822)
11422            (mode . "extract")
11423            ))
11424
11425 (defun gnus-mime-extract-multipart (entity situation)
11426   (let ((children (mime-entity-children entity))
11427         mime-acting-situation-to-override
11428         f)
11429     (while children
11430       (mime-play-entity (car children)
11431                         (cons (assq 'mode situation)
11432                               mime-acting-situation-to-override))
11433       (setq children (cdr children)))
11434     (if (setq f (cdr (assq 'after-method
11435                            mime-acting-situation-to-override)))
11436         (eval f)
11437       )))
11438
11439 (mime-add-condition
11440  'action '((type . multipart)
11441            (method . gnus-mime-extract-multipart)
11442            (mode . "extract")
11443            )
11444  'with-default)
11445
11446
11447 ;;; @ end
11448 ;;;
11449
11450 (defun gnus-summary-inherit-default-charset ()
11451   "Import `default-mime-charset' from summary buffer.
11452 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11453 of FLIM is used."
11454   (if (buffer-live-p gnus-summary-buffer)
11455       (let (d-m-c d-m-c-u)
11456         (with-current-buffer gnus-summary-buffer
11457           (setq d-m-c (if (local-variable-p 'default-mime-charset
11458                                             gnus-summary-buffer)
11459                           default-mime-charset
11460                         t)
11461                 ;; LIMIT
11462                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11463                                               gnus-summary-buffer)
11464                             (symbol-value 'default-mime-charset-unlimited)
11465                           t)))
11466         (if (eq t d-m-c)
11467             (kill-local-variable 'default-mime-charset)
11468           (set (make-local-variable 'default-mime-charset) d-m-c))
11469         (if (eq t d-m-c-u)
11470             (kill-local-variable 'default-mime-charset-unlimited)
11471           (set (make-local-variable 'default-mime-charset-unlimited)
11472                d-m-c-u)))))
11473
11474 (defun gnus-summary-setup-default-charset ()
11475   "Setup newsgroup default charset."
11476   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11477       (progn
11478         (setq gnus-newsgroup-charset nil)
11479         (set (make-local-variable 'default-mime-charset) nil)
11480         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11481           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11482     (let ((ignored-charsets
11483            (or gnus-newsgroup-ephemeral-ignored-charsets
11484                (append
11485                 (and gnus-newsgroup-name
11486                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11487                 gnus-newsgroup-ignored-charsets)))
11488           charset)
11489       (setq gnus-newsgroup-charset
11490             (or gnus-newsgroup-ephemeral-charset
11491                 (when (and gnus-newsgroup-name
11492                            (setq charset (gnus-parameter-charset
11493                                           gnus-newsgroup-name)))
11494                   (make-local-variable 'default-mime-charset)
11495                   (setq default-mime-charset charset))
11496                 gnus-default-charset))
11497       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11498            ignored-charsets))))
11499
11500 ;;;
11501 ;;; Mime Commands
11502 ;;;
11503
11504 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11505   "Display the current article buffer fully MIME-buttonized.
11506 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11507 treated as multipart/mixed."
11508   (interactive "P")
11509   (require 'gnus-art)
11510   (let ((gnus-unbuttonized-mime-types nil)
11511         (gnus-mime-display-multipart-as-mixed show-all-parts))
11512     (gnus-summary-show-article)))
11513
11514 (defun gnus-summary-repair-multipart (article)
11515   "Add a Content-Type header to a multipart article without one."
11516   (interactive (list (gnus-summary-article-number)))
11517   (gnus-with-article article
11518     (message-narrow-to-head)
11519     (message-remove-header "Mime-Version")
11520     (goto-char (point-max))
11521     (insert "Mime-Version: 1.0\n")
11522     (widen)
11523     (when (search-forward "\n--" nil t)
11524       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11525         (message-narrow-to-head)
11526         (message-remove-header "Content-Type")
11527         (goto-char (point-max))
11528         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11529                         separator))
11530         (widen))))
11531   (let (gnus-mark-article-hook)
11532     (gnus-summary-select-article t t nil article)))
11533
11534 (defun gnus-summary-toggle-display-buttonized ()
11535   "Toggle the buttonizing of the article buffer."
11536   (interactive)
11537   (require 'gnus-art)
11538   (if (setq gnus-inhibit-mime-unbuttonizing
11539             (not gnus-inhibit-mime-unbuttonizing))
11540       (let ((gnus-unbuttonized-mime-types nil))
11541         (gnus-summary-show-article))
11542     (gnus-summary-show-article)))
11543
11544 ;;;
11545 ;;; Intelli-mouse commmands
11546 ;;;
11547
11548 (defun gnus-wheel-summary-scroll (event)
11549   (interactive "e")
11550   (let ((amount (if (memq 'shift (event-modifiers event))
11551                     (car gnus-wheel-scroll-amount)
11552                   (cdr gnus-wheel-scroll-amount)))
11553         (direction (- (* (static-if (featurep 'xemacs)
11554                              (event-button event)
11555                            (cond ((eq 'mouse-4 (event-basic-type event))
11556                                   4)
11557                                  ((eq 'mouse-5 (event-basic-type event))
11558                                   5)))
11559                          2) 9))
11560         edge)
11561     (gnus-summary-scroll-up (* amount direction))
11562     (when (gnus-eval-in-buffer-window gnus-article-buffer
11563             (save-restriction
11564               (widen)
11565               (and (if (< 0 direction)
11566                        (gnus-article-next-page 0)
11567                      (gnus-article-prev-page 0)
11568                      (bobp))
11569                    (if (setq edge (get-text-property
11570                                    (point-min) 'gnus-wheel-edge))
11571                        (setq edge (* edge direction))
11572                      (setq edge -1))
11573                    (or (plusp edge)
11574                        (let ((buffer-read-only nil)
11575                              (inhibit-read-only t))
11576                          (put-text-property (point-min) (point-max)
11577                                             'gnus-wheel-edge direction)
11578                          nil))
11579                    (or (> edge gnus-wheel-edge-resistance)
11580                        (let ((buffer-read-only nil)
11581                              (inhibit-read-only t))
11582                          (put-text-property (point-min) (point-max)
11583                                             'gnus-wheel-edge
11584                                             (* (1+ edge) direction))
11585                          nil))
11586                    (eq last-command 'gnus-wheel-summary-scroll))))
11587       (gnus-summary-next-article nil nil (minusp direction)))))
11588
11589 (defun gnus-wheel-install ()
11590   "Enable mouse wheel support on summary window."
11591   (when gnus-use-wheel
11592     (let ((keys
11593            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11594       (dolist (key keys)
11595         (define-key gnus-summary-mode-map key
11596           'gnus-wheel-summary-scroll)))))
11597
11598 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11599
11600 ;;;
11601 ;;; Traditional PGP commmands
11602 ;;;
11603
11604 (defun gnus-summary-decrypt-article (&optional force)
11605   "Decrypt the current article in traditional PGP way.
11606 This will have permanent effect only in mail groups.
11607 If FORCE is non-nil, allow editing of articles even in read-only
11608 groups."
11609   (interactive "P")
11610   (gnus-summary-select-article t)
11611   (gnus-eval-in-buffer-window gnus-article-buffer
11612     (save-excursion
11613       (save-restriction
11614         (widen)
11615         (goto-char (point-min))
11616         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11617           (error "Not a traditional PGP message!"))
11618         (let ((armor-start (match-beginning 0)))
11619           (if (and (pgg-decrypt-region armor-start (point-max))
11620                    (or force (not (gnus-group-read-only-p))))
11621               (let ((inhibit-read-only t)
11622                     buffer-read-only)
11623                 (delete-region armor-start
11624                                (progn
11625                                  (re-search-forward "^-+END PGP" nil t)
11626                                  (beginning-of-line 2)
11627                                  (point)))
11628                 (insert-buffer-substring pgg-output-buffer))))))))
11629
11630 (defun gnus-summary-verify-article ()
11631   "Verify the current article in traditional PGP way."
11632   (interactive)
11633   (save-excursion
11634     (set-buffer gnus-original-article-buffer)
11635     (goto-char (point-min))
11636     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11637       (error "Not a traditional PGP message!"))
11638     (re-search-forward "^-+END PGP" nil t)
11639     (beginning-of-line 2)
11640     (call-interactively (function pgg-verify-region))))
11641
11642 ;;;
11643 ;;; Generic summary marking commands
11644 ;;;
11645
11646 (defvar gnus-summary-marking-alist
11647   '((read gnus-del-mark "d")
11648     (unread gnus-unread-mark "u")
11649     (ticked gnus-ticked-mark "!")
11650     (dormant gnus-dormant-mark "?")
11651     (expirable gnus-expirable-mark "e"))
11652   "An alist of names/marks/keystrokes.")
11653
11654 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11655 (defvar gnus-summary-mark-map)
11656
11657 (defun gnus-summary-make-all-marking-commands ()
11658   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11659   (dolist (elem gnus-summary-marking-alist)
11660     (apply 'gnus-summary-make-marking-command elem)))
11661
11662 (defun gnus-summary-make-marking-command (name mark keystroke)
11663   (let ((map (make-sparse-keymap)))
11664     (define-key gnus-summary-generic-mark-map keystroke map)
11665     (dolist (lway `((next "next" next nil "n")
11666                     (next-unread "next unread" next t "N")
11667                     (prev "previous" prev nil "p")
11668                     (prev-unread "previous unread" prev t "P")
11669                     (nomove "" nil nil ,keystroke)))
11670       (let ((func (gnus-summary-make-marking-command-1
11671                    mark (car lway) lway name)))
11672         (setq func (eval func))
11673         (define-key map (nth 4 lway) func)))))
11674
11675 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11676   `(defun ,(intern
11677             (format "gnus-summary-put-mark-as-%s%s"
11678                     name (if (eq way 'nomove)
11679                              ""
11680                            (concat "-" (symbol-name way)))))
11681      (n)
11682      ,(format
11683        "Mark the current article as %s%s.
11684 If N, the prefix, then repeat N times.
11685 If N is negative, move in reverse order.
11686 The difference between N and the actual number of articles marked is
11687 returned."
11688        name (car (cdr lway)))
11689      (interactive "p")
11690      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11691
11692 (defun gnus-summary-generic-mark (n mark move unread)
11693   "Mark N articles with MARK."
11694   (unless (eq major-mode 'gnus-summary-mode)
11695     (error "This command can only be used in the summary buffer"))
11696   (gnus-summary-show-thread)
11697   (let ((nummove
11698          (cond
11699           ((eq move 'next) 1)
11700           ((eq move 'prev) -1)
11701           (t 0))))
11702     (if (zerop nummove)
11703         (setq n 1)
11704       (when (< n 0)
11705         (setq n (abs n)
11706               nummove (* -1 nummove))))
11707     (while (and (> n 0)
11708                 (gnus-summary-mark-article nil mark)
11709                 (zerop (gnus-summary-next-subject nummove unread t)))
11710       (setq n (1- n)))
11711     (when (/= 0 n)
11712       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11713     (gnus-summary-recenter)
11714     (gnus-summary-position-point)
11715     (gnus-set-mode-line 'summary)
11716     n))
11717
11718 (defun gnus-summary-insert-articles (articles)
11719   (when (setq articles
11720               (gnus-sorted-difference articles
11721                                       (mapcar (lambda (h)
11722                                                 (mail-header-number h))
11723                                               gnus-newsgroup-headers)))
11724     (setq gnus-newsgroup-headers
11725           (merge 'list
11726                  gnus-newsgroup-headers
11727                  (gnus-fetch-headers articles)
11728                  'gnus-article-sort-by-number))
11729     ;; Suppress duplicates?
11730     (when gnus-suppress-duplicates
11731       (gnus-dup-suppress-articles))
11732
11733     ;; We might want to build some more threads first.
11734     (when (and gnus-fetch-old-headers
11735                (eq gnus-headers-retrieved-by 'nov))
11736       (if (eq gnus-fetch-old-headers 'invisible)
11737           (gnus-build-all-threads)
11738         (gnus-build-old-threads)))
11739     ;; Let the Gnus agent mark articles as read.
11740     (when gnus-agent
11741       (gnus-agent-get-undownloaded-list))
11742     ;; Remove list identifiers from subject
11743     (when gnus-list-identifiers
11744       (gnus-summary-remove-list-identifiers))
11745     ;; First and last article in this newsgroup.
11746     (when gnus-newsgroup-headers
11747       (setq gnus-newsgroup-begin
11748             (mail-header-number (car gnus-newsgroup-headers))
11749             gnus-newsgroup-end
11750             (mail-header-number
11751              (gnus-last-element gnus-newsgroup-headers))))
11752     (when gnus-use-scoring
11753       (gnus-possibly-score-headers))))
11754
11755 (defun gnus-summary-insert-old-articles (&optional all)
11756   "Insert all old articles in this group.
11757 If ALL is non-nil, already read articles become readable.
11758 If ALL is a number, fetch this number of articles."
11759   (interactive "P")
11760   (prog1
11761       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11762             older len)
11763         (setq older
11764               ;; Some nntp servers lie about their active range.  When
11765               ;; this happens, the active range can be in the millions.
11766               ;; Use a compressed range to avoid creating a huge list.
11767               (gnus-range-difference (list gnus-newsgroup-active) old))
11768         (setq len (gnus-range-length older))
11769         (cond
11770          ((null older) nil)
11771          ((numberp all)
11772           (if (< all len)
11773               (let ((older-range (nreverse older)))
11774                 (setq older nil)
11775
11776                 (while (> all 0)
11777                   (let* ((r (pop older-range))
11778                          (min (if (numberp r) r (car r)))
11779                          (max (if (numberp r) r (cdr r))))
11780                     (while (and (<= min max)
11781                                 (> all 0))
11782                       (push max older)
11783                       (setq all (1- all)
11784                             max (1- max))))))
11785             (setq older (gnus-uncompress-range older))))
11786          (all
11787           (setq older (gnus-uncompress-range older)))
11788          (t
11789           (when (and (numberp gnus-large-newsgroup)
11790                    (> len gnus-large-newsgroup))
11791               (let* ((cursor-in-echo-area nil)
11792                      (initial (gnus-parameter-large-newsgroup-initial
11793                                gnus-newsgroup-name))
11794                      (input
11795                       (read-string
11796                        (format
11797                         "How many articles from %s (%s %d): "
11798                         (gnus-limit-string
11799                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11800                         (if initial "max" "default")
11801                         len)
11802                        (if initial
11803                            (cons (number-to-string initial)
11804                                  0)))))
11805                 (unless (string-match "^[ \t]*$" input)
11806                   (setq all (string-to-number input))
11807                   (if (< all len)
11808                       (let ((older-range (nreverse older)))
11809                         (setq older nil)
11810
11811                         (while (> all 0)
11812                           (let* ((r (pop older-range))
11813                                  (min (if (numberp r) r (car r)))
11814                                  (max (if (numberp r) r (cdr r))))
11815                             (while (and (<= min max)
11816                                         (> all 0))
11817                               (push max older)
11818                               (setq all (1- all)
11819                                     max (1- max))))))))))
11820           (setq older (gnus-uncompress-range older))))
11821         (if (not older)
11822             (message "No old news.")
11823           (gnus-summary-insert-articles older)
11824           (gnus-summary-limit (gnus-sorted-nunion old older))))
11825     (gnus-summary-position-point)))
11826
11827 (defun gnus-summary-insert-new-articles ()
11828   "Insert all new articles in this group."
11829   (interactive)
11830   (prog1
11831       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11832             (old-active gnus-newsgroup-active)
11833             (nnmail-fetched-sources (list t))
11834             i new)
11835         (setq gnus-newsgroup-active
11836               (gnus-activate-group gnus-newsgroup-name 'scan))
11837         (setq i (cdr gnus-newsgroup-active))
11838         (while (> i (cdr old-active))
11839           (push i new)
11840           (decf i))
11841         (if (not new)
11842             (message "No gnus is bad news.")
11843           (gnus-summary-insert-articles new)
11844           (setq gnus-newsgroup-unreads
11845                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11846           (gnus-summary-limit (gnus-sorted-nunion old new))))
11847     (gnus-summary-position-point)))
11848
11849 (gnus-summary-make-all-marking-commands)
11850
11851 (gnus-ems-redefine)
11852
11853 (provide 'gnus-sum)
11854
11855 (run-hooks 'gnus-sum-load-hook)
11856
11857 ;;; gnus-sum.el ends here