Synch to No Gnus 200401120649.
[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, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
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 '(radio (sexp :format "Non-nil\n"
266                       :match (lambda (widget value)
267                                (not (or (consp value) (functionp value))))
268                       :value t)
269                 (const nil)
270                 (sexp :tag "Predicate specifier" :size 0)))
271
272 (defcustom gnus-thread-hide-killed t
273   "*If non-nil, hide killed threads automatically."
274   :group 'gnus-thread
275   :type 'boolean)
276
277 (defcustom gnus-thread-ignore-subject t
278   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
279 If nil, articles that have different subjects from their parents will
280 start separate threads."
281   :group 'gnus-thread
282   :type 'boolean)
283
284 (defcustom gnus-thread-operation-ignore-subject t
285   "*If non-nil, subjects will be ignored when doing thread commands.
286 This affects commands like `gnus-summary-kill-thread' and
287 `gnus-summary-lower-thread'.
288
289 If this variable is nil, articles in the same thread with different
290 subjects will not be included in the operation in question.  If this
291 variable is `fuzzy', only articles that have subjects that are fuzzily
292 equal will be included."
293   :group 'gnus-thread
294   :type '(choice (const :tag "off" nil)
295                  (const fuzzy)
296                  (sexp :tag "on" t)))
297
298 (defcustom gnus-thread-indent-level 4
299   "*Number that says how much each sub-thread should be indented."
300   :group 'gnus-thread
301   :type 'integer)
302
303 (defcustom gnus-auto-extend-newsgroup t
304   "*If non-nil, extend newsgroup forward and backward when requested."
305   :group 'gnus-summary-choose
306   :type 'boolean)
307
308 (defcustom gnus-auto-select-first t
309   "*If non-nil, select the article under point.
310 Which article this is is controlled by the `gnus-auto-select-subject'
311 variable.
312
313 If you want to prevent automatic selection of articles in some
314 newsgroups, set the variable to nil in `gnus-select-group-hook'."
315   :group 'gnus-group-select
316   :type '(choice (const :tag "none" nil)
317                  (sexp :menu-tag "first" t)))
318
319 (defcustom gnus-auto-select-subject 'unread
320   "*Says what subject to place under point when entering a group.
321
322 This variable can either be the symbols `first' (place point on the
323 first subject), `unread' (place point on the subject line of the first
324 unread article), `best' (place point on the subject line of the
325 higest-scored article), `unseen' (place point on the subject line of
326 the first unseen article), 'unseen-or-unread' (place point on the subject
327 line of the first unseen article or, if all article have been seen, on the
328 subject line of the first unread article), or a function to be called to
329 place point on some subject line."
330   :group 'gnus-group-select
331   :type '(choice (const best)
332                  (const unread)
333                  (const first)
334                  (const unseen)
335                  (const unseen-or-unread)))
336
337 (defcustom gnus-dont-select-after-jump-to-other-group nil
338   "If non-nil, don't select the first unread article after entering the
339 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
340 it is depend on the value of `gnus-auto-select-first' whether to select
341 or not."
342   :group 'gnus-group-select
343   :type 'boolean)
344
345 (defcustom gnus-auto-select-next t
346   "*If non-nil, offer to go to the next group from the end of the previous.
347 If the value is t and the next newsgroup is empty, Gnus will exit
348 summary mode and go back to group mode.  If the value is neither nil
349 nor t, Gnus will select the following unread newsgroup.  In
350 particular, if the value is the symbol `quietly', the next unread
351 newsgroup will be selected without any confirmation, and if it is
352 `almost-quietly', the next group will be selected without any
353 confirmation if you are located on the last article in the group.
354 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
355 will go to the next group without confirmation."
356   :group 'gnus-summary-maneuvering
357   :type '(choice (const :tag "off" nil)
358                  (const quietly)
359                  (const almost-quietly)
360                  (const slightly-quietly)
361                  (sexp :menu-tag "on" t)))
362
363 (defcustom gnus-auto-select-same nil
364   "*If non-nil, select the next article with the same subject.
365 If there are no more articles with the same subject, go to
366 the first unread article."
367   :group 'gnus-summary-maneuvering
368   :type 'boolean)
369
370 (defcustom gnus-auto-goto-ignores 'unfetched
371   "*Says how to handle unfetched articles when maneuvering.
372
373 This variable can either be the symbols nil (maneuver to any
374 article), `undownloaded' (maneuvering while unplugged ignores articles
375 that have not been fetched), `always-undownloaded' (maneuvering always
376 ignores articles that have not been fetched), `unfetched' (maneuvering
377 ignores articles whose headers have not been fetched).
378
379 NOTE: The list of unfetched articles will always be nil when plugged
380 and, when unplugged, a subset of the undownloaded article list."
381   :group 'gnus-summary-maneuvering
382   :type '(choice (const :tag "None" nil)
383                  (const :tag "Undownloaded when unplugged" undownloaded)
384                  (const :tag "Undownloaded" always-undownloaded)
385                  (const :tag "Unfetched" unfetched)))
386
387 (defcustom gnus-summary-check-current nil
388   "*If non-nil, consider the current article when moving.
389 The \"unread\" movement commands will stay on the same line if the
390 current article is unread."
391   :group 'gnus-summary-maneuvering
392   :type 'boolean)
393
394 (defcustom gnus-auto-center-summary t
395   "*If non-nil, always center the current summary buffer.
396 In particular, if `vertical' do only vertical recentering.  If non-nil
397 and non-`vertical', do both horizontal and vertical recentering."
398   :group 'gnus-summary-maneuvering
399   :type '(choice (const :tag "none" nil)
400                  (const vertical)
401                  (integer :tag "height")
402                  (sexp :menu-tag "both" t)))
403
404 (defvar gnus-auto-center-group t
405   "*If non-nil, always center the group buffer.")
406
407 (defcustom gnus-show-all-headers nil
408   "*If non-nil, don't hide any headers."
409   :group 'gnus-article-hiding
410   :group 'gnus-article-headers
411   :type 'boolean)
412
413 (defcustom gnus-summary-ignore-duplicates nil
414   "*If non-nil, ignore articles with identical Message-ID headers."
415   :group 'gnus-summary
416   :type 'boolean)
417
418 (defcustom gnus-single-article-buffer t
419   "*If non-nil, display all articles in the same buffer.
420 If nil, each group will get its own article buffer."
421   :group 'gnus-article-various
422   :type 'boolean)
423
424 (defcustom gnus-break-pages t
425   "*If non-nil, do page breaking on articles.
426 The page delimiter is specified by the `gnus-page-delimiter'
427 variable."
428   :group 'gnus-article-various
429   :type 'boolean)
430
431 (defcustom gnus-show-mime t
432   "*If non-nil, do mime processing of articles.
433 The articles will simply be fed to the function given by
434 `gnus-article-display-method-for-mime'."
435   :group 'gnus-article-mime
436   :type 'boolean)
437
438 (defcustom gnus-move-split-methods nil
439   "*Variable used to suggest where articles are to be moved to.
440 It uses the same syntax as the `gnus-split-methods' variable.
441 However, whereas `gnus-split-methods' specifies file names as targets,
442 this variable specifies group names."
443   :group 'gnus-summary-mail
444   :type '(repeat (choice (list :value (fun) function)
445                          (cons :value ("" "") regexp (repeat string))
446                          (sexp :value nil))))
447
448 (defcustom gnus-unread-mark ?\ ;;;Whitespace
449   "*Mark used for unread articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-ticked-mark ?!
454   "*Mark used for ticked articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-dormant-mark ??
459   "*Mark used for dormant articles."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-del-mark ?r
464   "*Mark used for del'd articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-read-mark ?R
469   "*Mark used for read articles."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-expirable-mark ?E
474   "*Mark used for expirable articles."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-killed-mark ?K
479   "*Mark used for killed articles."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-spam-mark ?$
484   "*Mark used for spam articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-recent-mark ?N
519   "*Mark used for articles that are recent."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-cached-mark ?*
524   "*Mark used for articles that are in the cache."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-saved-mark ?S
529   "*Mark used for articles that have been saved."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-unseen-mark ?.
534   "*Mark used for articles that haven't been seen."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-no-mark ?\ ;;;Whitespace
539   "*Mark used for articles that have no other secondary mark."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-ancient-mark ?O
544   "*Mark used for ancient articles."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-sparse-mark ?Q
549   "*Mark used for sparsely reffed articles."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-canceled-mark ?G
554   "*Mark used for canceled articles."
555   :group 'gnus-summary-marks
556   :type 'character)
557
558 (defcustom gnus-duplicate-mark ?M
559   "*Mark used for duplicate articles."
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-undownloaded-mark ?-
564   "*Mark used for articles that weren't downloaded."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
699   "*List of functions used for sorting articles in the summary buffer.
700
701 Each function takes two articles and returns non-nil if the first
702 article should be sorted before the other.  If you use more than one
703 function, the primary sort function should be the last.  You should
704 probably always include `gnus-article-sort-by-number' in the list of
705 sorting functions -- preferably first.  Also note that sorting by date
706 is often much slower than sorting by number, and the sorting order is
707 very similar.  (Sorting by date means sorting by the time the message
708 was sent, sorting by number means sorting by arrival time.)
709
710 Ready-made functions include `gnus-article-sort-by-number',
711 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
712 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
713 and `gnus-article-sort-by-score'.
714
715 When threading is turned on, the variable `gnus-thread-sort-functions'
716 controls how articles are sorted."
717   :group 'gnus-summary-sort
718   :type '(repeat (choice (function-item gnus-article-sort-by-number)
719                          (function-item gnus-article-sort-by-author)
720                          (function-item gnus-article-sort-by-subject)
721                          (function-item gnus-article-sort-by-date)
722                          (function-item gnus-article-sort-by-score)
723                          (function-item gnus-article-sort-by-random)
724                          (function :tag "other"))))
725
726 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
727   "*List of functions used for sorting threads in the summary buffer.
728 By default, threads are sorted by article number.
729
730 Each function takes two threads and returns non-nil if the first
731 thread should be sorted before the other.  If you use more than one
732 function, the primary sort function should be the last.  You should
733 probably always include `gnus-thread-sort-by-number' in the list of
734 sorting functions -- preferably first.  Also note that sorting by date
735 is often much slower than sorting by number, and the sorting order is
736 very similar.  (Sorting by date means sorting by the time the message
737 was sent, sorting by number means sorting by arrival time.)
738
739 Ready-made functions include `gnus-thread-sort-by-number',
740 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
741 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
742 `gnus-thread-sort-by-most-recent-number',
743 `gnus-thread-sort-by-most-recent-date',
744 `gnus-thread-sort-by-random', and
745 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
746
747 When threading is turned off, the variable
748 `gnus-article-sort-functions' controls how articles are sorted."
749   :group 'gnus-summary-sort
750   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
751                          (function-item gnus-thread-sort-by-author)
752                          (function-item gnus-thread-sort-by-subject)
753                          (function-item gnus-thread-sort-by-date)
754                          (function-item gnus-thread-sort-by-score)
755                          (function-item gnus-thread-sort-by-total-score)
756                          (function-item gnus-thread-sort-by-random)
757                          (function :tag "other"))))
758
759 (defcustom gnus-thread-score-function '+
760   "*Function used for calculating the total score of a thread.
761
762 The function is called with the scores of the article and each
763 subthread and should then return the score of the thread.
764
765 Some functions you can use are `+', `max', or `min'."
766   :group 'gnus-summary-sort
767   :type 'function)
768
769 (defcustom gnus-summary-expunge-below nil
770   "All articles that have a score less than this variable will be expunged.
771 This variable is local to the summary buffers."
772   :group 'gnus-score-default
773   :type '(choice (const :tag "off" nil)
774                  integer))
775
776 (defcustom gnus-thread-expunge-below nil
777   "All threads that have a total score less than this variable will be expunged.
778 See `gnus-thread-score-function' for en explanation of what a
779 \"thread score\" is.
780
781 This variable is local to the summary buffers."
782   :group 'gnus-threading
783   :group 'gnus-score-default
784   :type '(choice (const :tag "off" nil)
785                  integer))
786
787 (defcustom gnus-summary-mode-hook nil
788   "*A hook for Gnus summary mode.
789 This hook is run before any variables are set in the summary buffer."
790   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
791   :group 'gnus-summary-various
792   :type 'hook)
793
794 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
795 (when (featurep 'xemacs)
796   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
797   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
798   (add-hook 'gnus-summary-mode-hook
799             'gnus-xmas-switch-horizontal-scrollbar-off))
800
801 (defcustom gnus-summary-menu-hook nil
802   "*Hook run after the creation of the summary mode menu."
803   :group 'gnus-summary-visual
804   :type 'hook)
805
806 (defcustom gnus-summary-exit-hook nil
807   "*A hook called on exit from the summary buffer.
808 It will be called with point in the group buffer."
809   :group 'gnus-summary-exit
810   :type 'hook)
811
812 (defcustom gnus-summary-prepare-hook nil
813   "*A hook called after the summary buffer has been generated.
814 If you want to modify the summary buffer, you can use this hook."
815   :group 'gnus-summary-various
816   :type 'hook)
817
818 (defcustom gnus-summary-prepared-hook nil
819   "*A hook called as the last thing after the summary buffer has been generated."
820   :group 'gnus-summary-various
821   :type 'hook)
822
823 (defcustom gnus-summary-generate-hook nil
824   "*A hook run just before generating the summary buffer.
825 This hook is commonly used to customize threading variables and the
826 like."
827   :group 'gnus-summary-various
828   :type 'hook)
829
830 (defcustom gnus-select-group-hook nil
831   "*A hook called when a newsgroup is selected.
832
833 If you'd like to simplify subjects like the
834 `gnus-summary-next-same-subject' command does, you can use the
835 following hook:
836
837  (add-hook gnus-select-group-hook
838            (lambda ()
839              (mapcar (lambda (header)
840                        (mail-header-set-subject
841                         header
842                         (gnus-simplify-subject
843                          (mail-header-subject header) 're-only)))
844                      gnus-newsgroup-headers)))"
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-select-article-hook nil
849   "*A hook called when an article is selected."
850   :group 'gnus-summary-choose
851   :options '(gnus-agent-fetch-selected-article)
852   :type 'hook)
853
854 (defcustom gnus-visual-mark-article-hook
855   (list 'gnus-highlight-selected-summary)
856   "*Hook run after selecting an article in the summary buffer.
857 It is meant to be used for highlighting the article in some way.  It
858 is not run if `gnus-visual' is nil."
859   :group 'gnus-summary-visual
860   :type 'hook)
861
862 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
863   "*A hook called before parsing the headers."
864   :group 'gnus-various
865   :type 'hook)
866
867 (defcustom gnus-exit-group-hook nil
868   "*A hook called when exiting summary mode.
869 This hook is not called from the non-updating exit commands like `Q'."
870   :group 'gnus-various
871   :type 'hook)
872
873 (defcustom gnus-summary-update-hook
874   (list 'gnus-summary-highlight-line)
875   "*A hook called when a summary line is changed.
876 The hook will not be called if `gnus-visual' is nil.
877
878 The default function `gnus-summary-highlight-line' will
879 highlight the line according to the `gnus-summary-highlight'
880 variable."
881   :group 'gnus-summary-visual
882   :type 'hook)
883
884 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
885   "*A hook called when an article is selected for the first time.
886 The hook is intended to mark an article as read (or unread)
887 automatically when it is selected."
888   :group 'gnus-summary-choose
889   :type 'hook)
890
891 (defcustom gnus-group-no-more-groups-hook nil
892   "*A hook run when returning to group mode having no more (unread) groups."
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-ps-print-hook nil
897   "*A hook run before ps-printing something from Gnus."
898   :group 'gnus-summary
899   :type 'hook)
900
901 (defcustom gnus-summary-article-move-hook nil
902   "*A hook called after an article is moved, copied, respooled, or crossposted."
903   :group 'gnus-summary
904   :type 'hook)
905
906 (defcustom gnus-summary-article-delete-hook nil
907   "*A hook called after an article is deleted."
908   :group 'gnus-summary
909   :type 'hook)
910
911 (defcustom gnus-summary-article-expire-hook nil
912   "*A hook called after an article is expired."
913   :group 'gnus-summary
914   :type 'hook)
915
916 (defcustom gnus-summary-display-arrow
917   (and (fboundp 'display-graphic-p)
918        (display-graphic-p))
919   "*If non-nil, display an arrow highlighting the current article."
920   :version "21.1"
921   :group 'gnus-summary
922   :type 'boolean)
923
924 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
925   "Face used for highlighting the current article in the summary buffer."
926   :group 'gnus-summary-visual
927   :type 'face)
928
929 (defvar gnus-tmp-downloaded nil)
930
931 (defcustom gnus-summary-highlight
932   '(((eq mark gnus-canceled-mark)
933      . gnus-summary-cancelled-face)
934     ((and uncached (> score default-high))
935      . gnus-summary-high-undownloaded-face)
936     ((and uncached (< score default-low))
937      . gnus-summary-low-undownloaded-face)
938     (uncached
939      . gnus-summary-normal-undownloaded-face)
940     ((and (> score default-high)
941           (or (eq mark gnus-dormant-mark)
942               (eq mark gnus-ticked-mark)))
943      . gnus-summary-high-ticked-face)
944     ((and (< score default-low)
945           (or (eq mark gnus-dormant-mark)
946               (eq mark gnus-ticked-mark)))
947      . gnus-summary-low-ticked-face)
948     ((or (eq mark gnus-dormant-mark)
949          (eq mark gnus-ticked-mark))
950      . gnus-summary-normal-ticked-face)
951     ((and (> score default-high) (eq mark gnus-ancient-mark))
952      . gnus-summary-high-ancient-face)
953     ((and (< score default-low) (eq mark gnus-ancient-mark))
954      . gnus-summary-low-ancient-face)
955     ((eq mark gnus-ancient-mark)
956      . gnus-summary-normal-ancient-face)
957     ((and (> score default-high) (eq mark gnus-unread-mark))
958      . gnus-summary-high-unread-face)
959     ((and (< score default-low) (eq mark gnus-unread-mark))
960      . gnus-summary-low-unread-face)
961     ((eq mark gnus-unread-mark)
962      . gnus-summary-normal-unread-face)
963     ((> score default-high)
964      . gnus-summary-high-read-face)
965     ((< score default-low)
966      . gnus-summary-low-read-face)
967     (t
968      . gnus-summary-normal-read-face))
969   "*Controls the highlighting of summary buffer lines.
970
971 A list of (FORM . FACE) pairs.  When deciding how a a particular
972 summary line should be displayed, each form is evaluated.  The content
973 of the face field after the first true form is used.  You can change
974 how those summary lines are displayed, by editing the face field.
975
976 You can use the following variables in the FORM field.
977
978 score:        The article's score
979 default:      The default article score.
980 default-high: The default score for high scored articles.
981 default-low:  The default score for low scored articles.
982 below:        The score below which articles are automatically marked as read.
983 mark:         The article's mark.
984 uncached:     Non-nil if the article is uncached."
985   :group 'gnus-summary-visual
986   :type '(repeat (cons (sexp :tag "Form" nil)
987                        face)))
988
989 (defcustom gnus-alter-header-function nil
990   "Function called to allow alteration of article header structures.
991 The function is called with one parameter, the article header vector,
992 which it may alter in any way."
993   :type '(choice (const :tag "None" nil)
994                  function)
995   :group 'gnus-summary)
996
997 (defvar gnus-decode-encoded-word-function
998   (mime-find-field-decoder 'From 'nov)
999   "Variable that says which function should be used to decode a string with encoded words.")
1000
1001 (defcustom gnus-extra-headers '(To Newsgroups)
1002   "*Extra headers to parse."
1003   :version "21.1"
1004   :group 'gnus-summary
1005   :type '(repeat symbol))
1006
1007 (defcustom gnus-ignored-from-addresses
1008   (and user-mail-address (regexp-quote user-mail-address))
1009   "*Regexp of From headers that may be suppressed in favor of To headers."
1010   :version "21.1"
1011   :group 'gnus-summary
1012   :type 'regexp)
1013
1014 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1015   "List of charsets that should be ignored.
1016 When these charsets are used in the \"charset\" parameter, the
1017 default charset will be used instead."
1018   :version "21.1"
1019   :type '(repeat symbol)
1020   :group 'gnus-charset)
1021
1022 (gnus-define-group-parameter
1023  ignored-charsets
1024  :type list
1025  :function-document
1026  "Return the ignored charsets of GROUP."
1027  :variable gnus-group-ignored-charsets-alist
1028  :variable-default
1029  '(("alt\\.chinese\\.text" iso-8859-1))
1030  :variable-document
1031  "Alist of regexps (to match group names) and charsets that should be ignored.
1032 When these charsets are used in the \"charset\" parameter, the
1033 default charset will be used instead."
1034  :variable-group gnus-charset
1035  :variable-type '(repeat (cons (regexp :tag "Group")
1036                                (repeat symbol)))
1037  :parameter-type '(choice :tag "Ignored charsets"
1038                           :value nil
1039                           (repeat (symbol)))
1040  :parameter-document       "\
1041 List of charsets that should be ignored.
1042
1043 When these charsets are used in the \"charset\" parameter, the
1044 default charset will be used instead.")
1045
1046 (defcustom gnus-group-highlight-words-alist nil
1047   "Alist of group regexps and highlight regexps.
1048 This variable uses the same syntax as `gnus-emphasis-alist'."
1049   :version "21.1"
1050   :type '(repeat (cons (regexp :tag "Group")
1051                        (repeat (list (regexp :tag "Highlight regexp")
1052                                      (number :tag "Group for entire word" 0)
1053                                      (number :tag "Group for displayed part" 0)
1054                                      (symbol :tag "Face"
1055                                              gnus-emphasis-highlight-words)))))
1056   :group 'gnus-summary-visual)
1057
1058 (defcustom gnus-use-wheel nil
1059   "Use Intelli-mouse on summary movement"
1060   :type 'boolean
1061   :group 'gnus-summary-maneuvering)
1062
1063 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1064   "Amount to scroll messages by spinning the mouse wheel.
1065 This is actually a cons cell, where the first item is the amount to scroll
1066 on a normal wheel event, and the second is the amount to scroll when the
1067 wheel is moved with the shift key depressed."
1068   :type '(cons (integer :tag "Shift") integer)
1069   :group 'gnus-summary-maneuvering)
1070
1071 (defcustom gnus-wheel-edge-resistance 2
1072   "How hard it should be to change the current article
1073 by moving the mouse over the edge of the article window."
1074   :type 'integer
1075   :group 'gnus-summary-maneuvering)
1076
1077 (defcustom gnus-summary-show-article-charset-alist
1078   nil
1079   "Alist of number and charset.
1080 The article will be shown with the charset corresponding to the
1081 numbered argument.
1082 For example: ((1 . cn-gb-2312) (2 . big5))."
1083   :version "21.1"
1084   :type '(repeat (cons (number :tag "Argument" 1)
1085                        (symbol :tag "Charset")))
1086   :group 'gnus-charset)
1087
1088 (defcustom gnus-preserve-marks t
1089   "Whether marks are preserved when moving, copying and respooling messages."
1090   :version "21.1"
1091   :type 'boolean
1092   :group 'gnus-summary-marks)
1093
1094 (defcustom gnus-alter-articles-to-read-function nil
1095   "Function to be called to alter the list of articles to be selected."
1096   :type '(choice (const nil) function)
1097   :group 'gnus-summary)
1098
1099 (defcustom gnus-orphan-score nil
1100   "*All orphans get this score added.  Set in the score file."
1101   :group 'gnus-score-default
1102   :type '(choice (const nil)
1103                  integer))
1104
1105 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1106   "*A regexp to match MIME parts when saving multiple parts of a
1107 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1108 This regexp will be used by default when prompting the user for which
1109 type of files to save."
1110   :group 'gnus-summary
1111   :type 'regexp)
1112
1113 (defcustom gnus-read-all-available-headers nil
1114   "Whether Gnus should parse all headers made available to it.
1115 This is mostly relevant for slow back ends where the user may
1116 wish to widen the summary buffer to include all headers
1117 that were fetched.  Say, for nnultimate groups."
1118   :group 'gnus-summary
1119   :type '(choice boolean regexp))
1120
1121 (defcustom gnus-summary-muttprint-program "muttprint"
1122   "Command (and optional arguments) used to run Muttprint."
1123   :version "21.3"
1124   :group 'gnus-summary
1125   :type 'string)
1126
1127 (defcustom gnus-article-loose-mime nil
1128   "If non-nil, don't require MIME-Version header.
1129 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1130 supply the MIME-Version header or deliberately strip it From the mail.
1131 Set it to non-nil, Gnus will treat some articles as MIME even if
1132 the MIME-Version header is missed."
1133   :version "21.3"
1134   :type 'boolean
1135   :group 'gnus-article-mime)
1136
1137 (defcustom gnus-article-emulate-mime t
1138   "If non-nil, use MIME emulation for uuencode and the like.
1139 This means that Gnus will search message bodies for text that look
1140 like uuencoded bits, yEncoded bits, and so on, and present that using
1141 the normal Gnus MIME machinery."
1142   :type 'boolean
1143   :group 'gnus-article-mime)
1144
1145 ;;; Internal variables
1146
1147 (defvar gnus-summary-display-cache nil)
1148 (defvar gnus-article-mime-handles nil)
1149 (defvar gnus-article-decoded-p nil)
1150 (defvar gnus-article-charset nil)
1151 (defvar gnus-article-ignored-charsets nil)
1152 (defvar gnus-scores-exclude-files nil)
1153 (defvar gnus-page-broken nil)
1154
1155 (defvar gnus-original-article nil)
1156 (defvar gnus-article-internal-prepare-hook nil)
1157 (defvar gnus-newsgroup-process-stack nil)
1158
1159 (defvar gnus-thread-indent-array nil)
1160 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1161 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1162   "Function called to sort the articles within a thread after it has been gathered together.")
1163
1164 (defvar gnus-summary-save-parts-type-history nil)
1165 (defvar gnus-summary-save-parts-last-directory nil)
1166
1167 ;; Avoid highlighting in kill files.
1168 (defvar gnus-summary-inhibit-highlight nil)
1169 (defvar gnus-newsgroup-selected-overlay nil)
1170 (defvar gnus-inhibit-limiting nil)
1171 (defvar gnus-newsgroup-adaptive-score-file nil)
1172 (defvar gnus-current-score-file nil)
1173 (defvar gnus-current-move-group nil)
1174 (defvar gnus-current-copy-group nil)
1175 (defvar gnus-current-crosspost-group nil)
1176 (defvar gnus-newsgroup-display nil)
1177
1178 (defvar gnus-newsgroup-dependencies nil)
1179 (defvar gnus-newsgroup-adaptive nil)
1180 (defvar gnus-summary-display-article-function nil)
1181 (defvar gnus-summary-highlight-line-function nil
1182   "Function called after highlighting a summary line.")
1183
1184 (defvar gnus-summary-line-format-alist
1185   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1186     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1187     (?s gnus-tmp-subject-or-nil ?s)
1188     (?n gnus-tmp-name ?s)
1189     (?A (std11-address-string
1190          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1191     (?a (or (std11-full-name-string
1192              (car (mime-entity-read-field gnus-tmp-header 'From)))
1193             gnus-tmp-from) ?s)
1194     (?F gnus-tmp-from ?s)
1195     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1196     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1197     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1198     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1199     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1200     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1201     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1202     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1203     (?L gnus-tmp-lines ?s)
1204     (?O gnus-tmp-downloaded ?c)
1205     (?I gnus-tmp-indentation ?s)
1206     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1207     (?R gnus-tmp-replied ?c)
1208     (?\[ gnus-tmp-opening-bracket ?c)
1209     (?\] gnus-tmp-closing-bracket ?c)
1210     (?\> (make-string gnus-tmp-level ? ) ?s)
1211     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1212     (?i gnus-tmp-score ?d)
1213     (?z gnus-tmp-score-char ?c)
1214     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1215     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1216     (?U gnus-tmp-unread ?c)
1217     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1218         ?s)
1219     (?t (gnus-summary-number-of-articles-in-thread
1220          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1221         ?d)
1222     (?e (gnus-summary-number-of-articles-in-thread
1223          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1224         ?c)
1225     (?u gnus-tmp-user-defined ?s)
1226     (?P (gnus-pick-line-number) ?d)
1227     (?B gnus-tmp-thread-tree-header-string ?s)
1228     (user-date (gnus-user-date
1229                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1230   "An alist of format specifications that can appear in summary lines.
1231 These are paired with what variables they correspond with, along with
1232 the type of the variable (string, integer, character, etc).")
1233
1234 (defvar gnus-summary-dummy-line-format-alist
1235   `((?S gnus-tmp-subject ?s)
1236     (?N gnus-tmp-number ?d)
1237     (?u gnus-tmp-user-defined ?s)))
1238
1239 (defvar gnus-summary-mode-line-format-alist
1240   `((?G gnus-tmp-group-name ?s)
1241     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1242     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1243     (?A gnus-tmp-article-number ?d)
1244     (?Z gnus-tmp-unread-and-unselected ?s)
1245     (?V gnus-version ?s)
1246     (?U gnus-tmp-unread-and-unticked ?d)
1247     (?S gnus-tmp-subject ?s)
1248     (?e gnus-tmp-unselected ?d)
1249     (?u gnus-tmp-user-defined ?s)
1250     (?d (length gnus-newsgroup-dormant) ?d)
1251     (?t (length gnus-newsgroup-marked) ?d)
1252     (?h (length gnus-newsgroup-spam-marked) ?d)
1253     (?r (length gnus-newsgroup-reads) ?d)
1254     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1255     (?E gnus-newsgroup-expunged-tally ?d)
1256     (?s (gnus-current-score-file-nondirectory) ?s)))
1257
1258 (defvar gnus-last-search-regexp nil
1259   "Default regexp for article search command.")
1260
1261 (defvar gnus-summary-search-article-matched-data nil
1262   "Last matched data of article search command.  It is the local variable
1263 in `gnus-article-buffer' which consists of the list of start position,
1264 end position and text.")
1265
1266 (defvar gnus-last-shell-command nil
1267   "Default shell command on article.")
1268
1269 (defvar gnus-newsgroup-agentized nil
1270   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1271 (defvar gnus-newsgroup-begin nil)
1272 (defvar gnus-newsgroup-end nil)
1273 (defvar gnus-newsgroup-last-rmail nil)
1274 (defvar gnus-newsgroup-last-mail nil)
1275 (defvar gnus-newsgroup-last-folder nil)
1276 (defvar gnus-newsgroup-last-file nil)
1277 (defvar gnus-newsgroup-auto-expire nil)
1278 (defvar gnus-newsgroup-active nil)
1279
1280 (defvar gnus-newsgroup-data nil)
1281 (defvar gnus-newsgroup-data-reverse nil)
1282 (defvar gnus-newsgroup-limit nil)
1283 (defvar gnus-newsgroup-limits nil)
1284 (defvar gnus-summary-use-undownloaded-faces nil)
1285
1286 (defvar gnus-newsgroup-unreads nil
1287   "Sorted list of unread articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-unselected nil
1290   "Sorted list of unselected unread articles in the current newsgroup.")
1291
1292 (defvar gnus-newsgroup-reads nil
1293   "Alist of read articles and article marks in the current newsgroup.")
1294
1295 (defvar gnus-newsgroup-expunged-tally nil)
1296
1297 (defvar gnus-newsgroup-marked nil
1298   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1299
1300 (defvar gnus-newsgroup-spam-marked nil
1301   "List of ranges of articles that have been marked as spam.")
1302
1303 (defvar gnus-newsgroup-killed nil
1304   "List of ranges of articles that have been through the scoring process.")
1305
1306 (defvar gnus-newsgroup-cached nil
1307   "Sorted list of articles that come from the article cache.")
1308
1309 (defvar gnus-newsgroup-saved nil
1310   "List of articles that have been saved.")
1311
1312 (defvar gnus-newsgroup-kill-headers nil)
1313
1314 (defvar gnus-newsgroup-replied nil
1315   "List of articles that have been replied to in the current newsgroup.")
1316
1317 (defvar gnus-newsgroup-forwarded nil
1318   "List of articles that have been forwarded in the current newsgroup.")
1319
1320 (defvar gnus-newsgroup-recent nil
1321   "List of articles that have are recent in the current newsgroup.")
1322
1323 (defvar gnus-newsgroup-expirable nil
1324   "Sorted list of articles in the current newsgroup that can be expired.")
1325
1326 (defvar gnus-newsgroup-processable nil
1327   "List of articles in the current newsgroup that can be processed.")
1328
1329 (defvar gnus-newsgroup-downloadable nil
1330   "Sorted list of articles in the current newsgroup that can be processed.")
1331
1332 (defvar gnus-newsgroup-unfetched nil
1333   "Sorted list of articles in the current newsgroup whose headers have
1334 not been fetched into the agent.
1335
1336 This list will always be a subset of gnus-newsgroup-undownloaded.")
1337
1338 (defvar gnus-newsgroup-undownloaded nil
1339   "List of articles in the current newsgroup that haven't been downloaded.")
1340
1341 (defvar gnus-newsgroup-unsendable nil
1342   "List of articles in the current newsgroup that won't be sent.")
1343
1344 (defvar gnus-newsgroup-bookmarks nil
1345   "List of articles in the current newsgroup that have bookmarks.")
1346
1347 (defvar gnus-newsgroup-dormant nil
1348   "Sorted list of dormant articles in the current newsgroup.")
1349
1350 (defvar gnus-newsgroup-unseen nil
1351   "List of unseen articles in the current newsgroup.")
1352
1353 (defvar gnus-newsgroup-seen nil
1354   "Range of seen articles in the current newsgroup.")
1355
1356 (defvar gnus-newsgroup-articles nil
1357   "List of articles in the current newsgroup.")
1358
1359 (defvar gnus-newsgroup-scored nil
1360   "List of scored articles in the current newsgroup.")
1361
1362 (defvar gnus-newsgroup-incorporated nil
1363   "List of incorporated articles in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-headers nil
1366   "List of article headers in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-threads nil)
1369
1370 (defvar gnus-newsgroup-prepared nil
1371   "Whether the current group has been prepared properly.")
1372
1373 (defvar gnus-newsgroup-ancient nil
1374   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-sparse nil)
1377
1378 (defvar gnus-current-article nil)
1379 (defvar gnus-article-current nil)
1380 (defvar gnus-current-headers nil)
1381 (defvar gnus-have-all-headers nil)
1382 (defvar gnus-last-article nil)
1383 (defvar gnus-newsgroup-history nil)
1384 (defvar gnus-newsgroup-charset nil)
1385 (defvar gnus-newsgroup-ephemeral-charset nil)
1386 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1387
1388 (defvar gnus-article-before-search nil)
1389
1390 (defvar gnus-summary-local-variables
1391   '(gnus-newsgroup-name
1392     gnus-newsgroup-begin gnus-newsgroup-end
1393     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1394     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1395     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1396     gnus-newsgroup-unselected gnus-newsgroup-marked
1397     gnus-newsgroup-spam-marked
1398     gnus-newsgroup-reads gnus-newsgroup-saved
1399     gnus-newsgroup-replied gnus-newsgroup-forwarded
1400     gnus-newsgroup-recent
1401     gnus-newsgroup-expirable
1402     gnus-newsgroup-processable gnus-newsgroup-killed
1403     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1404     gnus-newsgroup-unfetched
1405     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1406     gnus-newsgroup-seen gnus-newsgroup-articles
1407     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1408     gnus-newsgroup-headers gnus-newsgroup-threads
1409     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1410     gnus-current-article gnus-current-headers gnus-have-all-headers
1411     gnus-last-article gnus-article-internal-prepare-hook
1412     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1413     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1414     gnus-thread-expunge-below
1415     gnus-score-alist gnus-current-score-file
1416     (gnus-summary-expunge-below . global)
1417     (gnus-summary-mark-below . global)
1418     (gnus-orphan-score . global)
1419     gnus-newsgroup-active gnus-scores-exclude-files
1420     gnus-newsgroup-history gnus-newsgroup-ancient
1421     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1422     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1423     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1424     (gnus-newsgroup-expunged-tally . 0)
1425     gnus-cache-removable-articles gnus-newsgroup-cached
1426     gnus-newsgroup-data gnus-newsgroup-data-reverse
1427     gnus-newsgroup-limit gnus-newsgroup-limits
1428     gnus-newsgroup-charset gnus-newsgroup-display
1429     gnus-summary-use-undownloaded-faces
1430     gnus-newsgroup-incorporated)
1431   "Variables that are buffer-local to the summary buffers.")
1432
1433 (defvar gnus-newsgroup-variables nil
1434   "A list of variables that have separate values in different newsgroups.
1435 A list of newsgroup (summary buffer) local variables, or cons of
1436 variables and their default values (when the default values are not
1437 nil), that should be made global while the summary buffer is active.
1438 These variables can be used to set variables in the group parameters
1439 while still allowing them to affect operations done in other
1440 buffers. For example:
1441
1442 \(setq gnus-newsgroup-variables
1443      '(message-use-followup-to
1444        (gnus-visible-headers .
1445          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1446 ")
1447
1448 ;; Byte-compiler warning.
1449 (eval-when-compile
1450   ;; Bind features so that require will believe that gnus-sum has
1451   ;; already been loaded (avoids infinite recursion)
1452   (let ((features (cons 'gnus-sum features)))
1453     ;; Several of the declarations in gnus-sum are needed to load the
1454     ;; following files. Right now, these definitions have been
1455     ;; compiled but not defined (evaluated).  We could either do a
1456     ;; eval-and-compile about all of the declarations or evaluate the
1457     ;; source file.
1458     (if (boundp 'gnus-newsgroup-variables)
1459         nil
1460       (load "gnus-sum.el" t t t))
1461     (require 'gnus)
1462     (require 'gnus-agent)
1463     (require 'gnus-art)))
1464
1465 ;; Subject simplification.
1466
1467 (defun gnus-simplify-whitespace (str)
1468   "Remove excessive whitespace from STR."
1469   ;; Multiple spaces.
1470   (while (string-match "[ \t][ \t]+" str)
1471     (setq str (concat (substring str 0 (match-beginning 0))
1472                         " "
1473                         (substring str (match-end 0)))))
1474   ;; Leading spaces.
1475   (when (string-match "^[ \t]+" str)
1476     (setq str (substring str (match-end 0))))
1477   ;; Trailing spaces.
1478   (when (string-match "[ \t]+$" str)
1479     (setq str (substring str 0 (match-beginning 0))))
1480   str)
1481
1482 (defun gnus-simplify-all-whitespace (str)
1483   "Remove all whitespace from STR."
1484   (while (string-match "[ \t\n]+" str)
1485     (setq str (replace-match "" nil nil str)))
1486   str)
1487
1488 (defsubst gnus-simplify-subject-re (subject)
1489   "Remove \"Re:\" from subject lines."
1490   (if (string-match message-subject-re-regexp subject)
1491       (substring subject (match-end 0))
1492     subject))
1493
1494 (defun gnus-simplify-subject (subject &optional re-only)
1495   "Remove `Re:' and words in parentheses.
1496 If RE-ONLY is non-nil, strip leading `Re:'s only."
1497   (let ((case-fold-search t))           ;Ignore case.
1498     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1499     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1500       (setq subject (substring subject (match-end 0))))
1501     ;; Remove uninteresting prefixes.
1502     (when (and (not re-only)
1503                gnus-simplify-ignored-prefixes
1504                (string-match gnus-simplify-ignored-prefixes subject))
1505       (setq subject (substring subject (match-end 0))))
1506     ;; Remove words in parentheses from end.
1507     (unless re-only
1508       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1509         (setq subject (substring subject 0 (match-beginning 0)))))
1510     ;; Return subject string.
1511     subject))
1512
1513 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1514 ;; all whitespace.
1515 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1516   (goto-char (point-min))
1517   (while (re-search-forward regexp nil t)
1518     (replace-match (or newtext ""))))
1519
1520 (defun gnus-simplify-buffer-fuzzy ()
1521   "Simplify string in the buffer fuzzily.
1522 The string in the accessible portion of the current buffer is simplified.
1523 It is assumed to be a single-line subject.
1524 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1525 matter is removed.  Additional things can be deleted by setting
1526 `gnus-simplify-subject-fuzzy-regexp'."
1527   (let ((case-fold-search t)
1528         (modified-tick))
1529     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1530
1531     (while (not (eq modified-tick (buffer-modified-tick)))
1532       (setq modified-tick (buffer-modified-tick))
1533       (cond
1534        ((listp gnus-simplify-subject-fuzzy-regexp)
1535         (mapcar 'gnus-simplify-buffer-fuzzy-step
1536                 gnus-simplify-subject-fuzzy-regexp))
1537        (gnus-simplify-subject-fuzzy-regexp
1538         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1539       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1540       (gnus-simplify-buffer-fuzzy-step
1541        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1542       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1543
1544     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1545     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1546     (gnus-simplify-buffer-fuzzy-step " $")
1547     (gnus-simplify-buffer-fuzzy-step "^ +")))
1548
1549 (defun gnus-simplify-subject-fuzzy (subject)
1550   "Simplify a subject string fuzzily.
1551 See `gnus-simplify-buffer-fuzzy' for details."
1552   (save-excursion
1553     (gnus-set-work-buffer)
1554     (let ((case-fold-search t))
1555       ;; Remove uninteresting prefixes.
1556       (when (and gnus-simplify-ignored-prefixes
1557                  (string-match gnus-simplify-ignored-prefixes subject))
1558         (setq subject (substring subject (match-end 0))))
1559       (insert subject)
1560       (inline (gnus-simplify-buffer-fuzzy))
1561       (buffer-string))))
1562
1563 (defsubst gnus-simplify-subject-fully (subject)
1564   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1565   (cond
1566    (gnus-simplify-subject-functions
1567     (gnus-map-function gnus-simplify-subject-functions subject))
1568    ((null gnus-summary-gather-subject-limit)
1569     (gnus-simplify-subject-re subject))
1570    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1571     (gnus-simplify-subject-fuzzy subject))
1572    ((numberp gnus-summary-gather-subject-limit)
1573     (gnus-limit-string (gnus-simplify-subject-re subject)
1574                        gnus-summary-gather-subject-limit))
1575    (t
1576     subject)))
1577
1578 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1579   "Check whether two subjects are equal.
1580 If optional argument SIMPLE-FIRST is t, first argument is already
1581 simplified."
1582   (cond
1583    ((null simple-first)
1584     (equal (gnus-simplify-subject-fully s1)
1585            (gnus-simplify-subject-fully s2)))
1586    (t
1587     (equal s1
1588            (gnus-simplify-subject-fully s2)))))
1589
1590 (defun gnus-summary-bubble-group ()
1591   "Increase the score of the current group.
1592 This is a handy function to add to `gnus-summary-exit-hook' to
1593 increase the score of each group you read."
1594   (gnus-group-add-score gnus-newsgroup-name))
1595
1596 \f
1597 ;;;
1598 ;;; Gnus summary mode
1599 ;;;
1600
1601 (put 'gnus-summary-mode 'mode-class 'special)
1602
1603 (defvar gnus-article-commands-menu)
1604
1605 ;; Non-orthogonal keys
1606
1607 (gnus-define-keys gnus-summary-mode-map
1608   " " gnus-summary-next-page
1609   "\177" gnus-summary-prev-page
1610   [delete] gnus-summary-prev-page
1611   [backspace] gnus-summary-prev-page
1612   "\r" gnus-summary-scroll-up
1613   "\M-\r" gnus-summary-scroll-down
1614   "n" gnus-summary-next-unread-article
1615   "p" gnus-summary-prev-unread-article
1616   "N" gnus-summary-next-article
1617   "P" gnus-summary-prev-article
1618   "\M-\C-n" gnus-summary-next-same-subject
1619   "\M-\C-p" gnus-summary-prev-same-subject
1620   "\M-n" gnus-summary-next-unread-subject
1621   "\M-p" gnus-summary-prev-unread-subject
1622   "." gnus-summary-first-unread-article
1623   "," gnus-summary-best-unread-article
1624   "\M-s" gnus-summary-search-article-forward
1625   "\M-r" gnus-summary-search-article-backward
1626   "<" gnus-summary-beginning-of-article
1627   ">" gnus-summary-end-of-article
1628   "j" gnus-summary-goto-article
1629   "^" gnus-summary-refer-parent-article
1630   "\M-^" gnus-summary-refer-article
1631   "u" gnus-summary-tick-article-forward
1632   "!" gnus-summary-tick-article-forward
1633   "U" gnus-summary-tick-article-backward
1634   "d" gnus-summary-mark-as-read-forward
1635   "D" gnus-summary-mark-as-read-backward
1636   "E" gnus-summary-mark-as-expirable
1637   "\M-u" gnus-summary-clear-mark-forward
1638   "\M-U" gnus-summary-clear-mark-backward
1639   "k" gnus-summary-kill-same-subject-and-select
1640   "\C-k" gnus-summary-kill-same-subject
1641   "\M-\C-k" gnus-summary-kill-thread
1642   "\M-\C-l" gnus-summary-lower-thread
1643   "e" gnus-summary-edit-article
1644   "#" gnus-summary-mark-as-processable
1645   "\M-#" gnus-summary-unmark-as-processable
1646   "\M-\C-t" gnus-summary-toggle-threads
1647   "\M-\C-s" gnus-summary-show-thread
1648   "\M-\C-h" gnus-summary-hide-thread
1649   "\M-\C-f" gnus-summary-next-thread
1650   "\M-\C-b" gnus-summary-prev-thread
1651   [(meta down)] gnus-summary-next-thread
1652   [(meta up)] gnus-summary-prev-thread
1653   "\M-\C-u" gnus-summary-up-thread
1654   "\M-\C-d" gnus-summary-down-thread
1655   "&" gnus-summary-execute-command
1656   "c" gnus-summary-catchup-and-exit
1657   "\C-w" gnus-summary-mark-region-as-read
1658   "\C-t" gnus-summary-toggle-truncation
1659   "?" gnus-summary-mark-as-dormant
1660   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1661   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1662   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1663   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1664   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1665   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1666   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1667   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1668   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1669   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1670   "=" gnus-summary-expand-window
1671   "\C-x\C-s" gnus-summary-reselect-current-group
1672   "\M-g" gnus-summary-rescan-group
1673   "w" gnus-summary-stop-page-breaking
1674   "\C-c\C-r" gnus-summary-caesar-message
1675   "\M-t" gnus-summary-toggle-mime
1676   "f" gnus-summary-followup
1677   "F" gnus-summary-followup-with-original
1678   "C" gnus-summary-cancel-article
1679   "r" gnus-summary-reply
1680   "R" gnus-summary-reply-with-original
1681   "\C-c\C-f" gnus-summary-mail-forward
1682   "o" gnus-summary-save-article
1683   "\C-o" gnus-summary-save-article-mail
1684   "|" gnus-summary-pipe-output
1685   "\M-k" gnus-summary-edit-local-kill
1686   "\M-K" gnus-summary-edit-global-kill
1687   ;; "V" gnus-version
1688   "\C-c\C-d" gnus-summary-describe-group
1689   "q" gnus-summary-exit
1690   "Q" gnus-summary-exit-no-update
1691   "\C-c\C-i" gnus-info-find-node
1692   gnus-mouse-2 gnus-mouse-pick-article
1693   "m" gnus-summary-mail-other-window
1694   "a" gnus-summary-post-news
1695   "i" gnus-summary-news-other-window
1696   "x" gnus-summary-limit-to-unread
1697   "s" gnus-summary-isearch-article
1698   "t" gnus-summary-toggle-header
1699   "g" gnus-summary-show-article
1700   "l" gnus-summary-goto-last-article
1701   "v" gnus-summary-preview-mime-message
1702   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1703   "\C-d" gnus-summary-enter-digest-group
1704   "\M-\C-d" gnus-summary-read-document
1705   "\M-\C-e" gnus-summary-edit-parameters
1706   "\M-\C-a" gnus-summary-customize-parameters
1707   "\C-c\C-b" gnus-bug
1708   "\C-c\C-n" gnus-namazu-search
1709   "*" gnus-cache-enter-article
1710   "\M-*" gnus-cache-remove-article
1711   "\M-&" gnus-summary-universal-argument
1712   "\C-l" gnus-recenter
1713   "I" gnus-summary-increase-score
1714   "L" gnus-summary-lower-score
1715   "\M-i" gnus-symbolic-argument
1716   "h" gnus-summary-select-article-buffer
1717
1718   "V" gnus-summary-score-map
1719   "X" gnus-uu-extract-map
1720   "S" gnus-summary-send-map)
1721
1722   ;; Sort of orthogonal keymap
1723 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1724   "t" gnus-summary-tick-article-forward
1725   "!" gnus-summary-tick-article-forward
1726   "d" gnus-summary-mark-as-read-forward
1727   "r" gnus-summary-mark-as-read-forward
1728   "c" gnus-summary-clear-mark-forward
1729   " " gnus-summary-clear-mark-forward
1730   "e" gnus-summary-mark-as-expirable
1731   "x" gnus-summary-mark-as-expirable
1732   "?" gnus-summary-mark-as-dormant
1733   "b" gnus-summary-set-bookmark
1734   "B" gnus-summary-remove-bookmark
1735   "#" gnus-summary-mark-as-processable
1736   "\M-#" gnus-summary-unmark-as-processable
1737   "S" gnus-summary-limit-include-expunged
1738   "C" gnus-summary-catchup
1739   "H" gnus-summary-catchup-to-here
1740   "h" gnus-summary-catchup-from-here
1741   "\C-c" gnus-summary-catchup-all
1742   "k" gnus-summary-kill-same-subject-and-select
1743   "K" gnus-summary-kill-same-subject
1744   "P" gnus-uu-mark-map)
1745
1746 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1747   "c" gnus-summary-clear-above
1748   "u" gnus-summary-tick-above
1749   "m" gnus-summary-mark-above
1750   "k" gnus-summary-kill-below)
1751
1752 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1753   "/" gnus-summary-limit-to-subject
1754   "n" gnus-summary-limit-to-articles
1755   "w" gnus-summary-pop-limit
1756   "s" gnus-summary-limit-to-subject
1757   "a" gnus-summary-limit-to-author
1758   "u" gnus-summary-limit-to-unread
1759   "m" gnus-summary-limit-to-marks
1760   "M" gnus-summary-limit-exclude-marks
1761   "v" gnus-summary-limit-to-score
1762   "*" gnus-summary-limit-include-cached
1763   "D" gnus-summary-limit-include-dormant
1764   "T" gnus-summary-limit-include-thread
1765   "d" gnus-summary-limit-exclude-dormant
1766   "t" gnus-summary-limit-to-age
1767   "." gnus-summary-limit-to-unseen
1768   "x" gnus-summary-limit-to-extra
1769   "p" gnus-summary-limit-to-display-predicate
1770   "E" gnus-summary-limit-include-expunged
1771   "c" gnus-summary-limit-exclude-childless-dormant
1772   "C" gnus-summary-limit-mark-excluded-as-read
1773   "o" gnus-summary-insert-old-articles
1774   "N" gnus-summary-insert-new-articles
1775   "r" gnus-summary-limit-to-replied)
1776
1777 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1778   "n" gnus-summary-next-unread-article
1779   "p" gnus-summary-prev-unread-article
1780   "N" gnus-summary-next-article
1781   "P" gnus-summary-prev-article
1782   "\C-n" gnus-summary-next-same-subject
1783   "\C-p" gnus-summary-prev-same-subject
1784   "\M-n" gnus-summary-next-unread-subject
1785   "\M-p" gnus-summary-prev-unread-subject
1786   "f" gnus-summary-first-unread-article
1787   "b" gnus-summary-best-unread-article
1788   "j" gnus-summary-goto-article
1789   "g" gnus-summary-goto-subject
1790   "l" gnus-summary-goto-last-article
1791   "o" gnus-summary-pop-article)
1792
1793 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1794   "k" gnus-summary-kill-thread
1795   "l" gnus-summary-lower-thread
1796   "i" gnus-summary-raise-thread
1797   "T" gnus-summary-toggle-threads
1798   "t" gnus-summary-rethread-current
1799   "^" gnus-summary-reparent-thread
1800   "s" gnus-summary-show-thread
1801   "S" gnus-summary-show-all-threads
1802   "h" gnus-summary-hide-thread
1803   "H" gnus-summary-hide-all-threads
1804   "n" gnus-summary-next-thread
1805   "p" gnus-summary-prev-thread
1806   "u" gnus-summary-up-thread
1807   "o" gnus-summary-top-thread
1808   "d" gnus-summary-down-thread
1809   "#" gnus-uu-mark-thread
1810   "\M-#" gnus-uu-unmark-thread)
1811
1812 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1813   "g" gnus-summary-prepare
1814   "c" gnus-summary-insert-cached-articles
1815   "d" gnus-summary-insert-dormant-articles)
1816
1817 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1818   "c" gnus-summary-catchup-and-exit
1819   "C" gnus-summary-catchup-all-and-exit
1820   "E" gnus-summary-exit-no-update
1821   "J" gnus-summary-jump-to-other-group
1822   "Q" gnus-summary-exit
1823   "Z" gnus-summary-exit
1824   "n" gnus-summary-catchup-and-goto-next-group
1825   "R" gnus-summary-reselect-current-group
1826   "G" gnus-summary-rescan-group
1827   "N" gnus-summary-next-group
1828   "s" gnus-summary-save-newsrc
1829   "P" gnus-summary-prev-group)
1830
1831 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1832   " " gnus-summary-next-page
1833   "n" gnus-summary-next-page
1834   "\177" gnus-summary-prev-page
1835   [delete] gnus-summary-prev-page
1836   "p" gnus-summary-prev-page
1837   "\r" gnus-summary-scroll-up
1838   "\M-\r" gnus-summary-scroll-down
1839   "<" gnus-summary-beginning-of-article
1840   ">" gnus-summary-end-of-article
1841   "b" gnus-summary-beginning-of-article
1842   "e" gnus-summary-end-of-article
1843   "^" gnus-summary-refer-parent-article
1844   "r" gnus-summary-refer-parent-article
1845   "D" gnus-summary-enter-digest-group
1846   "R" gnus-summary-refer-references
1847   "T" gnus-summary-refer-thread
1848   "g" gnus-summary-show-article
1849   "s" gnus-summary-isearch-article
1850   "P" gnus-summary-print-article
1851   "M" gnus-mailing-list-insinuate
1852   "t" gnus-article-babel)
1853
1854 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1855   "b" gnus-article-add-buttons
1856   "B" gnus-article-add-buttons-to-head
1857   "o" gnus-article-treat-overstrike
1858   "e" gnus-article-emphasize
1859   "w" gnus-article-fill-cited-article
1860   "Q" gnus-article-fill-long-lines
1861   "C" gnus-article-capitalize-sentences
1862   "c" gnus-article-remove-cr
1863   "Z" gnus-article-decode-HZ
1864   "A" gnus-article-treat-ansi-sequences
1865   "h" gnus-article-wash-html
1866   "u" gnus-article-unsplit-urls
1867   "f" gnus-article-display-x-face
1868   "l" gnus-summary-stop-page-breaking
1869   "r" gnus-summary-caesar-message
1870   "m" gnus-summary-morse-message
1871   "t" gnus-summary-toggle-header
1872   "g" gnus-treat-smiley
1873   "v" gnus-summary-verbose-headers
1874   "m" gnus-summary-toggle-mime
1875   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1876   "p" gnus-article-verify-x-pgp-sig
1877   "d" gnus-article-treat-dumbquotes)
1878
1879 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1880   ;; mnemonic: deuglif*Y*
1881   "u" gnus-article-outlook-unwrap-lines
1882   "a" gnus-article-outlook-repair-attribution
1883   "c" gnus-article-outlook-rearrange-citation
1884   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1885
1886 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1887   "a" gnus-article-hide
1888   "h" gnus-article-hide-headers
1889   "b" gnus-article-hide-boring-headers
1890   "s" gnus-article-hide-signature
1891   "c" gnus-article-hide-citation
1892   "C" gnus-article-hide-citation-in-followups
1893   "l" gnus-article-hide-list-identifiers
1894   "B" gnus-article-strip-banner
1895   "P" gnus-article-hide-pem
1896   "\C-c" gnus-article-hide-citation-maybe)
1897
1898 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1899   "a" gnus-article-highlight
1900   "h" gnus-article-highlight-headers
1901   "c" gnus-article-highlight-citation
1902   "s" gnus-article-highlight-signature)
1903
1904 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1905   "f" gnus-article-treat-fold-headers
1906   "u" gnus-article-treat-unfold-headers
1907   "n" gnus-article-treat-fold-newsgroups)
1908
1909 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1910   "x" gnus-article-display-x-face
1911   "d" gnus-article-display-face
1912   "s" gnus-treat-smiley
1913   "D" gnus-article-remove-images
1914   "f" gnus-treat-from-picon
1915   "m" gnus-treat-mail-picon
1916   "n" gnus-treat-newsgroups-picon)
1917
1918 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1919   "z" gnus-article-date-ut
1920   "u" gnus-article-date-ut
1921   "l" gnus-article-date-local
1922   "p" gnus-article-date-english
1923   "e" gnus-article-date-lapsed
1924   "o" gnus-article-date-original
1925   "i" gnus-article-date-iso8601
1926   "s" gnus-article-date-user)
1927
1928 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1929   "t" gnus-article-remove-trailing-blank-lines
1930   "l" gnus-article-strip-leading-blank-lines
1931   "m" gnus-article-strip-multiple-blank-lines
1932   "a" gnus-article-strip-blank-lines
1933   "A" gnus-article-strip-all-blank-lines
1934   "s" gnus-article-strip-leading-space
1935   "e" gnus-article-strip-trailing-space
1936   "w" gnus-article-remove-leading-whitespace)
1937
1938 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1939   "v" gnus-version
1940   "f" gnus-summary-fetch-faq
1941   "d" gnus-summary-describe-group
1942   "h" gnus-summary-describe-briefly
1943   "i" gnus-info-find-node
1944   "c" gnus-group-fetch-charter
1945   "C" gnus-group-fetch-control)
1946
1947 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1948   "e" gnus-summary-expire-articles
1949   "\M-\C-e" gnus-summary-expire-articles-now
1950   "\177" gnus-summary-delete-article
1951   [delete] gnus-summary-delete-article
1952   [backspace] gnus-summary-delete-article
1953   "m" gnus-summary-move-article
1954   "r" gnus-summary-respool-article
1955   "w" gnus-summary-edit-article
1956   "c" gnus-summary-copy-article
1957   "B" gnus-summary-crosspost-article
1958   "q" gnus-summary-respool-query
1959   "t" gnus-summary-respool-trace
1960   "i" gnus-summary-import-article
1961   "I" gnus-summary-create-article
1962   "p" gnus-summary-article-posted-p)
1963
1964 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1965   "o" gnus-summary-save-article
1966   "m" gnus-summary-save-article-mail
1967   "F" gnus-summary-write-article-file
1968   "r" gnus-summary-save-article-rmail
1969   "f" gnus-summary-save-article-file
1970   "b" gnus-summary-save-article-body-file
1971   "h" gnus-summary-save-article-folder
1972   "v" gnus-summary-save-article-vm
1973   "p" gnus-summary-pipe-output
1974   "P" gnus-summary-muttprint
1975   "s" gnus-soup-add-article)
1976
1977 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1978   "b" gnus-summary-display-buttonized
1979   "m" gnus-summary-repair-multipart
1980   "v" gnus-article-view-part
1981   "o" gnus-article-save-part
1982   "c" gnus-article-copy-part
1983   "C" gnus-article-view-part-as-charset
1984   "e" gnus-article-view-part-externally
1985   "E" gnus-article-encrypt-body
1986   "i" gnus-article-inline-part
1987   "|" gnus-article-pipe-part)
1988
1989 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1990   "p" gnus-summary-mark-as-processable
1991   "u" gnus-summary-unmark-as-processable
1992   "U" gnus-summary-unmark-all-processable
1993   "v" gnus-uu-mark-over
1994   "s" gnus-uu-mark-series
1995   "r" gnus-uu-mark-region
1996   "g" gnus-uu-unmark-region
1997   "R" gnus-uu-mark-by-regexp
1998   "G" gnus-uu-unmark-by-regexp
1999   "t" gnus-uu-mark-thread
2000   "T" gnus-uu-unmark-thread
2001   "a" gnus-uu-mark-all
2002   "b" gnus-uu-mark-buffer
2003   "S" gnus-uu-mark-sparse
2004   "k" gnus-summary-kill-process-mark
2005   "y" gnus-summary-yank-process-mark
2006   "w" gnus-summary-save-process-mark
2007   "i" gnus-uu-invert-processable)
2008
2009 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2010   ;;"x" gnus-uu-extract-any
2011   "m" gnus-summary-save-parts
2012   "u" gnus-uu-decode-uu
2013   "U" gnus-uu-decode-uu-and-save
2014   "s" gnus-uu-decode-unshar
2015   "S" gnus-uu-decode-unshar-and-save
2016   "o" gnus-uu-decode-save
2017   "O" gnus-uu-decode-save
2018   "b" gnus-uu-decode-binhex
2019   "B" gnus-uu-decode-binhex
2020   "p" gnus-uu-decode-postscript
2021   "P" gnus-uu-decode-postscript-and-save)
2022
2023 (gnus-define-keys
2024     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2025   "u" gnus-uu-decode-uu-view
2026   "U" gnus-uu-decode-uu-and-save-view
2027   "s" gnus-uu-decode-unshar-view
2028   "S" gnus-uu-decode-unshar-and-save-view
2029   "o" gnus-uu-decode-save-view
2030   "O" gnus-uu-decode-save-view
2031   "b" gnus-uu-decode-binhex-view
2032   "B" gnus-uu-decode-binhex-view
2033   "p" gnus-uu-decode-postscript-view
2034   "P" gnus-uu-decode-postscript-and-save-view)
2035
2036 (defvar gnus-article-post-menu nil)
2037
2038 (defconst gnus-summary-menu-maxlen 20)
2039
2040 (defun gnus-summary-menu-split (menu)
2041   ;; If we have lots of elements, divide them into groups of 20
2042   ;; and make a pane (or submenu) for each one.
2043   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2044       (let ((menu menu) sublists next
2045             (i 1))
2046         (while menu
2047           ;; Pull off the next gnus-summary-menu-maxlen elements
2048           ;; and make them the next element of sublist.
2049           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2050           (if next
2051               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2052                       nil))
2053           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2054                                              (aref (car (last menu)) 0)) menu)
2055                                sublists))
2056           (setq i (1+ i))
2057           (setq menu next))
2058         (nreverse sublists))
2059     ;; Few elements--put them all in one pane.
2060     menu))
2061
2062 (defun gnus-summary-make-menu-bar ()
2063   (gnus-turn-off-edit-menu 'summary)
2064
2065   (unless (boundp 'gnus-summary-misc-menu)
2066
2067     (easy-menu-define
2068      gnus-summary-kill-menu gnus-summary-mode-map ""
2069      (cons
2070       "Score"
2071       (nconc
2072        (list
2073         ["Customize" gnus-score-customize t])
2074        (gnus-make-score-map 'increase)
2075        (gnus-make-score-map 'lower)
2076        '(("Mark"
2077           ["Kill below" gnus-summary-kill-below t]
2078           ["Mark above" gnus-summary-mark-above t]
2079           ["Tick above" gnus-summary-tick-above t]
2080           ["Clear above" gnus-summary-clear-above t])
2081          ["Current score" gnus-summary-current-score t]
2082          ["Set score" gnus-summary-set-score t]
2083          ["Switch current score file..." gnus-score-change-score-file t]
2084          ["Set mark below..." gnus-score-set-mark-below t]
2085          ["Set expunge below..." gnus-score-set-expunge-below t]
2086          ["Edit current score file" gnus-score-edit-current-scores t]
2087          ["Edit score file" gnus-score-edit-file t]
2088          ["Trace score" gnus-score-find-trace t]
2089          ["Find words" gnus-score-find-favourite-words t]
2090          ["Rescore buffer" gnus-summary-rescore t]
2091          ["Increase score..." gnus-summary-increase-score t]
2092          ["Lower score..." gnus-summary-lower-score t]))))
2093
2094     ;; Define both the Article menu in the summary buffer and the
2095     ;; equivalent Commands menu in the article buffer here for
2096     ;; consistency.
2097     (let ((innards
2098            `(("Hide"
2099               ["All" gnus-article-hide t]
2100               ["Headers" gnus-article-hide-headers t]
2101               ["Signature" gnus-article-hide-signature t]
2102               ["Citation" gnus-article-hide-citation t]
2103               ["List identifiers" gnus-article-hide-list-identifiers t]
2104               ["Banner" gnus-article-strip-banner t]
2105               ["Boring headers" gnus-article-hide-boring-headers t])
2106              ("Highlight"
2107               ["All" gnus-article-highlight t]
2108               ["Headers" gnus-article-highlight-headers t]
2109               ["Signature" gnus-article-highlight-signature t]
2110               ["Citation" gnus-article-highlight-citation t])
2111              ("Date"
2112               ["Local" gnus-article-date-local t]
2113               ["ISO8601" gnus-article-date-iso8601 t]
2114               ["UT" gnus-article-date-ut t]
2115               ["Original" gnus-article-date-original t]
2116               ["Lapsed" gnus-article-date-lapsed t]
2117               ["User-defined" gnus-article-date-user t])
2118              ("Display"
2119               ["Remove images" gnus-article-remove-images t]
2120               ["Toggle smiley" gnus-treat-smiley t]
2121               ["Show X-Face" gnus-article-display-x-face t]
2122               ["Show picons in From" gnus-treat-from-picon t]
2123               ["Show picons in mail headers" gnus-treat-mail-picon t]
2124               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2125               ("View as different encoding"
2126                ,@(gnus-summary-menu-split
2127                   (mapcar
2128                    (lambda (cs)
2129                      ;; Since easymenu under Emacs doesn't allow
2130                      ;; lambda forms for menu commands, we should
2131                      ;; provide intern'ed function symbols.
2132                      (let ((command (intern (format "\
2133 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2134                        (fset command
2135                              `(lambda ()
2136                                 (interactive)
2137                                 (let ((gnus-summary-show-article-charset-alist
2138                                        '((1 . ,cs))))
2139                                   (gnus-summary-show-article 1))))
2140                        `[,(symbol-name cs) ,command t]))
2141                    (sort (if (fboundp 'coding-system-list)
2142                              (coding-system-list)
2143                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2144                            )
2145                          'string<)))))
2146              ("Washing"
2147               ("Remove Blanks"
2148                ["Leading" gnus-article-strip-leading-blank-lines t]
2149                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2150                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2151                ["All of the above" gnus-article-strip-blank-lines t]
2152                ["All" gnus-article-strip-all-blank-lines t]
2153                ["Leading space" gnus-article-strip-leading-space t]
2154                ["Trailing space" gnus-article-strip-trailing-space t]
2155                ["Leading space in headers"
2156                 gnus-article-remove-leading-whitespace t])
2157               ["Overstrike" gnus-article-treat-overstrike t]
2158               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2159               ["Emphasis" gnus-article-emphasize t]
2160               ["Word wrap" gnus-article-fill-cited-article t]
2161               ["Fill long lines" gnus-article-fill-long-lines t]
2162               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2163               ["Remove CR" gnus-article-remove-cr t]
2164               ["Rot 13" gnus-summary-caesar-message
2165                ,@(if (featurep 'xemacs) '(t)
2166                    '(:help "\"Caesar rotate\" article by 13"))]
2167               ["Morse decode" gnus-summary-morse-message t]
2168               ["Unix pipe..." gnus-summary-pipe-message t]
2169               ["Add buttons" gnus-article-add-buttons t]
2170               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2171               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2172               ["Toggle MIME" gnus-summary-toggle-mime t]
2173               ["Verbose header" gnus-summary-verbose-headers t]
2174               ["Toggle header" gnus-summary-toggle-header t]
2175               ["Unfold headers" gnus-article-treat-unfold-headers t]
2176               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2177               ["Html" gnus-article-wash-html t]
2178               ["Unsplit URLs" gnus-article-unsplit-urls t]
2179               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2180               ["Decode HZ" gnus-article-decode-HZ t]
2181               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2182               ("(Outlook) Deuglify"
2183                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2184                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2185                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2186                ["Full (Outlook) deuglify"
2187                 gnus-article-outlook-deuglify-article t])
2188               )
2189              ("Output"
2190               ["Save in default format..." gnus-summary-save-article
2191                ,@(if (featurep 'xemacs) '(t)
2192                    '(:help "Save article using default method"))]
2193               ["Save in file..." gnus-summary-save-article-file
2194                ,@(if (featurep 'xemacs) '(t)
2195                    '(:help "Save article in file"))]
2196               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2197               ["Save in MH folder..." gnus-summary-save-article-folder t]
2198               ["Save in VM folder..." gnus-summary-save-article-vm t]
2199               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2200               ["Save body in file..." gnus-summary-save-article-body-file t]
2201               ["Pipe through a filter..." gnus-summary-pipe-output t]
2202               ["Add to SOUP packet" gnus-soup-add-article t]
2203               ["Print with Muttprint..." gnus-summary-muttprint t]
2204               ["Print" gnus-summary-print-article t])
2205              ("Backend"
2206               ["Respool article..." gnus-summary-respool-article t]
2207               ["Move article..." gnus-summary-move-article
2208                (gnus-check-backend-function
2209                 'request-move-article gnus-newsgroup-name)]
2210               ["Copy article..." gnus-summary-copy-article t]
2211               ["Crosspost article..." gnus-summary-crosspost-article
2212                (gnus-check-backend-function
2213                 'request-replace-article gnus-newsgroup-name)]
2214               ["Import file..." gnus-summary-import-article
2215                (gnus-check-backend-function
2216                 'request-accept-article gnus-newsgroup-name)]
2217               ["Create article..." gnus-summary-create-article
2218                (gnus-check-backend-function
2219                 'request-accept-article gnus-newsgroup-name)]
2220               ["Check if posted" gnus-summary-article-posted-p t]
2221               ["Edit article" gnus-summary-edit-article
2222                (not (gnus-group-read-only-p))]
2223               ["Delete article" gnus-summary-delete-article
2224                (gnus-check-backend-function
2225                 'request-expire-articles gnus-newsgroup-name)]
2226               ["Query respool" gnus-summary-respool-query t]
2227               ["Trace respool" gnus-summary-respool-trace t]
2228               ["Delete expirable articles" gnus-summary-expire-articles-now
2229                (gnus-check-backend-function
2230                 'request-expire-articles gnus-newsgroup-name)])
2231              ("Extract"
2232               ["Uudecode" gnus-uu-decode-uu
2233                ,@(if (featurep 'xemacs) '(t)
2234                    '(:help "Decode uuencoded article(s)"))]
2235               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2236               ["Unshar" gnus-uu-decode-unshar t]
2237               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2238               ["Save" gnus-uu-decode-save t]
2239               ["Binhex" gnus-uu-decode-binhex t]
2240               ["Postscript" gnus-uu-decode-postscript t])
2241              ("Cache"
2242               ["Enter article" gnus-cache-enter-article t]
2243               ["Remove article" gnus-cache-remove-article t])
2244              ["Translate" gnus-article-babel t]
2245              ["Select article buffer" gnus-summary-select-article-buffer t]
2246              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2247              ["Isearch article..." gnus-summary-isearch-article t]
2248              ["Beginning of the article" gnus-summary-beginning-of-article t]
2249              ["End of the article" gnus-summary-end-of-article t]
2250              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2251              ["Fetch referenced articles" gnus-summary-refer-references t]
2252              ["Fetch current thread" gnus-summary-refer-thread t]
2253              ["Fetch article with id..." gnus-summary-refer-article t]
2254              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2255              ["Redisplay" gnus-summary-show-article t]
2256              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2257       (easy-menu-define
2258        gnus-summary-article-menu gnus-summary-mode-map ""
2259        (cons "Article" innards))
2260
2261       (if (not (keymapp gnus-summary-article-menu))
2262           (easy-menu-define
2263            gnus-article-commands-menu gnus-article-mode-map ""
2264            (cons "Commands" innards))
2265         ;; in Emacs, don't share menu.
2266         (setq gnus-article-commands-menu
2267               (copy-keymap gnus-summary-article-menu))
2268         (define-key gnus-article-mode-map [menu-bar commands]
2269           (cons "Commands" gnus-article-commands-menu))))
2270
2271     (easy-menu-define
2272      gnus-summary-thread-menu gnus-summary-mode-map ""
2273      '("Threads"
2274        ["Find all messages in thread" gnus-summary-refer-thread t]
2275        ["Toggle threading" gnus-summary-toggle-threads t]
2276        ["Hide threads" gnus-summary-hide-all-threads t]
2277        ["Show threads" gnus-summary-show-all-threads t]
2278        ["Hide thread" gnus-summary-hide-thread t]
2279        ["Show thread" gnus-summary-show-thread t]
2280        ["Go to next thread" gnus-summary-next-thread t]
2281        ["Go to previous thread" gnus-summary-prev-thread t]
2282        ["Go down thread" gnus-summary-down-thread t]
2283        ["Go up thread" gnus-summary-up-thread t]
2284        ["Top of thread" gnus-summary-top-thread t]
2285        ["Mark thread as read" gnus-summary-kill-thread t]
2286        ["Lower thread score" gnus-summary-lower-thread t]
2287        ["Raise thread score" gnus-summary-raise-thread t]
2288        ["Rethread current" gnus-summary-rethread-current t]))
2289
2290     (easy-menu-define
2291      gnus-summary-post-menu gnus-summary-mode-map ""
2292      `("Post"
2293        ["Send a message (mail or news)" gnus-summary-post-news
2294         ,@(if (featurep 'xemacs) '(t)
2295             '(:help "Post an article"))]
2296        ["Followup" gnus-summary-followup
2297         ,@(if (featurep 'xemacs) '(t)
2298             '(:help "Post followup to this article"))]
2299        ["Followup and yank" gnus-summary-followup-with-original
2300         ,@(if (featurep 'xemacs) '(t)
2301             '(:help "Post followup to this article, quoting its contents"))]
2302        ["Supersede article" gnus-summary-supersede-article t]
2303        ["Cancel article" gnus-summary-cancel-article
2304         ,@(if (featurep 'xemacs) '(t)
2305             '(:help "Cancel an article you posted"))]
2306        ["Reply" gnus-summary-reply t]
2307        ["Reply and yank" gnus-summary-reply-with-original t]
2308        ["Wide reply" gnus-summary-wide-reply t]
2309        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2310         ,@(if (featurep 'xemacs) '(t)
2311             '(:help "Mail a reply, quoting this article"))]
2312        ["Very wide reply" gnus-summary-very-wide-reply t]
2313        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2314         ,@(if (featurep 'xemacs) '(t)
2315             '(:help "Mail a very wide reply, quoting this article"))]
2316        ["Mail forward" gnus-summary-mail-forward t]
2317        ["Post forward" gnus-summary-post-forward t]
2318        ["Digest and mail" gnus-summary-digest-mail-forward t]
2319        ["Digest and post" gnus-summary-digest-post-forward t]
2320        ["Resend message" gnus-summary-resend-message t]
2321        ["Resend message edit" gnus-summary-resend-message-edit t]
2322        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2323        ["Send a mail" gnus-summary-mail-other-window t]
2324        ["Create a local message" gnus-summary-news-other-window t]
2325        ["Uuencode and post" gnus-uu-post-news
2326         ,@(if (featurep 'xemacs) '(t)
2327             '(:help "Post a uuencoded article"))]
2328        ["Followup via news" gnus-summary-followup-to-mail t]
2329        ["Followup via news and yank"
2330         gnus-summary-followup-to-mail-with-original t]
2331        ;;("Draft"
2332        ;;["Send" gnus-summary-send-draft t]
2333        ;;["Send bounced" gnus-resend-bounced-mail t])
2334        ))
2335
2336     (cond
2337      ((not (keymapp gnus-summary-post-menu))
2338       (setq gnus-article-post-menu gnus-summary-post-menu))
2339      ((not gnus-article-post-menu)
2340       ;; Don't share post menu.
2341       (setq gnus-article-post-menu
2342             (copy-keymap gnus-summary-post-menu))))
2343     (define-key gnus-article-mode-map [menu-bar post]
2344       (cons "Post" gnus-article-post-menu))
2345
2346     (easy-menu-define
2347      gnus-summary-misc-menu gnus-summary-mode-map ""
2348      `("Gnus"
2349        ("Mark Read"
2350         ["Mark as read" gnus-summary-mark-as-read-forward t]
2351         ["Mark same subject and select"
2352          gnus-summary-kill-same-subject-and-select t]
2353         ["Mark same subject" gnus-summary-kill-same-subject t]
2354         ["Catchup" gnus-summary-catchup
2355          ,@(if (featurep 'xemacs) '(t)
2356              '(:help "Mark unread articles in this group as read"))]
2357         ["Catchup all" gnus-summary-catchup-all t]
2358         ["Catchup to here" gnus-summary-catchup-to-here t]
2359         ["Catchup from here" gnus-summary-catchup-from-here t]
2360         ["Catchup region" gnus-summary-mark-region-as-read
2361          (gnus-mark-active-p)]
2362         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2363        ("Mark Various"
2364         ["Tick" gnus-summary-tick-article-forward t]
2365         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2366         ["Remove marks" gnus-summary-clear-mark-forward t]
2367         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2368         ["Set bookmark" gnus-summary-set-bookmark t]
2369         ["Remove bookmark" gnus-summary-remove-bookmark t])
2370        ("Limit to"
2371         ["Marks..." gnus-summary-limit-to-marks t]
2372         ["Subject..." gnus-summary-limit-to-subject t]
2373         ["Author..." gnus-summary-limit-to-author t]
2374         ["Age..." gnus-summary-limit-to-age t]
2375         ["Extra..." gnus-summary-limit-to-extra t]
2376         ["Score..." gnus-summary-limit-to-score t]
2377         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2378         ["Unread" gnus-summary-limit-to-unread t]
2379         ["Unseen" gnus-summary-limit-to-unseen t]
2380         ["Replied" gnus-summary-limit-to-replied t]
2381         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2382         ["Next articles" gnus-summary-limit-to-articles t]
2383         ["Pop limit" gnus-summary-pop-limit t]
2384         ["Show dormant" gnus-summary-limit-include-dormant t]
2385         ["Hide childless dormant"
2386          gnus-summary-limit-exclude-childless-dormant t]
2387         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2388         ["Hide marked" gnus-summary-limit-exclude-marks t]
2389         ["Show expunged" gnus-summary-limit-include-expunged t])
2390        ("Process Mark"
2391         ["Set mark" gnus-summary-mark-as-processable t]
2392         ["Remove mark" gnus-summary-unmark-as-processable t]
2393         ["Remove all marks" gnus-summary-unmark-all-processable t]
2394         ["Mark above" gnus-uu-mark-over t]
2395         ["Mark series" gnus-uu-mark-series t]
2396         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2397         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2398         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2399         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2400         ["Mark all" gnus-uu-mark-all t]
2401         ["Mark buffer" gnus-uu-mark-buffer t]
2402         ["Mark sparse" gnus-uu-mark-sparse t]
2403         ["Mark thread" gnus-uu-mark-thread t]
2404         ["Unmark thread" gnus-uu-unmark-thread t]
2405         ("Process Mark Sets"
2406          ["Kill" gnus-summary-kill-process-mark t]
2407          ["Yank" gnus-summary-yank-process-mark
2408           gnus-newsgroup-process-stack]
2409          ["Save" gnus-summary-save-process-mark t]
2410          ["Run command on marked..." gnus-summary-universal-argument t]))
2411        ("Scroll article"
2412         ["Page forward" gnus-summary-next-page
2413          ,@(if (featurep 'xemacs) '(t)
2414              '(:help "Show next page of article"))]
2415         ["Page backward" gnus-summary-prev-page
2416          ,@(if (featurep 'xemacs) '(t)
2417              '(:help "Show previous page of article"))]
2418         ["Line forward" gnus-summary-scroll-up t])
2419        ("Move"
2420         ["Next unread article" gnus-summary-next-unread-article t]
2421         ["Previous unread article" gnus-summary-prev-unread-article t]
2422         ["Next article" gnus-summary-next-article t]
2423         ["Previous article" gnus-summary-prev-article t]
2424         ["Next unread subject" gnus-summary-next-unread-subject t]
2425         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2426         ["Next article same subject" gnus-summary-next-same-subject t]
2427         ["Previous article same subject" gnus-summary-prev-same-subject t]
2428         ["First unread article" gnus-summary-first-unread-article t]
2429         ["Best unread article" gnus-summary-best-unread-article t]
2430         ["Go to subject number..." gnus-summary-goto-subject t]
2431         ["Go to article number..." gnus-summary-goto-article t]
2432         ["Go to the last article" gnus-summary-goto-last-article t]
2433         ["Pop article off history" gnus-summary-pop-article t])
2434        ("Sort"
2435         ["Sort by number" gnus-summary-sort-by-number t]
2436         ["Sort by author" gnus-summary-sort-by-author t]
2437         ["Sort by subject" gnus-summary-sort-by-subject t]
2438         ["Sort by date" gnus-summary-sort-by-date t]
2439         ["Sort by score" gnus-summary-sort-by-score t]
2440         ["Sort by lines" gnus-summary-sort-by-lines t]
2441         ["Sort by characters" gnus-summary-sort-by-chars t]
2442         ["Randomize" gnus-summary-sort-by-random t]
2443         ["Original sort" gnus-summary-sort-by-original t])
2444        ("Help"
2445         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2446         ["Describe group" gnus-summary-describe-group t]
2447         ["Fetch charter" gnus-group-fetch-charter
2448          ,@(if (featurep 'xemacs) nil
2449              '(:help "Display the charter of the current group"))]
2450         ["Fetch control message" gnus-group-fetch-control
2451          ,@(if (featurep 'xemacs) nil
2452              '(:help "Display the archived control message for the current group"))]
2453         ["Read manual" gnus-info-find-node t])
2454        ("Modes"
2455         ["Pick and read" gnus-pick-mode t]
2456         ["Binary" gnus-binary-mode t])
2457        ("Regeneration"
2458         ["Regenerate" gnus-summary-prepare t]
2459         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2460         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2461         ["Toggle threading" gnus-summary-toggle-threads t])
2462        ["See old articles" gnus-summary-insert-old-articles t]
2463        ["See new articles" gnus-summary-insert-new-articles t]
2464        ["Filter articles..." gnus-summary-execute-command t]
2465        ["Run command on articles..." gnus-summary-universal-argument t]
2466        ["Search articles forward..." gnus-summary-search-article-forward t]
2467        ["Search articles backward..." gnus-summary-search-article-backward t]
2468        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2469        ["Expand window" gnus-summary-expand-window t]
2470        ["Expire expirable articles" gnus-summary-expire-articles
2471         (gnus-check-backend-function
2472          'request-expire-articles gnus-newsgroup-name)]
2473        ["Edit local kill file" gnus-summary-edit-local-kill t]
2474        ["Edit main kill file" gnus-summary-edit-global-kill t]
2475        ["Edit group parameters" gnus-summary-edit-parameters t]
2476        ["Customize group parameters" gnus-summary-customize-parameters t]
2477        ["Send a bug report" gnus-bug t]
2478        ("Exit"
2479         ["Catchup and exit" gnus-summary-catchup-and-exit
2480          ,@(if (featurep 'xemacs) '(t)
2481              '(:help "Mark unread articles in this group as read, then exit"))]
2482         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2483         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2484         ["Exit group" gnus-summary-exit
2485          ,@(if (featurep 'xemacs) '(t)
2486              '(:help "Exit current group, return to group selection mode"))]
2487         ["Exit group without updating" gnus-summary-exit-no-update t]
2488         ["Exit and goto next group" gnus-summary-next-group t]
2489         ["Exit and goto prev group" gnus-summary-prev-group t]
2490         ["Reselect group" gnus-summary-reselect-current-group t]
2491         ["Rescan group" gnus-summary-rescan-group t]
2492         ["Update dribble" gnus-summary-save-newsrc t])))
2493
2494     (gnus-run-hooks 'gnus-summary-menu-hook)))
2495
2496 (defvar gnus-summary-tool-bar-map nil)
2497
2498 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2499 (defun gnus-summary-make-tool-bar ()
2500   (if (and (fboundp 'tool-bar-add-item-from-menu)
2501            (default-value 'tool-bar-mode)
2502            (not gnus-summary-tool-bar-map))
2503       (setq gnus-summary-tool-bar-map
2504             (let ((tool-bar-map (make-sparse-keymap))
2505                   (load-path (mm-image-load-path)))
2506               (tool-bar-add-item-from-menu
2507                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-summary-post-news "post" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-summary-followup "followup" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-summary-reply "reply" gnus-summary-mode-map)
2520               (tool-bar-add-item-from-menu
2521                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2522               (tool-bar-add-item-from-menu
2523                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2524               (tool-bar-add-item-from-menu
2525                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2526               (tool-bar-add-item-from-menu
2527                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2528               (tool-bar-add-item-from-menu
2529                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2530               (tool-bar-add-item-from-menu
2531                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2532               (tool-bar-add-item-from-menu
2533                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2534               (tool-bar-add-item-from-menu
2535                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2536               tool-bar-map)))
2537   (if gnus-summary-tool-bar-map
2538       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2539
2540 (defun gnus-score-set-default (var value)
2541   "A version of set that updates the GNU Emacs menu-bar."
2542   (set var value)
2543   ;; It is the message that forces the active status to be updated.
2544   (message ""))
2545
2546 (defun gnus-make-score-map (type)
2547   "Make a summary score map of type TYPE."
2548   (if t
2549       nil
2550     (let ((headers '(("author" "from" string)
2551                      ("subject" "subject" string)
2552                      ("article body" "body" string)
2553                      ("article head" "head" string)
2554                      ("xref" "xref" string)
2555                      ("extra header" "extra" string)
2556                      ("lines" "lines" number)
2557                      ("followups to author" "followup" string)))
2558           (types '((number ("less than" <)
2559                            ("greater than" >)
2560                            ("equal" =))
2561                    (string ("substring" s)
2562                            ("exact string" e)
2563                            ("fuzzy string" f)
2564                            ("regexp" r))))
2565           (perms '(("temporary" (current-time-string))
2566                    ("permanent" nil)
2567                    ("immediate" now)))
2568           header)
2569       (list
2570        (apply
2571         'nconc
2572         (list
2573          (if (eq type 'lower)
2574              "Lower score"
2575            "Increase score"))
2576         (let (outh)
2577           (while headers
2578             (setq header (car headers))
2579             (setq outh
2580                   (cons
2581                    (apply
2582                     'nconc
2583                     (list (car header))
2584                     (let ((ts (cdr (assoc (nth 2 header) types)))
2585                           outt)
2586                       (while ts
2587                         (setq outt
2588                               (cons
2589                                (apply
2590                                 'nconc
2591                                 (list (caar ts))
2592                                 (let ((ps perms)
2593                                       outp)
2594                                   (while ps
2595                                     (setq outp
2596                                           (cons
2597                                            (vector
2598                                             (caar ps)
2599                                             (list
2600                                              'gnus-summary-score-entry
2601                                              (nth 1 header)
2602                                              (if (or (string= (nth 1 header)
2603                                                               "head")
2604                                                      (string= (nth 1 header)
2605                                                               "body"))
2606                                                  ""
2607                                                (list 'gnus-summary-header
2608                                                      (nth 1 header)))
2609                                              (list 'quote (nth 1 (car ts)))
2610                                              (list 'gnus-score-delta-default
2611                                                    nil)
2612                                              (nth 1 (car ps))
2613                                              t)
2614                                             t)
2615                                            outp))
2616                                     (setq ps (cdr ps)))
2617                                   (list (nreverse outp))))
2618                                outt))
2619                         (setq ts (cdr ts)))
2620                       (list (nreverse outt))))
2621                    outh))
2622             (setq headers (cdr headers)))
2623           (list (nreverse outh))))))))
2624
2625 \f
2626
2627 (defun gnus-summary-mode (&optional group)
2628   "Major mode for reading articles.
2629
2630 All normal editing commands are switched off.
2631 \\<gnus-summary-mode-map>
2632 Each line in this buffer represents one article.  To read an
2633 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2634 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2635 respectively.
2636
2637 You can also post articles and send mail from this buffer.  To
2638 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2639 of an article, type `\\[gnus-summary-reply]'.
2640
2641 There are approx. one gazillion commands you can execute in this
2642 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2643
2644 The following commands are available:
2645
2646 \\{gnus-summary-mode-map}"
2647   (interactive)
2648   (kill-all-local-variables)
2649   (when (gnus-visual-p 'summary-menu 'menu)
2650     (gnus-summary-make-menu-bar)
2651     (gnus-summary-make-tool-bar))
2652   (gnus-summary-make-local-variables)
2653   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2654     (gnus-summary-make-local-variables))
2655   (gnus-make-thread-indent-array)
2656   (gnus-simplify-mode-line)
2657   (setq major-mode 'gnus-summary-mode)
2658   (setq mode-name "Summary")
2659   (make-local-variable 'minor-mode-alist)
2660   (use-local-map gnus-summary-mode-map)
2661   (buffer-disable-undo)
2662   (setq buffer-read-only t)             ;Disable modification
2663   (setq truncate-lines t)
2664   (setq selective-display t)
2665   (setq selective-display-ellipses t)   ;Display `...'
2666   (gnus-summary-set-display-table)
2667   (gnus-set-default-directory)
2668   (setq gnus-newsgroup-name group)
2669   (unless (gnus-news-group-p group)
2670     (setq gnus-newsgroup-incorporated
2671           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2672   (make-local-variable 'gnus-summary-line-format)
2673   (make-local-variable 'gnus-summary-line-format-spec)
2674   (make-local-variable 'gnus-summary-dummy-line-format)
2675   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2676   (make-local-variable 'gnus-summary-mark-positions)
2677   (gnus-make-local-hook 'pre-command-hook)
2678   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2679   (gnus-run-hooks 'gnus-summary-mode-hook)
2680   (turn-on-gnus-mailing-list-mode)
2681   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2682   (gnus-update-summary-mark-positions))
2683
2684 (defun gnus-summary-make-local-variables ()
2685   "Make all the local summary buffer variables."
2686   (let (global)
2687     (dolist (local gnus-summary-local-variables)
2688       (if (consp local)
2689           (progn
2690             (if (eq (cdr local) 'global)
2691                 ;; Copy the global value of the variable.
2692                 (setq global (symbol-value (car local)))
2693               ;; Use the value from the list.
2694               (setq global (eval (cdr local))))
2695             (set (make-local-variable (car local)) global))
2696         ;; Simple nil-valued local variable.
2697         (set (make-local-variable local) nil)))))
2698
2699 (defun gnus-summary-clear-local-variables ()
2700   (let ((locals gnus-summary-local-variables))
2701     (while locals
2702       (if (consp (car locals))
2703           (and (vectorp (caar locals))
2704                (set (caar locals) nil))
2705         (and (vectorp (car locals))
2706              (set (car locals) nil)))
2707       (setq locals (cdr locals)))))
2708
2709 ;; Summary data functions.
2710
2711 (defmacro gnus-data-number (data)
2712   `(car ,data))
2713
2714 (defmacro gnus-data-set-number (data number)
2715   `(setcar ,data ,number))
2716
2717 (defmacro gnus-data-mark (data)
2718   `(nth 1 ,data))
2719
2720 (defmacro gnus-data-set-mark (data mark)
2721   `(setcar (nthcdr 1 ,data) ,mark))
2722
2723 (defmacro gnus-data-pos (data)
2724   `(nth 2 ,data))
2725
2726 (defmacro gnus-data-set-pos (data pos)
2727   `(setcar (nthcdr 2 ,data) ,pos))
2728
2729 (defmacro gnus-data-header (data)
2730   `(nth 3 ,data))
2731
2732 (defmacro gnus-data-set-header (data header)
2733   `(setcar (nthcdr 3 ,data) ,header))
2734
2735 (defmacro gnus-data-level (data)
2736   `(nth 4 ,data))
2737
2738 (defmacro gnus-data-unread-p (data)
2739   `(= (nth 1 ,data) gnus-unread-mark))
2740
2741 (defmacro gnus-data-read-p (data)
2742   `(/= (nth 1 ,data) gnus-unread-mark))
2743
2744 (defmacro gnus-data-pseudo-p (data)
2745   `(consp (nth 3 ,data)))
2746
2747 (defmacro gnus-data-find (number)
2748   `(assq ,number gnus-newsgroup-data))
2749
2750 (defmacro gnus-data-find-list (number &optional data)
2751   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2752      (memq (assq ,number bdata)
2753            bdata)))
2754
2755 (defmacro gnus-data-make (number mark pos header level)
2756   `(list ,number ,mark ,pos ,header ,level))
2757
2758 (defun gnus-data-enter (after-article number mark pos header level offset)
2759   (let ((data (gnus-data-find-list after-article)))
2760     (unless data
2761       (error "No such article: %d" after-article))
2762     (setcdr data (cons (gnus-data-make number mark pos header level)
2763                        (cdr data)))
2764     (setq gnus-newsgroup-data-reverse nil)
2765     (gnus-data-update-list (cddr data) offset)))
2766
2767 (defun gnus-data-enter-list (after-article list &optional offset)
2768   (when list
2769     (let ((data (and after-article (gnus-data-find-list after-article)))
2770           (ilist list))
2771       (if (not (or data
2772                    after-article))
2773           (let ((odata gnus-newsgroup-data))
2774             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2775             (when offset
2776               (gnus-data-update-list odata offset)))
2777         ;; Find the last element in the list to be spliced into the main
2778         ;; list.
2779         (while (cdr list)
2780           (setq list (cdr list)))
2781         (if (not data)
2782             (progn
2783               (setcdr list gnus-newsgroup-data)
2784               (setq gnus-newsgroup-data ilist)
2785               (when offset
2786                 (gnus-data-update-list (cdr list) offset)))
2787           (setcdr list (cdr data))
2788           (setcdr data ilist)
2789           (when offset
2790             (gnus-data-update-list (cdr list) offset))))
2791       (setq gnus-newsgroup-data-reverse nil))))
2792
2793 (defun gnus-data-remove (article &optional offset)
2794   (let ((data gnus-newsgroup-data))
2795     (if (= (gnus-data-number (car data)) article)
2796         (progn
2797           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2798                 gnus-newsgroup-data-reverse nil)
2799           (when offset
2800             (gnus-data-update-list gnus-newsgroup-data offset)))
2801       (while (cdr data)
2802         (when (= (gnus-data-number (cadr data)) article)
2803           (setcdr data (cddr data))
2804           (when offset
2805             (gnus-data-update-list (cdr data) offset))
2806           (setq data nil
2807                 gnus-newsgroup-data-reverse nil))
2808         (setq data (cdr data))))))
2809
2810 (defmacro gnus-data-list (backward)
2811   `(if ,backward
2812        (or gnus-newsgroup-data-reverse
2813            (setq gnus-newsgroup-data-reverse
2814                  (reverse gnus-newsgroup-data)))
2815      gnus-newsgroup-data))
2816
2817 (defun gnus-data-update-list (data offset)
2818   "Add OFFSET to the POS of all data entries in DATA."
2819   (setq gnus-newsgroup-data-reverse nil)
2820   (while data
2821     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2822     (setq data (cdr data))))
2823
2824 (defun gnus-summary-article-pseudo-p (article)
2825   "Say whether this article is a pseudo article or not."
2826   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2827
2828 (defmacro gnus-summary-article-sparse-p (article)
2829   "Say whether this article is a sparse article or not."
2830   `(memq ,article gnus-newsgroup-sparse))
2831
2832 (defmacro gnus-summary-article-ancient-p (article)
2833   "Say whether this article is a sparse article or not."
2834   `(memq ,article gnus-newsgroup-ancient))
2835
2836 (defun gnus-article-parent-p (number)
2837   "Say whether this article is a parent or not."
2838   (let ((data (gnus-data-find-list number)))
2839     (and (cdr data)                     ; There has to be an article after...
2840          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2841             (gnus-data-level (nth 1 data))))))
2842
2843 (defun gnus-article-children (number)
2844   "Return a list of all children to NUMBER."
2845   (let* ((data (gnus-data-find-list number))
2846          (level (gnus-data-level (car data)))
2847          children)
2848     (setq data (cdr data))
2849     (while (and data
2850                 (= (gnus-data-level (car data)) (1+ level)))
2851       (push (gnus-data-number (car data)) children)
2852       (setq data (cdr data)))
2853     children))
2854
2855 (defmacro gnus-summary-skip-intangible ()
2856   "If the current article is intangible, then jump to a different article."
2857   '(let ((to (get-text-property (point) 'gnus-intangible)))
2858      (and to (gnus-summary-goto-subject to))))
2859
2860 (defmacro gnus-summary-article-intangible-p ()
2861   "Say whether this article is intangible or not."
2862   '(get-text-property (point) 'gnus-intangible))
2863
2864 (defun gnus-article-read-p (article)
2865   "Say whether ARTICLE is read or not."
2866   (not (or (memq article gnus-newsgroup-marked)
2867            (memq article gnus-newsgroup-spam-marked)
2868            (memq article gnus-newsgroup-unreads)
2869            (memq article gnus-newsgroup-unselected)
2870            (memq article gnus-newsgroup-dormant))))
2871
2872 ;; Some summary mode macros.
2873
2874 (defmacro gnus-summary-article-number ()
2875   "The article number of the article on the current line.
2876 If there isn't an article number here, then we return the current
2877 article number."
2878   '(progn
2879      (gnus-summary-skip-intangible)
2880      (or (get-text-property (point) 'gnus-number)
2881          (gnus-summary-last-subject))))
2882
2883 (defmacro gnus-summary-article-header (&optional number)
2884   "Return the header of article NUMBER."
2885   `(gnus-data-header (gnus-data-find
2886                       ,(or number '(gnus-summary-article-number)))))
2887
2888 (defmacro gnus-summary-thread-level (&optional number)
2889   "Return the level of thread that starts with article NUMBER."
2890   `(if (and (eq gnus-summary-make-false-root 'dummy)
2891             (get-text-property (point) 'gnus-intangible))
2892        0
2893      (gnus-data-level (gnus-data-find
2894                        ,(or number '(gnus-summary-article-number))))))
2895
2896 (defmacro gnus-summary-article-mark (&optional number)
2897   "Return the mark of article NUMBER."
2898   `(gnus-data-mark (gnus-data-find
2899                     ,(or number '(gnus-summary-article-number)))))
2900
2901 (defmacro gnus-summary-article-pos (&optional number)
2902   "Return the position of the line of article NUMBER."
2903   `(gnus-data-pos (gnus-data-find
2904                    ,(or number '(gnus-summary-article-number)))))
2905
2906 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2907 (defmacro gnus-summary-article-subject (&optional number)
2908   "Return current subject string or nil if nothing."
2909   `(let ((headers
2910           ,(if number
2911                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2912              '(gnus-data-header (assq (gnus-summary-article-number)
2913                                       gnus-newsgroup-data)))))
2914      (and headers
2915           (vectorp headers)
2916           (mail-header-subject headers))))
2917
2918 (defmacro gnus-summary-article-score (&optional number)
2919   "Return current article score."
2920   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2921                   gnus-newsgroup-scored))
2922        gnus-summary-default-score 0))
2923
2924 (defun gnus-summary-article-children (&optional number)
2925   "Return a list of article numbers that are children of article NUMBER."
2926   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2927          (level (gnus-data-level (car data)))
2928          l children)
2929     (while (and (setq data (cdr data))
2930                 (> (setq l (gnus-data-level (car data))) level))
2931       (and (= (1+ level) l)
2932            (push (gnus-data-number (car data))
2933                  children)))
2934     (nreverse children)))
2935
2936 (defun gnus-summary-article-parent (&optional number)
2937   "Return the article number of the parent of article NUMBER."
2938   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2939                                     (gnus-data-list t)))
2940          (level (gnus-data-level (car data))))
2941     (if (zerop level)
2942         ()                              ; This is a root.
2943       ;; We search until we find an article with a level less than
2944       ;; this one.  That function has to be the parent.
2945       (while (and (setq data (cdr data))
2946                   (not (< (gnus-data-level (car data)) level))))
2947       (and data (gnus-data-number (car data))))))
2948
2949 (defun gnus-unread-mark-p (mark)
2950   "Say whether MARK is the unread mark."
2951   (= mark gnus-unread-mark))
2952
2953 (defun gnus-read-mark-p (mark)
2954   "Say whether MARK is one of the marks that mark as read.
2955 This is all marks except unread, ticked, dormant, and expirable."
2956   (not (or (= mark gnus-unread-mark)
2957            (= mark gnus-ticked-mark)
2958            (= mark gnus-spam-mark)
2959            (= mark gnus-dormant-mark)
2960            (= mark gnus-expirable-mark))))
2961
2962 (defmacro gnus-article-mark (number)
2963   "Return the MARK of article NUMBER.
2964 This macro should only be used when computing the mark the \"first\"
2965 time; i.e., when generating the summary lines.  After that,
2966 `gnus-summary-article-mark' should be used to examine the
2967 marks of articles."
2968   `(cond
2969     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2970     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2971     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2972     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2973     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2974     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2975     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2976     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2977            gnus-ancient-mark))))
2978
2979 ;; Saving hidden threads.
2980
2981 (defmacro gnus-save-hidden-threads (&rest forms)
2982   "Save hidden threads, eval FORMS, and restore the hidden threads."
2983   (let ((config (make-symbol "config")))
2984     `(let ((,config (gnus-hidden-threads-configuration)))
2985        (unwind-protect
2986            (save-excursion
2987              ,@forms)
2988          (gnus-restore-hidden-threads-configuration ,config)))))
2989 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2990 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2991
2992 (defun gnus-data-compute-positions ()
2993   "Compute the positions of all articles."
2994   (setq gnus-newsgroup-data-reverse nil)
2995   (let ((data gnus-newsgroup-data))
2996     (save-excursion
2997       (gnus-save-hidden-threads
2998         (gnus-summary-show-all-threads)
2999         (goto-char (point-min))
3000         (while data
3001           (while (get-text-property (point) 'gnus-intangible)
3002             (forward-line 1))
3003           (gnus-data-set-pos (car data) (+ (point) 3))
3004           (setq data (cdr data))
3005           (forward-line 1))))))
3006
3007 (defun gnus-hidden-threads-configuration ()
3008   "Return the current hidden threads configuration."
3009   (save-excursion
3010     (let (config)
3011       (goto-char (point-min))
3012       (while (search-forward "\r" nil t)
3013         (push (1- (point)) config))
3014       config)))
3015
3016 (defun gnus-restore-hidden-threads-configuration (config)
3017   "Restore hidden threads configuration from CONFIG."
3018   (save-excursion
3019     (let (point buffer-read-only)
3020       (while (setq point (pop config))
3021         (when (and (< point (point-max))
3022                    (goto-char point)
3023                    (eq (char-after) ?\n))
3024           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3025
3026 ;; Various summary mode internalish functions.
3027
3028 (defun gnus-mouse-pick-article (e)
3029   (interactive "e")
3030   (mouse-set-point e)
3031   (gnus-summary-next-page nil t))
3032
3033 (defun gnus-summary-set-display-table ()
3034   "Change the display table.
3035 Odd characters have a tendency to mess
3036 up nicely formatted displays - we make all possible glyphs
3037 display only a single character."
3038
3039   ;; We start from the standard display table, if any.
3040   (let ((table (or (copy-sequence standard-display-table)
3041                    (make-display-table)))
3042         (i 32))
3043     ;; Nix out all the control chars...
3044     (while (>= (setq i (1- i)) 0)
3045       (aset table i [??]))
3046     ;; ... but not newline and cr, of course.  (cr is necessary for the
3047     ;; selective display).
3048     (aset table ?\n nil)
3049     (aset table ?\r nil)
3050     ;; We keep TAB as well.
3051     (aset table ?\t nil)
3052     ;; We nix out any glyphs over 126 that are not set already.
3053     (let ((i 256))
3054       (while (>= (setq i (1- i)) 127)
3055         ;; Only modify if the entry is nil.
3056         (unless (aref table i)
3057           (aset table i [??]))))
3058     (setq buffer-display-table table)))
3059
3060 (defun gnus-summary-set-article-display-arrow (pos)
3061   "Update the overlay arrow to point to line at position POS."
3062   (when (and gnus-summary-display-arrow
3063              (boundp 'overlay-arrow-position)
3064              (boundp 'overlay-arrow-string))
3065     (save-excursion
3066       (goto-char pos)
3067       (beginning-of-line)
3068       (unless overlay-arrow-position
3069         (setq overlay-arrow-position (make-marker)))
3070       (setq overlay-arrow-string "=>"
3071             overlay-arrow-position (set-marker overlay-arrow-position
3072                                                (point)
3073                                                (current-buffer))))))
3074
3075 (defun gnus-summary-setup-buffer (group)
3076   "Initialize summary buffer."
3077   (let ((buffer (gnus-summary-buffer-name group))
3078         (dead-name (concat "*Dead Summary "
3079                            (gnus-group-decoded-name group) "*")))
3080     ;; If a dead summary buffer exists, we kill it.
3081     (when (gnus-buffer-live-p dead-name)
3082       (gnus-kill-buffer dead-name))
3083     (if (get-buffer buffer)
3084         (progn
3085           (set-buffer buffer)
3086           (setq gnus-summary-buffer (current-buffer))
3087           (not gnus-newsgroup-prepared))
3088       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3089       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3090       (gnus-summary-mode group)
3091       (when gnus-carpal
3092         (gnus-carpal-setup-buffer 'summary))
3093       (unless gnus-single-article-buffer
3094         (make-local-variable 'gnus-article-buffer)
3095         (make-local-variable 'gnus-article-current)
3096         (make-local-variable 'gnus-original-article-buffer))
3097       (setq gnus-newsgroup-name group)
3098       ;; Set any local variables in the group parameters.
3099       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3100       t)))
3101
3102 (defun gnus-set-global-variables ()
3103   "Set the global equivalents of the buffer-local variables.
3104 They are set to the latest values they had.  These reflect the summary
3105 buffer that was in action when the last article was fetched."
3106   (when (eq major-mode 'gnus-summary-mode)
3107     (setq gnus-summary-buffer (current-buffer))
3108     (let ((name gnus-newsgroup-name)
3109           (marked gnus-newsgroup-marked)
3110           (spam gnus-newsgroup-spam-marked)
3111           (unread gnus-newsgroup-unreads)
3112           (headers gnus-current-headers)
3113           (data gnus-newsgroup-data)
3114           (summary gnus-summary-buffer)
3115           (article-buffer gnus-article-buffer)
3116           (original gnus-original-article-buffer)
3117           (gac gnus-article-current)
3118           (reffed gnus-reffed-article-number)
3119           (score-file gnus-current-score-file)
3120           (default-charset gnus-newsgroup-charset)
3121           vlist)
3122       (let ((locals gnus-newsgroup-variables))
3123         (while locals
3124           (if (consp (car locals))
3125               (push (eval (caar locals)) vlist)
3126             (push (eval (car locals)) vlist))
3127           (setq locals (cdr locals)))
3128         (setq vlist (nreverse vlist)))
3129       (save-excursion
3130         (set-buffer gnus-group-buffer)
3131         (setq gnus-newsgroup-name name
3132               gnus-newsgroup-marked marked
3133               gnus-newsgroup-spam-marked spam
3134               gnus-newsgroup-unreads unread
3135               gnus-current-headers headers
3136               gnus-newsgroup-data data
3137               gnus-article-current gac
3138               gnus-summary-buffer summary
3139               gnus-article-buffer article-buffer
3140               gnus-original-article-buffer original
3141               gnus-reffed-article-number reffed
3142               gnus-current-score-file score-file
3143               gnus-newsgroup-charset default-charset)
3144         (let ((locals gnus-newsgroup-variables))
3145           (while locals
3146             (if (consp (car locals))
3147                 (set (caar locals) (pop vlist))
3148               (set (car locals) (pop vlist)))
3149             (setq locals (cdr locals))))
3150         ;; The article buffer also has local variables.
3151         (when (gnus-buffer-live-p gnus-article-buffer)
3152           (set-buffer gnus-article-buffer)
3153           (setq gnus-summary-buffer summary))))))
3154
3155 (defun gnus-summary-article-unread-p (article)
3156   "Say whether ARTICLE is unread or not."
3157   (memq article gnus-newsgroup-unreads))
3158
3159 (defun gnus-summary-first-article-p (&optional article)
3160   "Return whether ARTICLE is the first article in the buffer."
3161   (if (not (setq article (or article (gnus-summary-article-number))))
3162       nil
3163     (eq article (caar gnus-newsgroup-data))))
3164
3165 (defun gnus-summary-last-article-p (&optional article)
3166   "Return whether ARTICLE is the last article in the buffer."
3167   (if (not (setq article (or article (gnus-summary-article-number))))
3168       ;; All non-existent numbers are the last article.  :-)
3169       t
3170     (not (cdr (gnus-data-find-list article)))))
3171
3172 (defun gnus-make-thread-indent-array ()
3173   (let ((n 200))
3174     (unless (and gnus-thread-indent-array
3175                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3176       (setq gnus-thread-indent-array (make-vector 201 "")
3177             gnus-thread-indent-array-level gnus-thread-indent-level)
3178       (while (>= n 0)
3179         (aset gnus-thread-indent-array n
3180               (make-string (* n gnus-thread-indent-level) ? ))
3181         (setq n (1- n))))))
3182
3183 (defun gnus-update-summary-mark-positions ()
3184   "Compute where the summary marks are to go."
3185   (save-excursion
3186     (when (gnus-buffer-exists-p gnus-summary-buffer)
3187       (set-buffer gnus-summary-buffer))
3188     (let ((gnus-replied-mark 129)
3189           (gnus-score-below-mark 130)
3190           (gnus-score-over-mark 130)
3191           (gnus-undownloaded-mark 131)
3192           (spec gnus-summary-line-format-spec)
3193           gnus-visual pos)
3194       (save-excursion
3195         (gnus-set-work-buffer)
3196         (let ((gnus-summary-line-format-spec spec)
3197               (gnus-newsgroup-downloadable '(0)))
3198           (gnus-summary-insert-line
3199            (make-full-mail-header 0 "" "nobody"
3200                                   "05 Apr 2001 23:33:09 +0400"
3201                                   "" "" 0 0 "" nil)
3202            0 nil t 128 t nil "" nil 1)
3203           (goto-char (point-min))
3204           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3205                                              (- (point) (point-min) 1)))))
3206           (goto-char (point-min))
3207           (push (cons 'replied (and (search-forward "\201" nil t)
3208                                     (- (point) (point-min) 1)))
3209                 pos)
3210           (goto-char (point-min))
3211           (push (cons 'score (and (search-forward "\202" nil t)
3212                                   (- (point) (point-min) 1)))
3213                 pos)
3214           (goto-char (point-min))
3215           (push (cons 'download
3216                       (and (search-forward "\203" nil t)
3217                            (- (point) (point-min) 1)))
3218                 pos)))
3219       (setq gnus-summary-mark-positions pos))))
3220
3221 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3222   "Insert a dummy root in the summary buffer."
3223   (beginning-of-line)
3224   (gnus-add-text-properties
3225    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3226    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3227
3228 (defun gnus-summary-extract-address-component (from)
3229   (or (car (funcall gnus-extract-address-components from))
3230       from))
3231
3232 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3233   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3234                                 default-mime-charset)))
3235     ;; Is it really necessary to do this next part for each summary line?
3236     ;; Luckily, doesn't seem to slow things down much.
3237     (or
3238      (and gnus-ignored-from-addresses
3239           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3240           (let ((extra-headers (mail-header-extra header))
3241                 to
3242                 newsgroups)
3243             (cond
3244              ((setq to (cdr (assq 'To extra-headers)))
3245               (concat "-> "
3246                       (inline
3247                         (gnus-summary-extract-address-component
3248                          (funcall gnus-decode-encoded-word-function to)))))
3249              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3250               (concat "=> " newsgroups)))))
3251      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3252
3253 (defun gnus-summary-insert-line (gnus-tmp-header
3254                                  gnus-tmp-level gnus-tmp-current
3255                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3256                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3257                                  &optional gnus-tmp-dummy gnus-tmp-score
3258                                  gnus-tmp-process)
3259   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3260          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3261          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3262          (gnus-tmp-score-char
3263           (if (or (null gnus-summary-default-score)
3264                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3265                       gnus-summary-zcore-fuzz))
3266               ?\ ;;;Whitespace
3267             (if (< gnus-tmp-score gnus-summary-default-score)
3268                 gnus-score-below-mark gnus-score-over-mark)))
3269          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3270          (gnus-tmp-replied
3271           (cond (gnus-tmp-process gnus-process-mark)
3272                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3273                  gnus-cached-mark)
3274                 (gnus-tmp-replied gnus-replied-mark)
3275                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3276                  gnus-forwarded-mark)
3277                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3278                  gnus-saved-mark)
3279                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3280                  gnus-recent-mark)
3281                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3282                  gnus-unseen-mark)
3283                 (t gnus-no-mark)))
3284          (gnus-tmp-downloaded
3285           (cond (undownloaded
3286                  gnus-undownloaded-mark)
3287                 (gnus-newsgroup-agentized
3288                  gnus-downloaded-mark)
3289                 (t
3290                  gnus-no-mark)))
3291          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3292          (gnus-tmp-name
3293           (cond
3294            ((string-match "<[^>]+> *$" gnus-tmp-from)
3295             (let ((beg (match-beginning 0)))
3296               (or (and (string-match "^\".+\"" gnus-tmp-from)
3297                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3298                   (substring gnus-tmp-from 0 beg))))
3299            ((string-match "(.+)" gnus-tmp-from)
3300             (substring gnus-tmp-from
3301                        (1+ (match-beginning 0)) (1- (match-end 0))))
3302            (t gnus-tmp-from)))
3303          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3304          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3305          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3306          (buffer-read-only nil))
3307     (when (string= gnus-tmp-name "")
3308       (setq gnus-tmp-name gnus-tmp-from))
3309     (unless (numberp gnus-tmp-lines)
3310       (setq gnus-tmp-lines -1))
3311     (if (= gnus-tmp-lines -1)
3312         (setq gnus-tmp-lines "?")
3313       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3314     (gnus-put-text-property-excluding-characters-with-faces
3315      (point)
3316      (progn (eval gnus-summary-line-format-spec) (point))
3317      'gnus-number gnus-tmp-number)
3318     (when (gnus-visual-p 'summary-highlight 'highlight)
3319       (forward-line -1)
3320       (gnus-run-hooks 'gnus-summary-update-hook)
3321       (forward-line 1))))
3322
3323 (defun gnus-summary-update-line (&optional dont-update)
3324   "Update summary line after change."
3325   (when (and gnus-summary-default-score
3326              (not gnus-summary-inhibit-highlight))
3327     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3328            (article (gnus-summary-article-number))
3329            (score (gnus-summary-article-score article)))
3330       (unless dont-update
3331         (if (and gnus-summary-mark-below
3332                  (< (gnus-summary-article-score)
3333                     gnus-summary-mark-below))
3334             ;; This article has a low score, so we mark it as read.
3335             (when (memq article gnus-newsgroup-unreads)
3336               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3337           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3338             ;; This article was previously marked as read on account
3339             ;; of a low score, but now it has risen, so we mark it as
3340             ;; unread.
3341             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3342         (gnus-summary-update-mark
3343          (if (or (null gnus-summary-default-score)
3344                  (<= (abs (- score gnus-summary-default-score))
3345                      gnus-summary-zcore-fuzz))
3346              ?\ ;;;Whitespace
3347            (if (< score gnus-summary-default-score)
3348                gnus-score-below-mark gnus-score-over-mark))
3349          'score))
3350       ;; Do visual highlighting.
3351       (when (gnus-visual-p 'summary-highlight 'highlight)
3352         (gnus-run-hooks 'gnus-summary-update-hook)))))
3353
3354 (defvar gnus-tmp-new-adopts nil)
3355
3356 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3357   "Return the number of articles in THREAD.
3358 This may be 0 in some cases -- if none of the articles in
3359 the thread are to be displayed."
3360   (let* ((number
3361           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3362           (cond
3363            ((not (listp thread))
3364             1)
3365            ((and (consp thread) (cdr thread))
3366             (apply
3367              '+ 1 (mapcar
3368                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3369            ((null thread)
3370             1)
3371            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3372             1)
3373            (t 0))))
3374     (when (and level (zerop level) gnus-tmp-new-adopts)
3375       (incf number
3376             (apply '+ (mapcar
3377                        'gnus-summary-number-of-articles-in-thread
3378                        gnus-tmp-new-adopts))))
3379     (if char
3380         (if (> number 1) gnus-not-empty-thread-mark
3381           gnus-empty-thread-mark)
3382       number)))
3383
3384 (defsubst gnus-summary-line-message-size (head)
3385   "Return pretty-printed version of message size.
3386 This function is intended to be used in
3387 `gnus-summary-line-format-alist'."
3388   (let ((c (or (mail-header-chars head) -1)))
3389     (cond ((< c 0) "n/a")               ; chars not available
3390           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3391           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3392           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3393           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3394
3395
3396 (defun gnus-summary-set-local-parameters (group)
3397   "Go through the local params of GROUP and set all variable specs in that list."
3398   (let ((params (gnus-group-find-parameter group))
3399         (vars '(quit-config))           ; Ignore quit-config.
3400         elem)
3401     (while params
3402       (setq elem (car params)
3403             params (cdr params))
3404       (and (consp elem)                 ; Has to be a cons.
3405            (consp (cdr elem))           ; The cdr has to be a list.
3406            (symbolp (car elem))         ; Has to be a symbol in there.
3407            (not (memq (car elem) vars))
3408            (ignore-errors               ; So we set it.
3409              (push (car elem) vars)
3410              (make-local-variable (car elem))
3411              (set (car elem) (eval (nth 1 elem))))))))
3412
3413 (defun gnus-summary-read-group (group &optional show-all no-article
3414                                       kill-buffer no-display backward
3415                                       select-articles)
3416   "Start reading news in newsgroup GROUP.
3417 If SHOW-ALL is non-nil, already read articles are also listed.
3418 If NO-ARTICLE is non-nil, no article is selected initially.
3419 If NO-DISPLAY, don't generate a summary buffer."
3420   (let (result)
3421     (while (and group
3422                 (null (setq result
3423                             (let ((gnus-auto-select-next nil))
3424                               (or (gnus-summary-read-group-1
3425                                    group show-all no-article
3426                                    kill-buffer no-display
3427                                    select-articles)
3428                                   (setq show-all nil
3429                                         select-articles nil)))))
3430                 (eq gnus-auto-select-next 'quietly))
3431       (set-buffer gnus-group-buffer)
3432       ;; The entry function called above goes to the next
3433       ;; group automatically, so we go two groups back
3434       ;; if we are searching for the previous group.
3435       (when backward
3436         (gnus-group-prev-unread-group 2))
3437       (if (not (equal group (gnus-group-group-name)))
3438           (setq group (gnus-group-group-name))
3439         (setq group nil)))
3440     result))
3441
3442 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3443   "Directly jump to the other GROUP from summary buffer.
3444 If SHOW-ALL is non-nil, already read articles are also listed."
3445   (interactive
3446    (if (eq gnus-summary-buffer (current-buffer))
3447        (list (completing-read
3448               "Group: " gnus-active-hashtb nil t
3449               (when (and gnus-newsgroup-name
3450                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3451                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3452               'gnus-group-history)
3453              current-prefix-arg)
3454      (error "%s must be invoked from a gnus summary buffer." this-command)))
3455   (unless (or (zerop (length group))
3456               (and gnus-newsgroup-name
3457                    (string-equal gnus-newsgroup-name group)))
3458     (gnus-summary-exit)
3459     (gnus-summary-read-group group show-all
3460                              gnus-dont-select-after-jump-to-other-group)))
3461
3462 (defun gnus-summary-read-group-1 (group show-all no-article
3463                                         kill-buffer no-display
3464                                         &optional select-articles)
3465   ;; Killed foreign groups can't be entered.
3466   ;;  (when (and (not (gnus-group-native-p group))
3467   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3468   ;;    (error "Dead non-native groups can't be entered"))
3469   (gnus-message 5 "Retrieving newsgroup: %s..."
3470                 (gnus-group-decoded-name group))
3471   (let* ((new-group (gnus-summary-setup-buffer group))
3472          (quit-config (gnus-group-quit-config group))
3473          (did-select (and new-group (gnus-select-newsgroup
3474                                      group show-all select-articles))))
3475     (cond
3476      ;; This summary buffer exists already, so we just select it.
3477      ((not new-group)
3478       (gnus-set-global-variables)
3479       (when kill-buffer
3480         (gnus-kill-or-deaden-summary kill-buffer))
3481       (gnus-configure-windows 'summary 'force)
3482       (gnus-set-mode-line 'summary)
3483       (gnus-summary-position-point)
3484       (message "")
3485       t)
3486      ;; We couldn't select this group.
3487      ((null did-select)
3488       (when (and (eq major-mode 'gnus-summary-mode)
3489                  (not (equal (current-buffer) kill-buffer)))
3490         (kill-buffer (current-buffer))
3491         (if (not quit-config)
3492             (progn
3493               ;; Update the info -- marks might need to be removed,
3494               ;; for instance.
3495               (gnus-summary-update-info)
3496               (set-buffer gnus-group-buffer)
3497               (gnus-group-jump-to-group group)
3498               (gnus-group-next-unread-group 1))
3499           (gnus-handle-ephemeral-exit quit-config)))
3500       (let ((grpinfo (gnus-get-info group)))
3501         (if (null (gnus-info-read grpinfo))
3502             (gnus-message 3 "Group %s contains no messages"
3503                           (gnus-group-decoded-name group))
3504           (gnus-message 3 "Can't select group")))
3505       nil)
3506      ;; The user did a `C-g' while prompting for number of articles,
3507      ;; so we exit this group.
3508      ((eq did-select 'quit)
3509       (and (eq major-mode 'gnus-summary-mode)
3510            (not (equal (current-buffer) kill-buffer))
3511            (kill-buffer (current-buffer)))
3512       (when kill-buffer
3513         (gnus-kill-or-deaden-summary kill-buffer))
3514       (if (not quit-config)
3515           (progn
3516             (set-buffer gnus-group-buffer)
3517             (gnus-group-jump-to-group group)
3518             (gnus-group-next-unread-group 1)
3519             (gnus-configure-windows 'group 'force))
3520         (gnus-handle-ephemeral-exit quit-config))
3521       ;; Finally signal the quit.
3522       (signal 'quit nil))
3523      ;; The group was successfully selected.
3524      (t
3525       (gnus-set-global-variables)
3526       ;; Save the active value in effect when the group was entered.
3527       (setq gnus-newsgroup-active
3528             (gnus-copy-sequence
3529              (gnus-active gnus-newsgroup-name)))
3530       ;; You can change the summary buffer in some way with this hook.
3531       (gnus-run-hooks 'gnus-select-group-hook)
3532       (gnus-update-format-specifications
3533        nil 'summary 'summary-mode 'summary-dummy)
3534       (gnus-update-summary-mark-positions)
3535       ;; Do score processing.
3536       (when gnus-use-scoring
3537         (gnus-possibly-score-headers))
3538       ;; Check whether to fill in the gaps in the threads.
3539       (when gnus-build-sparse-threads
3540         (gnus-build-sparse-threads))
3541       ;; Find the initial limit.
3542       (if gnus-show-threads
3543           (if show-all
3544               (let ((gnus-newsgroup-dormant nil))
3545                 (gnus-summary-initial-limit show-all))
3546             (gnus-summary-initial-limit show-all))
3547         ;; When unthreaded, all articles are always shown.
3548         (setq gnus-newsgroup-limit
3549               (mapcar
3550                (lambda (header) (mail-header-number header))
3551                gnus-newsgroup-headers)))
3552       ;; Generate the summary buffer.
3553       (unless no-display
3554         (gnus-summary-prepare))
3555       (when gnus-use-trees
3556         (gnus-tree-open group)
3557         (setq gnus-summary-highlight-line-function
3558               'gnus-tree-highlight-article))
3559       ;; If the summary buffer is empty, but there are some low-scored
3560       ;; articles or some excluded dormants, we include these in the
3561       ;; buffer.
3562       (when (and (zerop (buffer-size))
3563                  (not no-display))
3564         (cond (gnus-newsgroup-dormant
3565                (gnus-summary-limit-include-dormant))
3566               ((and gnus-newsgroup-scored show-all)
3567                (gnus-summary-limit-include-expunged t))))
3568       ;; Function `gnus-apply-kill-file' must be called in this hook.
3569       (gnus-run-hooks 'gnus-apply-kill-hook)
3570       (if (and (zerop (buffer-size))
3571                (not no-display))
3572           (progn
3573             ;; This newsgroup is empty.
3574             (gnus-summary-catchup-and-exit nil t)
3575             (gnus-message 6 "No unread news")
3576             (when kill-buffer
3577               (gnus-kill-or-deaden-summary kill-buffer))
3578             ;; Return nil from this function.
3579             nil)
3580         ;; Hide conversation thread subtrees.  We cannot do this in
3581         ;; gnus-summary-prepare-hook since kill processing may not
3582         ;; work with hidden articles.
3583         (gnus-summary-maybe-hide-threads)
3584         (when kill-buffer
3585           (gnus-kill-or-deaden-summary kill-buffer))
3586         (gnus-summary-auto-select-subject)
3587         ;; Show first unread article if requested.
3588         (if (and (not no-article)
3589                  (not no-display)
3590                  gnus-newsgroup-unreads
3591                  gnus-auto-select-first)
3592             (progn
3593               (gnus-configure-windows 'summary)
3594               (let ((art (gnus-summary-article-number)))
3595                 (unless (and (not gnus-plugged)
3596                              (or (memq art gnus-newsgroup-undownloaded)
3597                                  (memq art gnus-newsgroup-downloadable)))
3598                   (gnus-summary-goto-article art))))
3599           ;; Don't select any articles.
3600           (gnus-summary-position-point)
3601           (gnus-configure-windows 'summary 'force)
3602           (gnus-set-mode-line 'summary))
3603         (when (and gnus-auto-center-group
3604                    (get-buffer-window gnus-group-buffer t))
3605           ;; Gotta use windows, because recenter does weird stuff if
3606           ;; the current buffer ain't the displayed window.
3607           (let ((owin (selected-window)))
3608             (select-window (get-buffer-window gnus-group-buffer t))
3609             (when (gnus-group-goto-group group)
3610               (recenter))
3611             (select-window owin)))
3612         ;; Mark this buffer as "prepared".
3613         (setq gnus-newsgroup-prepared t)
3614         (gnus-run-hooks 'gnus-summary-prepared-hook)
3615         (unless (gnus-ephemeral-group-p group)
3616           (gnus-group-update-group group))
3617         t)))))
3618
3619 (defun gnus-summary-auto-select-subject ()
3620   "Select the subject line on initial group entry."
3621   (goto-char (point-min))
3622   (cond
3623    ((eq gnus-auto-select-subject 'best)
3624     (gnus-summary-best-unread-subject))
3625    ((eq gnus-auto-select-subject 'unread)
3626     (gnus-summary-first-unread-subject))
3627    ((eq gnus-auto-select-subject 'unseen)
3628     (gnus-summary-first-unseen-subject))
3629    ((eq gnus-auto-select-subject 'unseen-or-unread)
3630     (gnus-summary-first-unseen-or-unread-subject))
3631    ((eq gnus-auto-select-subject 'first)
3632     ;; Do nothing.
3633     )
3634    ((functionp gnus-auto-select-subject)
3635     (funcall gnus-auto-select-subject))))
3636
3637 (defun gnus-summary-prepare ()
3638   "Generate the summary buffer."
3639   (interactive)
3640   (let ((buffer-read-only nil))
3641     (erase-buffer)
3642     (setq gnus-newsgroup-data nil
3643           gnus-newsgroup-data-reverse nil)
3644     (gnus-run-hooks 'gnus-summary-generate-hook)
3645     ;; Generate the buffer, either with threads or without.
3646     (when gnus-newsgroup-headers
3647       (gnus-summary-prepare-threads
3648        (if gnus-show-threads
3649            (gnus-sort-gathered-threads
3650             (funcall gnus-summary-thread-gathering-function
3651                      (gnus-sort-threads
3652                       (gnus-cut-threads (gnus-make-threads)))))
3653          ;; Unthreaded display.
3654          (gnus-sort-articles gnus-newsgroup-headers))))
3655     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3656     ;; Call hooks for modifying summary buffer.
3657     (goto-char (point-min))
3658     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3659
3660 (defsubst gnus-general-simplify-subject (subject)
3661   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3662   (setq subject
3663         (cond
3664          ;; Truncate the subject.
3665          (gnus-simplify-subject-functions
3666           (gnus-map-function gnus-simplify-subject-functions subject))
3667          ((numberp gnus-summary-gather-subject-limit)
3668           (setq subject (gnus-simplify-subject-re subject))
3669           (if (> (length subject) gnus-summary-gather-subject-limit)
3670               (substring subject 0 gnus-summary-gather-subject-limit)
3671             subject))
3672          ;; Fuzzily simplify it.
3673          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3674           (gnus-simplify-subject-fuzzy subject))
3675          ;; Just remove the leading "Re:".
3676          (t
3677           (gnus-simplify-subject-re subject))))
3678
3679   (if (and gnus-summary-gather-exclude-subject
3680            (string-match gnus-summary-gather-exclude-subject subject))
3681       nil                               ; This article shouldn't be gathered
3682     subject))
3683
3684 (defun gnus-summary-simplify-subject-query ()
3685   "Query where the respool algorithm would put this article."
3686   (interactive)
3687   (gnus-summary-select-article)
3688   (message "%s"
3689            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3690
3691 (defun gnus-gather-threads-by-subject (threads)
3692   "Gather threads by looking at Subject headers."
3693   (if (not gnus-summary-make-false-root)
3694       threads
3695     (let ((hashtb (gnus-make-hashtable 1024))
3696           (prev threads)
3697           (result threads)
3698           subject hthread whole-subject)
3699       (while threads
3700         (setq subject (gnus-general-simplify-subject
3701                        (setq whole-subject (mail-header-subject
3702                                             (caar threads)))))
3703         (when subject
3704           (if (setq hthread (gnus-gethash subject hashtb))
3705               (progn
3706                 ;; We enter a dummy root into the thread, if we
3707                 ;; haven't done that already.
3708                 (unless (stringp (caar hthread))
3709                   (setcar hthread (list whole-subject (car hthread))))
3710                 ;; We add this new gathered thread to this gathered
3711                 ;; thread.
3712                 (setcdr (car hthread)
3713                         (nconc (cdar hthread) (list (car threads))))
3714                 ;; Remove it from the list of threads.
3715                 (setcdr prev (cdr threads))
3716                 (setq threads prev))
3717             ;; Enter this thread into the hash table.
3718             (gnus-sethash subject
3719                           (if gnus-summary-make-false-root-always
3720                               (progn
3721                                 ;; If you want a dummy root above all
3722                                 ;; threads...
3723                                 (setcar threads (list whole-subject
3724                                                       (car threads)))
3725                                 threads)
3726                             threads)
3727                           hashtb)))
3728         (setq prev threads)
3729         (setq threads (cdr threads)))
3730       result)))
3731
3732 (defun gnus-gather-threads-by-references (threads)
3733   "Gather threads by looking at References headers."
3734   (let ((idhashtb (gnus-make-hashtable 1024))
3735         (thhashtb (gnus-make-hashtable 1024))
3736         (prev threads)
3737         (result threads)
3738         ids references id gthread gid entered ref)
3739     (while threads
3740       (when (setq references (mail-header-references (caar threads)))
3741         (setq id (mail-header-id (caar threads))
3742               ids (inline (gnus-split-references references))
3743               entered nil)
3744         (while (setq ref (pop ids))
3745           (setq ids (delete ref ids))
3746           (if (not (setq gid (gnus-gethash ref idhashtb)))
3747               (progn
3748                 (gnus-sethash ref id idhashtb)
3749                 (gnus-sethash id threads thhashtb))
3750             (setq gthread (gnus-gethash gid thhashtb))
3751             (unless entered
3752               ;; We enter a dummy root into the thread, if we
3753               ;; haven't done that already.
3754               (unless (stringp (caar gthread))
3755                 (setcar gthread (list (mail-header-subject (caar gthread))
3756                                       (car gthread))))
3757               ;; We add this new gathered thread to this gathered
3758               ;; thread.
3759               (setcdr (car gthread)
3760                       (nconc (cdar gthread) (list (car threads)))))
3761             ;; Add it into the thread hash table.
3762             (gnus-sethash id gthread thhashtb)
3763             (setq entered t)
3764             ;; Remove it from the list of threads.
3765             (setcdr prev (cdr threads))
3766             (setq threads prev))))
3767       (setq prev threads)
3768       (setq threads (cdr threads)))
3769     result))
3770
3771 (defun gnus-sort-gathered-threads (threads)
3772   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3773   (let ((result threads))
3774     (while threads
3775       (when (stringp (caar threads))
3776         (setcdr (car threads)
3777                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3778       (setq threads (cdr threads)))
3779     result))
3780
3781 (defun gnus-thread-loop-p (root thread)
3782   "Say whether ROOT is in THREAD."
3783   (let ((stack (list thread))
3784         (infloop 0)
3785         th)
3786     (while (setq thread (pop stack))
3787       (setq th (cdr thread))
3788       (while (and th
3789                   (not (eq (caar th) root)))
3790         (pop th))
3791       (if th
3792           ;; We have found a loop.
3793           (let (ref-dep)
3794             (setcdr thread (delq (car th) (cdr thread)))
3795             (if (boundp (setq ref-dep (intern "none"
3796                                               gnus-newsgroup-dependencies)))
3797                 (setcdr (symbol-value ref-dep)
3798                         (nconc (cdr (symbol-value ref-dep))
3799                                (list (car th))))
3800               (set ref-dep (list nil (car th))))
3801             (setq infloop 1
3802                   stack nil))
3803         ;; Push all the subthreads onto the stack.
3804         (push (cdr thread) stack)))
3805     infloop))
3806
3807 (defun gnus-make-threads ()
3808   "Go through the dependency hashtb and find the roots.  Return all threads."
3809   (let (threads)
3810     (while (catch 'infloop
3811              (mapatoms
3812               (lambda (refs)
3813                 ;; Deal with self-referencing References loops.
3814                 (when (and (car (symbol-value refs))
3815                            (not (zerop
3816                                  (apply
3817                                   '+
3818                                   (mapcar
3819                                    (lambda (thread)
3820                                      (gnus-thread-loop-p
3821                                       (car (symbol-value refs)) thread))
3822                                    (cdr (symbol-value refs)))))))
3823                   (setq threads nil)
3824                   (throw 'infloop t))
3825                 (unless (car (symbol-value refs))
3826                   ;; These threads do not refer back to any other articles,
3827                   ;; so they're roots.
3828                   (setq threads (append (cdr (symbol-value refs)) threads))))
3829               gnus-newsgroup-dependencies)))
3830     threads))
3831
3832 ;; Build the thread tree.
3833 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3834   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3835
3836 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3837 if it was already present.
3838
3839 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3840 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3841 Message-IDs will be renamed to a unique Message-ID before being
3842 entered.
3843
3844 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3845   (let* ((id (mail-header-id header))
3846          (id-dep (and id (intern id dependencies)))
3847          parent-id ref ref-dep ref-header replaced)
3848     ;; Enter this `header' in the `dependencies' table.
3849     (cond
3850      ((not id-dep)
3851       (setq header nil))
3852      ;; The first two cases do the normal part: enter a new `header'
3853      ;; in the `dependencies' table.
3854      ((not (boundp id-dep))
3855       (set id-dep (list header)))
3856      ((null (car (symbol-value id-dep)))
3857       (setcar (symbol-value id-dep) header))
3858
3859      ;; From here the `header' was already present in the
3860      ;; `dependencies' table.
3861      (force-new
3862       ;; Overrides an existing entry;
3863       ;; just set the header part of the entry.
3864       (setcar (symbol-value id-dep) header)
3865       (setq replaced t))
3866
3867      ;; Renames the existing `header' to a unique Message-ID.
3868      ((not gnus-summary-ignore-duplicates)
3869       ;; An article with this Message-ID has already been seen.
3870       ;; We rename the Message-ID.
3871       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3872            (list header))
3873       (mail-header-set-id header id))
3874
3875      ;; The last case ignores an existing entry, except it adds any
3876      ;; additional Xrefs (in case the two articles came from different
3877      ;; servers.
3878      ;; Also sets `header' to `nil' meaning that the `dependencies'
3879      ;; table was *not* modified.
3880      (t
3881       (mail-header-set-xref
3882        (car (symbol-value id-dep))
3883        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3884                    "")
3885                (or (mail-header-xref header) "")))
3886       (setq header nil)))
3887
3888     (when (and header (not replaced))
3889       ;; First check that we are not creating a References loop.
3890       (setq parent-id (gnus-parent-id (mail-header-references header)))
3891       (setq ref parent-id)
3892       (while (and ref
3893                   (setq ref-dep (intern-soft ref dependencies))
3894                   (boundp ref-dep)
3895                   (setq ref-header (car (symbol-value ref-dep))))
3896         (if (string= id ref)
3897             ;; Yuk!  This is a reference loop.  Make the article be a
3898             ;; root article.
3899             (progn
3900               (mail-header-set-references (car (symbol-value id-dep)) "none")
3901               (setq ref nil)
3902               (setq parent-id nil))
3903           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3904       (setq ref-dep (intern (or parent-id "none") dependencies))
3905       (if (boundp ref-dep)
3906           (setcdr (symbol-value ref-dep)
3907                   (nconc (cdr (symbol-value ref-dep))
3908                          (list (symbol-value id-dep))))
3909         (set ref-dep (list nil (symbol-value id-dep)))))
3910     header))
3911
3912 (defun gnus-extract-message-id-from-in-reply-to (string)
3913   (if (string-match "<[^>]+>" string)
3914       (substring string (match-beginning 0) (match-end 0))
3915     nil))
3916
3917 (defun gnus-build-sparse-threads ()
3918   (let ((headers gnus-newsgroup-headers)
3919         (mail-parse-charset gnus-newsgroup-charset)
3920         (gnus-summary-ignore-duplicates t)
3921         header references generation relations
3922         subject child end new-child date)
3923     ;; First we create an alist of generations/relations, where
3924     ;; generations is how much we trust the relation, and the relation
3925     ;; is parent/child.
3926     (gnus-message 7 "Making sparse threads...")
3927     (save-excursion
3928       (nnheader-set-temp-buffer " *gnus sparse threads*")
3929       (while (setq header (pop headers))
3930         (when (and (setq references (mail-header-references header))
3931                    (not (string= references "")))
3932           (insert references)
3933           (setq child (mail-header-id header)
3934                 subject (mail-header-subject header)
3935                 date (mail-header-date header)
3936                 generation 0)
3937           (while (search-backward ">" nil t)
3938             (setq end (1+ (point)))
3939             (when (search-backward "<" nil t)
3940               (setq new-child (buffer-substring (point) end))
3941               (push (list (incf generation)
3942                           child (setq child new-child)
3943                           subject date)
3944                     relations)))
3945           (when child
3946             (push (list (1+ generation) child nil subject) relations))
3947           (erase-buffer)))
3948       (kill-buffer (current-buffer)))
3949     ;; Sort over trustworthiness.
3950     (mapcar
3951      (lambda (relation)
3952        (when (gnus-dependencies-add-header
3953               (make-full-mail-header-from-decoded-header
3954                gnus-reffed-article-number
3955                (nth 3 relation) "" (or (nth 4 relation) "")
3956                (nth 1 relation)
3957                (or (nth 2 relation) "") 0 0 "")
3958               gnus-newsgroup-dependencies nil)
3959          (push gnus-reffed-article-number gnus-newsgroup-limit)
3960          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3961          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3962                gnus-newsgroup-reads)
3963          (decf gnus-reffed-article-number)))
3964      (sort relations 'car-less-than-car))
3965     (gnus-message 7 "Making sparse threads...done")))
3966
3967 (defun gnus-build-old-threads ()
3968   ;; Look at all the articles that refer back to old articles, and
3969   ;; fetch the headers for the articles that aren't there.  This will
3970   ;; build complete threads - if the roots haven't been expired by the
3971   ;; server, that is.
3972   (let ((mail-parse-charset gnus-newsgroup-charset)
3973         id heads)
3974     (mapatoms
3975      (lambda (refs)
3976        (when (not (car (symbol-value refs)))
3977          (setq heads (cdr (symbol-value refs)))
3978          (while heads
3979            (if (memq (mail-header-number (caar heads))
3980                      gnus-newsgroup-dormant)
3981                (setq heads (cdr heads))
3982              (setq id (symbol-name refs))
3983              (while (and (setq id (gnus-build-get-header id))
3984                          (not (car (gnus-id-to-thread id)))))
3985              (setq heads nil)))))
3986      gnus-newsgroup-dependencies)))
3987
3988 (defsubst gnus-remove-odd-characters (string)
3989   "Translate STRING into something that doesn't contain weird characters."
3990   (mm-subst-char-in-string
3991    ?\r ?\-
3992    (mm-subst-char-in-string ?\n ?\- string t) t))
3993
3994 ;; This function has to be called with point after the article number
3995 ;; on the beginning of the line.
3996 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3997   (let ((eol (point-at-eol))
3998         (buffer (current-buffer))
3999         header references in-reply-to)
4000
4001     ;; overview: [num subject from date id refs chars lines misc]
4002     (unwind-protect
4003         (progn
4004           (narrow-to-region (point) eol)
4005           (unless (eobp)
4006             (forward-char))
4007
4008           (setq header
4009                 (make-full-mail-header
4010                  number                         ; number
4011                  (nnheader-nov-field)           ; subject
4012                  (nnheader-nov-field)           ; from
4013                  (nnheader-nov-field)           ; date
4014                  (nnheader-nov-read-message-id) ; id
4015                  (nnheader-nov-field)           ; refs
4016                  (nnheader-nov-read-integer)    ; chars
4017                  (nnheader-nov-read-integer)    ; lines
4018                  (unless (eobp)
4019                    (if (looking-at "Xref: ")
4020                        (goto-char (match-end 0)))
4021                    (nnheader-nov-field))        ; Xref
4022                  (nnheader-nov-parse-extra))))  ; extra
4023
4024       (widen))
4025
4026     (when (and (string= references "")
4027                (setq in-reply-to (mail-header-extra header))
4028                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4029       (mail-header-set-references
4030        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4031
4032     (when gnus-alter-header-function
4033       (funcall gnus-alter-header-function header))
4034     (gnus-dependencies-add-header header dependencies force-new)))
4035
4036 (defun gnus-build-get-header (id)
4037   "Look through the buffer of NOV lines and find the header to ID.
4038 Enter this line into the dependencies hash table, and return
4039 the id of the parent article (if any)."
4040   (let ((deps gnus-newsgroup-dependencies)
4041         found header)
4042     (prog1
4043         (save-excursion
4044           (set-buffer nntp-server-buffer)
4045           (let ((case-fold-search nil))
4046             (goto-char (point-min))
4047             (while (and (not found)
4048                         (search-forward id nil t))
4049               (beginning-of-line)
4050               (setq found (looking-at
4051                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4052                                    (regexp-quote id))))
4053               (or found (beginning-of-line 2)))
4054             (when found
4055               (beginning-of-line)
4056               (and
4057                (setq header (gnus-nov-parse-line
4058                              (read (current-buffer)) deps))
4059                (gnus-parent-id (mail-header-references header))))))
4060       (when header
4061         (let ((number (mail-header-number header)))
4062           (push number gnus-newsgroup-limit)
4063           (push header gnus-newsgroup-headers)
4064           (if (memq number gnus-newsgroup-unselected)
4065               (progn
4066                 (setq gnus-newsgroup-unreads
4067                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4068                                                number))
4069                 (setq gnus-newsgroup-unselected
4070                       (delq number gnus-newsgroup-unselected)))
4071             (push number gnus-newsgroup-ancient)))))))
4072
4073 (defun gnus-build-all-threads ()
4074   "Read all the headers."
4075   (let ((gnus-summary-ignore-duplicates t)
4076         (mail-parse-charset gnus-newsgroup-charset)
4077         (dependencies gnus-newsgroup-dependencies)
4078         header article)
4079     (save-excursion
4080       (set-buffer nntp-server-buffer)
4081       (let ((case-fold-search nil))
4082         (goto-char (point-min))
4083         (while (not (eobp))
4084           (ignore-errors
4085             (setq article (read (current-buffer))
4086                   header (gnus-nov-parse-line article dependencies)))
4087           (when header
4088             (save-excursion
4089               (set-buffer gnus-summary-buffer)
4090               (push header gnus-newsgroup-headers)
4091               (if (memq (setq article (mail-header-number header))
4092                         gnus-newsgroup-unselected)
4093                   (progn
4094                     (setq gnus-newsgroup-unreads
4095                           (gnus-add-to-sorted-list
4096                            gnus-newsgroup-unreads article))
4097                     (setq gnus-newsgroup-unselected
4098                           (delq article gnus-newsgroup-unselected)))
4099                 (push article gnus-newsgroup-ancient)))
4100             (forward-line 1)))))))
4101
4102 (defun gnus-summary-update-article-line (article header)
4103   "Update the line for ARTICLE using HEADER."
4104   (let* ((id (mail-header-id header))
4105          (thread (gnus-id-to-thread id)))
4106     (unless thread
4107       (error "Article in no thread"))
4108     ;; Update the thread.
4109     (setcar thread header)
4110     (gnus-summary-goto-subject article)
4111     (let* ((datal (gnus-data-find-list article))
4112            (data (car datal))
4113            (buffer-read-only nil)
4114            (level (gnus-summary-thread-level)))
4115       (gnus-delete-line)
4116       (let ((inserted (- (point)
4117                          (progn
4118                            (gnus-summary-insert-line
4119                             header level nil
4120                             (memq article gnus-newsgroup-undownloaded)
4121                             (gnus-article-mark article)
4122                             (memq article gnus-newsgroup-replied)
4123                             (memq article gnus-newsgroup-expirable)
4124                             ;; Only insert the Subject string when it's different
4125                             ;; from the previous Subject string.
4126                             (if (and
4127                                  gnus-show-threads
4128                                  (gnus-subject-equal
4129                                   (condition-case ()
4130                                       (mail-header-subject
4131                                        (gnus-data-header
4132                                         (cadr
4133                                          (gnus-data-find-list
4134                                           article
4135                                           (gnus-data-list t)))))
4136                                     ;; Error on the side of excessive subjects.
4137                                     (error ""))
4138                                   (mail-header-subject header)))
4139                                 ""
4140                               (mail-header-subject header))
4141                             nil (cdr (assq article gnus-newsgroup-scored))
4142                             (memq article gnus-newsgroup-processable))
4143                            (point)))))
4144         (when (cdr datal)
4145           (gnus-data-update-list
4146            (cdr datal)
4147            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4148
4149 (defun gnus-summary-update-article (article &optional iheader)
4150   "Update ARTICLE in the summary buffer."
4151   (set-buffer gnus-summary-buffer)
4152   (let* ((header (gnus-summary-article-header article))
4153          (id (mail-header-id header))
4154          (data (gnus-data-find article))
4155          (thread (gnus-id-to-thread id))
4156          (references (mail-header-references header))
4157          (parent
4158           (gnus-id-to-thread
4159            (or (gnus-parent-id
4160                 (when (and references
4161                            (not (equal "" references)))
4162                   references))
4163                "none")))
4164          (buffer-read-only nil)
4165          (old (car thread)))
4166     (when thread
4167       (unless iheader
4168         (setcar thread nil)
4169         (when parent
4170           (delq thread parent)))
4171       (if (gnus-summary-insert-subject id header)
4172           ;; Set the (possibly) new article number in the data structure.
4173           (gnus-data-set-number data (gnus-id-to-article id))
4174         (setcar thread old)
4175         nil))))
4176
4177 (defun gnus-rebuild-thread (id &optional line)
4178   "Rebuild the thread containing ID.
4179 If LINE, insert the rebuilt thread starting on line LINE."
4180   (let ((buffer-read-only nil)
4181         old-pos current thread data)
4182     (if (not gnus-show-threads)
4183         (setq thread (list (car (gnus-id-to-thread id))))
4184       ;; Get the thread this article is part of.
4185       (setq thread (gnus-remove-thread id)))
4186     (setq old-pos (point-at-bol))
4187     (setq current (save-excursion
4188                     (and (re-search-backward "[\r\n]" nil t)
4189                          (gnus-summary-article-number))))
4190     ;; If this is a gathered thread, we have to go some re-gathering.
4191     (when (stringp (car thread))
4192       (let ((subject (car thread))
4193             roots thr)
4194         (setq thread (cdr thread))
4195         (while thread
4196           (unless (memq (setq thr (gnus-id-to-thread
4197                                    (gnus-root-id
4198                                     (mail-header-id (caar thread)))))
4199                         roots)
4200             (push thr roots))
4201           (setq thread (cdr thread)))
4202         ;; We now have all (unique) roots.
4203         (if (= (length roots) 1)
4204             ;; All the loose roots are now one solid root.
4205             (setq thread (car roots))
4206           (setq thread (cons subject (gnus-sort-threads roots))))))
4207     (let (threads)
4208       ;; We then insert this thread into the summary buffer.
4209       (when line
4210         (goto-char (point-min))
4211         (forward-line (1- line)))
4212       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4213         (if gnus-show-threads
4214             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4215           (gnus-summary-prepare-unthreaded thread))
4216         (setq data (nreverse gnus-newsgroup-data))
4217         (setq threads gnus-newsgroup-threads))
4218       ;; We splice the new data into the data structure.
4219       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4220       ;;!!! then we want to insert at the beginning of the buffer.
4221       ;;!!! That happens to be true with Gnus now, but that may
4222       ;;!!! change in the future.  Perhaps.
4223       (gnus-data-enter-list
4224        (if line nil current) data (- (point) old-pos))
4225       (setq gnus-newsgroup-threads
4226             (nconc threads gnus-newsgroup-threads))
4227       (gnus-data-compute-positions))))
4228
4229 (defun gnus-number-to-header (number)
4230   "Return the header for article NUMBER."
4231   (let ((headers gnus-newsgroup-headers))
4232     (while (and headers
4233                 (not (= number (mail-header-number (car headers)))))
4234       (pop headers))
4235     (when headers
4236       (car headers))))
4237
4238 (defun gnus-parent-headers (in-headers &optional generation)
4239   "Return the headers of the GENERATIONeth parent of HEADERS."
4240   (unless generation
4241     (setq generation 1))
4242   (let ((parent t)
4243         (headers in-headers)
4244         references)
4245     (while (and parent
4246                 (not (zerop generation))
4247                 (setq references (mail-header-references headers)))
4248       (setq headers (if (and references
4249                              (setq parent (gnus-parent-id references)))
4250                         (car (gnus-id-to-thread parent))
4251                       nil))
4252       (decf generation))
4253     (and (not (eq headers in-headers))
4254          headers)))
4255
4256 (defun gnus-id-to-thread (id)
4257   "Return the (sub-)thread where ID appears."
4258   (gnus-gethash id gnus-newsgroup-dependencies))
4259
4260 (defun gnus-id-to-article (id)
4261   "Return the article number of ID."
4262   (let ((thread (gnus-id-to-thread id)))
4263     (when (and thread
4264                (car thread))
4265       (mail-header-number (car thread)))))
4266
4267 (defun gnus-id-to-header (id)
4268   "Return the article headers of ID."
4269   (car (gnus-id-to-thread id)))
4270
4271 (defun gnus-article-displayed-root-p (article)
4272   "Say whether ARTICLE is a root(ish) article."
4273   (let ((level (gnus-summary-thread-level article))
4274         (refs (mail-header-references  (gnus-summary-article-header article)))
4275         particle)
4276     (cond
4277      ((null level) nil)
4278      ((zerop level) t)
4279      ((null refs) t)
4280      ((null (gnus-parent-id refs)) t)
4281      ((and (= 1 level)
4282            (null (setq particle (gnus-id-to-article
4283                                  (gnus-parent-id refs))))
4284            (null (gnus-summary-thread-level particle)))))))
4285
4286 (defun gnus-root-id (id)
4287   "Return the id of the root of the thread where ID appears."
4288   (let (last-id prev)
4289     (while (and id (setq prev (car (gnus-id-to-thread id))))
4290       (setq last-id id
4291             id (gnus-parent-id (mail-header-references prev))))
4292     last-id))
4293
4294 (defun gnus-articles-in-thread (thread)
4295   "Return the list of articles in THREAD."
4296   (cons (mail-header-number (car thread))
4297         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4298
4299 (defun gnus-remove-thread (id &optional dont-remove)
4300   "Remove the thread that has ID in it."
4301   (let (headers thread last-id)
4302     ;; First go up in this thread until we find the root.
4303     (setq last-id (gnus-root-id id)
4304           headers (message-flatten-list (gnus-id-to-thread last-id)))
4305     ;; We have now found the real root of this thread.  It might have
4306     ;; been gathered into some loose thread, so we have to search
4307     ;; through the threads to find the thread we wanted.
4308     (let ((threads gnus-newsgroup-threads)
4309           sub)
4310       (while threads
4311         (setq sub (car threads))
4312         (if (stringp (car sub))
4313             ;; This is a gathered thread, so we look at the roots
4314             ;; below it to find whether this article is in this
4315             ;; gathered root.
4316             (progn
4317               (setq sub (cdr sub))
4318               (while sub
4319                 (when (member (caar sub) headers)
4320                   (setq thread (car threads)
4321                         threads nil
4322                         sub nil))
4323                 (setq sub (cdr sub))))
4324           ;; It's an ordinary thread, so we check it.
4325           (when (eq (car sub) (car headers))
4326             (setq thread sub
4327                   threads nil)))
4328         (setq threads (cdr threads)))
4329       ;; If this article is in no thread, then it's a root.
4330       (if thread
4331           (unless dont-remove
4332             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4333         (setq thread (gnus-id-to-thread last-id)))
4334       (when thread
4335         (prog1
4336             thread                      ; We return this thread.
4337           (unless dont-remove
4338             (if (stringp (car thread))
4339                 (progn
4340                   ;; If we use dummy roots, then we have to remove the
4341                   ;; dummy root as well.
4342                   (when (eq gnus-summary-make-false-root 'dummy)
4343                     ;; We go to the dummy root by going to
4344                     ;; the first sub-"thread", and then one line up.
4345                     (gnus-summary-goto-article
4346                      (mail-header-number (caadr thread)))
4347                     (forward-line -1)
4348                     (gnus-delete-line)
4349                     (gnus-data-compute-positions))
4350                   (setq thread (cdr thread))
4351                   (while thread
4352                     (gnus-remove-thread-1 (car thread))
4353                     (setq thread (cdr thread))))
4354               (gnus-remove-thread-1 thread))))))))
4355
4356 (defun gnus-remove-thread-1 (thread)
4357   "Remove the thread THREAD recursively."
4358   (let ((number (mail-header-number (pop thread)))
4359         d)
4360     (setq thread (reverse thread))
4361     (while thread
4362       (gnus-remove-thread-1 (pop thread)))
4363     (when (setq d (gnus-data-find number))
4364       (goto-char (gnus-data-pos d))
4365       (gnus-summary-show-thread)
4366       (gnus-data-remove
4367        number
4368        (- (point-at-bol)
4369           (prog1
4370               (1+ (point-at-eol))
4371             (gnus-delete-line)))))))
4372
4373 (defun gnus-sort-threads-1 (threads func)
4374   (sort (mapcar (lambda (thread)
4375                   (cons (car thread)
4376                         (and (cdr thread)
4377                              (gnus-sort-threads-1 (cdr thread) func))))
4378                 threads) func))
4379
4380 (defun gnus-sort-threads (threads)
4381   "Sort THREADS."
4382   (if (not gnus-thread-sort-functions)
4383       threads
4384     (gnus-message 8 "Sorting threads...")
4385     (let ((max-lisp-eval-depth 5000))
4386       (prog1 (gnus-sort-threads-1
4387          threads
4388          (gnus-make-sort-function gnus-thread-sort-functions))
4389         (gnus-message 8 "Sorting threads...done")))))
4390
4391 (defun gnus-sort-articles (articles)
4392   "Sort ARTICLES."
4393   (when gnus-article-sort-functions
4394     (gnus-message 7 "Sorting articles...")
4395     (prog1
4396         (setq gnus-newsgroup-headers
4397               (sort articles (gnus-make-sort-function
4398                               gnus-article-sort-functions)))
4399       (gnus-message 7 "Sorting articles...done"))))
4400
4401 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4402 (defmacro gnus-thread-header (thread)
4403   "Return header of first article in THREAD.
4404 Note that THREAD must never, ever be anything else than a variable -
4405 using some other form will lead to serious barfage."
4406   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4407   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4408   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4409         (vector thread) 2))
4410
4411 (defsubst gnus-article-sort-by-number (h1 h2)
4412   "Sort articles by article number."
4413   (< (mail-header-number h1)
4414      (mail-header-number h2)))
4415
4416 (defun gnus-thread-sort-by-number (h1 h2)
4417   "Sort threads by root article number."
4418   (gnus-article-sort-by-number
4419    (gnus-thread-header h1) (gnus-thread-header h2)))
4420
4421 (defsubst gnus-article-sort-by-random (h1 h2)
4422   "Sort articles by article number."
4423   (zerop (random 2)))
4424
4425 (defun gnus-thread-sort-by-random (h1 h2)
4426   "Sort threads by root article number."
4427   (gnus-article-sort-by-random
4428    (gnus-thread-header h1) (gnus-thread-header h2)))
4429
4430 (defsubst gnus-article-sort-by-lines (h1 h2)
4431   "Sort articles by article Lines header."
4432   (< (mail-header-lines h1)
4433      (mail-header-lines h2)))
4434
4435 (defun gnus-thread-sort-by-lines (h1 h2)
4436   "Sort threads by root article Lines header."
4437   (gnus-article-sort-by-lines
4438    (gnus-thread-header h1) (gnus-thread-header h2)))
4439
4440 (defsubst gnus-article-sort-by-chars (h1 h2)
4441   "Sort articles by octet length."
4442   (< (mail-header-chars h1)
4443      (mail-header-chars h2)))
4444
4445 (defun gnus-thread-sort-by-chars (h1 h2)
4446   "Sort threads by root article octet length."
4447   (gnus-article-sort-by-chars
4448    (gnus-thread-header h1) (gnus-thread-header h2)))
4449
4450 (defsubst gnus-article-sort-by-author (h1 h2)
4451   "Sort articles by root author."
4452   (string-lessp
4453    (let ((addr (car (mime-entity-read-field h1 'From))))
4454      (or (std11-full-name-string addr)
4455          (std11-address-string addr)
4456          ""))
4457    (let ((addr (car (mime-entity-read-field h2 'From))))
4458      (or (std11-full-name-string addr)
4459          (std11-address-string addr)
4460          ""))
4461    ))
4462
4463 (defun gnus-thread-sort-by-author (h1 h2)
4464   "Sort threads by root author."
4465   (gnus-article-sort-by-author
4466    (gnus-thread-header h1)  (gnus-thread-header h2)))
4467
4468 (defsubst gnus-article-sort-by-subject (h1 h2)
4469   "Sort articles by root subject."
4470   (string-lessp
4471    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4472    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4473
4474 (defun gnus-thread-sort-by-subject (h1 h2)
4475   "Sort threads by root subject."
4476   (gnus-article-sort-by-subject
4477    (gnus-thread-header h1) (gnus-thread-header h2)))
4478
4479 (defsubst gnus-article-sort-by-date (h1 h2)
4480   "Sort articles by root article date."
4481   (time-less-p
4482    (gnus-date-get-time (mail-header-date h1))
4483    (gnus-date-get-time (mail-header-date h2))))
4484
4485 (defun gnus-thread-sort-by-date (h1 h2)
4486   "Sort threads by root article date."
4487   (gnus-article-sort-by-date
4488    (gnus-thread-header h1) (gnus-thread-header h2)))
4489
4490 (defsubst gnus-article-sort-by-score (h1 h2)
4491   "Sort articles by root article score.
4492 Unscored articles will be counted as having a score of zero."
4493   (> (or (cdr (assq (mail-header-number h1)
4494                     gnus-newsgroup-scored))
4495          gnus-summary-default-score 0)
4496      (or (cdr (assq (mail-header-number h2)
4497                     gnus-newsgroup-scored))
4498          gnus-summary-default-score 0)))
4499
4500 (defun gnus-thread-sort-by-score (h1 h2)
4501   "Sort threads by root article score."
4502   (gnus-article-sort-by-score
4503    (gnus-thread-header h1) (gnus-thread-header h2)))
4504
4505 (defun gnus-thread-sort-by-total-score (h1 h2)
4506   "Sort threads by the sum of all scores in the thread.
4507 Unscored articles will be counted as having a score of zero."
4508   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4509
4510 (defun gnus-thread-total-score (thread)
4511   ;; This function find the total score of THREAD.
4512   (cond
4513    ((null thread)
4514     0)
4515    ((consp thread)
4516     (if (stringp (car thread))
4517         (apply gnus-thread-score-function 0
4518                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4519       (gnus-thread-total-score-1 thread)))
4520    (t
4521     (gnus-thread-total-score-1 (list thread)))))
4522
4523 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4524   "Sort threads such that the thread with the most recently arrived article comes first."
4525   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4526
4527 (defun gnus-thread-highest-number (thread)
4528   "Return the highest article number in THREAD."
4529   (apply 'max (mapcar (lambda (header)
4530                         (mail-header-number header))
4531                       (message-flatten-list thread))))
4532
4533 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4534   "Sort threads such that the thread with the most recently dated article comes first."
4535   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4536
4537 (defun gnus-thread-latest-date (thread)
4538   "Return the highest article date in THREAD."
4539   (let ((previous-time 0))
4540     (apply 'max
4541            (mapcar
4542             (lambda (header)
4543               (setq previous-time
4544                     (condition-case ()
4545                         (time-to-seconds (mail-header-parse-date
4546                                           (mail-header-date header)))
4547                       (error previous-time))))
4548             (sort
4549              (message-flatten-list thread)
4550              (lambda (h1 h2)
4551                (< (mail-header-number h1)
4552                   (mail-header-number h2))))))))
4553
4554 (defun gnus-thread-total-score-1 (root)
4555   ;; This function find the total score of the thread below ROOT.
4556   (setq root (car root))
4557   (apply gnus-thread-score-function
4558          (or (append
4559               (mapcar 'gnus-thread-total-score
4560                       (cdr (gnus-id-to-thread (mail-header-id root))))
4561               (when (> (mail-header-number root) 0)
4562                 (list (or (cdr (assq (mail-header-number root)
4563                                      gnus-newsgroup-scored))
4564                           gnus-summary-default-score 0))))
4565              (list gnus-summary-default-score)
4566              '(0))))
4567
4568 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4569 (defvar gnus-tmp-prev-subject nil)
4570 (defvar gnus-tmp-false-parent nil)
4571 (defvar gnus-tmp-root-expunged nil)
4572 (defvar gnus-tmp-dummy-line nil)
4573
4574 (eval-when-compile (defvar gnus-tmp-header))
4575 (defun gnus-extra-header (type &optional header)
4576   "Return the extra header of TYPE."
4577   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4578       ""))
4579
4580 (defvar gnus-tmp-thread-tree-header-string "")
4581
4582 (defcustom gnus-sum-thread-tree-root "> "
4583   "With %B spec, used for the root of a thread.
4584 If nil, use subject instead."
4585   :type '(radio (const :format "%v  " nil) (string :size 0))
4586   :group 'gnus-thread)
4587 (defcustom gnus-sum-thread-tree-false-root "> "
4588   "With %B spec, used for a false root of a thread.
4589 If nil, use subject instead."
4590   :type '(radio (const :format "%v  " nil) (string :size 0))
4591   :group 'gnus-thread)
4592 (defcustom gnus-sum-thread-tree-single-indent ""
4593   "With %B spec, used for a thread with just one message.
4594 If nil, use subject instead."
4595   :type '(radio (const :format "%v  " nil) (string :size 0))
4596   :group 'gnus-thread)
4597 (defcustom gnus-sum-thread-tree-vertical "| "
4598   "With %B spec, used for drawing a vertical line."
4599   :type 'string
4600   :group 'gnus-thread)
4601 (defcustom gnus-sum-thread-tree-indent "  "
4602   "With %B spec, used for indenting."
4603   :type 'string
4604   :group 'gnus-thread)
4605 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4606   "With %B spec, used for a leaf with brothers."
4607   :type 'string
4608   :group 'gnus-thread)
4609 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4610   "With %B spec, used for a leaf without brothers."
4611   :type 'string
4612   :group 'gnus-thread)
4613
4614 (defun gnus-summary-prepare-threads (threads)
4615   "Prepare summary buffer from THREADS and indentation LEVEL.
4616 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4617 or a straight list of headers."
4618   (gnus-message 7 "Generating summary...")
4619
4620   (setq gnus-newsgroup-threads threads)
4621   (beginning-of-line)
4622
4623   (let ((gnus-tmp-level 0)
4624         (default-score (or gnus-summary-default-score 0))
4625         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4626         (building-line-count gnus-summary-display-while-building)
4627         (building-count (integerp gnus-summary-display-while-building))
4628         thread number subject stack state gnus-tmp-gathered beg-match
4629         new-roots gnus-tmp-new-adopts thread-end simp-subject
4630         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4631         gnus-tmp-replied gnus-tmp-subject-or-nil
4632         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4633         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4634         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4635         tree-stack)
4636
4637     (setq gnus-tmp-prev-subject nil
4638           gnus-tmp-thread-tree-header-string "")
4639
4640     (if (vectorp (car threads))
4641         ;; If this is a straight (sic) list of headers, then a
4642         ;; threaded summary display isn't required, so we just create
4643         ;; an unthreaded one.
4644         (gnus-summary-prepare-unthreaded threads)
4645
4646       ;; Do the threaded display.
4647
4648       (if gnus-summary-display-while-building
4649           (switch-to-buffer (buffer-name)))
4650       (while (or threads stack gnus-tmp-new-adopts new-roots)
4651
4652         (if (and (= gnus-tmp-level 0)
4653                  (or (not stack)
4654                      (= (caar stack) 0))
4655                  (not gnus-tmp-false-parent)
4656                  (or gnus-tmp-new-adopts new-roots))
4657             (if gnus-tmp-new-adopts
4658                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4659                       thread (list (car gnus-tmp-new-adopts))
4660                       gnus-tmp-header (caar thread)
4661                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4662               (when new-roots
4663                 (setq thread (list (car new-roots))
4664                       gnus-tmp-header (caar thread)
4665                       new-roots (cdr new-roots))))
4666
4667           (if threads
4668               ;; If there are some threads, we do them before the
4669               ;; threads on the stack.
4670               (setq thread threads
4671                     gnus-tmp-header (caar thread))
4672             ;; There were no current threads, so we pop something off
4673             ;; the stack.
4674             (setq state (car stack)
4675                   gnus-tmp-level (car state)
4676                   tree-stack (cadr state)
4677                   thread (caddr state)
4678                   stack (cdr stack)
4679                   gnus-tmp-header (caar thread))))
4680
4681         (setq gnus-tmp-false-parent nil)
4682         (setq gnus-tmp-root-expunged nil)
4683         (setq thread-end nil)
4684
4685         (if (stringp gnus-tmp-header)
4686             ;; The header is a dummy root.
4687             (cond
4688              ((eq gnus-summary-make-false-root 'adopt)
4689               ;; We let the first article adopt the rest.
4690               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4691                                                (cddar thread)))
4692               (setq gnus-tmp-gathered
4693                     (nconc (mapcar
4694                             (lambda (h) (mail-header-number (car h)))
4695                             (cddar thread))
4696                            gnus-tmp-gathered))
4697               (setq thread (cons (list (caar thread)
4698                                        (cadar thread))
4699                                  (cdr thread)))
4700               (setq gnus-tmp-level -1
4701                     gnus-tmp-false-parent t))
4702              ((eq gnus-summary-make-false-root 'empty)
4703               ;; We print adopted articles with empty subject fields.
4704               (setq gnus-tmp-gathered
4705                     (nconc (mapcar
4706                             (lambda (h) (mail-header-number (car h)))
4707                             (cddar thread))
4708                            gnus-tmp-gathered))
4709               (setq gnus-tmp-level -1))
4710              ((eq gnus-summary-make-false-root 'dummy)
4711               ;; We remember that we probably want to output a dummy
4712               ;; root.
4713               (setq gnus-tmp-dummy-line gnus-tmp-header)
4714               (setq gnus-tmp-prev-subject gnus-tmp-header))
4715              (t
4716               ;; We do not make a root for the gathered
4717               ;; sub-threads at all.
4718               (setq gnus-tmp-level -1)))
4719
4720           (setq number (mail-header-number gnus-tmp-header)
4721                 subject (mail-header-subject gnus-tmp-header)
4722                 simp-subject (gnus-simplify-subject-fully subject))
4723
4724           (cond
4725            ;; If the thread has changed subject, we might want to make
4726            ;; this subthread into a root.
4727            ((and (null gnus-thread-ignore-subject)
4728                  (not (zerop gnus-tmp-level))
4729                  gnus-tmp-prev-subject
4730                  (not (string= gnus-tmp-prev-subject simp-subject)))
4731             (setq new-roots (nconc new-roots (list (car thread)))
4732                   thread-end t
4733                   gnus-tmp-header nil))
4734            ;; If the article lies outside the current limit,
4735            ;; then we do not display it.
4736            ((not (memq number gnus-newsgroup-limit))
4737             (setq gnus-tmp-gathered
4738                   (nconc (mapcar
4739                           (lambda (h) (mail-header-number (car h)))
4740                           (cdar thread))
4741                          gnus-tmp-gathered))
4742             (setq gnus-tmp-new-adopts (if (cdar thread)
4743                                           (append gnus-tmp-new-adopts
4744                                                   (cdar thread))
4745                                         gnus-tmp-new-adopts)
4746                   thread-end t
4747                   gnus-tmp-header nil)
4748             (when (zerop gnus-tmp-level)
4749               (setq gnus-tmp-root-expunged t)))
4750            ;; Perhaps this article is to be marked as read?
4751            ((and gnus-summary-mark-below
4752                  (< (or (cdr (assq number gnus-newsgroup-scored))
4753                         default-score)
4754                     gnus-summary-mark-below)
4755                  ;; Don't touch sparse articles.
4756                  (not (gnus-summary-article-sparse-p number))
4757                  (not (gnus-summary-article-ancient-p number)))
4758             (setq gnus-newsgroup-unreads
4759                   (delq number gnus-newsgroup-unreads))
4760             (if gnus-newsgroup-auto-expire
4761                 (setq gnus-newsgroup-expirable
4762                       (gnus-add-to-sorted-list
4763                        gnus-newsgroup-expirable number))
4764               (push (cons number gnus-low-score-mark)
4765                     gnus-newsgroup-reads))))
4766
4767           (when gnus-tmp-header
4768             ;; We may have an old dummy line to output before this
4769             ;; article.
4770             (when (and gnus-tmp-dummy-line
4771                        (gnus-subject-equal
4772                         gnus-tmp-dummy-line
4773                         (mail-header-subject gnus-tmp-header)))
4774               (gnus-summary-insert-dummy-line
4775                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4776               (setq gnus-tmp-dummy-line nil))
4777
4778             ;; Compute the mark.
4779             (setq gnus-tmp-unread (gnus-article-mark number))
4780
4781             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4782                                   gnus-tmp-header gnus-tmp-level)
4783                   gnus-newsgroup-data)
4784
4785             ;; Actually insert the line.
4786             (setq
4787              gnus-tmp-subject-or-nil
4788              (cond
4789               ((and gnus-thread-ignore-subject
4790                     gnus-tmp-prev-subject
4791                     (not (string= gnus-tmp-prev-subject simp-subject)))
4792                subject)
4793               ((zerop gnus-tmp-level)
4794                (if (and (eq gnus-summary-make-false-root 'empty)
4795                         (memq number gnus-tmp-gathered)
4796                         gnus-tmp-prev-subject
4797                         (string= gnus-tmp-prev-subject simp-subject))
4798                    gnus-summary-same-subject
4799                  subject))
4800               (t gnus-summary-same-subject)))
4801             (if (and (eq gnus-summary-make-false-root 'adopt)
4802                      (= gnus-tmp-level 1)
4803                      (memq number gnus-tmp-gathered))
4804                 (setq gnus-tmp-opening-bracket ?\<
4805                       gnus-tmp-closing-bracket ?\>)
4806               (setq gnus-tmp-opening-bracket ?\[
4807                     gnus-tmp-closing-bracket ?\]))
4808             (setq
4809              gnus-tmp-indentation
4810              (aref gnus-thread-indent-array gnus-tmp-level)
4811              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4812              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4813                                 gnus-summary-default-score 0)
4814              gnus-tmp-score-char
4815              (if (or (null gnus-summary-default-score)
4816                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4817                          gnus-summary-zcore-fuzz))
4818                  ?\ ;;;Whitespace
4819                (if (< gnus-tmp-score gnus-summary-default-score)
4820                    gnus-score-below-mark gnus-score-over-mark))
4821              gnus-tmp-replied
4822              (cond ((memq number gnus-newsgroup-processable)
4823                     gnus-process-mark)
4824                    ((memq number gnus-newsgroup-cached)
4825                     gnus-cached-mark)
4826                    ((memq number gnus-newsgroup-replied)
4827                     gnus-replied-mark)
4828                    ((memq number gnus-newsgroup-forwarded)
4829                     gnus-forwarded-mark)
4830                    ((memq number gnus-newsgroup-saved)
4831                     gnus-saved-mark)
4832                    ((memq number gnus-newsgroup-recent)
4833                     gnus-recent-mark)
4834                    ((memq number gnus-newsgroup-unseen)
4835                     gnus-unseen-mark)
4836                    (t gnus-no-mark))
4837              gnus-tmp-downloaded
4838              (cond ((memq number gnus-newsgroup-undownloaded)
4839                     gnus-undownloaded-mark)
4840                    (gnus-newsgroup-agentized
4841                     gnus-downloaded-mark)
4842                    (t
4843                     gnus-no-mark))
4844              gnus-tmp-from (mail-header-from gnus-tmp-header)
4845              gnus-tmp-name
4846              (cond
4847               ((string-match "<[^>]+> *$" gnus-tmp-from)
4848                (setq beg-match (match-beginning 0))
4849                (or (and (string-match "^\".+\"" gnus-tmp-from)
4850                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4851                    (substring gnus-tmp-from 0 beg-match)))
4852               ((string-match "(.+)" gnus-tmp-from)
4853                (substring gnus-tmp-from
4854                           (1+ (match-beginning 0)) (1- (match-end 0))))
4855               (t gnus-tmp-from))
4856
4857              ;; Do the %B string
4858              gnus-tmp-thread-tree-header-string
4859              (cond
4860               ((not gnus-show-threads) "")
4861               ((zerop gnus-tmp-level)
4862                (cond ((cdar thread)
4863                       (or gnus-sum-thread-tree-root subject))
4864                      (gnus-tmp-new-adopts
4865                       (or gnus-sum-thread-tree-false-root subject))
4866                      (t
4867                       (or gnus-sum-thread-tree-single-indent subject))))
4868               (t
4869                (concat (apply 'concat
4870                               (mapcar (lambda (item)
4871                                         (if (= item 1)
4872                                             gnus-sum-thread-tree-vertical
4873                                           gnus-sum-thread-tree-indent))
4874                                       (cdr (reverse tree-stack))))
4875                        (if (nth 1 thread)
4876                            gnus-sum-thread-tree-leaf-with-other
4877                          gnus-sum-thread-tree-single-leaf)))))
4878             (when (string= gnus-tmp-name "")
4879               (setq gnus-tmp-name gnus-tmp-from))
4880             (unless (numberp gnus-tmp-lines)
4881               (setq gnus-tmp-lines -1))
4882             (if (= gnus-tmp-lines -1)
4883                 (setq gnus-tmp-lines "?")
4884               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4885               (gnus-put-text-property
4886              (point)
4887              (progn (eval gnus-summary-line-format-spec) (point))
4888                'gnus-number number)
4889             (when gnus-visual-p
4890               (forward-line -1)
4891               (gnus-run-hooks 'gnus-summary-update-hook)
4892               (forward-line 1))
4893
4894             (setq gnus-tmp-prev-subject simp-subject)))
4895
4896         (when (nth 1 thread)
4897           (push (list (max 0 gnus-tmp-level)
4898                       (copy-sequence tree-stack)
4899                       (nthcdr 1 thread))
4900                 stack))
4901         (push (if (nth 1 thread) 1 0) tree-stack)
4902         (incf gnus-tmp-level)
4903         (setq threads (if thread-end nil (cdar thread)))
4904         (if gnus-summary-display-while-building
4905             (if building-count
4906                 (progn
4907                   ;; use a set frequency
4908                   (setq building-line-count (1- building-line-count))
4909                   (when (= building-line-count 0)
4910                     (sit-for 0)
4911                     (setq building-line-count
4912                           gnus-summary-display-while-building)))
4913               ;; always
4914               (sit-for 0)))
4915         (unless threads
4916           (setq gnus-tmp-level 0)))))
4917   (gnus-message 7 "Generating summary...done"))
4918
4919 (defun gnus-summary-prepare-unthreaded (headers)
4920   "Generate an unthreaded summary buffer based on HEADERS."
4921   (let (header number mark)
4922
4923     (beginning-of-line)
4924
4925     (while headers
4926       ;; We may have to root out some bad articles...
4927       (when (memq (setq number (mail-header-number
4928                                 (setq header (pop headers))))
4929                   gnus-newsgroup-limit)
4930         ;; Mark article as read when it has a low score.
4931         (when (and gnus-summary-mark-below
4932                    (< (or (cdr (assq number gnus-newsgroup-scored))
4933                           gnus-summary-default-score 0)
4934                       gnus-summary-mark-below)
4935                    (not (gnus-summary-article-ancient-p number)))
4936           (setq gnus-newsgroup-unreads
4937                 (delq number gnus-newsgroup-unreads))
4938           (if gnus-newsgroup-auto-expire
4939               (push number gnus-newsgroup-expirable)
4940             (push (cons number gnus-low-score-mark)
4941                   gnus-newsgroup-reads)))
4942
4943         (setq mark (gnus-article-mark number))
4944         (push (gnus-data-make number mark (1+ (point)) header 0)
4945               gnus-newsgroup-data)
4946         (gnus-summary-insert-line
4947          header 0 number
4948          (memq number gnus-newsgroup-undownloaded)
4949          mark (memq number gnus-newsgroup-replied)
4950          (memq number gnus-newsgroup-expirable)
4951          (mail-header-subject header) nil
4952          (cdr (assq number gnus-newsgroup-scored))
4953          (memq number gnus-newsgroup-processable))))))
4954
4955 (defun gnus-summary-remove-list-identifiers ()
4956   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4957   (let ((regexp (if (consp gnus-list-identifiers)
4958                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4959                   gnus-list-identifiers))
4960         changed subject)
4961     (when regexp
4962       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
4963       (dolist (header gnus-newsgroup-headers)
4964         (setq subject (mail-header-subject header)
4965               changed nil)
4966         (while (string-match regexp subject)
4967           (setq subject
4968                 (concat (substring subject 0 (match-beginning 1))
4969                         (substring subject (match-end 0)))
4970                 changed t))
4971         (when changed
4972           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
4973             (setq subject
4974                   (concat (substring subject 0 (match-beginning 1))
4975                           (substring subject (match-end 1)))))
4976           (mail-header-set-subject header subject))))))
4977
4978 (defun gnus-fetch-headers (articles)
4979   "Fetch headers of ARTICLES."
4980   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4981     (gnus-message 5 "Fetching headers for %s..." name)
4982     (prog1
4983         (if (eq 'nov
4984                 (setq gnus-headers-retrieved-by
4985                       (gnus-retrieve-headers
4986                        articles gnus-newsgroup-name
4987                        ;; We might want to fetch old headers, but
4988                        ;; not if there is only 1 article.
4989                        (and (or (and
4990                                  (not (eq gnus-fetch-old-headers 'some))
4991                                  (not (numberp gnus-fetch-old-headers)))
4992                                 (> (length articles) 1))
4993                             gnus-fetch-old-headers))))
4994             (gnus-get-newsgroup-headers-xover
4995              articles nil nil gnus-newsgroup-name t)
4996           (gnus-get-newsgroup-headers))
4997       (gnus-message 5 "Fetching headers for %s...done" name))))
4998
4999 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5000   "Select newsgroup GROUP.
5001 If READ-ALL is non-nil, all articles in the group are selected.
5002 If SELECT-ARTICLES, only select those articles from GROUP."
5003   (let* ((entry (gnus-group-entry group))
5004          ;;!!! Dirty hack; should be removed.
5005          (gnus-summary-ignore-duplicates
5006           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5007               t
5008             gnus-summary-ignore-duplicates))
5009          (info (nth 2 entry))
5010          articles fetched-articles cached)
5011
5012     (unless (gnus-check-server
5013              (set (make-local-variable 'gnus-current-select-method)
5014                   (gnus-find-method-for-group group)))
5015       (error "Couldn't open server"))
5016
5017     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5018         (gnus-activate-group group)     ; Or we can activate it...
5019         (progn                          ; Or we bug out.
5020           (when (equal major-mode 'gnus-summary-mode)
5021             (gnus-kill-buffer (current-buffer)))
5022           (error "Couldn't activate group %s: %s"
5023                  group (gnus-status-message group))))
5024
5025     (unless (gnus-request-group group t)
5026       (when (equal major-mode 'gnus-summary-mode)
5027         (gnus-kill-buffer (current-buffer)))
5028       (error "Couldn't request group %s: %s"
5029              group (gnus-status-message group)))
5030
5031     (when gnus-agent
5032       ;; The agent may be storing articles that are no longer in the
5033       ;; server's active range.  If that is the case, the active range
5034       ;; needs to be expanded such that the agent's articles can be
5035       ;; included in the summary.
5036       (let* ((gnus-command-method (gnus-find-method-for-group group))
5037              (alist (gnus-agent-load-alist group))
5038              (active (gnus-active group)))
5039         (if (and (car alist)
5040                  (< (caar alist) (car active)))
5041             (gnus-set-active group (cons (caar alist) (cdr active)))))
5042
5043       (setq gnus-summary-use-undownloaded-faces
5044             (gnus-agent-find-parameter
5045              group
5046              'agent-enable-undownloaded-faces)))
5047
5048     (setq gnus-newsgroup-name group
5049           gnus-newsgroup-unselected nil
5050           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5051
5052     (let ((display (gnus-group-find-parameter group 'display)))
5053       (setq gnus-newsgroup-display
5054             (cond
5055              ((not (zerop (or (car-safe read-all) 0)))
5056               ;; The user entered the group with C-u SPC/RET, let's show
5057               ;; all articles.
5058               'gnus-not-ignore)
5059              ((eq display 'all)
5060               'gnus-not-ignore)
5061              ((arrayp display)
5062               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5063              ((numberp display)
5064               ;; The following is probably the "correct" solution, but
5065               ;; it makes Gnus fetch all headers and then limit the
5066               ;; articles (which is slow), so instead we hack the
5067               ;; select-articles parameter instead. -- Simon Josefsson
5068               ;; <jas@kth.se>
5069               ;;
5070               ;; (gnus-byte-compile
5071               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5072               ;;                         display)))))
5073               (setq select-articles
5074                     (gnus-uncompress-range
5075                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5076                              (if (> tmp 0)
5077                                  tmp
5078                                1))
5079                            (cdr (gnus-active group)))))
5080               nil)
5081              (t
5082               nil))))
5083
5084     (gnus-summary-setup-default-charset)
5085
5086     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5087     (when (gnus-virtual-group-p group)
5088       (setq cached gnus-newsgroup-cached))
5089
5090     (setq gnus-newsgroup-unreads
5091           (gnus-sorted-ndifference
5092            (gnus-sorted-ndifference gnus-newsgroup-unreads
5093                                     gnus-newsgroup-marked)
5094            gnus-newsgroup-dormant))
5095
5096     (setq gnus-newsgroup-processable nil)
5097
5098     (gnus-update-read-articles group gnus-newsgroup-unreads)
5099
5100     ;; Adjust and set lists of article marks.
5101     (when info
5102       (gnus-adjust-marked-articles info))
5103     (if (setq articles select-articles)
5104         (setq gnus-newsgroup-unselected
5105               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5106       (setq articles (gnus-articles-to-read group read-all)))
5107
5108     (cond
5109      ((null articles)
5110       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5111       'quit)
5112      ((eq articles 0) nil)
5113      (t
5114       ;; Init the dependencies hash table.
5115       (setq gnus-newsgroup-dependencies
5116             (gnus-make-hashtable (length articles)))
5117       (gnus-set-global-variables)
5118       ;; Retrieve the headers and read them in.
5119
5120       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5121
5122       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5123       (when cached
5124         (setq gnus-newsgroup-cached cached))
5125
5126       ;; Suppress duplicates?
5127       (when gnus-suppress-duplicates
5128         (gnus-dup-suppress-articles))
5129
5130       ;; Set the initial limit.
5131       (setq gnus-newsgroup-limit (copy-sequence articles))
5132       ;; Remove canceled articles from the list of unread articles.
5133       (setq fetched-articles
5134             (mapcar (lambda (headers) (mail-header-number headers))
5135                     gnus-newsgroup-headers))
5136       (setq gnus-newsgroup-articles fetched-articles)
5137       (setq gnus-newsgroup-unreads
5138             (gnus-sorted-nintersection
5139              gnus-newsgroup-unreads fetched-articles))
5140       (gnus-compute-unseen-list)
5141
5142       ;; Removed marked articles that do not exist.
5143       (gnus-update-missing-marks
5144        (gnus-sorted-difference articles fetched-articles))
5145       ;; We might want to build some more threads first.
5146       (when (and gnus-fetch-old-headers
5147                  (eq gnus-headers-retrieved-by 'nov))
5148         (if (eq gnus-fetch-old-headers 'invisible)
5149             (gnus-build-all-threads)
5150           (gnus-build-old-threads)))
5151       ;; Let the Gnus agent mark articles as read.
5152       (when gnus-agent
5153         (gnus-agent-get-undownloaded-list))
5154       ;; Remove list identifiers from subject
5155       (when gnus-list-identifiers
5156         (gnus-summary-remove-list-identifiers))
5157       ;; Check whether auto-expire is to be done in this group.
5158       (setq gnus-newsgroup-auto-expire
5159             (gnus-group-auto-expirable-p group))
5160       ;; Set up the article buffer now, if necessary.
5161       (unless gnus-single-article-buffer
5162         (gnus-article-setup-buffer))
5163       ;; First and last article in this newsgroup.
5164       (when gnus-newsgroup-headers
5165         (setq gnus-newsgroup-begin
5166               (mail-header-number (car gnus-newsgroup-headers))
5167               gnus-newsgroup-end
5168               (mail-header-number
5169                (gnus-last-element gnus-newsgroup-headers))))
5170       ;; GROUP is successfully selected.
5171       (or gnus-newsgroup-headers t)))))
5172
5173 (defun gnus-compute-unseen-list ()
5174   ;; The `seen' marks are treated specially.
5175   (if (not gnus-newsgroup-seen)
5176       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5177     (setq gnus-newsgroup-unseen
5178           (gnus-inverse-list-range-intersection
5179            gnus-newsgroup-articles gnus-newsgroup-seen))))
5180
5181 (defun gnus-summary-display-make-predicate (display)
5182   (require 'gnus-agent)
5183   (when (= (length display) 1)
5184     (setq display (car display)))
5185   (unless gnus-summary-display-cache
5186     (dolist (elem (append '((unread . unread)
5187                             (read . read)
5188                             (unseen . unseen))
5189                           gnus-article-mark-lists))
5190       (push (cons (cdr elem)
5191                   (gnus-byte-compile
5192                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5193             gnus-summary-display-cache)))
5194   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5195         (gnus-category-predicate-cache gnus-summary-display-cache))
5196     (gnus-get-predicate display)))
5197
5198 ;; Uses the dynamically bound `number' variable.
5199 (eval-when-compile
5200   (defvar number))
5201 (defun gnus-article-marked-p (type &optional article)
5202   (let ((article (or article number)))
5203     (cond
5204      ((eq type 'tick)
5205       (memq article gnus-newsgroup-marked))
5206      ((eq type 'spam)
5207       (memq article gnus-newsgroup-spam-marked))
5208      ((eq type 'unsend)
5209       (memq article gnus-newsgroup-unsendable))
5210      ((eq type 'undownload)
5211       (memq article gnus-newsgroup-undownloaded))
5212      ((eq type 'download)
5213       (memq article gnus-newsgroup-downloadable))
5214      ((eq type 'unread)
5215       (memq article gnus-newsgroup-unreads))
5216      ((eq type 'read)
5217       (memq article gnus-newsgroup-reads))
5218      ((eq type 'dormant)
5219       (memq article gnus-newsgroup-dormant) )
5220      ((eq type 'expire)
5221       (memq article gnus-newsgroup-expirable))
5222      ((eq type 'reply)
5223       (memq article gnus-newsgroup-replied))
5224      ((eq type 'killed)
5225       (memq article gnus-newsgroup-killed))
5226      ((eq type 'bookmark)
5227       (assq article gnus-newsgroup-bookmarks))
5228      ((eq type 'score)
5229       (assq article gnus-newsgroup-scored))
5230      ((eq type 'save)
5231       (memq article gnus-newsgroup-saved))
5232      ((eq type 'cache)
5233       (memq article gnus-newsgroup-cached))
5234      ((eq type 'forward)
5235       (memq article gnus-newsgroup-forwarded))
5236      ((eq type 'seen)
5237       (not (memq article gnus-newsgroup-unseen)))
5238      ((eq type 'recent)
5239       (memq article gnus-newsgroup-recent))
5240      (t t))))
5241
5242 (defun gnus-articles-to-read (group &optional read-all)
5243   "Find out what articles the user wants to read."
5244   (let* ((display (gnus-group-find-parameter group 'display))
5245          (articles
5246           ;; Select all articles if `read-all' is non-nil, or if there
5247           ;; are no unread articles.
5248           (if (or read-all
5249                   (and (zerop (length gnus-newsgroup-marked))
5250                        (zerop (length gnus-newsgroup-unreads)))
5251                   ;; Fetch all if the predicate is non-nil.
5252                   gnus-newsgroup-display)
5253               ;; We want to select the headers for all the articles in
5254               ;; the group, so we select either all the active
5255               ;; articles in the group, or (if that's nil), the
5256               ;; articles in the cache.
5257               (or
5258                (gnus-uncompress-range (gnus-active group))
5259                (gnus-cache-articles-in-group group))
5260             ;; Select only the "normal" subset of articles.
5261             (gnus-sorted-nunion
5262              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5263              gnus-newsgroup-unreads)))
5264          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5265          (scored (length scored-list))
5266          (number (length articles))
5267          (marked (+ (length gnus-newsgroup-marked)
5268                     (length gnus-newsgroup-dormant)))
5269          (select
5270           (cond
5271            ((numberp read-all)
5272             read-all)
5273            ((numberp gnus-newsgroup-display)
5274             gnus-newsgroup-display)
5275            (t
5276             (condition-case ()
5277                 (cond
5278                  ((and (or (<= scored marked) (= scored number))
5279                        (numberp gnus-large-newsgroup)
5280                        (> number gnus-large-newsgroup))
5281                   (let* ((cursor-in-echo-area nil)
5282                          (initial (gnus-parameter-large-newsgroup-initial
5283                                    gnus-newsgroup-name))
5284                          (input
5285                           (read-string
5286                            (format
5287                             "How many articles from %s (%s %d): "
5288                             (gnus-limit-string
5289                              (gnus-group-decoded-name gnus-newsgroup-name)
5290                              35)
5291                             (if initial "max" "default")
5292                             number)
5293                            (if initial
5294                                (cons (number-to-string initial)
5295                                      0)))))
5296                     (if (string-match "^[ \t]*$" input) number input)))
5297                  ((and (> scored marked) (< scored number)
5298                        (> (- scored number) 20))
5299                   (let ((input
5300                          (read-string
5301                           (format "%s %s (%d scored, %d total): "
5302                                   "How many articles from"
5303                                   (gnus-group-decoded-name group)
5304                                   scored number))))
5305                     (if (string-match "^[ \t]*$" input)
5306                         number input)))
5307                  (t number))
5308               (quit
5309                (message "Quit getting the articles to read")
5310                nil))))))
5311     (setq select (if (stringp select) (string-to-number select) select))
5312     (if (or (null select) (zerop select))
5313         select
5314       (if (and (not (zerop scored)) (<= (abs select) scored))
5315           (progn
5316             (setq articles (sort scored-list '<))
5317             (setq number (length articles)))
5318         (setq articles (copy-sequence articles)))
5319
5320       (when (< (abs select) number)
5321         (if (< select 0)
5322             ;; Select the N oldest articles.
5323             (setcdr (nthcdr (1- (abs select)) articles) nil)
5324           ;; Select the N most recent articles.
5325           (setq articles (nthcdr (- number select) articles))))
5326       (setq gnus-newsgroup-unselected
5327             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5328       (when gnus-alter-articles-to-read-function
5329         (setq articles
5330               (sort
5331                (funcall gnus-alter-articles-to-read-function
5332                         gnus-newsgroup-name articles)
5333                '<)))
5334       articles)))
5335
5336 (defun gnus-killed-articles (killed articles)
5337   (let (out)
5338     (while articles
5339       (when (inline (gnus-member-of-range (car articles) killed))
5340         (push (car articles) out))
5341       (setq articles (cdr articles)))
5342     out))
5343
5344 (defun gnus-uncompress-marks (marks)
5345   "Uncompress the mark ranges in MARKS."
5346   (let ((uncompressed '(score bookmark))
5347         out)
5348     (while marks
5349       (if (memq (caar marks) uncompressed)
5350           (push (car marks) out)
5351         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5352       (setq marks (cdr marks)))
5353     out))
5354
5355 (defun gnus-article-mark-to-type (mark)
5356   "Return the type of MARK."
5357   (or (cadr (assq mark gnus-article-special-mark-lists))
5358       'list))
5359
5360 (defun gnus-article-unpropagatable-p (mark)
5361   "Return whether MARK should be propagated to back end."
5362   (memq mark gnus-article-unpropagated-mark-lists))
5363
5364 (defun gnus-adjust-marked-articles (info)
5365   "Set all article lists and remove all marks that are no longer valid."
5366   (let* ((marked-lists (gnus-info-marks info))
5367          (active (gnus-active (gnus-info-group info)))
5368          (min (car active))
5369          (max (cdr active))
5370          (types gnus-article-mark-lists)
5371          marks var articles article mark mark-type)
5372
5373     (dolist (marks marked-lists)
5374       (setq mark (car marks)
5375             mark-type (gnus-article-mark-to-type mark)
5376             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5377
5378       ;; We set the variable according to the type of the marks list,
5379       ;; and then adjust the marks to a subset of the active articles.
5380       (cond
5381        ;; Adjust "simple" lists.
5382        ((eq mark-type 'list)
5383         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5384         (when (memq mark '(tick dormant expire reply save))
5385           (while articles
5386             (when (or (< (setq article (pop articles)) min) (> article max))
5387               (set var (delq article (symbol-value var)))))))
5388        ;; Adjust assocs.
5389        ((eq mark-type 'tuple)
5390         (set var (setq articles (cdr marks)))
5391         (when (not (listp (cdr (symbol-value var))))
5392           (set var (list (symbol-value var))))
5393         (when (not (listp (cdr articles)))
5394           (setq articles (list articles)))
5395         (while articles
5396           (when (or (not (consp (setq article (pop articles))))
5397                     (< (car article) min)
5398                     (> (car article) max))
5399             (set var (delq article (symbol-value var))))))
5400        ;; Adjust ranges (sloppily).
5401        ((eq mark-type 'range)
5402         (cond
5403          ((eq mark 'seen)
5404           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5405           ;; It should be (seen (NUM1 . NUM2)).
5406           (when (numberp (cddr marks))
5407             (setcdr marks (list (cdr marks))))
5408           (setq articles (cdr marks))
5409           (while (and articles
5410                       (or (and (consp (car articles))
5411                                (> min (cdar articles)))
5412                           (and (numberp (car articles))
5413                                (> min (car articles)))))
5414             (pop articles))
5415           (set var articles))))))))
5416
5417 (defun gnus-update-missing-marks (missing)
5418   "Go through the list of MISSING articles and remove them from the mark lists."
5419   (when missing
5420     (let (var m)
5421       ;; Go through all types.
5422       (dolist (elem gnus-article-mark-lists)
5423         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5424           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5425           (when (symbol-value var)
5426             ;; This list has articles.  So we delete all missing
5427             ;; articles from it.
5428             (setq m missing)
5429             (while m
5430               (set var (delq (pop m) (symbol-value var))))))))))
5431
5432 (defun gnus-update-marks ()
5433   "Enter the various lists of marked articles into the newsgroup info list."
5434   (let ((types gnus-article-mark-lists)
5435         (info (gnus-get-info gnus-newsgroup-name))
5436         type list newmarked symbol delta-marks)
5437     (when info
5438       ;; Add all marks lists to the list of marks lists.
5439       (while (setq type (pop types))
5440         (setq list (symbol-value
5441                     (setq symbol
5442                           (intern (format "gnus-newsgroup-%s" (car type))))))
5443
5444         (when list
5445           ;; Get rid of the entries of the articles that have the
5446           ;; default score.
5447           (when (and (eq (cdr type) 'score)
5448                      gnus-save-score
5449                      list)
5450             (let* ((arts list)
5451                    (prev (cons nil list))
5452                    (all prev))
5453               (while arts
5454                 (if (or (not (consp (car arts)))
5455                         (= (cdar arts) gnus-summary-default-score))
5456                     (setcdr prev (cdr arts))
5457                   (setq prev arts))
5458                 (setq arts (cdr arts)))
5459               (setq list (cdr all)))))
5460
5461         (when (eq (cdr type) 'seen)
5462           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5463
5464         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5465           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5466
5467         (when (and (gnus-check-backend-function
5468                     'request-set-mark gnus-newsgroup-name)
5469                    (not (gnus-article-unpropagatable-p (cdr type))))
5470           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5471                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5472                  (add (gnus-remove-from-range
5473                        (gnus-copy-sequence list) old)))
5474             (when add
5475               (push (list add 'add (list (cdr type))) delta-marks))
5476             (when del
5477               (push (list del 'del (list (cdr type))) delta-marks))))
5478
5479         (when list
5480           (push (cons (cdr type) list) newmarked)))
5481
5482       (when delta-marks
5483         (unless (gnus-check-group gnus-newsgroup-name)
5484           (error "Can't open server for %s" gnus-newsgroup-name))
5485         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5486
5487       ;; Enter these new marks into the info of the group.
5488       (if (nthcdr 3 info)
5489           (setcar (nthcdr 3 info) newmarked)
5490         ;; Add the marks lists to the end of the info.
5491         (when newmarked
5492           (setcdr (nthcdr 2 info) (list newmarked))))
5493
5494       ;; Cut off the end of the info if there's nothing else there.
5495       (let ((i 5))
5496         (while (and (> i 2)
5497                     (not (nth i info)))
5498           (when (nthcdr (decf i) info)
5499             (setcdr (nthcdr i info) nil)))))))
5500
5501 (defun gnus-set-mode-line (where)
5502   "Set the mode line of the article or summary buffers.
5503 If WHERE is `summary', the summary mode line format will be used."
5504   ;; Is this mode line one we keep updated?
5505   (when (and (memq where gnus-updated-mode-lines)
5506              (symbol-value
5507               (intern (format "gnus-%s-mode-line-format-spec" where))))
5508     (let (mode-string)
5509       (save-excursion
5510         ;; We evaluate this in the summary buffer since these
5511         ;; variables are buffer-local to that buffer.
5512         (set-buffer gnus-summary-buffer)
5513         ;; We bind all these variables that are used in the `eval' form
5514         ;; below.
5515         (let* ((mformat (symbol-value
5516                          (intern
5517                           (format "gnus-%s-mode-line-format-spec" where))))
5518                (gnus-tmp-group-name (gnus-group-decoded-name
5519                                      gnus-newsgroup-name))
5520                (gnus-tmp-article-number (or gnus-current-article 0))
5521                (gnus-tmp-unread gnus-newsgroup-unreads)
5522                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5523                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5524                (gnus-tmp-unread-and-unselected
5525                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5526                             (zerop gnus-tmp-unselected))
5527                        "")
5528                       ((zerop gnus-tmp-unselected)
5529                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5530                       (t (format "{%d(+%d) more}"
5531                                  gnus-tmp-unread-and-unticked
5532                                  gnus-tmp-unselected))))
5533                (gnus-tmp-subject
5534                 (if (and gnus-current-headers
5535                          (vectorp gnus-current-headers))
5536                     (gnus-mode-string-quote
5537                      (mail-header-subject gnus-current-headers))
5538                   ""))
5539                bufname-length max-len
5540                gnus-tmp-header);; passed as argument to any user-format-funcs
5541           (setq mode-string (eval mformat))
5542           (setq bufname-length (if (string-match "%b" mode-string)
5543                                    (- (length
5544                                        (buffer-name
5545                                         (if (eq where 'summary)
5546                                             nil
5547                                           (get-buffer gnus-article-buffer))))
5548                                       2)
5549                                  0))
5550           (setq max-len (max 4 (if gnus-mode-non-string-length
5551                                    (- (window-width)
5552                                       gnus-mode-non-string-length
5553                                       bufname-length)
5554                                  (length mode-string))))
5555           ;; We might have to chop a bit of the string off...
5556           (when (> (length mode-string) max-len)
5557             (setq mode-string
5558                   (concat (gnus-truncate-string mode-string (- max-len 3))
5559                           "...")))
5560           ;; Pad the mode string a bit.
5561           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5562       ;; Update the mode line.
5563       (setq mode-line-buffer-identification
5564             (gnus-mode-line-buffer-identification (list mode-string)))
5565       (set-buffer-modified-p t))))
5566
5567 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5568   "Go through the HEADERS list and add all Xrefs to a hash table.
5569 The resulting hash table is returned, or nil if no Xrefs were found."
5570   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5571          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5572          (xref-hashtb (gnus-make-hashtable))
5573          start group entry number xrefs header)
5574     (while headers
5575       (setq header (pop headers))
5576       (when (and (setq xrefs (mail-header-xref header))
5577                  (not (memq (setq number (mail-header-number header))
5578                             unreads)))
5579         (setq start 0)
5580         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5581           (setq start (match-end 0))
5582           (setq group (if prefix
5583                           (concat prefix (substring xrefs (match-beginning 1)
5584                                                     (match-end 1)))
5585                         (substring xrefs (match-beginning 1) (match-end 1))))
5586           (setq number
5587                 (string-to-int (substring xrefs (match-beginning 2)
5588                                           (match-end 2))))
5589           (if (setq entry (gnus-gethash group xref-hashtb))
5590               (setcdr entry (cons number (cdr entry)))
5591             (gnus-sethash group (cons number nil) xref-hashtb)))))
5592     (and start xref-hashtb)))
5593
5594 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5595   "Look through all the headers and mark the Xrefs as read."
5596   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5597         name info xref-hashtb idlist method nth4)
5598     (save-excursion
5599       (set-buffer gnus-group-buffer)
5600       (when (setq xref-hashtb
5601                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5602         (mapatoms
5603          (lambda (group)
5604            (unless (string= from-newsgroup (setq name (symbol-name group)))
5605              (setq idlist (symbol-value group))
5606              ;; Dead groups are not updated.
5607              (and (prog1
5608                       (setq info (gnus-get-info name))
5609                     (when (stringp (setq nth4 (gnus-info-method info)))
5610                       (setq nth4 (gnus-server-to-method nth4))))
5611                   ;; Only do the xrefs if the group has the same
5612                   ;; select method as the group we have just read.
5613                   (or (gnus-methods-equal-p
5614                        nth4 (gnus-find-method-for-group from-newsgroup))
5615                       virtual
5616                       (equal nth4 (setq method (gnus-find-method-for-group
5617                                                 from-newsgroup)))
5618                       (and (equal (car nth4) (car method))
5619                            (equal (nth 1 nth4) (nth 1 method))))
5620                   gnus-use-cross-reference
5621                   (or (not (eq gnus-use-cross-reference t))
5622                       virtual
5623                       ;; Only do cross-references on subscribed
5624                       ;; groups, if that is what is wanted.
5625                       (<= (gnus-info-level info) gnus-level-subscribed))
5626                   (gnus-group-make-articles-read name idlist))))
5627          xref-hashtb)))))
5628
5629 (defun gnus-compute-read-articles (group articles)
5630   (let* ((entry (gnus-group-entry group))
5631          (info (nth 2 entry))
5632          (active (gnus-active group))
5633          ninfo)
5634     (when entry
5635       ;; First peel off all invalid article numbers.
5636       (when active
5637         (let ((ids articles)
5638               id first)
5639           (while (setq id (pop ids))
5640             (when (and first (> id (cdr active)))
5641               ;; We'll end up in this situation in one particular
5642               ;; obscure situation.  If you re-scan a group and get
5643               ;; a new article that is cross-posted to a different
5644               ;; group that has not been re-scanned, you might get
5645               ;; crossposted article that has a higher number than
5646               ;; Gnus believes possible.  So we re-activate this
5647               ;; group as well.  This might mean doing the
5648               ;; crossposting thingy will *increase* the number
5649               ;; of articles in some groups.  Tsk, tsk.
5650               (setq active (or (gnus-activate-group group) active)))
5651             (when (or (> id (cdr active))
5652                       (< id (car active)))
5653               (setq articles (delq id articles))))))
5654       ;; If the read list is nil, we init it.
5655       (if (and active
5656                (null (gnus-info-read info))
5657                (> (car active) 1))
5658           (setq ninfo (cons 1 (1- (car active))))
5659         (setq ninfo (gnus-info-read info)))
5660       ;; Then we add the read articles to the range.
5661       (gnus-add-to-range
5662        ninfo (setq articles (sort articles '<))))))
5663
5664 (defun gnus-group-make-articles-read (group articles)
5665   "Update the info of GROUP to say that ARTICLES are read."
5666   (let* ((num 0)
5667          (entry (gnus-group-entry group))
5668          (info (nth 2 entry))
5669          (active (gnus-active group))
5670          range)
5671     (when entry
5672       (setq range (gnus-compute-read-articles group articles))
5673       (with-current-buffer gnus-group-buffer
5674         (gnus-undo-register
5675           `(progn
5676              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5677              (gnus-info-set-read ',info ',(gnus-info-read info))
5678              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5679              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5680              (gnus-group-update-group ,group t))))
5681       ;; Add the read articles to the range.
5682       (gnus-info-set-read info range)
5683       (gnus-request-set-mark group (list (list range 'add '(read))))
5684       ;; Then we have to re-compute how many unread
5685       ;; articles there are in this group.
5686       (when active
5687         (cond
5688          ((not range)
5689           (setq num (- (1+ (cdr active)) (car active))))
5690          ((not (listp (cdr range)))
5691           (setq num (- (cdr active) (- (1+ (cdr range))
5692                                        (car range)))))
5693          (t
5694           (while range
5695             (if (numberp (car range))
5696                 (setq num (1+ num))
5697               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5698             (setq range (cdr range)))
5699           (setq num (- (cdr active) num))))
5700         ;; Update the number of unread articles.
5701         (setcar entry num)
5702         ;; Update the group buffer.
5703         (unless (gnus-ephemeral-group-p group)
5704           (gnus-group-update-group group t))))))
5705
5706 (defvar gnus-newsgroup-none-id 0)
5707
5708 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5709   (let ((cur nntp-server-buffer)
5710         (dependencies
5711          (or dependencies
5712              (save-excursion (set-buffer gnus-summary-buffer)
5713                              gnus-newsgroup-dependencies)))
5714         headers id end ref
5715         (mail-parse-charset gnus-newsgroup-charset)
5716         (mail-parse-ignored-charsets
5717          (save-excursion (condition-case nil
5718                              (set-buffer gnus-summary-buffer)
5719                            (error))
5720                          gnus-newsgroup-ignored-charsets)))
5721     (save-excursion
5722       (set-buffer nntp-server-buffer)
5723       ;; Translate all TAB characters into SPACE characters.
5724       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5725       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5726       (ietf-drums-unfold-fws)
5727       (gnus-run-hooks 'gnus-parse-headers-hook)
5728       (let ((case-fold-search t)
5729             in-reply-to header p lines chars ctype)
5730         (goto-char (point-min))
5731         ;; Search to the beginning of the next header.  Error messages
5732         ;; do not begin with 2 or 3.
5733         (while (re-search-forward "^[23][0-9]+ " nil t)
5734           (setq id nil
5735                 ref nil)
5736           ;; This implementation of this function, with nine
5737           ;; search-forwards instead of the one re-search-forward and
5738           ;; a case (which basically was the old function) is actually
5739           ;; about twice as fast, even though it looks messier.  You
5740           ;; can't have everything, I guess.  Speed and elegance
5741           ;; doesn't always go hand in hand.
5742           (setq
5743            header
5744            (make-full-mail-header
5745             ;; Number.
5746             (prog1
5747                 (read cur)
5748               (end-of-line)
5749               (setq p (point))
5750               (narrow-to-region (point)
5751                                 (or (and (search-forward "\n.\n" nil t)
5752                                          (- (point) 2))
5753                                     (point))))
5754             ;; Subject.
5755             (progn
5756               (goto-char p)
5757               (if (search-forward "\nsubject:" nil t)
5758                   (nnheader-header-value)
5759                 "(none)"))
5760             ;; From.
5761             (progn
5762               (goto-char p)
5763               (if (search-forward "\nfrom:" nil t)
5764                   (nnheader-header-value)
5765                 "(nobody)"))
5766             ;; Date.
5767             (progn
5768               (goto-char p)
5769               (if (search-forward "\ndate:" nil t)
5770                   (nnheader-header-value) ""))
5771             ;; Message-ID.
5772             (progn
5773               (goto-char p)
5774               (setq id (if (re-search-forward
5775                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5776                            ;; We do it this way to make sure the Message-ID
5777                            ;; is (somewhat) syntactically valid.
5778                            (buffer-substring (match-beginning 1)
5779                                              (match-end 1))
5780                          ;; If there was no message-id, we just fake one
5781                          ;; to make subsequent routines simpler.
5782                          (nnheader-generate-fake-message-id))))
5783             ;; References.
5784             (progn
5785               (goto-char p)
5786               (if (search-forward "\nreferences:" nil t)
5787                   (progn
5788                     (setq end (point))
5789                     (prog1
5790                         (nnheader-header-value)
5791                       (setq ref
5792                             (buffer-substring
5793                              (progn
5794                                ;; (end-of-line)
5795                                (search-backward ">" end t)
5796                                (1+ (point)))
5797                              (progn
5798                                (search-backward "<" end t)
5799                                (point))))))
5800                 ;; Get the references from the in-reply-to header if there
5801                 ;; were no references and the in-reply-to header looks
5802                 ;; promising.
5803                 (if (and (search-forward "\nin-reply-to:" nil t)
5804                          (setq in-reply-to (nnheader-header-value))
5805                          (string-match "<[^>]+>" in-reply-to))
5806                     (let (ref2)
5807                       (setq ref (substring in-reply-to (match-beginning 0)
5808                                            (match-end 0)))
5809                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5810                         (setq ref2 (substring in-reply-to (match-beginning 0)
5811                                               (match-end 0)))
5812                         (when (> (length ref2) (length ref))
5813                           (setq ref ref2)))
5814                       ref)
5815                   (setq ref nil))))
5816             ;; Chars.
5817             (progn
5818               (goto-char p)
5819               (if (search-forward "\nchars: " nil t)
5820                   (if (numberp (setq chars (ignore-errors (read cur))))
5821                       chars -1)
5822                 -1))
5823             ;; Lines.
5824             (progn
5825               (goto-char p)
5826               (if (search-forward "\nlines: " nil t)
5827                   (if (numberp (setq lines (ignore-errors (read cur))))
5828                       lines -1)
5829                 -1))
5830             ;; Xref.
5831             (progn
5832               (goto-char p)
5833               (and (search-forward "\nxref:" nil t)
5834                    (nnheader-header-value)))
5835             ;; Extra.
5836             (when gnus-extra-headers
5837               (let ((extra gnus-extra-headers)
5838                     out)
5839                 (while extra
5840                   (goto-char p)
5841                   (when (search-forward
5842                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5843                     (push (cons (car extra) (nnheader-header-value)) out))
5844                   (pop extra))
5845                 out))))
5846           (goto-char p)
5847           (if (and (search-forward "\ncontent-type: " nil t)
5848                    (setq ctype (nnheader-header-value)))
5849               (mime-entity-set-content-type-internal
5850                header (mime-parse-Content-Type ctype)))
5851           (when (equal id ref)
5852             (setq ref nil))
5853
5854           (when gnus-alter-header-function
5855             (funcall gnus-alter-header-function header)
5856             (setq id (mail-header-id header)
5857                   ref (gnus-parent-id (mail-header-references header))))
5858
5859           (when (setq header
5860                       (gnus-dependencies-add-header
5861                        header dependencies force-new))
5862             (push header headers))
5863           (goto-char (point-max))
5864           (widen))
5865         (nreverse headers)))))
5866
5867 ;; Goes through the xover lines and returns a list of vectors
5868 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5869                                                   force-new dependencies
5870                                                   group also-fetch-heads)
5871   "Parse the news overview data in the server buffer.
5872 Return a list of headers that match SEQUENCE (see
5873 `nntp-retrieve-headers')."
5874   ;; Get the Xref when the users reads the articles since most/some
5875   ;; NNTP servers do not include Xrefs when using XOVER.
5876   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5877   (let ((mail-parse-charset gnus-newsgroup-charset)
5878         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5879         (cur nntp-server-buffer)
5880         (dependencies (or dependencies gnus-newsgroup-dependencies))
5881         (allp (cond
5882                ((eq gnus-read-all-available-headers t)
5883                 t)
5884                ((stringp gnus-read-all-available-headers)
5885                 (string-match gnus-read-all-available-headers group))
5886                (t
5887                 nil)))
5888         number headers header)
5889     (save-excursion
5890       (set-buffer nntp-server-buffer)
5891       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5892       ;; Allow the user to mangle the headers before parsing them.
5893       (gnus-run-hooks 'gnus-parse-headers-hook)
5894       (goto-char (point-min))
5895       (gnus-parse-without-error
5896         (while (and (or sequence allp)
5897                     (not (eobp)))
5898           (setq number (read cur))
5899           (when (not allp)
5900             (while (and sequence
5901                         (< (car sequence) number))
5902               (setq sequence (cdr sequence))))
5903           (when (and (or allp
5904                          (and sequence
5905                               (eq number (car sequence))))
5906                      (progn
5907                        (setq sequence (cdr sequence))
5908                        (setq header (inline
5909                                       (gnus-nov-parse-line
5910                                        number dependencies force-new)))))
5911             (push header headers))
5912           (forward-line 1)))
5913       ;; A common bug in inn is that if you have posted an article and
5914       ;; then retrieves the active file, it will answer correctly --
5915       ;; the new article is included.  However, a NOV entry for the
5916       ;; article may not have been generated yet, so this may fail.
5917       ;; We work around this problem by retrieving the last few
5918       ;; headers using HEAD.
5919       (if (or (not also-fetch-heads)
5920               (not sequence))
5921           ;; We (probably) got all the headers.
5922           (nreverse headers)
5923         (let ((gnus-nov-is-evil t))
5924           (nconc
5925            (nreverse headers)
5926            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5927              (gnus-get-newsgroup-headers))))))))
5928
5929 (defun gnus-article-get-xrefs ()
5930   "Fill in the Xref value in `gnus-current-headers', if necessary.
5931 This is meant to be called in `gnus-article-internal-prepare-hook'."
5932   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5933                                  gnus-current-headers)))
5934     (or (not gnus-use-cross-reference)
5935         (not headers)
5936         (and (mail-header-xref headers)
5937              (not (string= (mail-header-xref headers) "")))
5938         (let ((case-fold-search t)
5939               xref)
5940           (save-restriction
5941             (nnheader-narrow-to-headers)
5942             (goto-char (point-min))
5943             (when (or (and (not (eobp))
5944                            (eq (downcase (char-after)) ?x)
5945                            (looking-at "Xref:"))
5946                       (search-forward "\nXref:" nil t))
5947               (goto-char (1+ (match-end 0)))
5948               (setq xref (buffer-substring (point) (point-at-eol)))
5949               (mail-header-set-xref headers xref)))))))
5950
5951 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5952   "Find article ID and insert the summary line for that article.
5953 OLD-HEADER can either be a header or a line number to insert
5954 the subject line on."
5955   (let* ((line (and (numberp old-header) old-header))
5956          (old-header (and (vectorp old-header) old-header))
5957          (header (cond ((and old-header use-old-header)
5958                         old-header)
5959                        ((and (numberp id)
5960                              (gnus-number-to-header id))
5961                         (gnus-number-to-header id))
5962                        (t
5963                         (gnus-read-header id))))
5964          (number (and (numberp id) id))
5965          d)
5966     (when header
5967       ;; Rebuild the thread that this article is part of and go to the
5968       ;; article we have fetched.
5969       (when (and (not gnus-show-threads)
5970                  old-header)
5971         (when (and number
5972                    (setq d (gnus-data-find (mail-header-number old-header))))
5973           (goto-char (gnus-data-pos d))
5974           (gnus-data-remove
5975            number
5976            (- (point-at-bol)
5977               (prog1
5978                   (1+ (point-at-eol))
5979                 (gnus-delete-line))))))
5980       (when old-header
5981         (mail-header-set-number header (mail-header-number old-header)))
5982       (setq gnus-newsgroup-sparse
5983             (delq (setq number (mail-header-number header))
5984                   gnus-newsgroup-sparse))
5985       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5986       (push number gnus-newsgroup-limit)
5987       (gnus-rebuild-thread (mail-header-id header) line)
5988       (gnus-summary-goto-subject number nil t))
5989     (when (and (numberp number)
5990                (> number 0))
5991       ;; We have to update the boundaries even if we can't fetch the
5992       ;; article if ID is a number -- so that the next `P' or `N'
5993       ;; command will fetch the previous (or next) article even
5994       ;; if the one we tried to fetch this time has been canceled.
5995       (when (> number gnus-newsgroup-end)
5996         (setq gnus-newsgroup-end number))
5997       (when (< number gnus-newsgroup-begin)
5998         (setq gnus-newsgroup-begin number))
5999       (setq gnus-newsgroup-unselected
6000             (delq number gnus-newsgroup-unselected)))
6001     ;; Report back a success?
6002     (and header (mail-header-number header))))
6003
6004 ;;; Process/prefix in the summary buffer
6005
6006 (defun gnus-summary-work-articles (n)
6007   "Return a list of articles to be worked upon.
6008 The prefix argument, the list of process marked articles, and the
6009 current article will be taken into consideration."
6010   (save-excursion
6011     (set-buffer gnus-summary-buffer)
6012     (cond
6013      (n
6014       ;; A numerical prefix has been given.
6015       (setq n (prefix-numeric-value n))
6016       (let ((backward (< n 0))
6017             (n (abs (prefix-numeric-value n)))
6018             articles article)
6019         (save-excursion
6020           (while
6021               (and (> n 0)
6022                    (push (setq article (gnus-summary-article-number))
6023                          articles)
6024                    (if backward
6025                        (gnus-summary-find-prev nil article)
6026                      (gnus-summary-find-next nil article)))
6027             (decf n)))
6028         (nreverse articles)))
6029      ((and (gnus-region-active-p) (mark))
6030       (message "region active")
6031       ;; Work on the region between point and mark.
6032       (let ((max (max (point) (mark)))
6033             articles article)
6034         (save-excursion
6035           (goto-char (min (point) (mark)))
6036           (while
6037               (and
6038                (push (setq article (gnus-summary-article-number)) articles)
6039                (gnus-summary-find-next nil article)
6040                (< (point) max)))
6041           (nreverse articles))))
6042      (gnus-newsgroup-processable
6043       ;; There are process-marked articles present.
6044       ;; Save current state.
6045       (gnus-summary-save-process-mark)
6046       ;; Return the list.
6047       (reverse gnus-newsgroup-processable))
6048      (t
6049       ;; Just return the current article.
6050       (list (gnus-summary-article-number))))))
6051
6052 (defmacro gnus-summary-iterate (arg &rest forms)
6053   "Iterate over the process/prefixed articles and do FORMS.
6054 ARG is the interactive prefix given to the command.  FORMS will be
6055 executed with point over the summary line of the articles."
6056   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6057     `(let ((,articles (gnus-summary-work-articles ,arg)))
6058        (while ,articles
6059          (gnus-summary-goto-subject (car ,articles))
6060          ,@forms
6061          (pop ,articles)))))
6062
6063 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6064 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6065
6066 (defun gnus-summary-save-process-mark ()
6067   "Push the current set of process marked articles on the stack."
6068   (interactive)
6069   (push (copy-sequence gnus-newsgroup-processable)
6070         gnus-newsgroup-process-stack))
6071
6072 (defun gnus-summary-kill-process-mark ()
6073   "Push the current set of process marked articles on the stack and unmark."
6074   (interactive)
6075   (gnus-summary-save-process-mark)
6076   (gnus-summary-unmark-all-processable))
6077
6078 (defun gnus-summary-yank-process-mark ()
6079   "Pop the last process mark state off the stack and restore it."
6080   (interactive)
6081   (unless gnus-newsgroup-process-stack
6082     (error "Empty mark stack"))
6083   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6084
6085 (defun gnus-summary-process-mark-set (set)
6086   "Make SET into the current process marked articles."
6087   (gnus-summary-unmark-all-processable)
6088   (while set
6089     (gnus-summary-set-process-mark (pop set))))
6090
6091 ;;; Searching and stuff
6092
6093 (defun gnus-summary-search-group (&optional backward use-level)
6094   "Search for next unread newsgroup.
6095 If optional argument BACKWARD is non-nil, search backward instead."
6096   (save-excursion
6097     (set-buffer gnus-group-buffer)
6098     (when (gnus-group-search-forward
6099            backward nil (if use-level (gnus-group-group-level) nil))
6100       (gnus-group-group-name))))
6101
6102 (defun gnus-summary-best-group (&optional exclude-group)
6103   "Find the name of the best unread group.
6104 If EXCLUDE-GROUP, do not go to this group."
6105   (save-excursion
6106     (set-buffer gnus-group-buffer)
6107     (save-excursion
6108       (gnus-group-best-unread-group exclude-group))))
6109
6110 (defun gnus-summary-find-next (&optional unread article backward)
6111   (if backward
6112       (gnus-summary-find-prev unread article)
6113     (let* ((dummy (gnus-summary-article-intangible-p))
6114            (article (or article (gnus-summary-article-number)))
6115            (data (gnus-data-find-list article))
6116            result)
6117       (when (and (not dummy)
6118                  (or (not gnus-summary-check-current)
6119                      (not unread)
6120                      (not (gnus-data-unread-p (car data)))))
6121         (setq data (cdr data)))
6122       (when (setq result
6123                   (if unread
6124                       (progn
6125                         (while data
6126                           (unless (memq (gnus-data-number (car data))
6127                                         (cond
6128                                          ((eq gnus-auto-goto-ignores
6129                                               'always-undownloaded)
6130                                           gnus-newsgroup-undownloaded)
6131                                          (gnus-plugged
6132                                           nil)
6133                                          ((eq gnus-auto-goto-ignores
6134                                               'unfetched)
6135                                           gnus-newsgroup-unfetched)
6136                                          ((eq gnus-auto-goto-ignores
6137                                               'undownloaded)
6138                                           gnus-newsgroup-undownloaded)))
6139                             (when (gnus-data-unread-p (car data))
6140                               (setq result (car data)
6141                                     data nil)))
6142                           (setq data (cdr data)))
6143                         result)
6144                     (car data)))
6145         (goto-char (gnus-data-pos result))
6146         (gnus-data-number result)))))
6147
6148 (defun gnus-summary-find-prev (&optional unread article)
6149   (let* ((eobp (eobp))
6150          (article (or article (gnus-summary-article-number)))
6151          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6152          result)
6153     (when (and (not eobp)
6154                (or (not gnus-summary-check-current)
6155                    (not unread)
6156                    (not (gnus-data-unread-p (car data)))))
6157       (setq data (cdr data)))
6158     (when (setq result
6159                 (if unread
6160                     (progn
6161                       (while data
6162                         (unless (memq (gnus-data-number (car data))
6163                                       (cond
6164                                        ((eq gnus-auto-goto-ignores
6165                                             'always-undownloaded)
6166                                         gnus-newsgroup-undownloaded)
6167                                        (gnus-plugged
6168                                         nil)
6169                                        ((eq gnus-auto-goto-ignores
6170                                             'unfetched)
6171                                         gnus-newsgroup-unfetched)
6172                                        ((eq gnus-auto-goto-ignores
6173                                             'undownloaded)
6174                                         gnus-newsgroup-undownloaded)))
6175                           (when (gnus-data-unread-p (car data))
6176                             (setq result (car data)
6177                                   data nil)))
6178                         (setq data (cdr data)))
6179                       result)
6180                   (car data)))
6181       (goto-char (gnus-data-pos result))
6182       (gnus-data-number result))))
6183
6184 (defun gnus-summary-find-subject (subject &optional unread backward article)
6185   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6186          (article (or article (gnus-summary-article-number)))
6187          (articles (gnus-data-list backward))
6188          (arts (gnus-data-find-list article articles))
6189          result)
6190     (when (or (not gnus-summary-check-current)
6191               (not unread)
6192               (not (gnus-data-unread-p (car arts))))
6193       (setq arts (cdr arts)))
6194     (while arts
6195       (and (or (not unread)
6196                (gnus-data-unread-p (car arts)))
6197            (vectorp (gnus-data-header (car arts)))
6198            (gnus-subject-equal
6199             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6200            (setq result (car arts)
6201                  arts nil))
6202       (setq arts (cdr arts)))
6203     (and result
6204          (goto-char (gnus-data-pos result))
6205          (gnus-data-number result))))
6206
6207 (defun gnus-summary-search-forward (&optional unread subject backward)
6208   "Search forward for an article.
6209 If UNREAD, look for unread articles.  If SUBJECT, look for
6210 articles with that subject.  If BACKWARD, search backward instead."
6211   (cond (subject (gnus-summary-find-subject subject unread backward))
6212         (backward (gnus-summary-find-prev unread))
6213         (t (gnus-summary-find-next unread))))
6214
6215 (defun gnus-recenter (&optional n)
6216   "Center point in window and redisplay frame.
6217 Also do horizontal recentering."
6218   (interactive "P")
6219   (when (and gnus-auto-center-summary
6220              (not (eq gnus-auto-center-summary 'vertical)))
6221     (gnus-horizontal-recenter))
6222   (recenter n))
6223
6224 (defun gnus-summary-recenter ()
6225   "Center point in the summary window.
6226 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6227 displayed, no centering will be performed."
6228   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6229   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6230   (interactive)
6231   ;; The user has to want it.
6232   (when gnus-auto-center-summary
6233     (let* ((top (cond ((< (window-height) 4) 0)
6234                       ((< (window-height) 7) 1)
6235                       (t (if (numberp gnus-auto-center-summary)
6236                              gnus-auto-center-summary
6237                            2))))
6238            (height (1- (window-height)))
6239            (bottom (save-excursion (goto-char (point-max))
6240                                    (forward-line (- height))
6241                                    (point)))
6242            (window (get-buffer-window (current-buffer))))
6243       (when (get-buffer-window gnus-article-buffer)
6244         ;; Only do recentering when the article buffer is displayed,
6245         ;; Set the window start to either `bottom', which is the biggest
6246         ;; possible valid number, or the second line from the top,
6247         ;; whichever is the least.
6248         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6249           (if (> bottom top-pos)
6250               ;; Keep the second line from the top visible
6251               (set-window-start window top-pos t)
6252             ;; Try to keep the bottom line visible; if it's partially
6253             ;; obscured, either scroll one more line to make it fully
6254             ;; visible, or revert to using TOP-POS.
6255             (save-excursion
6256               (goto-char (point-max))
6257               (forward-line -1)
6258               (let ((last-line-start (point)))
6259                 (goto-char bottom)
6260                 (set-window-start window (point) t)
6261                 (when (not (pos-visible-in-window-p last-line-start window))
6262                   (forward-line 1)
6263                   (set-window-start window (min (point) top-pos) t)))))))
6264       ;; Do horizontal recentering while we're at it.
6265       (when (and (get-buffer-window (current-buffer) t)
6266                  (not (eq gnus-auto-center-summary 'vertical)))
6267         (let ((selected (selected-window)))
6268           (select-window (get-buffer-window (current-buffer) t))
6269           (gnus-summary-position-point)
6270           (gnus-horizontal-recenter)
6271           (select-window selected))))))
6272
6273 (defun gnus-summary-jump-to-group (newsgroup)
6274   "Move point to NEWSGROUP in group mode buffer."
6275   ;; Keep update point of group mode buffer if visible.
6276   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6277       (save-window-excursion
6278         ;; Take care of tree window mode.
6279         (when (get-buffer-window gnus-group-buffer)
6280           (pop-to-buffer gnus-group-buffer))
6281         (gnus-group-jump-to-group newsgroup))
6282     (save-excursion
6283       ;; Take care of tree window mode.
6284       (if (get-buffer-window gnus-group-buffer)
6285           (pop-to-buffer gnus-group-buffer)
6286         (set-buffer gnus-group-buffer))
6287       (gnus-group-jump-to-group newsgroup))))
6288
6289 ;; This function returns a list of article numbers based on the
6290 ;; difference between the ranges of read articles in this group and
6291 ;; the range of active articles.
6292 (defun gnus-list-of-unread-articles (group)
6293   (let* ((read (gnus-info-read (gnus-get-info group)))
6294          (active (or (gnus-active group) (gnus-activate-group group)))
6295          (last (cdr active))
6296          first nlast unread)
6297     ;; If none are read, then all are unread.
6298     (if (not read)
6299         (setq first (car active))
6300       ;; If the range of read articles is a single range, then the
6301       ;; first unread article is the article after the last read
6302       ;; article.  Sounds logical, doesn't it?
6303       (if (and (not (listp (cdr read)))
6304                (or (< (car read) (car active))
6305                    (progn (setq read (list read))
6306                           nil)))
6307           (setq first (max (car active) (1+ (cdr read))))
6308         ;; `read' is a list of ranges.
6309         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6310                                   (caar read)))
6311                   1)
6312           (setq first (car active)))
6313         (while read
6314           (when first
6315             (while (< first nlast)
6316               (push first unread)
6317               (setq first (1+ first))))
6318           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6319           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6320           (setq read (cdr read)))))
6321     ;; And add the last unread articles.
6322     (while (<= first last)
6323       (push first unread)
6324       (setq first (1+ first)))
6325     ;; Return the list of unread articles.
6326     (delq 0 (nreverse unread))))
6327
6328 (defun gnus-list-of-read-articles (group)
6329   "Return a list of unread, unticked and non-dormant articles."
6330   (let* ((info (gnus-get-info group))
6331          (marked (gnus-info-marks info))
6332          (active (gnus-active group)))
6333     (and info active
6334          (gnus-list-range-difference
6335           (gnus-list-range-difference
6336            (gnus-sorted-complement
6337             (gnus-uncompress-range active)
6338             (gnus-list-of-unread-articles group))
6339            (cdr (assq 'dormant marked)))
6340           (cdr (assq 'tick marked))))))
6341
6342 ;; Various summary commands
6343
6344 (defun gnus-summary-select-article-buffer ()
6345   "Reconfigure windows to show article buffer."
6346   (interactive)
6347   (if (not (gnus-buffer-live-p gnus-article-buffer))
6348       (error "There is no article buffer for this summary buffer")
6349     (gnus-configure-windows 'article)
6350     (select-window (get-buffer-window gnus-article-buffer))))
6351
6352 (defun gnus-summary-universal-argument (arg)
6353   "Perform any operation on all articles that are process/prefixed."
6354   (interactive "P")
6355   (let ((articles (gnus-summary-work-articles arg))
6356         func article)
6357     (if (eq
6358          (setq
6359           func
6360           (key-binding
6361            (read-key-sequence
6362             (substitute-command-keys
6363              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6364          'undefined)
6365         (gnus-error 1 "Undefined key")
6366       (save-excursion
6367         (while articles
6368           (gnus-summary-goto-subject (setq article (pop articles)))
6369           (let (gnus-newsgroup-processable)
6370             (command-execute func))
6371           (gnus-summary-remove-process-mark article)))))
6372   (gnus-summary-position-point))
6373
6374 (defun gnus-summary-toggle-truncation (&optional arg)
6375   "Toggle truncation of summary lines.
6376 With ARG, turn line truncation on if ARG is positive."
6377   (interactive "P")
6378   (setq truncate-lines
6379         (if (null arg) (not truncate-lines)
6380           (> (prefix-numeric-value arg) 0)))
6381   (redraw-display))
6382
6383 (defun gnus-summary-find-for-reselect ()
6384   "Return the number of an article to stay on across a reselect.
6385 The current article is considered, then following articles, then previous
6386 articles.  An article is sought which is not cancelled and isn't a temporary
6387 insertion from another group.  If there's no such then return a dummy 0."
6388   (let (found)
6389     (dolist (rev '(nil t))
6390       (unless found      ; don't demand the reverse list if we don't need it
6391         (let ((data (gnus-data-find-list
6392                      (gnus-summary-article-number) (gnus-data-list rev))))
6393           (while (and data (not found))
6394             (if (and (< 0 (gnus-data-number (car data)))
6395                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6396                 (setq found (gnus-data-number (car data))))
6397             (setq data (cdr data))))))
6398     (or found 0)))
6399
6400 (defun gnus-summary-reselect-current-group (&optional all rescan)
6401   "Exit and then reselect the current newsgroup.
6402 The prefix argument ALL means to select all articles."
6403   (interactive "P")
6404   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6405     (error "Ephemeral groups can't be reselected"))
6406   (let ((current-subject (gnus-summary-find-for-reselect))
6407         (group gnus-newsgroup-name))
6408     (setq gnus-newsgroup-begin nil)
6409     (gnus-summary-exit nil 'leave-hidden)
6410     ;; We have to adjust the point of group mode buffer because
6411     ;; point was moved to the next unread newsgroup by exiting.
6412     (gnus-summary-jump-to-group group)
6413     (when rescan
6414       (save-excursion
6415         (save-window-excursion
6416           ;; Don't show group contents.
6417           (set-window-start (selected-window) (point-max))
6418           (gnus-group-get-new-news-this-group 1))))
6419     (gnus-group-read-group all t)
6420     (gnus-summary-goto-subject current-subject nil t)))
6421
6422 (defun gnus-summary-rescan-group (&optional all)
6423   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6424   (interactive "P")
6425   (gnus-summary-reselect-current-group all t))
6426
6427 (defun gnus-summary-update-info (&optional non-destructive)
6428   (save-excursion
6429     (let ((group gnus-newsgroup-name))
6430       (when group
6431         (when gnus-newsgroup-kill-headers
6432           (setq gnus-newsgroup-killed
6433                 (gnus-compress-sequence
6434                  (gnus-sorted-union
6435                   (gnus-list-range-intersection
6436                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6437                   gnus-newsgroup-unreads)
6438                  t)))
6439         (unless (listp (cdr gnus-newsgroup-killed))
6440           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6441         (let ((headers gnus-newsgroup-headers))
6442           ;; Set the new ranges of read articles.
6443           (save-excursion
6444             (set-buffer gnus-group-buffer)
6445             (gnus-undo-force-boundary))
6446           (gnus-update-read-articles
6447            group (gnus-sorted-union
6448                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6449           ;; Set the current article marks.
6450           (let ((gnus-newsgroup-scored
6451                  (if (and (not gnus-save-score)
6452                           (not non-destructive))
6453                      nil
6454                    gnus-newsgroup-scored)))
6455             (save-excursion
6456               (gnus-update-marks)))
6457           ;; Do the cross-ref thing.
6458           (when gnus-use-cross-reference
6459             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6460           ;; Do not switch windows but change the buffer to work.
6461           (set-buffer gnus-group-buffer)
6462           (unless (gnus-ephemeral-group-p group)
6463             (gnus-group-update-group group)))))))
6464
6465 (defun gnus-summary-save-newsrc (&optional force)
6466   "Save the current number of read/marked articles in the dribble buffer.
6467 The dribble buffer will then be saved.
6468 If FORCE (the prefix), also save the .newsrc file(s)."
6469   (interactive "P")
6470   (gnus-summary-update-info t)
6471   (if force
6472       (gnus-save-newsrc-file)
6473     (gnus-dribble-save)))
6474
6475 (defun gnus-summary-exit (&optional temporary leave-hidden)
6476   "Exit reading current newsgroup, and then return to group selection mode.
6477 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6478   (interactive)
6479   (gnus-set-global-variables)
6480   (gnus-kill-save-kill-buffer)
6481   (gnus-async-halt-prefetch)
6482   (let* ((group gnus-newsgroup-name)
6483          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6484          (gnus-group-is-exiting-p t)
6485          (mode major-mode)
6486          (group-point nil)
6487          (buf (current-buffer)))
6488     (unless quit-config
6489       ;; Do adaptive scoring, and possibly save score files.
6490       (when gnus-newsgroup-adaptive
6491         (gnus-score-adaptive))
6492       (when gnus-use-scoring
6493         (gnus-score-save)))
6494     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6495     ;; If we have several article buffers, we kill them at exit.
6496     (unless gnus-single-article-buffer
6497       (gnus-kill-buffer gnus-original-article-buffer)
6498       (setq gnus-article-current nil))
6499     (when gnus-use-cache
6500       (gnus-cache-possibly-remove-articles)
6501       (gnus-cache-save-buffers))
6502     (gnus-async-prefetch-remove-group group)
6503     (when gnus-suppress-duplicates
6504       (gnus-dup-enter-articles))
6505     (when gnus-use-trees
6506       (gnus-tree-close group))
6507     (when gnus-use-cache
6508       (gnus-cache-write-active))
6509     ;; Remove entries for this group.
6510     (nnmail-purge-split-history (gnus-group-real-name group))
6511     ;; Make all changes in this group permanent.
6512     (unless quit-config
6513       (gnus-run-hooks 'gnus-exit-group-hook)
6514       (gnus-summary-update-info))
6515     (gnus-close-group group)
6516     ;; Make sure where we were, and go to next newsgroup.
6517     (set-buffer gnus-group-buffer)
6518     (unless quit-config
6519       (gnus-group-jump-to-group group))
6520     (gnus-run-hooks 'gnus-summary-exit-hook)
6521     (unless (or quit-config
6522                 ;; If this group has disappeared from the summary
6523                 ;; buffer, don't skip forwards.
6524                 (not (string= group (gnus-group-group-name))))
6525       (gnus-group-next-unread-group 1))
6526     (setq group-point (point))
6527     (if temporary
6528         nil                             ;Nothing to do.
6529       ;; If we have several article buffers, we kill them at exit.
6530       (unless gnus-single-article-buffer
6531         (gnus-kill-buffer gnus-article-buffer)
6532         (gnus-kill-buffer gnus-original-article-buffer)
6533         (setq gnus-article-current nil))
6534       (set-buffer buf)
6535       (if (not gnus-kill-summary-on-exit)
6536           (progn
6537             (gnus-deaden-summary)
6538             (setq mode nil))
6539         ;; We set all buffer-local variables to nil.  It is unclear why
6540         ;; this is needed, but if we don't, buffer-local variables are
6541         ;; not garbage-collected, it seems.  This would the lead to en
6542         ;; ever-growing Emacs.
6543         (gnus-summary-clear-local-variables)
6544         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6545           (gnus-summary-clear-local-variables))
6546         (when (get-buffer gnus-article-buffer)
6547           (bury-buffer gnus-article-buffer))
6548         ;; We clear the global counterparts of the buffer-local
6549         ;; variables as well, just to be on the safe side.
6550         (set-buffer gnus-group-buffer)
6551         (gnus-summary-clear-local-variables)
6552         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6553           (gnus-summary-clear-local-variables))
6554         ;; Return to group mode buffer.
6555         (when (eq mode 'gnus-summary-mode)
6556           (gnus-kill-buffer buf)))
6557       (setq gnus-current-select-method gnus-select-method)
6558       (if leave-hidden
6559           (set-buffer gnus-group-buffer)
6560         (pop-to-buffer gnus-group-buffer))
6561       (if (not quit-config)
6562           (progn
6563             (goto-char group-point)
6564             (unless leave-hidden
6565               (gnus-configure-windows 'group 'force))
6566             (unless (pos-visible-in-window-p)
6567               (forward-line (/ (static-if (featurep 'xemacs)
6568                                    (window-displayed-height)
6569                                  (1- (window-height)))
6570                                -2))
6571               (set-window-start (selected-window) (point))
6572               (goto-char group-point)))
6573         (gnus-handle-ephemeral-exit quit-config))
6574       ;; Clear the current group name.
6575       (unless quit-config
6576         (setq gnus-newsgroup-name nil)))))
6577
6578 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6579 (defun gnus-summary-exit-no-update (&optional no-questions)
6580   "Quit reading current newsgroup without updating read article info."
6581   (interactive)
6582   (let* ((group gnus-newsgroup-name)
6583          (gnus-group-is-exiting-p t)
6584          (gnus-group-is-exiting-without-update-p t)
6585          (quit-config (gnus-group-quit-config group)))
6586     (when (or no-questions
6587               gnus-expert-user
6588               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6589       (gnus-async-halt-prefetch)
6590       (run-hooks 'gnus-summary-prepare-exit-hook)
6591       ;; If we have several article buffers, we kill them at exit.
6592       (unless gnus-single-article-buffer
6593         (gnus-kill-buffer gnus-article-buffer)
6594         (gnus-kill-buffer gnus-original-article-buffer)
6595         (setq gnus-article-current nil))
6596       (if (not gnus-kill-summary-on-exit)
6597           (gnus-deaden-summary)
6598         (gnus-close-group group)
6599         (gnus-summary-clear-local-variables)
6600         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6601           (gnus-summary-clear-local-variables))
6602         (set-buffer gnus-group-buffer)
6603         (gnus-summary-clear-local-variables)
6604         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6605           (gnus-summary-clear-local-variables))
6606         (gnus-kill-buffer gnus-summary-buffer))
6607       (unless gnus-single-article-buffer
6608         (setq gnus-article-current nil))
6609       (when gnus-use-trees
6610         (gnus-tree-close group))
6611       (gnus-async-prefetch-remove-group group)
6612       (when (get-buffer gnus-article-buffer)
6613         (bury-buffer gnus-article-buffer))
6614       ;; Return to the group buffer.
6615       (gnus-configure-windows 'group 'force)
6616       ;; Clear the current group name.
6617       (setq gnus-newsgroup-name nil)
6618       (unless (gnus-ephemeral-group-p group)
6619         (gnus-group-update-group group))
6620       (when (equal (gnus-group-group-name) group)
6621         (gnus-group-next-unread-group 1))
6622       (when quit-config
6623         (gnus-handle-ephemeral-exit quit-config)))))
6624
6625 (defun gnus-handle-ephemeral-exit (quit-config)
6626   "Handle movement when leaving an ephemeral group.
6627 The state which existed when entering the ephemeral is reset."
6628   (if (not (buffer-name (car quit-config)))
6629       (gnus-configure-windows 'group 'force)
6630     (set-buffer (car quit-config))
6631     (cond ((eq major-mode 'gnus-summary-mode)
6632            (gnus-set-global-variables))
6633           ((eq major-mode 'gnus-article-mode)
6634            (save-excursion
6635              ;; The `gnus-summary-buffer' variable may point
6636              ;; to the old summary buffer when using a single
6637              ;; article buffer.
6638              (unless (gnus-buffer-live-p gnus-summary-buffer)
6639                (set-buffer gnus-group-buffer))
6640              (set-buffer gnus-summary-buffer)
6641              (gnus-set-global-variables))))
6642     (if (or (eq (cdr quit-config) 'article)
6643             (eq (cdr quit-config) 'pick))
6644         (progn
6645           ;; The current article may be from the ephemeral group
6646           ;; thus it is best that we reload this article
6647           ;;
6648           ;; If we're exiting from a large digest, this can be
6649           ;; extremely slow.  So, it's better not to reload it. -- jh.
6650           ;;(gnus-summary-show-article)
6651           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6652               (gnus-configure-windows 'pick 'force)
6653             (gnus-configure-windows (cdr quit-config) 'force)))
6654       (gnus-configure-windows (cdr quit-config) 'force))
6655     (when (eq major-mode 'gnus-summary-mode)
6656       (gnus-summary-next-subject 1 nil t)
6657       (gnus-summary-recenter)
6658       (gnus-summary-position-point))))
6659
6660 (defun gnus-summary-preview-mime-message ()
6661   "MIME decode and play this message."
6662   (interactive)
6663   (let ((gnus-break-pages nil)
6664         (gnus-show-mime t))
6665     (gnus-summary-select-article gnus-show-all-headers t))
6666   (let ((w (get-buffer-window gnus-article-buffer)))
6667     (when w
6668       (select-window (get-buffer-window gnus-article-buffer)))))
6669
6670 ;;; Dead summaries.
6671
6672 (defvar gnus-dead-summary-mode-map nil)
6673
6674 (unless gnus-dead-summary-mode-map
6675   (setq gnus-dead-summary-mode-map (make-keymap))
6676   (suppress-keymap gnus-dead-summary-mode-map)
6677   (substitute-key-definition
6678    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6679   (dolist (key '("\C-d" "\r" "\177" [delete]))
6680     (define-key gnus-dead-summary-mode-map
6681       key 'gnus-summary-wake-up-the-dead))
6682   (dolist (key '("q" "Q"))
6683     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6684
6685 (defvar gnus-dead-summary-mode nil
6686   "Minor mode for Gnus summary buffers.")
6687
6688 (defun gnus-dead-summary-mode (&optional arg)
6689   "Minor mode for Gnus summary buffers."
6690   (interactive "P")
6691   (when (eq major-mode 'gnus-summary-mode)
6692     (make-local-variable 'gnus-dead-summary-mode)
6693     (setq gnus-dead-summary-mode
6694           (if (null arg) (not gnus-dead-summary-mode)
6695             (> (prefix-numeric-value arg) 0)))
6696     (when gnus-dead-summary-mode
6697       (add-minor-mode
6698        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6699
6700 (defun gnus-deaden-summary ()
6701   "Make the current summary buffer into a dead summary buffer."
6702   ;; Kill any previous dead summary buffer.
6703   (when (and gnus-dead-summary
6704              (buffer-name gnus-dead-summary))
6705     (save-excursion
6706       (set-buffer gnus-dead-summary)
6707       (when gnus-dead-summary-mode
6708         (kill-buffer (current-buffer)))))
6709   ;; Make this the current dead summary.
6710   (setq gnus-dead-summary (current-buffer))
6711   (gnus-dead-summary-mode 1)
6712   (let ((name (buffer-name)))
6713     (when (string-match "Summary" name)
6714       (rename-buffer
6715        (concat (substring name 0 (match-beginning 0)) "Dead "
6716                (substring name (match-beginning 0)))
6717        t)
6718       (bury-buffer))))
6719
6720 (defun gnus-kill-or-deaden-summary (buffer)
6721   "Kill or deaden the summary BUFFER."
6722   (save-excursion
6723     (when (and (buffer-name buffer)
6724                (not gnus-single-article-buffer))
6725       (save-excursion
6726         (set-buffer buffer)
6727         (gnus-kill-buffer gnus-article-buffer)
6728         (gnus-kill-buffer gnus-original-article-buffer)))
6729     (cond
6730      ;; Kill the buffer.
6731      (gnus-kill-summary-on-exit
6732       (when (and gnus-use-trees
6733                  (gnus-buffer-exists-p buffer))
6734         (save-excursion
6735           (set-buffer buffer)
6736           (gnus-tree-close gnus-newsgroup-name)))
6737       (gnus-kill-buffer buffer))
6738      ;; Deaden the buffer.
6739      ((gnus-buffer-exists-p buffer)
6740       (save-excursion
6741         (set-buffer buffer)
6742         (gnus-deaden-summary))))))
6743
6744 (defun gnus-summary-wake-up-the-dead (&rest args)
6745   "Wake up the dead summary buffer."
6746   (interactive)
6747   (gnus-dead-summary-mode -1)
6748   (let ((name (buffer-name)))
6749     (when (string-match "Dead " name)
6750       (rename-buffer
6751        (concat (substring name 0 (match-beginning 0))
6752                (substring name (match-end 0)))
6753        t)))
6754   (gnus-message 3 "This dead summary is now alive again"))
6755
6756 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6757 (defun gnus-summary-fetch-faq (&optional faq-dir)
6758   "Fetch the FAQ for the current group.
6759 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6760 in."
6761   (interactive
6762    (list
6763     (when current-prefix-arg
6764       (completing-read
6765        "FAQ dir: " (and (listp gnus-group-faq-directory)
6766                         (mapcar (lambda (file) (list file))
6767                                 gnus-group-faq-directory))))))
6768   (let (gnus-faq-buffer)
6769     (when (setq gnus-faq-buffer
6770                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6771       (gnus-configure-windows 'summary-faq))))
6772
6773 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6774 (defun gnus-summary-describe-group (&optional force)
6775   "Describe the current newsgroup."
6776   (interactive "P")
6777   (gnus-group-describe-group force gnus-newsgroup-name))
6778
6779 (defun gnus-summary-describe-briefly ()
6780   "Describe summary mode commands briefly."
6781   (interactive)
6782   (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")))
6783
6784 ;; Walking around group mode buffer from summary mode.
6785
6786 (defun gnus-summary-next-group (&optional no-article target-group backward)
6787   "Exit current newsgroup and then select next unread newsgroup.
6788 If prefix argument NO-ARTICLE is non-nil, no article is selected
6789 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6790 previous group instead."
6791   (interactive "P")
6792   ;; Stop pre-fetching.
6793   (gnus-async-halt-prefetch)
6794   (let ((current-group gnus-newsgroup-name)
6795         (current-buffer (current-buffer))
6796         entered)
6797     ;; First we semi-exit this group to update Xrefs and all variables.
6798     ;; We can't do a real exit, because the window conf must remain
6799     ;; the same in case the user is prompted for info, and we don't
6800     ;; want the window conf to change before that...
6801     (gnus-summary-exit t)
6802     (while (not entered)
6803       ;; Then we find what group we are supposed to enter.
6804       (set-buffer gnus-group-buffer)
6805       (gnus-group-jump-to-group current-group)
6806       (setq target-group
6807             (or target-group
6808                 (if (eq gnus-keep-same-level 'best)
6809                     (gnus-summary-best-group gnus-newsgroup-name)
6810                   (gnus-summary-search-group backward gnus-keep-same-level))))
6811       (if (not target-group)
6812           ;; There are no further groups, so we return to the group
6813           ;; buffer.
6814           (progn
6815             (gnus-message 5 "Returning to the group buffer")
6816             (setq entered t)
6817             (when (gnus-buffer-live-p current-buffer)
6818               (set-buffer current-buffer)
6819               (gnus-summary-exit))
6820             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6821         ;; We try to enter the target group.
6822         (gnus-group-jump-to-group target-group)
6823         (let ((unreads (gnus-group-group-unread)))
6824           (if (and (or (eq t unreads)
6825                        (and unreads (not (zerop unreads))))
6826                    (gnus-summary-read-group
6827                     target-group nil no-article
6828                     (and (buffer-name current-buffer) current-buffer)
6829                     nil backward))
6830               (setq entered t)
6831             (setq current-group target-group
6832                   target-group nil)))))))
6833
6834 (defun gnus-summary-prev-group (&optional no-article)
6835   "Exit current newsgroup and then select previous unread newsgroup.
6836 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6837   (interactive "P")
6838   (gnus-summary-next-group no-article nil t))
6839
6840 ;; Walking around summary lines.
6841
6842 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6843   "Go to the first subject satisfying any non-nil constraint.
6844 If UNREAD is non-nil, the article should be unread.
6845 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6846 If UNSEEN is non-nil, the article should be unseen.
6847 Returns the article selected or nil if there are no matching articles."
6848   (interactive "P")
6849   (cond
6850    ;; Empty summary.
6851    ((null gnus-newsgroup-data)
6852     (gnus-message 3 "No articles in the group")
6853     nil)
6854    ;; Pick the first article.
6855    ((not (or unread undownloaded unseen))
6856     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6857     (gnus-data-number (car gnus-newsgroup-data)))
6858    ;; Find the first unread article.
6859    (t
6860     (let ((data gnus-newsgroup-data))
6861       (while (and data
6862                   (let ((num (gnus-data-number (car data))))
6863                     (or (memq num gnus-newsgroup-unfetched)
6864                         (not (or (and unread
6865                                       (memq num gnus-newsgroup-unreads))
6866                                  (and undownloaded
6867                                       (memq num gnus-newsgroup-undownloaded))
6868                                  (and unseen
6869                                       (memq num gnus-newsgroup-unseen)))))))
6870         (setq data (cdr data)))
6871       (prog1
6872           (if data
6873               (progn
6874                 (goto-char (gnus-data-pos (car data)))
6875                 (gnus-data-number (car data)))
6876             (gnus-message 3 "No more%s articles"
6877                           (let* ((r (when unread " unread"))
6878                                  (d (when undownloaded " undownloaded"))
6879                                  (s (when unseen " unseen"))
6880                                  (l (delq nil (list r d s))))
6881                             (cond ((= 3 (length l))
6882                                    (concat r "," d ", or" s))
6883                                   ((= 2 (length l))
6884                                    (concat (car l) ", or" (cadr l)))
6885                                   ((= 1 (length l))
6886                                    (car l))
6887                                   (t
6888                                    ""))))
6889             nil
6890             )
6891         (gnus-summary-position-point))))))
6892
6893 (defun gnus-summary-next-subject (n &optional unread dont-display)
6894   "Go to next N'th summary line.
6895 If N is negative, go to the previous N'th subject line.
6896 If UNREAD is non-nil, only unread articles are selected.
6897 The difference between N and the actual number of steps taken is
6898 returned."
6899   (interactive "p")
6900   (let ((backward (< n 0))
6901         (n (abs n)))
6902     (while (and (> n 0)
6903                 (if backward
6904                     (gnus-summary-find-prev unread)
6905                   (gnus-summary-find-next unread)))
6906       (unless (zerop (setq n (1- n)))
6907         (gnus-summary-show-thread)))
6908     (when (/= 0 n)
6909       (gnus-message 7 "No more%s articles"
6910                     (if unread " unread" "")))
6911     (unless dont-display
6912       (gnus-summary-recenter)
6913       (gnus-summary-position-point))
6914     n))
6915
6916 (defun gnus-summary-next-unread-subject (n)
6917   "Go to next N'th unread summary line."
6918   (interactive "p")
6919   (gnus-summary-next-subject n t))
6920
6921 (defun gnus-summary-prev-subject (n &optional unread)
6922   "Go to previous N'th summary line.
6923 If optional argument UNREAD is non-nil, only unread article is selected."
6924   (interactive "p")
6925   (gnus-summary-next-subject (- n) unread))
6926
6927 (defun gnus-summary-prev-unread-subject (n)
6928   "Go to previous N'th unread summary line."
6929   (interactive "p")
6930   (gnus-summary-next-subject (- n) t))
6931
6932 (defun gnus-summary-goto-subjects (articles)
6933   "Insert the subject header for ARTICLES in the current buffer."
6934   (save-excursion
6935     (dolist (article articles)
6936       (gnus-summary-goto-subject article t)))
6937   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6938   (gnus-summary-position-point))
6939  
6940 (defun gnus-summary-goto-subject (article &optional force silent)
6941   "Go the subject line of ARTICLE.
6942 If FORCE, also allow jumping to articles not currently shown."
6943   (interactive "nArticle number: ")
6944   (unless (numberp article)
6945     (error "Article %s is not a number" article))
6946   (let ((b (point))
6947         (data (gnus-data-find article)))
6948     ;; We read in the article if we have to.
6949     (and (not data)
6950          force
6951          (gnus-summary-insert-subject
6952           article
6953           (if (or (numberp force) (vectorp force)) force)
6954           t)
6955          (setq data (gnus-data-find article)))
6956     (goto-char b)
6957     (if (not data)
6958         (progn
6959           (unless silent
6960             (gnus-message 3 "Can't find article %d" article))
6961           nil)
6962       (let ((pt (gnus-data-pos data)))
6963         (goto-char pt)
6964         (gnus-summary-set-article-display-arrow pt))
6965       (gnus-summary-position-point)
6966       article)))
6967
6968 ;; Walking around summary lines with displaying articles.
6969
6970 (defun gnus-summary-expand-window (&optional arg)
6971   "Make the summary buffer take up the entire Emacs frame.
6972 Given a prefix, will force an `article' buffer configuration."
6973   (interactive "P")
6974   (if arg
6975       (gnus-configure-windows 'article 'force)
6976     (gnus-configure-windows 'summary 'force)))
6977
6978 (defun gnus-summary-display-article (article &optional all-header)
6979   "Display ARTICLE in article buffer."
6980   (when (gnus-buffer-live-p gnus-article-buffer)
6981     (with-current-buffer gnus-article-buffer
6982       (set-buffer-multibyte t)))
6983   (gnus-set-global-variables)
6984   (when (gnus-buffer-live-p gnus-article-buffer)
6985     (with-current-buffer gnus-article-buffer
6986       (setq gnus-article-charset gnus-newsgroup-charset)
6987       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6988       (set-buffer-multibyte t)))
6989   (if (null article)
6990       nil
6991     (prog1
6992         (if gnus-summary-display-article-function
6993             (funcall gnus-summary-display-article-function article all-header)
6994           (gnus-article-prepare article all-header))
6995       (with-current-buffer gnus-article-buffer
6996         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6997              nil))
6998       (gnus-run-hooks 'gnus-select-article-hook)
6999       (when (and gnus-current-article
7000                  (not (zerop gnus-current-article)))
7001         (gnus-summary-goto-subject gnus-current-article))
7002       (gnus-summary-recenter)
7003       (when (and gnus-use-trees gnus-show-threads)
7004         (gnus-possibly-generate-tree article)
7005         (gnus-highlight-selected-tree article))
7006       ;; Successfully display article.
7007       (gnus-article-set-window-start
7008        (cdr (assq article gnus-newsgroup-bookmarks))))))
7009
7010 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7011   "Select the current article.
7012 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7013 non-nil, the article will be re-fetched even if it already present in
7014 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7015 be displayed."
7016   ;; Make sure we are in the summary buffer to work around bbdb bug.
7017   (unless (eq major-mode 'gnus-summary-mode)
7018     (set-buffer gnus-summary-buffer))
7019   (let ((article (or article (gnus-summary-article-number)))
7020         (all-headers (not (not all-headers))) ;Must be T or NIL.
7021         gnus-summary-display-article-function)
7022     (and (not pseudo)
7023          (gnus-summary-article-pseudo-p article)
7024          (error "This is a pseudo-article"))
7025     (save-excursion
7026       (set-buffer gnus-summary-buffer)
7027       (if (or (and gnus-single-article-buffer
7028                    (or (null gnus-current-article)
7029                        (null gnus-article-current)
7030                        (null (get-buffer gnus-article-buffer))
7031                        (not (eq article (cdr gnus-article-current)))
7032                        (not (equal (car gnus-article-current)
7033                                    gnus-newsgroup-name))))
7034               (and (not gnus-single-article-buffer)
7035                    (or (null gnus-current-article)
7036                        (not (eq gnus-current-article article))))
7037               force)
7038           ;; The requested article is different from the current article.
7039           (progn
7040             (gnus-summary-display-article article all-headers)
7041             (gnus-article-set-window-start
7042              (cdr (assq article gnus-newsgroup-bookmarks)))
7043             article)
7044         'old))))
7045
7046 (defun gnus-summary-force-verify-and-decrypt ()
7047   "Display buttons for signed/encrypted parts and verify/decrypt them."
7048   (interactive)
7049   (let ((mm-verify-option 'known)
7050         (mm-decrypt-option 'known)
7051         (gnus-article-emulate-mime t)
7052         (gnus-buttonized-mime-types (append (list "multipart/signed"
7053                                                   "multipart/encrypted")
7054                                             gnus-buttonized-mime-types)))
7055     (gnus-summary-select-article nil 'force)))
7056
7057 (defun gnus-summary-set-current-mark (&optional current-mark)
7058   "Obsolete function."
7059   nil)
7060
7061 (defun gnus-summary-next-article (&optional unread subject backward push)
7062   "Select the next article.
7063 If UNREAD, only unread articles are selected.
7064 If SUBJECT, only articles with SUBJECT are selected.
7065 If BACKWARD, the previous article is selected instead of the next."
7066   (interactive "P")
7067   (cond
7068    ;; Is there such an article?
7069    ((and (gnus-summary-search-forward unread subject backward)
7070          (or (gnus-summary-display-article (gnus-summary-article-number))
7071              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7072     (gnus-summary-position-point))
7073    ;; If not, we try the first unread, if that is wanted.
7074    ((and subject
7075          gnus-auto-select-same
7076          (gnus-summary-first-unread-article))
7077     (gnus-summary-position-point)
7078     (gnus-message 6 "Wrapped"))
7079    ;; Try to get next/previous article not displayed in this group.
7080    ((and gnus-auto-extend-newsgroup
7081          (not unread) (not subject))
7082     (gnus-summary-goto-article
7083      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7084      nil (count-lines (point-min) (point))))
7085    ;; Go to next/previous group.
7086    (t
7087     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7088       (gnus-summary-jump-to-group gnus-newsgroup-name))
7089     (let ((cmd last-command-char)
7090           (point
7091            (save-excursion
7092              (set-buffer gnus-group-buffer)
7093              (point)))
7094           (group
7095            (if (eq gnus-keep-same-level 'best)
7096                (gnus-summary-best-group gnus-newsgroup-name)
7097              (gnus-summary-search-group backward gnus-keep-same-level))))
7098       ;; For some reason, the group window gets selected.  We change
7099       ;; it back.
7100       (select-window (get-buffer-window (current-buffer)))
7101       ;; Select next unread newsgroup automagically.
7102       (cond
7103        ((or (not gnus-auto-select-next)
7104             (not cmd))
7105         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7106        ((or (eq gnus-auto-select-next 'quietly)
7107             (and (eq gnus-auto-select-next 'slightly-quietly)
7108                  push)
7109             (and (eq gnus-auto-select-next 'almost-quietly)
7110                  (gnus-summary-last-article-p)))
7111         ;; Select quietly.
7112         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7113             (gnus-summary-exit)
7114           (gnus-message 7 "No more%s articles (%s)..."
7115                         (if unread " unread" "")
7116                         (if group (concat "selecting " group)
7117                           "exiting"))
7118           (gnus-summary-next-group nil group backward)))
7119        (t
7120         (when (gnus-key-press-event-p last-input-event)
7121           (gnus-summary-walk-group-buffer
7122            gnus-newsgroup-name cmd unread backward point))))))))
7123
7124 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7125   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7126                       (?\C-p (gnus-group-prev-unread-group 1))))
7127         (cursor-in-echo-area t)
7128         keve key group ended prompt)
7129     (save-excursion
7130       (set-buffer gnus-group-buffer)
7131       (goto-char start)
7132       (setq group
7133             (if (eq gnus-keep-same-level 'best)
7134                 (gnus-summary-best-group gnus-newsgroup-name)
7135               (gnus-summary-search-group backward gnus-keep-same-level))))
7136     (while (not ended)
7137       (setq prompt
7138             (format
7139              "No more%s articles%s " (if unread " unread" "")
7140              (if (and group
7141                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7142                  (format " (Type %s for %s [%s])"
7143                          (single-key-description cmd) group
7144                          (gnus-group-unread group))
7145                (format " (Type %s to exit %s)"
7146                        (single-key-description cmd)
7147                        gnus-newsgroup-name))))
7148       ;; Confirm auto selection.
7149       (setq key (car (setq keve (gnus-read-event-char prompt)))
7150             ended t)
7151       (cond
7152        ((assq key keystrokes)
7153         (let ((obuf (current-buffer)))
7154           (switch-to-buffer gnus-group-buffer)
7155           (when group
7156             (gnus-group-jump-to-group group))
7157           (eval (cadr (assq key keystrokes)))
7158           (setq group (gnus-group-group-name))
7159           (switch-to-buffer obuf))
7160         (setq ended nil))
7161        ((equal key cmd)
7162         (if (or (not group)
7163                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7164             (gnus-summary-exit)
7165           (gnus-summary-next-group nil group backward)))
7166        (t
7167         (push (cdr keve) unread-command-events))))))
7168
7169 (defun gnus-summary-next-unread-article ()
7170   "Select unread article after current one."
7171   (interactive)
7172   (gnus-summary-next-article
7173    (or (not (eq gnus-summary-goto-unread 'never))
7174        (gnus-summary-last-article-p (gnus-summary-article-number)))
7175    (and gnus-auto-select-same
7176         (gnus-summary-article-subject))))
7177
7178 (defun gnus-summary-prev-article (&optional unread subject)
7179   "Select the article after the current one.
7180 If UNREAD is non-nil, only unread articles are selected."
7181   (interactive "P")
7182   (gnus-summary-next-article unread subject t))
7183
7184 (defun gnus-summary-prev-unread-article ()
7185   "Select unread article before current one."
7186   (interactive)
7187   (gnus-summary-prev-article
7188    (or (not (eq gnus-summary-goto-unread 'never))
7189        (gnus-summary-first-article-p (gnus-summary-article-number)))
7190    (and gnus-auto-select-same
7191         (gnus-summary-article-subject))))
7192
7193 (defun gnus-summary-next-page (&optional lines circular stop)
7194   "Show next page of the selected article.
7195 If at the end of the current article, select the next article.
7196 LINES says how many lines should be scrolled up.
7197
7198 If CIRCULAR is non-nil, go to the start of the article instead of
7199 selecting the next article when reaching the end of the current
7200 article.
7201
7202 If STOP is non-nil, just stop when reaching the end of the message.
7203
7204 Also see the variable `gnus-article-skip-boring'."
7205   (interactive "P")
7206   (setq gnus-summary-buffer (current-buffer))
7207   (gnus-set-global-variables)
7208   (let ((article (gnus-summary-article-number))
7209         (article-window (get-buffer-window gnus-article-buffer t))
7210         endp)
7211     ;; If the buffer is empty, we have no article.
7212     (unless article
7213       (error "No article to select"))
7214     (gnus-configure-windows 'article)
7215     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7216         (if (and (eq gnus-summary-goto-unread 'never)
7217                  (not (gnus-summary-last-article-p article)))
7218             (gnus-summary-next-article)
7219           (gnus-summary-next-unread-article))
7220       (if (or (null gnus-current-article)
7221               (null gnus-article-current)
7222               (/= article (cdr gnus-article-current))
7223               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7224           ;; Selected subject is different from current article's.
7225           (gnus-summary-display-article article)
7226         (when article-window
7227           (gnus-eval-in-buffer-window gnus-article-buffer
7228             (setq endp (or (gnus-article-next-page lines)
7229                            (gnus-article-only-boring-p))))
7230           (when endp
7231             (cond (stop
7232                    (gnus-message 3 "End of message"))
7233                   (circular
7234                    (gnus-summary-beginning-of-article))
7235                   (lines
7236                    (gnus-message 3 "End of message"))
7237                   ((null lines)
7238                    (if (and (eq gnus-summary-goto-unread 'never)
7239                             (not (gnus-summary-last-article-p article)))
7240                        (gnus-summary-next-article)
7241                      (gnus-summary-next-unread-article))))))))
7242     (gnus-summary-recenter)
7243     (gnus-summary-position-point)))
7244
7245 (defun gnus-summary-prev-page (&optional lines move)
7246   "Show previous page of selected article.
7247 Argument LINES specifies lines to be scrolled down.
7248 If MOVE, move to the previous unread article if point is at
7249 the beginning of the buffer."
7250   (interactive "P")
7251   (let ((article (gnus-summary-article-number))
7252         (article-window (get-buffer-window gnus-article-buffer t))
7253         endp)
7254     (gnus-configure-windows 'article)
7255     (if (or (null gnus-current-article)
7256             (null gnus-article-current)
7257             (/= article (cdr gnus-article-current))
7258             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7259         ;; Selected subject is different from current article's.
7260         (gnus-summary-display-article article)
7261       (gnus-summary-recenter)
7262       (when article-window
7263         (gnus-eval-in-buffer-window gnus-article-buffer
7264           (setq endp (gnus-article-prev-page lines)))
7265         (when (and move endp)
7266           (cond (lines
7267                  (gnus-message 3 "Beginning of message"))
7268                 ((null lines)
7269                  (if (and (eq gnus-summary-goto-unread 'never)
7270                           (not (gnus-summary-first-article-p article)))
7271                      (gnus-summary-prev-article)
7272                    (gnus-summary-prev-unread-article))))))))
7273   (gnus-summary-position-point))
7274
7275 (defun gnus-summary-prev-page-or-article (&optional lines)
7276   "Show previous page of selected article.
7277 Argument LINES specifies lines to be scrolled down.
7278 If at the beginning of the article, go to the next article."
7279   (interactive "P")
7280   (gnus-summary-prev-page lines t))
7281
7282 (defun gnus-summary-scroll-up (lines)
7283   "Scroll up (or down) one line current article.
7284 Argument LINES specifies lines to be scrolled up (or down if negative)."
7285   (interactive "p")
7286   (gnus-configure-windows 'article)
7287   (gnus-summary-show-thread)
7288   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7289     (gnus-eval-in-buffer-window gnus-article-buffer
7290       (cond ((> lines 0)
7291              (when (gnus-article-next-page lines)
7292                (gnus-message 3 "End of message")))
7293             ((< lines 0)
7294              (gnus-article-prev-page (- lines))))))
7295   (gnus-summary-recenter)
7296   (gnus-summary-position-point))
7297
7298 (defun gnus-summary-scroll-down (lines)
7299   "Scroll down (or up) one line current article.
7300 Argument LINES specifies lines to be scrolled down (or up if negative)."
7301   (interactive "p")
7302   (gnus-summary-scroll-up (- lines)))
7303
7304 (defun gnus-summary-next-same-subject ()
7305   "Select next article which has the same subject as current one."
7306   (interactive)
7307   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7308
7309 (defun gnus-summary-prev-same-subject ()
7310   "Select previous article which has the same subject as current one."
7311   (interactive)
7312   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7313
7314 (defun gnus-summary-next-unread-same-subject ()
7315   "Select next unread article which has the same subject as current one."
7316   (interactive)
7317   (gnus-summary-next-article t (gnus-summary-article-subject)))
7318
7319 (defun gnus-summary-prev-unread-same-subject ()
7320   "Select previous unread article which has the same subject as current one."
7321   (interactive)
7322   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7323
7324 (defun gnus-summary-first-unread-article ()
7325   "Select the first unread article.
7326 Return nil if there are no unread articles."
7327   (interactive)
7328   (prog1
7329       (when (gnus-summary-first-subject t)
7330         (gnus-summary-show-thread)
7331         (gnus-summary-first-subject t)
7332         (gnus-summary-display-article (gnus-summary-article-number)))
7333     (gnus-summary-position-point)))
7334
7335 (defun gnus-summary-first-unread-subject ()
7336   "Place the point on the subject line of the first unread article.
7337 Return nil if there are no unread articles."
7338   (interactive)
7339   (prog1
7340       (when (gnus-summary-first-subject t)
7341         (gnus-summary-show-thread)
7342         (gnus-summary-first-subject t))
7343     (gnus-summary-position-point)))
7344
7345 (defun gnus-summary-first-unseen-subject ()
7346   "Place the point on the subject line of the first unseen article.
7347 Return nil if there are no unseen articles."
7348   (interactive)
7349   (prog1
7350       (when (gnus-summary-first-subject nil nil t)
7351         (gnus-summary-show-thread)
7352         (gnus-summary-first-subject nil nil t))
7353     (gnus-summary-position-point)))
7354
7355 (defun gnus-summary-first-unseen-or-unread-subject ()
7356   "Place the point on the subject line of the first unseen article or,
7357 if all article have been seen, on the subject line of the first unread
7358 article."
7359   (interactive)
7360   (prog1
7361       (unless (when (gnus-summary-first-subject nil nil t)
7362                 (gnus-summary-show-thread)
7363                 (gnus-summary-first-subject nil nil t))
7364         (when (gnus-summary-first-subject t)
7365           (gnus-summary-show-thread)
7366           (gnus-summary-first-subject t)))
7367     (gnus-summary-position-point)))
7368
7369 (defun gnus-summary-first-article ()
7370   "Select the first article.
7371 Return nil if there are no articles."
7372   (interactive)
7373   (prog1
7374       (when (gnus-summary-first-subject)
7375         (gnus-summary-show-thread)
7376         (gnus-summary-first-subject)
7377         (gnus-summary-display-article (gnus-summary-article-number)))
7378     (gnus-summary-position-point)))
7379
7380 (defun gnus-summary-best-unread-article (&optional arg)
7381   "Select the unread article with the highest score.
7382 If given a prefix argument, select the next unread article that has a
7383 score higher than the default score."
7384   (interactive "P")
7385   (let ((article (if arg
7386                      (gnus-summary-better-unread-subject)
7387                    (gnus-summary-best-unread-subject))))
7388     (if article
7389         (gnus-summary-goto-article article)
7390       (error "No unread articles"))))
7391
7392 (defun gnus-summary-best-unread-subject ()
7393   "Select the unread subject with the highest score."
7394   (interactive)
7395   (let ((best -1000000)
7396         (data gnus-newsgroup-data)
7397         article score)
7398     (while data
7399       (and (gnus-data-unread-p (car data))
7400            (> (setq score
7401                     (gnus-summary-article-score (gnus-data-number (car data))))
7402               best)
7403            (setq best score
7404                  article (gnus-data-number (car data))))
7405       (setq data (cdr data)))
7406     (when article
7407       (gnus-summary-goto-subject article))
7408     (gnus-summary-position-point)
7409     article))
7410
7411 (defun gnus-summary-better-unread-subject ()
7412   "Select the first unread subject that has a score over the default score."
7413   (interactive)
7414   (let ((data gnus-newsgroup-data)
7415         article score)
7416     (while (and (setq article (gnus-data-number (car data)))
7417                 (or (gnus-data-read-p (car data))
7418                     (not (> (gnus-summary-article-score article)
7419                             gnus-summary-default-score))))
7420       (setq data (cdr data)))
7421     (when article
7422       (gnus-summary-goto-subject article))
7423     (gnus-summary-position-point)
7424     article))
7425
7426 (defun gnus-summary-last-subject ()
7427   "Go to the last displayed subject line in the group."
7428   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7429     (when article
7430       (gnus-summary-goto-subject article))))
7431
7432 (defun gnus-summary-goto-article (article &optional all-headers force)
7433   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7434 If ALL-HEADERS is non-nil, no header lines are hidden.
7435 If FORCE, go to the article even if it isn't displayed.  If FORCE
7436 is a number, it is the line the article is to be displayed on."
7437   (interactive
7438    (list
7439     (completing-read
7440      "Article number or Message-ID: "
7441      (mapcar (lambda (number) (list (int-to-string number)))
7442              gnus-newsgroup-limit))
7443     current-prefix-arg
7444     t))
7445   (prog1
7446       (if (and (stringp article)
7447                (string-match "@\\|%40" article))
7448           (gnus-summary-refer-article article)
7449         (when (stringp article)
7450           (setq article (string-to-number article)))
7451         (if (gnus-summary-goto-subject article force)
7452             (gnus-summary-display-article article all-headers)
7453           (gnus-message 4 "Couldn't go to article %s" article) nil))
7454     (gnus-summary-position-point)))
7455
7456 (defun gnus-summary-goto-last-article ()
7457   "Go to the previously read article."
7458   (interactive)
7459   (prog1
7460       (when gnus-last-article
7461         (gnus-summary-goto-article gnus-last-article nil t))
7462     (gnus-summary-position-point)))
7463
7464 (defun gnus-summary-pop-article (number)
7465   "Pop one article off the history and go to the previous.
7466 NUMBER articles will be popped off."
7467   (interactive "p")
7468   (let (to)
7469     (setq gnus-newsgroup-history
7470           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7471     (if to
7472         (gnus-summary-goto-article (car to) nil t)
7473       (error "Article history empty")))
7474   (gnus-summary-position-point))
7475
7476 ;; Summary commands and functions for limiting the summary buffer.
7477
7478 (defun gnus-summary-limit-to-articles (n)
7479   "Limit the summary buffer to the next N articles.
7480 If not given a prefix, use the process marked articles instead."
7481   (interactive "P")
7482   (prog1
7483       (let ((articles (gnus-summary-work-articles n)))
7484         (setq gnus-newsgroup-processable nil)
7485         (gnus-summary-limit articles))
7486     (gnus-summary-position-point)))
7487
7488 (defun gnus-summary-pop-limit (&optional total)
7489   "Restore the previous limit.
7490 If given a prefix, remove all limits."
7491   (interactive "P")
7492   (when total
7493     (setq gnus-newsgroup-limits
7494           (list (mapcar (lambda (h) (mail-header-number h))
7495                         gnus-newsgroup-headers))))
7496   (unless gnus-newsgroup-limits
7497     (error "No limit to pop"))
7498   (prog1
7499       (gnus-summary-limit nil 'pop)
7500     (gnus-summary-position-point)))
7501
7502 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7503   "Limit the summary buffer to articles that have subjects that match a regexp.
7504 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7505   (interactive
7506    (list (read-string (if current-prefix-arg
7507                           "Exclude subject (regexp): "
7508                         "Limit to subject (regexp): "))
7509          nil current-prefix-arg))
7510   (unless header
7511     (setq header "subject"))
7512   (when (not (equal "" subject))
7513     (prog1
7514         (let ((articles (gnus-summary-find-matching
7515                          (or header "subject") subject 'all nil nil
7516                          not-matching)))
7517           (unless articles
7518             (error "Found no matches for \"%s\"" subject))
7519           (gnus-summary-limit articles))
7520       (gnus-summary-position-point))))
7521
7522 (defun gnus-summary-limit-to-author (from &optional not-matching)
7523   "Limit the summary buffer to articles that have authors that match a regexp.
7524 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7525   (interactive
7526    (list (read-string (if current-prefix-arg
7527                           "Exclude author (regexp): "
7528                         "Limit to author (regexp): "))
7529          current-prefix-arg))
7530   (gnus-summary-limit-to-subject from "from" not-matching))
7531
7532 (defun gnus-summary-limit-to-age (age &optional younger-p)
7533   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7534 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7535 articles that are younger than AGE days."
7536   (interactive
7537    (let ((younger current-prefix-arg)
7538          (days-got nil)
7539          days)
7540      (while (not days-got)
7541        (setq days (if younger
7542                       (read-string "Limit to articles younger than (in days, older when negative): ")
7543                     (read-string
7544                      "Limit to articles older than (in days, younger when negative): ")))
7545        (when (> (length days) 0)
7546          (setq days (read days)))
7547        (if (numberp days)
7548            (progn
7549              (setq days-got t)
7550              (if (< days 0)
7551                  (progn
7552                    (setq younger (not younger))
7553                    (setq days (* days -1)))))
7554          (message "Please enter a number.")
7555          (sleep-for 1)))
7556      (list days younger)))
7557   (prog1
7558       (let ((data gnus-newsgroup-data)
7559             (cutoff (days-to-time age))
7560             articles d date is-younger)
7561         (while (setq d (pop data))
7562           (when (and (vectorp (gnus-data-header d))
7563                      (setq date (mail-header-date (gnus-data-header d))))
7564             (setq is-younger (time-less-p
7565                               (time-since (condition-case ()
7566                                               (date-to-time date)
7567                                             (error '(0 0))))
7568                               cutoff))
7569             (when (if younger-p
7570                       is-younger
7571                     (not is-younger))
7572               (push (gnus-data-number d) articles))))
7573         (gnus-summary-limit (nreverse articles)))
7574     (gnus-summary-position-point)))
7575
7576 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7577   "Limit the summary buffer to articles that match an 'extra' header."
7578   (interactive
7579    (let ((header
7580           (intern
7581            (gnus-completing-read-with-default
7582             (symbol-name (car gnus-extra-headers))
7583             (if current-prefix-arg
7584                 "Exclude extra header:"
7585               "Limit extra header:")
7586             (mapcar (lambda (x)
7587                       (cons (symbol-name x) x))
7588                     gnus-extra-headers)
7589             nil
7590             t))))
7591      (list header
7592            (read-string (format "%s header %s (regexp): "
7593                                 (if current-prefix-arg "Exclude" "Limit to")
7594                                 header))
7595            current-prefix-arg)))
7596   (when (not (equal "" regexp))
7597     (prog1
7598         (let ((articles (gnus-summary-find-matching
7599                          (cons 'extra header) regexp 'all nil nil
7600                          not-matching)))
7601           (unless articles
7602             (error "Found no matches for \"%s\"" regexp))
7603           (gnus-summary-limit articles))
7604       (gnus-summary-position-point))))
7605
7606 (defun gnus-summary-limit-to-display-predicate ()
7607   "Limit the summary buffer to the predicated in the `display' group parameter."
7608   (interactive)
7609   (unless gnus-newsgroup-display
7610     (error "There is no `display' group parameter"))
7611   (let (articles)
7612     (dolist (number gnus-newsgroup-articles)
7613       (when (funcall gnus-newsgroup-display)
7614         (push number articles)))
7615     (gnus-summary-limit articles))
7616   (gnus-summary-position-point))
7617
7618 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7619 (make-obsolete
7620  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7621
7622 (defun gnus-summary-limit-to-unread (&optional all)
7623   "Limit the summary buffer to articles that are not marked as read.
7624 If ALL is non-nil, limit strictly to unread articles."
7625   (interactive "P")
7626   (if all
7627       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7628     (gnus-summary-limit-to-marks
7629      ;; Concat all the marks that say that an article is read and have
7630      ;; those removed.
7631      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7632            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7633            gnus-low-score-mark gnus-expirable-mark
7634            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7635            gnus-duplicate-mark gnus-souped-mark)
7636      'reverse)))
7637
7638 (defun gnus-summary-limit-to-replied (&optional unreplied)
7639   "Limit the summary buffer to replied articles.
7640 If UNREPLIED (the prefix), limit to unreplied articles."
7641   (interactive "P")
7642   (if unreplied
7643       (gnus-summary-limit
7644        (gnus-set-difference gnus-newsgroup-articles
7645         gnus-newsgroup-replied))
7646     (gnus-summary-limit gnus-newsgroup-replied))
7647   (gnus-summary-position-point))
7648
7649 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7650 (make-obsolete 'gnus-summary-delete-marked-with
7651                'gnus-summary-limit-exclude-marks)
7652
7653 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7654   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7655 If REVERSE, limit the summary buffer to articles that are marked
7656 with MARKS.  MARKS can either be a string of marks or a list of marks.
7657 Returns how many articles were removed."
7658   (interactive "sMarks: ")
7659   (gnus-summary-limit-to-marks marks t))
7660
7661 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7662   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7663 If REVERSE (the prefix), limit the summary buffer to articles that are
7664 not marked with MARKS.  MARKS can either be a string of marks or a
7665 list of marks.
7666 Returns how many articles were removed."
7667   (interactive "sMarks: \nP")
7668   (prog1
7669       (let ((data gnus-newsgroup-data)
7670             (marks (if (listp marks) marks
7671                      (append marks nil))) ; Transform to list.
7672             articles)
7673         (while data
7674           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7675                   (memq (gnus-data-mark (car data)) marks))
7676             (push (gnus-data-number (car data)) articles))
7677           (setq data (cdr data)))
7678         (gnus-summary-limit articles))
7679     (gnus-summary-position-point)))
7680
7681 (defun gnus-summary-limit-to-score (score)
7682   "Limit to articles with score at or above SCORE."
7683   (interactive "NLimit to articles with score of at least: ")
7684   (let ((data gnus-newsgroup-data)
7685         articles)
7686     (while data
7687       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7688                 score)
7689         (push (gnus-data-number (car data)) articles))
7690       (setq data (cdr data)))
7691     (prog1
7692         (gnus-summary-limit articles)
7693       (gnus-summary-position-point))))
7694
7695 (defun gnus-summary-limit-to-unseen ()
7696   "Limit to unseen articles."
7697   (interactive)
7698   (prog1
7699       (gnus-summary-limit gnus-newsgroup-unseen)
7700     (gnus-summary-position-point)))
7701
7702 (defun gnus-summary-limit-include-thread (id)
7703   "Display all the hidden articles that is in the thread with ID in it.
7704 When called interactively, ID is the Message-ID of the current
7705 article."
7706   (interactive (list (mail-header-id (gnus-summary-article-header))))
7707   (let ((articles (gnus-articles-in-thread
7708                    (gnus-id-to-thread (gnus-root-id id)))))
7709     (prog1
7710         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7711       (gnus-summary-limit-include-matching-articles
7712        "subject"
7713        (regexp-quote (gnus-simplify-subject-re
7714                       (mail-header-subject (gnus-id-to-header id)))))
7715       (gnus-summary-position-point))))
7716
7717 (defun gnus-summary-limit-include-matching-articles (header regexp)
7718   "Display all the hidden articles that have HEADERs that match REGEXP."
7719   (interactive (list (read-string "Match on header: ")
7720                      (read-string "Regexp: ")))
7721   (let ((articles (gnus-find-matching-articles header regexp)))
7722     (prog1
7723         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7724       (gnus-summary-position-point))))
7725
7726 (defun gnus-summary-insert-dormant-articles ()
7727   "Insert all the dormant articles for this group into the current buffer."
7728   (interactive)
7729   (let ((gnus-verbose (max 6 gnus-verbose)))
7730     (if (not gnus-newsgroup-dormant)
7731         (gnus-message 3 "No cached articles for this group")
7732       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7733
7734 (defun gnus-summary-limit-include-dormant ()
7735   "Display all the hidden articles that are marked as dormant.
7736 Note that this command only works on a subset of the articles currently
7737 fetched for this group."
7738   (interactive)
7739   (unless gnus-newsgroup-dormant
7740     (error "There are no dormant articles in this group"))
7741   (prog1
7742       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7743     (gnus-summary-position-point)))
7744
7745 (defun gnus-summary-limit-exclude-dormant ()
7746   "Hide all dormant articles."
7747   (interactive)
7748   (prog1
7749       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7750     (gnus-summary-position-point)))
7751
7752 (defun gnus-summary-limit-exclude-childless-dormant ()
7753   "Hide all dormant articles that have no children."
7754   (interactive)
7755   (let ((data (gnus-data-list t))
7756         articles d children)
7757     ;; Find all articles that are either not dormant or have
7758     ;; children.
7759     (while (setq d (pop data))
7760       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7761                 (and (setq children
7762                            (gnus-article-children (gnus-data-number d)))
7763                      (let (found)
7764                        (while children
7765                          (when (memq (car children) articles)
7766                            (setq children nil
7767                                  found t))
7768                          (pop children))
7769                        found)))
7770         (push (gnus-data-number d) articles)))
7771     ;; Do the limiting.
7772     (prog1
7773         (gnus-summary-limit articles)
7774       (gnus-summary-position-point))))
7775
7776 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7777   "Mark all unread excluded articles as read.
7778 If ALL, mark even excluded ticked and dormants as read."
7779   (interactive "P")
7780   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7781   (let ((articles (gnus-sorted-ndifference
7782                    (sort
7783                     (mapcar (lambda (h) (mail-header-number h))
7784                             gnus-newsgroup-headers)
7785                     '<)
7786                    gnus-newsgroup-limit))
7787         article)
7788     (setq gnus-newsgroup-unreads
7789           (gnus-sorted-intersection gnus-newsgroup-unreads
7790                                     gnus-newsgroup-limit))
7791     (if all
7792         (setq gnus-newsgroup-dormant nil
7793               gnus-newsgroup-marked nil
7794               gnus-newsgroup-reads
7795               (nconc
7796                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7797                gnus-newsgroup-reads))
7798       (while (setq article (pop articles))
7799         (unless (or (memq article gnus-newsgroup-dormant)
7800                     (memq article gnus-newsgroup-marked))
7801           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7802
7803 (defun gnus-summary-limit (articles &optional pop)
7804   (if pop
7805       ;; We pop the previous limit off the stack and use that.
7806       (setq articles (car gnus-newsgroup-limits)
7807             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7808     ;; We use the new limit, so we push the old limit on the stack.
7809     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7810   ;; Set the limit.
7811   (setq gnus-newsgroup-limit articles)
7812   (let ((total (length gnus-newsgroup-data))
7813         (data (gnus-data-find-list (gnus-summary-article-number)))
7814         (gnus-summary-mark-below nil)   ; Inhibit this.
7815         found)
7816     ;; This will do all the work of generating the new summary buffer
7817     ;; according to the new limit.
7818     (gnus-summary-prepare)
7819     ;; Hide any threads, possibly.
7820     (gnus-summary-maybe-hide-threads)
7821     ;; Try to return to the article you were at, or one in the
7822     ;; neighborhood.
7823     (when data
7824       ;; We try to find some article after the current one.
7825       (while data
7826         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7827           (setq data nil
7828                 found t))
7829         (setq data (cdr data))))
7830     (unless found
7831       ;; If there is no data, that means that we were after the last
7832       ;; article.  The same goes when we can't find any articles
7833       ;; after the current one.
7834       (goto-char (point-max))
7835       (gnus-summary-find-prev))
7836     (gnus-set-mode-line 'summary)
7837     ;; We return how many articles were removed from the summary
7838     ;; buffer as a result of the new limit.
7839     (- total (length gnus-newsgroup-data))))
7840
7841 (defsubst gnus-invisible-cut-children (threads)
7842   (let ((num 0))
7843     (while threads
7844       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7845         (incf num))
7846       (pop threads))
7847     (< num 2)))
7848
7849 (defsubst gnus-cut-thread (thread)
7850   "Go forwards in the thread until we find an article that we want to display."
7851   (when (or (eq gnus-fetch-old-headers 'some)
7852             (eq gnus-fetch-old-headers 'invisible)
7853             (numberp gnus-fetch-old-headers)
7854             (eq gnus-build-sparse-threads 'some)
7855             (eq gnus-build-sparse-threads 'more))
7856     ;; Deal with old-fetched headers and sparse threads.
7857     (while (and
7858             thread
7859             (or
7860              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7861              (gnus-summary-article-ancient-p
7862               (mail-header-number (car thread))))
7863             (if (or (<= (length (cdr thread)) 1)
7864                     (eq gnus-fetch-old-headers 'invisible))
7865                 (setq gnus-newsgroup-limit
7866                       (delq (mail-header-number (car thread))
7867                             gnus-newsgroup-limit)
7868                       thread (cadr thread))
7869               (when (gnus-invisible-cut-children (cdr thread))
7870                 (let ((th (cdr thread)))
7871                   (while th
7872                     (if (memq (mail-header-number (caar th))
7873                               gnus-newsgroup-limit)
7874                         (setq thread (car th)
7875                               th nil)
7876                       (setq th (cdr th))))))))))
7877   thread)
7878
7879 (defun gnus-cut-threads (threads)
7880   "Cut off all uninteresting articles from the beginning of THREADS."
7881   (when (or (eq gnus-fetch-old-headers 'some)
7882             (eq gnus-fetch-old-headers 'invisible)
7883             (numberp gnus-fetch-old-headers)
7884             (eq gnus-build-sparse-threads 'some)
7885             (eq gnus-build-sparse-threads 'more))
7886     (let ((th threads))
7887       (while th
7888         (setcar th (gnus-cut-thread (car th)))
7889         (setq th (cdr th)))))
7890   ;; Remove nixed out threads.
7891   (delq nil threads))
7892
7893 (defun gnus-summary-initial-limit (&optional show-if-empty)
7894   "Figure out what the initial limit is supposed to be on group entry.
7895 This entails weeding out unwanted dormants, low-scored articles,
7896 fetch-old-headers verbiage, and so on."
7897   ;; Most groups have nothing to remove.
7898   (if (or gnus-inhibit-limiting
7899           (and (null gnus-newsgroup-dormant)
7900                (eq gnus-newsgroup-display 'gnus-not-ignore)
7901                (not (eq gnus-fetch-old-headers 'some))
7902                (not (numberp gnus-fetch-old-headers))
7903                (not (eq gnus-fetch-old-headers 'invisible))
7904                (null gnus-summary-expunge-below)
7905                (not (eq gnus-build-sparse-threads 'some))
7906                (not (eq gnus-build-sparse-threads 'more))
7907                (null gnus-thread-expunge-below)
7908                (not gnus-use-nocem)))
7909       ()                                ; Do nothing.
7910     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7911     (setq gnus-newsgroup-limit nil)
7912     (mapatoms
7913      (lambda (node)
7914        (unless (car (symbol-value node))
7915          ;; These threads have no parents -- they are roots.
7916          (let ((nodes (cdr (symbol-value node)))
7917                thread)
7918            (while nodes
7919              (if (and gnus-thread-expunge-below
7920                       (< (gnus-thread-total-score (car nodes))
7921                          gnus-thread-expunge-below))
7922                  (gnus-expunge-thread (pop nodes))
7923                (setq thread (pop nodes))
7924                (gnus-summary-limit-children thread))))))
7925      gnus-newsgroup-dependencies)
7926     ;; If this limitation resulted in an empty group, we might
7927     ;; pop the previous limit and use it instead.
7928     (when (and (not gnus-newsgroup-limit)
7929                show-if-empty)
7930       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7931     gnus-newsgroup-limit))
7932
7933 (defun gnus-summary-limit-children (thread)
7934   "Return 1 if this subthread is visible and 0 if it is not."
7935   ;; First we get the number of visible children to this thread.  This
7936   ;; is done by recursing down the thread using this function, so this
7937   ;; will really go down to a leaf article first, before slowly
7938   ;; working its way up towards the root.
7939   (when thread
7940     (let* ((max-lisp-eval-depth 5000)
7941            (children
7942            (if (cdr thread)
7943                (apply '+ (mapcar 'gnus-summary-limit-children
7944                                  (cdr thread)))
7945              0))
7946           (number (mail-header-number (car thread)))
7947           score)
7948       (if (and
7949            (not (memq number gnus-newsgroup-marked))
7950            (or
7951             ;; If this article is dormant and has absolutely no visible
7952             ;; children, then this article isn't visible.
7953             (and (memq number gnus-newsgroup-dormant)
7954                  (zerop children))
7955             ;; If this is "fetch-old-headered" and there is no
7956             ;; visible children, then we don't want this article.
7957             (and (or (eq gnus-fetch-old-headers 'some)
7958                      (numberp gnus-fetch-old-headers))
7959                  (gnus-summary-article-ancient-p number)
7960                  (zerop children))
7961             ;; If this is "fetch-old-headered" and `invisible', then
7962             ;; we don't want this article.
7963             (and (eq gnus-fetch-old-headers 'invisible)
7964                  (gnus-summary-article-ancient-p number))
7965             ;; If this is a sparsely inserted article with no children,
7966             ;; we don't want it.
7967             (and (eq gnus-build-sparse-threads 'some)
7968                  (gnus-summary-article-sparse-p number)
7969                  (zerop children))
7970             ;; If we use expunging, and this article is really
7971             ;; low-scored, then we don't want this article.
7972             (when (and gnus-summary-expunge-below
7973                        (< (setq score
7974                                 (or (cdr (assq number gnus-newsgroup-scored))
7975                                     gnus-summary-default-score))
7976                           gnus-summary-expunge-below))
7977               ;; We increase the expunge-tally here, but that has
7978               ;; nothing to do with the limits, really.
7979               (incf gnus-newsgroup-expunged-tally)
7980               ;; We also mark as read here, if that's wanted.
7981               (when (and gnus-summary-mark-below
7982                          (< score gnus-summary-mark-below))
7983                 (setq gnus-newsgroup-unreads
7984                       (delq number gnus-newsgroup-unreads))
7985                 (if gnus-newsgroup-auto-expire
7986                     (push number gnus-newsgroup-expirable)
7987                   (push (cons number gnus-low-score-mark)
7988                         gnus-newsgroup-reads)))
7989               t)
7990             ;; Do the `display' group parameter.
7991             (and gnus-newsgroup-display
7992                  (not (funcall gnus-newsgroup-display)))
7993             ;; Check NoCeM things.
7994             (if (and gnus-use-nocem
7995                      (gnus-nocem-unwanted-article-p
7996                       (mail-header-id (car thread))))
7997                 (progn
7998                   (setq gnus-newsgroup-unreads
7999                         (delq number gnus-newsgroup-unreads))
8000                   t))))
8001           ;; Nope, invisible article.
8002           0
8003         ;; Ok, this article is to be visible, so we add it to the limit
8004         ;; and return 1.
8005         (push number gnus-newsgroup-limit)
8006         1))))
8007
8008 (defun gnus-expunge-thread (thread)
8009   "Mark all articles in THREAD as read."
8010   (let* ((number (mail-header-number (car thread))))
8011     (incf gnus-newsgroup-expunged-tally)
8012     ;; We also mark as read here, if that's wanted.
8013     (setq gnus-newsgroup-unreads
8014           (delq number gnus-newsgroup-unreads))
8015     (if gnus-newsgroup-auto-expire
8016         (push number gnus-newsgroup-expirable)
8017       (push (cons number gnus-low-score-mark)
8018             gnus-newsgroup-reads)))
8019   ;; Go recursively through all subthreads.
8020   (mapcar 'gnus-expunge-thread (cdr thread)))
8021
8022 ;; Summary article oriented commands
8023
8024 (defun gnus-summary-refer-parent-article (n)
8025   "Refer parent article N times.
8026 If N is negative, go to ancestor -N instead.
8027 The difference between N and the number of articles fetched is returned."
8028   (interactive "p")
8029   (let ((skip 1)
8030         error header ref)
8031     (when (not (natnump n))
8032       (setq skip (abs n)
8033             n 1))
8034     (while (and (> n 0)
8035                 (not error))
8036       (setq header (gnus-summary-article-header))
8037       (if (and (eq (mail-header-number header)
8038                    (cdr gnus-article-current))
8039                (equal gnus-newsgroup-name
8040                       (car gnus-article-current)))
8041           ;; If we try to find the parent of the currently
8042           ;; displayed article, then we take a look at the actual
8043           ;; References header, since this is slightly more
8044           ;; reliable than the References field we got from the
8045           ;; server.
8046           (save-excursion
8047             (set-buffer gnus-original-article-buffer)
8048             (nnheader-narrow-to-headers)
8049             (unless (setq ref (message-fetch-field "references"))
8050               (when (setq ref (message-fetch-field "in-reply-to"))
8051                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8052             (widen))
8053         (setq ref
8054               ;; It's not the current article, so we take a bet on
8055               ;; the value we got from the server.
8056               (mail-header-references header)))
8057       (if (and ref
8058                (not (equal ref "")))
8059           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8060             (gnus-message 1 "Couldn't find parent"))
8061         (gnus-message 1 "No references in article %d"
8062                       (gnus-summary-article-number))
8063         (setq error t))
8064       (decf n))
8065     (gnus-summary-position-point)
8066     n))
8067
8068 (defun gnus-summary-refer-references ()
8069   "Fetch all articles mentioned in the References header.
8070 Return the number of articles fetched."
8071   (interactive)
8072   (let ((ref (mail-header-references (gnus-summary-article-header)))
8073         (current (gnus-summary-article-number))
8074         (n 0))
8075     (if (or (not ref)
8076             (equal ref ""))
8077         (error "No References in the current article")
8078       ;; For each Message-ID in the References header...
8079       (while (string-match "<[^>]*>" ref)
8080         (incf n)
8081         ;; ... fetch that article.
8082         (gnus-summary-refer-article
8083          (prog1 (match-string 0 ref)
8084            (setq ref (substring ref (match-end 0))))))
8085       (gnus-summary-goto-subject current)
8086       (gnus-summary-position-point)
8087       n)))
8088
8089 (defun gnus-summary-refer-thread (&optional limit)
8090   "Fetch all articles in the current thread.
8091 If LIMIT (the numerical prefix), fetch that many old headers instead
8092 of what's specified by the `gnus-refer-thread-limit' variable."
8093   (interactive "P")
8094   (let ((id (mail-header-id (gnus-summary-article-header)))
8095         (limit (if limit (prefix-numeric-value limit)
8096                  gnus-refer-thread-limit)))
8097     (unless (eq gnus-fetch-old-headers 'invisible)
8098       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8099       ;; Retrieve the headers and read them in.
8100       (if (eq (if (numberp limit)
8101                   (gnus-retrieve-headers
8102                    (list (min
8103                           (+ (mail-header-number
8104                               (gnus-summary-article-header))
8105                              limit)
8106                           gnus-newsgroup-end))
8107                    gnus-newsgroup-name (* limit 2))
8108                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8109                 ;; headers.
8110                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8111                                        gnus-newsgroup-name limit))
8112               'nov)
8113           (gnus-build-all-threads)
8114         (error "Can't fetch thread from back ends that don't support NOV"))
8115       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8116     (gnus-summary-limit-include-thread id)))
8117
8118 (defun gnus-summary-refer-article (message-id)
8119   "Fetch an article specified by MESSAGE-ID."
8120   (interactive "sMessage-ID: ")
8121   (when (and (stringp message-id)
8122              (not (zerop (length message-id))))
8123     (setq message-id (gnus-replace-in-string message-id " " ""))
8124     ;; Construct the correct Message-ID if necessary.
8125     ;; Suggested by tale@pawl.rpi.edu.
8126     (unless (string-match "^<" message-id)
8127       (setq message-id (concat "<" message-id)))
8128     (unless (string-match ">$" message-id)
8129       (setq message-id (concat message-id ">")))
8130     ;; People often post MIDs from URLs, so unhex it:
8131     (unless (string-match "@" message-id)
8132       (setq message-id (gnus-url-unhex-string message-id)))
8133     (let* ((header (gnus-id-to-header message-id))
8134            (sparse (and header
8135                         (gnus-summary-article-sparse-p
8136                          (mail-header-number header))
8137                         (memq (mail-header-number header)
8138                               gnus-newsgroup-limit)))
8139            number)
8140       (cond
8141        ;; If the article is present in the buffer we just go to it.
8142        ((and header
8143              (or (not (gnus-summary-article-sparse-p
8144                        (mail-header-number header)))
8145                  sparse))
8146         (prog1
8147             (gnus-summary-goto-article
8148              (mail-header-number header) nil t)
8149           (when sparse
8150             (gnus-summary-update-article (mail-header-number header)))))
8151        (t
8152         ;; We fetch the article.
8153         (catch 'found
8154           (dolist (gnus-override-method (gnus-refer-article-methods))
8155             (when (and (gnus-check-server gnus-override-method)
8156                        ;; Fetch the header,
8157                        (setq number (gnus-summary-insert-subject message-id)))
8158               ;; and display the article.
8159               (gnus-summary-select-article nil nil nil number)
8160               (throw 'found t)))
8161           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8162
8163 (defun gnus-refer-article-methods ()
8164   "Return a list of referable methods."
8165   (cond
8166    ;; No method, so we default to current and native.
8167    ((null gnus-refer-article-method)
8168     (list gnus-current-select-method gnus-select-method))
8169    ;; Current.
8170    ((eq 'current gnus-refer-article-method)
8171     (list gnus-current-select-method))
8172    ;; List of select methods.
8173    ((not (and (symbolp (car gnus-refer-article-method))
8174               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8175     (let (out)
8176       (dolist (method gnus-refer-article-method)
8177         (push (if (eq 'current method)
8178                   gnus-current-select-method
8179                 method)
8180               out))
8181       (nreverse out)))
8182    ;; One single select method.
8183    (t
8184     (list gnus-refer-article-method))))
8185
8186 (defun gnus-summary-edit-parameters ()
8187   "Edit the group parameters of the current group."
8188   (interactive)
8189   (gnus-group-edit-group gnus-newsgroup-name 'params))
8190
8191 (defun gnus-summary-customize-parameters ()
8192   "Customize the group parameters of the current group."
8193   (interactive)
8194   (gnus-group-customize gnus-newsgroup-name))
8195
8196 (defun gnus-summary-enter-digest-group (&optional force)
8197   "Enter an nndoc group based on the current article.
8198 If FORCE, force a digest interpretation.  If not, try
8199 to guess what the document format is."
8200   (interactive "P")
8201   (let ((conf gnus-current-window-configuration))
8202     (save-window-excursion
8203       (save-excursion
8204         (let (gnus-article-prepare-hook
8205               gnus-display-mime-function
8206               gnus-break-pages)
8207           (gnus-summary-select-article))))
8208     (setq gnus-current-window-configuration conf)
8209     (let* ((name (format "%s-%d"
8210                          (gnus-group-prefixed-name
8211                           gnus-newsgroup-name (list 'nndoc ""))
8212                          (save-excursion
8213                            (set-buffer gnus-summary-buffer)
8214                            gnus-current-article)))
8215            (ogroup gnus-newsgroup-name)
8216            (params (append (gnus-info-params (gnus-get-info ogroup))
8217                            (list (cons 'to-group ogroup))
8218                            (list (cons 'parent-group ogroup))
8219                            (list (cons 'save-article-group ogroup))))
8220            (case-fold-search t)
8221            (buf (current-buffer))
8222            dig to-address)
8223       (save-excursion
8224         (set-buffer gnus-original-article-buffer)
8225         ;; Have the digest group inherit the main mail address of
8226         ;; the parent article.
8227         (when (setq to-address (or (gnus-fetch-field "reply-to")
8228                                    (gnus-fetch-field "from")))
8229           (setq params (append
8230                         (list (cons 'to-address
8231                                     (funcall gnus-decode-encoded-word-function
8232                                              to-address))))))
8233         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8234         (insert-buffer-substring gnus-original-article-buffer)
8235         ;; Remove lines that may lead nndoc to misinterpret the
8236         ;; document type.
8237         (narrow-to-region
8238          (goto-char (point-min))
8239          (or (search-forward "\n\n" nil t) (point)))
8240         (goto-char (point-min))
8241         (delete-matching-lines "^Path:\\|^From ")
8242         (widen))
8243       (unwind-protect
8244           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8245                     (gnus-newsgroup-ephemeral-ignored-charsets
8246                      gnus-newsgroup-ignored-charsets))
8247                 (gnus-group-read-ephemeral-group
8248                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8249                               (nndoc-article-type
8250                                ,(if force 'mbox 'guess)))
8251                  t nil nil nil
8252                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8253                                                         "ADAPT")))))
8254               ;; Make all postings to this group go to the parent group.
8255               (nconc (gnus-info-params (gnus-get-info name))
8256                      params)
8257             ;; Couldn't select this doc group.
8258             (switch-to-buffer buf)
8259             (gnus-set-global-variables)
8260             (gnus-configure-windows 'summary)
8261             (gnus-message 3 "Article couldn't be entered?"))
8262         (kill-buffer dig)))))
8263
8264 (defun gnus-summary-read-document (n)
8265   "Open a new group based on the current article(s).
8266 This will allow you to read digests and other similar
8267 documents as newsgroups.
8268 Obeys the standard process/prefix convention."
8269   (interactive "P")
8270   (let* ((articles (gnus-summary-work-articles n))
8271          (ogroup gnus-newsgroup-name)
8272          (params (append (gnus-info-params (gnus-get-info ogroup))
8273                          (list (cons 'to-group ogroup))))
8274          article group egroup groups vgroup)
8275     (while (setq article (pop articles))
8276       (setq group (format "%s-%d" gnus-newsgroup-name article))
8277       (gnus-summary-remove-process-mark article)
8278       (when (gnus-summary-display-article article)
8279         (save-excursion
8280           (with-temp-buffer
8281             (insert-buffer-substring gnus-original-article-buffer)
8282             ;; Remove some headers that may lead nndoc to make
8283             ;; the wrong guess.
8284             (message-narrow-to-head)
8285             (goto-char (point-min))
8286             (delete-matching-lines "^Path:\\|^From ")
8287             (widen)
8288             (if (setq egroup
8289                       (gnus-group-read-ephemeral-group
8290                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8291                                      (nndoc-article-type guess))
8292                        t nil t))
8293                 (progn
8294                   ;; Make all postings to this group go to the parent group.
8295                   (nconc (gnus-info-params (gnus-get-info egroup))
8296                          params)
8297                   (push egroup groups))
8298               ;; Couldn't select this doc group.
8299               (gnus-error 3 "Article couldn't be entered"))))))
8300     ;; Now we have selected all the documents.
8301     (cond
8302      ((not groups)
8303       (error "None of the articles could be interpreted as documents"))
8304      ((gnus-group-read-ephemeral-group
8305        (setq vgroup (format
8306                      "nnvirtual:%s-%s" gnus-newsgroup-name
8307                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8308        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8309        t
8310        (cons (current-buffer) 'summary)))
8311      (t
8312       (error "Couldn't select virtual nndoc group")))))
8313
8314 (defun gnus-summary-isearch-article (&optional regexp-p)
8315   "Do incremental search forward on the current article.
8316 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8317   (interactive "P")
8318   (let* ((gnus-inhibit-treatment t)
8319          (old (gnus-summary-select-article)))
8320     (gnus-configure-windows 'article)
8321     (gnus-eval-in-buffer-window gnus-article-buffer
8322       (save-restriction
8323         (widen)
8324         (when (eq 'old old)
8325           (gnus-article-show-all-headers))
8326         (goto-char (point-min))
8327         (isearch-forward regexp-p)))))
8328
8329 (defun gnus-summary-search-article-forward (regexp &optional backward)
8330   "Search for an article containing REGEXP forward.
8331 If BACKWARD, search backward instead."
8332   (interactive
8333    (list (read-string
8334           (format "Search article %s (regexp%s): "
8335                   (if current-prefix-arg "backward" "forward")
8336                   (if gnus-last-search-regexp
8337                       (concat ", default " gnus-last-search-regexp)
8338                     "")))
8339          current-prefix-arg))
8340   (if (string-equal regexp "")
8341       (setq regexp (or gnus-last-search-regexp ""))
8342     (setq gnus-last-search-regexp regexp)
8343     (setq gnus-article-before-search gnus-current-article))
8344   ;; Intentionally set gnus-last-article.
8345   (setq gnus-last-article gnus-article-before-search)
8346   (let ((gnus-last-article gnus-last-article))
8347     (if (gnus-summary-search-article regexp backward)
8348         (gnus-summary-show-thread)
8349       (error "Search failed: \"%s\"" regexp))))
8350
8351 (defun gnus-summary-search-article-backward (regexp)
8352   "Search for an article containing REGEXP backward."
8353   (interactive
8354    (list (read-string
8355           (format "Search article backward (regexp%s): "
8356                   (if gnus-last-search-regexp
8357                       (concat ", default " gnus-last-search-regexp)
8358                     "")))))
8359   (gnus-summary-search-article-forward regexp 'backward))
8360
8361 (eval-when-compile
8362   (defmacro gnus-summary-search-article-position-point (regexp backward)
8363     "Dehighlight the last matched text and goto the beginning position."
8364     (` (if (and gnus-summary-search-article-matched-data
8365                 (let ((text (caddr gnus-summary-search-article-matched-data))
8366                       (inhibit-read-only t)
8367                       buffer-read-only)
8368                   (delete-region
8369                    (goto-char (car gnus-summary-search-article-matched-data))
8370                    (cadr gnus-summary-search-article-matched-data))
8371                   (insert text)
8372                   (string-match (, regexp) text)))
8373            (if (, backward) (beginning-of-line) (end-of-line))
8374          (goto-char (if (, backward) (point-max) (point-min))))))
8375
8376   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8377     "Place point where X-Face image is displayed."
8378     (if (featurep 'xemacs)
8379         (` (let ((end (if (search-forward "\n\n" nil t)
8380                           (goto-char (1- (point)))
8381                         (point-min)))
8382                  extent)
8383              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8384              (unless (and (re-search-forward "^From:" end t)
8385                           (setq extent (extent-at (point)))
8386                           (extent-begin-glyph extent))
8387                (goto-char (, opoint)))))
8388       (` (let ((end (if (search-forward "\n\n" nil t)
8389                         (goto-char (1- (point)))
8390                       (point-min)))
8391                (start (or (search-backward "\n\n" nil t) (point-min))))
8392            (goto-char
8393             (or (text-property-any start end 'x-face-image t);; x-face-e21
8394                 (text-property-any start end 'x-face-mule-bitmap-image t)
8395                 (, opoint)))))))
8396
8397   (defmacro gnus-summary-search-article-highlight-matched-text
8398     (backward treated x-face)
8399     "Highlight matched text in the function `gnus-summary-search-article'."
8400     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8401              (end (set-marker (make-marker) (match-end 0)))
8402              (inhibit-read-only t)
8403              buffer-read-only)
8404          (unless treated
8405            (let ((,@
8406                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8407                     (mapcar
8408                      (lambda (item) (setq items (delq item items)))
8409                      '(gnus-treat-buttonize
8410                        gnus-treat-fill-article
8411                        gnus-treat-fill-long-lines
8412                        gnus-treat-emphasize
8413                        gnus-treat-highlight-headers
8414                        gnus-treat-highlight-citation
8415                        gnus-treat-highlight-signature
8416                        gnus-treat-overstrike
8417                        gnus-treat-display-x-face
8418                        gnus-treat-buttonize-head
8419                        gnus-treat-decode-article-as-default-mime-charset))
8420                     (static-if (featurep 'xemacs)
8421                         items
8422                       (cons '(x-face-mule-delete-x-face-field
8423                               (quote never))
8424                             items))))
8425                  (gnus-treat-display-x-face
8426                   (when (, x-face) gnus-treat-display-x-face)))
8427              (gnus-article-prepare-mime-display)))
8428          (goto-char (if (, backward) start end))
8429          (when (, x-face)
8430            (gnus-summary-search-article-highlight-goto-x-face (point)))
8431          (setq gnus-summary-search-article-matched-data
8432                (list start end (buffer-substring start end)))
8433          (unless (eq start end);; matched text has been deleted. :-<
8434            (put-text-property start end 'face
8435                               (or (find-face 'isearch)
8436                                   'secondary-selection))))))
8437   )
8438
8439 (defun gnus-summary-search-article (regexp &optional backward)
8440   "Search for an article containing REGEXP.
8441 Optional argument BACKWARD means do search for backward.
8442 `gnus-select-article-hook' is not called during the search."
8443   ;; We have to require this here to make sure that the following
8444   ;; dynamic binding isn't shadowed by autoloading.
8445   (require 'gnus-async)
8446   (require 'gnus-art)
8447   (let ((gnus-select-article-hook nil)  ;Disable hook.
8448         (gnus-article-prepare-hook nil)
8449         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8450         (gnus-use-article-prefetch nil)
8451         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8452         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8453         (gnus-visual nil)
8454         (gnus-keep-backlog nil)
8455         (gnus-break-pages nil)
8456         (gnus-summary-display-arrow nil)
8457         (gnus-updated-mode-lines nil)
8458         (gnus-auto-center-summary nil)
8459         (sum (current-buffer))
8460         (found nil)
8461         point treated)
8462     (gnus-save-hidden-threads
8463       (static-if (featurep 'xemacs)
8464           (let ((gnus-inhibit-treatment t))
8465             (setq treated (eq 'old (gnus-summary-select-article)))
8466             (when (and treated
8467                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8468                                  (window-live-p (get-buffer-window
8469                                                  gnus-article-buffer t)))))
8470               (gnus-summary-select-article nil t)
8471               (setq treated nil)))
8472         (let ((gnus-inhibit-treatment t)
8473               (x-face-mule-delete-x-face-field 'never))
8474           (setq treated (eq 'old (gnus-summary-select-article)))
8475           (when (and treated
8476                      (not
8477                       (and (gnus-buffer-live-p gnus-article-buffer)
8478                            (window-live-p (get-buffer-window
8479                                            gnus-article-buffer t))
8480                            (or (not (string-match "^\\^X-Face:" regexp))
8481                                (with-current-buffer gnus-article-buffer
8482                                  gnus-summary-search-article-matched-data)))))
8483             (gnus-summary-select-article nil t)
8484             (setq treated nil))))
8485       (set-buffer gnus-article-buffer)
8486       (widen)
8487       (if treated
8488           (progn
8489             (gnus-article-show-all-headers)
8490             (gnus-summary-search-article-position-point regexp backward))
8491         (goto-char (if backward (point-max) (point-min))))
8492       (while (not found)
8493         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8494         (if (if backward
8495                 (re-search-backward regexp nil t)
8496               (re-search-forward regexp nil t))
8497             ;; We found the regexp.
8498             (progn
8499               (gnus-summary-search-article-highlight-matched-text
8500                backward treated (string-match "^\\^X-Face:" regexp))
8501               (setq found 'found)
8502               (forward-line
8503                (/ (- 2 (window-height
8504                         (get-buffer-window gnus-article-buffer t)))
8505                   2))
8506               (set-window-start
8507                (get-buffer-window (current-buffer))
8508                (point))
8509               (set-buffer sum)
8510               (setq point (point)))
8511           ;; We didn't find it, so we go to the next article.
8512           (set-buffer sum)
8513           (setq found 'not)
8514           (while (eq found 'not)
8515             (if (not (if backward (gnus-summary-find-prev)
8516                        (gnus-summary-find-next)))
8517                 ;; No more articles.
8518                 (setq found t)
8519               ;; Select the next article and adjust point.
8520               (unless (gnus-summary-article-sparse-p
8521                        (gnus-summary-article-number))
8522                 (setq found nil)
8523                 (let ((gnus-inhibit-treatment t))
8524                   (gnus-summary-select-article))
8525                 (setq treated nil)
8526                 (set-buffer gnus-article-buffer)
8527                 (widen)
8528                 (goto-char (if backward (point-max) (point-min))))))))
8529       (gnus-message 7 ""))
8530     ;; Return whether we found the regexp.
8531     (when (eq found 'found)
8532       (goto-char point)
8533       (gnus-summary-show-thread)
8534       (gnus-summary-goto-subject gnus-current-article)
8535       (gnus-summary-position-point)
8536       t)))
8537
8538 (defun gnus-find-matching-articles (header regexp)
8539   "Return a list of all articles that match REGEXP on HEADER.
8540 This search includes all articles in the current group that Gnus has
8541 fetched headers for, whether they are displayed or not."
8542   (let ((articles nil)
8543         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8544         (case-fold-search t))
8545     (dolist (header gnus-newsgroup-headers)
8546       (when (string-match regexp (funcall func header))
8547         (push (mail-header-number header) articles)))
8548     (nreverse articles)))
8549
8550 (defun gnus-summary-find-matching (header regexp &optional backward unread
8551                                           not-case-fold not-matching)
8552   "Return a list of all articles that match REGEXP on HEADER.
8553 The search stars on the current article and goes forwards unless
8554 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8555 If UNREAD is non-nil, only unread articles will
8556 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8557 in the comparisons. If NOT-MATCHING, return a list of all articles that
8558 not match REGEXP on HEADER."
8559   (let ((case-fold-search (not not-case-fold))
8560         articles d func)
8561     (if (consp header)
8562         (if (eq (car header) 'extra)
8563             (setq func
8564                   `(lambda (h)
8565                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8566                          "")))
8567           (error "%s is an invalid header" header))
8568       (unless (fboundp (intern (concat "mail-header-" header)))
8569         (error "%s is not a valid header" header))
8570       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8571     (dolist (d (if (eq backward 'all)
8572                    gnus-newsgroup-data
8573                  (gnus-data-find-list
8574                   (gnus-summary-article-number)
8575                   (gnus-data-list backward))))
8576       (when (and (or (not unread)       ; We want all articles...
8577                      (gnus-data-unread-p d)) ; Or just unreads.
8578                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8579                  (if not-matching
8580                      (not (string-match
8581                            regexp
8582                            (funcall func (gnus-data-header d))))
8583                    (string-match regexp
8584                                  (funcall func (gnus-data-header d)))))
8585         (push (gnus-data-number d) articles))) ; Success!
8586     (nreverse articles)))
8587
8588 (defun gnus-summary-execute-command (header regexp command &optional backward)
8589   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8590 If HEADER is an empty string (or nil), the match is done on the entire
8591 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8592   (interactive
8593    (list (let ((completion-ignore-case t))
8594            (completing-read
8595             "Header name: "
8596             (mapcar (lambda (header) (list (format "%s" header)))
8597                     (append
8598                      '("Number" "Subject" "From" "Lines" "Date"
8599                        "Message-ID" "Xref" "References" "Body")
8600                      gnus-extra-headers))
8601             nil 'require-match))
8602          (read-string "Regexp: ")
8603          (read-key-sequence "Command: ")
8604          current-prefix-arg))
8605   (when (equal header "Body")
8606     (setq header ""))
8607   ;; Hidden thread subtrees must be searched as well.
8608   (gnus-summary-show-all-threads)
8609   ;; We don't want to change current point nor window configuration.
8610   (save-excursion
8611     (save-window-excursion
8612       (let (gnus-visual
8613             gnus-treat-strip-trailing-blank-lines
8614             gnus-treat-strip-leading-blank-lines
8615             gnus-treat-strip-multiple-blank-lines
8616             gnus-treat-hide-boring-headers
8617             gnus-treat-fold-newsgroups
8618             gnus-article-prepare-hook)
8619         (gnus-message 6 "Executing %s..." (key-description command))
8620         ;; We'd like to execute COMMAND interactively so as to give arguments.
8621         (gnus-execute header regexp
8622                       `(call-interactively ',(key-binding command))
8623                       backward)
8624         (gnus-message 6 "Executing %s...done" (key-description command))))))
8625
8626 (defun gnus-summary-beginning-of-article ()
8627   "Scroll the article back to the beginning."
8628   (interactive)
8629   (gnus-summary-select-article)
8630   (gnus-configure-windows 'article)
8631   (gnus-eval-in-buffer-window gnus-article-buffer
8632     (widen)
8633     (goto-char (point-min))
8634     (when gnus-break-pages
8635       (gnus-narrow-to-page))))
8636
8637 (defun gnus-summary-end-of-article ()
8638   "Scroll to the end of the article."
8639   (interactive)
8640   (gnus-summary-select-article)
8641   (gnus-configure-windows 'article)
8642   (gnus-eval-in-buffer-window gnus-article-buffer
8643     (widen)
8644     (goto-char (point-max))
8645     (recenter -3)
8646     (when gnus-break-pages
8647       (when (re-search-backward page-delimiter nil t)
8648         (narrow-to-region (match-end 0) (point-max)))
8649       (gnus-narrow-to-page))))
8650
8651 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8652   "Truncate to LEN and quote all \"(\"'s in STRING."
8653   (gnus-replace-in-string (if (and len (> (length string) len))
8654                               (substring string 0 len)
8655                             string)
8656                           "[()]" "\\\\\\&"))
8657
8658 (defun gnus-summary-print-article (&optional filename n)
8659   "Generate and print a PostScript image of the process-marked (mail) articles.
8660
8661 If used interactively, print the current article if none are
8662 process-marked.  With prefix arg, prompt the user for the name of the
8663 file to save in.
8664
8665 When used from Lisp, accept two optional args FILENAME and N.  N means
8666 to print the next N articles.  If N is negative, print the N previous
8667 articles.  If N is nil and articles have been marked with the process
8668 mark, print these instead.
8669
8670 If the optional first argument FILENAME is nil, send the image to the
8671 printer.  If FILENAME is a string, save the PostScript image in a file with
8672 that name.  If FILENAME is a number, prompt the user for the name of the file
8673 to save in."
8674   (interactive (list (ps-print-preprint current-prefix-arg)))
8675   (dolist (article (gnus-summary-work-articles n))
8676     (gnus-summary-select-article nil nil 'pseudo article)
8677     (gnus-eval-in-buffer-window gnus-article-buffer
8678       (gnus-print-buffer))
8679     (gnus-summary-remove-process-mark article))
8680   (ps-despool filename))
8681
8682 (defun gnus-print-buffer ()
8683   (let ((buffer (generate-new-buffer " *print*")))
8684     (unwind-protect
8685         (progn
8686           (copy-to-buffer buffer (point-min) (point-max))
8687           (set-buffer buffer)
8688           (gnus-remove-text-with-property 'gnus-decoration)
8689           (when (gnus-visual-p 'article-highlight 'highlight)
8690             ;; Copy-to-buffer doesn't copy overlay.  So redo
8691             ;; highlight.
8692             (let ((gnus-article-buffer buffer))
8693               (gnus-article-highlight-citation t)
8694               (gnus-article-highlight-signature)
8695               (gnus-article-emphasize)
8696               (gnus-article-delete-invisible-text)))
8697           (let ((ps-left-header
8698                  (list
8699                   (concat "("
8700                           (gnus-summary-print-truncate-and-quote
8701                            (mail-header-subject gnus-current-headers)
8702                            66) ")")
8703                   (concat "("
8704                           (gnus-summary-print-truncate-and-quote
8705                            (mail-header-from gnus-current-headers)
8706                            45) ")")))
8707                 (ps-right-header
8708                  (list
8709                   "/pagenumberstring load"
8710                   (concat "("
8711                           (mail-header-date gnus-current-headers) ")"))))
8712             (gnus-run-hooks 'gnus-ps-print-hook)
8713             (save-excursion
8714               (if window-system
8715                   (ps-spool-buffer-with-faces)
8716                 (ps-spool-buffer)))))
8717       (kill-buffer buffer))))
8718
8719 (defun gnus-summary-show-article (&optional arg)
8720   "Force redisplaying of the current article.
8721 If ARG (the prefix) is a number, show the article with the charset
8722 defined in `gnus-summary-show-article-charset-alist', or the charset
8723 input.
8724 If ARG (the prefix) is non-nil and not a number, show the raw article
8725 without any article massaging functions being run.  Normally, the key
8726 strokes are `C-u g'."
8727   (interactive "P")
8728   (cond
8729    ((numberp arg)
8730     (gnus-summary-show-article t)
8731     (let* ((gnus-newsgroup-charset
8732             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8733                 (mm-read-coding-system
8734                  "View as charset: " ;; actually it is coding system.
8735                  (save-excursion
8736                    (set-buffer gnus-article-buffer)
8737                    (mm-detect-coding-region (point) (point-max))))))
8738            (default-mime-charset gnus-newsgroup-charset)
8739            (gnus-newsgroup-ignored-charsets 'gnus-all))
8740       (gnus-summary-select-article nil 'force)
8741       (let ((deps gnus-newsgroup-dependencies)
8742             head header lines)
8743         (save-excursion
8744           (set-buffer gnus-original-article-buffer)
8745           (save-restriction
8746             (message-narrow-to-head)
8747             (setq head (buffer-string))
8748             (goto-char (point-min))
8749             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8750               (goto-char (point-max))
8751               (widen)
8752               (setq lines (1- (count-lines (point) (point-max))))))
8753           (with-temp-buffer
8754             (insert (format "211 %d Article retrieved.\n"
8755                             (cdr gnus-article-current)))
8756             (insert head)
8757             (if lines (insert (format "Lines: %d\n" lines)))
8758             (insert ".\n")
8759             (let ((nntp-server-buffer (current-buffer)))
8760               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8761         (gnus-data-set-header
8762          (gnus-data-find (cdr gnus-article-current))
8763          header)
8764         (gnus-summary-update-article-line
8765          (cdr gnus-article-current) header)
8766         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8767           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8768    ((not arg)
8769     ;; Select the article the normal way.
8770     (gnus-summary-select-article nil 'force))
8771    (t
8772     ;; We have to require this here to make sure that the following
8773     ;; dynamic binding isn't shadowed by autoloading.
8774     (require 'gnus-async)
8775     (require 'gnus-art)
8776     ;; Bind the article treatment functions to nil.
8777     (let ((gnus-have-all-headers t)
8778           gnus-article-prepare-hook
8779           gnus-article-decode-hook
8780           gnus-break-pages
8781           gnus-show-mime
8782           (gnus-inhibit-treatment t))
8783       (gnus-summary-select-article nil 'force))))
8784   (gnus-summary-goto-subject gnus-current-article)
8785   (gnus-summary-position-point))
8786
8787 (defun gnus-summary-show-raw-article ()
8788   "Show the raw article without any article massaging functions being run."
8789   (interactive)
8790   (gnus-summary-show-article t))
8791
8792 (defun gnus-summary-verbose-headers (&optional arg)
8793   "Toggle permanent full header display.
8794 If ARG is a positive number, turn header display on.
8795 If ARG is a negative number, turn header display off."
8796   (interactive "P")
8797   (setq gnus-show-all-headers
8798         (cond ((or (not (numberp arg))
8799                    (zerop arg))
8800                (not gnus-show-all-headers))
8801               ((natnump arg)
8802                t)))
8803   (gnus-summary-show-article))
8804
8805 (defun gnus-summary-toggle-header (&optional arg)
8806   "Show the headers if they are hidden, or hide them if they are shown.
8807 If ARG is a positive number, show the entire header.
8808 If ARG is a negative number, hide the unwanted header lines."
8809   (interactive "P")
8810   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8811                      (get-buffer-window gnus-article-buffer t))))
8812     (with-current-buffer gnus-article-buffer
8813       (widen)
8814       (article-narrow-to-head)
8815       (let* ((buffer-read-only nil)
8816              (inhibit-point-motion-hooks t)
8817              (hidden (if (numberp arg)
8818                          (>= arg 0)
8819                        (gnus-article-hidden-text-p 'headers)))
8820              s e)
8821         (delete-region (point-min) (point-max))
8822         (with-current-buffer gnus-original-article-buffer
8823           (goto-char (setq s (point-min)))
8824           (setq e (if (search-forward "\n\n" nil t)
8825                       (1- (point))
8826                     (point-max))))
8827         (insert-buffer-substring gnus-original-article-buffer s e)
8828         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8829         ;; article-decode-encoded-words by default.
8830         (article-decode-encoded-words)
8831         (run-hooks 'gnus-article-decode-hook)
8832         (if hidden
8833             (let ((gnus-treat-hide-headers nil)
8834                   (gnus-treat-hide-boring-headers nil))
8835               (gnus-delete-wash-type 'headers)
8836               (gnus-treat-article 'head))
8837           (gnus-treat-article 'head))
8838         (widen)
8839         (if window
8840             (set-window-start window (goto-char (point-min))))
8841         (if gnus-break-pages
8842             (gnus-narrow-to-page)
8843           (when (gnus-visual-p 'page-marker)
8844             (let ((buffer-read-only nil))
8845               (gnus-remove-text-with-property 'gnus-prev)
8846               (gnus-remove-text-with-property 'gnus-next))))
8847         (gnus-set-mode-line 'article)))))
8848
8849 (defun gnus-summary-show-all-headers ()
8850   "Make all header lines visible."
8851   (interactive)
8852   (gnus-summary-toggle-header 1))
8853
8854 (defun gnus-summary-toggle-mime (&optional arg)
8855   "Toggle MIME processing.
8856 If ARG is a positive number, turn MIME processing on."
8857   (interactive "P")
8858   (setq gnus-show-mime
8859         (if (null arg)
8860             (not gnus-show-mime)
8861           (> (prefix-numeric-value arg) 0)))
8862   (gnus-summary-select-article t 'force))
8863
8864 (defun gnus-summary-caesar-message (&optional arg)
8865   "Caesar rotate the current article by 13.
8866 The numerical prefix specifies how many places to rotate each letter
8867 forward."
8868   (interactive "P")
8869   (gnus-summary-select-article)
8870   (let ((mail-header-separator ""))
8871     (gnus-eval-in-buffer-window gnus-article-buffer
8872       (save-restriction
8873         (widen)
8874         (let ((start (window-start))
8875               buffer-read-only)
8876           (message-caesar-buffer-body arg)
8877           (set-window-start (get-buffer-window (current-buffer)) start))))))
8878
8879 (autoload 'unmorse-region "morse"
8880   "Convert morse coded text in region to ordinary ASCII text."
8881   t)
8882
8883 (defun gnus-summary-morse-message (&optional arg)
8884   "Morse decode the current article."
8885   (interactive "P")
8886   (gnus-summary-select-article)
8887   (let ((mail-header-separator ""))
8888     (gnus-eval-in-buffer-window gnus-article-buffer
8889       (save-excursion
8890         (save-restriction
8891           (widen)
8892           (let ((pos (window-start))
8893                 buffer-read-only)
8894             (goto-char (point-min))
8895             (when (message-goto-body)
8896               (gnus-narrow-to-body))
8897             (goto-char (point-min))
8898             (while (re-search-forward "·" (point-max) t)
8899               (replace-match "."))
8900             (unmorse-region (point-min) (point-max))
8901             (widen)
8902             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8903
8904 (defun gnus-summary-stop-page-breaking ()
8905   "Stop page breaking in the current article."
8906   (interactive)
8907   (gnus-summary-select-article)
8908   (gnus-eval-in-buffer-window gnus-article-buffer
8909     (widen)
8910     (when (gnus-visual-p 'page-marker)
8911       (let ((buffer-read-only nil))
8912         (gnus-remove-text-with-property 'gnus-prev)
8913         (gnus-remove-text-with-property 'gnus-next))
8914       (setq gnus-page-broken nil))))
8915
8916 (defun gnus-summary-move-article (&optional n to-newsgroup
8917                                             select-method action)
8918   "Move the current article to a different newsgroup.
8919 If N is a positive number, move the N next articles.
8920 If N is a negative number, move the N previous articles.
8921 If N is nil and any articles have been marked with the process mark,
8922 move those articles instead.
8923 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8924 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8925 re-spool using this method.
8926
8927 When called interactively with TO-NEWSGROUP being nil, the value of
8928 the variable `gnus-move-split-methods' is used for finding a default
8929 for the target newsgroup.
8930
8931 For this function to work, both the current newsgroup and the
8932 newsgroup that you want to move to have to support the `request-move'
8933 and `request-accept' functions.
8934
8935 ACTION can be either `move' (the default), `crosspost' or `copy'."
8936   (interactive "P")
8937   (unless action
8938     (setq action 'move))
8939   ;; Check whether the source group supports the required functions.
8940   (cond ((and (eq action 'move)
8941               (not (gnus-check-backend-function
8942                     'request-move-article gnus-newsgroup-name)))
8943          (error "The current group does not support article moving"))
8944         ((and (eq action 'crosspost)
8945               (not (gnus-check-backend-function
8946                     'request-replace-article gnus-newsgroup-name)))
8947          (error "The current group does not support article editing")))
8948   (let ((articles (gnus-summary-work-articles n))
8949         (prefix (if (gnus-check-backend-function
8950                      'request-move-article gnus-newsgroup-name)
8951                     (gnus-group-real-prefix gnus-newsgroup-name)
8952                   ""))
8953         (names '((move "Move" "Moving")
8954                  (copy "Copy" "Copying")
8955                  (crosspost "Crosspost" "Crossposting")))
8956         (copy-buf (save-excursion
8957                     (nnheader-set-temp-buffer " *copy article*")))
8958         art-group to-method new-xref article to-groups)
8959     (unless (assq action names)
8960       (error "Unknown action %s" action))
8961     ;; Read the newsgroup name.
8962     (when (and (not to-newsgroup)
8963                (not select-method))
8964       (if (and gnus-move-split-methods
8965                (not
8966                 (and (memq gnus-current-article articles)
8967                      (gnus-buffer-live-p gnus-original-article-buffer))))
8968           ;; When `gnus-move-split-methods' is non-nil, we have to
8969           ;; select an article to give `gnus-read-move-group-name' an
8970           ;; opportunity to suggest an appropriate default.  However,
8971           ;; we needn't render or mark the article.
8972           (let ((gnus-display-mime-function nil)
8973                 (gnus-article-prepare-hook nil)
8974                 (gnus-mark-article-hook nil))
8975             (gnus-summary-select-article nil nil nil (car articles))))
8976       (setq to-newsgroup
8977             (gnus-read-move-group-name
8978              (cadr (assq action names))
8979              (symbol-value (intern (format "gnus-current-%s-group" action)))
8980              articles prefix))
8981       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8982     (setq to-method (or select-method
8983                         (gnus-server-to-method
8984                          (gnus-group-method to-newsgroup))))
8985     ;; Check the method we are to move this article to...
8986     (unless (gnus-check-backend-function
8987              'request-accept-article (car to-method))
8988       (error "%s does not support article copying" (car to-method)))
8989     (unless (gnus-check-server to-method)
8990       (error "Can't open server %s" (car to-method)))
8991     (gnus-message 6 "%s to %s: %s..."
8992                   (caddr (assq action names))
8993                   (or (car select-method) to-newsgroup) articles)
8994     (while articles
8995       (setq article (pop articles))
8996       (setq
8997        art-group
8998        (cond
8999         ;; Move the article.
9000         ((eq action 'move)
9001          ;; Remove this article from future suppression.
9002          (gnus-dup-unsuppress-article article)
9003          (gnus-request-move-article
9004           article                       ; Article to move
9005           gnus-newsgroup-name           ; From newsgroup
9006           (nth 1 (gnus-find-method-for-group
9007                   gnus-newsgroup-name)) ; Server
9008           (list 'gnus-request-accept-article
9009                 to-newsgroup (list 'quote select-method)
9010                 (not articles) t)       ; Accept form
9011           (not articles)))              ; Only save nov last time
9012         ;; Copy the article.
9013         ((eq action 'copy)
9014          (save-excursion
9015            (set-buffer copy-buf)
9016            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9017              (gnus-request-accept-article
9018               to-newsgroup select-method (not articles) t))))
9019         ;; Crosspost the article.
9020         ((eq action 'crosspost)
9021          (let ((xref (message-tokenize-header
9022                       (mail-header-xref (gnus-summary-article-header article))
9023                       " ")))
9024            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9025                                   ":" (number-to-string article)))
9026            (unless xref
9027              (setq xref (list (system-name))))
9028            (setq new-xref
9029                  (concat
9030                   (mapconcat 'identity
9031                              (delete "Xref:" (delete new-xref xref))
9032                              " ")
9033                   " " new-xref))
9034            (save-excursion
9035              (set-buffer copy-buf)
9036              ;; First put the article in the destination group.
9037              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9038              (when (consp (setq art-group
9039                                 (gnus-request-accept-article
9040                                  to-newsgroup select-method (not articles))))
9041                (setq new-xref (concat new-xref " " (car art-group)
9042                                       ":"
9043                                       (number-to-string (cdr art-group))))
9044                ;; Now we have the new Xrefs header, so we insert
9045                ;; it and replace the new article.
9046                (nnheader-replace-header "Xref" new-xref)
9047                (gnus-request-replace-article
9048                 (cdr art-group) to-newsgroup (current-buffer))
9049                art-group))))))
9050       (cond
9051        ((not art-group)
9052         (gnus-message 1 "Couldn't %s article %s: %s"
9053                       (cadr (assq action names)) article
9054                       (nnheader-get-report (car to-method))))
9055        ((eq art-group 'junk)
9056         (when (eq action 'move)
9057           (gnus-summary-mark-article article gnus-canceled-mark)
9058           (gnus-message 4 "Deleted article %s" article)
9059           ;; run the delete hook
9060           (run-hook-with-args 'gnus-summary-article-delete-hook
9061                               action
9062                               (gnus-data-header
9063                                (assoc article (gnus-data-list nil)))
9064                               gnus-newsgroup-name nil
9065                               select-method)))
9066        (t
9067         (let* ((pto-group (gnus-group-prefixed-name
9068                            (car art-group) to-method))
9069                (info (gnus-get-info pto-group))
9070                (to-group (gnus-info-group info))
9071                to-marks)
9072           ;; Update the group that has been moved to.
9073           (when (and info
9074                      (memq action '(move copy)))
9075             (unless (member to-group to-groups)
9076               (push to-group to-groups))
9077
9078             (unless (memq article gnus-newsgroup-unreads)
9079               (push 'read to-marks)
9080               (gnus-info-set-read
9081                info (gnus-add-to-range (gnus-info-read info)
9082                                        (list (cdr art-group)))))
9083
9084             ;; See whether the article is to be put in the cache.
9085             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9086                              gnus-article-mark-lists
9087                            (delete '(expirable . expire)
9088                                    (copy-sequence gnus-article-mark-lists))))
9089                   (to-article (cdr art-group)))
9090
9091               ;; Enter the article into the cache in the new group,
9092               ;; if that is required.
9093               (when gnus-use-cache
9094                 (gnus-cache-possibly-enter-article
9095                  to-group to-article
9096                  (let ((header (copy-sequence
9097                                 (gnus-summary-article-header article))))
9098                    (mail-header-set-number header to-article)
9099                    header)
9100                  (memq article gnus-newsgroup-marked)
9101                  (memq article gnus-newsgroup-dormant)
9102                  (memq article gnus-newsgroup-unreads)))
9103
9104               (when gnus-preserve-marks
9105                 ;; Copy any marks over to the new group.
9106                 (when (and (equal to-group gnus-newsgroup-name)
9107                            (not (memq article gnus-newsgroup-unreads)))
9108                   ;; Mark this article as read in this group.
9109                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9110                   (setcdr (gnus-active to-group) to-article)
9111                   (setcdr gnus-newsgroup-active to-article))
9112
9113                 (while marks
9114                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9115                     (when (memq article (symbol-value
9116                                          (intern (format "gnus-newsgroup-%s"
9117                                                          (caar marks)))))
9118                       (push (cdar marks) to-marks)
9119                       ;; If the other group is the same as this group,
9120                       ;; then we have to add the mark to the list.
9121                       (when (equal to-group gnus-newsgroup-name)
9122                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9123                              (cons to-article
9124                                    (symbol-value
9125                                     (intern (format "gnus-newsgroup-%s"
9126                                                     (caar marks)))))))
9127                       ;; Copy the marks to other group.
9128                       (gnus-add-marked-articles
9129                        to-group (cdar marks) (list to-article) info)))
9130                   (setq marks (cdr marks)))
9131
9132                 (gnus-request-set-mark
9133                  to-group (list (list (list to-article) 'add to-marks))))
9134
9135               (gnus-dribble-enter
9136                (concat "(gnus-group-set-info '"
9137                        (gnus-prin1-to-string (gnus-get-info to-group))
9138                        ")"))))
9139
9140           ;; Update the Xref header in this article to point to
9141           ;; the new crossposted article we have just created.
9142           (when (eq action 'crosspost)
9143             (save-excursion
9144               (set-buffer copy-buf)
9145               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9146               (nnheader-replace-header "Xref" new-xref)
9147               (gnus-request-replace-article
9148                article gnus-newsgroup-name (current-buffer))))
9149
9150           ;; run the move/copy/crosspost/respool hook
9151           (run-hook-with-args 'gnus-summary-article-move-hook
9152                               action
9153                               (gnus-data-header
9154                                (assoc article (gnus-data-list nil)))
9155                               gnus-newsgroup-name
9156                               to-newsgroup
9157                               select-method))
9158
9159         ;;;!!!Why is this necessary?
9160         (set-buffer gnus-summary-buffer)
9161         
9162         (gnus-summary-goto-subject article)
9163         (when (eq action 'move)
9164           (gnus-summary-mark-article article gnus-canceled-mark))))
9165       (gnus-summary-remove-process-mark article))
9166     ;; Re-activate all groups that have been moved to.
9167     (save-excursion
9168       (set-buffer gnus-group-buffer)
9169       (let ((gnus-group-marked to-groups))
9170         (gnus-group-get-new-news-this-group nil t)))
9171
9172     (gnus-kill-buffer copy-buf)
9173     (gnus-summary-position-point)
9174     (gnus-set-mode-line 'summary)))
9175
9176 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9177   "Move the current article to a different newsgroup.
9178 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9179 When called interactively, if TO-NEWSGROUP is nil, use the value of
9180 the variable `gnus-move-split-methods' for finding a default target
9181 newsgroup.
9182 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9183 re-spool using this method."
9184   (interactive "P")
9185   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9186
9187 (defun gnus-summary-crosspost-article (&optional n)
9188   "Crosspost the current article to some other group."
9189   (interactive "P")
9190   (gnus-summary-move-article n nil nil 'crosspost))
9191
9192 (defcustom gnus-summary-respool-default-method nil
9193   "Default method type for respooling an article.
9194 If nil, use to the current newsgroup method."
9195   :type 'symbol
9196   :group 'gnus-summary-mail)
9197
9198 (defcustom gnus-summary-display-while-building nil
9199   "If non-nil, show and update the summary buffer as it's being built.
9200 If the value is t, update the buffer after every line is inserted.  If
9201 the value is an integer (N), update the display every N lines."
9202   :group 'gnus-thread
9203   :type '(choice (const :tag "off" nil)
9204                  number
9205                  (const :tag "frequently" t)))
9206
9207 (defun gnus-summary-respool-article (&optional n method)
9208   "Respool the current article.
9209 The article will be squeezed through the mail spooling process again,
9210 which means that it will be put in some mail newsgroup or other
9211 depending on `nnmail-split-methods'.
9212 If N is a positive number, respool the N next articles.
9213 If N is a negative number, respool the N previous articles.
9214 If N is nil and any articles have been marked with the process mark,
9215 respool those articles instead.
9216
9217 Respooling can be done both from mail groups and \"real\" newsgroups.
9218 In the former case, the articles in question will be moved from the
9219 current group into whatever groups they are destined to.  In the
9220 latter case, they will be copied into the relevant groups."
9221   (interactive
9222    (list current-prefix-arg
9223          (let* ((methods (gnus-methods-using 'respool))
9224                 (methname
9225                  (symbol-name (or gnus-summary-respool-default-method
9226                                   (car (gnus-find-method-for-group
9227                                         gnus-newsgroup-name)))))
9228                 (method
9229                  (gnus-completing-read-with-default
9230                   methname "What backend do you want to use when respooling?"
9231                   methods nil t nil 'gnus-mail-method-history))
9232                 ms)
9233            (cond
9234             ((zerop (length (setq ms (gnus-servers-using-backend
9235                                       (intern method)))))
9236              (list (intern method) ""))
9237             ((= 1 (length ms))
9238              (car ms))
9239             (t
9240              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9241                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9242                            ms-alist))))))))
9243   (unless method
9244     (error "No method given for respooling"))
9245   (if (assoc (symbol-name
9246               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9247              (gnus-methods-using 'respool))
9248       (gnus-summary-move-article n nil method)
9249     (gnus-summary-copy-article n nil method)))
9250
9251 (defun gnus-summary-import-article (file &optional edit)
9252   "Import an arbitrary file into a mail newsgroup."
9253   (interactive "fImport file: \nP")
9254   (let ((group gnus-newsgroup-name)
9255         (now (current-time))
9256         atts lines group-art)
9257     (unless (gnus-check-backend-function 'request-accept-article group)
9258       (error "%s does not support article importing" group))
9259     (or (file-readable-p file)
9260         (not (file-regular-p file))
9261         (error "Can't read %s" file))
9262     (save-excursion
9263       (set-buffer (gnus-get-buffer-create " *import file*"))
9264       (erase-buffer)
9265       (nnheader-insert-file-contents file)
9266       (goto-char (point-min))
9267       (if (nnheader-article-p)
9268           (save-restriction
9269             (goto-char (point-min))
9270             (search-forward "\n\n" nil t)
9271             (narrow-to-region (point-min) (1- (point)))
9272             (goto-char (point-min))
9273             (unless (re-search-forward "^date:" nil t)
9274               (goto-char (point-max))
9275               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9276         ;; This doesn't look like an article, so we fudge some headers.
9277         (setq atts (file-attributes file)
9278               lines (count-lines (point-min) (point-max)))
9279         (insert "From: " (read-string "From: ") "\n"
9280                 "Subject: " (read-string "Subject: ") "\n"
9281                 "Date: " (message-make-date (nth 5 atts)) "\n"
9282                 "Message-ID: " (message-make-message-id) "\n"
9283                 "Lines: " (int-to-string lines) "\n"
9284                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9285       (setq group-art (gnus-request-accept-article group nil t))
9286       (kill-buffer (current-buffer)))
9287     (setq gnus-newsgroup-active (gnus-activate-group group))
9288     (forward-line 1)
9289     (gnus-summary-goto-article (cdr group-art) nil t)
9290     (when edit
9291       (gnus-summary-edit-article))))
9292
9293 (defun gnus-summary-create-article ()
9294   "Create an article in a mail newsgroup."
9295   (interactive)
9296   (let ((group gnus-newsgroup-name)
9297         (now (current-time))
9298         group-art)
9299     (unless (gnus-check-backend-function 'request-accept-article group)
9300       (error "%s does not support article importing" group))
9301     (save-excursion
9302       (set-buffer (gnus-get-buffer-create " *import file*"))
9303       (erase-buffer)
9304       (goto-char (point-min))
9305       ;; This doesn't look like an article, so we fudge some headers.
9306       (insert "From: " (read-string "From: ") "\n"
9307               "Subject: " (read-string "Subject: ") "\n"
9308               "Date: " (message-make-date now) "\n"
9309               "Message-ID: " (message-make-message-id) "\n")
9310       (setq group-art (gnus-request-accept-article group nil t))
9311       (kill-buffer (current-buffer)))
9312     (setq gnus-newsgroup-active (gnus-activate-group group))
9313     (forward-line 1)
9314     (gnus-summary-goto-article (cdr group-art) nil t)
9315     (gnus-summary-edit-article)))
9316
9317 (defun gnus-summary-article-posted-p ()
9318   "Say whether the current (mail) article is available from news as well.
9319 This will be the case if the article has both been mailed and posted."
9320   (interactive)
9321   (let ((id (mail-header-references (gnus-summary-article-header)))
9322         (gnus-override-method (car (gnus-refer-article-methods))))
9323     (if (gnus-request-head id "")
9324         (gnus-message 2 "The current message was found on %s"
9325                       gnus-override-method)
9326       (gnus-message 2 "The current message couldn't be found on %s"
9327                     gnus-override-method)
9328       nil)))
9329
9330 (defun gnus-summary-expire-articles (&optional now)
9331   "Expire all articles that are marked as expirable in the current group."
9332   (interactive)
9333   (when (and (not gnus-group-is-exiting-without-update-p)
9334              (gnus-check-backend-function
9335               'request-expire-articles gnus-newsgroup-name))
9336     ;; This backend supports expiry.
9337     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9338            (expirable (if total
9339                           (progn
9340                             ;; We need to update the info for
9341                             ;; this group for `gnus-list-of-read-articles'
9342                             ;; to give us the right answer.
9343                             (gnus-run-hooks 'gnus-exit-group-hook)
9344                             (gnus-summary-update-info)
9345                             (gnus-list-of-read-articles gnus-newsgroup-name))
9346                         (setq gnus-newsgroup-expirable
9347                               (sort gnus-newsgroup-expirable '<))))
9348            (expiry-wait (if now 'immediate
9349                           (gnus-group-find-parameter
9350                            gnus-newsgroup-name 'expiry-wait)))
9351            (nnmail-expiry-target
9352             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9353                 nnmail-expiry-target))
9354            es)
9355       (when expirable
9356         ;; There are expirable articles in this group, so we run them
9357         ;; through the expiry process.
9358         (gnus-message 6 "Expiring articles...")
9359         (unless (gnus-check-group gnus-newsgroup-name)
9360           (error "Can't open server for %s" gnus-newsgroup-name))
9361         ;; The list of articles that weren't expired is returned.
9362         (save-excursion
9363           (if expiry-wait
9364               (let ((nnmail-expiry-wait-function nil)
9365                     (nnmail-expiry-wait expiry-wait))
9366                 (setq es (gnus-request-expire-articles
9367                           expirable gnus-newsgroup-name)))
9368             (setq es (gnus-request-expire-articles
9369                       expirable gnus-newsgroup-name)))
9370           (unless total
9371             (setq gnus-newsgroup-expirable es))
9372           ;; We go through the old list of expirable, and mark all
9373           ;; really expired articles as nonexistent.
9374           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9375             (let ((gnus-use-cache nil))
9376               (dolist (article expirable)
9377                 (when (and (not (memq article es))
9378                            (gnus-data-find article))
9379                   (gnus-summary-mark-article article gnus-canceled-mark)
9380                   (run-hook-with-args 'gnus-summary-article-expire-hook
9381                                       'delete
9382                                       (gnus-data-header
9383                                        (assoc article (gnus-data-list nil)))
9384                                       gnus-newsgroup-name
9385                                       nil
9386                                       nil))))))
9387         (gnus-message 6 "Expiring articles...done")))))
9388
9389 (defun gnus-summary-expire-articles-now ()
9390   "Expunge all expirable articles in the current group.
9391 This means that *all* articles that are marked as expirable will be
9392 deleted forever, right now."
9393   (interactive)
9394   (or gnus-expert-user
9395       (gnus-yes-or-no-p
9396        "Are you really, really, really sure you want to delete all these messages? ")
9397       (error "Phew!"))
9398   (gnus-summary-expire-articles t))
9399
9400 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9401 (defun gnus-summary-delete-article (&optional n)
9402   "Delete the N next (mail) articles.
9403 This command actually deletes articles.  This is not a marking
9404 command.  The article will disappear forever from your life, never to
9405 return.
9406
9407 If N is negative, delete backwards.
9408 If N is nil and articles have been marked with the process mark,
9409 delete these instead.
9410
9411 If `gnus-novice-user' is non-nil you will be asked for
9412 confirmation before the articles are deleted."
9413   (interactive "P")
9414   (unless (gnus-check-backend-function 'request-expire-articles
9415                                        gnus-newsgroup-name)
9416     (error "The current newsgroup does not support article deletion"))
9417   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9418     (error "Couldn't open server"))
9419   ;; Compute the list of articles to delete.
9420   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9421         (nnmail-expiry-target 'delete)
9422         not-deleted)
9423     (if (and gnus-novice-user
9424              (not (gnus-yes-or-no-p
9425                    (format "Do you really want to delete %s forever? "
9426                            (if (> (length articles) 1)
9427                                (format "these %s articles" (length articles))
9428                              "this article")))))
9429         ()
9430       ;; Delete the articles.
9431       (setq not-deleted (gnus-request-expire-articles
9432                          articles gnus-newsgroup-name 'force))
9433       (while articles
9434         (gnus-summary-remove-process-mark (car articles))
9435         ;; The backend might not have been able to delete the article
9436         ;; after all.
9437         (unless (memq (car articles) not-deleted)
9438           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9439         (let* ((article (car articles))
9440                (id (mail-header-id (gnus-data-header
9441                                     (assoc article (gnus-data-list nil))))))
9442           (run-hook-with-args 'gnus-summary-article-delete-hook
9443                               'delete id gnus-newsgroup-name nil
9444                               nil))
9445         (setq articles (cdr articles)))
9446       (when not-deleted
9447         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9448     (gnus-summary-position-point)
9449     (gnus-set-mode-line 'summary)
9450     not-deleted))
9451
9452 (defun gnus-summary-edit-article (&optional force)
9453   "Edit the current article.
9454 This will have permanent effect only in mail groups.
9455 If FORCE is non-nil, allow editing of articles even in read-only
9456 groups."
9457   (interactive "P")
9458   (save-excursion
9459     (set-buffer gnus-summary-buffer)
9460     (let ((mail-parse-charset gnus-newsgroup-charset)
9461           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9462       (gnus-set-global-variables)
9463       (when (and (not force)
9464                  (gnus-group-read-only-p))
9465         (error "The current newsgroup does not support article editing"))
9466       (gnus-summary-show-article t)
9467       (gnus-article-edit-article
9468        'ignore
9469        `(lambda (no-highlight)
9470           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9471                 (message-options message-options)
9472                 (message-options-set-recipient)
9473                 (mail-parse-ignored-charsets
9474                  ',gnus-newsgroup-ignored-charsets))
9475             (gnus-summary-edit-article-done
9476              ,(or (mail-header-references gnus-current-headers) "")
9477              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9478
9479 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9480
9481 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9482                                                  no-highlight)
9483   "Make edits to the current article permanent."
9484   (interactive)
9485   (save-excursion
9486     ;; The buffer restriction contains the entire article if it exists.
9487     (when (article-goto-body)
9488       (let ((lines (count-lines (point) (point-max)))
9489             (length (- (point-max) (point)))
9490             (case-fold-search t)
9491             (body (copy-marker (point))))
9492         (goto-char (point-min))
9493         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9494           (delete-region (match-beginning 1) (match-end 1))
9495           (insert (number-to-string length)))
9496         (goto-char (point-min))
9497         (when (re-search-forward
9498                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9499           (delete-region (match-beginning 1) (match-end 1))
9500           (insert (number-to-string length)))
9501         (goto-char (point-min))
9502         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9503           (delete-region (match-beginning 1) (match-end 1))
9504           (insert (number-to-string lines))))))
9505   ;; Replace the article.
9506   (let ((buf (current-buffer)))
9507     (with-temp-buffer
9508       (insert-buffer-substring buf)
9509
9510       (if (and (not read-only)
9511                (not (gnus-request-replace-article
9512                      (cdr gnus-article-current) (car gnus-article-current)
9513                      (current-buffer) t)))
9514           (error "Couldn't replace article")
9515         ;; Update the summary buffer.
9516         (if (and references
9517                  (equal (message-tokenize-header references " ")
9518                         (message-tokenize-header
9519                          (or (message-fetch-field "references") "") " ")))
9520             ;; We only have to update this line.
9521             (save-excursion
9522               (save-restriction
9523                 (message-narrow-to-head)
9524                 (let ((head (buffer-string))
9525                       header)
9526                   (with-temp-buffer
9527                     (insert (format "211 %d Article retrieved.\n"
9528                                     (cdr gnus-article-current)))
9529                     (insert head)
9530                     (insert ".\n")
9531                     (let ((nntp-server-buffer (current-buffer)))
9532                       (setq header (car (gnus-get-newsgroup-headers
9533                                          nil t))))
9534                     (save-excursion
9535                       (set-buffer gnus-summary-buffer)
9536                       (gnus-data-set-header
9537                        (gnus-data-find (cdr gnus-article-current))
9538                        header)
9539                       (gnus-summary-update-article-line
9540                        (cdr gnus-article-current) header)
9541                       (if (gnus-summary-goto-subject
9542                            (cdr gnus-article-current) nil t)
9543                           (gnus-summary-update-secondary-mark
9544                            (cdr gnus-article-current))))))))
9545           ;; Update threads.
9546           (set-buffer (or buffer gnus-summary-buffer))
9547           (gnus-summary-update-article (cdr gnus-article-current))
9548           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9549               (gnus-summary-update-secondary-mark
9550                (cdr gnus-article-current))))
9551         ;; Prettify the article buffer again.
9552         (unless no-highlight
9553           (save-excursion
9554             (set-buffer gnus-article-buffer)
9555             ;;;!!! Fix this -- article should be rehighlighted.
9556             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9557             (set-buffer gnus-original-article-buffer)
9558             (gnus-request-article
9559              (cdr gnus-article-current)
9560              (car gnus-article-current) (current-buffer))))
9561         ;; Prettify the summary buffer line.
9562         (when (gnus-visual-p 'summary-highlight 'highlight)
9563           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9564
9565 (defun gnus-summary-edit-wash (key)
9566   "Perform editing command KEY in the article buffer."
9567   (interactive
9568    (list
9569     (progn
9570       (message "%s" (concat (this-command-keys) "- "))
9571       (read-char))))
9572   (message "")
9573   (gnus-summary-edit-article)
9574   (execute-kbd-macro (concat (this-command-keys) key))
9575   (gnus-article-edit-done))
9576
9577 ;;; Respooling
9578
9579 (defun gnus-summary-respool-query (&optional silent trace)
9580   "Query where the respool algorithm would put this article."
9581   (interactive)
9582   (let (gnus-mark-article-hook)
9583     (gnus-summary-select-article)
9584     (save-excursion
9585       (set-buffer gnus-original-article-buffer)
9586       (let ((groups (nnmail-article-group 'identity trace)))
9587         (unless silent
9588           (if groups
9589               (message "This message would go to %s"
9590                        (mapconcat 'car groups ", "))
9591             (message "This message would go to no groups"))
9592           groups)))))
9593
9594 (defun gnus-summary-respool-trace ()
9595   "Trace where the respool algorithm would put this article.
9596 Display a buffer showing all fancy splitting patterns which matched."
9597   (interactive)
9598   (gnus-summary-respool-query nil t))
9599
9600 ;; Summary marking commands.
9601
9602 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9603   "Mark articles which has the same subject as read, and then select the next.
9604 If UNMARK is positive, remove any kind of mark.
9605 If UNMARK is negative, tick articles."
9606   (interactive "P")
9607   (when unmark
9608     (setq unmark (prefix-numeric-value unmark)))
9609   (let ((count
9610          (gnus-summary-mark-same-subject
9611           (gnus-summary-article-subject) unmark)))
9612     ;; Select next unread article.  If auto-select-same mode, should
9613     ;; select the first unread article.
9614     (gnus-summary-next-article t (and gnus-auto-select-same
9615                                       (gnus-summary-article-subject)))
9616     (gnus-message 7 "%d article%s marked as %s"
9617                   count (if (= count 1) " is" "s are")
9618                   (if unmark "unread" "read"))))
9619
9620 (defun gnus-summary-kill-same-subject (&optional unmark)
9621   "Mark articles which has the same subject as read.
9622 If UNMARK is positive, remove any kind of mark.
9623 If UNMARK is negative, tick articles."
9624   (interactive "P")
9625   (when unmark
9626     (setq unmark (prefix-numeric-value unmark)))
9627   (let ((count
9628          (gnus-summary-mark-same-subject
9629           (gnus-summary-article-subject) unmark)))
9630     ;; If marked as read, go to next unread subject.
9631     (when (null unmark)
9632       ;; Go to next unread subject.
9633       (gnus-summary-next-subject 1 t))
9634     (gnus-message 7 "%d articles are marked as %s"
9635                   count (if unmark "unread" "read"))))
9636
9637 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9638   "Mark articles with same SUBJECT as read, and return marked number.
9639 If optional argument UNMARK is positive, remove any kinds of marks.
9640 If optional argument UNMARK is negative, mark articles as unread instead."
9641   (let ((count 1))
9642     (save-excursion
9643       (cond
9644        ((null unmark)                   ; Mark as read.
9645         (while (and
9646                 (progn
9647                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9648                   (gnus-summary-show-thread) t)
9649                 (gnus-summary-find-subject subject))
9650           (setq count (1+ count))))
9651        ((> unmark 0)                    ; Tick.
9652         (while (and
9653                 (progn
9654                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9655                   (gnus-summary-show-thread) t)
9656                 (gnus-summary-find-subject subject))
9657           (setq count (1+ count))))
9658        (t                               ; Mark as unread.
9659         (while (and
9660                 (progn
9661                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9662                   (gnus-summary-show-thread) t)
9663                 (gnus-summary-find-subject subject))
9664           (setq count (1+ count)))))
9665       (gnus-set-mode-line 'summary)
9666       ;; Return the number of marked articles.
9667       count)))
9668
9669 (defun gnus-summary-mark-as-processable (n &optional unmark)
9670   "Set the process mark on the next N articles.
9671 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9672 the process mark instead.  The difference between N and the actual
9673 number of articles marked is returned."
9674   (interactive "P")
9675   (if (and (null n) (gnus-region-active-p))
9676       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9677     (setq n (prefix-numeric-value n))
9678     (let ((backward (< n 0))
9679           (n (abs n)))
9680       (while (and
9681               (> n 0)
9682               (if unmark
9683                   (gnus-summary-remove-process-mark
9684                    (gnus-summary-article-number))
9685                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9686               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9687         (setq n (1- n)))
9688       (when (/= 0 n)
9689         (gnus-message 7 "No more articles"))
9690       (gnus-summary-recenter)
9691       (gnus-summary-position-point)
9692       n)))
9693
9694 (defun gnus-summary-unmark-as-processable (n)
9695   "Remove the process mark from the next N articles.
9696 If N is negative, unmark backward instead.  The difference between N and
9697 the actual number of articles unmarked is returned."
9698   (interactive "P")
9699   (gnus-summary-mark-as-processable n t))
9700
9701 (defun gnus-summary-unmark-all-processable ()
9702   "Remove the process mark from all articles."
9703   (interactive)
9704   (save-excursion
9705     (while gnus-newsgroup-processable
9706       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9707   (gnus-summary-position-point))
9708
9709 (defun gnus-summary-add-mark (article type)
9710   "Mark ARTICLE with a mark of TYPE."
9711   (let ((vtype (car (assq type gnus-article-mark-lists)))
9712         var)
9713     (if (not vtype)
9714         (error "No such mark type: %s" type)
9715       (setq var (intern (format "gnus-newsgroup-%s" type)))
9716       (set var (cons article (symbol-value var)))
9717       (if (memq type '(processable cached replied forwarded recent saved))
9718           (gnus-summary-update-secondary-mark article)
9719         ;;; !!! This is bogus.  We should find out what primary
9720         ;;; !!! mark we want to set.
9721         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9722
9723 (defun gnus-summary-mark-as-expirable (n)
9724   "Mark N articles forward as expirable.
9725 If N is negative, mark backward instead.  The difference between N and
9726 the actual number of articles marked is returned."
9727   (interactive "p")
9728   (gnus-summary-mark-forward n gnus-expirable-mark))
9729
9730 (defun gnus-summary-mark-as-spam (n)
9731   "Mark N articles forward as spam.
9732 If N is negative, mark backward instead.  The difference between N and
9733 the actual number of articles marked is returned."
9734   (interactive "p")
9735   (gnus-summary-mark-forward n gnus-spam-mark))
9736
9737 (defun gnus-summary-mark-article-as-replied (article)
9738   "Mark ARTICLE as replied to and update the summary line.
9739 ARTICLE can also be a list of articles."
9740   (interactive (list (gnus-summary-article-number)))
9741   (let ((articles (if (listp article) article (list article))))
9742     (dolist (article articles)
9743       (unless (numberp article)
9744         (error "%s is not a number" article))
9745       (push article gnus-newsgroup-replied)
9746       (let ((buffer-read-only nil))
9747         (when (gnus-summary-goto-subject article nil t)
9748           (gnus-summary-update-secondary-mark article))))))
9749
9750 (defun gnus-summary-mark-article-as-forwarded (article)
9751   "Mark ARTICLE as forwarded and update the summary line.
9752 ARTICLE can also be a list of articles."
9753   (let ((articles (if (listp article) article (list article))))
9754     (dolist (article articles)
9755       (push article gnus-newsgroup-forwarded)
9756       (let ((buffer-read-only nil))
9757         (when (gnus-summary-goto-subject article nil t)
9758           (gnus-summary-update-secondary-mark article))))))
9759
9760 (defun gnus-summary-set-bookmark (article)
9761   "Set a bookmark in current article."
9762   (interactive (list (gnus-summary-article-number)))
9763   (when (or (not (get-buffer gnus-article-buffer))
9764             (not gnus-current-article)
9765             (not gnus-article-current)
9766             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9767     (error "No current article selected"))
9768   ;; Remove old bookmark, if one exists.
9769   (gnus-pull article gnus-newsgroup-bookmarks)
9770   ;; Set the new bookmark, which is on the form
9771   ;; (article-number . line-number-in-body).
9772   (push
9773    (cons article
9774          (save-excursion
9775            (set-buffer gnus-article-buffer)
9776            (count-lines
9777             (min (point)
9778                  (save-excursion
9779                    (article-goto-body)
9780                    (point)))
9781             (point))))
9782    gnus-newsgroup-bookmarks)
9783   (gnus-message 6 "A bookmark has been added to the current article."))
9784
9785 (defun gnus-summary-remove-bookmark (article)
9786   "Remove the bookmark from the current article."
9787   (interactive (list (gnus-summary-article-number)))
9788   ;; Remove old bookmark, if one exists.
9789   (if (not (assq article gnus-newsgroup-bookmarks))
9790       (gnus-message 6 "No bookmark in current article.")
9791     (gnus-pull article gnus-newsgroup-bookmarks)
9792     (gnus-message 6 "Removed bookmark.")))
9793
9794 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9795 (defun gnus-summary-mark-as-dormant (n)
9796   "Mark N articles forward as dormant.
9797 If N is negative, mark backward instead.  The difference between N and
9798 the actual number of articles marked is returned."
9799   (interactive "p")
9800   (gnus-summary-mark-forward n gnus-dormant-mark))
9801
9802 (defun gnus-summary-set-process-mark (article)
9803   "Set the process mark on ARTICLE and update the summary line."
9804   (setq gnus-newsgroup-processable
9805         (cons article
9806               (delq article gnus-newsgroup-processable)))
9807   (when (gnus-summary-goto-subject article)
9808     (gnus-summary-show-thread)
9809     (gnus-summary-goto-subject article)
9810     (gnus-summary-update-secondary-mark article)))
9811
9812 (defun gnus-summary-remove-process-mark (article)
9813   "Remove the process mark from ARTICLE and update the summary line."
9814   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9815   (when (gnus-summary-goto-subject article)
9816     (gnus-summary-show-thread)
9817     (gnus-summary-goto-subject article)
9818     (gnus-summary-update-secondary-mark article)))
9819
9820 (defun gnus-summary-set-saved-mark (article)
9821   "Set the process mark on ARTICLE and update the summary line."
9822   (push article gnus-newsgroup-saved)
9823   (when (gnus-summary-goto-subject article)
9824     (gnus-summary-update-secondary-mark article)))
9825
9826 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9827   "Mark N articles as read forwards.
9828 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9829 The difference between N and the actual number of articles marked is
9830 returned.
9831 If NO-EXPIRE, auto-expiry will be inhibited."
9832   (interactive "p")
9833   (gnus-summary-show-thread)
9834   (let ((backward (< n 0))
9835         (gnus-summary-goto-unread
9836          (and gnus-summary-goto-unread
9837               (not (eq gnus-summary-goto-unread 'never))
9838               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9839                                     gnus-ticked-mark gnus-dormant-mark)))))
9840         (n (abs n))
9841         (mark (or mark gnus-del-mark)))
9842     (while (and (> n 0)
9843                 (gnus-summary-mark-article nil mark no-expire)
9844                 (zerop (gnus-summary-next-subject
9845                         (if backward -1 1)
9846                         (and gnus-summary-goto-unread
9847                              (not (eq gnus-summary-goto-unread 'never)))
9848                         t)))
9849       (setq n (1- n)))
9850     (when (/= 0 n)
9851       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9852     (gnus-summary-recenter)
9853     (gnus-summary-position-point)
9854     (gnus-set-mode-line 'summary)
9855     n))
9856
9857 (defun gnus-summary-mark-article-as-read (mark)
9858   "Mark the current article quickly as read with MARK."
9859   (let ((article (gnus-summary-article-number)))
9860     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9861     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9862     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9863     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9864     (push (cons article mark) gnus-newsgroup-reads)
9865     ;; Possibly remove from cache, if that is used.
9866     (when gnus-use-cache
9867       (gnus-cache-enter-remove-article article))
9868     ;; Allow the backend to change the mark.
9869     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9870     ;; Check for auto-expiry.
9871     (when (and gnus-newsgroup-auto-expire
9872                (memq mark gnus-auto-expirable-marks))
9873       (setq mark gnus-expirable-mark)
9874       ;; Let the backend know about the mark change.
9875       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9876       (push article gnus-newsgroup-expirable))
9877     ;; Set the mark in the buffer.
9878     (gnus-summary-update-mark mark 'unread)
9879     t))
9880
9881 (defun gnus-summary-mark-article-as-unread (mark)
9882   "Mark the current article quickly as unread with MARK."
9883   (let* ((article (gnus-summary-article-number))
9884          (old-mark (gnus-summary-article-mark article)))
9885     ;; Allow the backend to change the mark.
9886     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9887     (if (eq mark old-mark)
9888         t
9889       (if (<= article 0)
9890           (progn
9891             (gnus-error 1 "Can't mark negative article numbers")
9892             nil)
9893         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9894         (setq gnus-newsgroup-spam-marked
9895               (delq article gnus-newsgroup-spam-marked))
9896         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9897         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9898         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9899         (cond ((= mark gnus-ticked-mark)
9900                (setq gnus-newsgroup-marked
9901                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9902                                               article)))
9903               ((= mark gnus-spam-mark)
9904                (setq gnus-newsgroup-spam-marked
9905                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9906                                               article)))
9907               ((= mark gnus-dormant-mark)
9908                (setq gnus-newsgroup-dormant
9909                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9910                                               article)))
9911               (t
9912                (setq gnus-newsgroup-unreads
9913                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9914                                               article))))
9915         (gnus-pull article gnus-newsgroup-reads)
9916
9917         ;; See whether the article is to be put in the cache.
9918         (and gnus-use-cache
9919              (vectorp (gnus-summary-article-header article))
9920              (save-excursion
9921                (gnus-cache-possibly-enter-article
9922                 gnus-newsgroup-name article
9923                 (gnus-summary-article-header article)
9924                 (= mark gnus-ticked-mark)
9925                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9926
9927         ;; Fix the mark.
9928         (gnus-summary-update-mark mark 'unread)
9929         t))))
9930
9931 (defun gnus-summary-mark-article (&optional article mark no-expire)
9932   "Mark ARTICLE with MARK.  MARK can be any character.
9933 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9934 `??' (dormant) and `?E' (expirable).
9935 If MARK is nil, then the default character `?r' is used.
9936 If ARTICLE is nil, then the article on the current line will be
9937 marked.
9938 If NO-EXPIRE, auto-expiry will be inhibited."
9939   ;; The mark might be a string.
9940   (when (stringp mark)
9941     (setq mark (aref mark 0)))
9942   ;; If no mark is given, then we check auto-expiring.
9943   (when (null mark)
9944     (setq mark gnus-del-mark))
9945   (when (and (not no-expire)
9946              gnus-newsgroup-auto-expire
9947              (memq mark gnus-auto-expirable-marks))
9948     (setq mark gnus-expirable-mark))
9949   (let ((article (or article (gnus-summary-article-number)))
9950         (old-mark (gnus-summary-article-mark article)))
9951     ;; Allow the backend to change the mark.
9952     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9953     (if (eq mark old-mark)
9954         t
9955       (unless article
9956         (error "No article on current line"))
9957       (if (not (if (or (= mark gnus-unread-mark)
9958                        (= mark gnus-ticked-mark)
9959                        (= mark gnus-spam-mark)
9960                        (= mark gnus-dormant-mark))
9961                    (gnus-mark-article-as-unread article mark)
9962                  (gnus-mark-article-as-read article mark)))
9963           t
9964         ;; See whether the article is to be put in the cache.
9965         (and gnus-use-cache
9966              (not (= mark gnus-canceled-mark))
9967              (vectorp (gnus-summary-article-header article))
9968              (save-excursion
9969                (gnus-cache-possibly-enter-article
9970                 gnus-newsgroup-name article
9971                 (gnus-summary-article-header article)
9972                 (= mark gnus-ticked-mark)
9973                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9974
9975         (when (gnus-summary-goto-subject article nil t)
9976           (let ((buffer-read-only nil))
9977             (gnus-summary-show-thread)
9978             ;; Fix the mark.
9979             (gnus-summary-update-mark mark 'unread)
9980             t))))))
9981
9982 (defun gnus-summary-update-secondary-mark (article)
9983   "Update the secondary (read, process, cache) mark."
9984   (gnus-summary-update-mark
9985    (cond ((memq article gnus-newsgroup-processable)
9986           gnus-process-mark)
9987          ((memq article gnus-newsgroup-cached)
9988           gnus-cached-mark)
9989          ((memq article gnus-newsgroup-replied)
9990           gnus-replied-mark)
9991          ((memq article gnus-newsgroup-forwarded)
9992           gnus-forwarded-mark)
9993          ((memq article gnus-newsgroup-saved)
9994           gnus-saved-mark)
9995          ((memq article gnus-newsgroup-recent)
9996           gnus-recent-mark)
9997          ((memq article gnus-newsgroup-unseen)
9998           gnus-unseen-mark)
9999          (t gnus-no-mark))
10000    'replied)
10001   (when (gnus-visual-p 'summary-highlight 'highlight)
10002     (gnus-run-hooks 'gnus-summary-update-hook))
10003   t)
10004
10005 (defun gnus-summary-update-download-mark (article)
10006   "Update the download mark."
10007   (gnus-summary-update-mark
10008    (cond ((memq article gnus-newsgroup-undownloaded)
10009           gnus-undownloaded-mark)
10010          (gnus-newsgroup-agentized
10011           gnus-downloaded-mark)
10012          (t
10013           gnus-no-mark))
10014    'download)
10015   (gnus-summary-update-line t)
10016   t)
10017
10018 (defun gnus-summary-update-mark (mark type)
10019   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10020         (buffer-read-only nil))
10021     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10022     (when forward
10023       (when (looking-at "\r")
10024         (incf forward))
10025       (when (<= (+ forward (point)) (point-max))
10026         ;; Go to the right position on the line.
10027         (goto-char (+ forward (point)))
10028         ;; Replace the old mark with the new mark.
10029         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10030         ;; Optionally update the marks by some user rule.
10031         (when (eq type 'unread)
10032           (gnus-data-set-mark
10033            (gnus-data-find (gnus-summary-article-number)) mark)
10034           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10035
10036 (defun gnus-mark-article-as-read (article &optional mark)
10037   "Enter ARTICLE in the pertinent lists and remove it from others."
10038   ;; Make the article expirable.
10039   (let ((mark (or mark gnus-del-mark)))
10040     (setq gnus-newsgroup-expirable
10041           (if (= mark gnus-expirable-mark)
10042               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10043             (delq article gnus-newsgroup-expirable)))
10044     ;; Remove from unread and marked lists.
10045     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10046     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10047     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10048     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10049     (push (cons article mark) gnus-newsgroup-reads)
10050     ;; Possibly remove from cache, if that is used.
10051     (when gnus-use-cache
10052       (gnus-cache-enter-remove-article article))
10053     t))
10054
10055 (defun gnus-mark-article-as-unread (article &optional mark)
10056   "Enter ARTICLE in the pertinent lists and remove it from others."
10057   (let ((mark (or mark gnus-ticked-mark)))
10058     (if (<= article 0)
10059         (progn
10060           (gnus-error 1 "Can't mark negative article numbers")
10061           nil)
10062       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10063             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10064             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10065             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10066             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10067
10068       ;; Unsuppress duplicates?
10069       (when gnus-suppress-duplicates
10070         (gnus-dup-unsuppress-article article))
10071
10072       (cond ((= mark gnus-ticked-mark)
10073              (setq gnus-newsgroup-marked
10074                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10075             ((= mark gnus-spam-mark)
10076              (setq gnus-newsgroup-spam-marked
10077                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10078                                             article)))
10079             ((= mark gnus-dormant-mark)
10080              (setq gnus-newsgroup-dormant
10081                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10082             (t
10083              (setq gnus-newsgroup-unreads
10084                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10085       (gnus-pull article gnus-newsgroup-reads)
10086       t)))
10087
10088 (defalias 'gnus-summary-mark-as-unread-forward
10089   'gnus-summary-tick-article-forward)
10090 (make-obsolete 'gnus-summary-mark-as-unread-forward
10091                'gnus-summary-tick-article-forward)
10092 (defun gnus-summary-tick-article-forward (n)
10093   "Tick N articles forwards.
10094 If N is negative, tick backwards instead.
10095 The difference between N and the number of articles ticked is returned."
10096   (interactive "p")
10097   (gnus-summary-mark-forward n gnus-ticked-mark))
10098
10099 (defalias 'gnus-summary-mark-as-unread-backward
10100   'gnus-summary-tick-article-backward)
10101 (make-obsolete 'gnus-summary-mark-as-unread-backward
10102                'gnus-summary-tick-article-backward)
10103 (defun gnus-summary-tick-article-backward (n)
10104   "Tick N articles backwards.
10105 The difference between N and the number of articles ticked is returned."
10106   (interactive "p")
10107   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10108
10109 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10110 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10111 (defun gnus-summary-tick-article (&optional article clear-mark)
10112   "Mark current article as unread.
10113 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10114 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10115   (interactive)
10116   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10117                                        gnus-ticked-mark)))
10118
10119 (defun gnus-summary-mark-as-read-forward (n)
10120   "Mark N articles as read forwards.
10121 If N is negative, mark backwards instead.
10122 The difference between N and the actual number of articles marked is
10123 returned."
10124   (interactive "p")
10125   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10126
10127 (defun gnus-summary-mark-as-read-backward (n)
10128   "Mark the N articles as read backwards.
10129 The difference between N and the actual number of articles marked is
10130 returned."
10131   (interactive "p")
10132   (gnus-summary-mark-forward
10133    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10134
10135 (defun gnus-summary-mark-as-read (&optional article mark)
10136   "Mark current article as read.
10137 ARTICLE specifies the article to be marked as read.
10138 MARK specifies a string to be inserted at the beginning of the line."
10139   (gnus-summary-mark-article article mark))
10140
10141 (defun gnus-summary-clear-mark-forward (n)
10142   "Clear marks from N articles forward.
10143 If N is negative, clear backward instead.
10144 The difference between N and the number of marks cleared is returned."
10145   (interactive "p")
10146   (gnus-summary-mark-forward n gnus-unread-mark))
10147
10148 (defun gnus-summary-clear-mark-backward (n)
10149   "Clear marks from N articles backward.
10150 The difference between N and the number of marks cleared is returned."
10151   (interactive "p")
10152   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10153
10154 (defun gnus-summary-mark-unread-as-read ()
10155   "Intended to be used by `gnus-summary-mark-article-hook'."
10156   (when (memq gnus-current-article gnus-newsgroup-unreads)
10157     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10158
10159 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10160   "Intended to be used by `gnus-summary-mark-article-hook'."
10161   (let ((mark (gnus-summary-article-mark)))
10162     (when (or (gnus-unread-mark-p mark)
10163               (gnus-read-mark-p mark))
10164       (gnus-summary-mark-article gnus-current-article
10165                                  (or new-mark gnus-read-mark)))))
10166
10167 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10168   "Intended to be used by `gnus-summary-mark-article-hook'."
10169   (let ((mark (gnus-summary-article-mark)))
10170     (when (or (gnus-unread-mark-p mark)
10171               (gnus-read-mark-p mark))
10172       (gnus-summary-mark-article (gnus-summary-article-number)
10173                                  (or new-mark gnus-read-mark)))))
10174
10175 (defun gnus-summary-mark-unread-as-ticked ()
10176   "Intended to be used by `gnus-summary-mark-article-hook'."
10177   (when (memq gnus-current-article gnus-newsgroup-unreads)
10178     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10179
10180 (defun gnus-summary-mark-region-as-read (point mark all)
10181   "Mark all unread articles between point and mark as read.
10182 If given a prefix, mark all articles between point and mark as read,
10183 even ticked and dormant ones."
10184   (interactive "r\nP")
10185   (save-excursion
10186     (let (article)
10187       (goto-char point)
10188       (beginning-of-line)
10189       (while (and
10190               (< (point) mark)
10191               (progn
10192                 (when (or all
10193                           (memq (setq article (gnus-summary-article-number))
10194                                 gnus-newsgroup-unreads))
10195                   (gnus-summary-mark-article article gnus-del-mark))
10196                 t)
10197               (gnus-summary-find-next))))))
10198
10199 (defun gnus-summary-mark-below (score mark)
10200   "Mark articles with score less than SCORE with MARK."
10201   (interactive "P\ncMark: ")
10202   (setq score (if score
10203                   (prefix-numeric-value score)
10204                 (or gnus-summary-default-score 0)))
10205   (save-excursion
10206     (set-buffer gnus-summary-buffer)
10207     (goto-char (point-min))
10208     (while
10209         (progn
10210           (and (< (gnus-summary-article-score) score)
10211                (gnus-summary-mark-article nil mark))
10212           (gnus-summary-find-next)))))
10213
10214 (defun gnus-summary-kill-below (&optional score)
10215   "Mark articles with score below SCORE as read."
10216   (interactive "P")
10217   (gnus-summary-mark-below score gnus-killed-mark))
10218
10219 (defun gnus-summary-clear-above (&optional score)
10220   "Clear all marks from articles with score above SCORE."
10221   (interactive "P")
10222   (gnus-summary-mark-above score gnus-unread-mark))
10223
10224 (defun gnus-summary-tick-above (&optional score)
10225   "Tick all articles with score above SCORE."
10226   (interactive "P")
10227   (gnus-summary-mark-above score gnus-ticked-mark))
10228
10229 (defun gnus-summary-mark-above (score mark)
10230   "Mark articles with score over SCORE with MARK."
10231   (interactive "P\ncMark: ")
10232   (setq score (if score
10233                   (prefix-numeric-value score)
10234                 (or gnus-summary-default-score 0)))
10235   (save-excursion
10236     (set-buffer gnus-summary-buffer)
10237     (goto-char (point-min))
10238     (while (and (progn
10239                   (when (> (gnus-summary-article-score) score)
10240                     (gnus-summary-mark-article nil mark))
10241                   t)
10242                 (gnus-summary-find-next)))))
10243
10244 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10245 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10246 (defun gnus-summary-limit-include-expunged (&optional no-error)
10247   "Display all the hidden articles that were expunged for low scores."
10248   (interactive)
10249   (let ((buffer-read-only nil))
10250     (let ((scored gnus-newsgroup-scored)
10251           headers h)
10252       (while scored
10253         (unless (gnus-summary-article-header (caar scored))
10254           (and (setq h (gnus-number-to-header (caar scored)))
10255                (< (cdar scored) gnus-summary-expunge-below)
10256                (push h headers)))
10257         (setq scored (cdr scored)))
10258       (if (not headers)
10259           (when (not no-error)
10260             (error "No expunged articles hidden"))
10261         (goto-char (point-min))
10262         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10263         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10264         (mapcar (lambda (x) (push (mail-header-number x)
10265                                   gnus-newsgroup-limit))
10266                 headers)
10267         (gnus-summary-prepare-unthreaded (nreverse headers))
10268         (goto-char (point-min))
10269         (gnus-summary-position-point)
10270         t))))
10271
10272 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10273   "Mark all unread articles in this newsgroup as read.
10274 If prefix argument ALL is non-nil, ticked and dormant articles will
10275 also be marked as read.
10276 If QUIETLY is non-nil, no questions will be asked.
10277
10278 If TO-HERE is non-nil, it should be a point in the buffer.  All
10279 articles before (after, if REVERSE is set) this point will be marked
10280 as read.
10281
10282 Note that this function will only catch up the unread article
10283 in the current summary buffer limitation.
10284
10285 The number of articles marked as read is returned."
10286   (interactive "P")
10287   (prog1
10288       (save-excursion
10289         (when (or quietly
10290                   (not gnus-interactive-catchup) ;Without confirmation?
10291                   gnus-expert-user
10292                   (gnus-y-or-n-p
10293                    (if all
10294                        "Mark absolutely all articles as read? "
10295                      "Mark all unread articles as read? ")))
10296           (if (and not-mark
10297                    (not gnus-newsgroup-adaptive)
10298                    (not gnus-newsgroup-auto-expire)
10299                    (not gnus-suppress-duplicates)
10300                    (or (not gnus-use-cache)
10301                        (eq gnus-use-cache 'passive)))
10302               (progn
10303                 (when all
10304                   (setq gnus-newsgroup-marked nil
10305                         gnus-newsgroup-spam-marked nil
10306                         gnus-newsgroup-dormant nil))
10307                 (setq gnus-newsgroup-unreads
10308                       (gnus-sorted-nunion
10309                        (gnus-intersection gnus-newsgroup-unreads
10310                                           gnus-newsgroup-downloadable)
10311                        gnus-newsgroup-unfetched)))
10312             ;; We actually mark all articles as canceled, which we
10313             ;; have to do when using auto-expiry or adaptive scoring.
10314             (gnus-summary-show-all-threads)
10315             (if (and to-here reverse)
10316                 (progn
10317                   (goto-char to-here)
10318                   (gnus-summary-mark-current-read-and-unread-as-read
10319                    gnus-catchup-mark)
10320                   (while (gnus-summary-find-next (not all))
10321                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10322               (when (gnus-summary-first-subject (not all))
10323                 (while (and
10324                         (if to-here (< (point) to-here) t)
10325                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10326                         (gnus-summary-find-next (not all))))))
10327             (gnus-set-mode-line 'summary))
10328           t))
10329     (gnus-summary-position-point)))
10330
10331 (defun gnus-summary-catchup-to-here (&optional all)
10332   "Mark all unticked articles before the current one as read.
10333 If ALL is non-nil, also mark ticked and dormant articles as read."
10334   (interactive "P")
10335   (save-excursion
10336     (gnus-save-hidden-threads
10337       (let ((beg (point)))
10338         ;; We check that there are unread articles.
10339         (when (or all (gnus-summary-find-prev))
10340           (gnus-summary-catchup all t beg)))))
10341   (gnus-summary-position-point))
10342
10343 (defun gnus-summary-catchup-from-here (&optional all)
10344   "Mark all unticked articles after (and including) the current one as read.
10345 If ALL is non-nil, also mark ticked and dormant articles as read."
10346   (interactive "P")
10347   (save-excursion
10348     (gnus-save-hidden-threads
10349       (let ((beg (point)))
10350         ;; We check that there are unread articles.
10351         (when (or all (gnus-summary-find-next))
10352           (gnus-summary-catchup all t beg nil t)))))
10353   (gnus-summary-position-point))
10354
10355 (defun gnus-summary-catchup-all (&optional quietly)
10356   "Mark all articles in this newsgroup as read.
10357 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10358 instead, which marks only unread articles as read."
10359   (interactive "P")
10360   (gnus-summary-catchup t quietly))
10361
10362 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10363   "Mark all unread articles in this group as read, then exit.
10364 If prefix argument ALL is non-nil, all articles are marked as read.
10365 If QUIETLY is non-nil, no questions will be asked."
10366   (interactive "P")
10367   (when (gnus-summary-catchup all quietly nil 'fast)
10368     ;; Select next newsgroup or exit.
10369     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10370              (eq gnus-auto-select-next 'quietly))
10371         (gnus-summary-next-group nil)
10372       (gnus-summary-exit))))
10373
10374 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10375   "Mark all articles in this newsgroup as read, and then exit.
10376 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10377 instead, which marks only unread articles as read."
10378   (interactive "P")
10379   (gnus-summary-catchup-and-exit t quietly))
10380
10381 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10382   "Mark all articles in this group as read and select the next group.
10383 If given a prefix, mark all articles, unread as well as ticked, as
10384 read."
10385   (interactive "P")
10386   (save-excursion
10387     (gnus-summary-catchup all))
10388   (gnus-summary-next-group))
10389
10390 ;;;
10391 ;;; with article
10392 ;;;
10393
10394 (defmacro gnus-with-article (article &rest forms)
10395   "Select ARTICLE and perform FORMS in the original article buffer.
10396 Then replace the article with the result."
10397   `(progn
10398      ;; We don't want the article to be marked as read.
10399      (let (gnus-mark-article-hook)
10400        (gnus-summary-select-article t t nil ,article))
10401      (set-buffer gnus-original-article-buffer)
10402      ,@forms
10403      (if (not (gnus-check-backend-function
10404                'request-replace-article (car gnus-article-current)))
10405          (gnus-message 5 "Read-only group; not replacing")
10406        (unless (gnus-request-replace-article
10407                 ,article (car gnus-article-current)
10408                 (current-buffer) t)
10409          (error "Couldn't replace article")))
10410      ;; The cache and backlog have to be flushed somewhat.
10411      (when gnus-keep-backlog
10412        (gnus-backlog-remove-article
10413         (car gnus-article-current) (cdr gnus-article-current)))
10414      (when gnus-use-cache
10415        (gnus-cache-update-article
10416         (car gnus-article-current) (cdr gnus-article-current)))))
10417
10418 (put 'gnus-with-article 'lisp-indent-function 1)
10419 (put 'gnus-with-article 'edebug-form-spec '(form body))
10420
10421 ;; Thread-based commands.
10422
10423 (defun gnus-summary-articles-in-thread (&optional article)
10424   "Return a list of all articles in the current thread.
10425 If ARTICLE is non-nil, return all articles in the thread that starts
10426 with that article."
10427   (let* ((article (or article (gnus-summary-article-number)))
10428          (data (gnus-data-find-list article))
10429          (top-level (gnus-data-level (car data)))
10430          (top-subject
10431           (cond ((null gnus-thread-operation-ignore-subject)
10432                  (gnus-simplify-subject-re
10433                   (mail-header-subject (gnus-data-header (car data)))))
10434                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10435                  (gnus-simplify-subject-fuzzy
10436                   (mail-header-subject (gnus-data-header (car data)))))
10437                 (t nil)))
10438          (end-point (save-excursion
10439                       (if (gnus-summary-go-to-next-thread)
10440                           (point) (point-max))))
10441          articles)
10442     (while (and data
10443                 (< (gnus-data-pos (car data)) end-point))
10444       (when (or (not top-subject)
10445                 (string= top-subject
10446                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10447                              (gnus-simplify-subject-fuzzy
10448                               (mail-header-subject
10449                                (gnus-data-header (car data))))
10450                            (gnus-simplify-subject-re
10451                             (mail-header-subject
10452                              (gnus-data-header (car data)))))))
10453         (push (gnus-data-number (car data)) articles))
10454       (unless (and (setq data (cdr data))
10455                    (> (gnus-data-level (car data)) top-level))
10456         (setq data nil)))
10457     ;; Return the list of articles.
10458     (nreverse articles)))
10459
10460 (defun gnus-summary-rethread-current ()
10461   "Rethread the thread the current article is part of."
10462   (interactive)
10463   (let* ((gnus-show-threads t)
10464          (article (gnus-summary-article-number))
10465          (id (mail-header-id (gnus-summary-article-header)))
10466          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10467     (unless id
10468       (error "No article on the current line"))
10469     (gnus-rebuild-thread id)
10470     (gnus-summary-goto-subject article)))
10471
10472 (defun gnus-summary-reparent-thread ()
10473   "Make the current article child of the marked (or previous) article.
10474
10475 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10476 is non-nil or the Subject: of both articles are the same."
10477   (interactive)
10478   (unless (not (gnus-group-read-only-p))
10479     (error "The current newsgroup does not support article editing"))
10480   (unless (<= (length gnus-newsgroup-processable) 1)
10481     (error "No more than one article may be marked"))
10482   (save-window-excursion
10483     (let ((gnus-article-buffer " *reparent*")
10484           (current-article (gnus-summary-article-number))
10485           ;; First grab the marked article, otherwise one line up.
10486           (parent-article (if (not (null gnus-newsgroup-processable))
10487                               (car gnus-newsgroup-processable)
10488                             (save-excursion
10489                               (if (eq (forward-line -1) 0)
10490                                   (gnus-summary-article-number)
10491                                 (error "Beginning of summary buffer"))))))
10492       (unless (not (eq current-article parent-article))
10493         (error "An article may not be self-referential"))
10494       (let ((message-id (mail-header-id
10495                          (gnus-summary-article-header parent-article))))
10496         (unless (and message-id (not (equal message-id "")))
10497           (error "No message-id in desired parent"))
10498         (gnus-with-article current-article
10499           (save-restriction
10500             (goto-char (point-min))
10501             (message-narrow-to-head)
10502             (if (re-search-forward "^References: " nil t)
10503                 (progn
10504                   (re-search-forward "^[^ \t]" nil t)
10505                   (forward-line -1)
10506                   (end-of-line)
10507                   (insert " " message-id))
10508               (insert "References: " message-id "\n"))))
10509         (set-buffer gnus-summary-buffer)
10510         (gnus-summary-unmark-all-processable)
10511         (gnus-summary-update-article current-article)
10512         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10513             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10514         (gnus-summary-rethread-current)
10515         (gnus-message 3 "Article %d is now the child of article %d"
10516                       current-article parent-article)))))
10517
10518 (defun gnus-summary-toggle-threads (&optional arg)
10519   "Toggle showing conversation threads.
10520 If ARG is positive number, turn showing conversation threads on."
10521   (interactive "P")
10522   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10523     (setq gnus-show-threads
10524           (if (null arg) (not gnus-show-threads)
10525             (> (prefix-numeric-value arg) 0)))
10526     (gnus-summary-prepare)
10527     (gnus-summary-goto-subject current)
10528     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10529     (gnus-summary-position-point)))
10530
10531 (defun gnus-summary-show-all-threads ()
10532   "Show all threads."
10533   (interactive)
10534   (save-excursion
10535     (let ((buffer-read-only nil))
10536       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10537   (gnus-summary-position-point))
10538
10539 (defun gnus-summary-show-thread ()
10540   "Show thread subtrees.
10541 Returns nil if no thread was there to be shown."
10542   (interactive)
10543   (let ((buffer-read-only nil)
10544         (orig (point))
10545         (end (point-at-eol))
10546         ;; Leave point at bol
10547         (beg (progn (beginning-of-line) (point))))
10548     (prog1
10549         ;; Any hidden lines here?
10550         (search-forward "\r" end t)
10551       (subst-char-in-region beg end ?\^M ?\n t)
10552       (goto-char orig)
10553       (gnus-summary-position-point))))
10554
10555 (defun gnus-summary-maybe-hide-threads ()
10556   "If requested, hide the threads that should be hidden."
10557   (when (and gnus-show-threads
10558              gnus-thread-hide-subtree)
10559     (gnus-summary-hide-all-threads
10560      (if (or (consp gnus-thread-hide-subtree)
10561              (functionp gnus-thread-hide-subtree))
10562          (gnus-make-predicate gnus-thread-hide-subtree)
10563        nil))))
10564
10565 ;;; Hiding predicates.
10566
10567 (defun gnus-article-unread-p (header)
10568   (memq (mail-header-number header) gnus-newsgroup-unreads))
10569
10570 (defun gnus-article-unseen-p (header)
10571   (memq (mail-header-number header) gnus-newsgroup-unseen))
10572
10573 (defun gnus-map-articles (predicate articles)
10574   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10575   (apply 'gnus-or (mapcar predicate
10576                           (mapcar 'gnus-summary-article-header articles))))
10577
10578 (defun gnus-summary-hide-all-threads (&optional predicate)
10579   "Hide all thread subtrees.
10580 If PREDICATE is supplied, threads that satisfy this predicate
10581 will not be hidden."
10582   (interactive)
10583   (save-excursion
10584     (goto-char (point-min))
10585     (let ((end nil))
10586       (while (not end)
10587         (when (or (not predicate)
10588                   (gnus-map-articles
10589                    predicate (gnus-summary-article-children)))
10590             (gnus-summary-hide-thread))
10591         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10592   (gnus-summary-position-point))
10593
10594 (defun gnus-summary-hide-thread ()
10595   "Hide thread subtrees.
10596 If PREDICATE is supplied, threads that satisfy this predicate
10597 will not be hidden.
10598 Returns nil if no threads were there to be hidden."
10599   (interactive)
10600   (let ((buffer-read-only nil)
10601         (start (point))
10602         (article (gnus-summary-article-number)))
10603     (goto-char start)
10604     ;; Go forward until either the buffer ends or the subthread
10605     ;; ends.
10606     (when (and (not (eobp))
10607                (or (zerop (gnus-summary-next-thread 1 t))
10608                    (goto-char (point-max))))
10609       (prog1
10610           (if (and (> (point) start)
10611                    (search-backward "\n" start t))
10612               (progn
10613                 (subst-char-in-region start (point) ?\n ?\^M)
10614                 (gnus-summary-goto-subject article))
10615             (goto-char start)
10616             nil)))))
10617
10618 (defun gnus-summary-go-to-next-thread (&optional previous)
10619   "Go to the same level (or less) next thread.
10620 If PREVIOUS is non-nil, go to previous thread instead.
10621 Return the article number moved to, or nil if moving was impossible."
10622   (let ((level (gnus-summary-thread-level))
10623         (way (if previous -1 1))
10624         (beg (point)))
10625     (forward-line way)
10626     (while (and (not (eobp))
10627                 (< level (gnus-summary-thread-level)))
10628       (forward-line way))
10629     (if (eobp)
10630         (progn
10631           (goto-char beg)
10632           nil)
10633       (setq beg (point))
10634       (prog1
10635           (gnus-summary-article-number)
10636         (goto-char beg)))))
10637
10638 (defun gnus-summary-next-thread (n &optional silent)
10639   "Go to the same level next N'th thread.
10640 If N is negative, search backward instead.
10641 Returns the difference between N and the number of skips actually
10642 done.
10643
10644 If SILENT, don't output messages."
10645   (interactive "p")
10646   (let ((backward (< n 0))
10647         (n (abs n)))
10648     (while (and (> n 0)
10649                 (gnus-summary-go-to-next-thread backward))
10650       (decf n))
10651     (unless silent
10652       (gnus-summary-position-point))
10653     (when (and (not silent) (/= 0 n))
10654       (gnus-message 7 "No more threads"))
10655     n))
10656
10657 (defun gnus-summary-prev-thread (n)
10658   "Go to the same level previous N'th thread.
10659 Returns the difference between N and the number of skips actually
10660 done."
10661   (interactive "p")
10662   (gnus-summary-next-thread (- n)))
10663
10664 (defun gnus-summary-go-down-thread ()
10665   "Go down one level in the current thread."
10666   (let ((children (gnus-summary-article-children)))
10667     (when children
10668       (gnus-summary-goto-subject (car children)))))
10669
10670 (defun gnus-summary-go-up-thread ()
10671   "Go up one level in the current thread."
10672   (let ((parent (gnus-summary-article-parent)))
10673     (when parent
10674       (gnus-summary-goto-subject parent))))
10675
10676 (defun gnus-summary-down-thread (n)
10677   "Go down thread N steps.
10678 If N is negative, go up instead.
10679 Returns the difference between N and how many steps down that were
10680 taken."
10681   (interactive "p")
10682   (let ((up (< n 0))
10683         (n (abs n)))
10684     (while (and (> n 0)
10685                 (if up (gnus-summary-go-up-thread)
10686                   (gnus-summary-go-down-thread)))
10687       (setq n (1- n)))
10688     (gnus-summary-position-point)
10689     (when (/= 0 n)
10690       (gnus-message 7 "Can't go further"))
10691     n))
10692
10693 (defun gnus-summary-up-thread (n)
10694   "Go up thread N steps.
10695 If N is negative, go down instead.
10696 Returns the difference between N and how many steps down that were
10697 taken."
10698   (interactive "p")
10699   (gnus-summary-down-thread (- n)))
10700
10701 (defun gnus-summary-top-thread ()
10702   "Go to the top of the thread."
10703   (interactive)
10704   (while (gnus-summary-go-up-thread))
10705   (gnus-summary-article-number))
10706
10707 (defun gnus-summary-kill-thread (&optional unmark)
10708   "Mark articles under current thread as read.
10709 If the prefix argument is positive, remove any kinds of marks.
10710 If the prefix argument is negative, tick articles instead."
10711   (interactive "P")
10712   (when unmark
10713     (setq unmark (prefix-numeric-value unmark)))
10714   (let ((articles (gnus-summary-articles-in-thread)))
10715     (save-excursion
10716       ;; Expand the thread.
10717       (gnus-summary-show-thread)
10718       ;; Mark all the articles.
10719       (while articles
10720         (gnus-summary-goto-subject (car articles))
10721         (cond ((null unmark)
10722                (gnus-summary-mark-article-as-read gnus-killed-mark))
10723               ((> unmark 0)
10724                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10725               (t
10726                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10727         (setq articles (cdr articles))))
10728     ;; Hide killed subtrees.
10729     (and (null unmark)
10730          gnus-thread-hide-killed
10731          (gnus-summary-hide-thread))
10732     ;; If marked as read, go to next unread subject.
10733     (when (null unmark)
10734       ;; Go to next unread subject.
10735       (gnus-summary-next-subject 1 t)))
10736   (gnus-set-mode-line 'summary))
10737
10738 ;; Summary sorting commands
10739
10740 (defun gnus-summary-sort-by-number (&optional reverse)
10741   "Sort the summary buffer by article number.
10742 Argument REVERSE means reverse order."
10743   (interactive "P")
10744   (gnus-summary-sort 'number reverse))
10745
10746 (defun gnus-summary-sort-by-random (&optional reverse)
10747   "Randomize the order in the summary buffer.
10748 Argument REVERSE means to randomize in reverse order."
10749   (interactive "P")
10750   (gnus-summary-sort 'random reverse))
10751
10752 (defun gnus-summary-sort-by-author (&optional reverse)
10753   "Sort the summary buffer by author name alphabetically.
10754 If `case-fold-search' is non-nil, case of letters is ignored.
10755 Argument REVERSE means reverse order."
10756   (interactive "P")
10757   (gnus-summary-sort 'author reverse))
10758
10759 (defun gnus-summary-sort-by-subject (&optional reverse)
10760   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10761 If `case-fold-search' is non-nil, case of letters is ignored.
10762 Argument REVERSE means reverse order."
10763   (interactive "P")
10764   (gnus-summary-sort 'subject reverse))
10765
10766 (defun gnus-summary-sort-by-date (&optional reverse)
10767   "Sort the summary buffer by date.
10768 Argument REVERSE means reverse order."
10769   (interactive "P")
10770   (gnus-summary-sort 'date reverse))
10771
10772 (defun gnus-summary-sort-by-score (&optional reverse)
10773   "Sort the summary buffer by score.
10774 Argument REVERSE means reverse order."
10775   (interactive "P")
10776   (gnus-summary-sort 'score reverse))
10777
10778 (defun gnus-summary-sort-by-lines (&optional reverse)
10779   "Sort the summary buffer by the number of lines.
10780 Argument REVERSE means reverse order."
10781   (interactive "P")
10782   (gnus-summary-sort 'lines reverse))
10783
10784 (defun gnus-summary-sort-by-chars (&optional reverse)
10785   "Sort the summary buffer by article length.
10786 Argument REVERSE means reverse order."
10787   (interactive "P")
10788   (gnus-summary-sort 'chars reverse))
10789
10790 (defun gnus-summary-sort-by-original (&optional reverse)
10791   "Sort the summary buffer using the default sorting method.
10792 Argument REVERSE means reverse order."
10793   (interactive "P")
10794   (let* ((buffer-read-only)
10795          (gnus-summary-prepare-hook nil))
10796     ;; We do the sorting by regenerating the threads.
10797     (gnus-summary-prepare)
10798     ;; Hide subthreads if needed.
10799     (gnus-summary-maybe-hide-threads)))
10800
10801 (defun gnus-summary-sort (predicate reverse)
10802   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10803   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10804          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10805          (gnus-thread-sort-functions
10806           (if (not reverse)
10807               thread
10808             `(lambda (t1 t2)
10809                (,thread t2 t1))))
10810          (gnus-sort-gathered-threads-function
10811           gnus-thread-sort-functions)
10812          (gnus-article-sort-functions
10813           (if (not reverse)
10814               article
10815             `(lambda (t1 t2)
10816                (,article t2 t1))))
10817          (buffer-read-only)
10818          (gnus-summary-prepare-hook nil))
10819     ;; We do the sorting by regenerating the threads.
10820     (gnus-summary-prepare)
10821     ;; Hide subthreads if needed.
10822     (gnus-summary-maybe-hide-threads)))
10823
10824 ;; Summary saving commands.
10825
10826 (defun gnus-summary-save-article (&optional n not-saved)
10827   "Save the current article using the default saver function.
10828 If N is a positive number, save the N next articles.
10829 If N is a negative number, save the N previous articles.
10830 If N is nil and any articles have been marked with the process mark,
10831 save those articles instead.
10832 The variable `gnus-default-article-saver' specifies the saver function."
10833   (interactive "P")
10834   (let* ((articles (gnus-summary-work-articles n))
10835          (save-buffer (save-excursion
10836                         (nnheader-set-temp-buffer " *Gnus Save*")))
10837          (num (length articles))
10838          header file)
10839     (dolist (article articles)
10840       (setq header (gnus-summary-article-header article))
10841       (if (not (vectorp header))
10842           ;; This is a pseudo-article.
10843           (if (assq 'name header)
10844               (gnus-copy-file (cdr (assq 'name header)))
10845             (gnus-message 1 "Article %d is unsaveable" article))
10846         ;; This is a real article.
10847         (save-window-excursion
10848           (let ((gnus-display-mime-function nil)
10849                 (gnus-article-prepare-hook nil))
10850             (gnus-summary-select-article t nil nil article)))
10851         (save-excursion
10852           (set-buffer save-buffer)
10853           (erase-buffer)
10854           (insert-buffer-substring gnus-original-article-buffer))
10855         (setq file (gnus-article-save save-buffer file num))
10856         (gnus-summary-remove-process-mark article)
10857         (unless not-saved
10858           (gnus-summary-set-saved-mark article))))
10859     (gnus-kill-buffer save-buffer)
10860     (gnus-summary-position-point)
10861     (gnus-set-mode-line 'summary)
10862     n))
10863
10864 (defun gnus-summary-pipe-output (&optional arg headers)
10865   "Pipe the current article to a subprocess.
10866 If N is a positive number, pipe the N next articles.
10867 If N is a negative number, pipe the N previous articles.
10868 If N is nil and any articles have been marked with the process mark,
10869 pipe those articles instead.
10870 If HEADERS (the symbolic prefix), include the headers, too."
10871   (interactive (gnus-interactive "P\ny"))
10872   (require 'gnus-art)
10873   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10874         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10875     (gnus-summary-save-article arg t))
10876   (let ((buffer (get-buffer "*Shell Command Output*")))
10877     (when (and buffer
10878                (not (zerop (buffer-size buffer))))
10879       (gnus-configure-windows 'pipe))))
10880
10881 (defun gnus-summary-save-article-mail (&optional arg)
10882   "Append the current article to an mail file.
10883 If N is a positive number, save the N next articles.
10884 If N is a negative number, save the N previous articles.
10885 If N is nil and any articles have been marked with the process mark,
10886 save those articles instead."
10887   (interactive "P")
10888   (require 'gnus-art)
10889   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10890     (gnus-summary-save-article arg)))
10891
10892 (defun gnus-summary-save-article-rmail (&optional arg)
10893   "Append the current article to an rmail file.
10894 If N is a positive number, save the N next articles.
10895 If N is a negative number, save the N previous articles.
10896 If N is nil and any articles have been marked with the process mark,
10897 save those articles instead."
10898   (interactive "P")
10899   (require 'gnus-art)
10900   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10901     (gnus-summary-save-article arg)))
10902
10903 (defun gnus-summary-save-article-file (&optional arg)
10904   "Append the current article to a file.
10905 If N is a positive number, save the N next articles.
10906 If N is a negative number, save the N previous articles.
10907 If N is nil and any articles have been marked with the process mark,
10908 save those articles instead."
10909   (interactive "P")
10910   (require 'gnus-art)
10911   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10912     (gnus-summary-save-article arg)))
10913
10914 (defun gnus-summary-write-article-file (&optional arg)
10915   "Write the current article to a file, deleting the previous file.
10916 If N is a positive number, save the N next articles.
10917 If N is a negative number, save the N previous articles.
10918 If N is nil and any articles have been marked with the process mark,
10919 save those articles instead."
10920   (interactive "P")
10921   (require 'gnus-art)
10922   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10923     (gnus-summary-save-article arg)))
10924
10925 (defun gnus-summary-save-article-body-file (&optional arg)
10926   "Append the current article body to a file.
10927 If N is a positive number, save the N next articles.
10928 If N is a negative number, save the N previous articles.
10929 If N is nil and any articles have been marked with the process mark,
10930 save those articles instead."
10931   (interactive "P")
10932   (require 'gnus-art)
10933   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10934     (gnus-summary-save-article arg)))
10935
10936 (defun gnus-summary-muttprint (&optional arg)
10937   "Print the current article using Muttprint.
10938 If N is a positive number, save the N next articles.
10939 If N is a negative number, save the N previous articles.
10940 If N is nil and any articles have been marked with the process mark,
10941 save those articles instead."
10942   (interactive "P")
10943   (require 'gnus-art)
10944   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10945     (gnus-summary-save-article arg t)))
10946
10947 (defun gnus-summary-pipe-message (program)
10948   "Pipe the current article through PROGRAM."
10949   (interactive "sProgram: ")
10950   (gnus-summary-select-article)
10951   (let ((mail-header-separator ""))
10952     (gnus-eval-in-buffer-window gnus-article-buffer
10953       (save-restriction
10954         (widen)
10955         (let ((start (window-start))
10956               buffer-read-only)
10957           (message-pipe-buffer-body program)
10958           (set-window-start (get-buffer-window (current-buffer)) start))))))
10959
10960 (defun gnus-get-split-value (methods)
10961   "Return a value based on the split METHODS."
10962   (let (split-name method result match)
10963     (when methods
10964       (save-excursion
10965         (set-buffer gnus-original-article-buffer)
10966         (save-restriction
10967           (nnheader-narrow-to-headers)
10968           (while (and methods (not split-name))
10969             (goto-char (point-min))
10970             (setq method (pop methods))
10971             (setq match (car method))
10972             (when (cond
10973                    ((stringp match)
10974                     ;; Regular expression.
10975                     (ignore-errors
10976                       (re-search-forward match nil t)))
10977                    ((functionp match)
10978                     ;; Function.
10979                     (save-restriction
10980                       (widen)
10981                       (setq result (funcall match gnus-newsgroup-name))))
10982                    ((consp match)
10983                     ;; Form.
10984                     (save-restriction
10985                       (widen)
10986                       (setq result (eval match)))))
10987               (setq split-name (cdr method))
10988               (cond ((stringp result)
10989                      (push (expand-file-name
10990                             result gnus-article-save-directory)
10991                            split-name))
10992                     ((consp result)
10993                      (setq split-name (append result split-name)))))))))
10994     (nreverse split-name)))
10995
10996 (defun gnus-valid-move-group-p (group)
10997   (and (boundp group)
10998        (symbol-name group)
10999        (symbol-value group)
11000        (gnus-get-function (gnus-find-method-for-group
11001                            (symbol-name group)) 'request-accept-article t)))
11002
11003 (defun gnus-read-move-group-name (prompt default articles prefix)
11004   "Read a group name."
11005   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11006          (minibuffer-confirm-incomplete nil) ; XEmacs
11007          (prom
11008           (format "%s %s to:"
11009                   prompt
11010                   (if (> (length articles) 1)
11011                       (format "these %d articles" (length articles))
11012                     "this article")))
11013          (to-newsgroup
11014           (cond
11015            ((null split-name)
11016             (gnus-completing-read-with-default
11017              default prom
11018              gnus-active-hashtb
11019              'gnus-valid-move-group-p
11020              nil prefix
11021              'gnus-group-history))
11022            ((= 1 (length split-name))
11023             (gnus-completing-read-with-default
11024              (car split-name) prom
11025              gnus-active-hashtb
11026              'gnus-valid-move-group-p
11027              nil nil
11028              'gnus-group-history))
11029            (t
11030             (gnus-completing-read-with-default
11031              nil prom
11032              (mapcar (lambda (el) (list el))
11033                      (nreverse split-name))
11034              nil nil nil
11035              'gnus-group-history))))
11036          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11037     (when to-newsgroup
11038       (if (or (string= to-newsgroup "")
11039               (string= to-newsgroup prefix))
11040           (setq to-newsgroup default))
11041       (unless to-newsgroup
11042         (error "No group name entered"))
11043       (or (gnus-active to-newsgroup)
11044           (gnus-activate-group to-newsgroup nil nil to-method)
11045           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11046                                      to-newsgroup))
11047               (or (and (gnus-request-create-group to-newsgroup to-method)
11048                        (gnus-activate-group
11049                         to-newsgroup nil nil to-method)
11050                        (gnus-subscribe-group to-newsgroup))
11051                   (error "Couldn't create group %s" to-newsgroup)))
11052           (error "No such group: %s" to-newsgroup)))
11053     to-newsgroup))
11054
11055 (defun gnus-summary-save-parts (type dir n &optional reverse)
11056   "Save parts matching TYPE to DIR.
11057 If REVERSE, save parts that do not match TYPE."
11058   (interactive
11059    (list (read-string "Save parts of type: "
11060                       (or (car gnus-summary-save-parts-type-history)
11061                           gnus-summary-save-parts-default-mime)
11062                       'gnus-summary-save-parts-type-history)
11063          (setq gnus-summary-save-parts-last-directory
11064                (read-file-name "Save to directory: "
11065                                gnus-summary-save-parts-last-directory
11066                                nil t))
11067          current-prefix-arg))
11068   (gnus-summary-iterate n
11069     (let ((gnus-display-mime-function nil)
11070           (gnus-inhibit-treatment t))
11071       (gnus-summary-select-article))
11072     (save-excursion
11073       (set-buffer gnus-article-buffer)
11074       (let ((handles (or gnus-article-mime-handles
11075                          (mm-dissect-buffer nil gnus-article-loose-mime)
11076                          (and gnus-article-emulate-mime
11077                               (mm-uu-dissect)))))
11078         (when handles
11079           (gnus-summary-save-parts-1 type dir handles reverse)
11080           (unless gnus-article-mime-handles ;; Don't destroy this case.
11081             (mm-destroy-parts handles)))))))
11082
11083 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11084   (if (stringp (car handle))
11085       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11086               (cdr handle))
11087     (when (if reverse
11088               (not (string-match type (mm-handle-media-type handle)))
11089             (string-match type (mm-handle-media-type handle)))
11090       (let ((file (expand-file-name
11091                    (gnus-map-function
11092                     mm-file-name-rewrite-functions
11093                     (file-name-nondirectory
11094                      (or
11095                       (mail-content-type-get
11096                        (mm-handle-disposition handle) 'filename)
11097                       (mail-content-type-get
11098                        (mm-handle-type handle) 'name)
11099                       (concat gnus-newsgroup-name
11100                               "." (number-to-string
11101                                    (cdr gnus-article-current))))))
11102                    dir)))
11103         (unless (file-exists-p file)
11104           (mm-save-part-to-file handle file))))))
11105
11106 ;; Summary extract commands
11107
11108 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11109   (let ((buffer-read-only nil)
11110         (article (gnus-summary-article-number))
11111         after-article b e)
11112     (unless (gnus-summary-goto-subject article)
11113       (error "No such article: %d" article))
11114     (gnus-summary-position-point)
11115     ;; If all commands are to be bunched up on one line, we collect
11116     ;; them here.
11117     (unless gnus-view-pseudos-separately
11118       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11119             files action)
11120         (while ps
11121           (setq action (cdr (assq 'action (car ps))))
11122           (setq files (list (cdr (assq 'name (car ps)))))
11123           (while (and ps (cdr ps)
11124                       (string= (or action "1")
11125                                (or (cdr (assq 'action (cadr ps))) "2")))
11126             (push (cdr (assq 'name (cadr ps))) files)
11127             (setcdr ps (cddr ps)))
11128           (when files
11129             (when (not (string-match "%s" action))
11130               (push " " files))
11131             (push " " files)
11132             (when (assq 'execute (car ps))
11133               (setcdr (assq 'execute (car ps))
11134                       (funcall (if (string-match "%s" action)
11135                                    'format 'concat)
11136                                action
11137                                (mapconcat
11138                                 (lambda (f)
11139                                   (if (equal f " ")
11140                                       f
11141                                     (shell-quote-argument f)))
11142                                 files " ")))))
11143           (setq ps (cdr ps)))))
11144     (if (and gnus-view-pseudos (not not-view))
11145         (while pslist
11146           (when (assq 'execute (car pslist))
11147             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11148                                   (eq gnus-view-pseudos 'not-confirm)))
11149           (setq pslist (cdr pslist)))
11150       (save-excursion
11151         (while pslist
11152           (setq after-article (or (cdr (assq 'article (car pslist)))
11153                                   (gnus-summary-article-number)))
11154           (gnus-summary-goto-subject after-article)
11155           (forward-line 1)
11156           (setq b (point))
11157           (insert "    " (file-name-nondirectory
11158                           (cdr (assq 'name (car pslist))))
11159                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11160           (setq e (point))
11161           (forward-line -1)             ; back to `b'
11162           (gnus-add-text-properties
11163            b (1- e) (list 'gnus-number gnus-reffed-article-number
11164                           gnus-mouse-face-prop gnus-mouse-face))
11165           (gnus-data-enter
11166            after-article gnus-reffed-article-number
11167            gnus-unread-mark b (car pslist) 0 (- e b))
11168           (setq gnus-newsgroup-unreads
11169                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11170                                          gnus-reffed-article-number))
11171           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11172           (setq pslist (cdr pslist)))))))
11173
11174 (defun gnus-pseudos< (p1 p2)
11175   (let ((c1 (cdr (assq 'action p1)))
11176         (c2 (cdr (assq 'action p2))))
11177     (and c1 c2 (string< c1 c2))))
11178
11179 (defun gnus-request-pseudo-article (props)
11180   (cond ((assq 'execute props)
11181          (gnus-execute-command (cdr (assq 'execute props)))))
11182   (let ((gnus-current-article (gnus-summary-article-number)))
11183     (gnus-run-hooks 'gnus-mark-article-hook)))
11184
11185 (defun gnus-execute-command (command &optional automatic)
11186   (save-excursion
11187     (gnus-article-setup-buffer)
11188     (set-buffer gnus-article-buffer)
11189     (setq buffer-read-only nil)
11190     (let ((command (if automatic command
11191                      (read-string "Command: " (cons command 0)))))
11192       (erase-buffer)
11193       (insert "$ " command "\n\n")
11194       (if gnus-view-pseudo-asynchronously
11195           (start-process "gnus-execute" (current-buffer) shell-file-name
11196                          shell-command-switch command)
11197         (call-process shell-file-name nil t nil
11198                       shell-command-switch command)))))
11199
11200 ;; Summary kill commands.
11201
11202 (defun gnus-summary-edit-global-kill (article)
11203   "Edit the \"global\" kill file."
11204   (interactive (list (gnus-summary-article-number)))
11205   (gnus-group-edit-global-kill article))
11206
11207 (defun gnus-summary-edit-local-kill ()
11208   "Edit a local kill file applied to the current newsgroup."
11209   (interactive)
11210   (setq gnus-current-headers (gnus-summary-article-header))
11211   (gnus-group-edit-local-kill
11212    (gnus-summary-article-number) gnus-newsgroup-name))
11213
11214 ;;; Header reading.
11215
11216 (defun gnus-read-header (id &optional header)
11217   "Read the headers of article ID and enter them into the Gnus system."
11218   (let ((group gnus-newsgroup-name)
11219         (gnus-override-method
11220          (or
11221           gnus-override-method
11222           (and (gnus-news-group-p gnus-newsgroup-name)
11223                (car (gnus-refer-article-methods)))))
11224         where)
11225     ;; First we check to see whether the header in question is already
11226     ;; fetched.
11227     (if (stringp id)
11228         ;; This is a Message-ID.
11229         (setq header (or header (gnus-id-to-header id)))
11230       ;; This is an article number.
11231       (setq header (or header (gnus-summary-article-header id))))
11232     (if (and header
11233              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11234         ;; We have found the header.
11235         header
11236       ;; If this is a sparse article, we have to nix out its
11237       ;; previous entry in the thread hashtb.
11238       (when (and header
11239                  (gnus-summary-article-sparse-p (mail-header-number header)))
11240         (let* ((parent (gnus-parent-id (mail-header-references header)))
11241                (thread (and parent (gnus-id-to-thread parent))))
11242           (when thread
11243             (delq (assq header thread) thread))))
11244       ;; We have to really fetch the header to this article.
11245       (save-excursion
11246         (set-buffer nntp-server-buffer)
11247         (when (setq where (gnus-request-head id group))
11248           (nnheader-fold-continuation-lines)
11249           (goto-char (point-max))
11250           (insert ".\n")
11251           (goto-char (point-min))
11252           (insert "211 ")
11253           (princ (cond
11254                   ((numberp id) id)
11255                   ((cdr where) (cdr where))
11256                   (header (mail-header-number header))
11257                   (t gnus-reffed-article-number))
11258                  (current-buffer))
11259           (insert " Article retrieved.\n"))
11260         (if (or (not where)
11261                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11262             ()                          ; Malformed head.
11263           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11264             (when (and (stringp id)
11265                        (not (string= (gnus-group-real-name group)
11266                                      (car where))))
11267               ;; If we fetched by Message-ID and the article came
11268               ;; from a different group, we fudge some bogus article
11269               ;; numbers for this article.
11270               (mail-header-set-number header gnus-reffed-article-number))
11271             (save-excursion
11272               (set-buffer gnus-summary-buffer)
11273               (decf gnus-reffed-article-number)
11274               (gnus-remove-header (mail-header-number header))
11275               (push header gnus-newsgroup-headers)
11276               (setq gnus-current-headers header)
11277               (push (mail-header-number header) gnus-newsgroup-limit)))
11278           header)))))
11279
11280 (defun gnus-remove-header (number)
11281   "Remove header NUMBER from `gnus-newsgroup-headers'."
11282   (if (and gnus-newsgroup-headers
11283            (= number (mail-header-number (car gnus-newsgroup-headers))))
11284       (pop gnus-newsgroup-headers)
11285     (let ((headers gnus-newsgroup-headers))
11286       (while (and (cdr headers)
11287                   (not (= number (mail-header-number (cadr headers)))))
11288         (pop headers))
11289       (when (cdr headers)
11290         (setcdr headers (cddr headers))))))
11291
11292 ;;;
11293 ;;; summary highlights
11294 ;;;
11295
11296 (defun gnus-highlight-selected-summary ()
11297   "Highlight selected article in summary buffer."
11298   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11299   (when gnus-summary-selected-face
11300     (save-excursion
11301       (let* ((beg (point-at-bol))
11302              (end (point-at-eol))
11303              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11304              (from (if (get-text-property beg gnus-mouse-face-prop)
11305                        beg
11306                      (or (next-single-property-change
11307                           beg gnus-mouse-face-prop nil end)
11308                          beg)))
11309              (to
11310               (if (= from end)
11311                   (- from 2)
11312                 (or (next-single-property-change
11313                      from gnus-mouse-face-prop nil end)
11314                     end))))
11315         ;; If no mouse-face prop on line we will have to = from = end,
11316         ;; so we highlight the entire line instead.
11317         (when (= (+ to 2) from)
11318           (setq from beg)
11319           (setq to end))
11320         (if gnus-newsgroup-selected-overlay
11321             ;; Move old overlay.
11322             (gnus-move-overlay
11323              gnus-newsgroup-selected-overlay from to (current-buffer))
11324           ;; Create new overlay.
11325           (gnus-overlay-put
11326            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11327            'face gnus-summary-selected-face))))))
11328
11329 (defvar gnus-summary-highlight-line-cached nil)
11330 (defvar gnus-summary-highlight-line-trigger nil)
11331
11332 (defun gnus-summary-highlight-line-0 ()
11333   (if (and (eq gnus-summary-highlight-line-trigger
11334                gnus-summary-highlight)
11335            gnus-summary-highlight-line-cached)
11336       gnus-summary-highlight-line-cached
11337     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11338           gnus-summary-highlight-line-cached
11339           (let* ((cond (list 'cond))
11340                  (c cond)
11341                  (list gnus-summary-highlight))
11342             (while list
11343               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11344                               nil))
11345               (setq c (cdr c)
11346                     list (cdr list)))
11347             (gnus-byte-compile (list 'lambda nil cond))))))
11348
11349 (defun gnus-summary-highlight-line ()
11350   "Highlight current line according to `gnus-summary-highlight'."
11351   (let* ((beg (point-at-bol))
11352          (article (or (gnus-summary-article-number) gnus-current-article))
11353          (score (or (cdr (assq article
11354                                gnus-newsgroup-scored))
11355                     gnus-summary-default-score 0))
11356          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11357          (inhibit-read-only t)
11358          (default gnus-summary-default-score)
11359          (default-high gnus-summary-default-high-score)
11360          (default-low gnus-summary-default-low-score)
11361          (uncached (and gnus-summary-use-undownloaded-faces
11362                         (memq article gnus-newsgroup-undownloaded))))
11363     (let ((face (funcall (gnus-summary-highlight-line-0))))
11364       (unless (eq face (get-text-property beg 'face))
11365         (gnus-put-text-property-excluding-characters-with-faces
11366          beg (point-at-eol) 'face
11367          (setq face (if (boundp face) (symbol-value face) face)))
11368         (when gnus-summary-highlight-line-function
11369           (funcall gnus-summary-highlight-line-function article face))))))
11370
11371 (defun gnus-update-read-articles (group unread &optional compute)
11372   "Update the list of read articles in GROUP.
11373 UNREAD is a sorted list."
11374   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11375         (info (gnus-get-info group))
11376         (prev 1)
11377         read)
11378     (if (or (not info) (not active))
11379         ;; There is no info on this group if it was, in fact,
11380         ;; killed.  Gnus stores no information on killed groups, so
11381         ;; there's nothing to be done.
11382         ;; One could store the information somewhere temporarily,
11383         ;; perhaps...  Hmmm...
11384         ()
11385       ;; Remove any negative articles numbers.
11386       (while (and unread (< (car unread) 0))
11387         (setq unread (cdr unread)))
11388       ;; Remove any expired article numbers
11389       (while (and unread (< (car unread) (car active)))
11390         (setq unread (cdr unread)))
11391       ;; Compute the ranges of read articles by looking at the list of
11392       ;; unread articles.
11393       (while unread
11394         (when (/= (car unread) prev)
11395           (push (if (= prev (1- (car unread))) prev
11396                   (cons prev (1- (car unread))))
11397                 read))
11398         (setq prev (1+ (car unread)))
11399         (setq unread (cdr unread)))
11400       (when (<= prev (cdr active))
11401         (push (cons prev (cdr active)) read))
11402       (setq read (if (> (length read) 1) (nreverse read) read))
11403       (if compute
11404           read
11405         (save-excursion
11406           (let (setmarkundo)
11407             ;; Propagate the read marks to the backend.
11408             (when (gnus-check-backend-function 'request-set-mark group)
11409               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11410                     (add (gnus-remove-from-range read (gnus-info-read info))))
11411                 (when (or add del)
11412                   (unless (gnus-check-group group)
11413                     (error "Can't open server for %s" group))
11414                   (gnus-request-set-mark
11415                    group (delq nil (list (if add (list add 'add '(read)))
11416                                          (if del (list del 'del '(read))))))
11417                   (setq setmarkundo
11418                         `(gnus-request-set-mark
11419                           ,group
11420                           ',(delq nil (list
11421                                        (if del (list del 'add '(read)))
11422                                        (if add (list add 'del '(read))))))))))
11423             (set-buffer gnus-group-buffer)
11424             (gnus-undo-register
11425               `(progn
11426                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11427                  (gnus-info-set-read ',info ',(gnus-info-read info))
11428                  (gnus-get-unread-articles-in-group ',info
11429                                                     (gnus-active ,group))
11430                  (gnus-group-update-group ,group t)
11431                  ,setmarkundo))))
11432         ;; Enter this list into the group info.
11433         (gnus-info-set-read info read)
11434         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11435         (gnus-get-unread-articles-in-group info (gnus-active group))
11436         t))))
11437
11438 (defun gnus-offer-save-summaries ()
11439   "Offer to save all active summary buffers."
11440   (let (buffers)
11441     ;; Go through all buffers and find all summaries.
11442     (dolist (buffer (buffer-list))
11443       (when (and (setq buffer (buffer-name buffer))
11444                  (string-match "Summary" buffer)
11445                  (save-excursion
11446                    (set-buffer buffer)
11447                    ;; We check that this is, indeed, a summary buffer.
11448                    (and (eq major-mode 'gnus-summary-mode)
11449                         ;; Also make sure this isn't bogus.
11450                         gnus-newsgroup-prepared
11451                         ;; Also make sure that this isn't a
11452                         ;; dead summary buffer.
11453                         (not gnus-dead-summary-mode))))
11454         (push buffer buffers)))
11455     ;; Go through all these summary buffers and offer to save them.
11456     (when buffers
11457       (save-excursion
11458         (map-y-or-n-p
11459          "Update summary buffer %s? "
11460          (lambda (buf)
11461            (switch-to-buffer buf)
11462            (gnus-summary-exit))
11463          buffers)))))
11464
11465
11466 ;;; @ for mime-partial
11467 ;;;
11468
11469 (defun gnus-request-partial-message ()
11470   (save-excursion
11471     (let ((number (gnus-summary-article-number))
11472           (group gnus-newsgroup-name)
11473           (mother gnus-article-buffer))
11474       (set-buffer (get-buffer-create " *Partial Article*"))
11475       (erase-buffer)
11476       (setq mime-preview-buffer mother)
11477       (gnus-request-article-this-buffer number group)
11478       (mime-parse-buffer)
11479       )))
11480
11481 (autoload 'mime-combine-message/partial-pieces-automatically
11482   "mime-partial"
11483   "Internal method to combine message/partial messages automatically.")
11484
11485 (mime-add-condition
11486  'action '((type . message)(subtype . partial)
11487            (major-mode . gnus-original-article-mode)
11488            (method . mime-combine-message/partial-pieces-automatically)
11489            (summary-buffer-exp . gnus-summary-buffer)
11490            (request-partial-message-method . gnus-request-partial-message)
11491            ))
11492
11493
11494 ;;; @ for message/rfc822
11495 ;;;
11496
11497 (defun gnus-mime-extract-message/rfc822 (entity situation)
11498   "Burst a forwarded article."
11499   (save-excursion
11500     (set-buffer gnus-summary-buffer)
11501     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11502                                    gnus-newsgroup-name 'gnus-group-history))
11503            (gnus-group-marked (list group))
11504            article info)
11505       (with-temp-buffer
11506         (mime-insert-entity-content entity)
11507         (setq article (gnus-request-accept-article group)))
11508       (when (and (consp article)
11509                  (numberp (setq article (cdr article))))
11510         (setq info (gnus-get-info group))
11511         (gnus-info-set-read info
11512                             (gnus-remove-from-range (gnus-info-read info)
11513                                                     (list article)))
11514         (when (string-equal group gnus-newsgroup-name)
11515           (forward-line 1)
11516           (let (gnus-show-threads)
11517             (gnus-summary-goto-subject article t))
11518           (gnus-summary-clear-mark-forward 1))
11519         (set-buffer gnus-group-buffer)
11520         (gnus-group-get-new-news-this-group nil t)))))
11521
11522 (mime-add-condition
11523  'action '((type . message)(subtype . rfc822)
11524            (major-mode . gnus-original-article-mode)
11525            (method . gnus-mime-extract-message/rfc822)
11526            (mode . "extract")
11527            ))
11528
11529 (mime-add-condition
11530  'action '((type . message)(subtype . news)
11531            (major-mode . gnus-original-article-mode)
11532            (method . gnus-mime-extract-message/rfc822)
11533            (mode . "extract")
11534            ))
11535
11536 (defun gnus-mime-extract-multipart (entity situation)
11537   (let ((children (mime-entity-children entity))
11538         mime-acting-situation-to-override
11539         f)
11540     (while children
11541       (mime-play-entity (car children)
11542                         (cons (assq 'mode situation)
11543                               mime-acting-situation-to-override))
11544       (setq children (cdr children)))
11545     (if (setq f (cdr (assq 'after-method
11546                            mime-acting-situation-to-override)))
11547         (eval f)
11548       )))
11549
11550 (mime-add-condition
11551  'action '((type . multipart)
11552            (method . gnus-mime-extract-multipart)
11553            (mode . "extract")
11554            )
11555  'with-default)
11556
11557
11558 ;;; @ end
11559 ;;;
11560
11561 (defun gnus-summary-inherit-default-charset ()
11562   "Import `default-mime-charset' from summary buffer.
11563 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11564 of FLIM is used."
11565   (if (buffer-live-p gnus-summary-buffer)
11566       (let (d-m-c d-m-c-u)
11567         (with-current-buffer gnus-summary-buffer
11568           (setq d-m-c (if (local-variable-p 'default-mime-charset
11569                                             gnus-summary-buffer)
11570                           default-mime-charset
11571                         t)
11572                 ;; LIMIT
11573                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11574                                               gnus-summary-buffer)
11575                             (symbol-value 'default-mime-charset-unlimited)
11576                           t)))
11577         (if (eq t d-m-c)
11578             (kill-local-variable 'default-mime-charset)
11579           (set (make-local-variable 'default-mime-charset) d-m-c))
11580         (if (eq t d-m-c-u)
11581             (kill-local-variable 'default-mime-charset-unlimited)
11582           (set (make-local-variable 'default-mime-charset-unlimited)
11583                d-m-c-u)))))
11584
11585 (defun gnus-summary-setup-default-charset ()
11586   "Setup newsgroup default charset."
11587   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11588       (progn
11589         (setq gnus-newsgroup-charset nil)
11590         (set (make-local-variable 'default-mime-charset) nil)
11591         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11592           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11593     (let ((ignored-charsets
11594            (or gnus-newsgroup-ephemeral-ignored-charsets
11595                (append
11596                 (and gnus-newsgroup-name
11597                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11598                 gnus-newsgroup-ignored-charsets)))
11599           charset)
11600       (setq gnus-newsgroup-charset
11601             (or gnus-newsgroup-ephemeral-charset
11602                 (when (and gnus-newsgroup-name
11603                            (setq charset (gnus-parameter-charset
11604                                           gnus-newsgroup-name)))
11605                   (make-local-variable 'default-mime-charset)
11606                   (setq default-mime-charset charset))
11607                 gnus-default-charset))
11608       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11609            ignored-charsets))))
11610
11611 ;;;
11612 ;;; Mime Commands
11613 ;;;
11614
11615 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11616   "Display the current article buffer fully MIME-buttonized.
11617 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11618 treated as multipart/mixed."
11619   (interactive "P")
11620   (require 'gnus-art)
11621   (let ((gnus-unbuttonized-mime-types nil)
11622         (gnus-mime-display-multipart-as-mixed show-all-parts))
11623     (gnus-summary-show-article)))
11624
11625 (defun gnus-summary-repair-multipart (article)
11626   "Add a Content-Type header to a multipart article without one."
11627   (interactive (list (gnus-summary-article-number)))
11628   (gnus-with-article article
11629     (message-narrow-to-head)
11630     (message-remove-header "Mime-Version")
11631     (goto-char (point-max))
11632     (insert "Mime-Version: 1.0\n")
11633     (widen)
11634     (when (search-forward "\n--" nil t)
11635       (let ((separator (buffer-substring (point) (point-at-eol))))
11636         (message-narrow-to-head)
11637         (message-remove-header "Content-Type")
11638         (goto-char (point-max))
11639         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11640                         separator))
11641         (widen))))
11642   (let (gnus-mark-article-hook)
11643     (gnus-summary-select-article t t nil article)))
11644
11645 (defun gnus-summary-toggle-display-buttonized ()
11646   "Toggle the buttonizing of the article buffer."
11647   (interactive)
11648   (require 'gnus-art)
11649   (if (setq gnus-inhibit-mime-unbuttonizing
11650             (not gnus-inhibit-mime-unbuttonizing))
11651       (let ((gnus-unbuttonized-mime-types nil))
11652         (gnus-summary-show-article))
11653     (gnus-summary-show-article)))
11654
11655 ;;;
11656 ;;; Intelli-mouse commmands
11657 ;;;
11658
11659 (defun gnus-wheel-summary-scroll (event)
11660   (interactive "e")
11661   (let ((amount (if (memq 'shift (event-modifiers event))
11662                     (car gnus-wheel-scroll-amount)
11663                   (cdr gnus-wheel-scroll-amount)))
11664         (direction (- (* (static-if (featurep 'xemacs)
11665                              (event-button event)
11666                            (cond ((eq 'mouse-4 (event-basic-type event))
11667                                   4)
11668                                  ((eq 'mouse-5 (event-basic-type event))
11669                                   5)))
11670                          2) 9))
11671         edge)
11672     (gnus-summary-scroll-up (* amount direction))
11673     (when (gnus-eval-in-buffer-window gnus-article-buffer
11674             (save-restriction
11675               (widen)
11676               (and (if (< 0 direction)
11677                        (gnus-article-next-page 0)
11678                      (gnus-article-prev-page 0)
11679                      (bobp))
11680                    (if (setq edge (get-text-property
11681                                    (point-min) 'gnus-wheel-edge))
11682                        (setq edge (* edge direction))
11683                      (setq edge -1))
11684                    (or (plusp edge)
11685                        (let ((buffer-read-only nil)
11686                              (inhibit-read-only t))
11687                          (put-text-property (point-min) (point-max)
11688                                             'gnus-wheel-edge direction)
11689                          nil))
11690                    (or (> edge gnus-wheel-edge-resistance)
11691                        (let ((buffer-read-only nil)
11692                              (inhibit-read-only t))
11693                          (put-text-property (point-min) (point-max)
11694                                             'gnus-wheel-edge
11695                                             (* (1+ edge) direction))
11696                          nil))
11697                    (eq last-command 'gnus-wheel-summary-scroll))))
11698       (gnus-summary-next-article nil nil (minusp direction)))))
11699
11700 (defun gnus-wheel-install ()
11701   "Enable mouse wheel support on summary window."
11702   (when gnus-use-wheel
11703     (let ((keys
11704            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11705       (dolist (key keys)
11706         (define-key gnus-summary-mode-map key
11707           'gnus-wheel-summary-scroll)))))
11708
11709 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11710
11711 ;;;
11712 ;;; Traditional PGP commmands
11713 ;;;
11714
11715 (defun gnus-summary-decrypt-article (&optional force)
11716   "Decrypt the current article in traditional PGP way.
11717 This will have permanent effect only in mail groups.
11718 If FORCE is non-nil, allow editing of articles even in read-only
11719 groups."
11720   (interactive "P")
11721   (gnus-summary-select-article t)
11722   (gnus-eval-in-buffer-window gnus-article-buffer
11723     (save-excursion
11724       (save-restriction
11725         (widen)
11726         (goto-char (point-min))
11727         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11728           (error "Not a traditional PGP message!"))
11729         (let ((armor-start (match-beginning 0)))
11730           (if (and (pgg-decrypt-region armor-start (point-max))
11731                    (or force (not (gnus-group-read-only-p))))
11732               (let ((inhibit-read-only t)
11733                     buffer-read-only)
11734                 (delete-region armor-start
11735                                (progn
11736                                  (re-search-forward "^-+END PGP" nil t)
11737                                  (beginning-of-line 2)
11738                                  (point)))
11739                 (insert-buffer-substring pgg-output-buffer))))))))
11740
11741 (defun gnus-summary-verify-article ()
11742   "Verify the current article in traditional PGP way."
11743   (interactive)
11744   (save-excursion
11745     (set-buffer gnus-original-article-buffer)
11746     (goto-char (point-min))
11747     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11748       (error "Not a traditional PGP message!"))
11749     (re-search-forward "^-+END PGP" nil t)
11750     (beginning-of-line 2)
11751     (call-interactively (function pgg-verify-region))))
11752
11753 ;;;
11754 ;;; Generic summary marking commands
11755 ;;;
11756
11757 (defvar gnus-summary-marking-alist
11758   '((read gnus-del-mark "d")
11759     (unread gnus-unread-mark "u")
11760     (ticked gnus-ticked-mark "!")
11761     (dormant gnus-dormant-mark "?")
11762     (expirable gnus-expirable-mark "e"))
11763   "An alist of names/marks/keystrokes.")
11764
11765 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11766 (defvar gnus-summary-mark-map)
11767
11768 (defun gnus-summary-make-all-marking-commands ()
11769   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11770   (dolist (elem gnus-summary-marking-alist)
11771     (apply 'gnus-summary-make-marking-command elem)))
11772
11773 (defun gnus-summary-make-marking-command (name mark keystroke)
11774   (let ((map (make-sparse-keymap)))
11775     (define-key gnus-summary-generic-mark-map keystroke map)
11776     (dolist (lway `((next "next" next nil "n")
11777                     (next-unread "next unread" next t "N")
11778                     (prev "previous" prev nil "p")
11779                     (prev-unread "previous unread" prev t "P")
11780                     (nomove "" nil nil ,keystroke)))
11781       (let ((func (gnus-summary-make-marking-command-1
11782                    mark (car lway) lway name)))
11783         (setq func (eval func))
11784         (define-key map (nth 4 lway) func)))))
11785
11786 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11787   `(defun ,(intern
11788             (format "gnus-summary-put-mark-as-%s%s"
11789                     name (if (eq way 'nomove)
11790                              ""
11791                            (concat "-" (symbol-name way)))))
11792      (n)
11793      ,(format
11794        "Mark the current article as %s%s.
11795 If N, the prefix, then repeat N times.
11796 If N is negative, move in reverse order.
11797 The difference between N and the actual number of articles marked is
11798 returned."
11799        name (car (cdr lway)))
11800      (interactive "p")
11801      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11802
11803 (defun gnus-summary-generic-mark (n mark move unread)
11804   "Mark N articles with MARK."
11805   (unless (eq major-mode 'gnus-summary-mode)
11806     (error "This command can only be used in the summary buffer"))
11807   (gnus-summary-show-thread)
11808   (let ((nummove
11809          (cond
11810           ((eq move 'next) 1)
11811           ((eq move 'prev) -1)
11812           (t 0))))
11813     (if (zerop nummove)
11814         (setq n 1)
11815       (when (< n 0)
11816         (setq n (abs n)
11817               nummove (* -1 nummove))))
11818     (while (and (> n 0)
11819                 (gnus-summary-mark-article nil mark)
11820                 (zerop (gnus-summary-next-subject nummove unread t)))
11821       (setq n (1- n)))
11822     (when (/= 0 n)
11823       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11824     (gnus-summary-recenter)
11825     (gnus-summary-position-point)
11826     (gnus-set-mode-line 'summary)
11827     n))
11828
11829 (defun gnus-summary-insert-articles (articles)
11830   (when (setq articles
11831               (gnus-sorted-difference articles
11832                                       (mapcar (lambda (h)
11833                                                 (mail-header-number h))
11834                                               gnus-newsgroup-headers)))
11835     (setq gnus-newsgroup-headers
11836           (gnus-merge 'list
11837                       gnus-newsgroup-headers
11838                       (gnus-fetch-headers articles)
11839                       'gnus-article-sort-by-number))
11840     ;; Suppress duplicates?
11841     (when gnus-suppress-duplicates
11842       (gnus-dup-suppress-articles))
11843
11844     ;; We might want to build some more threads first.
11845     (when (and gnus-fetch-old-headers
11846                (eq gnus-headers-retrieved-by 'nov))
11847       (if (eq gnus-fetch-old-headers 'invisible)
11848           (gnus-build-all-threads)
11849         (gnus-build-old-threads)))
11850     ;; Let the Gnus agent mark articles as read.
11851     (when gnus-agent
11852       (gnus-agent-get-undownloaded-list))
11853     ;; Remove list identifiers from subject
11854     (when gnus-list-identifiers
11855       (gnus-summary-remove-list-identifiers))
11856     ;; First and last article in this newsgroup.
11857     (when gnus-newsgroup-headers
11858       (setq gnus-newsgroup-begin
11859             (mail-header-number (car gnus-newsgroup-headers))
11860             gnus-newsgroup-end
11861             (mail-header-number
11862              (gnus-last-element gnus-newsgroup-headers))))
11863     (when gnus-use-scoring
11864       (gnus-possibly-score-headers))))
11865
11866 (defun gnus-summary-insert-old-articles (&optional all)
11867   "Insert all old articles in this group.
11868 If ALL is non-nil, already read articles become readable.
11869 If ALL is a number, fetch this number of articles."
11870   (interactive "P")
11871   (prog1
11872       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11873             older len)
11874         (setq older
11875               ;; Some nntp servers lie about their active range.  When
11876               ;; this happens, the active range can be in the millions.
11877               ;; Use a compressed range to avoid creating a huge list.
11878               (gnus-range-difference (list gnus-newsgroup-active) old))
11879         (setq len (gnus-range-length older))
11880         (cond
11881          ((null older) nil)
11882          ((numberp all)
11883           (if (< all len)
11884               (let ((older-range (nreverse older)))
11885                 (setq older nil)
11886
11887                 (while (> all 0)
11888                   (let* ((r (pop older-range))
11889                          (min (if (numberp r) r (car r)))
11890                          (max (if (numberp r) r (cdr r))))
11891                     (while (and (<= min max)
11892                                 (> all 0))
11893                       (push max older)
11894                       (setq all (1- all)
11895                             max (1- max))))))
11896             (setq older (gnus-uncompress-range older))))
11897          (all
11898           (setq older (gnus-uncompress-range older)))
11899          (t
11900           (when (and (numberp gnus-large-newsgroup)
11901                    (> len gnus-large-newsgroup))
11902               (let* ((cursor-in-echo-area nil)
11903                      (initial (gnus-parameter-large-newsgroup-initial
11904                                gnus-newsgroup-name))
11905                      (input
11906                       (read-string
11907                        (format
11908                         "How many articles from %s (%s %d): "
11909                         (gnus-limit-string
11910                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11911                         (if initial "max" "default")
11912                         len)
11913                        (if initial
11914                            (cons (number-to-string initial)
11915                                  0)))))
11916                 (unless (string-match "^[ \t]*$" input)
11917                   (setq all (string-to-number input))
11918                   (if (< all len)
11919                       (let ((older-range (nreverse older)))
11920                         (setq older nil)
11921
11922                         (while (> all 0)
11923                           (let* ((r (pop older-range))
11924                                  (min (if (numberp r) r (car r)))
11925                                  (max (if (numberp r) r (cdr r))))
11926                             (while (and (<= min max)
11927                                         (> all 0))
11928                               (push max older)
11929                               (setq all (1- all)
11930                                     max (1- max))))))))))
11931           (setq older (gnus-uncompress-range older))))
11932         (if (not older)
11933             (message "No old news.")
11934           (gnus-summary-insert-articles older)
11935           (gnus-summary-limit (gnus-sorted-nunion old older))))
11936     (gnus-summary-position-point)))
11937
11938 (defun gnus-summary-insert-new-articles ()
11939   "Insert all new articles in this group."
11940   (interactive)
11941   (prog1
11942       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11943             (old-active gnus-newsgroup-active)
11944             (nnmail-fetched-sources (list t))
11945             i new)
11946         (setq gnus-newsgroup-active
11947               (gnus-activate-group gnus-newsgroup-name 'scan))
11948         (setq i (cdr gnus-newsgroup-active))
11949         (while (> i (cdr old-active))
11950           (push i new)
11951           (decf i))
11952         (if (not new)
11953             (message "No gnus is bad news")
11954           (gnus-summary-insert-articles new)
11955           (setq gnus-newsgroup-unreads
11956                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11957           (gnus-summary-limit (gnus-sorted-nunion old new))))
11958     (gnus-summary-position-point)))
11959
11960 (gnus-summary-make-all-marking-commands)
11961
11962 (gnus-ems-redefine)
11963
11964 (provide 'gnus-sum)
11965
11966 (run-hooks 'gnus-sum-load-hook)
11967
11968 ;; Local Variables:
11969 ;; coding: iso-8859-1
11970 ;; End:
11971
11972 ;;; gnus-sum.el ends here